Skip to content

Dedupe redundant cp dot_product in EqSolver post-processing - #148

Open
djkees wants to merge 1 commit into
nasa:mainfrom
djkees:up/dedupe-cp-dot-product
Open

djkees wants to merge 1 commit into
nasa:mainfrom
djkees:up/dedupe-cp-dot-product

Conversation

@djkees

@djkees djkees commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the duplicate dot_product(soln%thermo%cp, soln%nj) calls in source/equilibrium.f90 identified 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 local cp_dot_nj and reuses it for self%cp_eq and soln%cp_fr.
  • EqSolver_post_process: the two guarded assignments (cp_fr < 1e-10, and cp_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, since compute_partials already sets both fields before post_process runs whenever partials/transport are requested. Instead, both guards are evaluated into need_cp_fr/need_cp_eq locals, 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 .out files across equilibrium, rocket, shock, and detonation examples).

Added test_reused_eqsolution_cp_matches_fresh to source/bind/python/tests/test_reuse_solution.py, following the existing test_issue42_reused_eqsolution_matches_fresh pattern: it solves into a reused EqSolution twice (so cp_fr/cp_eq carry 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

  • No expected changes to numerical results

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

  • Both duplicate-computation sites were confirmed by direct read of EqPartials_compute_partials and EqSolver_post_process, checking nothing mutates soln%thermo%cp/soln%nj between the duplicate calls (per the linked issue).
  • Verified the post_process guard refactor preserves real-world skip behavior by instrumenting the guard with a debug print, rebuilding, and tracing actual need_cp_fr/need_cp_eq values through a reused-EqSolution scenario before removing the instrumentation.
  • Full local build + test suite rerun (Fortran ctest, Python pytest, and the legacy CLI byte-comparison suite) confirmed identical results before and after the change, as detailed in Testing above.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant