Repository navigation
Conversation
guess_nonlinear compared each new guess with _ps_guess_cache, a Python attribute, so restoring a model's vectors (load_case or a vector copy) did not determine the next solve (OpenMDAO#125). Area mode now re-seeds Ps when |resid['Ps']| >= 1e-2, which OpenMDAO recomputes just before guess_nonlinear. MN mode seeds only while Ps still holds its initial value: the stateless form of the old first-call check. A residual gate in MN mode was rejected because re-seeding Ps with a stale T fails the Mach 2 CEA static test. Converged results move only at solver tolerance. In the high-bypass turbofan example's envelope sweep, six OD_full_pwr solves that stock left stuck with the inlet exit Ps at its lower bound now converge.
Code ReviewChanges requested. The area-mode gate introduces a cold-start convergence regression.
On |
The area-mode residual gate skipped the seed whenever |resid['Ps']| was below 1e-2, including on a cold start. There, Ps is still at its initial 0.001 bar but the enthalpy residual can happen to be small (-8.1e-5 for a tabulated static_A at 10 bar, 1000 K, 1 kg/s, 0.00082 m^2), and Newton then stalls at the lower pressure bound. Area mode now seeds on the same cold-start check MN mode uses, and still uses the residual gate after that.
The restored-state test only reused the solved model, so it could not catch an MN-mode seed that overwrites a restored Ps on a model's first solve. Move test_statics' setup into _setup_statics() and also restore the saved vectors into a new problem. That check alone fails on master (42 of 111 outputs differ).
Code review responseAgreed on both findings. The area-mode gate needed the same cold-start seed as MN mode, and the restore test now also restores into a freshly built
Kept as-is: nothing from this review.
Tests: |
Code re-review at
|
Summary
PsResid.guess_nonlineardecided whether to re-seedPsby comparing the new guess withself._ps_guess_cache, a Python attribute outside OpenMDAO's vectors. Restoring a model's state (load_caseor a vector copy) therefore didn't determine the next solve (#125). This PR removes the attribute and makes the decision from the vectors:areamode: re-seedPswhen|resid['Ps']| >= 1e-2, so a nearly convergedPsis kept as the starting point, which is what the cache was for. This is the same gate and threshold OpenMDAO'sguess_nonlineardocs example uses. OpenMDAO recomputes the residual withapply_nonlinearright beforeguess_nonlinear, from whatever inputs are available at that point. On a cold start those can still be initial thermo values, so the residual can look small.Psis therefore also seeded whenever it still holds its initial value.MNmode: seedPsonly while it still holds its initial value. That's the cold-start condition the old first-call check stood in for. A residual gate here was tried and rejected: it failsTestStaticJanaf.test_case_MNcase 5 (MN 2.0), because re-seedingPswhileTis still from the previous case sends that Newton astray. (Stock fails that case too when it's solved cold.)Of the options in #125, this is (b). Before choosing it I tried (a) "always re-seed in
areamode", which is what an opt-out flag would turn on. It restores history independence within one model, but not after loading a case into a fresh model, because of the MN first-call seed. It also costs 20–45% more inner Newton iterations. Option (c), a reset hook, only helps callers who know to use it.Related Issues
PsResidkeeps its guess cache outside OpenMDAO's vectors, soload_casedoesn't reproduce off-design solves #125Backwards incompatibilities
PsResid._ps_guess_cacheno longer exists. Code that saved and restored it as a workaround forPsResidkeeps its guess cache outside OpenMDAO's vectors, soload_casedoesn't reproduce off-design solves #125 can drop it, since restoring the vectors is now enough.MNmode, aPsset by the user before the first solve is no longer overwritten by the guess.New Dependencies
None
Proof of behavior
Restored state reproduces the solve. For each example's OD point: solve condition A and record the case, then compare three re-solves of A. The baseline is
load_case(A)with nothing run in between. Same model solves another condition B first, thenload_case(A). Fresh model builds a newProblemand callsload_case(A).mixedflow_turbofan.pysimple_turbojet.pyConvergence on the examples' own off-design sweeps (same sequence before and after; "inner" counts every
ThermoNewton iteration):high_bypass_turbofan.py__main__envelope (21 conditions × 6 throttle steps × 2 points)mixedflow_turbofan.pyOD (5 altitude/Mach × 5 T4)simple_turbojet.pyOD1 (3 altitude/Mach × 5 Fn)The six stock failures are
OD_full_pwrat M0.55 / 35 kft. There,inlet.out_stat.ps_resid.Pssits at its lower bound (1e-4 bar) with a residual of 3.3e5 on every re-solve, because the guess at that condition never changes and so the cache never lets it re-seed. With the residual gate it re-seeds and converges.Tests:
test_statics_restored_staterestores the vectors into the same model and into a freshly built one. It fails onmaster(22 and 42 of 111 outputs differ) and passes with this change.test_static_area_cold_startcovers an area-mode static whose cold-start residual is small. Without the cold-start seed, Newton stalls at thePslower bound.testflo pycycle example_cyclespasses 69/69, andtestflo -b example_cycles(the golden-value benchmarks inexample_cycles/tests/andexample_cycles/N+3ref/) passes 13 with 1 skipped, the same as onmaster.Environment: OpenMDAO 3.39.0, NumPy 2.0.2, SciPy 1.13.1, Python 3.9.6, macOS.