Validation model for the room temperature controller that takes the surface temperature set point as an input. This example validates the room temperature controller

Buildings.Controls.OBC.RadiantSystems.Cooling.HighMassSupplyTemperature_TSurRelHum
for the radiant system.
The validation model applies a
ramp signal for the measured surface temperature and a tabulated signal to the controller input for the measured room air temperature.
The model also calculates the dew point temperature to verify that the supply water temperature is never below the dew point.

within Buildings.Controls.OBC.RadiantSystems.Cooling.Validation;
model HighMassSupplyTemperature_TSurRelHum
  "Validation model for the room temperature controller that takes the surface temperature set point as an input"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable TPhiRooMea(
    table=[0.0, 18, 0.5;
           0.5, 28, 0.5;
           1.0, 18, 0.5;
           1.0, 18, 0.9;
           1.5, 28, 0.9;
           2.0, 18, 0.9],
    extrapolation=Buildings.Controls.OBC.CDL.Types.Extrapolation.HoldLastPoint,
    offset={273.15, 0},
    timeScale=3600) "Measured room temperature and relative humidity"

  Buildings.Controls.OBC.RadiantSystems.Cooling.HighMassSupplyTemperature_TSurRelHum
                                                                            conCoo(
      TSupSet_min=291.15) "Controller"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSurSet(final k(
      final unit="K",
      displayUnit="degC") = 293.15) "Set point temperature for surface"

  CDL.Psychrometrics.DewPoint_TDryBulPhi dewPoi "Dew point temperature"
  CDL.Reals.Sources.Ramp     TSur(
    height=1,
    duration=1800,
    offset=293.15)                  "Measured surface temperature"
equation
  connect(TPhiRooMea.y[1], conCoo.TRoo)
  connect(TPhiRooMea.y[2], conCoo.phiRoo)
  connect(dewPoi.TDryBul, TPhiRooMea.y[1])
  connect(dewPoi.phi, TPhiRooMea.y[2])
  connect(conCoo.TSurSet, TSurSet.y)
  connect(TSur.y, conCoo.TSur)
end HighMassSupplyTemperature_TSurRelHum;


Collection of validation models

within Buildings.Controls.OBC.RadiantSystems.Cooling;
package Validation "Collection of validation models"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


Room temperature controller for radiant heating with constant mass flow and variable supply temperature. Controller for a radiant heating system.

within Buildings.Controls.OBC.RadiantSystems.Heating;
block HighMassSupplyTemperature_TRoom
  "Room temperature controller for radiant heating with constant mass flow and variable supply temperature"

  parameter Real TSupSet_max(
    final unit="K",
    displayUnit="degC") "Maximum heating supply water temperature";
  parameter Real TSupSet_min(
    final unit="K",
    displayUnit="degC") = 293.15 "Minimum heating supply water temperature";

  parameter Controls.OBC.CDL.Types.SimpleController controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.P
    "Type of controller"
  parameter Real k(
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=2
    "Gain of controller"
  parameter Real Ti(
    final quantity="Time",
    final unit="s",
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=3600
    "Time constant of integrator block"
  parameter Real Td(
    final quantity="Time",
    final unit="s",
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=0.1
    "Time constant of derivative block"

  Controls.OBC.CDL.Interfaces.RealInput TRooSet(
    final unit="K",
    displayUnit="degC")
    "Set point for room air temperature"
  Controls.OBC.CDL.Interfaces.RealInput TRoo(
    final unit="K",
    displayUnit="degC") "Measured room air temperature"
  Controls.OBC.CDL.Interfaces.RealOutput TSupSet(
    final unit="K",
    displayUnit="degC")
    "Set point for heating supply water temperature"

  Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit="1",
    final min=0,
    final max=1)
    "Control signal for heating system from P controller"

  Controls.OBC.CDL.Interfaces.BooleanOutput on
    "Outputs true if the system is demanded on"

  Controls.OBC.CDL.Interfaces.RealOutput yPum(
    final unit="1",
    final min=0,
    final max=1)
    "Pump speed control signal"

  Buildings.Controls.OBC.CDL.Reals.PID conHea(
    final controllerType=controllerType,
    final k=k,
    final Ti = Ti,
    final Td = Td,
    final yMax=1,
    final yMin=0,
    final reverseActing=true) "Controller for heating supply set point signal"

  Buildings.Controls.OBC.CDL.Reals.Hysteresis hysHea(
    uLow=0.1,
    uHigh=0.2)
    "Hysteresis to switch system on and off"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one(final k=1) "Outputs one"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant zero(final k=0) "Outputs zero"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaSup_minimum(final k(
      final unit="K",
      displayUnit="degC") = TSupSet_min)
    "Negative value of minimum heating supply water temperature"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaSup_maximum(
    final k(
      final unit="K",
      displayUnit="degC") = TSupSet_max) "Maximum heating supply water temperature"

  Buildings.Controls.OBC.CDL.Reals.Line TSup(
    limitBelow=false,
    limitAbove=false,
    y(final unit="K",
      displayUnit="degC")) "Set point for supply water temperature"

  CDL.Conversions.BooleanToReal booToRea(
    final realFalse=0,
    final realTrue=1)
    "Pump control signal as a Real number (either 0 or 1)"
equation
  connect(conHea.y,hysHea.u)
  connect(TRoo, conHea.u_m)
  connect(TRooSet, conHea.u_s)
  connect(TSup.x1, zero.y)
  connect(one.y, TSup.x2)
  connect(conHea.y, TSup.u)
  connect(TSup.f1, THeaSup_minimum.y)
  connect(THeaSup_maximum.y, TSup.f2)
  connect(TSup.y, TSupSet)
  connect(hysHea.y, on)
  connect(conHea.y, y)
  connect(booToRea.y, yPum)
  connect(booToRea.u, hysHea.y)
end HighMassSupplyTemperature_TRoom;


within Buildings.Controls.OBC.RadiantSystems;
package Heating "Package with control sequences for radiant heating systems"
  extends Modelica.Icons.Package;
end Heating;


Validation model for the room temperature controller. This example validates the room temperature controller

Buildings.Controls.OBC.RadiantSystems.Heating.HighMassSupplyTemperature_TRoom
for the radiant system.
The validation model applies a ramp signal to the controller input for the measured room air temperature.

within Buildings.Controls.OBC.RadiantSystems.Heating.Validation;
model HighMassSupplyTemperature_TRoom
  "Validation model for the room temperature controller"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Sources.TimeTable TRooMea(
    table=[0,18; 1,22; 2,18],
    extrapolation=Buildings.Controls.OBC.CDL.Types.Extrapolation.HoldLastPoint,
    offset={273.15},
    timeScale=3600) "Measured room temperature"

  Controls.OBC.RadiantSystems.Heating.HighMassSupplyTemperature_TRoom conHea(TSupSet_max=303.15) "Controller"

protected
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TRooSet(final k(
      final unit="K",
      displayUnit="degC") = 293.15) "Set point temperature for room"
equation
  connect(TRooSet.y, conHea.TRooSet)
  connect(TRooMea.y[1], conHea.TRoo)
end HighMassSupplyTemperature_TRoom;


Collection of validation models

within Buildings.Controls.OBC.RadiantSystems.Heating;
package Validation "Collection of validation models"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


Package with controllers for shades

within Buildings.Controls.OBC;
package Shade "Package with controllers for shades"
end Shade;


Shade controller with solar irradiation as input. Block that outputs a shade control signal <i>y ∈ {0, 1}</i> as follows:

within Buildings.Controls.OBC.Shade;
block Shade_H
  "Shade controller with solar irradiation as input"
  parameter Real HHigh(
    final quantity="Irradiance",
    final unit="W/m2")
    "if y=0 and H>=HHigh, switch to y=1";
  parameter Real HLow(
    final quantity="Irradiance",
    final unit="W/m2")
    "if y=1 and H<=HLow, switch to y=0";
  CDL.Interfaces.RealInput H(
    final unit="W/m2")
    "Measured irradiation"
  CDL.Interfaces.RealOutput y(
    final min=0,
    final max=1,
    unit="1")
    "Control signal"

protected
  CDL.Reals.Hysteresis hys(
    final uLow=HLow,
    final uHigh=HHigh)
    "Hysteresis block"
  CDL.Conversions.BooleanToReal booToRea
    "Boolean to real converter"

equation
  connect(H,hys.u)
  connect(hys.y,booToRea.u)
  connect(booToRea.y,y)
end Shade_H;


Shade controller with temperature as input. Block that outputs a shade control signal <i>y ∈ {0, 1}</i> as follows:

within Buildings.Controls.OBC.Shade;
block Shade_T
  "Shade controller with temperature as input"
  parameter Real THigh(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC")
    "if y=0 and T>=THigh, switch to y=1";
  parameter Real TLow(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC")
    "if y=1 and T<=TLow, switch to y=0";
  CDL.Interfaces.RealInput T(
    final unit="K")
    "Measured temperature"
  CDL.Interfaces.RealOutput y(
    final min=0,
    final max=1,
    unit="1")
    "Control signal"

protected
  CDL.Reals.Hysteresis hys(
    final uLow=TLow,
    final uHigh=THigh)
    "Temperature hysteresis"
  CDL.Conversions.BooleanToReal booToRea
    "Boolean to real converter"

equation
  connect(T,hys.u)
  connect(hys.y,booToRea.u)
  connect(booToRea.y,y)
end Shade_T;


Collection of validation models

within Buildings.Controls.OBC.Shade;
package Validation "Collection of validation models"
end Validation;


Validation model for shading control based on solar irradiance. This example validates

Buildings.Controls.OBC.Shade.Shade_H
for a solar irradiance input signal.

within Buildings.Controls.OBC.Shade.Validation;
model Shade_H
  "Validation model for shading control based on solar irradiance"
  Buildings.Controls.OBC.Shade.Shade_H shaH(
    HHigh=500,
    HLow=400)
    "Shade controller"
  CDL.Reals.Sources.Sin H(
    final amplitude=500,
    final freqHz=1/(2*1800),
    final offset=250)
    "Solar irradiance"

equation
  connect(H.y,shaH.H)
end Shade_H;


Validation model for shade control based on temperature. This example validates

Buildings.Controls.OBC.Shade.Shade_T
for a temperature input signal.

within Buildings.Controls.OBC.Shade.Validation;
model Shade_T
  "Validation model for shade control based on temperature"
  Buildings.Controls.OBC.Shade.Shade_T shaT(
    THigh=298.15,
    TLow=295.15)
    "Shade controller"
  CDL.Reals.Sources.Sin T(
    final amplitude=10,
    final freqHz=1/(2*1800),
    final offset=293.15)
    "Measured temperature"

equation
  connect(T.y,shaT.T)
end Shade_T;


Block that converts pressure from bar to pascal. Converts pressure given in bar [bar] to pascal [Pa].

within Buildings.Controls.OBC.UnitConversions;
block From_bar "Block that converts pressure from bar to pascal"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "bar",
    final quantity = "Pressure")
    "Pressure in bar"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "Pa",
    final quantity = "Pressure")
    "Pressure in pascal"

protected
  constant Real k = 100000. "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_bar;


Block that converts energy from British thermal units to joule. Converts energy given in British thermal units [Btu] to joule [J].

within Buildings.Controls.OBC.UnitConversions;
block From_Btu "Block that converts energy from British thermal units to joule"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final quantity = "Energy")
    "Energy in British thermal units"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "J",
    final quantity = "Energy")
    "Energy in joule"

protected
  constant Real k = 1055.056 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_Btu;


Block that converts power from British thermal units per hour to watt. Converts power given in British thermal units per hour [Btu/h] to watt [W].

within Buildings.Controls.OBC.UnitConversions;
block From_BtuPerHour "Block that converts power from British thermal units per hour to watt"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final quantity = "Power")
    "Power in British thermal units per hour"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "W",
    final quantity = "Power")
    "Power in watt"

protected
  constant Real k = 0.2930711 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_BtuPerHour;


Block that converts volume flow from cubic feet per minute to cubic meters per second. Converts volume flow given in cubic feet per minute [cfm] to cubic meters per second [m3/s].

within Buildings.Controls.OBC.UnitConversions;
block From_cfm "Block that converts volume flow from cubic feet per minute to cubic meters per second"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final quantity = "VolumeFlowRate")
    "Volume flow in cubic feet per minute"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "m3/s",
    final quantity = "VolumeFlowRate")
    "Volume flow in cubic meters per second"

protected
  constant Real k = 0.000471947 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_cfm;


Block that converts temperature from degree Celsius to kelvin. Converts temperature given in degree Celsius [degC] to kelvin [K].

within Buildings.Controls.OBC.UnitConversions;
block From_degC "Block that converts temperature from degree Celsius to kelvin"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "degC",
    final quantity = "ThermodynamicTemperature")
    "Temperature in degree Celsius"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "K",
    final quantity = "ThermodynamicTemperature")
    "Temperature in kelvin"

protected
  constant Real k = 1. "Multiplier";
  constant Real p = 273.15 "Adder";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k = k) "Gain factor"

  Buildings.Controls.OBC.CDL.Reals.AddParameter conv(
    final p = p) "Unit converter"

equation
  connect(conv.y, y)
  connect(u, gai.u)
  connect(gai.y, conv.u)
end From_degC;


Block that converts temperature from degree Fahrenheit to kelvin. Converts temperature given in degree Fahrenheit [degF] to kelvin [K].

within Buildings.Controls.OBC.UnitConversions;
block From_degF "Block that converts temperature from degree Fahrenheit to kelvin"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "degF",
    final quantity = "ThermodynamicTemperature")
    "Temperature in degree Fahrenheit"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "K",
    final quantity = "ThermodynamicTemperature")
    "Temperature in kelvin"

protected
  constant Real k = 5./9. "Multiplier";
  constant Real p = -32. * (5./9.) + 273.15 "Adder";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k = k) "Gain factor"

  Buildings.Controls.OBC.CDL.Reals.AddParameter conv(
    final p = p) "Unit converter"

equation
  connect(conv.y, y)
  connect(u, gai.u)
  connect(gai.y, conv.u)
end From_degF;


Block that converts volume from gallon to cubic meter. Converts volume given in gallon [gal] to cubic meter [m3].

within Buildings.Controls.OBC.UnitConversions;
block From_gal "Block that converts volume from gallon to cubic meter"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final quantity = "Volume")
    "Volume in gallon"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "m3",
    final quantity = "Volume")
    "Volume in cubic meter"

protected
  constant Real k = 0.003785412 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_gal;


Block that converts power from horsepower to watt. Converts power given in horsepower [hp] to watt [W].

within Buildings.Controls.OBC.UnitConversions;
block From_hp "Block that converts power from horsepower to watt"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final quantity = "Power")
    "Power in horsepower"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "W",
    final quantity = "Power")
    "Power in watt"

protected
  constant Real k = 0.7457 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_hp;


Block that converts pressure from inch of water gauge (at 60 degF) to pascal. Converts pressure given in inch of water gauge (at 60 degF) [inH2O] to pascal [Pa].

within Buildings.Controls.OBC.UnitConversions;
block From_inH2O "Block that converts pressure from inch of water gauge (at 60 degF) to pascal"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final quantity = "Pressure")
    "Pressure in inch of water gauge (at 60 degF)"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "Pa",
    final quantity = "Pressure")
    "Pressure in pascal"

protected
  constant Real k = 248.84 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_inH2O;


Block that converts pressure from pound-force per square inch to pascal. Converts pressure given in pound-force per square inch [psi] to pascal [Pa].

within Buildings.Controls.OBC.UnitConversions;
block From_psi "Block that converts pressure from pound-force per square inch to pascal"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final quantity = "Pressure")
    "Pressure in pound-force per square inch"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "Pa",
    final quantity = "Pressure")
    "Pressure in pascal"

protected
  constant Real k = 6895. "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_psi;


Block that converts energy from quads to joule. Converts energy given in quads [quad] to joule [J].

within Buildings.Controls.OBC.UnitConversions;
block From_quad "Block that converts energy from quads to joule"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final quantity = "Energy")
    "Energy in quads"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "J",
    final quantity = "Energy")
    "Energy in joule"

protected
  constant Real k = 1055.56e15 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_quad;


Block that converts power from ton of refrigeration to watt. Converts power given in ton of refrigeration [ton] to watt [W].

within Buildings.Controls.OBC.UnitConversions;
block From_ton "Block that converts power from ton of refrigeration to watt"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final quantity = "Power")
    "Power in ton of refrigeration"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "W",
    final quantity = "Power")
    "Power in watt"

protected
  constant Real k = 3517. "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end From_ton;


Package with blocks for unit conversion

within Buildings.Controls.OBC;
package UnitConversions "Package with blocks for unit conversion"
end UnitConversions;


Block that converts pressure from pascal to bar. Converts pressure given in pascal [Pa] to bar [bar].

within Buildings.Controls.OBC.UnitConversions;
block To_bar "Block that converts pressure from pascal to bar"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "Pa",
    final quantity = "Pressure")
    "Pressure in pascal"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "bar",
    final quantity = "Pressure")
    "Pressure in bar"

protected
  constant Real k = 1./100000. "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_bar;


Block that converts energy from joule to British thermal units. Converts energy given in joule [J] to British thermal units [Btu].

within Buildings.Controls.OBC.UnitConversions;
block To_Btu "Block that converts energy from joule to British thermal units"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "J",
    final quantity = "Energy")
    "Energy in joule"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final quantity = "Energy")
    "Energy in British thermal units"

protected
  constant Real k = 1./1055.056 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_Btu;


Block that converts power from watt to British thermal units per hour. Converts power given in watt [W] to British thermal units per hour [Btu/h].

within Buildings.Controls.OBC.UnitConversions;
block To_BtuPerHour "Block that converts power from watt to British thermal units per hour"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "W",
    final quantity = "Power")
    "Power in watt"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final quantity = "Power")
    "Power in British thermal units per hour"

protected
  constant Real k = 1./0.2930711 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_BtuPerHour;


Block that converts volume flow from cubic meters per second to cubic feet per minute. Converts volume flow given in cubic meters per second [m3/s] to cubic feet per minute [cfm].

within Buildings.Controls.OBC.UnitConversions;
block To_cfm "Block that converts volume flow from cubic meters per second to cubic feet per minute"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "m3/s",
    final quantity = "VolumeFlowRate")
    "Volume flow in cubic meters per second"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final quantity = "VolumeFlowRate")
    "Volume flow in cubic feet per minute"

protected
  constant Real k = 1./0.000471947 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_cfm;


Block that converts temperature from kelvin to degree Celsius. Converts temperature given in kelvin [K] to degree Celsius [degC].

within Buildings.Controls.OBC.UnitConversions;
block To_degC "Block that converts temperature from kelvin to degree Celsius"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "K",
    final quantity = "ThermodynamicTemperature")
    "Temperature in kelvin"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "degC",
    final quantity = "ThermodynamicTemperature")
    "Temperature in degree Celsius"

protected
  constant Real k = 1. "Multiplier";
  constant Real p = -273.15 "Adder";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k = k) "Gain factor"

  Buildings.Controls.OBC.CDL.Reals.AddParameter conv(
    final p = p) "Unit converter"

equation
  connect(conv.y, y)
  connect(u, gai.u)
  connect(gai.y, conv.u)
end To_degC;


Block that converts temperature from kelvin to degree Fahrenheit. Converts temperature given in kelvin [K] to degree Fahrenheit [degF].

within Buildings.Controls.OBC.UnitConversions;
block To_degF "Block that converts temperature from kelvin to degree Fahrenheit"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "K",
    final quantity = "ThermodynamicTemperature")
    "Temperature in kelvin"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final unit = "degF",
    final quantity = "ThermodynamicTemperature")
    "Temperature in degree Fahrenheit"

protected
  constant Real k = 9./5. "Multiplier";
  constant Real p = (-9./5.) * 273.15 + 32 "Adder";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k = k) "Gain factor"

  Buildings.Controls.OBC.CDL.Reals.AddParameter conv(
    final p = p) "Unit converter"

equation
  connect(conv.y, y)
  connect(u, gai.u)
  connect(gai.y, conv.u)
end To_degF;


Block that converts volume from cubic meter to gallon. Converts volume given in cubic meter [m3] to gallon [gal].

within Buildings.Controls.OBC.UnitConversions;
block To_gal "Block that converts volume from cubic meter to gallon"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "m3",
    final quantity = "Volume")
    "Volume in cubic meter"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final quantity = "Volume")
    "Volume in gallon"

protected
  constant Real k = 1./0.003785412 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_gal;


Block that converts power from watt to horsepower. Converts power given in watt [W] to horsepower [hp].

within Buildings.Controls.OBC.UnitConversions;
block To_hp "Block that converts power from watt to horsepower"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "W",
    final quantity = "Power")
    "Power in watt"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final quantity = "Power")
    "Power in horsepower"

protected
  constant Real k = 1./0.7457 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_hp;


Block that converts pressure from pascal to inch of water gauge (at 60 degF). Converts pressure given in pascal [Pa] to inch of water gauge (at 60 degF) [inH2O].

within Buildings.Controls.OBC.UnitConversions;
block To_inH2O "Block that converts pressure from pascal to inch of water gauge (at 60 degF)"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "Pa",
    final quantity = "Pressure")
    "Pressure in pascal"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final quantity = "Pressure")
    "Pressure in inch of water gauge (at 60 degF)"

protected
  constant Real k = 1./248.84 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_inH2O;


Block that converts pressure from pascal to pound-force per square inch. Converts pressure given in pascal [Pa] to pound-force per square inch [psi].

within Buildings.Controls.OBC.UnitConversions;
block To_psi "Block that converts pressure from pascal to pound-force per square inch"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "Pa",
    final quantity = "Pressure")
    "Pressure in pascal"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final quantity = "Pressure")
    "Pressure in pound-force per square inch"

protected
  constant Real k = 1./6895. "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_psi;


Block that converts energy from joule to quads. Converts energy given in joule [J] to quads [quad].

within Buildings.Controls.OBC.UnitConversions;
block To_quad "Block that converts energy from joule to quads"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "J",
    final quantity = "Energy")
    "Energy in joule"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final quantity = "Energy")
    "Energy in quads"

protected
  constant Real k = 1./1055.56e15 "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_quad;


Block that converts power from watt to ton of refrigeration. Converts power given in watt [W] to ton of refrigeration [ton].

within Buildings.Controls.OBC.UnitConversions;
block To_ton "Block that converts power from watt to ton of refrigeration"

  Buildings.Controls.OBC.CDL.Interfaces.RealInput u(
    final unit = "W",
    final quantity = "Power")
    "Power in watt"

  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y(
    final quantity = "Power")
    "Power in ton of refrigeration"

protected
  constant Real k = 1./3517. "Multiplier";

  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter conv(
    final k = k) "Unit converter"

equation
  connect(u, conv.u)
  connect(conv.y, y)
end To_ton;


Validation model for unit conversion from bar to pascal. This model validates pressure unit conversion from bar to pascal.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_bar "Validation model for unit conversion from bar to pascal"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1. "Validation input";
  parameter Real kin1 = 0.00025 "Validation input 1";
  parameter Real kout = 1.*100000. "Validation output";
  parameter Real kout1 = 0.00025*100000. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_bar from_bar
  "Unit converter from bar to pascal "
  Buildings.Controls.OBC.UnitConversions.From_bar from_bar1
  "Unit converter from bar to pascal "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_bar1.u)
  connect(from_bar1.y, sub1.u1)
  connect(from_bar.y, sub.u1)
  connect(value.y,from_bar.u)
end From_bar;


Validation model for unit conversion from British thermal units to joule. This model validates energy unit conversion from British thermal units to joule.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_Btu "Validation model for unit conversion from British thermal units to joule"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1. "Validation input";
  parameter Real kin1 = 2. "Validation input 1";
  parameter Real kout = 1.*1055.056 "Validation output";
  parameter Real kout1 = 2.*1055.056 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_Btu from_Btu
  "Unit converter from British thermal units to joule "
  Buildings.Controls.OBC.UnitConversions.From_Btu from_Btu1
  "Unit converter from British thermal units to joule "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_Btu1.u)
  connect(from_Btu1.y, sub1.u1)
  connect(from_Btu.y, sub.u1)
  connect(value.y,from_Btu.u)
end From_Btu;


Validation model for unit conversion from British thermal units per hour to watt. This model validates power unit conversion from British thermal units per hour to watt.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_BtuPerHour "Validation model for unit conversion from British thermal units per hour to watt"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1./0.2930711 "Validation input";
  parameter Real kin1 = 1000./0.2930711 "Validation input 1";
  parameter Real kout = 1 "Validation output";
  parameter Real kout1 = 1000 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_BtuPerHour from_BtuPerHour
  "Unit converter from British thermal units per hour to watt "
  Buildings.Controls.OBC.UnitConversions.From_BtuPerHour from_BtuPerHour1
  "Unit converter from British thermal units per hour to watt "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_BtuPerHour1.u)
  connect(from_BtuPerHour1.y, sub1.u1)
  connect(from_BtuPerHour.y, sub.u1)
  connect(value.y,from_BtuPerHour.u)
end From_BtuPerHour;


Validation model for unit conversion from cubic feet per minute to cubic meters per second. This model validates volume flow unit conversion from cubic feet per minute to cubic meters per second.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_cfm "Validation model for unit conversion from cubic feet per minute to cubic meters per second"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 100. "Validation input";
  parameter Real kin1 = 2000. "Validation input 1";
  parameter Real kout = 100.*0.000471947 "Validation output";
  parameter Real kout1 = 2000.*0.000471947 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_cfm from_cfm
  "Unit converter from cubic feet per minute to cubic meters per second "
  Buildings.Controls.OBC.UnitConversions.From_cfm from_cfm1
  "Unit converter from cubic feet per minute to cubic meters per second "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_cfm1.u)
  connect(from_cfm1.y, sub1.u1)
  connect(from_cfm.y, sub.u1)
  connect(value.y,from_cfm.u)
end From_cfm;


Validation model for unit conversion from degree Celsius to kelvin. This model validates temperature unit conversion from degree Celsius to kelvin.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_degC "Validation model for unit conversion from degree Celsius to kelvin"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 0. "Validation input";
  parameter Real kin1 = 100. "Validation input 1";
  parameter Real kout = 273.15 "Validation output";
  parameter Real kout1 = 373.15 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_degC from_degC
  "Unit converter from degree Celsius to kelvin "
  Buildings.Controls.OBC.UnitConversions.From_degC from_degC1
  "Unit converter from degree Celsius to kelvin "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_degC1.u)
  connect(from_degC1.y, sub1.u1)
  connect(from_degC.y, sub.u1)
  connect(value.y,from_degC.u)
end From_degC;


Validation model for unit conversion from degree Fahrenheit to kelvin. This model validates temperature unit conversion from degree Fahrenheit to kelvin.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_degF "Validation model for unit conversion from degree Fahrenheit to kelvin"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 32. "Validation input";
  parameter Real kin1 = 100. * (9./5.) + 32. "Validation input 1";
  parameter Real kout = 273.15 "Validation output";
  parameter Real kout1 = 373.15 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_degF from_degF
  "Unit converter from degree Fahrenheit to kelvin "
  Buildings.Controls.OBC.UnitConversions.From_degF from_degF1
  "Unit converter from degree Fahrenheit to kelvin "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_degF1.u)
  connect(from_degF1.y, sub1.u1)
  connect(from_degF.y, sub.u1)
  connect(value.y,from_degF.u)
end From_degF;


Validation model for unit conversion from gallon to cubic meter. This model validates volume unit conversion from gallon to cubic meter.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_gal "Validation model for unit conversion from gallon to cubic meter"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1. "Validation input";
  parameter Real kin1 = 100. "Validation input 1";
  parameter Real kout = 1.*0.003785412 "Validation output";
  parameter Real kout1 = 100.*0.003785412 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_gal from_gal
  "Unit converter from gallon to cubic meter "
  Buildings.Controls.OBC.UnitConversions.From_gal from_gal1
  "Unit converter from gallon to cubic meter "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_gal1.u)
  connect(from_gal1.y, sub1.u1)
  connect(from_gal.y, sub.u1)
  connect(value.y,from_gal.u)
end From_gal;


Validation model for unit conversion from horsepower to watt. This model validates power unit conversion from horsepower to watt.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_hp "Validation model for unit conversion from horsepower to watt"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 10. "Validation input";
  parameter Real kin1 = 45. "Validation input 1";
  parameter Real kout = 10.*0.7457 "Validation output";
  parameter Real kout1 = 45.*0.7457 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_hp from_hp
  "Unit converter from horsepower to watt "
  Buildings.Controls.OBC.UnitConversions.From_hp from_hp1
  "Unit converter from horsepower to watt "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_hp1.u)
  connect(from_hp1.y, sub1.u1)
  connect(from_hp.y, sub.u1)
  connect(value.y,from_hp.u)
end From_hp;


Validation model for unit conversion from inch of water gauge (at 60 degF) to pascal. This model validates pressure unit conversion from inch of water gauge (at 60 degF) to pascal.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_inH2O "Validation model for unit conversion from inch of water gauge (at 60 degF) to pascal"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 25./248.84 "Validation input";
  parameter Real kin1 = 100000./248.84 "Validation input 1";
  parameter Real kout = 25 "Validation output";
  parameter Real kout1 = 100000 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_inH2O from_inH2O
  "Unit converter from inch of water gauge (at 60 degF) to pascal "
  Buildings.Controls.OBC.UnitConversions.From_inH2O from_inH2O1
  "Unit converter from inch of water gauge (at 60 degF) to pascal "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_inH2O1.u)
  connect(from_inH2O1.y, sub1.u1)
  connect(from_inH2O.y, sub.u1)
  connect(value.y,from_inH2O.u)
end From_inH2O;


Validation model for unit conversion from pound-force per square inch to pascal. This model validates pressure unit conversion from pound-force per square inch to pascal.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_psi "Validation model for unit conversion from pound-force per square inch to pascal"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 0.0036 "Validation input";
  parameter Real kin1 = 1. "Validation input 1";
  parameter Real kout = 0.0036*6895. "Validation output";
  parameter Real kout1 = 1.*6895. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_psi from_psi
  "Unit converter from pound-force per square inch to pascal "
  Buildings.Controls.OBC.UnitConversions.From_psi from_psi1
  "Unit converter from pound-force per square inch to pascal "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_psi1.u)
  connect(from_psi1.y, sub1.u1)
  connect(from_psi.y, sub.u1)
  connect(value.y,from_psi.u)
end From_psi;


Validation model for unit conversion from quads to joule. This model validates energy unit conversion from quads to joule.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_quad "Validation model for unit conversion from quads to joule"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1. "Validation input";
  parameter Real kin1 = 2. "Validation input 1";
  parameter Real kout = 1.*1055.56e15 "Validation output";
  parameter Real kout1 = 2.*1055.56e15 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_quad from_quad
  "Unit converter from quads to joule "
  Buildings.Controls.OBC.UnitConversions.From_quad from_quad1
  "Unit converter from quads to joule "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_quad1.u)
  connect(from_quad1.y, sub1.u1)
  connect(from_quad.y, sub.u1)
  connect(value.y,from_quad.u)
end From_quad;


Validation model for unit conversion from ton of refrigeration to watt. This model validates power unit conversion from ton of refrigeration to watt.

within Buildings.Controls.OBC.UnitConversions.Validation;
model From_ton "Validation model for unit conversion from ton of refrigeration to watt"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1. "Validation input";
  parameter Real kin1 = 100. "Validation input 1";
  parameter Real kout = 3517. "Validation output";
  parameter Real kout1 = 351700. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.From_ton from_ton
  "Unit converter from ton of refrigeration to watt "
  Buildings.Controls.OBC.UnitConversions.From_ton from_ton1
  "Unit converter from ton of refrigeration to watt "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,from_ton1.u)
  connect(from_ton1.y, sub1.u1)
  connect(from_ton.y, sub.u1)
  connect(value.y,from_ton.u)
end From_ton;


within Buildings.Controls.OBC.UnitConversions;
package Validation "Collection of models that validate the unit conversion blocks of the CDL"
end Validation;


Validation model for unit conversion from pascal to bar. This model validates pressure unit conversion from pascal to bar.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_bar "Validation model for unit conversion from pascal to bar"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1.*100000. "Validation input";
  parameter Real kin1 = 0.00025*100000. "Validation input 1";
  parameter Real kout = 1. "Validation output";
  parameter Real kout1 = 0.00025 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_bar to_bar
  "Unit converter from pascal to bar "
  Buildings.Controls.OBC.UnitConversions.To_bar to_bar1
  "Unit converter from pascal to bar "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_bar1.u)
  connect(to_bar1.y, sub1.u1)
  connect(to_bar.y, sub.u1)
  connect(value.y,to_bar.u)
end To_bar;


Validation model for unit conversion from joule to British thermal units. This model validates energy unit conversion from joule to British thermal units.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_Btu "Validation model for unit conversion from joule to British thermal units"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1.*1055.056 "Validation input";
  parameter Real kin1 = 2.*1055.056 "Validation input 1";
  parameter Real kout = 1. "Validation output";
  parameter Real kout1 = 2. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_Btu to_Btu
  "Unit converter from joule to British thermal units "
  Buildings.Controls.OBC.UnitConversions.To_Btu to_Btu1
  "Unit converter from joule to British thermal units "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_Btu1.u)
  connect(to_Btu1.y, sub1.u1)
  connect(to_Btu.y, sub.u1)
  connect(value.y,to_Btu.u)
end To_Btu;


Validation model for unit conversion from watt to British thermal units per hour. This model validates power unit conversion from watt to British thermal units per hour.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_BtuPerHour "Validation model for unit conversion from watt to British thermal units per hour"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1 "Validation input";
  parameter Real kin1 = 1000 "Validation input 1";
  parameter Real kout = 1./0.2930711 "Validation output";
  parameter Real kout1 = 1000./0.2930711 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_BtuPerHour to_BtuPerHour
  "Unit converter from watt to British thermal units per hour "
  Buildings.Controls.OBC.UnitConversions.To_BtuPerHour to_BtuPerHour1
  "Unit converter from watt to British thermal units per hour "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_BtuPerHour1.u)
  connect(to_BtuPerHour1.y, sub1.u1)
  connect(to_BtuPerHour.y, sub.u1)
  connect(value.y,to_BtuPerHour.u)
end To_BtuPerHour;


Validation model for unit conversion from cubic meters per second to cubic feet per minute. This model validates volume flow unit conversion from cubic meters per second to cubic feet per minute.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_cfm "Validation model for unit conversion from cubic meters per second to cubic feet per minute"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 100.*0.000471947 "Validation input";
  parameter Real kin1 = 2000.*0.000471947 "Validation input 1";
  parameter Real kout = 100. "Validation output";
  parameter Real kout1 = 2000. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_cfm to_cfm
  "Unit converter from cubic meters per second to cubic feet per minute "
  Buildings.Controls.OBC.UnitConversions.To_cfm to_cfm1
  "Unit converter from cubic meters per second to cubic feet per minute "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_cfm1.u)
  connect(to_cfm1.y, sub1.u1)
  connect(to_cfm.y, sub.u1)
  connect(value.y,to_cfm.u)
end To_cfm;


Validation model for unit conversion from kelvin to degree Celsius. This model validates temperature unit conversion from kelvin to degree Celsius.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_degC "Validation model for unit conversion from kelvin to degree Celsius"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 273.15 "Validation input";
  parameter Real kin1 = 373.15 "Validation input 1";
  parameter Real kout = 0. "Validation output";
  parameter Real kout1 = 100. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_degC to_degC
  "Unit converter from kelvin to degree Celsius "
  Buildings.Controls.OBC.UnitConversions.To_degC to_degC1
  "Unit converter from kelvin to degree Celsius "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_degC1.u)
  connect(to_degC1.y, sub1.u1)
  connect(to_degC.y, sub.u1)
  connect(value.y,to_degC.u)
end To_degC;


Validation model for unit conversion from kelvin to degree Fahrenheit. This model validates temperature unit conversion from kelvin to degree Fahrenheit.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_degF "Validation model for unit conversion from kelvin to degree Fahrenheit"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 273.15 "Validation input";
  parameter Real kin1 = 373.15 "Validation input 1";
  parameter Real kout = 32. "Validation output";
  parameter Real kout1 = 100. * (9./5.) + 32. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_degF to_degF
  "Unit converter from kelvin to degree Fahrenheit "
  Buildings.Controls.OBC.UnitConversions.To_degF to_degF1
  "Unit converter from kelvin to degree Fahrenheit "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_degF1.u)
  connect(to_degF1.y, sub1.u1)
  connect(to_degF.y, sub.u1)
  connect(value.y,to_degF.u)
end To_degF;


Validation model for unit conversion from cubic meter to gallon. This model validates volume unit conversion from cubic meter to gallon.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_gal "Validation model for unit conversion from cubic meter to gallon"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1.*0.003785412 "Validation input";
  parameter Real kin1 = 100.*0.003785412 "Validation input 1";
  parameter Real kout = 1. "Validation output";
  parameter Real kout1 = 100. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_gal to_gal
  "Unit converter from cubic meter to gallon "
  Buildings.Controls.OBC.UnitConversions.To_gal to_gal1
  "Unit converter from cubic meter to gallon "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_gal1.u)
  connect(to_gal1.y, sub1.u1)
  connect(to_gal.y, sub.u1)
  connect(value.y,to_gal.u)
end To_gal;


Validation model for unit conversion from watt to horsepower. This model validates power unit conversion from watt to horsepower.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_hp "Validation model for unit conversion from watt to horsepower"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 10.*0.7457 "Validation input";
  parameter Real kin1 = 45.*0.7457 "Validation input 1";
  parameter Real kout = 10. "Validation output";
  parameter Real kout1 = 45. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_hp to_hp
  "Unit converter from watt to horsepower "
  Buildings.Controls.OBC.UnitConversions.To_hp to_hp1
  "Unit converter from watt to horsepower "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_hp1.u)
  connect(to_hp1.y, sub1.u1)
  connect(to_hp.y, sub.u1)
  connect(value.y,to_hp.u)
end To_hp;


Validation model for unit conversion from pascal to inch of water gauge (at 60 degF). This model validates pressure unit conversion from pascal to inch of water gauge (at 60 degF).

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_inH2O "Validation model for unit conversion from pascal to inch of water gauge (at 60 degF)"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 25. "Validation input";
  parameter Real kin1 = 100000. "Validation input 1";
  parameter Real kout = 25./248.84 "Validation output";
  parameter Real kout1 = 100000./248.84 "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_inH2O to_inH2O
  "Unit converter from pascal to inch of water gauge (at 60 degF) "
  Buildings.Controls.OBC.UnitConversions.To_inH2O to_inH2O1
  "Unit converter from pascal to inch of water gauge (at 60 degF) "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_inH2O1.u)
  connect(to_inH2O1.y, sub1.u1)
  connect(to_inH2O.y, sub.u1)
  connect(value.y,to_inH2O.u)
end To_inH2O;


Validation model for unit conversion from pascal to pound-force per square inch. This model validates pressure unit conversion from pascal to pound-force per square inch.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_psi "Validation model for unit conversion from pascal to pound-force per square inch"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 0.0036*6895. "Validation input";
  parameter Real kin1 = 1.*6895. "Validation input 1";
  parameter Real kout = 0.0036 "Validation output";
  parameter Real kout1 = 1. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_psi to_psi
  "Unit converter from pascal to pound-force per square inch "
  Buildings.Controls.OBC.UnitConversions.To_psi to_psi1
  "Unit converter from pascal to pound-force per square inch "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_psi1.u)
  connect(to_psi1.y, sub1.u1)
  connect(to_psi.y, sub.u1)
  connect(value.y,to_psi.u)
end To_psi;


Validation model for unit conversion from joule to quads. This model validates energy unit conversion from joule to quads.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_quad "Validation model for unit conversion from joule to quads"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 1.*1055.56e15 "Validation input";
  parameter Real kin1 = 2.*1055.56e15 "Validation input 1";
  parameter Real kout = 1. "Validation output";
  parameter Real kout1 = 2. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_quad to_quad
  "Unit converter from joule to quads "
  Buildings.Controls.OBC.UnitConversions.To_quad to_quad1
  "Unit converter from joule to quads "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_quad1.u)
  connect(to_quad1.y, sub1.u1)
  connect(to_quad.y, sub.u1)
  connect(value.y,to_quad.u)
end To_quad;


Validation model for unit conversion from watt to ton of refrigeration. This model validates power unit conversion from watt to ton of refrigeration.

within Buildings.Controls.OBC.UnitConversions.Validation;
model To_ton "Validation model for unit conversion from watt to ton of refrigeration"
  extends Modelica.Icons.Example;

  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Difference between the calculated and expected conversion output"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Difference between the calculated and expected conversion output"

protected
  parameter Real kin = 3517. "Validation input";
  parameter Real kin1 = 351700. "Validation input 1";
  parameter Real kout = 1. "Validation output";
  parameter Real kout1 = 100. "Validation output 1";

  Buildings.Controls.OBC.UnitConversions.To_ton to_ton
  "Unit converter from watt to ton of refrigeration "
  Buildings.Controls.OBC.UnitConversions.To_ton to_ton1
  "Unit converter from watt to ton of refrigeration "

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value(
    final k=kin)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant value1(
    final k=kin1)
    "Value to convert"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result(
    final k=kout)
    "Expected converted value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant result1(
    final k=kout1)
    "Expected converted value"

equation
  connect(result.y, sub.u2)
  connect(result1.y, sub1.u2)
  connect(value1.y,to_ton1.u)
  connect(to_ton1.y, sub1.u1)
  connect(to_ton.y, sub.u1)
  connect(value.y,to_ton.u)
end To_ton;


Block that outputs the optimal start time for an HVAC system before occupancy. This block predicts the shortest time for an HVAC system to meet the occupied setpoint
prior to the scheduled occupancy. The block requires inputs of zone temperature,
occupied zone setpoint(s) and next occupancy. The two outputs are the optimal start
duration tOpt and the optimal start on signal optOn for
the HVAC system.

within Buildings.Controls.OBC.Utilities;
block OptimalStart
  "Block that outputs the optimal start time for an HVAC system before occupancy"
  parameter Real tOptMax(
    final quantity="Time",
    final unit="s",
    displayUnit="h",
    final min=0,
    max=21600)=10800
    "Maximum optimal start time";
  parameter Integer nDay(
    min=1)=3
    "Number of previous days used to compute the optimal start up time";
  parameter Boolean computeHeating=false
    "Set to true to compute optimal start for heating";
  parameter Boolean computeCooling=false
    "Set to true to compute optimal start for cooling";
  parameter Real uLow(
    final quantity="TemperatureDifference",
    final unit="K",
    final min=0)=0
    "Threshold to determine if the zone temperature reaches the occupied setpoint,
     must be a non-negative number";
  parameter Real uHigh(
    final quantity="TemperatureDifference",
    final unit="K",
    final min=0)=0.5
    "Threshold to determine the need to start the HVAC system before occupancy,
     must be greater than uLow";
  parameter Real thrOptOn(
    final quantity="Time",
    final unit="s",
    displayUnit="h",
    final min=0,
    max=10800)=60
    "Threshold time, optimal start on signal becomes true when tOpt larger than thrOptOn";
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSetZonHea(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC",
    min=200) if computeHeating
    "Zone heating setpoint temperature during occupancy"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TZon(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC",
    min=200)
    "Zone temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSetZonCoo(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC",
    min=200) if computeCooling
    "Zone cooling setpoint temperature during occupancy"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput tNexOcc(
    final quantity="Time",
    final unit="s",
    displayUnit="h")
    "Time until next occupancy"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput tOpt(
    final quantity="Time",
    final unit="s",
    displayUnit="h")
    "Optimal start time duration of HVAC system"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput optOn
    "Outputs true if the HVAC system remains in the optimal start period"
  Buildings.Controls.OBC.Utilities.BaseClasses.OptimalStartCalculation optHea(
    final tOptMax=tOptMax,
    final thrOptOn=thrOptOn,
    final nDay=nDay,
    final uLow=uLow,
    final uHigh=uHigh) if computeHeating
    "Optimal start time for heating system"
  Buildings.Controls.OBC.Utilities.BaseClasses.OptimalStartCalculation optCoo(
    final tOptMax=tOptMax,
    final thrOptOn=thrOptOn,
    final nDay=nDay,
    final uLow=uLow,
    final uHigh=uHigh) if computeCooling
    "Optimal start time for cooling system"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold hysSta(
    t=60,
    h=60)
    "Hysteresis to activate the optimal start boolean output"

protected
  Buildings.Controls.OBC.CDL.Reals.Max max
    "Get the maximum optimal start time "
  Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(
    p=-tOptMax)
    "Maximum optimal start time"
  Buildings.Controls.OBC.CDL.Logical.Or or2
    "Get the optimal start boolean output"
  Buildings.Controls.OBC.CDL.Reals.Subtract dTHea if computeHeating
    "Temperature difference between heating setpoint and zone temperature"
  Buildings.Controls.OBC.CDL.Reals.Subtract dTCoo if computeCooling
    "Temperature difference between zone temperature and cooling setpoint"
  Buildings.Controls.OBC.CDL.Logical.FallingEdge falEdg
    "Stop calculation"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con2(
    final k=0) if not computeHeating
    "Becomes effective when optimal start is only for heating"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con1(
    final k=0) if not computeCooling
    "Becomes effective when optimal start is only for cooling"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con(
    final k=false) if not computeHeating
    "Becomes effective when optimal start is only for heating"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con3(
    final k=false) if not computeCooling
    "Becomes effective when optimal start is only for cooling"

equation
  connect(TSetZonCoo,dTCoo.u2)
  connect(TZon,dTCoo.u1)
  connect(TZon,dTHea.u2)
  connect(TSetZonHea,dTHea.u1)
  connect(max.y,tOpt)
  connect(con2.y,max.u1)
  connect(con1.y,max.u2)
  connect(dTCoo.y,optCoo.TDif)
  connect(dTHea.y,optHea.TDif)
  connect(tNexOcc,addPar.u)
  connect(tNexOcc,optHea.tNexOcc)
  connect(optCoo.tOpt,max.u2)
  connect(optHea.tOpt,max.u1)
  connect(tNexOcc,optCoo.tNexOcc)
  connect(falEdg.y,optHea.staCal)
  connect(falEdg.y,optCoo.staCal)
  connect(or2.y,optOn)
  connect(con.y,or2.u1)
  connect(con3.y,or2.u2)
  connect(optCoo.optOn,or2.u2)
  connect(optHea.optOn,or2.u1)
  connect(falEdg.u,hysSta.y)
  connect(addPar.y,hysSta.u)
end OptimalStart;


Package with utility functions

within Buildings.Controls.OBC;
package Utilities "Package with utility functions"
end Utilities;


P, PI, PD, and PID controller with output reset and input gains. PID controller in the standard form

within Buildings.Controls.OBC.Utilities;
block PIDWithInputGains
  "P, PI, PD, and PID controller with output reset and input gains"
  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller";
  parameter Real r(
    min=100*CDL.Constants.eps)=1
    "Typical range of control error, used for scaling the control error";
  parameter Real yMax=1
    "Upper limit of output"
  parameter Real yMin=0
    "Lower limit of output"
  parameter Real Ni(
    min=100*CDL.Constants.eps)=0.9
    "Ni*Ti is time constant of anti-windup compensation"
  parameter Real Nd(
    min=100*CDL.Constants.eps)=10
    "The higher Nd, the more ideal the derivative block"
  parameter Real xi_start=0
    "Initial value of integrator state"
  parameter Real yd_start=0
    "Initial value of derivative output"
  parameter Boolean reverseActing=true
    "Set to true for reverse acting, or false for direct acting control action";
  parameter Real y_reset=xi_start
    "Value to which the controller output is reset if the boolean trigger has a rising edge"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u_s
    "Connector for setpoint input signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput u_m
    "Connector for measurement input signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput k(
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)
    "Connector for control gain signal"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput Ti(
    quantity="Time",
    unit="s",
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)
    if with_I
    "Connector for time constant signal for the integral term"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput Td(
    quantity="Time",
    unit="s",
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)
    if with_D
    "Connector for time constant signal for the derivative term"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput y
    "Connector for actuator output signal"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput trigger
    "Resets the controller output when trigger becomes true"
  Buildings.Controls.OBC.CDL.Reals.Subtract controlError
    "Control error (set point - measurement)"
  Buildings.Controls.OBC.CDL.Reals.Multiply P
    "Proportional action"
  Buildings.Controls.OBC.CDL.Reals.IntegratorWithReset I(
    final k=1,
    final y_start=xi_start) if with_I
    "Integral term"
  Buildings.Controls.OBC.CDL.Reals.Derivative D(
    final y_start=yd_start) if with_D
    "Derivative term"
  Buildings.Controls.OBC.CDL.Reals.Subtract errP
    "P error"
  Buildings.Controls.OBC.CDL.Reals.Subtract errD if with_D
    "D error"
  Buildings.Controls.OBC.CDL.Reals.Subtract errI1 if with_I
    "I error (before anti-windup compensation)"
  Buildings.Controls.OBC.CDL.Reals.Subtract errI2 if with_I
    "I error (after anti-windup compensation)"
  Buildings.Controls.OBC.CDL.Reals.Limiter lim(
    final uMax=yMax,
    final uMin=yMin)
    "Limiter"
  Buildings.Controls.OBC.CDL.Reals.Divide antWinGai2 if with_I
    "Outputs of anti-windup compensation"
  Buildings.Controls.OBC.CDL.Reals.Divide gaiI if with_I "Gain of the integral term"
  Buildings.Controls.OBC.CDL.Reals.Multiply errIWithGai if with_I
    "I error (after multiplying with the gain of the integral term)"
  Buildings.Controls.OBC.CDL.Reals.Multiply mulkTd if with_D
    "Product of k and Td"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThrkTd(
    t=1E-6,
    h=1E-6/2)
    if with_D
    "Check if k*Td is larger than 0"

protected
  final parameter Real revAct=
    if reverseActing then
      1
    else
      -1
    "Switch for sign for reverse or direct acting controller";
  final parameter Boolean with_I=controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PI or controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PID
    "Boolean flag to enable integral action"
  final parameter Boolean with_D=controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PD or controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PID
    "Boolean flag to enable derivative action"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant Dzero(
    final k=0) if not with_D
    "Zero input signal"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant Izero(
    final k=0) if not with_I
    "Zero input signal"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uS_revAct(
    final k=revAct/r) "Set point multiplied by reverse action sign"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter uMea_revAct(
    final k=revAct/r)
    "Set point multiplied by reverse action sign"
  Buildings.Controls.OBC.CDL.Reals.Add addPD
    "Outputs P and D gains added"
  Buildings.Controls.OBC.CDL.Reals.Add addPID
    "Outputs P, I and D gains added"
  Buildings.Controls.OBC.CDL.Reals.Subtract antWinErr if with_I
    "Error for anti-windup compensation"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter antWinGai1(k=1/Ni)
    if with_I "Gain for anti-windup compensation without the proportional gain"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant yResSig(
    final k=y_reset) if with_I
    "Signal for y_reset"
  Buildings.Controls.OBC.CDL.Reals.Subtract addRes if with_I
    "Adder for integrator reset"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant cheYMinMax(
    final k=yMin < yMax) "Check for values of yMin and yMax"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMesYMinMax(
    message="LimPID: Limits must be yMin < yMax") "Assertion on yMin and yMax"
  Buildings.Controls.OBC.CDL.Utilities.Assert assMeskTd(
    message="LimPIDWithInputGains: Limits must be k*Td > 0")
    if with_D
    "Assertion on k and Td"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiT(final k=1/Nd) if with_D
    "Gain to compute time constant for derivative action"

equation
  connect(trigger,I.trigger)
  connect(u_s,uS_revAct.u)
  connect(u_m,uMea_revAct.u)
  connect(errD.u2,uMea_revAct.y)
  connect(D.u,errD.y)
  connect(errI1.u1,uS_revAct.y)
  connect(addPID.u1,addPD.y)
  connect(lim.y,y)
  connect(antWinErr.y, antWinGai1.u)
  connect(addPD.u2,Dzero.y)
  connect(D.y,addPD.u2)
  connect(addPID.u2,I.y)
  connect(addRes.y,I.y_reset_in)
  connect(antWinErr.u2,lim.y)
  connect(errI1.y,errI2.u1)
  connect(controlError.u1,u_s)
  connect(cheYMinMax.y,assMesYMinMax.u)
  connect(Izero.y,addPID.u2)
  connect(errP.u1,uS_revAct.y)
  connect(errD.u1,uS_revAct.y)
  connect(addPD.u1, P.y)
  connect(addPID.y, lim.u)
  connect(addPID.y, antWinErr.u1)
  connect(addRes.u1, yResSig.y)
  connect(u_m, controlError.u2)
  connect(uMea_revAct.y, errP.u2)
  connect(uMea_revAct.y, errI1.u2)
  connect(addPD.y, addRes.u2)
  connect(errP.y, P.u2)
  connect(P.u1, k)
  connect(antWinGai1.y, antWinGai2.u1)
  connect(antWinGai2.u2, k)
  connect(antWinGai2.y, errI2.u2)
  connect(gaiI.u1, k)
  connect(gaiI.u2, Ti)
  connect(gaiI.y, errIWithGai.u1)
  connect(errI2.y, errIWithGai.u2)
  connect(errIWithGai.y, I.u)
  connect(mulkTd.u1, k)
  connect(greThrkTd.y, assMeskTd.u)
  connect(mulkTd.y, greThrkTd.u)
  connect(mulkTd.u2, Td)
  connect(Td, gaiT.u)
  connect(gaiT.y, D.T)
  connect(mulkTd.y, D.k)
end PIDWithInputGains;


Base class for the block OptimalStart. This base class contains the algorithm for the optimal start calculation. For the
description of the algorithm, please refer to the documentation for the block

Buildings.Controls.OBC.Utilities.OptimalStart.

within Buildings.Controls.OBC.Utilities.BaseClasses;
block OptimalStartCalculation
  "Base class for the block OptimalStart"
  parameter Real tOptMax(
    final quantity="Time",
    final unit="s")
    "Maximum optimal start time";
  parameter Real thrOptOn(
    final quantity="Time",
    final unit="s")
    "Threshold time for the output optOn to become true";
  parameter Integer nDay
    "Number of previous days for averaging the temperature slope";
  parameter Real uLow(
    final quantity="TemperatureDifference",
    final unit="K")
    "Threshold to determine if the zone temperature reaches the occupied setpoint,
     should be a non-negative number";
  parameter Real uHigh(
    final quantity="TemperatureDifference",
    final unit="K")
    "Threshold to determine the need to start the HVAC system before occupancy,
     should be greater than uLow";
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TDif(
    final quantity="TemperatureDifference",
    final unit="K")
    "Difference between zone setpoint and measured temperature, must be bigger than zero for heating and cooling if setpoint is not yet reached"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanInput staCal
    "Start calculation"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput tNexOcc(
    final quantity="Time",
    final unit="s",
    displayUnit="h")
    "Time until next occupancy"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput tOpt(
    final quantity="Time",
    final unit="s",
    displayUnit="h")
    "Optimal start time of HVAC system"
  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput optOn
    "Optimal start boolean output"

protected
  constant Real tReaMin(
    final quantity="Time",
    final unit="s",
    displayUnit="h")=120
    "Minimum value for optimal start time if the system reached the set point almost immediately (used to avoid division by zero)";
  constant Real temSloDef(
    final quantity="TemperatureSlope",
    final unit="K/s")=1/3600
    "Minimum value for temperature slope (used to avoid division by zero)";
  Buildings.Controls.OBC.CDL.Logical.Sources.SampleTrigger samTri(
    final period=86400,
    final shift=0)
    "Trigger that triggers each midnight"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredMovingMean samTemSloAve(
    final n=nDay)
    "Calculate the averaged temperature slope over the past n days"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler dTCalOn
    "Get the sampled temperature difference at the same time each day"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler dTHVACOn
    "Get the temperature difference when the HVAC system starts"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant con(
    final k=0)
    "Deadband case"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant timReaMin(
    final k=tReaMin)
    "Minimum time to reach set point (used to avoid division by zero)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant defTemSlo(
    final k=temSloDef)
    "Default temperature slope in case of zero division"
  Buildings.Controls.OBC.CDL.Logical.Edge edg
    "HVAC start time"
  Buildings.Controls.OBC.CDL.Logical.FallingEdge falEdg
    "The instant when the zone temperature reaches setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hys(
    final uLow=uLow,
    final uHigh=uHigh)
    "Comparing zone temperature with zone setpoint"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis hysOpt(
    final pre_y_start=false,
    final uHigh=0,
    final uLow=-60)
    "Hysteresis to activate the optimal start"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxStaTim(
    final k=tOptMax)
    "Maximum optimal start time"
  Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truHol(
    final falseHoldDuration=0,
    final trueHoldDuration=tOptMax + 11*3600)
    "Hold the start time for timer"
  Buildings.Controls.OBC.CDL.Reals.Divide temSlo
    "Calculate temperature slope"
  Buildings.Controls.OBC.CDL.Logical.Pre pre
    "Break algebraic loops"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub1
    "Calculate the time duration to reach the setpoint"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub2
    "Calculate differential between time-to-next-occupancy and the cool-down time"
  Buildings.Controls.OBC.CDL.Reals.Min min
    "Get the final optimal start time"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triSam
    "The instant when the zone temperature reaches setpoint with maximum time cutoff"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler triSam1
    "Record the start time when the HVAC system is turned on"
  Buildings.Controls.OBC.CDL.Logical.Latch lat
    "Stop calculation when the zone temperature reaches setpoint"
  Buildings.Controls.OBC.CDL.Logical.Timer tim
    "Record time duration for the zone temperature to reach setpoint"
  Buildings.Controls.OBC.CDL.Logical.Not not1
    "Becomes true when the setpoint is reached"
  Buildings.Controls.OBC.CDL.Reals.Divide tOptCal
    "Calculate optimal start time using the averaged previous temperature slope"
  Buildings.Controls.OBC.CDL.Discrete.TriggeredSampler samTimOpt
    "Get the sampled optimal start time at the same time each day"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    final t=thrOptOn)
    "The threshold for optOn signal becomes true"
  Buildings.Controls.OBC.CDL.Logical.And and2
    "Logical and"
  Buildings.Controls.OBC.CDL.Reals.Max timRea
    "Time required to reach the set point"
  Buildings.Controls.OBC.CDL.Reals.Max temSloAve
    "Temperature slope during heat up or cool down over the past sampled days"
  Buildings.Controls.OBC.CDL.Reals.Switch dTUse
    "dT used in the calculations (to avoid negative dT)"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold reqStaUp(
    final t=0,
    final h=0)
    "Output true if optimal startup is needed"
  Buildings.Controls.OBC.CDL.Logical.And triAve
    "Trigger sampling but only if optimal start up is needed"

equation
  connect(tim.y,triSam.u)
  connect(falEdg.y,triSam.trigger)
  connect(not1.y,lat.clr)
  connect(temSlo.y,samTemSloAve.u)
  connect(TDif,hys.u)
  connect(staCal,dTCalOn.trigger)
  connect(TDif,dTHVACOn.u)
  connect(pre.y,dTHVACOn.trigger)
  connect(pre.y,lat.u)
  connect(edg.y,triSam1.trigger)
  connect(triSam1.y,sub1.u2)
  connect(triSam.y,sub1.u1)
  connect(TDif,dTCalOn.u)
  connect(tNexOcc,sub2.u2)
  connect(sub2.y,hysOpt.u)
  connect(min.y,sub2.u1)
  connect(staCal,truHol.u)
  connect(truHol.y,tim.u)
  connect(tim.y,triSam1.u)
  connect(min.y,tOpt)
  connect(not1.u,hys.y)
  connect(lat.y,edg.u)
  connect(lat.y,falEdg.u)
  connect(tOptCal.y,samTimOpt.u)
  connect(staCal,samTimOpt.trigger)
  connect(dTHVACOn.y,temSlo.u1)
  connect(min.y,greThr.u)
  connect(hysOpt.y,and2.u2)
  connect(greThr.y,and2.u1)
  connect(and2.y,pre.u)
  connect(pre.y,optOn)
  connect(timRea.y,temSlo.u2)
  connect(timRea.u1,sub1.y)
  connect(temSloAve.y,tOptCal.u2)
  connect(temSloAve.u1,samTemSloAve.y)
  connect(defTemSlo.y,temSloAve.u2)
  connect(min.u1,samTimOpt.y)
  connect(maxStaTim.y,min.u2)
  connect(reqStaUp.u,dTCalOn.y)
  connect(dTUse.u2,reqStaUp.y)
  connect(dTCalOn.y,dTUse.u1)
  connect(con.y,dTUse.u3)
  connect(dTUse.y,tOptCal.u1)
  connect(triAve.u2,samTri.y)
  connect(reqStaUp.y,triAve.u1)
  connect(triAve.y,samTemSloAve.trigger)
  connect(timReaMin.y, timRea.u2)
end OptimalStartCalculation;


Package with base classes

within Buildings.Controls.OBC.Utilities;
package BaseClasses "Package with base classes"
end BaseClasses;


Package with blocks for setpoint resets

within Buildings.Controls.OBC.Utilities;
package SetPoints "Package with blocks for setpoint resets"
end SetPoints;


Block to compute the supply and return set point. This block computes the set point temperatures for the
supply and return water temperature.
The set point for the zone air temperature can be an input to the model.
It allows to use this model with systems that have night set back.

within Buildings.Controls.OBC.Utilities.SetPoints;
block SupplyReturnTemperatureReset
  "Block to compute the supply and return set point"
  parameter Real m=1.3
    "Exponent for heat transfer";
  parameter Real TSup_nominal(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC")
    "Supply temperature"
  parameter Real TRet_nominal(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC")
    "Return temperature"
  parameter Real TZon_nominal(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC")=293.15
    "Zone temperature"
  parameter Real TOut_nominal(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC")
    "Outside temperature"
  parameter Real dTOutHeaBal(
    final quantity="TemperatureDifference",
    final unit="K",
    displayUnit="K")=8
    "Offset for heating curve";
  CDL.Interfaces.RealInput TSetZon(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC",
    min=200)
    "Zone setpoint temperature"
  CDL.Interfaces.RealInput TOut(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC",
    min=200)
    "Outside temperature"
  CDL.Interfaces.RealOutput TSup(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC",
    min=200)
    "Setpoint for supply temperature"
  CDL.Interfaces.RealOutput TRet(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC",
    min=200)
    "Setpoint for return temperature"

protected
  CDL.Reals.Sources.Constant dTOutHeaBal_nominal(
    final k=dTOutHeaBal,
    y(final quantity="TemperatureDifference",
      final unit="K"))
    "Offset of outdoor temperature to take into account heat gain"
  CDL.Reals.Sources.Constant TSup_nom(
    final k=TSup_nominal,
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Heating supply water temperature at nominal condition"
  CDL.Reals.Sources.Constant TZon_nom(
    final k=TZon_nominal,
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Zone temperature at design condition"
  CDL.Reals.Sources.Constant zer(
    final k=1E-100)
    "Small positive constant to avoid log(0)"
  CDL.Reals.Sources.Constant TRet_nom(
    final k=TRet_nominal,
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Heating return water temperature at nominal condition"
  CDL.Reals.Sources.Constant TOut_nom(
    final k=TOut_nominal,
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Outside temperature at design condition"
  CDL.Reals.Sources.Constant expM(
    final k=m)
    "Exponent of heat transfer"
  CDL.Reals.Sources.Constant one(
    final k=1)
    "Outputs 1"
  CDL.Reals.Add TOutOffSet(
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Effective outside temperature for heat transfer (takes into account zone heat gains)"
  CDL.Reals.Subtract qRelDen(
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Denominator for relative heating load calculation"
  CDL.Reals.Subtract qRelNum(
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Numerator for relative heating load calculation"
  CDL.Reals.Divide qRel "Relative heating load = Q_flow/Q_flow_nominal"
  CDL.Reals.Subtract dTFlu2_nom
    "Heating supply minus return water temperature at nominal condition"
  CDL.Reals.Average TFluAve_nominal(
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Average heating water temperature at nominal condition"
  CDL.Reals.Subtract dTFluAve_nominal(
    y(final quantity="TemperatureDifference",
      final unit="K"))
    "Average heating water temperature minus room temperature at nominal condition"
  CDL.Reals.Divide mInv "Inverse of heat transfer exponent, y = 1/m"
  CDL.Reals.Add TAve(
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Average of supply and return temperature"
  CDL.Reals.Add TSupCur(
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Current supply water temperature"
  CDL.Reals.Subtract TRetCur(
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Current return water temperature"
  CDL.Reals.Max qRel0
    "Relative heating load, but always non-zero value"
  CDL.Reals.Multiply pro "Product used to compute q^(1/m)"
  CDL.Reals.Exp qRaiInvM
    "Outputs qRel^(1/m)"
  CDL.Reals.Log log1
    "Logarithm used for evaluation of qRel^(1/m)"
  CDL.Reals.Multiply dTQ(y(
    final quantity="TemperatureDifference",
    final unit="K")) "Temperature contribution due to qRel^(1/m)"
  CDL.Reals.Multiply dTFlu(y(
    final quantity="TemperatureDifference",
    final unit="K")) "Supply minus return water temperature"
  CDL.Reals.Add TOutOffSet_nominal(
    y(final quantity="ThermodynamicTemperature",
      final unit="K",
      displayUnit="degC"))
    "Effective outside temperature for heat transfer at nominal condition (takes into account zone heat gains)"
  CDL.Reals.MultiplyByParameter gai(
    final k=0.5,
    y(final quantity="TemperatureDifference",
      final unit="K")) "Gain factor"

equation
  connect(dTOutHeaBal_nominal.y,TOutOffSet.u1)
  connect(TOut,TOutOffSet.u2)
  connect(TZon_nom.y,qRelDen.u1)
  connect(qRel.y,qRel0.u2)
  connect(zer.y,qRel0.u1)
  connect(dTFlu2_nom.u1,TSup_nom.y)
  connect(dTFlu2_nom.u2,TRet_nom.y)
  connect(TFluAve_nominal.u1,TSup_nom.y)
  connect(TRet_nom.y,TFluAve_nominal.u2)
  connect(dTFluAve_nominal.u2,TZon_nom.y)
  connect(qRel0.y,log1.u)
  connect(one.y,mInv.u1)
  connect(expM.y,mInv.u2)
  connect(log1.y,pro.u1)
  connect(pro.u2,mInv.y)
  connect(qRaiInvM.u,pro.y)
  connect(dTQ.u1,dTFluAve_nominal.y)
  connect(qRaiInvM.y,dTQ.u2)
  connect(TSetZon,TAve.u1)
  connect(TAve.u2,dTQ.y)
  connect(qRel0.y,dTFlu.u2)
  connect(TSupCur.u1,TAve.y)
  connect(dTFlu.y,TSupCur.u2)
  connect(TSupCur.y,TSup)
  connect(TRetCur.u1,TAve.y)
  connect(TRetCur.u2,dTFlu.y)
  connect(TRetCur.y,TRet)
  connect(qRel.u1,qRelNum.y)
  connect(qRel.u2,qRelDen.y)
  connect(TOutOffSet_nominal.u1,TOut_nom.y)
  connect(dTOutHeaBal_nominal.y,TOutOffSet_nominal.u2)
  connect(TOutOffSet_nominal.y,qRelDen.u2)
  connect(TSetZon, qRelNum.u1)
  connect(TOutOffSet.y, qRelNum.u2)
  connect(dTFlu2_nom.y, gai.u)
  connect(gai.y, dTFlu.u1)
  connect(TFluAve_nominal.y, dTFluAve_nominal.u1)
end SupplyReturnTemperatureReset;


within Buildings.Controls.OBC.Utilities.SetPoints;
package Validation "Collection of models that validate the SetPoints blocks of the CDL"
end Validation;


Test model for the heating curve. Example that demonstrates the use of the hot water temperature reset
for a heating system.
The parameters of the block heaCur
are for a heating system with
60°C supply water temperature and
40°C return water temperature at
an outside temperature of
-10°C and a room temperature of
20°C. The offset for the temperature reset is
8 Kelvin, i.e., above
12°C outside temperature, there is no heating load.
The figure below shows the computed supply and return water temperatures.

within Buildings.Controls.OBC.Utilities.SetPoints.Validation;
model SupplyReturnTemperatureReset
  "Test model for the heating curve"
  Buildings.Controls.OBC.Utilities.SetPoints.SupplyReturnTemperatureReset heaCur(
    m=1,
    TSup_nominal=333.15,
    TRet_nominal=313.15,
    TOut_nominal=263.15)
    "Compute the supply and return set point of heating systems with varying outdoor temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp TOut(
    height=40,
    duration=1,
    offset=263.15,
    y(unit="K"))
    "Outdoor temperature varying from -10 degC to 30 degC"
  Buildings.Controls.OBC.Utilities.SetPoints.SupplyReturnTemperatureReset heaCur1(
    m=1,
    dTOutHeaBal=15,
    TSup_nominal=333.15,
    TRet_nominal=313.15,
    TOut_nominal=263.15)
    "Compute the supply and return set point of heating systems with changing room setpoint temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Pulse TRoo1(
    offset=273.15+20,
    shift=0.5,
    amplitude=-5,
    period=1,
    y(unit="K"))
    "Night set back from 20 degC to 15 degC"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOut1(
    k=273.15-10,
    y(unit="K"))
    "Constant outdoor air temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TRoo(
    k=273.15+20,
    y(unit="K"))
    "Room temperature 20 degC"

equation
  connect(TOut1.y,heaCur1.TOut)
  connect(TOut.y,heaCur.TOut)
  connect(TRoo.y,heaCur.TSetZon)
  connect(TRoo1.y,heaCur1.TSetZon)
end SupplyReturnTemperatureReset;