Description: "Package with functions to communicate with the Building Controls Virtual Test Bed"

- Home > Modelica

## Buildings.Utilities.IO.BCVTB

Package with functions to communicate with the Building Controls Virtual Test Bed

### Information

Extends from Modelica.Icons.VariantsPackage (Icon for package containing variants).

### Package Content

Name | Description
--- | ---
UsersGuide | User's Guide
BCVTB | Block that exchanges data with the Building Controls Virtual Test Bed
From_degC | Converts Celsius to Kelvin
MoistAirInterface | Fluid interface that can be coupled to BCVTB for medium that model the air humidity
To_degC | Converts Kelvin to Celsius
Examples | Collection of models that illustrate model use and test models
BaseClasses | Package with base classes for Buildings.Utilities.IO.BCVTB

## Buildings.Utilities.IO.BCVTB.BCVTB

Block that exchanges data with the Building Controls Virtual Test Bed

### Information

Block that exchanges data with the Building Controls Virtual Test Bed (BCVTB).

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

For the first call to the BCVTB interface, the value of the parameter `uStart[nDblWri]` will be used instead of `uR[nDblWri]`. This avoids an algebraic loop when determining the initial conditions. If `uR[nDblWri]` were to be used, then computing the initial conditions may require an iterative solution in which the function `exchangeWithSocket` may be called multiple times. Unfortunately, it does not seem possible to use a parameter that would give a user the option to either select `uR[i]` or `uStart[i]` in the first data exchange. The reason is that the symbolic solver does not evaluate the test that picks `uR[i]` or `uStart[i]`, and hence there would be an algebraic loop.

If the parameter `activateInterface` is set to false, then no data is exchanged with the BCVTB. The output of this block is then equal to the value of the parameter `yRFixed[nDblRea]`. This option can be helpful during debugging. Since during model translation, the functions are still linked to the C library, the header files and libraries need to be present in the current working directory even if `activateInterface=false`.

Extends from Modelica.Blocks.Interfaces.DiscreteBlock (Base class of discrete control blocks).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
Time | samplePeriod | if activateInterface then ti... | Sample period of component [s]
Time | startTime | 0 | First sample time instant [s]
Boolean | activateInterface | true | Set to false to deactivate interface and use instead yFixed as output
Time | timeStep |  | Time step used for the synchronization [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)
Real | uStart[nDblWri] |  | Initial input signal, used during first data transfer with BCVTB
Real | yRFixed[nDblRea] | zeros(nDblRea) | Fixed output, used if activateInterface=false

### Connectors

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

### Modelica definition

model BCVTB "Block that exchanges data with the Building Controls Virtual Test Bed" extends Modelica.Blocks.Interfaces.DiscreteBlock(final startTime=0, final samplePeriod = if activateInterface then timeStep else Modelica.Constants.inf); parameter Boolean activateInterface = true "Set to false to deactivate interface and use instead yFixed as output"; parameter Modelica.SIunits.Time timeStep "Time step used for the synchronization"; 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)"; parameter Real uStart[nDblWri] "Initial input signal, used during first data transfer with BCVTB"; parameter Real yRFixed[nDblRea] = zeros(nDblRea) "Fixed output, used if activateInterface=false"; 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 occurred"; parameter Real _uStart[nDblWri](fixed=false) "Initial input signal, used during first data transfer with BCVTB"; 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 :=if activateInterface then Buildings.Utilities.IO.BCVTB.BaseClasses.establishClientSocket(xmlFileName=xmlFileName) else 0; // 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 = " + String(socketFD)); flaRea := 0; uRInt := zeros(nDblWri); uRIntPre := zeros(nDblWri); for i in 1:nDblWri loop assert(flaDblWri[i]>=0 and flaDblWri[i]<=2, "Parameter flaDblWri out of range for " + String(i) + "-th component."); if (flaDblWri[i] == 0) then _uStart[i] := uStart[i]; // Current value. elseif (flaDblWri[i] == 1) then _uStart[i] := uStart[i]; // Average over interval else _uStart[i] := uStart[i]*samplePeriod; // Integral over the sampling interval // This is multiplied with samplePeriod because if // u is power, then uRWri needs to be energy. end if; end for; // Exchange initial values if activateInterface then (flaRea, simTimRea, yR, retVal) := Buildings.Utilities.IO.BCVTB.BaseClasses.exchangeReals( socketFD=socketFD, flaWri=flaWri, simTimWri=time, dblValWri=_uStart, nDblWri=size(uRWri, 1), nDblRea=size(yR, 1)); else flaRea := 0; simTimRea := time; yR := yRFixed; retVal := 0; end if; 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 = " + String(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 if activateInterface then (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)); else flaRea := 0; simTimRea := time; yR := yRFixed; retVal := 0; end if; // 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 = " + String(flaRea)); assert(retVal >= 0, "Obtained negative return value during data transfer with BCVTB.\n" + " Aborting simulation. Check file 'utilSocket.log'.\n" + " Received: retVal = " + String(retVal)); // Store current value of integral uRIntPre:=uRInt; end when; // Close socket connnection when terminal() then if activateInterface then Buildings.Utilities.IO.BCVTB.BaseClasses.closeClientSocket( socketFD); end if; end when; end BCVTB;

## Buildings.Utilities.IO.BCVTB.From_degC

Converts Celsius to Kelvin

### Information

Converts the input from Kelvin to degree Celsius. Note that inside Modelica, by convention, all models use Kelvin. This block is provided for convenience since the BCVTB interface may couple Modelica to programs that use Celsius as the unit for temperature.

Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).

### Connectors

Type | Name | Description
--- | --- | ---
input RealInput | Celsius | Temperature in Celsius [degC]
output RealOutput | Kelvin | Temperature in Kelvin [K]

### Modelica definition

block From_degC "Converts Celsius to Kelvin" extends Modelica.Blocks.Icons.Block; Modelica.Blocks.Interfaces.RealInput Celsius(final quantity="ThermodynamicTemperature", final unit = "degC", displayUnit = "degC", min=-273.15) "Temperature in Celsius"; Modelica.Blocks.Interfaces.RealOutput Kelvin(final quantity="ThermodynamicTemperature", final unit = "K", displayUnit = "degC", min=0) "Temperature in Kelvin"; equation Celsius = Modelica.SIunits.Conversions.to_degC(Kelvin); end From_degC;

## Buildings.Utilities.IO.BCVTB.MoistAirInterface

Fluid interface that can be coupled to BCVTB for medium that model the air humidity

### Information

This model allows interfacing to the Building Controls Virtual Test Bed an air-conditioning system that uses a medium model with water vapor concentration.

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.

Extends from Buildings.Utilities.IO.BCVTB.BaseClasses.FluidInterface (Partial class for fluid interface that can be coupled to BCVTB).

### Parameters

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]
Nominal condition
MassFlowRate | m_flow_nominal |  | Nominal mass flow rate, used for regularization near zero flow [kg/s]
Advanced
MassFlowRate | m_flow_small | 1E-4*m_flow_nominal | For bi-directional flow, temperature is regularized in the region |m_flow| < m_flow_small (m_flow_small > 0 required) [kg/s]

### Connectors

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 | phi | Medium relative humidity

### Modelica definition

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 final package Medium = Medium, each final m_flow_nominal=m_flow_nominal) "Sensible enthalpy flow rates"; 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 phi "Medium relative humidity"; Buildings.Utilities.Psychrometrics.X_pTphi masFra(use_p_in=false) "Mass fraction"; 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(masFra.T, T_in); connect(masFra.phi, phi); connect(masFra.X, bou.X_in); end MoistAirInterface;

## Buildings.Utilities.IO.BCVTB.To_degC

Converts Kelvin to Celsius

### Information

Converts the input from degree Celsius to Kelvin. Note that inside Modelica, it is strongly recommended to use Kelvin. This block is provided for convenience since the BCVTB interface may couple Modelica to programs that use Celsius as the unit for temperature.

Extends from Modelica.Blocks.Icons.Block (Basic graphical layout of input/output block).

### Connectors

Type | Name | Description
--- | --- | ---
input RealInput | Kelvin | Temperature in Kelvin [K]
output RealOutput | Celsius | Temperature in Celsius [degC]

### Modelica definition

block To_degC "Converts Kelvin to Celsius" extends Modelica.Blocks.Icons.Block; Modelica.Blocks.Interfaces.RealInput Kelvin(final quantity="ThermodynamicTemperature", final unit = "K", displayUnit = "degC", min=0) "Temperature in Kelvin"; Modelica.Blocks.Interfaces.RealOutput Celsius(final quantity="ThermodynamicTemperature", final unit = "degC", displayUnit = "degC", min=-273.15) "Temperature in Celsius"; equation Kelvin = Modelica.SIunits.Conversions.from_degC(Celsius); end To_degC;