from __future__ import annotations from abc import ABC, abstractmethod class Component(ABC): def __init__(self, name: str) -> None: self.name = name class DynamicComponent(Component): state_size = 2 @staticmethod def actual_stream_enthalpy( port_m_flow: float, connected_h: float, internal_h: float, ) -> float: """Approximate `actualStream(port.h_outflow)` for a mixed control volume port.""" return connected_h if port_m_flow > 0.0 else internal_h def connection_inlet_enthalpy( self, port_m_flow: float, connected_h: float, internal_h: float, ) -> float: """Resolve the enthalpy convected into this control volume through one port.""" return self.actual_stream_enthalpy( port_m_flow=port_m_flow, connected_h=connected_h, internal_h=internal_h, ) @abstractmethod def get_state_vector(self) -> list[float]: raise NotImplementedError @abstractmethod def set_state_vector(self, values: list[float]) -> None: raise NotImplementedError class AlgebraicComponent(Component): """Stateless element described by algebraic constraints only."""