test(reverse-rates): testing reverse rates

This commit is contained in:
2025-07-29 07:49:17 -04:00
parent 2d9216600f
commit e3d7bed39c
2 changed files with 28 additions and 21 deletions

View File

@@ -71,26 +71,26 @@ int main() {
NetIn netIn; NetIn netIn;
netIn.composition = composition; netIn.composition = composition;
netIn.temperature = 1.5e7; netIn.temperature = 5e9;
netIn.density = 1.6e2; netIn.density = 1.6e6;
netIn.energy = 0; netIn.energy = 0;
netIn.tMax = 3.1536e17; // ~ 10Gyr // netIn.tMax = 3.1536e17; // ~ 10Gyr
netIn.tMax = 1e-14;
netIn.dt0 = 1e-12; netIn.dt0 = 1e-12;
for (const auto& [symbol, entry] : netIn.composition) {
std::cout << symbol << ": " << entry.mass_fraction() << "\n";
}
// GraphEngine ReaclibEngine(composition, partitionFunction, NetworkBuildDepth::SecondOrder); GraphEngine ReaclibEngine(composition, partitionFunction, NetworkBuildDepth::SecondOrder);
// ReaclibEngine.setUseReverseReactions(true);
// ReaclibEngine.setPrecomputation(true);
// ReaclibEngine.setUseReverseReactions(false);
// ReaclibEngine.setScreeningModel(screening::ScreeningType::WEAK); // ReaclibEngine.setScreeningModel(screening::ScreeningType::WEAK);
// //
// MultiscalePartitioningEngineView partitioningView(ReaclibEngine); MultiscalePartitioningEngineView partitioningView(ReaclibEngine);
// AdaptiveEngineView adaptiveView(partitioningView); AdaptiveEngineView adaptiveView(partitioningView);
// //
// solver::DirectNetworkSolver solver(adaptiveView); solver::DirectNetworkSolver solver(adaptiveView);
// NetOut netOut; 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;
// measure_execution_time([&](){netOut = solver.evaluate(netIn);}, "DirectNetworkSolver Evaluation"); // measure_execution_time([&](){netOut = solver.evaluate(netIn);}, "DirectNetworkSolver Evaluation");
// std::cout << "DirectNetworkSolver completed in " << netOut.num_steps << " steps.\n"; // std::cout << "DirectNetworkSolver completed in " << netOut.num_steps << " steps.\n";
// std::cout << "Final composition:\n"; // std::cout << "Final composition:\n";

View File

@@ -7,28 +7,35 @@ from fourdst.composition import Composition
symbols : list[str] = ["H-1", "He-3", "He-4", "C-12", "N-14", "O-16", "Ne-20", "Mg-24"] symbols : list[str] = ["H-1", "He-3", "He-4", "C-12", "N-14", "O-16", "Ne-20", "Mg-24"]
X : list[float] = [0.708, 2.94e-5, 0.276, 0.003, 0.0011, 9.62e-3, 1.62e-3, 5.16e-4] X : list[float] = [0.708, 2.94e-5, 0.276, 0.003, 0.0011, 9.62e-3, 1.62e-3, 5.16e-4]
comp = Composition();
comp = Composition()
comp.registerSymbol(symbols) comp.registerSymbol(symbols)
comp.setMassFraction(symbols, X) comp.setMassFraction(symbols, X)
comp.finalize(True) comp.finalize(True)
print(f"Initial H-1 mass fraction {comp.getMassFraction("H-1")}")
netIn = NetIn() netIn = NetIn()
netIn.composition = comp netIn.composition = comp
netIn.temperature = 1.5e7 netIn.temperature = 1.5e7
netIn.density = 1.5e2 netIn.density = 1.6e2
netIn.tMax = 3e17 netIn.tMax = 1e-9
netIn.dt0 = 1e-12 netIn.dt0 = 1e-12
baseEngine = GraphEngine(comp, 2) baseEngine = GraphEngine(netIn.composition, 2)
baseEngine.setUseReverseReactions(False) baseEngine.setUseReverseReactions(False)
qseEngine = MultiscalePartitioningEngineView(baseEngine) qseEngine = MultiscalePartitioningEngineView(baseEngine)
adaptiveEngine = AdaptiveEngineView(qseEngine) adaptiveEngine = AdaptiveEngineView(qseEngine)
solver = DirectNetworkSolver(adaptiveEngine) solver = DirectNetworkSolver(adaptiveEngine)
results = solver.evaluate(netIn);
print(results.composition.getMassFraction("H-1")) results = solver.evaluate(netIn)
print(f"Final H-1 mass fraction {results.composition.getMassFraction("H-1")}")