fix(svdsbtl): skip patch polish for two-phase points#2949
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds phase-aware guards to skip forward-h polishing when the patch source is two-phase, and sets a patched point's phase from patch_source->phase() (with try/catch) instead of leaving it as not-imposed. ChangesTwo-phase critical-patch polishing guards & phase propagation
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/Backends/SVDSBTL/SVDSBTLBackend.cpp`:
- Around line 541-546: The patched branch preserves a genuine two-phase patch in
patch_source_ but update() fails to propagate that into the internal _phase,
leaving _phase as iphase_not_imposed; inside the PointEvaluation::Kind::Patched
handling (where only iQ is copied currently) update the code to also copy
patch_source_->phase() into _phase (and any other phase-tracking members used by
state.phase()), so that state.phase() matches the preserved patch_source_ phase
after polish_patch_state_ and in the subsequent logic that relies on _phase.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b97efb04-709e-4b02-8d06-77747fb1ddbf
📒 Files selected for processing (2)
.beads/issues.jsonlsrc/Backends/SVDSBTL/SVDSBTLBackend.cpp
…aries Two combined effects vs the previous plot: - SA-backed sat boundary curves replace the 64-knot cubic spline in the atlas, so liquid-side error drops by ~100x for R245fa and ~3000x for Water (median rho rel-err 5.33e-12 vs old 1.61e-08). - The patch-polish bug fix (PR #2949) restores correctness for the previously-missing wedge of two-phase points inside the critical patch bbox -- those cells now blend correctly through HEOS PQ instead of returning rho=-inf via the corrupted polish state. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Follow-up to the polish-skip-for-twophase fix: the Kind::Patched branch in update() was copying iQ from patch_source_ but leaving _phase as iphase_not_imposed. For genuine two-phase patched states (which the skip-polish path now correctly preserves) that meant state.phase() disagreed with the source — rho / Q were correct but the caller saw iphase_not_imposed instead of iphase_twophase, surfacing as e.g. phase=8 (sc_liq) on R245fa near-critical dome probes. Read patch_source_->phase() and write it into _phase alongside the iQ copy. Defensive try/catch around the phase read mirrors the existing iQ pattern in case a source backend doesn't always report a phase value. Resolves CodeRabbit's review comment on PR #2949 — without this follow-up the polish skip is correct for rho/T/Q but the phase remains stale. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
polish_patch_state_ assumes a single-phase solution exists at h(T, p) = h_target on a tight T bracket around T_seed. Inside the saturation dome h(T, p) is multi-valued (jumps from h_L to h_V across T = T_sat), so the bracket [T_seed-0.5, T_seed+0.5] straddles the dome and resid changes sign without any single-phase root in the range. TOMS748 silently converges to a nonsense T and the returned state classifies as supercritical_liquid with rho / Q = ±inf. Skip the polish entirely when the patched state is iphase_twophase — two-phase points coming out of the patch already have correct (T_sat, Q, rho) from the source's PQ-blend; the forward-h polish was only designed for the ±25 mK backward-equation residual of IF97's single-phase formulations. Reproducer (R245fa, before the fix): h=450.7e3 J/kg, p=2.89e6 Pa (Q=0.5 dome point inside auto-cal patch bbox) → rho=-inf, phase=supercritical_liquid, Q=-inf HEOS: rho=346.65 After: rho=346.65 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Follow-up to the polish-skip-for-twophase fix: the Kind::Patched branch in update() was copying iQ from patch_source_ but leaving _phase as iphase_not_imposed. For genuine two-phase patched states (which the skip-polish path now correctly preserves) that meant state.phase() disagreed with the source — rho / Q were correct but the caller saw iphase_not_imposed instead of iphase_twophase, surfacing as e.g. phase=8 (sc_liq) on R245fa near-critical dome probes. Read patch_source_->phase() and write it into _phase alongside the iQ copy. Defensive try/catch around the phase read mirrors the existing iQ pattern in case a source backend doesn't always report a phase value. Resolves CodeRabbit's review comment on PR #2949 — without this follow-up the polish skip is correct for rho/T/Q but the phase remains stale. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ae72c74 to
ef6fb1a
Compare
…aries Two combined effects vs the previous plot: - SA-backed sat boundary curves replace the 64-knot cubic spline in the atlas, so liquid-side error drops by ~100x for R245fa and ~3000x for Water (median rho rel-err 5.33e-12 vs old 1.61e-08). - The patch-polish bug fix (PR #2949) restores correctness for the previously-missing wedge of two-phase points inside the critical patch bbox -- those cells now blend correctly through HEOS PQ instead of returning rho=-inf via the corrupted polish state. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
polish_patch_state_runs a forward-h TOMS748 polish on every HmassP / HmolarP probe that lands inside the critical-patch bbox, on the assumption that a single-phase solution exists ath(T, p) = h_targeton a tight T bracket aroundT_seed. Inside the saturation domeh(T, p)is multi-valued (it jumps fromh_Ltoh_VacrossT = T_sat), so the bracket[T_seed-0.5, T_seed+0.5]straddles the dome and resid changes sign without any single-phase root in the range. TOMS748 silently converges to a nonsense T, and the returned state classifies as supercritical_liquid withrho/Q= ±inf.The auto-calibrated patch bbox for non-water fluids whose critical region overlaps a wide h-range (R245fa, R134a, …) has its HmassP envelope straddle the saturation dome by construction, so any two-phase probe inside the patch hits the failure mode.
This skips the polish entirely when the patched state is
iphase_twophase— two-phase points coming out of the patch already have correct(T_sat, Q, rho)from the source's PQ-blend; the forward-h polish was only designed for the ±25 mK backward-equation residual of IF97's single-phase formulations.Reproducer (R245fa, before the fix):
After the fix all 6 sweep probes (T = 0.96 … 0.999 · Tc, Q = 0.5) match HEOS within ~1e-14.
Test plan
CatchTestRunner "[SVDSBTL]"— 40 passed / 6 skipped / 0 failed🤖 Generated with Claude Code
Summary by CodeRabbit