Skip to content

Fix recuperator bisection bracket failure on wasm#64

Merged
dyreby merged 2 commits into
mainfrom
fix/recuperator-wasm-bracket
Mar 3, 2026
Merged

Fix recuperator bisection bracket failure on wasm#64
dyreby merged 2 commits into
mainfrom
fix/recuperator-wasm-bracket

Conversation

@dyreby

@dyreby dyreby commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

What

Fixes the recuperator "invalid bracket: no sign change" error on wasm targets with segments > 1.

On wasm (strict IEEE 754, no x86 extended precision), CoolProp's enthalpy round-trip noise at the lower bracket boundary (t_out = t_in) can exceed the ENTHALPY_RELATIVE_ZERO threshold from #59. When the noise produces a spurious wrong-direction heat flow, the resolve step emits a SecondLawViolation. The event handler was mapping all such violations to assume_positive — correct for genuine overshoots mid-iteration, but wrong at the zero-heat-transfer boundary where UA ≈ 0 and the residual should be negative. Both endpoints end up positive → bracket rejected.

How

The event handler now checks whether the candidate t_out is near t_top_in (within 1e-9 K). Near the inlet, a SecondLawViolation is FP noise → assume_negative. Farther away, it's a real overshoot → assume_positive.

The ENTHALPY_RELATIVE_ZERO threshold is unchanged — it's still the first line of defense in the resolve step. The event handler is the fallback for when the thermo backend's noise exceeds it.

Closes #63

The bisection event handler mapped all SecondLawViolation errors to
assume_positive. On wasm, CoolProp enthalpy round-trip noise at the
lower bracket endpoint (t_out = t_in) can exceed the ENTHALPY_RELATIVE_ZERO
threshold and produce a spurious wrong-direction heat flow. The handler
then made both bracket endpoints positive, causing 'no sign change'.

Now the handler checks whether t_out is near t_top_in. Near the inlet,
the violation is FP noise (UA ≈ 0, negative residual). Farther away,
it's a genuine overshoot (positive residual).

Closes #63
@dyreby dyreby requested a review from gdtroszak March 3, 2026 20:55
@dyreby dyreby merged commit 99f2a21 into main Mar 3, 2026
1 check passed
@dyreby dyreby mentioned this pull request Mar 3, 2026
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.

Recuperator bisection fails on wasm with segments > 1

2 participants