2025-06-26 15:13:46 -04:00
|
|
|
#include <iostream>
|
2025-06-29 14:54:25 -04:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
#include "gridfire/engine/engine_graph.h"
|
|
|
|
|
#include "gridfire/engine/engine_approx8.h"
|
2025-07-01 11:41:14 -04:00
|
|
|
#include "gridfire/engine/views/engine_adaptive.h"
|
|
|
|
|
#include "gridfire/engine/views/engine_defined.h"
|
|
|
|
|
#include "gridfire/io/network_file.h"
|
2025-06-29 14:54:25 -04:00
|
|
|
|
|
|
|
|
#include "gridfire/solver/solver.h"
|
|
|
|
|
|
2025-06-26 15:13:46 -04:00
|
|
|
#include "gridfire/network.h"
|
|
|
|
|
|
|
|
|
|
#include "fourdst/composition/composition.h"
|
|
|
|
|
|
2025-06-29 14:54:25 -04:00
|
|
|
#include "fourdst/logging/logging.h"
|
|
|
|
|
#include "quill/Logger.h"
|
|
|
|
|
#include "quill/LogMacros.h"
|
|
|
|
|
#include "quill/Backend.h"
|
|
|
|
|
#include "quill/Frontend.h"
|
|
|
|
|
|
2025-07-01 14:30:45 -04:00
|
|
|
#include <chrono>
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
2025-06-29 14:54:25 -04:00
|
|
|
// Keep a copy of the previous handler
|
|
|
|
|
static std::terminate_handler g_previousHandler = nullptr;
|
|
|
|
|
|
2025-07-01 14:30:45 -04:00
|
|
|
void measure_execution_time(const std::function<void()>& callback, const std::string& name)
|
|
|
|
|
{
|
|
|
|
|
// variable names in camelCase
|
|
|
|
|
const auto startTime = std::chrono::steady_clock::now();
|
|
|
|
|
callback();
|
|
|
|
|
const auto endTime = std::chrono::steady_clock::now();
|
|
|
|
|
const auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime);
|
|
|
|
|
std::cout << "Execution time for " << name << ": "
|
|
|
|
|
<< duration.count()/1e9 << " s\n";
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-29 14:54:25 -04:00
|
|
|
void quill_terminate_handler()
|
|
|
|
|
{
|
|
|
|
|
// 1. Stop the Quill backend (flushes all sinks and joins thread)
|
|
|
|
|
quill::Backend::stop();
|
|
|
|
|
|
|
|
|
|
// 2. Optionally, flush individual loggers:
|
|
|
|
|
// for (auto logger : quill::get_all_loggers())
|
|
|
|
|
// logger->flush_log();
|
|
|
|
|
|
|
|
|
|
// 3. Chain to the previous terminate handler (or abort if none)
|
|
|
|
|
if (g_previousHandler)
|
|
|
|
|
g_previousHandler();
|
|
|
|
|
else
|
|
|
|
|
std::abort();
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-26 15:13:46 -04:00
|
|
|
int main() {
|
2025-06-29 14:54:25 -04:00
|
|
|
g_previousHandler = std::set_terminate(quill_terminate_handler);
|
|
|
|
|
quill::Logger* logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
2025-07-01 11:41:14 -04:00
|
|
|
logger->set_log_level(quill::LogLevel::Debug);
|
2025-06-29 14:54:25 -04:00
|
|
|
LOG_DEBUG(logger, "Starting Adaptive Engine View Example...");
|
|
|
|
|
|
2025-06-26 15:13:46 -04:00
|
|
|
using namespace gridfire;
|
|
|
|
|
const std::vector<double> comp = {0.708, 0.0, 2.94e-5, 0.276, 0.003, 0.0011, 9.62e-3, 1.62e-3, 5.16e-4};
|
|
|
|
|
const std::vector<std::string> symbols = {"H-1", "H-2", "He-3", "He-4", "C-12", "N-14", "O-16", "Ne-20", "Mg-24"};
|
|
|
|
|
|
|
|
|
|
fourdst::composition::Composition composition;
|
|
|
|
|
composition.registerSymbol(symbols, true);
|
|
|
|
|
composition.setMassFraction(symbols, comp);
|
|
|
|
|
composition.finalize(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NetIn netIn;
|
|
|
|
|
netIn.composition = composition;
|
2025-06-29 14:54:25 -04:00
|
|
|
netIn.temperature = 1.5e7;
|
2025-06-26 15:13:46 -04:00
|
|
|
netIn.density = 1e2;
|
|
|
|
|
netIn.energy = 0.0;
|
|
|
|
|
|
2025-06-29 14:54:25 -04:00
|
|
|
netIn.tMax = 3.1536e17;
|
2025-06-26 15:13:46 -04:00
|
|
|
netIn.dt0 = 1e12;
|
|
|
|
|
|
|
|
|
|
NetOut netOut;
|
2025-07-01 11:41:14 -04:00
|
|
|
|
2025-07-01 14:30:45 -04:00
|
|
|
// netIn.dt0 = 1e12;
|
2025-06-29 14:54:25 -04:00
|
|
|
// approx8::Approx8Network approx8Network;
|
2025-07-01 14:30:45 -04:00
|
|
|
// measure_execution_time([&]() {
|
|
|
|
|
// netOut = approx8Network.evaluate(netIn);
|
|
|
|
|
// }, "Approx8 Network Initialization");
|
2025-07-01 11:41:14 -04:00
|
|
|
// std::cout << "Approx8 Network H-1: " << netOut.composition.getMassFraction("H-1") << " in " << netOut.num_steps << " steps." << std::endl;
|
|
|
|
|
|
2025-06-26 15:13:46 -04:00
|
|
|
|
|
|
|
|
netIn.dt0 = 1e-15;
|
|
|
|
|
|
|
|
|
|
GraphEngine ReaclibEngine(composition);
|
2025-07-01 14:30:45 -04:00
|
|
|
ReaclibEngine.setPrecomputation(true);
|
2025-07-01 11:41:14 -04:00
|
|
|
// AdaptiveEngineView adaptiveEngine(ReaclibEngine);
|
|
|
|
|
io::SimpleReactionListFileParser parser{};
|
|
|
|
|
FileDefinedEngineView approx8EngineView(ReaclibEngine, "approx8.net", parser);
|
|
|
|
|
approx8EngineView.setScreeningModel(screening::ScreeningType::WEAK);
|
|
|
|
|
solver::QSENetworkSolver solver(approx8EngineView);
|
2025-06-26 15:13:46 -04:00
|
|
|
netOut = solver.evaluate(netIn);
|
2025-07-01 14:30:45 -04:00
|
|
|
|
|
|
|
|
// measure_execution_time([&]() {
|
|
|
|
|
// netOut = solver.evaluate(netIn);
|
|
|
|
|
// }, "Approx8 Network Evaluation (Precomputation)");
|
|
|
|
|
// ReaclibEngine.setPrecomputation(false);
|
|
|
|
|
// std::cout << "Precomputation H-1: " << netOut.composition.getMassFraction("H-1") << " in " << netOut.num_steps << " steps." << std::endl;
|
2025-06-26 15:13:46 -04:00
|
|
|
}
|