2025-12-10 12:47:16 -05:00
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
|
|
#include "gridfire/gridfire.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "fourdst/composition/composition.h"
|
|
|
|
|
|
#include "fourdst/logging/logging.h"
|
|
|
|
|
|
#include "fourdst/atomic/species.h"
|
|
|
|
|
|
#include "fourdst/composition/utils.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "quill/Logger.h"
|
|
|
|
|
|
#include "quill/Backend.h"
|
|
|
|
|
|
#include "CLI/CLI.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <clocale>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static std::terminate_handler g_previousHandler = nullptr;
|
|
|
|
|
|
static std::vector<std::pair<double, std::unordered_map<std::string, std::pair<double, double>>>> g_callbackHistory;
|
|
|
|
|
|
static bool s_wrote_abundance_history = false;
|
|
|
|
|
|
void quill_terminate_handler();
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<double> linspace(const double start, const double end, const size_t num) {
|
|
|
|
|
|
std::vector<double> result;
|
|
|
|
|
|
if (num == 0) return result;
|
|
|
|
|
|
if (num == 1) {
|
|
|
|
|
|
result.push_back(start);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
const double step = (end - start) / static_cast<double>(num - 1);
|
|
|
|
|
|
for (size_t i = 0; i < num; ++i) {
|
|
|
|
|
|
result.push_back(start + i * step);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-10 12:50:35 -05:00
|
|
|
|
std::vector<gridfire::NetIn> init(const double tMin, const double tMax, const double rhoMin, const double rhoMax, const double nShells, const double evolveTime) {
|
2025-12-10 12:47:16 -05:00
|
|
|
|
std::setlocale(LC_ALL, "");
|
|
|
|
|
|
g_previousHandler = std::set_terminate(quill_terminate_handler);
|
|
|
|
|
|
quill::Logger* logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
|
|
|
|
|
logger->set_log_level(quill::LogLevel::TraceL2);
|
2025-12-10 12:50:35 -05:00
|
|
|
|
LOG_INFO(logger, "Initializing GridFire Spectral Solver Sandbox...");
|
2025-12-10 12:47:16 -05:00
|
|
|
|
|
|
|
|
|
|
using namespace gridfire;
|
|
|
|
|
|
const std::vector<double> X = {0.7081145999999999, 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"};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fourdst::composition::Composition composition = fourdst::composition::buildCompositionFromMassFractions(symbols, X);
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<NetIn> netIns;
|
|
|
|
|
|
for (const auto& [T, ρ]: std::views::zip(linspace(tMin, tMax, nShells), linspace(rhoMax, rhoMin, nShells))) {
|
|
|
|
|
|
NetIn netIn;
|
|
|
|
|
|
netIn.composition = composition;
|
|
|
|
|
|
netIn.temperature = T;
|
|
|
|
|
|
netIn.density = ρ;
|
|
|
|
|
|
netIn.energy = 0;
|
|
|
|
|
|
|
2025-12-10 12:50:35 -05:00
|
|
|
|
netIn.tMax = evolveTime;
|
2025-12-10 12:47:16 -05:00
|
|
|
|
netIn.dt0 = 1e-12;
|
|
|
|
|
|
netIns.push_back(netIn);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return netIns;
|
|
|
|
|
|
}
|
|
|
|
|
|
void quill_terminate_handler()
|
|
|
|
|
|
{
|
|
|
|
|
|
quill::Backend::stop();
|
|
|
|
|
|
if (g_previousHandler)
|
|
|
|
|
|
g_previousHandler();
|
|
|
|
|
|
else
|
|
|
|
|
|
std::abort();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
|
using namespace gridfire;
|
|
|
|
|
|
|
|
|
|
|
|
CLI::App app{"GridFire Sandbox Application."};
|
|
|
|
|
|
|
2025-12-12 17:24:53 -05:00
|
|
|
|
double tMin = 1.5e7;
|
|
|
|
|
|
double tMax = 1.7e7;
|
|
|
|
|
|
double rhoMin = 1.5e2;
|
|
|
|
|
|
double rhoMax = 1.5e2;
|
|
|
|
|
|
double nShells = 15;
|
2025-12-10 12:50:35 -05:00
|
|
|
|
double evolveTime = 3.1536e+16;
|
2025-12-10 12:47:16 -05:00
|
|
|
|
|
|
|
|
|
|
app.add_option("--tMin", tMin, "Minimum time in seconds");
|
|
|
|
|
|
app.add_option("--tMax", tMax, "Maximum time in seconds");
|
|
|
|
|
|
app.add_option("--rhoMin", rhoMin, "Minimum density in g/cm^3");
|
|
|
|
|
|
app.add_option("--rhoMax", rhoMax, "Maximum density in g/cm^3");
|
|
|
|
|
|
app.add_option("--nShells", nShells, "Number of shells");
|
2025-12-10 12:50:35 -05:00
|
|
|
|
app.add_option("--evolveTime", evolveTime, "Maximum time in seconds");
|
2025-12-10 12:47:16 -05:00
|
|
|
|
|
|
|
|
|
|
CLI11_PARSE(app, argc, argv);
|
|
|
|
|
|
|
2025-12-10 12:50:35 -05:00
|
|
|
|
const std::vector<NetIn> netIns = init(tMin, tMax, rhoMin, rhoMax, nShells, evolveTime);
|
2025-12-10 12:47:16 -05:00
|
|
|
|
|
|
|
|
|
|
policy::MainSequencePolicy stellarPolicy(netIns[0].composition);
|
|
|
|
|
|
stellarPolicy.construct();
|
2025-12-12 17:24:53 -05:00
|
|
|
|
policy::ConstructionResults construct = stellarPolicy.construct();
|
2025-12-10 12:47:16 -05:00
|
|
|
|
|
2025-12-12 17:24:53 -05:00
|
|
|
|
solver::SpectralSolverStrategy solver(construct.engine);
|
2025-12-10 12:47:16 -05:00
|
|
|
|
std::vector<double> mass_coords = linspace(1e-5, 1.0, nShells);
|
|
|
|
|
|
|
2025-12-12 17:24:53 -05:00
|
|
|
|
std::vector<NetOut> results = solver.evaluate(netIns, mass_coords, *construct.scratch_blob);
|
2025-12-10 12:47:16 -05:00
|
|
|
|
}
|