feat(python): implement python bindings for all components and solvers
This commit is contained in:
@@ -100,6 +100,8 @@ pub struct ExpansionValve<State> {
|
||||
port_outlet: Port<State>,
|
||||
/// Calibration: ṁ_eff = f_m × ṁ_nominal (mass flow scaling)
|
||||
calib: Calib,
|
||||
/// Calibration indices to extract factors dynamically from SystemState
|
||||
pub calib_indices: entropyk_core::CalibIndices,
|
||||
operational_state: OperationalState,
|
||||
opening: Option<f64>,
|
||||
fluid_id: FluidId,
|
||||
@@ -153,6 +155,7 @@ impl ExpansionValve<Disconnected> {
|
||||
port_inlet,
|
||||
port_outlet,
|
||||
calib: Calib::default(),
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
operational_state: OperationalState::default(),
|
||||
opening,
|
||||
fluid_id,
|
||||
@@ -552,7 +555,8 @@ impl Component for ExpansionValve<Connected> {
|
||||
// Mass flow: ṁ_out = f_m × ṁ_in (calibration factor on inlet flow)
|
||||
let mass_flow_in = state[0];
|
||||
let mass_flow_out = state[1];
|
||||
residuals[1] = mass_flow_out - self.calib.f_m * mass_flow_in;
|
||||
let f_m = self.calib_indices.f_m.map(|idx| state[idx]).unwrap_or(self.calib.f_m);
|
||||
residuals[1] = mass_flow_out - f_m * mass_flow_in;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -579,11 +583,19 @@ impl Component for ExpansionValve<Connected> {
|
||||
OperationalState::On | OperationalState::Off => {}
|
||||
}
|
||||
|
||||
let f_m = self.calib_indices.f_m.map(|idx| _state[idx]).unwrap_or(self.calib.f_m);
|
||||
jacobian.add_entry(0, 0, 0.0);
|
||||
jacobian.add_entry(0, 1, 0.0);
|
||||
jacobian.add_entry(1, 0, -self.calib.f_m);
|
||||
jacobian.add_entry(1, 0, -f_m);
|
||||
jacobian.add_entry(1, 1, 1.0);
|
||||
|
||||
if let Some(idx) = self.calib_indices.f_m {
|
||||
// d(R2)/d(f_m) = -mass_flow_in
|
||||
// We need mass_flow_in here, which is _state[0]
|
||||
let mass_flow_in = _state[0];
|
||||
jacobian.add_entry(1, idx, -mass_flow_in);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -594,6 +606,10 @@ impl Component for ExpansionValve<Connected> {
|
||||
fn get_ports(&self) -> &[ConnectedPort] {
|
||||
&[]
|
||||
}
|
||||
|
||||
fn set_calib_indices(&mut self, indices: entropyk_core::CalibIndices) {
|
||||
self.calib_indices = indices;
|
||||
}
|
||||
}
|
||||
|
||||
use crate::state_machine::StateManageable;
|
||||
@@ -653,6 +669,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_bar(3.5));
|
||||
|
||||
ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -836,6 +853,7 @@ mod tests {
|
||||
let (inlet_conn, outlet_conn) = inlet.connect(outlet).unwrap();
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -872,6 +890,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_bar(3.5));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -901,6 +920,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_bar(3.5));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1059,6 +1079,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_pascals(0.0));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1087,6 +1108,7 @@ mod tests {
|
||||
let (inlet_conn, outlet_conn) = inlet.connect(outlet).unwrap();
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1117,6 +1139,7 @@ mod tests {
|
||||
let (inlet_conn, outlet_conn) = inlet.connect(outlet).unwrap();
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1216,6 +1239,7 @@ mod tests {
|
||||
outlet_conn.set_enthalpy(Enthalpy::from_joules_per_kg(180000.0));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1248,6 +1272,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_bar(3.5));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1281,6 +1306,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_bar(3.5));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1313,6 +1339,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_bar(3.5));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1345,6 +1372,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_bar(3.5));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1377,6 +1405,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_bar(3.5));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
@@ -1409,6 +1438,7 @@ mod tests {
|
||||
outlet_conn.set_pressure(Pressure::from_bar(3.5));
|
||||
|
||||
let valve = ExpansionValve {
|
||||
calib_indices: entropyk_core::CalibIndices::default(),
|
||||
port_inlet: inlet_conn,
|
||||
port_outlet: outlet_conn,
|
||||
calib: Calib::default(),
|
||||
|
||||
Reference in New Issue
Block a user