Buildings.Utilities.IO.BCVTB

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

Package Content

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


Buildings.Utilities.IO.BCVTB.BCVTB Buildings.Utilities.IO.BCVTB.BCVTB

Block that exchanges data with the Building Controls Virtual Test Bed

Buildings.Utilities.IO.BCVTB.BCVTB

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


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

Parameters

TypeNameDefaultDescription
TimesamplePeriod Sample period of component [s]
TimestartTime0First sample time instant [s]
StringxmlFileName"socket.cfg"Name of the file that is generated by the BCVTB and that contains the socket information
IntegernDblWri Number of double values to write to the BCVTB
IntegernDblRea Number of double values to be read from the BCVTB
IntegerflaDblWri[nDblWri]zeros(nDblWri)Flag for double values (0: use current value, 1: use average over interval, 2: use integral over interval)

Connectors

TypeNameDescription
input RealInputuR[nDblWri]Real inputs to be sent to the BCVTB
output RealOutputyR[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;
  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;

Buildings.Utilities.IO.BCVTB.MoistAirInterface Buildings.Utilities.IO.BCVTB.MoistAirInterface

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

Buildings.Utilities.IO.BCVTB.MoistAirInterface

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

TypeNameDefaultDescription
replaceable package MediumPartialMediumMedium model within the source
Booleanuse_m_flow_infalseGet the mass flow rate from the input connector
MassFlowRatem_flow0Fixed mass flow rate going out of the fluid port [kg/s]

Connectors

TypeNameDescription
input RealInputm_flow_inPrescribed mass flow rate
input RealInputT_inPrescribed boundary temperature
FluidPorts_bports[nPorts] 
output RealOutputHSen_flowSensible enthalpy flow rate, positive if flow into the component [W]
output RealOutputHLat_flowLatent enthalpy flow rate, positive if flow into the component [W]
input RealInputXWat_totAirPrescribed water vapor concentration in [kg/kg_totalAirMass]

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 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;

HTML-documentation generated by Dymola Tue Sep 29 08:10:18 2009.