Conversation
Computes dot_product(soln%thermo%cp, soln%nj) once per guarded branch instead of twice, preserving the exact skip/compute behavior. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit 3bb843f)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the duplicate
dot_product(soln%thermo%cp, soln%nj)calls insource/equilibrium.f90identified in djkees#30. Same arguments, nothing mutates them in between, so each site computed the identical value twice.Changes
EqPartials_compute_partials: computes the dot product once into a localcp_dot_njand reuses it forself%cp_eqandsoln%cp_fr.EqSolver_post_process: the two guarded assignments (cp_fr < 1e-10, andcp_eq < 1e-10 .and. .not. computed_partials_) are independent conditions, so hoisting the dot product unconditionally would have computed it even when neither branch needs it — a common case in practice, sincecompute_partialsalready sets both fields beforepost_processruns whenever partials/transport are requested. Instead, both guards are evaluated intoneed_cp_fr/need_cp_eqlocals, the dot product is computed once only if either is true, and reused in both branches. This preserves the exact original skip/compute behavior while deduping the common "both true" case (a fresh solve with no partials requested).Testing
cmake --build build-dev— clean build, no new warnings.ctest --test-dir build-dev --output-on-failure— 15/15 passed.python -m pytest source/bind/python/tests -q— 115/115 passed (114 existing + 1 new regression test).python test/main_interface/test_main.py— 14/14 passed (byte-comparison against reference.outfiles across equilibrium, rocket, shock, and detonation examples).Added
test_reused_eqsolution_cp_matches_freshtosource/bind/python/tests/test_reuse_solution.py, following the existingtest_issue42_reused_eqsolution_matches_freshpattern: it solves into a reusedEqSolutiontwice (socp_fr/cp_eqcarry stale values from the first solve into the second solve's guards) and checks the result matches a fresh solve — directly exercising the guard logic touched by this change.Compatibility / Numerical behavior
Same summation, same order, bitwise-identical result by construction — this only removes a redundant recomputation, it does not change what gets computed or in what order.
Drafted with Claude's assistance
EqPartials_compute_partialsandEqSolver_post_process, checking nothing mutatessoln%thermo%cp/soln%njbetween the duplicate calls (per the linked issue).post_processguard refactor preserves real-world skip behavior by instrumenting the guard with a debug print, rebuilding, and tracing actualneed_cp_fr/need_cp_eqvalues through a reused-EqSolutionscenario before removing the instrumentation.