# -*- coding: utf-8 -*-"""Created on Fri May 10 14:31:24 2024@author: Basile"""fromconnector.mass_connectorimportMassConnectorfromcomponent.base_componentimportBaseComponent
[docs]classTankSpliter(BaseComponent):""" **Component**: Spliter **Model**: Mass Flow Splitting Model **Description**: The `Spliter` component divides an incoming mass flow into multiple outlet streams based on specified mass flow fractions. It assumes no change in fluid properties (pressure, temperature, enthalpy) across the splitter. The model is useful for distributing mass flows in a system model where the thermodynamic state remains unchanged. **Assumptions**: - Steady-state operation. - No heat or work interactions (adiabatic, no shaft work). - Ideal splitting with no pressure or temperature drops. - The sum of the outlet flow fractions must equal 1 (within a small numerical tolerance). **Connectors**: su (MassConnector): Mass connector for the inlet supply stream. ex_1, ex_2, ..., ex_n (MassConnector): Mass connectors for each outlet stream, created based on the number of elements in `outlet_repartition`. **Parameters**: outlet_repartition (list of float): Fractions of the total inlet mass flow allocated to each outlet. Must sum to 1 within a small tolerance. **Inputs**: fluid (str): Inlet fluid. T_su (float): Inlet temperature [K]. h_su (float): Inlet specific enthalpy [J/kg]. P_su (float): Inlet pressure [Pa]. m_dot (float): Inlet mass flow rate [kg/s]. **Outputs**: For each outlet connector (ex_1, ex_2, ..., ex_n): - fluid: Same as inlet fluid. - P: Same as inlet pressure [Pa]. - h: Same as inlet enthalpy [J/kg]. - m_dot: Mass flow rate for the outlet, computed as `su_m_dot * outlet_repartition[i]` [kg/s]. """def__init__(self,geom=None,outlet_repartition=None):super().__init__()"Status variables"self.calculable=Noneself.parametrized=Noneself.solved=False"Geometry sub-object"self.geom=geom# parameters ifself.geomisnotNone:self.outlet_repartition=self.geom.flow_coefelse:ifoutlet_repartitionisnotNone:self.outlet_repartition=outlet_repartitionelse:raiseValueError("'Spliter' model requires to set an array for its 'outlet_repartition' input")"Input"self.su=MassConnector()"Outputs"foriinrange(len(self.outlet_repartition)):outlet_num=i+1setattr(self,f"ex_{outlet_num}",MassConnector())defget_required_inputs(self):# Return a list of required inputsreturn['P_su','T_su','m_dot','fluid']defget_required_parameters(self):return[]defsolve(self):"1) Compute output"ifself.check_parametrized():ifself.check_calculable():tolerance=1e-3ifabs(sum(self.outlet_repartition)-1)<tolerance:foriinrange(len(self.outlet_repartition)):outlet_num=i+1connector=getattr(self,f"ex_{outlet_num}")connector.set_fluid(self.su.fluid)connector.set_p(self.su.p)connector.set_h(self.su.h)connector.set_m_dot(self.su.m_dot*self.outlet_repartition[i])self.solved=Trueelse:raiseValueError(f"'Spliter' total outlet repartition is too far from 1 (tolerance : {tolerance}).")else:raiseValueError("'Spliter' is not fully calculable.")else:raiseValueError("'Spliter' is not fully parametrized.")return