Name | Description |
---|---|
UsersGuide | User's Guide |
BaseClasses | Package with base classes for BCVTB interface |
BCVTB | Block that exchanges data with the Building Controls Virtual Test Bed |
Examples | Collection of models that illustrate model use and test models |
MoistAirInterface | Fluid interface that can be coupled to BCVTB for medium that model the air humidity |
At the start of the simulation, this block establishes a socket connection using the Berkeley Software Distribution socket (BSD socket). At each sampling interval, data are exchanged between Modelica and the BCVTB. When Dymola terminates, a signal is sent to the BCVTB so that it can terminate gracefully.
For each element in the input vector uR[nDblWri]
,
the value of the flag flaDblWri[nDblWri]
determines whether
the current value, the average over the sampling interval or the integral
over the sampling interval is sent to the BCVTB. The following three options are allowed:
flaDblWri[i] | Value sent to the BCVTB |
0 | Current value of uR[i] |
1 | Average value of uR[i] over the sampling interval |
2 | Integral of uR[i] over the sampling interval |
Type | Name | Default | Description |
---|---|---|---|
Time | samplePeriod | Sample period of component [s] | |
Time | startTime | 0 | First sample time instant [s] |
String | xmlFileName | "socket.cfg" | Name of the file that is generated by the BCVTB and that contains the socket information |
Integer | nDblWri | Number of double values to write to the BCVTB | |
Integer | nDblRea | Number of double values to be read from the BCVTB | |
Integer | flaDblWri[nDblWri] | zeros(nDblWri) | Flag for double values (0: use current value, 1: use average over interval, 2: use integral over interval) |
Type | Name | Description |
---|---|---|
input RealInput | uR[nDblWri] | Real inputs to be sent to the BCVTB |
output RealOutput | yR[nDblRea] | Real outputs received from the BCVTB |
model BCVTB "Block that exchanges data with the Building Controls Virtual Test Bed" extends Modelica.Blocks.Interfaces.DiscreteBlock; parameter String xmlFileName = "socket.cfg" "Name of the file that is generated by the BCVTB and that contains the socket information"; parameter Integer nDblWri(min=0) "Number of double values to write to the BCVTB"; parameter Integer nDblRea(min=0) "Number of double values to be read from the BCVTB"; parameter Integer flaDblWri[nDblWri] = zeros(nDblWri) "Flag for double values (0: use current value, 1: use average over interval, 2: use integral over interval)"; Modelica.Blocks.Interfaces.RealInput uR[nDblWri] "Real inputs to be sent to the BCVTB"; Modelica.Blocks.Interfaces.RealOutput yR[nDblRea] "Real outputs received from the BCVTB"; Integer flaRea "Flag received from BCVTB"; Modelica.SIunits.Time simTimRea "Current simulation time received from the BCVTB"; Integer retVal "Return value from the BSD socket data exchange"; protected parameter Integer socketFD(fixed=false) "Socket file descripter, or a negative value if an error occured"; constant Integer flaWri=0; Real uRInt[nDblWri] "Value of integral"; Real uRIntPre[nDblWri] "Value of integral at previous sampling instance"; public Real uRWri[nDblWri] "Value to be sent to the interface"; initial algorithm socketFD :=Buildings.Utilities.IO.BCVTB.BaseClasses.establishClientSocket( xmlFileName=xmlFileName); // check for valid socketFD assert(socketFD >= 0, "Socket file descripter for BCVTB must be positive.\n" + " A negative value indicates that no connection\n" + " could be established. Check file 'utilSocket.log'.\n" + " Received: socketFD = " + integerString(socketFD)); flaRea := 0; uRInt := zeros(nDblWri); uRIntPre := zeros(nDblWri); equation for i in 1:nDblWri loop der(uRInt[i]) = if (flaDblWri[i] > 0) then uR[i] else 0; end for; algorithm when {sampleTrigger} then assert(flaRea == 0, "BCVTB interface attempts to exchange data after Ptolemy reached its final time.\n" + " Aborting simulation. Check final time in Modelica and in Ptolemy.\n" + " Received: flaRea = " + integerString(flaRea)); // Compute value that will be sent to the BCVTB interface for i in 1:nDblWri loop if (flaDblWri[i] == 0) then uRWri[i] :=pre(uR[i]); // Send the current value. // Without the pre(), Dymola 7.2 crashes during translation of Examples.MoistAir else uRWri[i] :=uRInt[i] - uRIntPre[i]; // Integral over the sampling interval if (flaDblWri[i] == 1) then uRWri[i] := uRWri[i]/samplePeriod; // Average value over the sampling interval end if; end if; end for; // Exchange data (flaRea, simTimRea, yR, retVal) := Buildings.Utilities.IO.BCVTB.BaseClasses.exchangeReals( socketFD=socketFD, flaWri=flaWri, simTimWri=time, dblValWri=uRWri, nDblWri=size(uRWri, 1), nDblRea=size(yR, 1)); // Check for valid return flags assert(flaRea >= 0, "BCVTB sent a negative flag to Modelica during data transfer.\n" + " Aborting simulation. Check file 'utilSocket.log'.\n" + " Received: flaRea = " + integerString(flaRea)); assert(retVal >= 0, "Obtained negative return value during data transfer with BCVTB.\n" + " Aborting simulation. Check file 'utilSocket.log'.\n" + " Received: retVal = " + integerString(retVal)); // Store current value of integral uRIntPre:=uRInt; end when; // Close socket connnection when terminal() then Buildings.Utilities.IO.BCVTB.BaseClasses.closeClientSocket( socketFD); end when; end BCVTB;
The model takes as input signals the temperature and water vapor concentration and, optionally, a bulk mass flow rate into or out of the system boundary. The state of the fluid that flows out of this model will be at this temperature and water vapor concentration. The output of this model are the sensible and latent heat exchanged across the system boundary.
When used with the BCVTB, a building simulation program such as EnergyPlus may compute the room air temperatures and room air humidity rate, which is then used as an input to this model. The sensible and latent heat flow rates may be sent to EnergyPlus to couple the air-conditioning system to the energy balance of the building model.
Note: The EnergyPlus building simulation program outputs the
absolute humidity ratio in units of [kg/kg dry air]. Since
Modelica.Media
uses [kg/kg total mass of air], this quantity
needs to be converted. The conversion can be done with the model
Buildings.Utilities.Psychrometrics.ToTotalAir.
Type | Name | Default | Description |
---|---|---|---|
replaceable package Medium | PartialMedium | Medium model within the source | |
Boolean | use_m_flow_in | false | Get the mass flow rate from the input connector |
MassFlowRate | m_flow | 0 | Fixed mass flow rate going out of the fluid port [kg/s] |
Type | Name | Description |
---|---|---|
input RealInput | m_flow_in | Prescribed mass flow rate |
input RealInput | T_in | Prescribed boundary temperature |
FluidPorts_b | ports[nPorts] | |
output RealOutput | HSen_flow | Sensible enthalpy flow rate, positive if flow into the component [W] |
output RealOutput | HLat_flow | Latent enthalpy flow rate, positive if flow into the component [W] |
input RealInput | XWat_totAir | Prescribed water vapor concentration in [kg/kg_totalAirMass] |
model MoistAirInterface "Fluid interface that can be coupled to BCVTB for medium that model the air humidity" extends Buildings.Utilities.IO.BCVTB.BaseClasses.FluidInterface(bou( final use_X_in=true)); Modelica.Blocks.Interfaces.RealOutput HLat_flow(unit="W") "Latent enthalpy flow rate, positive if flow into the component"; Buildings.Fluid.Sensors.SensibleEnthalpyFlowRate senEntFloRat[nPorts]( redeclare package Medium = Medium) "Sensible enthalpy flow rates"; public Modelica.Blocks.Math.Sum sumHSen_flow(nin=nPorts) "Sum of sensible enthalpy flow rates"; Modelica.Blocks.Math.Feedback diff "Difference between total and sensible enthalpy flow rate"; Modelica.Blocks.Interfaces.RealInput XWat_totAir "Prescribed water vapor concentration in [kg/kg_totalAirMass]"; Modelica.Blocks.Sources.Constant uni(k=1) "Outputs 1"; Modelica.Blocks.Math.Feedback feedback; equation for i in 1:nPorts loop connect(senEntFloRat[i].port_a, ports[i]); connect(senEntFloRat[i].H_flow, sumHSen_flow.u[i]); end for; connect(senEntFloRat.port_b, totEntFloRat.port_a); connect(sumHSen_flow.y, HSen_flow); connect(sumHTot_flow.y, diff.u1); connect(diff.y, HLat_flow); connect(diff.u2, sumHSen_flow.y); connect(feedback.y, bou.X_in[2]); connect(XWat_totAir, feedback.u2); connect(uni.y, feedback.u1); connect(bou.X_in[1], XWat_totAir); end MoistAirInterface;