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"
|
2025-07-03 09:55:10 -04:00
|
|
|
#include "gridfire/partition/partition_types.h"
|
2025-07-01 11:41:14 -04:00
|
|
|
#include "gridfire/engine/views/engine_defined.h"
|
2025-07-10 09:36:05 -04:00
|
|
|
#include "gridfire/engine/views/engine_multiscale.h"
|
|
|
|
|
#include "gridfire/engine/procedures/priming.h"
|
2025-07-01 11:41:14 -04:00
|
|
|
#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-07-02 11:32:45 -04:00
|
|
|
#include "gridfire/partition/composite/partition_composite.h"
|
|
|
|
|
|
2025-06-29 14:54:25 -04:00
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
quill::Backend::stop();
|
|
|
|
|
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-18 15:23:43 -04:00
|
|
|
logger->set_log_level(quill::LogLevel::Info);
|
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;
|
2025-07-14 14:54:22 -04:00
|
|
|
const std::vector<double> comp = {0.708, 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", "He-3", "He-4", "C-12", "N-14", "O-16", "Ne-20", "Mg-24"};
|
2025-06-26 15:13:46 -04:00
|
|
|
|
2025-07-10 09:36:05 -04:00
|
|
|
|
2025-06-26 15:13:46 -04:00
|
|
|
fourdst::composition::Composition composition;
|
|
|
|
|
composition.registerSymbol(symbols, true);
|
|
|
|
|
composition.setMassFraction(symbols, comp);
|
|
|
|
|
composition.finalize(true);
|
2025-07-10 09:36:05 -04:00
|
|
|
using partition::BasePartitionType;
|
|
|
|
|
const auto partitionFunction = partition::CompositePartitionFunction({
|
|
|
|
|
BasePartitionType::RauscherThielemann,
|
|
|
|
|
BasePartitionType::GroundState
|
|
|
|
|
});
|
2025-06-26 15:13:46 -04:00
|
|
|
|
|
|
|
|
NetIn netIn;
|
|
|
|
|
netIn.composition = composition;
|
2025-07-29 07:49:17 -04:00
|
|
|
netIn.temperature = 5e9;
|
|
|
|
|
netIn.density = 1.6e6;
|
2025-07-14 14:54:22 -04:00
|
|
|
netIn.energy = 0;
|
2025-07-29 07:49:17 -04:00
|
|
|
// netIn.tMax = 3.1536e17; // ~ 10Gyr
|
|
|
|
|
netIn.tMax = 1e-14;
|
2025-07-14 14:54:22 -04:00
|
|
|
netIn.dt0 = 1e-12;
|
2025-07-16 12:14:02 -04:00
|
|
|
|
2025-07-29 07:49:17 -04:00
|
|
|
GraphEngine ReaclibEngine(composition, partitionFunction, NetworkBuildDepth::SecondOrder);
|
|
|
|
|
ReaclibEngine.setUseReverseReactions(true);
|
2025-07-22 12:48:24 -04:00
|
|
|
// ReaclibEngine.setScreeningModel(screening::ScreeningType::WEAK);
|
|
|
|
|
//
|
2025-07-29 07:49:17 -04:00
|
|
|
MultiscalePartitioningEngineView partitioningView(ReaclibEngine);
|
|
|
|
|
AdaptiveEngineView adaptiveView(partitioningView);
|
2025-07-22 12:48:24 -04:00
|
|
|
//
|
2025-07-29 07:49:17 -04:00
|
|
|
solver::DirectNetworkSolver solver(adaptiveView);
|
|
|
|
|
NetOut netOut;
|
|
|
|
|
netOut = solver.evaluate(netIn);
|
|
|
|
|
std::cout << "Initial H-1: " << netIn.composition.getMassFraction("H-1") << std::endl;
|
|
|
|
|
std::cout << "NetOut H-1: " << netOut.composition.getMassFraction("H-1") << std::endl;
|
|
|
|
|
std::cout << "Consumed " << (netIn.composition.getMassFraction("H-1") - netOut.composition.getMassFraction("H-1")) * 100 << " % H-1 by mass" << std::endl;
|
2025-07-22 12:48:24 -04:00
|
|
|
// measure_execution_time([&](){netOut = solver.evaluate(netIn);}, "DirectNetworkSolver Evaluation");
|
|
|
|
|
// std::cout << "DirectNetworkSolver completed in " << netOut.num_steps << " steps.\n";
|
|
|
|
|
// std::cout << "Final composition:\n";
|
|
|
|
|
// for (const auto& [symbol, entry] : netOut.composition) {
|
|
|
|
|
// std::cout << symbol << ": " << entry.mass_fraction() << "\n";
|
|
|
|
|
// }
|
|
|
|
|
|
2025-06-26 15:13:46 -04:00
|
|
|
}
|