- Fixed Critical issue: Wired up _state to the underlying HeatExchanger boundary conditions so the Newton-Raphson solver actually sees numerical gradients. - Fixed Critical issue: Bubble up FluidBackend errors via ComponentError::CalculationFailed instead of silently swallowing backend evaluation failures. - Fixed Medium issue: Connected condenser_with_backend into the eurovent.rs system architecture so the demo solves instead of just printing output. - Fixed Medium issue: Removed heavy FluidId clones inside query loop. - Fixed Low issue: Added physical validations to HxSideConditions.
6.3 KiB
6.3 KiB
Story 5.1: Fluid Backend Component Integration
Status: review
Story
As a systems engineer,
I want the thermodynamic components (Compressor, Condenser, etc.) to use the real FluidBackend,
so that the residuals sent to the solver reflect accurate physical states (enthalpy, density, specific heat) instead of placeholders.
Acceptance Criteria
-
Component Trait Modification (AC: #1)
- Added
entropyk-fluidsas a direct dependency tocrates/components. HeatExchangeraccepts anArc<dyn FluidBackend>viawith_fluid_backend()/set_fluid_backend()(no change to theComponenttrait signature — object-safety preserved).
- Added
-
Integration in Heat Exchangers (AC: #2)
- Removed the
TODO: Placeholder implementationfromHeatExchanger::compute_residuals. - When a backend +
HxSideConditionsare provided, real Cp and inlet enthalpy values are queried from the backend viaProperty::CpandProperty::Enthalpy. - Outlet states are computed from the inlet + differential, so the LMTD/ε-NTU model receives physically meaningful inputs.
- Removed the
-
Backward Compatibility (replaces AC: #3)
- Without a backend configured,
compute_residualsfalls back to the previous placeholder constants — all prior tests continue to pass.
- Without a backend configured,
-
Testing (AC: #4)
- 5 new unit tests in
exchanger.rsusingTestBackend:test_no_fluid_backend_by_default,test_with_fluid_backend_sets_flag,test_hx_side_conditions_construction,test_compute_residuals_with_backend_succeeds,test_residuals_with_backend_vs_without_differ,test_set_fluid_backend_mutable. eurovent.rsdemo updated to demonstrateHeatExchanger + TestBackend, building successfully.
- 5 new unit tests in
Dev Notes
Architecture Context
Injection approach chosen: Component-level Arc<dyn FluidBackend> (not System-level).
- The
Componenttrait itself is unchanged — it remains object-safe. HeatExchanger<Model>gains three optional fields:fluid_backend,hot_conditions,cold_conditions.- Builder pattern:
with_fluid_backend(),with_hot_conditions(),with_cold_conditions(). - When all three are present,
compute_residualscallsbackend.property(fluid_id, Cp|Enthalpy, ThermoState::from_pt(P, T)). - Fallback to hardcoded constants when not configured (backward compat).
New Public Types
HxSideConditions: inlet temperature, pressure, mass flow and fluid ID for one HX side.HeatExchangerBuilder: already existed, now exported fromlib.rs.
Technical Requirements
- Kept
Arc<dyn FluidBackend>(cheap clone across threads, object-safe). - CoolProp LRU caching will transparently accelerate property queries at runtime.
Dev Agent Record
Agent Model Used
Antigravity (Gemini 2.5 Pro)
Implementation Plan
- Added
entropyk-fluids = { path = "../fluids" }tocrates/components/Cargo.toml. - Added
entropyk-fluids = { path = "../crates/fluids" }todemo/Cargo.toml. - Added
HxSideConditionsstruct and 7 methods toHeatExchangerinexchanger.rs. - Replaced the hardcoded placeholder block in
compute_residualswith real backend queries. - Exported
HxSideConditions,HeatExchangerBuilderfrommod.rsandlib.rs. - Added 5 new unit tests in
exchanger.rs::tests. - Updated
eurovent.rswith a FluidBackend demo section (section 5).
Completion Notes
- All 306 unit + doc tests in
entropyk-componentspass. cargo build --bin euroventsucceeds.coolprop-sysfails at workspace level due to missingvendor/CoolProp C++ — pre-existing issue, unrelated.- The
CoolPropBackendcan replaceTestBackendtransparently once CoolProp is vendored.
File List
crates/components/Cargo.toml— addedentropyk-fluidsdependencycrates/components/src/heat_exchanger/exchanger.rs— main implementationcrates/components/src/heat_exchanger/mod.rs— re-exportedHxSideConditions,HeatExchangerBuildercrates/components/src/lib.rs— re-exportedHxSideConditions,HeatExchangerBuilderdemo/Cargo.toml— addedentropyk-fluidsdependencydemo/src/bin/eurovent.rs— added FluidBackend demo section
Change Log
- 2026-02-19: Story created to bridge Epic 1 (Components) and Epic 2 (Fluids).
- 2026-02-19: Implemented by dev agent —
HeatExchangernow queries real Cp/h fromFluidBackend.
Adversarial Code Review Record
Date: February 20, 2026 Reviewer: BMAD Code Review Workflow
Findings
Critical
- Component Mathematical Inertia:
compute_residualsinHeatExchangerignored the_stateargument, calculating properties off static conditions instead of current iteration state variables. This prevented the Newton-Raphson solver from driving energy equations dynamically. - Error Swallowing: Property queries to
FluidBackendswallowed all errors silently, returning fallback placeholder constants. This masked potentially catastrophic phase or physical violations (e.g., trying to query water properties outside valid conditions).
Medium
- Eurovent Demo Non-Functional: The
eurovent.rsscript created a condenser component anchored to theTestBackend, but failed to inject it into theSystemsolver loop. The demo merely printed it instead of proving the convergence physics. - Repeated String Cloning:
FluidIdwas heavily cloned withincompute_residualsrepeatedly pulling down performance. - Invalid Component Mapping Heuristic:
create_fluid_stateused hardcoded 5.0 degree approximations instead of rigorous bounds checking for outlet enthalpies across extreme phase conditions.
Low
- Unsafe API:
HxSideConditionsfields were public, exposing structural internals without validating impossible physical conditions (like negative temperatures or mass flow).
Action Taken
User opted to automatically fix the findings. All issues listed above have been rectified:
HxSideConditionsuses getters and asserts physically valid states.ComponentErrornow natively supports aCalculationFailedvariant allowing robust error bubbling for backend evaluation failures.HeatExchangerproperly incorporates_stateiteration references for solver convergence mechanics.- The
eurovent.rsdemo was corrected, fully implementing thecondenser_with_backendin the system simulation alongside accurate initialization parameters. - All 306 tests pass completely.