7.2 KiB
Story 5.5: Swappable Calibration Variables (Inverse Calibration One-Shot)
Status: done
Story
As a R&D engineer calibrating a machine model against test bench data, I want to swap calibration coefficients (f_m, f_ua, f_power, etc.) into unknowns and measured values (Tsat, capacity, power) into constraints, so that the solver directly computes the calibration coefficients in one shot without an external optimizer.
Acceptance Criteria
-
Condenser Calibration
- Given a Condenser with
f_uaas a calibration factor - When I enable calibration mode and fix
Tsat_condto a measured value - Then
f_uabecomes an unknown in the solver state vector - And a residual is added:
Tsat_cond_computed - Tsat_cond_measured = 0 - And the solver computes
f_uadirectly
- Given a Condenser with
-
Evaporator Calibration
- Given an Evaporator with
f_uaas a calibration factor - When I enable calibration mode and fix
Tsat_evapto a measured value - Then same swap mechanism:
f_ua→ unknown,Tsat_evap→ constraint
- Given an Evaporator with
-
Compressor Power Calibration
- Given a Compressor with
f_poweras a calibration factor - When I enable calibration mode and fix Power to a measured value
- Then
f_powerbecomes an unknown - And residual:
Power_computed - Power_measured = 0
- Given a Compressor with
-
Compressor Mass Flow Calibration
- Given a Compressor with
f_mas a calibration factor - When I enable calibration mode and fix mass flow
ṁto a measured value - Then
f_mbecomes an unknown - And residual:
ṁ_computed - ṁ_measured = 0
- Given a Compressor with
-
System Specific Modes
- Given a machine in cooling mode calibration, when I impose evaporator cooling capacity
Q_evap_measured, thenQ_evapbecomes a constraint (Q_evap_computed - Q_evap_measured = 0) and correspondingf_(typicallyf_uaon evaporator) becomes an unknown. - Given a machine in heating mode calibration, when I impose condenser heating capacity
Q_cond_measured, thenQ_condbecomes a constraint and correspondingf_(typicallyf_uaon condenser) becomes an unknown.
- Given a machine in cooling mode calibration, when I impose evaporator cooling capacity
Tasks / Subtasks
- Extend
Componentimplementations to respectf_calibration variables- Update
Compressorto applyf_m(mass flow) andf_power(power) factors if provided. - Update Heat Exchangers (
Condenser,Evaporator) to applyf_ua(heat transfer) factor if provided. - Update Pipes/Valves for
f_morf_dpwhere applicable.
- Update
- Connect
BoundedVariableforf_factors- Use
BoundedVariableto representf_m,f_ua, etc. in theSystemstate as control variables with min/max bounds (e.g., 0.5 to 2.0). - Allow components to extract their current calibration factors from the
SystemStateduringcompute_residuals.
- Use
- Inverse Control Constraint Setup
- Add ability to cleanly formulate targets like
Target Capacity,Target Power,Target Tsat. - Test the solver for MIMO (Multi-Input Multi-Output) with these new variables mapping to these targets.
- Add ability to cleanly formulate targets like
- Write integration test for Swappable Calibration
- Create a test with fixed component geometries, imposing a known capacity and power.
- Check if the solver successfully converges to the required
f_uaandf_powerto match those targets.
Dev Notes
Architecture Context
This is Story 5.5 in Epic 5: Inverse Control & Optimization. It leverages the MIMO capability built in Story 5.4. Instead of traditional controls like Valve Opening targeting Superheat, this story treats the actual physical calibration parameters (like UA multiplier, mass flow multiplier) as the "Control Variables" and the test bench measurements (Capacity, Power) as the "Constraints".
Critical Numerical Challenge:
The components must read from the solver's expanded SystemState (control vector section) to obtain their f_ multipliers instead of using hardcoded internal struct fields. If the multiplier is NOT part of the inverse control problem (regular forward simulation), it should default to 1.0.
Technical Stack Requirements:
- Rust (edition 2021) with
#![deny(warnings)] nalgebrafor linear algebrathiserrorfor error handlingtracingfor structured logging
Component → Calibration Factor Mapping:
| Component | f_ Factors | Measurable Values (Constraints) |
|---|---|---|
| Condenser | f_ua, f_dp | Tsat_cond, Q_cond (capacity), ΔP_cond |
| Evaporator | f_ua, f_dp | Tsat_evap, Q_evap (capacity), ΔP_evap |
| Compressor | f_m, f_power, f_etav | ṁ, Power, η_v |
| Expansion Valve | f_m | ṁ |
| Pipe | f_dp | ΔP |
Previous Story Intelligence
From Story 5.4 (Multi-Variable Control):
- MIMO Jacobian calculation using cross-derivatives is fully working and tested.
extract_constraint_values_with_controls()accurately maps primary and secondary effects via component IDs usingBoundedVariable::with_component().- Use
BoundedVariable::with_component()to properly associate the calibration factor with the component so that the Jacobian builder can calculate perturbations accurately.
Technical Requirements
Critical Implementation Details:
- State Extraction in Components:
Components like
Condensermust query theSystemStatefor their specificBoundedVariable(likef_ua) duringcompute_residuals. If present, multiply the nominal UA byf_ua. If not, assume1.0. - Bounds definition:
Calibration factors should be bounded to physically meaningful ranges (e.g.
f_uabetween 0.1 and 10.0) to prevent the solver from taking unphysical steps or diverging. - MIMO Stability:
Because swapping
f_mandf_powersimultaneously affects both mass flow and power, the Newton-Raphson solver will rely entirely on the cross-derivatives implemented in Story 5.4. Ensure that the component IDs strictly match between the constraint output extraction and the bounded variable.
Anti-Patterns to Avoid:
- ❌ DON'T force components to store stateful
f_values locally that drift out of sync with the solver. Always compute dynamically from the solver state. - ❌ DON'T use exact
1.0equality checks. Since these are floats, if not using a control variable, passNone. - ❌ DON'T use
unwrap()orexpect().
Project Structure Notes
- Changes isolated to
crates/components/src/(modifying components to respectf_factors) - May need minor additions to
crates/solver/src/system.rsto allow components to extract their mapped controls. - Integration tests go in
crates/solver/tests/inverse_calibration.rs.
References
- [Source:
epics.mdStory 5.5] Swappable Calibration Variables acceptance criteria. - [Source:
5-4-multi-variable-control.md] Multi-Variable MIMO Jacobian and component-id linking logic. - [Source:
architecture.md#Inverse-Control] Architecture decisions for one-shot inverse solving.
Dev Agent Record
Agent Model Used
z-ai/glm-5:free (Antigravity proxy)
Debug Log References
Completion Notes List
File List
crates/components/src/expansion_valve.rscrates/components/src/compressor.rscrates/components/src/heat_exchanger/exchanger.rscrates/solver/tests/inverse_calibration.rs