Skip to content

added LAST_VALID_SOLUTION convergence enum#77

Merged
markleader merged 2 commits into
nasa:mainfrom
markleader:fix/last_valid_solution
May 12, 2026
Merged

added LAST_VALID_SOLUTION convergence enum#77
markleader merged 2 commits into
nasa:mainfrom
markleader:fix/last_valid_solution

Conversation

@markleader
Copy link
Copy Markdown
Contributor

Summary

Add a new soft-failure status, CEA_LAST_VALID_SOLUTION, for the incident-equilibrium shock recovery path when CEA retains a last valid incident state without converging the shock iteration. Closes #76.

Motivation:

  • Preserve the meaning of solution.converged == false for strict shock non-convergence
  • Make the C/Python API distinguish between a hard non-converged failure and a retained last-valid shock state
  • Avoid incorrectly signaling full success for fallback shock states

Impacted components:

  • Fortran shock solver internals
  • C binding error/status mapping
  • Python binding warning/error handling
  • C/Python docs and regression tests

Changes

  • Added shared error code CEA_LAST_VALID_SOLUTION to the C API enum surface
  • Added a private internal shock solve status on ShockSolution to distinguish:
    • converged shock solve
    • hard non-converged failure
    • retained last-valid incident-equilibrium state
  • Kept ShockSolution%converged semantics unchanged:
    • true still means the shock iteration converged
    • retained last-valid states still report false
  • Updated cea_shock_solver_solve to return:
    • CEA_SUCCESS for converged shock solves
    • CEA_LAST_VALID_SOLUTION for retained incident last-valid states
    • CEA_NOT_CONVERGED for other non-converged shock outcomes
  • Updated the Python binding to:
    • expose LAST_VALID_SOLUTION
    • emit a RuntimeWarning for this soft-failure code
    • keep soln.last_error interpretable without changing soln.converged
  • Added comments/docs clarifying that a last-valid retained state is not a converged shock point
  • Added regressions for:
    • internal shock status behavior
    • direct C API return-code behavior
    • Python warning + last_error behavior

Testing

  • Ran ctest -R cea_core_test -V
  • Ran Python binding tests against the freshly built extension from build-dev:
    • source/bind/python/tests -> 51 passed

Compatibility / Numerical behavior

  • No expected changes to numerical results
  • Expected changes (explain and provide validation)

Expected behavior changes:

  • C shock callers can now distinguish retained last-valid incident states from hard CEA_NOT_CONVERGED failures.
  • Python now warns with LAST_VALID_SOLUTION for this specific soft-failure path while keeping solution.converged == false.
  • For retained last-valid incident states, the incident pressure array entry is now restored consistently with the retained shock ratios instead of being left stale/zero.

Validation:

  • Added a direct C regression covering CEA_LAST_VALID_SOLUTION
  • Added a Python regression asserting warning text, last_error, and converged == false
  • Added a Fortran regression asserting the internal retained-state status remains non-converged

@markleader markleader merged commit 89f0842 into nasa:main May 12, 2026
23 checks passed
@markleader markleader deleted the fix/last_valid_solution branch May 12, 2026 13:26
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.

Incident equilibrium shock can return CEA_NOT_CONVERGED while retaining a usable “last valid” solution

2 participants