chore: sync project state and current artifacts
This commit is contained in:
@@ -62,10 +62,12 @@ pub mod fan;
|
||||
pub mod flow_boundary;
|
||||
pub mod flow_junction;
|
||||
pub mod heat_exchanger;
|
||||
pub mod node;
|
||||
pub mod pipe;
|
||||
pub mod polynomials;
|
||||
pub mod port;
|
||||
pub mod pump;
|
||||
pub mod python_components;
|
||||
pub mod state_machine;
|
||||
|
||||
pub use compressor::{Ahri540Coefficients, Compressor, CompressorModel, SstSdtCoefficients};
|
||||
@@ -75,32 +77,38 @@ pub use external_model::{
|
||||
ExternalModelType, MockExternalModel, ThreadSafeExternalModel,
|
||||
};
|
||||
pub use fan::{Fan, FanCurves};
|
||||
pub use flow_boundary::{
|
||||
CompressibleSink, CompressibleSource, FlowSink, FlowSource, IncompressibleSink,
|
||||
IncompressibleSource,
|
||||
};
|
||||
pub use flow_junction::{
|
||||
CompressibleMerger, CompressibleSplitter, FlowMerger, FlowSplitter, FluidKind,
|
||||
IncompressibleMerger, IncompressibleSplitter,
|
||||
};
|
||||
pub use heat_exchanger::model::FluidState;
|
||||
pub use heat_exchanger::{
|
||||
Condenser, CondenserCoil, Economizer, EpsNtuModel, Evaporator, EvaporatorCoil, ExchangerType,
|
||||
FlowConfiguration, HeatExchanger, HeatExchangerBuilder, HeatTransferModel, HxSideConditions,
|
||||
LmtdModel,
|
||||
};
|
||||
pub use node::{Node, NodeMeasurements, NodePhase};
|
||||
pub use pipe::{friction_factor, roughness, Pipe, PipeGeometry};
|
||||
pub use polynomials::{AffinityLaws, PerformanceCurves, Polynomial1D, Polynomial2D};
|
||||
pub use port::{
|
||||
validate_port_continuity, Connected, ConnectedPort, ConnectionError, Disconnected, FluidId, Port,
|
||||
};
|
||||
pub use flow_boundary::{
|
||||
CompressibleSink, CompressibleSource, FlowSink, FlowSource,
|
||||
IncompressibleSink, IncompressibleSource,
|
||||
};
|
||||
pub use flow_junction::{
|
||||
CompressibleMerger, CompressibleSplitter, FlowMerger, FlowSplitter, FluidKind,
|
||||
IncompressibleMerger, IncompressibleSplitter,
|
||||
validate_port_continuity, Connected, ConnectedPort, ConnectionError, Disconnected, FluidId,
|
||||
Port,
|
||||
};
|
||||
pub use pump::{Pump, PumpCurves};
|
||||
pub use python_components::{
|
||||
PyCompressorReal, PyExpansionValveReal, PyFlowMergerReal, PyFlowSinkReal, PyFlowSourceReal,
|
||||
PyFlowSplitterReal, PyHeatExchangerReal, PyPipeReal,
|
||||
};
|
||||
pub use state_machine::{
|
||||
CircuitId, OperationalState, StateHistory, StateManageable, StateTransitionError,
|
||||
StateTransitionRecord,
|
||||
};
|
||||
|
||||
use entropyk_core::MassFlow;
|
||||
use entropyk_core::{MassFlow, Power};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Errors that can occur during component operations.
|
||||
@@ -158,7 +166,7 @@ pub enum ComponentError {
|
||||
/// Reason for rejection
|
||||
reason: String,
|
||||
},
|
||||
|
||||
|
||||
/// Calculation dynamically failed.
|
||||
///
|
||||
/// Occurs when an underlying model or backend fails to evaluate
|
||||
@@ -169,9 +177,16 @@ pub enum ComponentError {
|
||||
|
||||
/// Represents the state of the entire thermodynamic system.
|
||||
///
|
||||
/// This type will be refined in future iterations as the system architecture
|
||||
/// evolves. For now, it provides a placeholder for system-wide state information.
|
||||
pub type SystemState = Vec<f64>;
|
||||
/// Re-exported from `entropyk_core` for convenience. Each edge in the system
|
||||
/// graph has two state variables: pressure and enthalpy.
|
||||
///
|
||||
/// See [`entropyk_core::SystemState`] for full documentation.
|
||||
pub use entropyk_core::SystemState;
|
||||
|
||||
/// Type alias for state slice used in component methods.
|
||||
///
|
||||
/// This allows both `&Vec<f64>` and `&SystemState` to be passed via deref coercion.
|
||||
pub type StateSlice = [f64];
|
||||
|
||||
/// Vector of residual values for equation solving.
|
||||
///
|
||||
@@ -316,14 +331,14 @@ impl JacobianBuilder {
|
||||
/// This trait is **object-safe**, meaning it can be used with dynamic dispatch:
|
||||
///
|
||||
/// ```
|
||||
/// use entropyk_components::{Component, ComponentError, SystemState, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
/// use entropyk_components::{Component, ComponentError, StateSlice, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
///
|
||||
/// struct SimpleComponent;
|
||||
/// impl Component for SimpleComponent {
|
||||
/// fn compute_residuals(&self, _state: &SystemState, _residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// fn compute_residuals(&self, _state: &StateSlice, _residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// fn jacobian_entries(&self, _state: &SystemState, _jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// fn jacobian_entries(&self, _state: &StateSlice, _jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// fn n_equations(&self) -> usize { 1 }
|
||||
@@ -366,7 +381,7 @@ pub trait Component {
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `state` - Current state vector of the entire system
|
||||
/// * `state` - Current state vector of the entire system as a slice
|
||||
/// * `residuals` - Mutable slice to store computed residual values
|
||||
///
|
||||
/// # Returns
|
||||
@@ -381,11 +396,11 @@ pub trait Component {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use entropyk_components::{Component, ComponentError, SystemState, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
/// use entropyk_components::{Component, ComponentError, StateSlice, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
///
|
||||
/// struct MassBalanceComponent;
|
||||
/// impl Component for MassBalanceComponent {
|
||||
/// fn compute_residuals(&self, state: &SystemState, residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// fn compute_residuals(&self, state: &StateSlice, residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// // Validate dimensions
|
||||
/// if state.len() < 2 {
|
||||
/// return Err(ComponentError::InvalidStateDimensions { expected: 2, actual: state.len() });
|
||||
@@ -395,7 +410,7 @@ pub trait Component {
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// fn jacobian_entries(&self, _state: &SystemState, _jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// fn jacobian_entries(&self, _state: &StateSlice, _jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// fn n_equations(&self) -> usize { 1 }
|
||||
@@ -404,7 +419,7 @@ pub trait Component {
|
||||
/// ```
|
||||
fn compute_residuals(
|
||||
&self,
|
||||
state: &SystemState,
|
||||
state: &StateSlice,
|
||||
residuals: &mut ResidualVector,
|
||||
) -> Result<(), ComponentError>;
|
||||
|
||||
@@ -415,7 +430,7 @@ pub trait Component {
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `state` - Current state vector of the entire system
|
||||
/// * `state` - Current state vector of the entire system as a slice
|
||||
/// * `jacobian` - Builder for accumulating Jacobian entries
|
||||
///
|
||||
/// # Returns
|
||||
@@ -430,15 +445,15 @@ pub trait Component {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use entropyk_components::{Component, ComponentError, SystemState, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
/// use entropyk_components::{Component, ComponentError, StateSlice, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
///
|
||||
/// struct LinearComponent;
|
||||
/// impl Component for LinearComponent {
|
||||
/// fn compute_residuals(&self, _state: &SystemState, _residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// fn compute_residuals(&self, _state: &StateSlice, _residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// fn jacobian_entries(&self, _state: &SystemState, jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// fn jacobian_entries(&self, _state: &StateSlice, jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// // ∂r₀/∂s₀ = 2.0
|
||||
/// jacobian.add_entry(0, 0, 2.0);
|
||||
/// // ∂r₀/∂s₁ = -1.0
|
||||
@@ -452,7 +467,7 @@ pub trait Component {
|
||||
/// ```
|
||||
fn jacobian_entries(
|
||||
&self,
|
||||
state: &SystemState,
|
||||
state: &StateSlice,
|
||||
jacobian: &mut JacobianBuilder,
|
||||
) -> Result<(), ComponentError>;
|
||||
|
||||
@@ -464,14 +479,14 @@ pub trait Component {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use entropyk_components::{Component, ComponentError, SystemState, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
/// use entropyk_components::{Component, ComponentError, StateSlice, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
///
|
||||
/// struct ThreeEquationComponent;
|
||||
/// impl Component for ThreeEquationComponent {
|
||||
/// fn compute_residuals(&self, _state: &SystemState, _residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// fn compute_residuals(&self, _state: &StateSlice, _residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// fn jacobian_entries(&self, _state: &SystemState, _jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// fn jacobian_entries(&self, _state: &StateSlice, _jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// fn n_equations(&self) -> usize { 3 }
|
||||
@@ -492,14 +507,14 @@ pub trait Component {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use entropyk_components::{Component, ComponentError, SystemState, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
/// use entropyk_components::{Component, ComponentError, StateSlice, ResidualVector, JacobianBuilder, ConnectedPort};
|
||||
///
|
||||
/// struct PortlessComponent;
|
||||
/// impl Component for PortlessComponent {
|
||||
/// fn compute_residuals(&self, _state: &SystemState, _residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// fn compute_residuals(&self, _state: &StateSlice, _residuals: &mut ResidualVector) -> Result<(), ComponentError> {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// fn jacobian_entries(&self, _state: &SystemState, _jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// fn jacobian_entries(&self, _state: &StateSlice, _jacobian: &mut JacobianBuilder) -> Result<(), ComponentError> {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// fn n_equations(&self) -> usize { 0 }
|
||||
@@ -545,20 +560,43 @@ pub trait Component {
|
||||
}
|
||||
|
||||
/// Returns the mass flow vector associated with the component's ports.
|
||||
///
|
||||
///
|
||||
/// The returned vector matches the order of ports returned by `get_ports()`.
|
||||
/// Positive values indicate flow *into* the component, negative values flow *out*.
|
||||
///
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `state` - The global system state vector
|
||||
///
|
||||
///
|
||||
/// * `state` - The global system state vector as a slice
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
///
|
||||
/// * `Ok(Vec<MassFlow>)` containing the mass flows if calculation is supported
|
||||
/// * `Err(ComponentError::NotImplemented)` by default
|
||||
fn port_mass_flows(&self, _state: &SystemState) -> Result<Vec<MassFlow>, ComponentError> {
|
||||
Err(ComponentError::CalculationFailed("Mass flow calculation not implemented for this component".to_string()))
|
||||
fn port_mass_flows(&self, _state: &StateSlice) -> Result<Vec<MassFlow>, ComponentError> {
|
||||
Err(ComponentError::CalculationFailed(
|
||||
"Mass flow calculation not implemented for this component".to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Returns the specified enthalpy vector associated with the component's ports.
|
||||
///
|
||||
/// The returned vector matches the order of ports returned by `get_ports()`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `state` - The global system state vector as a slice
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Ok(Vec<Enthalpy>)` containing the enthalpies if calculation is supported
|
||||
/// * `Err(ComponentError::NotImplemented)` by default
|
||||
fn port_enthalpies(
|
||||
&self,
|
||||
_state: &StateSlice,
|
||||
) -> Result<Vec<entropyk_core::Enthalpy>, ComponentError> {
|
||||
Err(ComponentError::CalculationFailed(
|
||||
"Enthalpy calculation not implemented for this component".to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Injects control variable indices for calibration parameters into a component.
|
||||
@@ -569,6 +607,27 @@ pub trait Component {
|
||||
fn set_calib_indices(&mut self, _indices: entropyk_core::CalibIndices) {
|
||||
// Default: no-op for components that don't support inverse calibration
|
||||
}
|
||||
|
||||
/// Evaluates the energy interactions of the component with its environment.
|
||||
///
|
||||
/// Returns a tuple of `(HeatTransfer, WorkTransfer)` in Watts (converted to `Power`).
|
||||
/// - `HeatTransfer` > 0 means heat added TO the component from the environment.
|
||||
/// - `WorkTransfer` > 0 means work done BY the component on the environment.
|
||||
///
|
||||
/// The default implementation returns `None`, indicating that the component does
|
||||
/// not support or has not implemented energy transfer reporting. Components that
|
||||
/// are strictly adiabatic and passive (like Pipes) should return `Some((Power(0.0), Power(0.0)))`.
|
||||
fn energy_transfers(&self, _state: &StateSlice) -> Option<(Power, Power)> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Generates a string signature of the component's configuration (parameters, fluid, etc.).
|
||||
/// Used for simulation traceability (input hashing).
|
||||
/// Default implementation is provided, but components should override this to include
|
||||
/// their specific parameters (e.g., fluid type, geometry).
|
||||
fn signature(&self) -> String {
|
||||
"Component".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -583,7 +642,7 @@ mod tests {
|
||||
impl Component for MockComponent {
|
||||
fn compute_residuals(
|
||||
&self,
|
||||
state: &SystemState,
|
||||
state: &StateSlice,
|
||||
residuals: &mut ResidualVector,
|
||||
) -> Result<(), ComponentError> {
|
||||
// Validate dimensions
|
||||
@@ -602,7 +661,7 @@ mod tests {
|
||||
|
||||
fn jacobian_entries(
|
||||
&self,
|
||||
_state: &SystemState,
|
||||
_state: &StateSlice,
|
||||
jacobian: &mut JacobianBuilder,
|
||||
) -> Result<(), ComponentError> {
|
||||
// Add identity-like entries for testing
|
||||
@@ -865,14 +924,14 @@ mod tests {
|
||||
impl Component for ComponentWithPorts {
|
||||
fn compute_residuals(
|
||||
&self,
|
||||
_state: &SystemState,
|
||||
_state: &StateSlice,
|
||||
_residuals: &mut ResidualVector,
|
||||
) -> Result<(), ComponentError> {
|
||||
Ok(())
|
||||
}
|
||||
fn jacobian_entries(
|
||||
&self,
|
||||
_state: &SystemState,
|
||||
_state: &StateSlice,
|
||||
_jacobian: &mut JacobianBuilder,
|
||||
) -> Result<(), ComponentError> {
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user