Skip to content

Bug/deton unconverged#47

Merged
markleader merged 4 commits intonasa:mainfrom
markleader:bug/deton-unconverged
Feb 27, 2026
Merged

Bug/deton unconverged#47
markleader merged 4 commits intonasa:mainfrom
markleader:bug/deton-unconverged

Conversation

@markleader
Copy link
Copy Markdown
Contributor

@markleader markleader commented Feb 26, 2026

Summary

Fix Issue #42 by resetting transient equilibrium Newton state on each EqSolver_solve call so reusing an EqSolution does not carry stale iteration history into the next solve.

This addresses history-dependent non-convergence observed in:

  • HP → TP reuse flow (O2/C2H4 case)
  • Reused TP sequences with condensed phases (Air/C2H4/AL case)

In addition, this PR now hardens the non-converged recovery path so failed/singular solves do not poison subsequent solves:

  • EqSolution now stores a last-stable warm-start snapshot
  • If the previous solve was non-converged, the next solve restores that stable snapshot before iterating
  • Expected non-converged solver paths return converged=.false. (instead of abort) so sweeps can continue

Changes

  • Core solver robustness:

    • Added EqSolution_reset_iteration_state(soln) in source/equilibrium.f90
    • Called it at the start of EqSolver_solve (after constraints setup, before matrix/phase iteration)
  • Reset scope is intentionally surgical (transient fields only):

    • dln_nj(:), dnj_c(:), dln_n, dln_T, dpi_e
    • convergence flags (gas_converged, condensed_converged, moles_converged, element_converged, temperature_converged, entropy_converged, pi_converged, ions_converged, converged)
    • does not reset warm-start state (T, nj, ln_nj, active condensed set, pi, pi_prev)
  • Additional core recovery/state lifecycle updates in source/equilibrium.f90:

    • Added last-stable warm-start snapshot fields on EqSolution:
      • T_seed, n_seed
      • nj_seed(:), ln_nj_seed(:)
      • is_active_seed(:), active_rank_seed(:)
      • j_sol_seed, j_liq_seed, j_switch_seed, last_cond_idx_seed
    • Added helper routines:
      • EqSolution_save_seed(soln)
      • EqSolution_restore_seed(soln)
    • Initialized snapshot state in EqSolution_init
    • Updated EqSolver_solve entry logic:
      • if prior solve did not converge, restore last stable snapshot before starting new solve
    • Snapshot updates are success-only:
      • save seed only when solve exits converged
    • Normalized expected non-converged exits in EqSolver_solve:
      • too many singular matrices
      • failure to establish condensed species set
      • maximum iterations reached without convergence
      • now return with soln%converged=.false. (and restore reduced elements) rather than aborting
  • New core regressions in source/equilibrium_test.pf:

    • test_issue42_reuse_solution_hp_then_tp
    • test_issue42_reuse_solution_condensed_tp_grid
    • test_reuse_solution_recovers_after_nonconverged_point
  • New Python regressions in source/bind/python/tests/test_issue42_solver_history.py:

    • test_issue42_detonation_no_inner_eq_failure
    • test_issue42_reused_eqsolution_matches_fresh

Testing

  • Ran:
    • ctest -R cea_core_test -V
    • python test_main.py
    • python -m pytest
    • .py files attached to the issue

Compatibility / Numerical behavior

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

Expected behavior change is limited to solver robustness when reusing EqSolution objects across solves:

  • Previously history-dependent non-convergence cases now converge in core regression tests.
  • Reuse-vs-fresh solutions agree within tight tolerances in new tests.
  • Non-converged expected sweep points now return converged=.false. instead of aborting the process.
  • Subsequent solves after a failed point are seeded from the last stable converged snapshot, not the failed iterate.
  • No API/signature changes in Fortran/C/Python interfaces.

@markleader markleader merged commit 602ab5e into nasa:main Feb 27, 2026
21 checks passed
@markleader markleader deleted the bug/deton-unconverged branch February 27, 2026 18:16
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.

[bug] Equilibrium solver doesn't converge for detonation; CEA2 converges

1 participant