fix(engine_multiscale): resolved a major species index ordering bug

All jacobian calculations were broken because the indexing used to record the AD tape was broken (see not parallel to) the indexing used by the composition object. A fix for this was to sort the network species by mass. However, more generally we should introduce a mechanism to ensure these two indexed sets always remain parallel
This commit is contained in:
2025-10-14 13:37:48 -04:00
parent 408f6d83a2
commit 3b8a0a1f33
10 changed files with 276 additions and 232 deletions

View File

@@ -120,6 +120,9 @@ namespace gridfire {
LOG_INFO(logger, "Starting network construction with {} available species.", availableSpecies.size());
for (int layer = 0; layer < depth && !remainingReactions.empty(); ++layer) {
size_t collectedThisLayer = 0;
size_t collectedStrong = 0;
size_t collectedWeak = 0;
LOG_TRACE_L1(logger, "Collecting reactions for layer {} with {} remaining reactions. Currently there are {} available species", layer, remainingReactions.size(), availableSpecies.size());
std::vector<Reaction*> reactionsForNextPass;
std::unordered_set<Species> newProductsThisLayer;
@@ -138,6 +141,12 @@ namespace gridfire {
if (allReactantsAvailable) {
collectedReactionPtrs.push_back(reaction);
if (reaction->type() == reaction::ReactionType::WEAK) {
collectedWeak++;
} else {
collectedStrong++;
}
collectedThisLayer++;
newReactionsAdded = true;
for (const auto& product : reaction->products()) {
@@ -153,14 +162,18 @@ namespace gridfire {
break;
}
size_t oldProductCount = availableSpecies.size();
availableSpecies.insert(newProductsThisLayer.begin(), newProductsThisLayer.end());
size_t newProductCount = availableSpecies.size() - oldProductCount;
LOG_TRACE_L1(
logger,
"Layer {}: Collected {} new reactions. New products this layer: {}",
"Layer {}: Collected {} new reactions ({} strong, {} weak). New products this layer: {}",
layer,
collectedReactionPtrs.size() - collectedReactionPtrs.size(),
newProductsThisLayer.size()
collectedThisLayer,
collectedStrong,
collectedWeak,
newProductCount
);
availableSpecies.insert(newProductsThisLayer.begin(), newProductsThisLayer.end());
remainingReactions = std::move(reactionsForNextPass);
}