Package with base classes that facilitate exporting models as an FMU
Information
This package contains blocks that serve as containers for exporting
models from Buildings.Fluid
as a Functional Mockup Unit (FMU).
This allows using models from Buildings.Fluid
, add them
to a block that only has input and output signals, but no acausal connectors,
and then export the model as a Functional Mockup Unit.
Models can be individual models or systems that are composed of various
models.
For more information, see the
User's Guide.
Extends from Modelica.Icons.VariantsPackage (Icon for package containing variants).
Package Content
Name |
Description |
UsersGuide
|
User's Guide |
FlowSplitter_u
|
Container to export a flow splitter as an FMU |
InletAdaptor
|
Model for exposing a fluid inlet to the FMI interface |
OutletAdaptor
|
Model for exposing a fluid outlet to the FMI interface |
Sink_T
|
FMI model for a sink with temperature for reverse flow as an input |
Source_T
|
FMI model for a boundary with mass flow rate, pressure and temperature as an input |
TwoPort
|
Container to export a thermofluid flow model with two ports as an FMU |
TwoPortComponent
|
Container to export thermofluid flow models with two ports as an FMU |
Examples
|
Collection of models that illustrate model use and test models |
Interfaces
|
Package with interfaces for models that serves as an FMU container |
Container to export a flow splitter as an FMU
Information
Block that takes as an input the inflowing fluid at the port inlet
and a vector of control signals for the mass flow rates u
.
The mass flow of all outlet ports i
is set to the value of u[i] m_flow_nominal[i]
.
If the inflowing mass flow rate at the port inlet
is not equal
to the sum of u[i] m_flow_in[i]
, the simulation stops with an assert.
Assumptions and limitations
The mass flow rates at all outlet ports must be non-negative.
Reverse flow is not yet implemented.
If either of these limitations are violated, then
the model stops with an error.
Parameters
Type | Name | Default | Description |
replaceable package Medium | Modelica.Media.Interfaces.Pa... | Medium in the component |
MassFlowRate | m_flow_nominal[nout] | | Nominal mass flow rate for each outlet [kg/s] |
Integer | nout | | Number of outlets |
Boolean | use_p_in | true | = true to use a pressure from connector, false to output Medium.p_default |
Assumptions |
Boolean | allowFlowReversal | true | = true to allow flow reversal, false restricts to design direction (inlet -> outlet) |
Connectors
Type | Name | Description |
replaceable package Medium | Medium in the component |
Inlet | inlet | Fluid inlet |
Outlet | outlet[nout] | Fluid outlet |
input RealInput | u[nout] | Control signal for the mass flow rates [1] |
Modelica definition
block FlowSplitter_u
replaceable package Medium =
Modelica.Media.Interfaces.PartialMedium ;
parameter Modelica.SIunits.MassFlowRate m_flow_nominal[nout](
each min=0) ;
parameter Boolean allowFlowReversal = true ;
parameter Integer nout(min=1) ;
parameter Boolean use_p_in=true ;
Interfaces.Inlet inlet(
redeclare final package Medium =
Medium,
final allowFlowReversal=allowFlowReversal,
final use_p_in=use_p_in) ;
Interfaces.Outlet outlet[nout](
redeclare each final package Medium =
Medium,
each final allowFlowReversal=allowFlowReversal,
each final use_p_in=use_p_in) ;
Modelica.Blocks.Interfaces.RealInput u[nout](
unit="1") ;
protected
final parameter Modelica.SIunits.MassFlowRate mAve_flow_nominal=
sum(m_flow_nominal)/nout ;
protected
Buildings.Fluid.FMI.Interfaces.FluidProperties bacPro_internal(
redeclare final package Medium =
Medium) ;
Buildings.Fluid.FMI.Interfaces.MassFractionConnector X_w_out_internal = 0 ;
initial equation
for i
in 1:nout
loop
assert(m_flow_nominal[i] > 0,
"Nominal mass flow rate must be bigger than zero.");
end for;
equation
for i
in 1:nout
loop
assert(u[i] >= 0, "Control signal must be non-negative.");
if use_p_in
then
connect(inlet.p, outlet[i].p);
end if;
outlet[i].m_flow = u[i]*m_flow_nominal[i];
outlet[i].forward = inlet.forward;
end for;
bacPro_internal.T = Medium.T_default;
connect(bacPro_internal.X_w, X_w_out_internal);
bacPro_internal.C =
zeros(Medium.nC);
connect(bacPro_internal, inlet.backward);
assert(
abs(inlet.m_flow-
sum(outlet.m_flow)) < 1E-2 * mAve_flow_nominal,
"Mass flow rate is not conserved.
inlet.m_flow = " +
String(inlet.m_flow) + "
sum(outlet.m_flow) = " +
String(
sum(outlet.m_flow)));
end FlowSplitter_u;
Model for exposing a fluid inlet to the FMI interface
Information
Model that is used to connect an input signal to a fluid port.
The model needs to be used in conjunction with an instance of
Buildings.Fluid.FMI.OutletAdaptor in order for
fluid mass flow rate and pressure to be properly assigned to
the acausal fluid models.
See
Buildings.Fluid.FMI.TwoPortComponent
or
Buildings.Fluid.FMI.Examples.FMUs.ResistanceVolume
for how to use this model.
Parameters
Type | Name | Default | Description |
replaceable package Medium | Modelica.Media.Interfaces.Pa... | Medium model within the source |
Boolean | use_p_in | true | = true to use a pressure from connector, false to output Medium.p_default |
Assumptions |
Boolean | allowFlowReversal | true | = true to allow flow reversal, false restricts to design direction (inlet -> outlet) |
Connectors
Type | Name | Description |
replaceable package Medium | Medium model within the source |
Inlet | inlet | Fluid inlet |
FluidPort_b | port_b | Fluid port |
output RealOutput | p | Pressure [Pa] |
Modelica definition
model InletAdaptor
replaceable package Medium =
Modelica.Media.Interfaces.PartialMedium ;
parameter Boolean allowFlowReversal = true ;
parameter Boolean use_p_in = true ;
Buildings.Fluid.FMI.Interfaces.Inlet inlet(
redeclare final package Medium =
Medium,
final allowFlowReversal=allowFlowReversal,
final use_p_in=use_p_in) ;
Modelica.Fluid.Interfaces.FluidPort_b port_b(
redeclare final package Medium=
Medium) ;
Modelica.Blocks.Interfaces.RealOutput p(unit="Pa")
if
use_p_in ;
protected
Buildings.Fluid.FMI.Interfaces.FluidProperties bacPro_internal(
redeclare final package Medium =
Medium) ;
Buildings.Fluid.FMI.Interfaces.PressureOutput p_in_internal ;
Buildings.Fluid.FMI.Interfaces.MassFractionConnector X_w_in_internal ;
Buildings.Fluid.FMI.Interfaces.MassFractionConnector X_w_out_internal ;
initial equation
assert(Medium.nXi < 2,
"The medium must have zero or one independent mass fraction Medium.nXi.");
equation
-port_b.m_flow = inlet.m_flow;
port_b.h_outflow =
Medium.specificEnthalpy_pTX(
p= p_in_internal,
T= inlet.forward.T,
X=
fill(X_w_in_internal, Medium.nXi));
port_b.C_outflow = inlet.forward.C;
if Medium.nXi == 0
then
X_w_in_internal = 0;
else
connect(X_w_in_internal, inlet.forward.X_w);
end if;
port_b.Xi_outflow =
fill(X_w_in_internal, Medium.nXi);
connect(inlet.backward, bacPro_internal);
X_w_out_internal =
if Medium.nXi > 0
and allowFlowReversal
then inStream(port_b.Xi_outflow[1])
else 0;
connect(bacPro_internal.X_w, X_w_out_internal);
if allowFlowReversal
then
bacPro_internal.T =
Medium.temperature_phX(
p= p_in_internal,
h=
inStream(port_b.h_outflow),
X=
inStream(port_b.Xi_outflow));
bacPro_internal.C =
inStream(port_b.C_outflow);
else
bacPro_internal.T = Medium.T_default;
bacPro_internal.C =
fill(0, Medium.nC);
end if;
if use_p_in
then
connect(inlet.p, p_in_internal);
else
p_in_internal = Medium.p_default;
end if;
connect(p, p_in_internal);
end InletAdaptor;
Model for exposing a fluid outlet to the FMI interface
Information
Model that is used to connect a fluid port with an output signal.
The model needs to be used in conjunction with an instance of
Buildings.Fluid.FMI.InletAdaptor in order for
fluid mass flow rate and pressure to be properly assigned to
the acausal fluid models.
See
Buildings.Fluid.FMI.TwoPortComponent
or
Buildings.Fluid.FMI.Examples.FMUs.ResistanceVolume
for how to use this model.
Parameters
Type | Name | Default | Description |
replaceable package Medium | Modelica.Media.Interfaces.Pa... | Medium model within the source |
Boolean | use_p_in | true | = true to use a pressure from connector, false to output Medium.p_default |
Assumptions |
Boolean | allowFlowReversal | true | = true to allow flow reversal, false restricts to design direction (inlet -> outlet) |
Connectors
Type | Name | Description |
replaceable package Medium | Medium model within the source |
Outlet | outlet | Fluid outlet |
FluidPort_a | port_a | Fluid port |
input PressureInput | p | Pressure to be sent to outlet [Pa] |
Modelica definition
model OutletAdaptor
replaceable package Medium =
Modelica.Media.Interfaces.PartialMedium ;
parameter Boolean allowFlowReversal = true ;
parameter Boolean use_p_in = true ;
Buildings.Fluid.FMI.Interfaces.Outlet outlet(
redeclare final package Medium =
Medium,
final allowFlowReversal=allowFlowReversal,
final use_p_in=use_p_in) ;
Modelica.Fluid.Interfaces.FluidPort_a port_a(
redeclare final package Medium=
Medium) ;
Buildings.Fluid.FMI.Interfaces.PressureInput p
if
use_p_in ;
protected
Buildings.Fluid.FMI.Interfaces.FluidProperties bacPro_internal(
redeclare final package Medium =
Medium) ;
Buildings.Fluid.FMI.Interfaces.PressureOutput p_in_internal ;
Buildings.Fluid.FMI.Interfaces.MassFractionConnector X_w_in_internal ;
Buildings.Fluid.FMI.Interfaces.MassFractionConnector X_w_out_internal ;
initial equation
assert(Medium.nXi < 2,
"The medium must have zero or one independent mass fraction Medium.nXi.");
equation
port_a.m_flow = outlet.m_flow;
outlet.forward.T =
Medium.temperature_phX(
p= p_in_internal,
h=
inStream(port_a.h_outflow),
X=
inStream(port_a.Xi_outflow));
inStream(port_a.C_outflow) = outlet.forward.C;
X_w_in_internal =
if Medium.nXi > 0
then inStream(port_a.Xi_outflow[1])
else 0;
connect(outlet.forward.X_w, X_w_in_internal);
if Medium.nXi > 0
and allowFlowReversal
then
connect(X_w_out_internal, outlet.backward.X_w);
else
X_w_out_internal = 0;
end if;
port_a.Xi_outflow =
fill(X_w_out_internal, Medium.nXi);
connect(outlet.backward, bacPro_internal);
if not allowFlowReversal
then
bacPro_internal.T = Medium.T_default;
bacPro_internal.C =
fill(0, Medium.nC);
if Medium.nXi > 0
then
connect(bacPro_internal.X_w, X_w_out_internal);
end if;
end if;
bacPro_internal.T =
Medium.temperature_phX(
p= p_in_internal,
h= port_a.h_outflow,
X= port_a.Xi_outflow);
bacPro_internal.C = port_a.C_outflow;
if use_p_in
then
connect(outlet.p, p_in_internal);
else
p_in_internal = Medium.p_default;
end if;
connect(p, p_in_internal);
port_a.p = p_in_internal;
end OutletAdaptor;
FMI model for a sink with temperature for reverse flow as an input
Information
Model of a sink that takes as an input the medium properties
temperature, mass fractions (if Medium.nXi > 0
)
and trace substances (if Medium.nC > 0
).
These properties are used during reverse flow.
For a system of components with the connectors of the
Buildings.Fluid.FMI
package, this component is required to set the medium properties
for the reverse flow.
If the parameter use_p_in
is set to true
,
then the model as an output connector p
.
This can be used to obtain the pressure of the sink, which
may be needed to iteratively solve for the mass flow rate.
Extends from Buildings.BaseClasses.BaseIcon (Base icon).
Parameters
Type | Name | Default | Description |
replaceable package Medium | Modelica.Media.Interfaces.Pa... | Medium in the component |
Boolean | use_p_in | true | = true to use a pressure from connector, false to output Medium.p_default |
Assumptions |
Boolean | allowFlowReversal | true | = true to allow flow reversal, false restricts to design direction (inlet -> outlet) |
Connectors
Type | Name | Description |
replaceable package Medium | Medium in the component |
input RealInput | T_in | Prescribed boundary temperature [K] |
input RealInput | X_w_in | Prescribed boundary composition [1] |
input RealInput | C_in[Medium.nC] | Prescribed boundary composition |
Inlet | inlet | Fluid port |
output PressureOutput | p | Pressure [Pa] |
Modelica definition
model Sink_T
extends Buildings.BaseClasses.BaseIcon;
replaceable package Medium =
Modelica.Media.Interfaces.PartialMedium ;
parameter Boolean use_p_in = true ;
parameter Boolean allowFlowReversal = true ;
Modelica.Blocks.Interfaces.RealInput T_in(unit="K",
displayUnit="degC",
min=0) ;
Modelica.Blocks.Interfaces.RealInput X_w_in(unit="1")
if
Medium.nXi > 0 ;
Modelica.Blocks.Interfaces.RealInput C_in[Medium.nC] ;
Interfaces.Inlet inlet(
redeclare final package Medium =
Medium,
final allowFlowReversal=allowFlowReversal,
final use_p_in=use_p_in) ;
Buildings.Fluid.FMI.Interfaces.PressureOutput p
if
use_p_in ;
protected
Buildings.Fluid.FMI.Interfaces.FluidProperties bacPro_internal(
redeclare final package Medium =
Medium) ;
Buildings.Fluid.FMI.Interfaces.PressureOutput p_in_internal ;
output Buildings.Fluid.FMI.Interfaces.MassFractionConnector X_w_in_internal ;
equation
connect(inlet.backward, bacPro_internal);
connect(bacPro_internal.X_w, X_w_in_internal);
if allowFlowReversal
and Medium.nXi > 0
then
connect(X_w_in_internal, X_w_in);
else
X_w_in_internal = 0;
end if;
if allowFlowReversal
then
bacPro_internal.T = T_in;
bacPro_internal.C = C_in;
else
bacPro_internal.T = Medium.T_default;
bacPro_internal.C =
fill(0, Medium.nC);
end if;
if use_p_in
then
connect(inlet.p, p_in_internal);
else
p_in_internal = Medium.p_default;
end if;
connect(p, p_in_internal);
end Sink_T;
FMI model for a boundary with mass flow rate, pressure and temperature as an input
Information
Model of a source that takes as an input the mass flow rate,
pressure and the medium properties
temperature, mass fractions (if Medium.nXi > 0
)
and trace substances (if Medium.nC > 0
).
For a system of components with the connectors of the
Buildings.Fluid.FMI
package, this component is required to set the pressure
and the mass flow rate of the system.
Extends from Buildings.BaseClasses.BaseIcon (Base icon).
Parameters
Type | Name | Default | Description |
replaceable package Medium | Modelica.Media.Interfaces.Pa... | Medium in the component |
Boolean | use_p_in | true | = true to use a pressure from connector, false to output Medium.p_default |
Assumptions |
Boolean | allowFlowReversal | true | = true to allow flow reversal, false restricts to design direction (inlet -> outlet) |
Connectors
Type | Name | Description |
replaceable package Medium | Medium in the component |
input RealInput | m_flow_in | Prescribed mass flow source [kg/s] |
input PressureInput | p_in | Prescribed boundary pressure [Pa] |
input RealInput | T_in | Prescribed boundary temperature [K] |
input RealInput | X_w_in | Prescribed boundary composition [1] |
input RealInput | C_in[Medium.nC] | Prescribed boundary composition |
Outlet | outlet | Fluid port |
Modelica definition
model Source_T
extends Buildings.BaseClasses.BaseIcon;
replaceable package Medium =
Modelica.Media.Interfaces.PartialMedium ;
parameter Boolean allowFlowReversal = true ;
parameter Boolean use_p_in = true ;
Modelica.Blocks.Interfaces.RealInput m_flow_in(unit="kg/s") ;
Buildings.Fluid.FMI.Interfaces.PressureInput p_in
if
use_p_in ;
Modelica.Blocks.Interfaces.RealInput T_in(unit="K",
displayUnit="degC",
min=0) ;
Modelica.Blocks.Interfaces.RealInput X_w_in(unit="1")
if
Medium.nXi > 0 ;
Modelica.Blocks.Interfaces.RealInput C_in[Medium.nC] ;
Interfaces.Outlet outlet(
redeclare final package Medium =
Medium,
final allowFlowReversal=allowFlowReversal,
final use_p_in=use_p_in) ;
protected
Buildings.Fluid.FMI.Interfaces.PressureOutput p_in_internal ;
Buildings.Fluid.FMI.Interfaces.MassFractionConnector X_w_in_internal ;
initial equation
assert(Medium.nXi < 2,
"The medium must have zero or one independent mass fraction Medium.nXi.");
equation
if use_p_in
then
connect(p_in, p_in_internal);
else
p_in_internal = Medium.p_default;
end if;
connect(outlet.p, p_in_internal);
if Medium.nXi > 0
then
connect(X_w_in_internal, X_w_in);
else
X_w_in_internal = 0;
end if;
connect(outlet.forward.X_w, X_w_in_internal);
outlet.m_flow = m_flow_in;
connect(outlet.p, p_in);
outlet.forward.T = T_in;
outlet.forward.C = C_in;
end Source_T;
Container to export a thermofluid flow model with two ports as an FMU
Information
Partial model that can be used to export thermofluid flow models as an FMU.
This model only declares the inlet and outlet ports, the medium and
whether flow reversal is allowed.
See
Buildings.Fluid.FMI.Examples.FMUs.ResistanceVolume
for a block that extends this partial block.
Parameters
Type | Name | Default | Description |
replaceable package Medium | Modelica.Media.Interfaces.Pa... | Medium in the component |
Boolean | use_p_in | true | = true to use a pressure from connector, false to output Medium.p_default |
Assumptions |
Boolean | allowFlowReversal | true | = true to allow flow reversal, false restricts to design direction (inlet -> outlet) |
Connectors
Type | Name | Description |
replaceable package Medium | Medium in the component |
Inlet | inlet | Fluid inlet |
Outlet | outlet | Fluid outlet |
Modelica definition
partial block TwoPort
replaceable package Medium =
Modelica.Media.Interfaces.PartialMedium ;
parameter Boolean allowFlowReversal = true ;
parameter Boolean use_p_in = true ;
Interfaces.Inlet inlet(
redeclare final package Medium =
Medium,
final allowFlowReversal=allowFlowReversal,
final use_p_in=use_p_in) ;
Interfaces.Outlet outlet(
redeclare final package Medium =
Medium,
final allowFlowReversal=allowFlowReversal,
final use_p_in=use_p_in) ;
end TwoPort;
Container to export thermofluid flow models with two ports as an FMU
Information
Block that serves as a container to export a thermofluid flow component.
This block contains a replaceable model com
that needs to
be redeclared to export any model that has as its base class
Buildings.Fluid.Interfaces.PartialTwoPort.
This allows exporting a large variety of thermofluid flow models
with a simple redeclare.
See for example
Buildings.Fluid.FMI.Examples.FMUs.FixedResistanceDpM
or
Buildings.Fluid.FMI.Examples.FMUs.HeaterCooler_u
for how to use this block.
Note that this block must not be used if the instance com
sets a constant pressure. In such a situation, use
Buildings.Fluid.FMI.TwoPort
together with
Buildings.Fluid.FMI.InletAdaptor
and
Buildings.Fluid.FMI.OutletAdaptor
and set the pressure to be equal to the port p
of
Buildings.Fluid.FMI.OutletAdaptor.
Extends from TwoPort (Container to export a thermofluid flow model with two ports as an FMU).
Parameters
Type | Name | Default | Description |
replaceable package Medium | PartialMedium | Medium in the component |
Boolean | use_p_in | true | = true to use a pressure from connector, false to output Medium.p_default |
PartialTwoPort | com | redeclare Buildings.Fluid.In... | Component that holds the actual model |
Assumptions |
Boolean | allowFlowReversal | true | = true to allow flow reversal, false restricts to design direction (inlet -> outlet) |
Connectors
Type | Name | Description |
Inlet | inlet | Fluid inlet |
Outlet | outlet | Fluid outlet |
Modelica definition
block TwoPortComponent
extends TwoPort;
replaceable Buildings.Fluid.Interfaces.PartialTwoPort com
constrainedby Buildings.Fluid.Interfaces.PartialTwoPort(
redeclare final package Medium =
Medium,
final allowFlowReversal=allowFlowReversal) ;
Modelica.Blocks.Sources.RealExpression dpCom(y=com.port_a.p - com.port_b.p)
if
use_p_in ;
protected
Buildings.Fluid.FMI.InletAdaptor bouIn(
redeclare final package Medium=
Medium,
final allowFlowReversal=allowFlowReversal,
final use_p_in=use_p_in) ;
Buildings.Fluid.FMI.OutletAdaptor bouOut(
redeclare final package Medium=
Medium,
final allowFlowReversal=allowFlowReversal,
final use_p_in=use_p_in) ;
Modelica.Blocks.Math.Feedback pOut
if
use_p_in ;
equation
connect(pOut.u1, bouIn.p);
connect(com.port_a, bouIn.port_b);
connect(com.port_b, bouOut.port_a);
connect(inlet, bouIn.inlet);
connect(bouOut.outlet, outlet);
connect(dpCom.y, pOut.u2);
connect(pOut.y, bouOut.p);
end TwoPortComponent;
http://simulationresearch.lbl.gov/modelica