Name | Description |
---|---|
MixingVolume | Mixing volume with inlet and outlet ports (flow reversal is allowed) |
This model represents the same physics as Modelica_Fluid.Volumes.MixingVolume, but it allows to have more than two fluid ports. This is convenient for modeling the room volume in a building energy simulation since rooms often have more than two fluid connections, such as an HVAC inlet, outlet and a leakage flow to other rooms or the outside. If a fluid port is connected twice, the model will terminate the simulation with an error message.
The thermal port need not be connected, but can have any number of connections.
Type | Name | Default | Description |
---|---|---|---|
replaceable package Medium | PartialMedium | Medium in the component | |
Volume | V | Volume [m3] | |
Integer | nP | 2 | Number of ports |
Initialization | |||
Temp | initType | Types.Init.NoInit | Initialization option |
AbsolutePressure | p_start | Medium.p_default | Start value of pressure [Pa] |
Boolean | use_T_start | true | = true, use T_start, otherwise h_start |
Temperature | T_start | if use_T_start then Medium.T... | Start value of temperature [K] |
SpecificEnthalpy | h_start | if use_T_start then Medium.s... | Start value of specific enthalpy [J/kg] |
MassFraction | X_start[Medium.nX] | Medium.X_default | Start value of mass fractions m_i/m [kg/kg] |
Type | Name | Description |
---|---|---|
FluidPort_a | port[nP] | Fluid port |
HeatPort_a | thermalPort | Thermal port |
model MixingVolume "Mixing volume with inlet and outlet ports (flow reversal is allowed)" extends Modelica_Fluid.Interfaces.PartialInitializationParameters; replaceable package Medium = Modelica.Media.Interfaces.PartialMedium "Medium in the component"; parameter Modelica.SIunits.Volume V "Volume"; parameter Integer nP(min=1) = 2 "Number of ports"; Modelica_Fluid.Interfaces.FluidPort_a port[nP](redeclare each package Medium = Medium) "Fluid port"; Medium.BaseProperties medium( preferredMediumStates=true, p(start=p_start), h(start=h_start), T(start=T_start), Xi(start=X_start[1:Medium.nXi])); Modelica.SIunits.Energy U "Internal energy of fluid"; Modelica.SIunits.Mass m "Mass of fluid"; Modelica.SIunits.Mass mXi[Medium.nXi] "Masses of independent components in the fluid"; Modelica.SIunits.Volume V_lumped=V "Volume"; protected Modelica.SIunits.HeatFlowRate Qs_flow "Heat flow across boundaries or energy source/sink"; Modelica.SIunits.Power Ws_flow=0 "Work flow across boundaries or source term"; public Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a thermalPort "Thermal port"; equation thermalPort.T = medium.T; Qs_flow = thermalPort.Q_flow; // boundary conditions for i in 1:nP loop port[i].p = medium.p; port[i].H_flow = semiLinear( port[i].m_flow, port[i].h, medium.h); port[i].mXi_flow = semiLinear( port[i].m_flow, port[i].Xi, medium.Xi); end for; // Total quantities m = V_lumped*medium.d; mXi = m*medium.Xi; U = m*medium.u; // Mass and energy balance der(m) = sum(port[i].m_flow for i in 1:nP); der(mXi) = sum(port[i].mXi_flow for i in 1:nP); der(U) = sum(port[i].H_flow for i in 1:nP) + Qs_flow + Ws_flow; initial equation // Initial conditions for i in 1:nP loop assert(cardinality(port[i]) == 1, "Only one port connection allowed. To fix, increase nP and use new port."); end for; if initType == Modelica_Fluid.Types.Init.NoInit then // no initial equations elseif initType == Modelica_Fluid.Types.Init.InitialValues then if not Medium.singleState then medium.p = p_start; end if; if use_T_start then medium.T = T_start; else medium.h = h_start; end if; medium.Xi = X_start[1:Medium.nXi]; elseif initType == Modelica_Fluid.Types.Init.SteadyState then if not Medium.singleState then der(medium.p) = 0; end if; der(medium.h) = 0; der(medium.Xi) = zeros(Medium.nXi); elseif initType == Modelica_Fluid.Types.Init.SteadyStateHydraulic then if not Medium.singleState then der(medium.p) = 0; end if; if use_T_start then medium.T = T_start; else medium.h = h_start; end if; medium.Xi = X_start[1:Medium.nXi]; else assert(false, "Unsupported initialization option"); end if; end MixingVolume;