Package with base classes for Buildings.ThermalZones.EnergyPlus_9_6_0
Information
This package contains base classes that are used to construct the models in
Buildings.ThermalZones.EnergyPlus_9_6_0.
Extends from Modelica.Icons.BasesPackage (Icon for packages containing base classes).
Package Content
Name |
Description |
PartialEnergyPlusObject
|
Partial definitions of an EnergyPlus object |
SpawnExternalObject
|
Class used to couple the FMU to interact with a thermal zone |
ThermalZoneAdapter
|
Block that interacts with this EnergyPlus zone |
exchange
|
Exchange the values with the EnergyPlus thermal zone |
getParameters
|
Get parameters for an EnergyPlus object |
getUnitAsString
|
Return the unit enumeration as a string |
initialize
|
Initialization for an EnergyPlus thermal zone |
Synchronize
|
Package with classes to synchronize Spawn objects |
buildingsRootFileLocation=Modelica.Utilities.Files.loadResource("modelica://Buildings/legal.html") |
Path to top-level legal.html of the Buildings library (used to find the spawn executable) |
Validation
|
Collection of validation models |
Types and constants
constant String buildingsRootFileLocation=
Modelica.Utilities.Files.loadResource("modelica://Buildings/legal.html")
;
Partial definitions of an EnergyPlus object
Information
Partial model for an EnergyPlus object.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).
Modelica definition
partial block PartialEnergyPlusObject
extends Modelica.Blocks.Icons.Block;
outer Buildings.ThermalZones.EnergyPlus_9_6_0.Building building
;
protected
constant String modelicaNameBuilding=building.modelicaNameBuilding
;
constant String modelicaInstanceName=
getInstanceName()
;
constant String spawnExe=building.spawnExe
;
constant String idfVersion = building.idfVersion
;
final parameter String idfName=building.idfName
;
final parameter String epwName=building.epwName
;
final parameter Real relativeSurfaceTolerance=building.relativeSurfaceTolerance
;
final parameter Boolean usePrecompiledFMU=building.usePrecompiledFMU
;
final parameter String fmuName=building.fmuName
;
final parameter Buildings.ThermalZones.EnergyPlus_9_6_0.Types.LogLevels logLevel=building.logLevel
;
parameter Modelica.Units.SI.Time startTime(fixed=false)
;
function round
input Real u;
input Real accuracy;
output Real y;
algorithm
y :=
if
(u > 0)
then
floor(
u/accuracy+0.5)*accuracy
else
ceil(
u/accuracy-0.5)*accuracy;
end round;
initial equation
startTime=time;
end PartialEnergyPlusObject;
Class used to couple the FMU to interact with a thermal zone
Information
Class derived from ExternalObject
having two local external function definition,
named destructor
and constructor
respectively.
These functions create and release an external object that allows the storage
of the data structure needed to communicate with the EnergyPlus FMU.
Extends from ExternalObject.
Modelica definition
class SpawnExternalObject
extends ExternalObject;
impure function constructor
extends Modelica.Icons.Function;
input Integer objectType
;
input Modelica.Units.SI.Time startTime ;
input String modelicaNameBuilding
;
input String modelicaInstanceName
;
input String spawnExe
;
input String idfVersion
;
input String idfName
;
input String epwName
;
input Real relativeSurfaceTolerance
;
input String epName
;
input Boolean usePrecompiledFMU
;
input String fmuName
;
input String buildingsRootFileLocation
;
input Buildings.ThermalZones.EnergyPlus_9_6_0.Types.LogLevels logLevel
;
input Boolean printUnit
;
input String jsonName
;
input String jsonKeysValues
;
input String parOutNames[nParOut]
;
input String parOutUnits[nParOut]
;
input Integer nParOut
;
input String inpNames[nInp]
;
input String inpUnits[nInp]
;
input Integer nInp
;
input String outNames[nOut]
;
input String outUnits[nOut]
;
input Integer nOut
;
input Integer derivatives_structure[nDer,2]
;
input Integer nDer
;
input Real derivatives_delta[nDer]
;
output SpawnExternalObject adapter;
external "C" adapter=
allocate_Modelica_EnergyPlus_9_6_0(
objectType,
startTime,
modelicaNameBuilding,
modelicaInstanceName,
spawnExe,
idfVersion,
idfName,
epwName,
relativeSurfaceTolerance,
epName,
usePrecompiledFMU,
fmuName,
buildingsRootFileLocation,
logLevel,
printUnit,
jsonName,
jsonKeysValues,
parOutNames,
nParOut,
parOutUnits,
nParOut,
inpNames,
nInp,
inpUnits,
nInp,
outNames,
nOut,
outUnits,
nOut,
derivatives_structure,
2,
nDer,
derivatives_delta,
nDer);
end constructor;
pure function destructor
extends Modelica.Icons.Function;
input SpawnExternalObject adapter;
external "C"
free_Modelica_EnergyPlus_9_6_0(adapter);
end destructor;
end SpawnExternalObject;
Block that interacts with this EnergyPlus zone
Information
Block that exchanges data between Modelica and EnergyPlus.
This block is calling the C functions to initialize EnergyPlus,
exchange data with EnergyPlus, and free the memory, through the destructor
of its class adapter
, of EnergyPlus.
Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block), Buildings.ThermalZones.EnergyPlus_9_6_0.BaseClasses.Synchronize.ObjectSynchronizer (Block that synchronizes an object).
Parameters
Type | Name | Default | Description |
String | modelicaNameBuilding | | Name of the building to which this thermal zone belongs to |
String | spawnExe | | Name of the spawn executable, without extension, such as spawn-0.2.0-d7f1e095f3 |
String | idfVersion | | IDF version with underscore, used for error report |
String | idfName | | Name of the IDF file that contains this zone |
String | epwName | | Name of the Energyplus weather file including the epw extension |
Real | relativeSurfaceTolerance | | Relative tolerance of surface temperature calculations |
String | zoneName | | Name of the thermal zone as specified in the EnergyPlus input |
Integer | nFluPor | | Number of fluid ports (Set to 2 for one inlet and one outlet) |
Debug |
Boolean | usePrecompiledFMU | false | Set to true to use pre-compiled FMU with name specified by fmuName |
String | fmuName | "" | Specify if a pre-compiled FMU should be used instead of EnergyPlus (mainly for development) |
LogLevels | logLevel | Buildings.ThermalZones.Energ... | LogLevels of EnergyPlus output |
Connectors
Type | Name | Description |
input RealInput | T | Zone air temperature [K] |
input RealInput | X_w | Zone air mass fraction in kg/kg total air [kg/kg] |
input RealInput | m_flow[nFluPor] | Mass flow rate [kg/s] |
input RealInput | TInlet[nFluPor] | Air inlet temperatures [K] |
input RealInput | QGaiRad_flow | Radiative heat gain [W] |
output RealOutput | TRad | Radiative temperature [K] |
output RealOutput | QCon_flow | Convective sensible heat to be added to zone air [W] |
output RealOutput | QLat_flow | Latent heat to be added to zone air [W] |
output RealOutput | QPeo_flow | Total heat gain from people, to be used for optional computation of CO2 released [W] |
Modelica definition
model ThermalZoneAdapter
extends Modelica.Blocks.Icons.Block;
extends Buildings.ThermalZones.EnergyPlus_9_6_0.BaseClasses.Synchronize.ObjectSynchronizer;
constant String modelicaNameBuilding
;
constant String modelicaInstanceName=
getInstanceName()
;
constant String spawnExe
;
constant String idfVersion
;
parameter String idfName
;
parameter String epwName
;
parameter Real relativeSurfaceTolerance
;
parameter String zoneName
;
parameter Boolean usePrecompiledFMU=false
;
parameter String fmuName=""
;
parameter Buildings.ThermalZones.EnergyPlus_9_6_0.Types.LogLevels logLevel=Buildings.ThermalZones.EnergyPlus_9_6_0.Types.LogLevels.Warning
;
parameter Integer nFluPor
;
final parameter Modelica.Units.SI.Area AFlo(fixed=false) ;
final parameter Modelica.Units.SI.Volume V(fixed=false) ;
final parameter Real mSenFac(
fixed=false)
;
Modelica.Blocks.Interfaces.RealInput T(
final unit="K",
displayUnit="degC")
;
Modelica.Blocks.Interfaces.RealInput X_w(
final unit="kg/kg")
;
Modelica.Blocks.Interfaces.RealInput m_flow[nFluPor](
each final unit="kg/s")
;
Modelica.Blocks.Interfaces.RealInput TInlet[nFluPor](
each final unit="K",
each displayUnit="degC")
;
Modelica.Blocks.Interfaces.RealInput QGaiRad_flow(
final unit="W")
;
Modelica.Blocks.Interfaces.RealOutput TRad(
final unit="K",
displayUnit="degC")
;
Modelica.Blocks.Interfaces.RealOutput QCon_flow(
final unit="W")
;
Modelica.Blocks.Interfaces.RealOutput QLat_flow(
final unit="W")
;
Modelica.Blocks.Interfaces.RealOutput QPeo_flow(
final unit="W")
;
protected
constant Integer nParOut=3
;
constant Integer nInp=5
;
constant Integer nOut=4
;
constant Integer nDer=0
;
constant Integer nY=nOut+nDer+1
;
parameter Integer nObj(
fixed=false,
start=0)
;
parameter Modelica.Units.SI.MassFlowRate m_flow_small(fixed=false)
;
Buildings.ThermalZones.EnergyPlus_9_6_0.BaseClasses.SpawnExternalObject adapter=
Buildings.ThermalZones.EnergyPlus_9_6_0.BaseClasses.SpawnExternalObject(
objectType=1,
startTime=startTime,
modelicaNameBuilding=modelicaNameBuilding,
modelicaInstanceName=modelicaInstanceName,
spawnExe=spawnExe,
idfVersion=idfVersion,
idfName=idfName,
epwName=epwName,
relativeSurfaceTolerance=relativeSurfaceTolerance,
epName=zoneName,
usePrecompiledFMU=usePrecompiledFMU,
fmuName=fmuName,
buildingsRootFileLocation=Buildings.ThermalZones.EnergyPlus_9_6_0.BaseClasses.buildingsRootFileLocation,
logLevel=logLevel,
printUnit=false,
jsonName="zones",
jsonKeysValues=" \"name\": \""+zoneName+"\"",
parOutNames={"AFlo","V","mSenFac"},
parOutUnits={"m2","m3","1"},
nParOut=nParOut,
inpNames={"T","X","mInlets_flow","TAveInlet","QGaiRad_flow"},
inpUnits={"K","1","kg/s","K","W"},
nInp=nInp,
outNames={"TRad","QConSen_flow","QLat_flow","QPeo_flow"},
outUnits={"K","W","W","W"},
nOut=nOut,
derivatives_structure=
fill(
fill(nDer,2),nDer),
nDer=nDer,
derivatives_delta=
fill(0,nDer))
;
parameter Modelica.Units.SI.Time startTime(fixed=false)
;
Real yEP[nY]
;
Modelica.Units.SI.Time tNext(start=startTime, fixed=true)
;
discrete Modelica.Units.SI.Time tLast(fixed=true, start=startTime)
;
discrete Modelica.Units.SI.Time dtLast
;
discrete Modelica.Units.SI.MassFlowRate mInlet_flow(
start=0,
fixed=true)
;
discrete Modelica.Units.SI.Temperature TAveInlet
;
discrete Modelica.Units.SI.Temperature TRooLast
;
discrete Modelica.Units.SI.HeatFlowRate QConLast_flow(fixed=false, start=0)
;
function round
input Real u;
input Real accuracy;
output Real y;
algorithm
y :=
if
(u > 0)
then
floor(
u/accuracy+0.5)*accuracy
else
ceil(
u/accuracy-0.5)*accuracy;
end round;
initial equation
if usePrecompiledFMU
then
assert(
Modelica.Utilities.Strings.length(fmuName) > 1,
"If usePrecompiledFMU = true, must set parameter fmuName");
end if;
startTime=time;
nObj=
Buildings.ThermalZones.EnergyPlus_9_6_0.BaseClasses.initialize(
adapter=adapter,
isSynchronized=building.isSynchronized);
{AFlo,V,mSenFac}=
Buildings.ThermalZones.EnergyPlus_9_6_0.BaseClasses.getParameters(
adapter=adapter,
nParOut=nParOut,
isSynchronized=nObj);
TAveInlet=293.15;
m_flow_small=V*3*1.2/3600*1E-10;
assert(
AFlo > 0,
"Floor area must not be zero.");
assert(
V > 0,
"Volume must not be zero.");
assert(
mSenFac > 0.9999,
"mSenFac must be bigger or equal than one.");
equation
if usePrecompiledFMU
then
assert(
Modelica.Utilities.Strings.length(fmuName) > 1,
"If usePrecompiledFMU = true, must set parameter fmuName");
end if;
when {
initial(),time >=
pre(tNext)}
then
TRooLast=T;
dtLast=time-
pre(tLast);
mInlet_flow=
noEvent(
sum(
if m_flow[i] > 0
then
m_flow[i]
else
0
for i
in 1:nFluPor));
TAveInlet=
noEvent(
(
sum(
if m_flow[i] > 0
then
TInlet[i]*m_flow[i]
else
0
for i
in 1:nFluPor)+m_flow_small*
pre(TAveInlet))/(mInlet_flow+m_flow_small));
yEP=
Buildings.ThermalZones.EnergyPlus_9_6_0.BaseClasses.exchange(
adapter=adapter,
initialCall=false,
nY=nY,
u={T,X_w/(1.-X_w),
pre(mInlet_flow),TAveInlet,
pre(QGaiRad_flow),
round(time,1E-3)},
dummy=AFlo);
TRad=yEP[1];
QConLast_flow=yEP[2];
QLat_flow=yEP[3];
QPeo_flow=yEP[4];
tNext=yEP[5];
tLast=time;
end when;
QCon_flow=QConLast_flow;
synBui.synchronize.done=nObj;
end ThermalZoneAdapter;
Exchange the values with the EnergyPlus thermal zone
Information
External function that exchanges data with EnergyPlus.
Extends from Modelica.Icons.Function (Icon for functions).
Inputs
Outputs
Type | Name | Description |
Real | y[nY] | Output values. First all outputs, then all derivatives, then next event time |
Modelica definition
Get parameters for an EnergyPlus object
Information
External function that obtains parameters from the EnergyPlus FMU
and returns them to Modelica.
Extends from Modelica.Icons.Function (Icon for functions).
Inputs
Outputs
Type | Name | Description |
Real | parOut[nParOut] | Parameter values returned from EnergyPlus |
Modelica definition
Return the unit enumeration as a string
Information
Function that returns the string representation of a unit enumeration from
Buildings.ThermalZones.EnergyPlus_9_6_0.Types.Units.
Extends from Modelica.Icons.Function (Icon for functions).
Inputs
Outputs
Type | Name | Description |
String | unitAsString | String representation of the unit |
Modelica definition
pure function getUnitAsString
extends Modelica.Icons.Function;
input Buildings.ThermalZones.EnergyPlus_9_6_0.Types.Units unit
;
output String unitAsString
;
algorithm
unitAsString :=
if unit == Types.Units.Normalized
then
"1"
elseif unit == Types.Units.AngleRad
then
"rad"
elseif unit == Types.Units.AngleDeg
then
"deg"
elseif unit == Types.Units.Energy
then
"J"
elseif unit == Types.Units.Illuminance
then
"lm/m2"
elseif unit == Types.Units.HumidityAbsolute
then
"kg/kg"
elseif unit == Types.Units.HumidityRelative
then
"1"
elseif unit == Types.Units.LuminousFlux
then
"cd.sr"
elseif unit == Types.Units.MassFlowRate
then
"kg/s"
elseif unit == Types.Units.Power
then
"W"
elseif unit == Types.Units.Pressure
then
"Pa"
elseif unit == Types.Units.Status
then
"1"
elseif unit == Types.Units.Temperature
then
"K"
elseif unit == Types.Units.Time
then
"s"
elseif unit == Types.Units.VolumeFlowRate
then
"m3/s"
else
"error";
end getUnitAsString;
Initialization for an EnergyPlus thermal zone
Information
External function that generates the EnergyPlus FMU.
Extends from Modelica.Icons.Function (Icon for functions).
Inputs
Outputs
Type | Name | Description |
Integer | nObj | Returns 1 from C, used to force synchronization |
Modelica definition