Package with base classes for Buildings.Fluid.MixingVolumes
Information
This package contains base classes that are used to construct the models in
Buildings.Fluid.MixingVolumes.
Extends from Modelica.Icons.BasesPackage (Icon for packages containing base classes).
Package Content
Name |
Description |
PartialMixingVolume
|
Partial mixing volume with inlet and outlet ports (flow reversal is allowed) |
Partial mixing volume with inlet and outlet ports (flow reversal is allowed)
Information
This is a partial model of an instantaneously mixed volume.
It is used as the base class for all fluid volumes of the package
Buildings.Fluid.MixingVolumes.
To increase the numerical robustness of the model, the parameter
prescribedHeatFlowRate
can be set by the user.
This parameter only has an effect if the model has exactly two fluid ports connected,
and if it is used as a steady-state model.
Use the following settings:
- Set
prescribedHeatFlowRate=true
if the only means of heat transfer
at the heatPort
is a prescribed heat flow rate that
is not a function of the temperature difference
between the medium and an ambient temperature. Examples include an ideal electrical heater,
a pump that rejects heat into the fluid stream, or a chiller that removes heat based on a performance curve.
If the heatPort
is not connected, then set prescribedHeatFlowRate=true
as
in this case, heatPort.Q_flow=0
.
- Set
prescribedHeatFlowRate=false
if there is heat flow at the heatPort
computed as K * (T-heatPort.T), for some temperature T and some conductance K,
which may itself be a function of temperature or mass flow rate.
If there is a combination of K * (T-heatPort.T) and a prescribed heat flow rate,
for example a solar collector that dissipates heat to the ambient and receives heat from
the solar radiation, then set prescribedHeatFlowRate=false
.
Implementation
If the model is (i) operated in steady-state,
(ii) has two fluid ports connected, and
(iii) prescribedHeatFlowRate=true
, then
the model uses
Buildings.Fluid.Interfaces.StaticTwoPortConservationEquation
in order to use
the same energy and mass balance implementation as is used as in
steady-state component models.
In this situation, the functions inStream
are used for the two
flow directions rather than the function
actualStream
, which is less efficient.
However, the use of inStream
has the disadvantage
that hOut
has to be computed, in
Buildings.Fluid.Interfaces.StaticTwoPortConservationEquation,
using
if allowFlowReversal then
hOut = Buildings.Utilities.Math.Functions.spliceFunction(pos=port_b.h_outflow,
neg=port_a.h_outflow,
x=port_a.m_flow,
deltax=m_flow_small/1E3);
else
hOut = port_b.h_outflow;
end if;
Hence, for allowFlowReversal=true
, if hOut
were to be used to compute the temperature that
drives heat transfer such as by conduction,
then the heat transfer would depend on upstream and the downstream
temperatures for small mass flow rates.
This can give wrong results. Consider for example a mass flow rate that is positive
but very close to zero. Suppose the upstream temperature is 20ˆC,
the downstream temperature is 10ˆC, and the heat port is
connected through a heat conductor to a boundary condition of 20ˆC.
Then, hOut = (port_b.h_outflow + port_a.h_outflow)/2
and hence
the temperature heatPort.T
is 15ˆC. Therefore, heat is added to the component.
As the mass flow rate is by assumption very small, the fluid that leaves the component
will have a very high temperature, violating the 2nd law.
To avoid this situation, if
prescribedHeatFlowRate=false
, then the model
Buildings.Fluid.Interfaces.ConservationEquation
is used instead of
Buildings.Fluid.Interfaces.StaticTwoPortConservationEquation.
For simple models that uses this model, see
Buildings.Fluid.MixingVolumes.
Extends from Buildings.Fluid.Interfaces.LumpedVolumeDeclarations (Declarations for lumped volumes).
Parameters
Type | Name | Default | Description |
replaceable package Medium | PartialMedium | Medium in the component |
Volume | V | | Volume [m3] |
Nominal condition |
MassFlowRate | m_flow_nominal | | Nominal mass flow rate [kg/s] |
Dynamics |
Equations |
Dynamics | energyDynamics | Modelica.Fluid.Types.Dynamic... | Formulation of energy balance |
Dynamics | massDynamics | energyDynamics | Formulation of mass balance |
Real | mSenFac | 1 | Factor for scaling the sensible thermal mass of the volume |
Initialization |
AbsolutePressure | p_start | Medium.p_default | Start value of pressure [Pa] |
Temperature | T_start | Medium.T_default | Start value of temperature [K] |
MassFraction | X_start[Medium.nX] | Medium.X_default | Start value of mass fractions m_i/m [kg/kg] |
ExtraProperty | C_start[Medium.nC] | fill(0, Medium.nC) | Start value of trace substances |
ExtraProperty | C_nominal[Medium.nC] | fill(1E-2, Medium.nC) | Nominal value of trace substances. (Set to typical order of magnitude.) |
Advanced |
MassFlowRate | m_flow_small | 1E-4*abs(m_flow_nominal) | Small mass flow rate for regularization of zero flow [kg/s] |
Assumptions |
Boolean | allowFlowReversal | true | = true to allow flow reversal in medium, false restricts to design direction (ports[1] -> ports[2]). Used only if model has two ports. |
Heat transfer |
Boolean | prescribedHeatFlowRate | false | Set to true if the model has a prescribed heat flow at its heatPort. If the heat flow rate at the heatPort is only based on temperature difference, then set to false. |
Connectors
Modelica definition
partial model PartialMixingVolume
"Partial mixing volume with inlet and outlet ports (flow reversal is allowed)"
extends Buildings.Fluid.Interfaces.LumpedVolumeDeclarations;
constant Boolean initialize_p =
not Medium.singleState
"= true to set up initial equations for pressure";
parameter Modelica.SIunits.MassFlowRate m_flow_nominal(min=0)
"Nominal mass flow rate";
// Port definitions
parameter Integer nPorts=0
"Number of ports";
parameter Modelica.SIunits.MassFlowRate m_flow_small(min=0) = 1E-4*
abs(m_flow_nominal)
"Small mass flow rate for regularization of zero flow";
parameter Boolean allowFlowReversal = true
"= true to allow flow reversal in medium, false restricts to design direction (ports[1] -> ports[2]). Used only if model has two ports.";
parameter Modelica.SIunits.Volume V
"Volume";
parameter Boolean prescribedHeatFlowRate=false
"Set to true if the model has a prescribed heat flow at its heatPort. If the heat flow rate at the heatPort is only based on temperature difference, then set to false.";
Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b ports[nPorts](
redeclare each package Medium =
Medium)
"Fluid inlets and outlets";
Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort(
T(start=T_start))
"Heat port for sensible heat input";
Medium.Temperature T
"Temperature of the fluid";
Modelica.SIunits.Pressure p
"Pressure of the fluid";
Modelica.SIunits.MassFraction Xi[Medium.nXi]
"Species concentration of the fluid";
Medium.ExtraProperty C[Medium.nC](nominal=C_nominal)
"Trace substance mixture content";
// Models for the steady-state and dynamic energy balance.
protected
Buildings.Fluid.Interfaces.StaticTwoPortConservationEquation steBal(
sensibleOnly = true,
redeclare final package Medium=
Medium,
final m_flow_nominal = m_flow_nominal,
final allowFlowReversal = allowFlowReversal,
final m_flow_small = m_flow_small)
if
useSteadyStateTwoPort
"Model for steady-state balance if nPorts=2";
Buildings.Fluid.Interfaces.ConservationEquation dynBal(
redeclare final package Medium =
Medium,
final energyDynamics=energyDynamics,
final massDynamics=massDynamics,
final p_start=p_start,
final T_start=T_start,
final X_start=X_start,
final C_start=C_start,
final C_nominal=C_nominal,
final fluidVolume = V,
final initialize_p = initialize_p,
m(start=V*rho_start),
nPorts=nPorts,
final mSenFac=mSenFac)
if
not useSteadyStateTwoPort
"Model for dynamic energy balance";
// Density at start values, used to compute initial values and start guesses
parameter Modelica.SIunits.Density rho_start=
Medium.density(
state=state_start)
"Density, used to compute start and guess values";
final parameter Medium.ThermodynamicState state_default =
Medium.setState_pTX(
T=Medium.T_default,
p=Medium.p_default,
X=Medium.X_default[1:Medium.nXi])
"Medium state at default values";
// Density at medium default values, used to compute the size of control volumes
final parameter Modelica.SIunits.Density rho_default=
Medium.density(
state=state_default)
"Density, used to compute fluid mass";
final parameter Medium.ThermodynamicState state_start =
Medium.setState_pTX(
T=T_start,
p=p_start,
X=X_start[1:Medium.nXi])
"Medium state at start values";
// See info section for why prescribedHeatFlowRate is used here.
final parameter Boolean useSteadyStateTwoPort=(nPorts == 2)
and
(prescribedHeatFlowRate
or (
not allowFlowReversal))
and (
energyDynamics == Modelica.Fluid.Types.Dynamics.SteadyState)
and (
massDynamics == Modelica.Fluid.Types.Dynamics.SteadyState)
and (
substanceDynamics == Modelica.Fluid.Types.Dynamics.SteadyState)
and (
traceDynamics == Modelica.Fluid.Types.Dynamics.SteadyState)
"Flag, true if the model has two ports only and uses a steady state balance";
// Outputs that are needed to assign the medium properties
Modelica.Blocks.Interfaces.RealOutput hOut_internal(unit="J/kg")
"Internal connector for leaving temperature of the component";
Modelica.Blocks.Interfaces.RealOutput XiOut_internal[Medium.nXi](
each unit="1")
"Internal connector for leaving species concentration of the component";
Modelica.Blocks.Interfaces.RealOutput COut_internal[Medium.nC](
each unit="1")
"Internal connector for leaving trace substances of the component";
Modelica.Blocks.Sources.RealExpression QSen_flow(y=heatPort.Q_flow)
"Block to set sensible heat input into volume";
equation
///////////////////////////////////////////////////////////////////////////
// asserts
if not allowFlowReversal
then
assert(ports[1].m_flow > -m_flow_small,
"Model has flow reversal, but the parameter allowFlowReversal is set to false.
m_flow_small = " +
String(m_flow_small) + "
ports[1].m_flow = " +
String(ports[1].m_flow) + "
");
end if;
// Actual definition of port variables.
//
// If the model computes the energy and mass balances as steady-state,
// and if it has only two ports,
// then we use the same base class as for all other steady state models.
if useSteadyStateTwoPort
then
connect(steBal.port_a, ports[1]);
connect(steBal.port_b, ports[2]);
connect(hOut_internal, steBal.hOut);
connect(XiOut_internal, steBal.XiOut);
connect(COut_internal, steBal.COut);
else
connect(dynBal.ports, ports);
connect(hOut_internal, dynBal.hOut);
connect(XiOut_internal, dynBal.XiOut);
connect(COut_internal, dynBal.COut);
end if;
// Medium properties
p =
if nPorts > 0
then ports[1].p
else p_start;
T =
Medium.temperature_phX(p=p, h=hOut_internal, X=
cat(1,Xi,{1-
sum(Xi)}));
Xi = XiOut_internal;
C = COut_internal;
// Port properties
heatPort.T = T;
end PartialMixingVolume;
Automatically generated Mon Jul 13 14:25:42 2015.