feat: implement mass balance validation for Story 7.1

- Added port_mass_flows to Component trait and implements for core components.
- Added System::check_mass_balance and integrated it into the solver.
- Restored connect methods for ExpansionValve, Compressor, and Pipe to fix integration tests.
- Updated Python and C bindings for validation errors.
- Updated sprint status and story documentation.
This commit is contained in:
Sepehr
2026-02-21 23:21:34 +01:00
parent 4440132b0a
commit fa480ed303
55 changed files with 5987 additions and 31 deletions

View File

@@ -404,6 +404,36 @@ impl Pipe<Disconnected> {
pub fn set_calib(&mut self, calib: Calib) {
self.calib = calib;
}
/// Connects the pipe to inlet and outlet ports.
///
/// This consumes the disconnected pipe and returns a connected one,
/// transitioning the state at compile time.
pub fn connect(
self,
inlet: Port<Disconnected>,
outlet: Port<Disconnected>,
) -> Result<Pipe<Connected>, ComponentError> {
let (p_in, _) = self
.port_inlet
.connect(inlet)
.map_err(|e| ComponentError::InvalidState(e.to_string()))?;
let (p_out, _) = self
.port_outlet
.connect(outlet)
.map_err(|e| ComponentError::InvalidState(e.to_string()))?;
Ok(Pipe {
geometry: self.geometry,
port_inlet: p_in,
port_outlet: p_out,
fluid_density_kg_per_m3: self.fluid_density_kg_per_m3,
fluid_viscosity_pa_s: self.fluid_viscosity_pa_s,
calib: self.calib,
circuit_id: self.circuit_id,
operational_state: self.operational_state,
_state: PhantomData,
})
}
}
impl Pipe<Connected> {
@@ -622,6 +652,17 @@ impl Component for Pipe<Connected> {
1
}
fn port_mass_flows(&self, state: &SystemState) -> Result<Vec<entropyk_core::MassFlow>, ComponentError> {
if state.is_empty() {
return Err(ComponentError::InvalidStateDimensions {
expected: 1,
actual: 0,
});
}
let m = entropyk_core::MassFlow::from_kg_per_s(state[0]);
Ok(vec![m, entropyk_core::MassFlow::from_kg_per_s(-m.to_kg_per_s())])
}
fn get_ports(&self) -> &[ConnectedPort] {
&[]
}