perf(precomputation): cleaned up allocations
recovered about 5% execution time
This commit is contained in:
@@ -53,7 +53,7 @@ namespace gridfire::engine {
|
||||
struct StepDerivatives {
|
||||
std::map<fourdst::atomic::Species, T> dydt{}; ///< Derivatives of abundances (dY/dt for each species).
|
||||
T nuclearEnergyGenerationRate = T(0.0); ///< Specific energy generation rate (e.g., erg/g/s).
|
||||
std::map<fourdst::atomic::Species, std::unordered_map<std::string, T>> reactionContributions{};
|
||||
std::optional<std::map<fourdst::atomic::Species, std::unordered_map<std::string, T>>> reactionContributions = std::nullopt;
|
||||
T neutrinoEnergyLossRate = T(0.0); // (erg/g/s)
|
||||
T totalNeutrinoFlux = T(0.0); // (neutrinos/g/s)
|
||||
|
||||
|
||||
@@ -753,6 +753,14 @@ namespace gridfire::engine {
|
||||
[[nodiscard]]
|
||||
SpeciesStatus getSpeciesStatus(const fourdst::atomic::Species &species) const override;
|
||||
|
||||
[[nodiscard]] bool get_store_intermediate_reaction_contributions() const {
|
||||
return m_store_intermediate_reaction_contributions;
|
||||
}
|
||||
|
||||
void set_store_intermediate_reaction_contributions(const bool value) {
|
||||
m_store_intermediate_reaction_contributions = value;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
struct PrecomputedReaction {
|
||||
@@ -879,6 +887,7 @@ namespace gridfire::engine {
|
||||
|
||||
bool m_usePrecomputation = true; ///< Flag to enable or disable using precomputed reactions for efficiency. Mathematically, this should not change the results. Generally end users should not need to change this.
|
||||
bool m_useReverseReactions = true; ///< Flag to enable or disable reverse reactions. If false, only forward reactions are considered.
|
||||
bool m_store_intermediate_reaction_contributions = false; ///< Flag to enable or disable storing intermediate reaction contributions for debugging.
|
||||
|
||||
BuildDepthType m_depth;
|
||||
|
||||
@@ -1207,7 +1216,10 @@ namespace gridfire::engine {
|
||||
const T nu_ij = static_cast<T>(reaction.stoichiometry(species));
|
||||
const T dydt_increment = threshold_flag * molarReactionFlow * nu_ij;
|
||||
dydt_vec[speciesIdx] += dydt_increment;
|
||||
result.reactionContributions[species][std::string(reaction.id())] = dydt_increment;
|
||||
|
||||
if (m_store_intermediate_reaction_contributions) {
|
||||
result.reactionContributions.value()[species][std::string(reaction.id())] = dydt_increment;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ namespace gridfire::solver {
|
||||
};
|
||||
|
||||
struct CVODERHSOutputData {
|
||||
std::map<fourdst::atomic::Species, std::unordered_map<std::string, double>> reaction_contribution_map;
|
||||
std::optional<std::map<fourdst::atomic::Species, std::unordered_map<std::string, double>>> reaction_contribution_map;
|
||||
double neutrino_energy_loss_rate;
|
||||
double total_neutrino_flux;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user