Skip to content

Bump twine to 0.6 and use solve_from_bracket#71

Merged
dyreby merged 1 commit into
mainfrom
feat/bump-twine-0.6
Mar 4, 2026
Merged

Bump twine to 0.6 and use solve_from_bracket#71
dyreby merged 1 commit into
mainfrom
feat/bump-twine-0.6

Conversation

@dyreby

@dyreby dyreby commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Bump twine dependencies to 0.6 and take advantage of the new solve_from_bracket API to simplify the discretized UA solver.

Two hardcoded tolerance constants are removed:

  • INLET_PROXIMITY_THRESHOLD_K — distinguished FP noise from real second-law violations near the bracket boundary
  • ENTHALPY_RELATIVE_ZERO — snapped tiny enthalpy differences to zero in the forward solver

Both were workarounds for edge cases at T_out == T_in. With solve_from_bracket, the bracket signs are known from physics — no endpoint evaluation needed — and the observer only sees midpoints where these edge cases don't arise.

@dyreby dyreby force-pushed the feat/bump-twine-0.6 branch 2 times, most recently from 36fd7d2 to c1e0c6c Compare March 4, 2026 16:34
@dyreby dyreby requested a review from gdtroszak March 4, 2026 17:21
GivenUaError::EqualInletTemperatures => Self::Convergence {
message: "equal inlet temperatures: positive UA requires a temperature difference"
.to_owned(),
iterations: None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EqualInletTemperatures maps to Convergence, but it's a precondition violation like NegativeUa, not a convergence failure. Was this intentional to avoid a breaking change to RecuperatorGivenUaError, or worth a dedicated variant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — wasn't intentional, just avoiding the variant addition without thinking it through. Added a dedicated EqualInletTemperatures variant to RecuperatorGivenUaError and mapped directly to it. It's a precondition violation like NegativeUa, not a convergence failure.

Also corrected the doc comments — the original framing claimed no heat transfer is possible with equal inlet temperatures, but that's only true for perfect gases. With real fluids and pressure drop (Joule-Thomson effect), temperature gradients can develop along the exchanger even from equal inlets. The actual constraint is that the bisection bracket collapses to zero width.

Commit: cfdeaf0

// Any second-law violation during midpoint iteration is a
// genuine overshoot — the candidate outlet temperature
// exceeds physical limits, so UA is overestimated.
if matches!(event, bisection::Event::ModelFailed { .. }) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old handler specifically matched SolveError::SecondLawViolation. This catches any ModelFailed — if the inner solve can fail for other reasons (thermo backend error, etc.), those now silently become assume_positive instead of propagating. Is that intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not intentional — the old code matched specifically and I lost that precision in the refactor. Now matches only SolveError::SecondLawViolation { .. } inside the ModelFailed event. Other model errors (thermo backend failures, etc.) return None from the observer and propagate as solver failures.

Commit: cfdeaf0

@dyreby dyreby force-pushed the feat/bump-twine-0.6 branch from c1e0c6c to beea6b5 Compare March 4, 2026 17:58
Bump twine-core, twine-solvers, and twine-observers to 0.6.

Refactor the given_ua solver to build the bracket from known physics
rather than evaluating endpoints. At T_out = T_top_in, UA is zero
(negative residual); at T_out = T_bottom_in, UA is infinite (positive
residual). This eliminates both INLET_PROXIMITY_THRESHOLD_K and
ENTHALPY_RELATIVE_ZERO — hardcoded tolerances that papered over
edge cases the caller should control.

The observer now only sees midpoints via solve_from_bracket, where
any second-law violation is a genuine overshoot.
@dyreby dyreby force-pushed the feat/bump-twine-0.6 branch from beea6b5 to cfdeaf0 Compare March 4, 2026 18:00
@dyreby dyreby merged commit ba8405c into main Mar 4, 2026
1 check passed
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.

2 participants