Start file for simple house example

within Buildings.Examples.Tutorial.SimpleHouse;
model SimpleHouse0
  "Start file for simple house example"
  extends Modelica.Icons.Example;
  package MediumAir = Buildings.Media.Air "Medium model for air";
  package MediumWater = Buildings.Media.Water "Medium model for water";
  parameter Modelica.Units.SI.Area AWall = 100 "Wall area";
  parameter Modelica.Units.SI.Length dWall = 0.25 "Wall thickness";
  parameter Modelica.Units.SI.ThermalConductivity kWall = 0.04 "Wall thermal conductivity";
  parameter Modelica.Units.SI.Density rhoWall = 2000 "Wall density";
  parameter Modelica.Units.SI.SpecificHeatCapacity cpWall = 1000 "Wall specific heat capacity";
  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=
        Modelica.Utilities.Files.loadResource(
        "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Weather data reader"
  Buildings.BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TOut
    "Exterior temperature boundary condition"
equation
  connect(weaDat.weaBus, weaBus)
  connect(TOut.T, weaBus.TDryBul)
end SimpleHouse0;


Building wall model. A very simple building envelope model will be constructed manually using thermal resistors and heat capacitors.
The house consists of a wall represented by a single heat capacitor and a thermal resistor.
The boundary temperature are already included in

Buildings.Examples.Tutorial.SimpleHouse.SimpleHouse0.
The wall has a surface area of Awall=100 m2,
a thickness of dwall=25 cm,
a thermal conductivity of kwall=0.04 W/(m K),
a density of ρwall=2000 kg/m3,
and a specific heat capacity of cp,wall= 1000 J/(kg K)

within Buildings.Examples.Tutorial.SimpleHouse;
model SimpleHouse1 "Building wall model"
  extends SimpleHouse0;

  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor walCap(
    C=AWall*dWall*cpWall*rhoWall,
    T(fixed=true))
    "Thermal mass of wall"
  Modelica.Thermal.HeatTransfer.Components.ThermalResistor walRes(
    R=dWall/AWall/kWall) "Thermal resistor for wall: 25 cm of rockwool"
equation
  connect(walRes.port_b, walCap.port)
  connect(TOut.port, walRes.port_a)
end SimpleHouse1;


Building window model. The window has a surface area of 2 m2.
In this simple model we will therefore assume that
two times the outdoor solar irradiance is injected as heat onto the inside of the wall.

within Buildings.Examples.Tutorial.SimpleHouse;
model SimpleHouse2 "Building window model"
  extends SimpleHouse1;

  parameter Modelica.Units.SI.Area AWin=2 "Window area";

  Modelica.Blocks.Math.Gain gaiWin(k=AWin)
    "Gain for solar irradiance through the window"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow win
    "Very simple window model"
equation
  connect(gaiWin.y, win.Q_flow)
  connect(gaiWin.u, weaBus.HDirNor)
  connect(win.port, walCap.port)
end SimpleHouse2;


Air model

within Buildings.Examples.Tutorial.SimpleHouse;
model SimpleHouse3 "Air model"
  extends SimpleHouse2;

  parameter Modelica.Units.SI.Volume VZone=8*8*3 "Zone volume";
  parameter Modelica.Units.SI.MassFlowRate mAir_flow_nominal=1
    "Nominal mass flow rate for air loop";
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hWall=2
    "Convective heat transfer coefficient at the wall";

  Modelica.Thermal.HeatTransfer.Components.ThermalResistor conRes(R=1/hWall/
        AWall) "Thermal resistance for convective heat transfer"
  Buildings.Fluid.MixingVolumes.MixingVolume zon(
    redeclare package Medium = MediumAir,
    V=VZone,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    m_flow_nominal=mAir_flow_nominal) "Very simple zone air model"
equation
  connect(zon.heatPort, conRes.port_a)
  connect(conRes.port_b, walCap.port)
end SimpleHouse3;


Heating model

within Buildings.Examples.Tutorial.SimpleHouse;
model SimpleHouse4 "Heating model"
  extends SimpleHouse3;

  constant Boolean use_constantHeater=true
    "To enable/disable the connection between the constant source and heater and circulation pump";

  parameter Modelica.Units.SI.HeatFlowRate QHea_flow_nominal=3000
    "Nominal capacity of heating system";
  parameter Modelica.Units.SI.MassFlowRate mWat_flow_nominal=0.1
    "Nominal mass flow rate for water loop";

  Buildings.Fluid.HeatExchangers.Radiators.RadiatorEN442_2 rad(
    redeclare package Medium = MediumWater,
    T_a_nominal=333.15,
    T_b_nominal=313.15,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    allowFlowReversal=false,
    Q_flow_nominal=QHea_flow_nominal) "Radiator"

  Buildings.Fluid.HeatExchangers.HeaterCooler_u heaWat(
    redeclare package Medium = MediumWater,
    m_flow_nominal=mWat_flow_nominal,
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState,
    allowFlowReversal=false,
    dp_nominal=5000,
    Q_flow_nominal=QHea_flow_nominal) "Heater for water circuit"

  Fluid.Movers.Preconfigured.FlowControlled_m_flow pum(
    redeclare package Medium = MediumWater,
    use_riseTime=false,
    m_flow_nominal=mWat_flow_nominal,
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState,
    allowFlowReversal=false) "Pump"

  Buildings.Fluid.Sources.Boundary_pT bouWat(
    redeclare package Medium = MediumWater,
    nPorts=1)
    "Pressure bound for water circuit"
  Modelica.Blocks.Sources.Constant conHea(k=1)
    if use_constantHeater "Gain for heater"
  Modelica.Blocks.Sources.Constant conPum(k=mWat_flow_nominal)
    if use_constantHeater "Gain for pump"
equation
  connect(heaWat.port_b,rad. port_a)
  connect(rad.port_b, pum.port_a)
  connect(heaWat.port_a, pum.port_b)
  connect(rad.heatPortCon, zon.heatPort)
  connect(rad.heatPortRad, walCap.port)
  connect(conPum.y, pum.m_flow_in)
  connect(conHea.y, heaWat.u)
  connect(bouWat.ports[1], pum.port_b)
end SimpleHouse4;


Heating controller model. Since the zone becomes too warm, a controller is required that disables the heater when a setpoint is reached.
We will implement a hysteresis controller with a setpoint of 295.15 +/- 1K (21-23°C).
A temperature sensor will measure the zone air temperature.

within Buildings.Examples.Tutorial.SimpleHouse;
model SimpleHouse5 "Heating controller model"
  extends SimpleHouse4(final use_constantHeater=false);

  Modelica.Blocks.Math.BooleanToReal booRea1(realTrue=mWat_flow_nominal)
    "Boolean to integer"
  Modelica.Blocks.Math.BooleanToReal booRea "Boolean to real"
  Modelica.Blocks.Logical.Hysteresis hysRad(uLow=273.15 + 21, uHigh=273.15 + 23)
    "Hysteresis controller for radiator"
  Modelica.Blocks.Logical.Not not1
    "Negation for enabling heating when temperature is low"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor senTemZonAir
    "Zone air temperature sensor"
equation
  connect(booRea1.u, not1.y)
  connect(not1.u,hysRad. y)
  connect(senTemZonAir.T,hysRad. u)
  connect(senTemZonAir.port, zon.heatPort)
  connect(not1.y, booRea.u)
  connect(booRea.y, heaWat.u)
  connect(booRea1.y, pum.m_flow_in)
end SimpleHouse5;


Free cooling model

within Buildings.Examples.Tutorial.SimpleHouse;
model SimpleHouse6 "Free cooling model"
  extends SimpleHouse5(
    zon(nPorts=2),
    mAir_flow_nominal=0.1,
    AWin=6);

  parameter Modelica.Units.SI.PressureDifference dpAir_nominal=200
    "Pressure drop at nominal mass flow rate for air loop";

  Buildings.Fluid.Actuators.Dampers.Exponential vavDam(
    redeclare package Medium = MediumAir,
    from_dp=true,
    m_flow_nominal=mAir_flow_nominal,
    dpDamper_nominal=dpAir_nominal)
    "Damper"
  Buildings.Fluid.Movers.Preconfigured.FlowControlled_dp fan(
    redeclare package Medium = MediumAir,
    show_T=true,
    dp_nominal=dpAir_nominal,
    use_riseTime=false,
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState,
    m_flow_nominal=mAir_flow_nominal) "Constant head fan"

  Buildings.Fluid.HeatExchangers.ConstantEffectiveness hexRec(
    redeclare package Medium1 = MediumAir,
    redeclare package Medium2 = MediumAir,
    dp1_nominal=10,
    dp2_nominal=10,
    m1_flow_nominal=mAir_flow_nominal,
    m2_flow_nominal=mAir_flow_nominal,
    eps=0.85) "Heat exchanger for heat recuperation"
  Buildings.Fluid.Sources.Boundary_pT bouAir(
    redeclare package Medium = MediumAir,
    use_T_in=true,
    nPorts=2) "Air boundary with constant temperature"
  Modelica.Blocks.Logical.Hysteresis hysAir(uLow=273.15 + 23, uHigh=273.15 + 25)
    "Hysteresis controller for damper"
  Modelica.Blocks.Math.BooleanToReal booRea2 "Boolean to real"
  Modelica.Blocks.Math.BooleanToReal booRea3(realTrue=dpAir_nominal)
    "Boolean to real"
  Buildings.Fluid.Sensors.TemperatureTwoPort TFanIn(
    redeclare final package Medium = MediumAir,
    final m_flow_nominal=mAir_flow_nominal,
    tau=0) "Temperature at fan inlet"
  Buildings.Fluid.Sensors.TemperatureTwoPort TFanOut(
    redeclare final package Medium = MediumAir,
    final m_flow_nominal=mAir_flow_nominal,
    tau=0) "Temperature at fan outlet"
equation
  connect(hexRec.port_a1, zon.ports[1])
  connect(bouAir.T_in, weaBus.TDryBul)
  connect(vavDam.port_b, zon.ports[2])
  connect(booRea2.y, vavDam.y)
  connect(hysAir.y, booRea2.u)
  connect(bouAir.ports[1], hexRec.port_a2)
  connect(hexRec.port_b1, bouAir.ports[2])
  connect(booRea1.y, pum.m_flow_in)
  connect(hysAir.u, hysRad.u)
  connect(booRea3.y, fan.dp_in)
  connect(booRea3.u, hysAir.y)
  connect(hexRec.port_b2, TFanIn.port_a)
  connect(TFanIn.port_b, fan.port_a)
  connect(vavDam.port_a, TFanOut.port_b)
  connect(TFanOut.port_a, fan.port_b)
end SimpleHouse6;


within Buildings.Examples.Tutorial;
package SpaceCooling "Package with example for how to build a model for space cooling"
  extends Modelica.Icons.ExamplesPackage;
end SpaceCooling;


within Buildings.Examples.Tutorial.SpaceCooling;
model System1
  "First part of the system model, consisting of the room with heat transfer"
  extends Modelica.Icons.Example;
  replaceable package MediumA = Buildings.Media.Air "Medium for air";

  Buildings.Fluid.MixingVolumes.MixingVolume vol(
    redeclare package Medium = MediumA,
    m_flow_nominal=mA_flow_nominal,
    V=V,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    mSenFac=3)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon(G=10000/30)
    "Thermal conductance with the ambient"
  parameter Modelica.Units.SI.Volume V=6*10*3 "Room volume";
  parameter Modelica.Units.SI.MassFlowRate mA_flow_nominal=V*1.2*6/3600
    "Nominal mass flow rate";
  parameter Modelica.Units.SI.HeatFlowRate QRooInt_flow=1000
    "Internal heat gains of the room";
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature TOut(T=263.15)
    "Outside temperature"
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow preHea(Q_flow=
        QRooInt_flow) "Prescribed heat flow"
equation
  connect(TOut.port, theCon.port_a)
  connect(theCon.port_b, vol.heatPort)
  connect(preHea.port, vol.heatPort)
end System1;


within Buildings.Examples.Tutorial.SpaceCooling;
model System2
  "Second part of the system model with air supply and open loop control"
  extends Modelica.Icons.Example;

  replaceable package MediumA = Buildings.Media.Air "Medium for air";
  replaceable package MediumW = Buildings.Media.Water "Medium for water";

  Buildings.Fluid.MixingVolumes.MixingVolume vol(
    redeclare package Medium = MediumA,
    m_flow_nominal=mA_flow_nominal,
    V=V,
    nPorts=2,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    mSenFac=3)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon(G=10000/30)
    "Thermal conductance with the ambient"
  parameter Modelica.Units.SI.Volume V=6*10*3 "Room volume";
  //////////////////////////////////////////////////////////
  // Heat recovery effectiveness
  parameter Real eps = 0.8 "Heat recovery effectiveness";

  /////////////////////////////////////////////////////////
  // Design air conditions
  parameter Modelica.Units.SI.Temperature TASup_nominal=291.15
    "Nominal air temperature supplied to room";
  parameter Modelica.Units.SI.DimensionlessRatio wASup_nominal=0.012
    "Nominal air humidity ratio supplied to room [kg/kg] assuming 90% relative humidity";
  parameter Modelica.Units.SI.Temperature TRooSet=297.15
    "Nominal room air temperature";
  parameter Modelica.Units.SI.Temperature TOut_nominal=303.15
    "Design outlet air temperature";
  parameter Modelica.Units.SI.Temperature THeaRecLvg=TOut_nominal - eps*(
      TOut_nominal - TRooSet) "Air temperature leaving the heat recovery";
  parameter Modelica.Units.SI.DimensionlessRatio wHeaRecLvg=0.0135
    "Air humidity ratio leaving the heat recovery [kg/kg]";

  /////////////////////////////////////////////////////////
  // Cooling loads and air mass flow rates
  parameter Modelica.Units.SI.HeatFlowRate QRooInt_flow=1000
    "Internal heat gains of the room";
  parameter Modelica.Units.SI.HeatFlowRate QRooC_flow_nominal=-QRooInt_flow -
      10E3/30*(TOut_nominal - TRooSet) "Nominal cooling load of the room";
  parameter Modelica.Units.SI.MassFlowRate mA_flow_nominal=1.3*
      QRooC_flow_nominal/1006/(TASup_nominal - TRooSet)
    "Nominal air mass flow rate, increased by factor 1.3 to allow for recovery after temperature setback";
  parameter Modelica.Units.SI.TemperatureDifference dTFan=2
    "Estimated temperature raise across fan that needs to be made up by the cooling coil";
  parameter Modelica.Units.SI.HeatFlowRate QCoiC_flow_nominal=mA_flow_nominal*(
      TASup_nominal - THeaRecLvg - dTFan)*1006 + mA_flow_nominal*(wASup_nominal
       - wHeaRecLvg)*2458.3e3
    "Cooling load of coil, taking into account outside air sensible and latent heat removal";

  /////////////////////////////////////////////////////////
  // Water temperatures and mass flow rates
  parameter Modelica.Units.SI.Temperature TWSup_nominal=285.15
    "Water supply temperature";
  parameter Modelica.Units.SI.Temperature TWRet_nominal=289.15
    "Water return temperature";
  parameter Modelica.Units.SI.MassFlowRate mW_flow_nominal=-QCoiC_flow_nominal/
      (TWRet_nominal - TWSup_nominal)/4200 "Nominal water mass flow rate";

  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature TOut
    "Outside temperature"
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow preHea(Q_flow=
        QRooInt_flow) "Prescribed heat flow"
  Buildings.Fluid.Movers.FlowControlled_m_flow fan(
    redeclare package Medium = MediumA,
    nominalValuesDefineDefaultPressureCurve=true,
    m_flow_nominal=mA_flow_nominal,
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState) "Supply air fan"
  Buildings.Fluid.HeatExchangers.ConstantEffectiveness hex(redeclare package Medium1 =
        MediumA, redeclare package Medium2 = MediumA,
    m1_flow_nominal=mA_flow_nominal,
    m2_flow_nominal=mA_flow_nominal,
    dp1_nominal=200,
    dp2_nominal=200,
    eps=eps) "Heat recovery"
  Buildings.Fluid.HeatExchangers.WetCoilEffectivenessNTU cooCoi(
    redeclare package Medium1 = MediumW,
    redeclare package Medium2 = MediumA,
    m1_flow_nominal=mW_flow_nominal,
    m2_flow_nominal=mA_flow_nominal,
    dp1_nominal=6000,
    dp2_nominal=200,
    use_Q_flow_nominal=true,
    Q_flow_nominal=QCoiC_flow_nominal,
    T_a1_nominal=TWSup_nominal,
    T_a2_nominal=THeaRecLvg,
    w_a2_nominal=wHeaRecLvg,
    show_T=true,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial) "Cooling coil"
  Buildings.Fluid.Sources.Outside out(nPorts=2, redeclare package Medium = MediumA)
  Buildings.Fluid.Sources.MassFlowSource_T souWat(
    nPorts=1,
    redeclare package Medium = MediumW,
    use_m_flow_in=true,
    T=TWSup_nominal) "Source for water flow rate"
  Buildings.Fluid.Sources.Boundary_pT sinWat(nPorts=1, redeclare package Medium =
        MediumW) "Sink for water circuit"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    pAtmSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
    TDryBulSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
    TDryBul=TOut_nominal,
    filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Weather data reader"
  BoundaryConditions.WeatherData.Bus weaBus
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant mAir_flow(k=
        mA_flow_nominal) "Fan air flow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant mWat_flow(k=mW_flow_nominal)
    "Water flow rate"
  Buildings.Fluid.Sensors.TemperatureTwoPort senTemHXOut(redeclare package Medium =
        MediumA, m_flow_nominal=mA_flow_nominal)
    "Temperature sensor for heat recovery outlet on supply side"
  Buildings.Fluid.Sensors.TemperatureTwoPort senTemSupAir(redeclare package Medium =
        MediumA, m_flow_nominal=mA_flow_nominal)
    "Temperature sensor for supply air"
equation
  connect(theCon.port_b, vol.heatPort)
  connect(preHea.port, vol.heatPort)
  connect(fan.port_b, vol.ports[1])
  connect(vol.ports[2], hex.port_a2)
  connect(out.ports[1], hex.port_a1)
  connect(out.ports[2], hex.port_b2)

  connect(souWat.ports[1], cooCoi.port_a1)
  connect(cooCoi.port_b1, sinWat.ports[1])
  connect(weaDat.weaBus, out.weaBus)
  connect(weaDat.weaBus, weaBus)
  connect(weaBus.TDryBul, TOut.T)
  connect(fan.m_flow_in, mAir_flow.y)
  connect(mWat_flow.y, souWat.m_flow_in)
  connect(hex.port_b1, senTemHXOut.port_a)
  connect(senTemHXOut.port_b, cooCoi.port_a2)
  connect(cooCoi.port_b2, senTemSupAir.port_a)
  connect(senTemSupAir.port_b, fan.port_a)
  connect(TOut.port, theCon.port_a)
end System2;


within Buildings.Examples.Tutorial.SpaceCooling;
model System3
  "Third part of the system model with air supply and closed loop control"
  extends Modelica.Icons.Example;

  replaceable package MediumA = Buildings.Media.Air "Medium for air";
  replaceable package MediumW = Buildings.Media.Water "Medium for water";

  Buildings.Fluid.MixingVolumes.MixingVolume vol(
    redeclare package Medium = MediumA,
    m_flow_nominal=mA_flow_nominal,
    V=V,
    nPorts=2,
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyStateInitial,
    mSenFac=3)
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor theCon(G=10000/30)
    "Thermal conductance with the ambient"
  parameter Modelica.Units.SI.Volume V=6*10*3 "Room volume";
  //////////////////////////////////////////////////////////
  // Heat recovery effectiveness
  parameter Real eps = 0.8 "Heat recovery effectiveness";

  /////////////////////////////////////////////////////////
  // Design air conditions
  parameter Modelica.Units.SI.Temperature TASup_nominal=291.15
    "Nominal air temperature supplied to room";
  parameter Modelica.Units.SI.DimensionlessRatio wASup_nominal=0.012
    "Nominal air humidity ratio supplied to room [kg/kg] assuming 90% relative humidity";
  parameter Modelica.Units.SI.Temperature TRooSet=297.15
    "Nominal room air temperature";
  parameter Modelica.Units.SI.Temperature TOut_nominal=303.15
    "Design outlet air temperature";
  parameter Modelica.Units.SI.Temperature THeaRecLvg=TOut_nominal - eps*(
      TOut_nominal - TRooSet) "Air temperature leaving the heat recovery";
  parameter Modelica.Units.SI.DimensionlessRatio wHeaRecLvg=0.0135
    "Air humidity ratio leaving the heat recovery [kg/kg]";

  /////////////////////////////////////////////////////////
  // Cooling loads and air mass flow rates
  parameter Modelica.Units.SI.HeatFlowRate QRooInt_flow=1000
    "Internal heat gains of the room";
  parameter Modelica.Units.SI.HeatFlowRate QRooC_flow_nominal=-QRooInt_flow -
      10E3/30*(TOut_nominal - TRooSet) "Nominal cooling load of the room";
  parameter Modelica.Units.SI.MassFlowRate mA_flow_nominal=1.3*
      QRooC_flow_nominal/1006/(TASup_nominal - TRooSet)
    "Nominal air mass flow rate, increased by factor 1.3 to allow for recovery after temperature setback";
  parameter Modelica.Units.SI.TemperatureDifference dTFan=2
    "Estimated temperature raise across fan that needs to be made up by the cooling coil";
  parameter Modelica.Units.SI.HeatFlowRate QCoiC_flow_nominal=mA_flow_nominal*(
      TASup_nominal - THeaRecLvg - dTFan)*1006 + mA_flow_nominal*(wASup_nominal
       - wHeaRecLvg)*2458.3e3
    "Cooling load of coil, taking into account outside air sensible and latent heat removal";

  /////////////////////////////////////////////////////////
  // Water temperatures and mass flow rates
  parameter Modelica.Units.SI.Temperature TWSup_nominal=285.15
    "Water supply temperature";
  parameter Modelica.Units.SI.Temperature TWRet_nominal=289.15
    "Water return temperature";
  parameter Modelica.Units.SI.MassFlowRate mW_flow_nominal=-QCoiC_flow_nominal/
      (TWRet_nominal - TWSup_nominal)/4200 "Nominal water mass flow rate";

  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature TOut
    "Outside temperature"
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow preHea(Q_flow=
        QRooInt_flow) "Prescribed heat flow"
  Buildings.Fluid.Movers.FlowControlled_m_flow fan(
    redeclare package Medium = MediumA,
    nominalValuesDefineDefaultPressureCurve=true,
    m_flow_nominal=mA_flow_nominal,
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState) "Supply air fan"
  Buildings.Fluid.HeatExchangers.ConstantEffectiveness hex(redeclare package Medium1 =
        MediumA, redeclare package Medium2 = MediumA,
    m1_flow_nominal=mA_flow_nominal,
    m2_flow_nominal=mA_flow_nominal,
    dp1_nominal=200,
    dp2_nominal=200,
    eps=eps) "Heat recovery"
  Buildings.Fluid.HeatExchangers.WetCoilEffectivenessNTU cooCoi(
    redeclare package Medium1 = MediumW,
    redeclare package Medium2 = MediumA,
    m1_flow_nominal=mW_flow_nominal,
    m2_flow_nominal=mA_flow_nominal,
    dp1_nominal=6000,
    dp2_nominal=200,
    use_Q_flow_nominal=true,
    Q_flow_nominal=QCoiC_flow_nominal,
    T_a1_nominal=TWSup_nominal,
    T_a2_nominal=THeaRecLvg,
    w_a2_nominal=wHeaRecLvg,
    show_T=true,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial) "Cooling coil"
  Buildings.Fluid.Sources.Outside out(nPorts=2, redeclare package Medium = MediumA)
  Buildings.Fluid.Sources.MassFlowSource_T souWat(
    nPorts=1,
    redeclare package Medium = MediumW,
    use_m_flow_in=true,
    T=TWSup_nominal) "Source for water flow rate"
  Buildings.Fluid.Sources.Boundary_pT sinWat(nPorts=1, redeclare package Medium =
        MediumW) "Sink for water circuit"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    pAtmSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
    TDryBul=TOut_nominal,
    filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"),
    TDryBulSou=Buildings.BoundaryConditions.Types.DataSource.File)
    "Weather data reader"
  BoundaryConditions.WeatherData.Bus weaBus
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant mAir_flow(k=mA_flow_nominal)
    "Fan air flow rate"
  Buildings.Fluid.Sensors.TemperatureTwoPort senTemHXOut(redeclare package Medium =
        MediumA, m_flow_nominal=mA_flow_nominal)
    "Temperature sensor for heat recovery outlet on supply side"
  Buildings.Fluid.Sensors.TemperatureTwoPort senTemSupAir(redeclare package Medium =
        MediumA, m_flow_nominal=mA_flow_nominal)
    "Temperature sensor for supply air"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TRooSetPoi(k=TRooSet)
    "Room temperature set point"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor senTemRoo
    "Room temperature sensor"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal mWat_flow(realTrue=0, realFalse=
        mW_flow_nominal) "Conversion from boolean to real for water flow rate"
  Buildings.Controls.OBC.CDL.Reals.Subtract sub
    "Inputs different"
  Buildings.Controls.OBC.CDL.Reals.Hysteresis con(
    final uLow=-0.5,
    final uHigh=0.5)
    "Controller for coil water flow rate"
equation
  connect(theCon.port_b, vol.heatPort)
  connect(preHea.port, vol.heatPort)
  connect(fan.port_b, vol.ports[1])
  connect(vol.ports[2], hex.port_a2)
  connect(out.ports[1], hex.port_a1)
  connect(out.ports[2], hex.port_b2)
  connect(souWat.ports[1], cooCoi.port_a1)
  connect(cooCoi.port_b1, sinWat.ports[1])
  connect(weaDat.weaBus, out.weaBus)
  connect(weaDat.weaBus, weaBus)
  connect(weaBus.TDryBul, TOut.T)
  connect(fan.m_flow_in, mAir_flow.y)
  connect(hex.port_b1, senTemHXOut.port_a)
  connect(senTemHXOut.port_b, cooCoi.port_a2)
  connect(cooCoi.port_b2, senTemSupAir.port_a)
  connect(senTemSupAir.port_b, fan.port_a)
  connect(TOut.port, theCon.port_a)
  connect(vol.heatPort, senTemRoo.port)
  connect(mWat_flow.y, souWat.m_flow_in)
  connect(sub.y, con.u)
  connect(con.y, mWat_flow.u)
  connect(TRooSetPoi.y, sub.u1)
  connect(senTemRoo.T, sub.u2)
end System3;


within Buildings.Examples;
package VAVCO2 "Variable air volume flow system of MIT building with continuous time control for static pressure reset"
  extends Modelica.Icons.ExamplesPackage;

end VAVCO2;


within Buildings.Examples.VAVCO2;
model VAVSystemCTControl
  "Variable air volume flow system of MIT building with CO2 control and continuous time control for static pressure reset"
  extends Modelica.Icons.Example;

  package Medium = Buildings.Media.Air(extraPropertiesNames={"CO2"});
  parameter Modelica.Units.SI.MassFlowRate mMIT_flow=roo.m0Tot_flow
    "Nominal mass flow rate of MIT system model as in ASHRAE 825-RP";
  parameter Modelica.Units.SI.PressureDifference dpSuiSup_nominal(displayUnit=
        "Pa") = 95
    "Pressure drop supply air leg with splitters of one suite (obtained from simulation)";
  parameter Modelica.Units.SI.PressureDifference dpSuiRet_nominal(displayUnit=
        "Pa") = 233
    "Pressure drop return air leg with splitters of one suite (obtained from simulation)";
  parameter Modelica.Units.SI.PressureDifference dpFanSupMIT_nominal(
      displayUnit="Pa") = 1050
    "Pressure increase over supply fan in MIT system model as in ASHRAE 825-RP (obtained from simulation)";
  parameter Modelica.Units.SI.PressureDifference dpFanRetMIT_nominal(
      displayUnit="Pa") = 347
    "Pressure increase over supply fan in MIT system model as in ASHRAE 825-RP (obtained from simulation)";
parameter Real scaM_flow = 1 "Scaling factor for mass flow rate";
parameter Real scaDpFanSup_nominal = 1
    "Scaling factor for supply fan pressure lift with NSui number of suites";
parameter Real scaDpFanRet_nominal = 1
    "Scaling factor for supply fan pressure lift with NSui number of suites";
  parameter Real l(min=1e-10, max=1) = 6.708204E-04
    "Damper leakage, ratio of flow coefficients k(y=0)/k(y=1)"
  Modelica.Blocks.Sources.Constant PAtm(k=101325)
  Modelica.Blocks.Sources.Constant yDam(k=0.5)
  Buildings.Fluid.FixedResistances.PressureDrop res31(
    dp_nominal=0.546,
    m_flow_nominal=scaM_flow*1,
    redeclare package Medium = Medium,
    from_dp=true)
  Buildings.Fluid.FixedResistances.PressureDrop res33(
    dp_nominal=0.164,
    m_flow_nominal=scaM_flow*1,
    redeclare package Medium = Medium)
  Buildings.Fluid.FixedResistances.PressureDrop res57(
    dp_nominal=0.118000,
    m_flow_nominal=scaM_flow*1,
    redeclare package Medium = Medium,
    from_dp=true)
  Buildings.Examples.VAVCO2.BaseClasses.Suite roo(
    redeclare package Medium = Medium,
    scaM_flow=scaM_flow,
    l=l)
  Fluid.Actuators.Dampers.MixingBox mixBox(
    mOut_flow_nominal=scaM_flow*1,
    mRec_flow_nominal=scaM_flow*1,
    mExh_flow_nominal=scaM_flow*1,
    redeclare package Medium = Medium,
    allowFlowReversal=true,
    from_dp=false,
    use_strokeTime=false,
    dpDamExh_nominal=0.27,
    dpDamOut_nominal=0.27,
    dpDamRec_nominal=0.27,
    dpFixExh_nominal=0.467,
    dpFixOut_nominal=0.467,
    dpFixRec_nominal=0.665,
    l=l) "mixing box"
  Buildings.Fluid.Sources.Boundary_pT bouIn(
    redeclare package Medium = Medium,
    use_p_in=true,
    T=293.15,
    nPorts=2)
  Buildings.Controls.Continuous.LimPID conSupFan(
    Ti=60,
    yMax=1,
    yMin=0,
    Td=60,
    k=0.1,
    initType=Modelica.Blocks.Types.Init.InitialState,
    controllerType=Modelica.Blocks.Types.SimpleController.P)
    "Controller for supply fan"
  Buildings.Fluid.Movers.FlowControlled_dp fan32(
    redeclare package Medium = Medium,
    per(pressure(final V_flow={0,11.08,14.9}, dp={1508,743,100})),
    use_riseTime=false,
    init=Modelica.Blocks.Types.Init.InitialState,
    m_flow_nominal=mMIT_flow,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial)
  Buildings.Fluid.Movers.FlowControlled_dp fan56(
    redeclare package Medium = Medium,
    per(pressure(final V_flow={2.676,11.05}, dp={600,100})),
    use_riseTime=false,
    init=Modelica.Blocks.Types.Init.InitialState,
    m_flow_nominal=mMIT_flow,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial)
  Modelica.Blocks.Sources.BooleanPulse onSig(
    period=86400,
    startTime=6*3600,
    width=50) "On/off signal for plant"
  Modelica.Blocks.Math.Gain dp32(k=150) "Gain for fan"
  Modelica.Blocks.Math.Gain dp56(k=60) "Gain for fan"
  Modelica.Blocks.Logical.Switch switch1
  Modelica.Blocks.Sources.Constant off(k=0) "Off signal"
  Controls.OBC.CDL.Conversions.BooleanToReal booToRea(realTrue=120)
    "Boolean to real conversion, outputs static pressure set point"
  Controls.OBC.CDL.Reals.LimitSlewRate ramLim(raisingSlewRate=1/120)
    "Ramp limiter for fan control signal"
equation
  connect(PAtm.y, bouIn.p_in)
  connect(roo.p_rel, conSupFan.u_m)
  connect(yDam.y, mixBox.y)
  connect(roo.p, PAtm.y)
  connect(mixBox.port_Sup, res31.port_a)
  connect(res31.port_b, fan32.port_a)
  connect(res57.port_b, mixBox.port_Ret)
  connect(res33.port_b, roo.port_aSup)
  connect(bouIn.ports[1], mixBox.port_Out)
  connect(bouIn.ports[2], mixBox.port_Exh)
  connect(fan56.port_b, res57.port_a)
  connect(fan32.port_b, res33.port_a)
  connect(fan56.port_a, roo.port_bExh)
  connect(dp32.y, fan32.dp_in)
  connect(dp56.y, fan56.dp_in)
  connect(switch1.u1, conSupFan.y)
  connect(off.y, switch1.u3)
  connect(conSupFan.u_s, booToRea.y)
  connect(onSig.y, booToRea.u)
  connect(onSig.y, switch1.u2)
  connect(switch1.y, ramLim.u)
  connect(dp32.u, ramLim.y)
  connect(dp56.u, ramLim.y)
end VAVSystemCTControl;


Local loop controller for damper.

within Buildings.Examples.VAVCO2.BaseClasses;
block DamperControl "Local loop controller for damper"
  extends Modelica.Blocks.Interfaces.SISO;
  parameter Real CO2Set = 700E-6 "CO2 set point in volume fraction";
  parameter Real Kp = 10 "Gain";

  Buildings.Controls.Continuous.LimPID con(
    yMin=0,
    y_start=0.5,
    Ti=1,
    controllerType=Modelica.Blocks.Types.SimpleController.P,
    k=Kp,
    yMax=1,
    reverseActing=false,
    Td=60)

protected
  Modelica.Blocks.Sources.Constant xSetNor(k=1) "CO2 set point (normalized)"

  Modelica.Blocks.Math.Gain gain1(k=1/CO2Set)
    "Gain. Division by CO2Set is to normalize the control error"
equation

  connect(con.y, y)
  connect(xSetNor.y, con.u_s)
  connect(gain1.y, con.u_m)
  connect(u, gain1.u)
end DamperControl;


Model for occupancy.

within Buildings.Examples.VAVCO2.BaseClasses;
model Occupancy "Model for occupancy"
  extends Modelica.Blocks.Icons.Block;

  Modelica.Blocks.Sources.CombiTimeTable office1(
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    tableOnFile=false,
    table=[-6,0.0;
            8,2;
            9,3;
            12,2;
            13,6;
            15,3;
            16,4;
            18,0],
    timeScale=3600) "Office with double occupancy"

  Modelica.Blocks.Sources.CombiTimeTable office2(
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    tableOnFile=false,
    table=[-6,0.0;
            8,2;
            9,3;
            12,2;
            13,5;
            15,3;
            16,6;
            18,0],
    timeScale=3600) "Office with double occupancy"

  Modelica.Blocks.Sources.CombiTimeTable cla1(
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    tableOnFile=false,
    table=[-6,0.0;
            8,25;
            9,20;
            10,30;
            12,0;
            13,30;
            15,40;
            16,20;
            18,0],
    timeScale=3600) "Class room"

  Modelica.Blocks.Sources.CombiTimeTable cla2(
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    tableOnFile=false,
    table=[-6,0.0;
            8,20;
            9,10;
            10,20;
            11,15;
            12,0;
            13,30;
            15,20;
            16,25;
            18,0],
    timeScale=3600) "Class room"

  Modelica.Blocks.Sources.CombiTimeTable smaRoo1(
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    tableOnFile=false,
    table=[-6,0.0;
            8,0.4;
            9,1;
            12,1;
            13,0.5;
            14,1.0;
            16,0.5;
            18,0],
    timeScale=3600) "Small rooms"

  Modelica.Blocks.Sources.CombiTimeTable smaRoo2(
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    tableOnFile=false,
    table=[-6,0.0;
            8,0.4;
            9,1;
            10,0.4;
            12,1;
            13,0.3;
            14,0.4;
            16,0.2;
            18,0],
    timeScale=3600) "Small rooms"

  Modelica.Blocks.Interfaces.RealOutput y1[2]
    "Connector of Real output signals"
  Modelica.Blocks.Interfaces.RealOutput y2[2]
    "Connector of Real output signals"
  Modelica.Blocks.Interfaces.RealOutput y3[2]
    "Connector of Real output signals"
  Modelica.Blocks.Math.Gain sca1(k=2) "Scaling for occupancy"
  Modelica.Blocks.Math.Gain sca2(k=3) "Scaling for occupancy"
  Modelica.Blocks.Math.Gain sca3(k=3) "Scaling for occupancy"
  Modelica.Blocks.Math.Gain sca4(k=2) "Scaling for occupancy"
  Modelica.Blocks.Math.Gain sca5(k=3) "Scaling for occupancy"
  Modelica.Blocks.Math.Gain sca6(k=3) "Scaling for occupancy"
  Modelica.Blocks.Routing.Multiplex2 mul1(
    final n1=1,
    final n2=1)
    "Multiplex to route signals"
  Modelica.Blocks.Routing.Multiplex2 mul2(
    final n1=1,
    final n2=1)
    "Multiplex to route signals"
  Modelica.Blocks.Routing.Multiplex2 mul3(
    final n1=1,
    final n2=1)
    "Multiplex to route signals"
equation
  connect(y1, mul1.y)
  connect(mul1.u1[1], sca1.y)
  connect(mul1.u2[1], sca4.y)
  connect(mul2.y, y2)
  connect(mul3.y, y3)
  connect(sca2.y, mul2.u1[1])
  connect(sca5.y, mul2.u2[1])
  connect(sca3.y, mul3.u1[1])
  connect(sca6.y, mul3.u2[1])
  connect(cla1.y[1], sca1.u)
  connect(cla2.y[1], sca4.u)
  connect(office1.y[1], sca2.u)
  connect(office2.y[1], sca5.u)
  connect(smaRoo1.y[1], sca3.u)
  connect(smaRoo2.y[1], sca6.u)
end Occupancy;


within Buildings.Examples.VAVCO2;
package BaseClasses "Package with base classes for Buildings.Examples.VAVCO2"
  extends Modelica.Icons.BasesPackage;
end BaseClasses;


Room leakage model

within Buildings.Examples.VAVCO2.BaseClasses;
model RoomLeakage "Room leakage model"
  extends Buildings.BaseClasses.BaseIcon;
  replaceable package Medium =
      Modelica.Media.Interfaces.PartialMedium "Medium in the component"

  Buildings.Fluid.FixedResistances.PressureDrop res(
    m_flow_nominal=1,
    redeclare package Medium = Medium,
    dp_nominal=1000) "Resistance model"

  Modelica.Blocks.Interfaces.RealInput p "Pressure"
  Modelica.Fluid.Interfaces.FluidPort_b port_b(redeclare package Medium =
        Medium)

  Buildings.Fluid.Sources.Boundary_pT amb(             redeclare package Medium =Medium,
    nPorts=1,
    use_p_in=true,
    p=101325,
    T=293.15)
equation
  connect(res.port_b, port_b)
  connect(p, amb.p_in)
  connect(amb.ports[1], res.port_a)
end RoomLeakage;


Model for CO2 emitted by people

within Buildings.Examples.VAVCO2.BaseClasses;
model RoomVAV "Model for CO2 emitted by people"
  replaceable package Medium =
      Modelica.Media.Interfaces.PartialMedium "Medium in the component";

  parameter Modelica.Units.SI.Volume VRoo "Volume of room";
  parameter Modelica.Units.SI.Volume VPle "Volume of plenum";
  parameter Modelica.Units.SI.Area ADam "Damper face area";
  parameter Modelica.Units.SI.MassFlowRate m_flow_nominal
    "Nominal mass flow rate";
  parameter Real l(min=1e-10, max=1) = 0.0001
    "Damper leakage, ratio of flow coefficients k(y=0)/k(y=1)"
  Buildings.Fluid.Actuators.Dampers.Exponential vav(
    redeclare package Medium = Medium,
    m_flow_nominal=m_flow_nominal,
    from_dp=false,
    dpDamper_nominal=0.27,
    dpFixed_nominal=1E2 - 0.27,
    final l=l)
  Buildings.Fluid.MixingVolumes.MixingVolume vol(
    redeclare package Medium = Medium,
    V=VRoo,
    nPorts=5,
    m_flow_nominal=m_flow_nominal,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    use_C_flow=true) "Room volume"
  Buildings.Fluid.Sensors.TraceSubstances senCO2(
    redeclare package Medium = Medium, warnAboutOnePortConnection=false)
                                       "Sensor at volume"
  Buildings.Fluid.MixingVolumes.MixingVolume ple(
    redeclare package Medium = Medium,
    V=VPle,
    m_flow_nominal=m_flow_nominal,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    nPorts=2)
    "Plenum volume"
  Modelica.Fluid.Interfaces.FluidPort_a portRoo1(
    redeclare package Medium = Medium) "Fluid port"
  Modelica.Fluid.Interfaces.FluidPort_a portSup(
    redeclare package Medium = Medium) "Fluid port"
  Modelica.Fluid.Interfaces.FluidPort_a portRet(
    redeclare package Medium = Medium) "Fluid port"
  Modelica.Fluid.Interfaces.FluidPort_a portRoo2(
    redeclare package Medium = Medium) "Fluid port"
  Modelica.Blocks.Interfaces.RealOutput yDam "Damper control signal"
  Modelica.Blocks.Interfaces.RealInput nPeo "Number of people"
  Modelica.Blocks.Math.Gain gaiCO2(k=8.18E-6) "CO2 emission per person"
  Buildings.Fluid.Sensors.Conversions.To_VolumeFraction volFraCO2(
    MMMea=Modelica.Media.
    IdealGases.Common.SingleGasesData.CO2.MM) "CO2 volume fraction"
  DamperControl con(Kp=1) "Damper controller"
  Modelica.Blocks.Math.Gain peoDen(k=2.5/VRoo) "People density per m2"

  Modelica.Blocks.Sources.RealExpression vavACH(
    y=vav.m_flow*3600/VRoo/1.2)
    "VAV box air change per hour"
  Buildings.Fluid.FixedResistances.PressureDrop dpPle(
    redeclare package Medium = Medium,
    m_flow_nominal=m_flow_nominal,
    dp_nominal=20,
    from_dp=true)

equation
  connect(senCO2.C, volFraCO2.m)
  connect(volFraCO2.V, con.u)
  connect(con.y, yDam)
  connect(con.y, vav.y)
  connect(nPeo, gaiCO2.u)
  connect(nPeo, peoDen.u)
  connect(portSup, vav.port_a)
  connect(portRoo1, vol.ports[1])
  connect(vav.port_b, vol.ports[2])
  connect(senCO2.port, vol.ports[3])
  connect(portRoo2, vol.ports[4])
  connect(dpPle.port_a, vol.ports[5])
  connect(vol.C_flow[1], gaiCO2.y)
  connect(dpPle.port_b, ple.ports[1])
  connect(ple.ports[2], portRet)
end RoomVAV;


within Buildings.Examples.VAVCO2.BaseClasses;
model Suite "Model of a suite consisting of five rooms of the MIT system model"
  replaceable package Medium =
      Modelica.Media.Interfaces.PartialMedium "Medium in the component";
  Modelica.Blocks.Interfaces.RealInput p "Pressure"
  Modelica.Fluid.Interfaces.FluidPort_b port_aSup(
    redeclare package Medium = Medium)

  parameter Real scaM_flow "Scaling factor for mass flow rate";
  parameter Modelica.Units.SI.MassFlowRate m0Tot_flow=scaM_flow*(5.196 + 2.8428
       + 1.0044 + 0.9612 + 0.3624 + 0.1584);
  parameter Real l(min=1e-10, max=1) = 0.0001
    "Damper leakage, ratio of flow coefficients k(y=0)/k(y=1)"
  Buildings.Fluid.FixedResistances.Junction spl34(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{1,-1,-1},
    dp_nominal={0.176,-0.844,-0.0662},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Buildings.Fluid.FixedResistances.Junction mix55(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{-1,1,1},
    dp_nominal=1E3*{-0.263200E-02,0.999990E-03,0.649000E-03},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Buildings.Fluid.FixedResistances.PressureDrop res13(
    m_flow_nominal=scaM_flow*1,
    dp_nominal=0.1E3,
    redeclare package Medium = Medium)
  Buildings.Fluid.FixedResistances.PressureDrop res14(
    m_flow_nominal=scaM_flow*1,
    dp_nominal=0.1E3,
    redeclare package Medium = Medium)
  Buildings.Fluid.FixedResistances.PressureDrop res15(
    m_flow_nominal=scaM_flow*1,
    dp_nominal=0.1E3,
    redeclare package Medium = Medium)
  Buildings.Fluid.FixedResistances.PressureDrop res16(
    m_flow_nominal=scaM_flow*1,
    dp_nominal=0.1E3,
    redeclare package Medium = Medium)
  Buildings.Fluid.FixedResistances.PressureDrop res17(
    m_flow_nominal=scaM_flow*1,
    dp_nominal=0.1E3,
    redeclare package Medium = Medium)
  Buildings.Fluid.FixedResistances.Junction spl35(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{1,-1,-1},
    dp_nominal=1E3*{0.371000E-04,-0.259000E-02,-0.131000E-02},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Buildings.Fluid.FixedResistances.Junction spl36(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{1,-1,-1},
    dp_nominal=1E3*{0.211000E-03,-0.128000E-01,-0.223000E-02},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Buildings.Fluid.FixedResistances.Junction spl37(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{1,-1,-1},
    dp_nominal=1E3*{0.730000E-03,-0.128000E-01,-0.938000E-02},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Buildings.Fluid.FixedResistances.Junction spl38(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{1,-1,-1},
    dp_nominal=1E3*{0.731000E-02,-0.895000E-01,-0.942000E-01},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Buildings.Fluid.FixedResistances.Junction mix54(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{-1,1,1},
    dp_nominal=1E3*{-0.653000E-02,0.271000E-03,0.402000E-04},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Buildings.Fluid.FixedResistances.Junction mix53(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{-1,1,1},
    dp_nominal=1E3*{-0.566000E-01,0.541000E-02,0.749000E-04},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Buildings.Fluid.FixedResistances.Junction mix52(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{-1,1,1},
    dp_nominal=1E3*{-0.353960,0.494000E-03,0.922000E-03},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Buildings.Fluid.FixedResistances.Junction mix51(
    redeclare package Medium = Medium,
    m_flow_nominal=scaM_flow*{-1,1,1},
    dp_nominal=1E3*{-0.847600E-01,1.89750,0.150000E-02},
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState)
  Modelica.Fluid.Interfaces.FluidPort_b port_bExh(
    redeclare package Medium = Medium)
  Buildings.Fluid.FixedResistances.PressureDrop res1(
    m_flow_nominal=scaM_flow*1,
    dp_nominal=0.1E3,
    redeclare package Medium = Medium)
  RoomVAV roo45(
    redeclare package Medium = Medium,
    ADam=scaM_flow*0.49,
    m_flow_nominal=scaM_flow*5.196,
    VRoo=1820,
    VPle=396,
    final l=l) "Room model"
  RoomVAV roo46(
    redeclare package Medium = Medium,
    ADam=scaM_flow*0.245,
    m_flow_nominal=scaM_flow*2.8428,
    VRoo=1210,
    VPle=330,
    final l=l) "Room model"
  RoomVAV roo47(
    redeclare package Medium = Medium,
    ADam=scaM_flow*0.128,
    m_flow_nominal=scaM_flow*1.0044,
    VRoo=647,
    VPle=125,
    final l=l) "Room model"
  RoomVAV roo48(
    redeclare package Medium = Medium,
    ADam=scaM_flow*0.128,
    m_flow_nominal=scaM_flow*0.9612,
    VRoo=385,
    VPle=107,
    final l=l) "Room model"
  RoomVAV roo49(
    redeclare package Medium = Medium,
    ADam=scaM_flow*0.0494,
    m_flow_nominal=scaM_flow*0.3624,
    VRoo=48,
    VPle=13,
    final l=l) "Room model"
  RoomVAV roo50(
    redeclare package Medium = Medium,
    ADam=scaM_flow*0.024,
    m_flow_nominal=scaM_flow*0.1584,
    VRoo=155,
    VPle=43,
    final l=l) "Room model"
  Occupancy occ "Occupancy"
  Buildings.Fluid.Sensors.RelativePressure dpMea(
      redeclare package Medium = Medium) "Static pressure measurement"
  Modelica.Blocks.Interfaces.RealOutput p_rel "Relative pressure signal"
  Modelica.Blocks.Interfaces.RealOutput yDam[6] "VAV damper positions"
  Buildings.Fluid.Sensors.Pressure pRoo(redeclare package Medium = Medium)
    "Room pressure"
  Modelica.Blocks.Math.Feedback feeBac
  Modelica.Blocks.Interfaces.RealOutput dPRoo "Room pressurization"
equation
  connect(spl38.port_2, roo50.portSup)
  connect(port_aSup, spl34.port_1)
  connect(spl34.port_2, spl35.port_1)
  connect(spl35.port_2, spl36.port_1)
  connect(spl36.port_2, spl37.port_1)
  connect(spl37.port_2, spl38.port_1)
  connect(dpMea.port_a, spl38.port_1)
  connect(pRoo.p, feeBac.u2)
  connect(roo50.portRoo2, pRoo.port)
  connect(spl34.port_3, roo45.portSup)
  connect(spl35.port_3, roo46.portSup)
  connect(spl36.port_3, roo47.portSup)
  connect(spl37.port_3, roo48.portSup)
  connect(spl38.port_3, roo49.portSup)
  connect(dpMea.port_b, res16.port_b)
  connect(p, feeBac.u1)
  connect(dPRoo, feeBac.y)
  connect(dpMea.p_rel, p_rel)
  connect(roo45.yDam, yDam[1])
  connect(roo46.yDam, yDam[2])
  connect(roo47.yDam, yDam[3])
  connect(roo48.yDam, yDam[4])
  connect(roo49.yDam, yDam[5])
  connect(roo50.yDam, yDam[6])
  connect(occ.y1[1], roo45.nPeo)
  connect(occ.y1[2], roo46.nPeo)
  connect(occ.y2[1], roo47.nPeo)
  connect(occ.y2[2], roo48.nPeo)
  connect(occ.y3[1], roo49.nPeo)
  connect(occ.y3[2], roo50.nPeo)
  connect(port_bExh, mix55.port_1)
  connect(mix55.port_2, mix54.port_1)
  connect(mix54.port_2, mix53.port_1)
  connect(mix53.port_2, mix52.port_1)
  connect(mix52.port_2, mix51.port_1)
  connect(mix51.port_2, roo50.portRet)
  connect(roo48.portRet, mix51.port_3)
  connect(mix52.port_3, roo49.portRet)
  connect(roo47.portRet, mix53.port_3)
  connect(roo46.portRet, mix54.port_3)
  connect(roo45.portRet, mix55.port_3)
  connect(res1.port_b, roo45.portRoo1)
  connect(roo45.portRoo2, res13.port_a)
  connect(res13.port_b, roo46.portRoo1)
  connect(roo46.portRoo2, res14.port_a)
  connect(res14.port_b, roo47.portRoo1)
  connect(roo47.portRoo2, res15.port_a)
  connect(res15.port_b, roo48.portRoo1)
  connect(roo48.portRoo2, res16.port_a)
  connect(res16.port_b, roo49.portRoo1)
  connect(roo49.portRoo2, res17.port_a)
  connect(res17.port_b, roo50.portRoo1)
  connect(roo50.portRoo2, res1.port_a)
end Suite;


Variable air volume flow system with terminal reheat and five thermal zones. This model consist of an HVAC system, a building envelope model and a model
for air flow through building leakage and through open doors.

within Buildings.Examples.VAVReheat;
model ASHRAE2006
  "Variable air volume flow system with terminal reheat and five thermal zones"
  extends Modelica.Icons.Example;
  extends Buildings.Examples.VAVReheat.BaseClasses.HVACBuilding(
    mCor_flow_nominal=ACHCor*VRooCor*conv,
    mSou_flow_nominal=ACHSou*VRooSou*conv,
    mEas_flow_nominal=ACHEas*VRooEas*conv,
    mNor_flow_nominal=ACHNor*VRooNor*conv,
    mWes_flow_nominal=ACHWes*VRooWes*conv,
    redeclare Buildings.Examples.VAVReheat.BaseClasses.ASHRAE2006 hvac,
    redeclare replaceable Buildings.Examples.VAVReheat.BaseClasses.Floor flo(
      sampleModel=true));

  parameter Real ACHCor(final unit="1/h")=6
    "Design air change per hour core";
  parameter Real ACHSou(final unit="1/h")=6
    "Design air change per hour south";
  parameter Real ACHEas(final unit="1/h")=9
    "Design air change per hour east";
  parameter Real ACHNor(final unit="1/h")=6
    "Design air change per hour north";
  parameter Real ACHWes(final unit="1/h")=7
    "Design air change per hour west";
end ASHRAE2006;


within Buildings.Examples.VAVReheat;
model Guideline36
  "Variable air volume flow system with terminal reheat and five thermal zones"
  extends Modelica.Icons.Example;
  extends Buildings.Examples.VAVReheat.BaseClasses.HVACBuilding(
    mCor_flow_nominal=ACHCor*VRooCor*conv,
    mSou_flow_nominal=ACHSou*VRooSou*conv,
    mEas_flow_nominal=ACHEas*VRooEas*conv,
    mNor_flow_nominal=ACHNor*VRooNor*conv,
    mWes_flow_nominal=ACHWes*VRooWes*conv,
    redeclare Buildings.Examples.VAVReheat.BaseClasses.Guideline36 hvac,
    redeclare Buildings.Examples.VAVReheat.BaseClasses.Floor flo(sampleModel=
          true));

  parameter Real ACHCor(final unit="1/h")=6
    "Design air change per hour core";
  parameter Real ACHSou(final unit="1/h")=6
    "Design air change per hour south";
  parameter Real ACHEas(final unit="1/h")=9
    "Design air change per hour east";
  parameter Real ACHNor(final unit="1/h")=6
    "Design air change per hour north";
  parameter Real ACHWes(final unit="1/h")=7
    "Design air change per hour west";
end Guideline36;


within Buildings.Examples;
package VAVReheat "Variable air volume flow system with terminal reheat and five thermal zones"
  extends Modelica.Icons.ExamplesPackage;
end VAVReheat;


within Buildings.Examples.VAVReheat.BaseClasses;
model ASHRAE2006
  "Variable air volume flow system with terminal reheat and ASHRAE 2006 control sequence serving five thermal zones"
  extends Buildings.Examples.VAVReheat.BaseClasses.PartialHVAC(amb(nPorts=3));

  parameter Real ratVMinVAV_flow[numZon](each final unit="1") = {max(1.5*
    VZonOA_flow_nominal[i]/mCooVAV_flow_nominal[i]/1.2, 0.15) for i in 1:numZon}
    "Minimum discharge air flow rate ratio";

  Controls.FanVFD conFanSup(
    xSet_nominal(
      final unit="Pa",
      displayUnit="Pa") = 410,
    r_N_min=yFanMin)
    "Controller for fan"
  Controls.ModeSelector modeSelector
  Controls.ControlBus controlBus

  Controls.Economizer conEco(
    have_reset=true,
    have_frePro=true,
    VOut_flow_min=Vot_flow_nominal)
           "Controller for economizer"
  Controls.RoomTemperatureSetpoint TSetRoo(
    final THeaOn=THeaOn,
    final THeaOff=THeaOff,
    final TCooOn=TCooOn,
    final TCooOff=TCooOff)
  Controls.DuctStaticPressureSetpoint pSetDuc(
    nin=5,
    pMin=50) "Duct static pressure setpoint"
  Controls.RoomVAV conVAV[numZon](
    have_preIndDam=fill(false, numZon),
    ratVFloMin=ratVMinVAV_flow,
    ratVFloHea=mHeaVAV_flow_nominal ./ mCooVAV_flow_nominal,
    V_flow_nominal=mCooVAV_flow_nominal/1.2)
    "Controller for terminal unit"

  Buildings.Controls.OBC.CDL.Logical.Or or2
  Controls.SupplyAirTemperature conTSup
    "Supply air temperature and economizer controller"
  Controls.SupplyAirTemperatureSetpoint TSupSet
    "Supply air temperature set point"
  Buildings.Fluid.Actuators.Dampers.Exponential damExh(
    from_dp=false,
    strokeTime=15,
    dpFixed_nominal=5,
    redeclare package Medium = MediumA,
    m_flow_nominal=mAir_flow_nominal,
    dpDamper_nominal=5) "Exhaust air damper"
  Controls.SystemHysteresis sysHysHea
    "Hysteresis and delay to switch heating on and off"
  Controls.SystemHysteresis sysHysCoo
    "Hysteresis and delay to switch cooling on and off"
  Buildings.Controls.OBC.CDL.Reals.Switch swiFreStaPum
    "Switch for freeze stat of pump"
  Buildings.Controls.OBC.CDL.Reals.Switch swiFreStaVal
    "Switch for freeze stat of valve"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant yFreHeaCoi(final k=1.0)
    "Flow rate signal for heating coil when freeze stat is on"
  Buildings.Controls.OBC.CDL.Reals.MultiMin TRooMin(
    final nin=numZon,
    u(each final unit="K",
      each displayUnit="degC"),
    y(final unit="K",
      displayUnit="degC"))
    "Minimum room temperature"
  Utilities.Math.Average TRooAve(
    final nin=numZon,
    u(each final unit="K",
      each displayUnit="degC"),
    y(final unit="K",
      displayUnit="degC")) "Average room temperature"
  Controls.FreezeStat freSta "Freeze stat for heating coil"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator TRooHeaSet(final nout=
       numZon) "Replicate room temperature heating setpoint"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator TRooCooSet(final nout=
       numZon) "Replicate room temperature cooling setpoint"
equation
  connect(controlBus, modeSelector.cb)
  connect(TRooAve.y, controlBus.TRooAve)
  connect(TRet.T, conEco.TRet)
  connect(TSetRoo.controlBus, controlBus)
  connect(dpDisSupFan.p_rel, conFanSup.u_m)

  connect(pSetDuc.y, conFanSup.u)
  connect(conEco.VOut_flow, VOut1.V_flow)

  connect(occSch.tNexOcc, controlBus.dTNexOcc)
  connect(occSch.occupied, controlBus.occupied)
  connect(TOut.y, controlBus.TOut)
  connect(conEco.controlBus, controlBus)
  connect(modeSelector.yFan, conFanSup.uFan)
  connect(conFanSup.y, fanSup.y)
  connect(or2.u2, modeSelector.yFan)
  connect(VAVBox.y_actual, pSetDuc.u)
  connect(TSup.T, conTSup.TSup)
  connect(conTSup.yOA, conEco.uOATSup)
  connect(or2.y, conTSup.uEna)
  connect(modeSelector.yEco, conEco.uEna)
  connect(TMix.T, conEco.TMix)
  connect(controlBus, TSupSet.controlBus)
  connect(TSupSet.TSet, conTSup.TSupSet)
  connect(damRet.y, conEco.yRet)
  connect(damExh.y, conEco.yOA)
  connect(damOut.y, conEco.yOA)
  connect(damExh.port_a, TRet.port_b)
  connect(freSta.y, or2.u1)
  connect(conTSup.yHea, sysHysHea.u)
  connect(conTSup.yCoo, sysHysCoo.u)
  connect(sysHysCoo.y, valCooCoi.y)
  connect(sysHysCoo.yPum, pumCooCoi.y)
  connect(sysHysCoo.sysOn, modeSelector.yFan)
  connect(sysHysHea.sysOn, modeSelector.yFan)
  connect(yFreHeaCoi.y, swiFreStaPum.u1)
  connect(yFreHeaCoi.y, swiFreStaVal.u1)
  connect(freSta.y, swiFreStaPum.u2)
  connect(freSta.y, swiFreStaVal.u2)
  connect(sysHysHea.y, swiFreStaVal.u3)
  connect(sysHysHea.yPum, swiFreStaPum.u3)
  connect(swiFreStaPum.y, pumHeaCoi.y)
  connect(swiFreStaVal.y, valHeaCoi.y)
  connect(TRooMin.y, controlBus.TRooMin)
  connect(TRooMin.u, TRoo)
  connect(TRooAve.u, TRoo)
  connect(freSta.u, TMix.T)
  connect(damExh.port_b, amb.ports[3])
  connect(TRoo, conVAV.TRoo)
  connect(controlBus.TRooSetHea, TRooHeaSet.u)
  connect(controlBus.TRooSetCoo, TRooCooSet.u)
  connect(TRooHeaSet.y, conVAV.TRooHeaSet)
  connect(TRooCooSet.y, conVAV.TRooCooSet)
  connect(conVAV.yDam, VAVBox.yVAV)
  connect(conVAV.yVal, VAVBox.yHea)
  connect(VAVBox.VSup_flow, conVAV.VDis_flow)
end ASHRAE2006;


Model of a floor of the building

within Buildings.Examples.VAVReheat.BaseClasses;
model Floor "Model of a floor of the building"
  extends Buildings.Examples.VAVReheat.BaseClasses.PartialFloor(
    final VRooCor=cor.AFlo*hRoo,
    final VRooSou=sou.AFlo*hRoo,
    final VRooNor=nor.AFlo*hRoo,
    final VRooEas=eas.AFlo*hRoo,
    final VRooWes=wes.AFlo*hRoo,
    AFloCor=2698/hRoo,
    AFloSou=568.77/hRoo,
    AFloNor=568.77/hRoo,
    AFloEas=360.0785/hRoo,
    AFloWes=360.0785/hRoo);

  parameter Modelica.Units.SI.Length wExtSou=49.91
    "South zone exterior wall width";
  parameter Modelica.Units.SI.Length wExtNor=49.91
    "North zone exterior wall width";
  parameter Modelica.Units.SI.Length wExtEas=33.27
    "East zone exterior wall width";
  parameter Modelica.Units.SI.Length wExtWes=33.27
    "West zone exterior wall width";

  parameter HeatTransfer.Types.InteriorConvection intConMod=Buildings.HeatTransfer.Types.InteriorConvection.Temperature
    "Convective heat transfer model for room-facing surfaces of opaque constructions";
  parameter Real winWalRat(
    min=0.01,
    max=0.99) = 0.33 "Window to wall ratio for exterior walls";
  parameter Modelica.Units.SI.Length hWin=1.5 "Height of windows";
  parameter HeatTransfer.Data.Solids.Plywood matFur(x=0.15, nStaRef=5)
    "Material for furniture"
  parameter HeatTransfer.Data.Resistances.Carpet matCar "Carpet"
  parameter HeatTransfer.Data.Solids.Concrete matCon(
    x=0.1,
    k=1.311,
    c=836,
    nStaRef=5) "Concrete"
  parameter HeatTransfer.Data.Solids.Plywood matWoo(
    x=0.01,
    k=0.11,
    d=544,
    nStaRef=1) "Wood for exterior construction"
  parameter HeatTransfer.Data.Solids.Generic matIns(
    x=0.087,
    k=0.049,
    c=836.8,
    d=265,
    nStaRef=5) "Steelframe construction with insulation"
  parameter HeatTransfer.Data.Solids.GypsumBoard matGyp(
    x=0.0127,
    k=0.16,
    c=830,
    d=784,
    nStaRef=2) "Gypsum board"
  parameter HeatTransfer.Data.Solids.GypsumBoard matGyp2(
    x=0.025,
    k=0.16,
    c=830,
    d=784,
    nStaRef=2) "Gypsum board"
  parameter HeatTransfer.Data.OpaqueConstructions.Generic conExtWal(final nLay=3,
      material={matWoo,matIns,matGyp}) "Exterior construction"
  parameter HeatTransfer.Data.OpaqueConstructions.Generic conIntWal(final nLay=1,
      material={matGyp2}) "Interior wall construction"
  parameter HeatTransfer.Data.OpaqueConstructions.Generic conFlo(final nLay=1, material={
        matCon}) "Floor construction (opa_a is carpet)"
  parameter HeatTransfer.Data.OpaqueConstructions.Generic conFur(final nLay=1, material={
        matFur}) "Construction for internal mass of furniture"
  parameter HeatTransfer.Data.Solids.Plywood matCarTra(
    k=0.11,
    d=544,
    nStaRef=1,
    x=0.215/0.11) "Wood for floor"
  parameter HeatTransfer.Data.GlazingSystems.DoubleClearAir13Clear glaSys(
    UFra=2,
    shade=Buildings.HeatTransfer.Data.Shades.Gray(),
    haveInteriorShade=false,
    haveExteriorShade=false) "Data record for the glazing system"

  constant Modelica.Units.SI.Height hRoo=2.74 "Room height";

  parameter Boolean sampleModel = false
    "Set to true to time-sample the model, which can give shorter simulation time if there is already time sampling in the system model"

  Buildings.ThermalZones.Detailed.MixedAir sou(
    redeclare package Medium = Medium,
    AFlo=AFloSou,
    hRoo=hRoo,
    nConExt=0,
    nConExtWin=1,
    datConExtWin(
      layers={conExtWal},
      A={wExtSou*hRoo},
      glaSys={glaSys},
      wWin={winWalRat/hWin*wExtSou*hRoo},
      each hWin=hWin,
      fFra={0.1},
      til={Buildings.Types.Tilt.Wall},
      azi={Buildings.Types.Azimuth.S}),
    nConPar=2,
    datConPar(
      layers={conFlo,conFur},
      A={AFloSou,414.68},
      til={Buildings.Types.Tilt.Floor,Buildings.Types.Tilt.Wall}),
    nConBou=3,
    datConBou(
      layers={conIntWal,conIntWal,conIntWal},
      A={6.47,40.76,6.47}*hRoo,
      til={Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall}),
    nSurBou=0,
    nPorts=5,
    intConMod=intConMod,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final sampleModel=sampleModel) "South zone"
  Buildings.ThermalZones.Detailed.MixedAir eas(
    redeclare package Medium = Medium,
    AFlo=AFloEas,
    hRoo=hRoo,
    nConExt=0,
    nConExtWin=1,
    datConExtWin(
      layers={conExtWal},
      A={wExtEas*hRoo},
      glaSys={glaSys},
      wWin={winWalRat/hWin*wExtEas*hRoo},
      each hWin=hWin,
      fFra={0.1},
      til={Buildings.Types.Tilt.Wall},
      azi={Buildings.Types.Azimuth.E}),
    nConPar=2,
    datConPar(
      layers={conFlo,conFur},
      A={AFloEas,262.52},
      til={Buildings.Types.Tilt.Floor,Buildings.Types.Tilt.Wall}),
    nConBou=1,
    datConBou(
      layers={conIntWal},
      A={24.13}*hRoo,
      til={Buildings.Types.Tilt.Wall}),
    nSurBou=2,
    surBou(
      each A=6.47*hRoo,
      each absIR=0.9,
      each absSol=0.9,
      til={Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall}),
    nPorts=5,
    intConMod=intConMod,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final sampleModel=sampleModel) "East zone"
  Buildings.ThermalZones.Detailed.MixedAir nor(
    redeclare package Medium = Medium,
    AFlo=AFloNor,
    hRoo=hRoo,
    nConExt=0,
    nConExtWin=1,
    datConExtWin(
      layers={conExtWal},
      A={wExtNor*hRoo},
      glaSys={glaSys},
      wWin={winWalRat/hWin*wExtNor*hRoo},
      each hWin=hWin,
      fFra={0.1},
      til={Buildings.Types.Tilt.Wall},
      azi={Buildings.Types.Azimuth.N}),
    nConPar=2,
    datConPar(
      layers={conFlo,conFur},
      A={AFloNor,414.68},
      til={Buildings.Types.Tilt.Floor,Buildings.Types.Tilt.Wall}),
    nConBou=3,
    datConBou(
      layers={conIntWal,conIntWal,conIntWal},
      A={6.47,40.76,6.47}*hRoo,
      til={Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall}),
    nSurBou=0,
    nPorts=5,
    intConMod=intConMod,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final sampleModel=sampleModel) "North zone"
  Buildings.ThermalZones.Detailed.MixedAir wes(
    redeclare package Medium = Medium,
    AFlo=AFloWes,
    hRoo=hRoo,
    nConExt=0,
    nConExtWin=1,
    datConExtWin(
      layers={conExtWal},
      A={wExtEas*hRoo},
      glaSys={glaSys},
      wWin={winWalRat/hWin*wExtEas*hRoo},
      each hWin=hWin,
      fFra={0.1},
      til={Buildings.Types.Tilt.Wall},
      azi={Buildings.Types.Azimuth.W}),
    nConPar=2,
    datConPar(
      layers={conFlo,conFur},
      A={AFloWes,262.52},
      til={Buildings.Types.Tilt.Floor,Buildings.Types.Tilt.Wall}),
    nConBou=1,
    datConBou(
      layers={conIntWal},
      A={24.13}*hRoo,
      til={Buildings.Types.Tilt.Wall}),
    nSurBou=2,
    surBou(
      each A=6.47*hRoo,
      each absIR=0.9,
      each absSol=0.9,
      til={Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall}),
    nPorts=5,
    intConMod=intConMod,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final sampleModel=sampleModel) "West zone"
  Buildings.ThermalZones.Detailed.MixedAir cor(
    redeclare package Medium = Medium,
    AFlo=AFloCor,
    hRoo=hRoo,
    nConExt=0,
    nConExtWin=0,
    nConPar=2,
    datConPar(
      layers={conFlo,conFur},
      A={AFloCor,1967.01},
      til={Buildings.Types.Tilt.Floor,Buildings.Types.Tilt.Wall}),
    nConBou=0,
    nSurBou=4,
    surBou(
      A={40.76,24.13,40.76,24.13}*hRoo,
      each absIR=0.9,
      each absSol=0.9,
      til={Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall}),
    nPorts=11,
    intConMod=intConMod,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final sampleModel=sampleModel) "Core zone"

  Modelica.Blocks.Math.MatrixGain gai(K=20*[0.4; 0.4; 0.2])
    "Matrix gain to split up heat gain in radiant, convective and latent gain"
  Modelica.Blocks.Sources.CombiTimeTable intGaiFra(
    table=[0,0.05; 8,0.05; 9,0.9; 12,0.9; 12,0.8; 13,0.8; 13,1; 17,1; 19,0.1;
        24,0.05],
    timeScale=3600,
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic)
    "Fraction of internal heat gain"
  Modelica.Blocks.Math.Gain gaiIntNor[3](each k=kIntNor)
    "Gain for internal heat gain amplification for north zone"
  Modelica.Blocks.Math.Gain gaiIntSou[3](each k=2 - kIntNor)
    "Gain to change the internal heat gain for south"
  Modelica.Blocks.Sources.Constant uSha(k=0)
    "Control signal for the shading device"
  Modelica.Blocks.Routing.Replicator replicator(nout=1)
equation
  connect(sou.surf_conBou[1], wes.surf_surBou[2])
  connect(sou.surf_conBou[2], cor.surf_surBou[1])
  connect(sou.surf_conBou[3], eas.surf_surBou[1])
  connect(eas.surf_conBou[1], cor.surf_surBou[2])
  connect(eas.surf_surBou[2], nor.surf_conBou[1])
  connect(nor.surf_conBou[2], cor.surf_surBou[3])
  connect(nor.surf_conBou[3], wes.surf_surBou[1])
  connect(wes.surf_conBou[1], cor.surf_surBou[4])
  connect(replicator.y, nor.uSha)
  connect(replicator.y, wes.uSha)
  connect(replicator.y, eas.uSha)
  connect(replicator.y, sou.uSha)
  connect(replicator.y, cor.uSha)
  connect(gai.y, cor.qGai_flow)
  connect(gai.y, eas.qGai_flow)
  connect(gai.y, wes.qGai_flow)
  connect(sou.weaBus, weaBus)
  connect(eas.weaBus, weaBus)
  connect(nor.weaBus, weaBus)
  connect(wes.weaBus, weaBus)
  connect(cor.weaBus, weaBus)
  connect(sou.heaPorAir, temAirSou.port)
  connect(eas.heaPorAir, temAirEas.port)
  connect(nor.heaPorAir, temAirNor.port)
  connect(wes.heaPorAir, temAirWes.port)
  connect(cor.heaPorAir, temAirCor.port)
  connect(sou.ports[1], portsSou[1])
  connect(sou.ports[2], portsSou[2])
  connect(eas.ports[1], portsEas[1])
  connect(eas.ports[2], portsEas[2])
  connect(nor.ports[1], portsNor[1])
  connect(nor.ports[2], portsNor[2])
  connect(wes.ports[1], portsWes[1])
  connect(wes.ports[2], portsWes[2])
  connect(cor.ports[1], portsCor[1])
  connect(cor.ports[2], portsCor[2])
  connect(leaSou.port_b, sou.ports[3])
  connect(leaEas.port_b, eas.ports[3])
  connect(leaNor.port_b, nor.ports[3])
  connect(leaWes.port_b, wes.ports[3])
  connect(opeSouCor.port_b1, cor.ports[3])
  connect(opeSouCor.port_a2, cor.ports[4])
  connect(opeSouCor.port_a1, sou.ports[4])
  connect(opeSouCor.port_b2, sou.ports[5])
  connect(opeEasCor.port_b1, eas.ports[4])
  connect(opeEasCor.port_a2, eas.ports[5])
  connect(opeEasCor.port_a1, cor.ports[5])
  connect(opeEasCor.port_b2, cor.ports[6])
  connect(opeNorCor.port_b1, nor.ports[4])
  connect(opeNorCor.port_a2, nor.ports[5])
  connect(opeNorCor.port_a1, cor.ports[7])
  connect(opeNorCor.port_b2, cor.ports[8])
  connect(opeWesCor.port_b1, cor.ports[9])
  connect(opeWesCor.port_a2, cor.ports[10])
  connect(opeWesCor.port_a1, wes.ports[4])
  connect(opeWesCor.port_b2, wes.ports[5])
  connect(cor.ports[11], senRelPre.port_a)
  connect(senRelPre.p_rel, p_rel)
  connect(gaiIntNor.y, nor.qGai_flow)
  connect(gaiIntSou.y, sou.qGai_flow)
  connect(gai.y,gaiIntSou. u)
  connect(gai.y,gaiIntNor. u)
  connect(intGaiFra.y,gai. u)
  connect(uSha.y,replicator. u)
end Floor;


Variable air volume flow system with terminal reheat and Guideline 36 control sequence serving five thermal zones. This model consist of an HVAC system is a variable air volume (VAV) flow system with economizer
and a heating and cooling coil in the air handler unit. There is also a
reheat coil and an air damper in each of the five zone inlet branches.

within Buildings.Examples.VAVReheat.BaseClasses;
model Guideline36
  "Variable air volume flow system with terminal reheat and Guideline 36 control sequence serving five thermal zones"
  extends Buildings.Examples.VAVReheat.BaseClasses.PartialHVAC(
    damOut(
      dpDamper_nominal=10,
      dpFixed_nominal=10),
    amb(nPorts=3));

//   parameter Modelica.Units.SI.VolumeFlowRate minZonPriFlo[numZon]=conVAV.VDisSetMin_flow
//     "Minimum expected zone primary flow rate";
  parameter Modelica.Units.SI.Time samplePeriod=120
    "Sample period of component, set to the same value as the trim and respond that process yPreSetReq";
  parameter Modelica.Units.SI.PressureDifference dpDisRetMax(displayUnit="Pa")=
       40 "Maximum return fan discharge static pressure setpoint";

  Buildings.Controls.OBC.CDL.Reals.Switch swiFreStaPum
    "Switch for freeze stat of pump"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant yFreHeaCoi(final k=1.0)
    "Flow rate signal for heating coil when freeze stat is on"

  Buildings.Controls.OBC.CDL.Reals.Sources.Constant warCooTim[numZon](
    final k=fill(1800, numZon)) "Warm up and cool down time"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant falSta[numZon](
    final k=fill(false, numZon)) "No zone has override switch"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator reaRep(nout=numZon)
    "Assume all zones have same occupancy schedule"
  Buildings.Controls.OBC.CDL.Routing.BooleanScalarReplicator booRep(nout=numZon)
    "Assume all zones have same occupancy schedule"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant demLimLev[numZon](
    final  k=fill(0, numZon)) "Demand limit level, assumes to be 0"

  Buildings.Examples.VAVReheat.BaseClasses.Controls.SystemHysteresis sysHysHea
    "Hysteresis and delay to switch heating on and off"
  Buildings.Examples.VAVReheat.BaseClasses.Controls.SystemHysteresis sysHysCoo
    "Hysteresis and delay to switch cooling on and off"
  Buildings.Controls.OBC.CDL.Reals.Switch swiFreStaVal
    "Switch for freeze stat of valve"
  Buildings.Examples.VAVReheat.BaseClasses.Controls.FreezeStat freSta(lockoutTime=3600)
    "Freeze stat for heating coil"
  Buildings.Controls.OBC.Utilities.OptimalStart optSta[numZon](
    each computeHeating=true,
    each computeCooling=true) "Optimal startup"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator tZonNexOcc(nout=
        numZon) "Next occupancy for each zone"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOccHeaSet[numZon](
    each k(
      unit="K",
      displayUnit="degC") = 293.15) "Occupied heating setpoint for zone air"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TOccCooSet[numZon](
    each k(
      unit="K",
      displayUnit="degC") = 297.15) "Occupied cooling setpoint for zone air"
  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Controller conAHU(
    final eneStd=Buildings.Controls.OBC.ASHRAE.G36.Types.EnergyStandard.ASHRAE90_1,

    final venStd=Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1,

    final ashCliZon=Buildings.Controls.OBC.ASHRAE.G36.Types.ASHRAEClimateZone.Zone_5A,

    final freSta=Buildings.Controls.OBC.ASHRAE.G36.Types.FreezeStat.No_freeze_stat,

    final minOADes=Buildings.Controls.OBC.ASHRAE.G36.Types.OutdoorAirSection.SingleDamper,

    final buiPreCon=Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.BarometricRelief,

    final ecoHigLimCon=Buildings.Controls.OBC.ASHRAE.G36.Types.ControlEconomizer.FixedDryBulb,

    final have_perZonRehBox=true,
    final VUncDesOutAir_flow=0.644,
    final VDesTotOutAir_flow=1.107) "Air handler unit controller"

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.SetPoints.OutdoorAirFlow.ASHRAE62_1.SumZone
    sumZon(
    final nZon=numZon,
    final nGro=1,
    final zonGroMat=[1,1,1,1,1],
    final zonGroMatTra=[1; 1; 1; 1; 1])
    "Sum up zone ventilation setpoints"
  Buildings.Controls.OBC.ASHRAE.G36.ZoneGroups.OperationMode opeModSel(
    final nZon=numZon) "Operation mode"
  Buildings.Controls.OBC.ASHRAE.G36.ZoneGroups.ZoneStatus zonSta[numZon]
    "Status of different zone temperature"
  Buildings.Controls.OBC.ASHRAE.G36.ZoneGroups.GroupStatus groSta(final nBuiZon=
       numZon)
    "Zone group status"
  Buildings.Controls.OBC.ASHRAE.G36.ThermalZones.Setpoints TZonSet[numZon](
    final have_occSen=fill(false, numZon),
    final have_winSen=fill(false, numZon),
    final have_locAdj=fill(false, numZon)) "Zone setpoint temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TUnoHeaSet[numZon](
      each k(
      unit="K",
      displayUnit="degC") = 285.15) "Unoccupied heating setpoint for zone air"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TUnoCooSet[numZon](
      each k(
      unit="K",
      displayUnit="degC") = 303.15) "Unoccupied cooling setpoint for zone air"
  Buildings.Controls.OBC.CDL.Routing.IntegerScalarReplicator intRep(
    final nout=numZon)
    "All zones in same operation mode"
  Buildings.Controls.OBC.ASHRAE.G36.TerminalUnits.Reheat.Controller conVAV[numZon](
    final venStd=fill(Buildings.Controls.OBC.ASHRAE.G36.Types.VentilationStandard.ASHRAE62_1, numZon),
    final have_winSen=fill(false, numZon),
    final have_occSen=fill(false, numZon),
    final have_CO2Sen=fill(false, numZon),
    final VAreBreZon_flow={ratOAFlo_A*AFlo[i] for i in 1:numZon},
    final VPopBreZon_flow={ratP_A*AFlo[i]*ratOAFlo_P for i in 1:numZon},
    final VMin_flow={max(1.5*VZonOA_flow_nominal[i], 0.15*mCooVAV_flow_nominal[
        i]/1.2) for i in 1:numZon},
    final VCooMax_flow=mCooVAV_flow_nominal/1.2,
    final VHeaMin_flow=fill(0, numZon),
    final VHeaMax_flow=mHeaVAV_flow_nominal/1.2,
    final VAreMin_flow=fill(0, numZon),
    final VOccMin_flow=fill(0, numZon),
    floHys=fill(0.01, numZon))          "Reheat box control"

  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator TSupAHU(
    final nout=numZon)
    "Replicate AHU supply temperature"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator TSupAHUSet(
    final nout=numZon)
    "Replicate AHU supply temperature setpoint"
  Buildings.Controls.OBC.CDL.Integers.Sources.Constant oveRid[numZon](
    final k=fill(0, numZon))
    "No override flow setpoint, no override damper position"
  Buildings.Controls.OBC.CDL.Routing.BooleanScalarReplicator booScaRep(
    final nout=numZon) "Supply fan commanded on"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant hotWatPla[numZon](
    final k=fill(true, numZon)) "Hot water plant status"
  Buildings.Controls.OBC.CDL.Integers.MultiSum preRetReq(
    final nin=numZon)
    "Zone pressure reset request"
  Buildings.Controls.OBC.CDL.Integers.MultiSum temResReq(
    final nin=numZon)
    "Zone temperature reset request"
  Buildings.Controls.OBC.CDL.Logical.FallingEdge falEdg
    "Reset back to normal after freeze protection"
  Buildings.Controls.OBC.ASHRAE.G36.ZoneGroups.ZoneGroupSystem ahuMod(
    final nGro=1)
    "AHU operating mode"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant truSta[numZon](
    final k=fill(true, numZon))
    "All windows are closed"

equation
  connect(yFreHeaCoi.y, swiFreStaPum.u1)
  connect(occSch.tNexOcc, reaRep.u)
  connect(occSch.occupied, booRep.u)
  connect(freSta.y, swiFreStaPum.u2)
  connect(sysHysCoo.y, valCooCoi.y)
  connect(sysHysCoo.yPum, pumCooCoi.y)
  connect(swiFreStaPum.y, pumHeaCoi.y)
  connect(swiFreStaVal.u1, yFreHeaCoi.y)
  connect(sysHysHea.y, swiFreStaVal.u3)
  connect(sysHysHea.yPum, swiFreStaPum.u3)
  connect(freSta.y, swiFreStaVal.u2)
  connect(swiFreStaVal.y, valHeaCoi.y)
  connect(TMix.T, freSta.u)
  connect(TRet.port_b, amb.ports[3])
  connect(optSta.TZon, TRoo)
  connect(occSch.tNexOcc, tZonNexOcc.u)
  connect(tZonNexOcc.y, optSta.tNexOcc)
  connect(optSta.TSetZonCoo,TOccCooSet. y)
  connect(optSta.TSetZonHea,TOccHeaSet. y)
  connect(zonSta.yCooTim, groSta.uCooTim)
  connect(zonSta.yWarTim, groSta.uWarTim)
  connect(zonSta.yOccHeaHig, groSta.u1OccHeaHig)
  connect(zonSta.yHigOccCoo, groSta.u1HigOccCoo)
  connect(zonSta.yUnoHeaHig, groSta.u1UnoHeaHig)
  connect(zonSta.yEndSetBac, groSta.u1EndSetBac)
  connect(zonSta.yHigUnoCoo, groSta.u1HigUnoCoo)
  connect(zonSta.yEndSetUp, groSta.u1EndSetUp)
  connect(falSta.y, groSta.zonOcc)
  connect(optSta.tOpt, zonSta.cooDowTim)
  connect(optSta.tOpt, zonSta.warUpTim)
  connect(TOccHeaSet.y, zonSta.TOccHeaSet)
  connect(TOccCooSet.y, zonSta.TOccCooSet)
  connect(TUnoHeaSet.y, zonSta.TUnoHeaSet)
  connect(TUnoCooSet.y, zonSta.TUnoCooSet)
  connect(TRoo, zonSta.TZon)
  connect(TRoo, groSta.TZon)
  connect(booRep.y, groSta.u1Occ)
  connect(reaRep.y, groSta.tNexOcc)
  connect(groSta.uGroOcc, opeModSel.u1Occ)
  connect(groSta.nexOcc, opeModSel.tNexOcc)
  connect(groSta.yCooTim, opeModSel.maxCooDowTim)
  connect(groSta.yOccHeaHig, opeModSel.u1OccHeaHig)
  connect(groSta.yHigOccCoo, opeModSel.u1HigOccCoo)
  connect(groSta.yWarTim, opeModSel.maxWarUpTim)
  connect(groSta.yColZon, opeModSel.totColZon)
  connect(groSta.yOpeWin, opeModSel.uOpeWin)
  connect(groSta.ySetBac, opeModSel.u1SetBac)
  connect(groSta.yEndSetBac, opeModSel.u1EndSetBac)
  connect(groSta.TZonMin, opeModSel.TZonMin)
  connect(groSta.yHotZon, opeModSel.totHotZon)
  connect(groSta.ySetUp, opeModSel.u1SetUp)
  connect(groSta.yEndSetUp, opeModSel.u1EndSetUp)
  connect(opeModSel.yOpeMod, intRep.u)
  connect(intRep.y, TZonSet.uOpeMod)
  connect(TOccCooSet.y, TZonSet.TOccCooSet)
  connect(TUnoCooSet.y, TZonSet.TUnoCooSet)
  connect(TOccHeaSet.y, TZonSet.TOccHeaSet)
  connect(TUnoHeaSet.y, TZonSet.TUnoHeaSet)
  connect(demLimLev.y, TZonSet.uCooDemLimLev)
  connect(demLimLev.y, TZonSet.uHeaDemLimLev)
  connect(TRoo, conVAV.TZon)
  connect(TZonSet.TCooSet, conVAV.TCooSet)
  connect(TZonSet.THeaSet, conVAV.THeaSet)
  connect(intRep.y, conVAV.uOpeMod)
  connect(VAVBox.TSup, conVAV.TDis)
  connect(VAVBox.VSup_flow, conVAV.VDis_flow)
  connect(TSup.T, TSupAHU.u)
  connect(TSupAHU.y, conVAV.TSup)
  connect(conAHU.TAirSupSet, TSupAHUSet.u)
  connect(TSupAHUSet.y, conVAV.TSupSet)
  connect(oveRid.y, conVAV.oveFloSet)
  connect(oveRid.y, conVAV.oveDamPos)
  connect(falSta.y, conVAV.uHeaOff)
  connect(conAHU.y1SupFan, booScaRep.u)
  connect(booScaRep.y, conVAV.u1Fan)
  connect(conVAV.VAdjPopBreZon_flow, sumZon.VAdjPopBreZon_flow)
  connect(conVAV.VAdjAreBreZon_flow, sumZon.VAdjAreBreZon_flow)
  connect(conVAV.VMinOA_flow, sumZon.VMinOA_flow)
  connect(VAVBox.VSup_flow, sumZon.VZonPri_flow)
  connect(conVAV.yVal, VAVBox.yHea)
  connect(conVAV.yDam, VAVBox.yVAV)
  connect(sumZon.VSumAdjPopBreZon_flow, conAHU.VSumAdjPopBreZon_flow)
  connect(sumZon.VSumAdjAreBreZon_flow, conAHU.VSumAdjAreBreZon_flow)
  connect(sumZon.VSumZonPri_flow, conAHU.VSumZonPri_flow)
  connect(sumZon.uOutAirFra_max, conAHU.uOutAirFra_max)
  connect(dpDisSupFan.p_rel, conAHU.dpDuc)
  connect(TOut.y, conAHU.TOut)
  connect(TMix.T, conAHU.TAirMix)
  connect(VOut1.V_flow, conAHU.VAirOut_flow)
  connect(TSup.T, conAHU.TAirSup)
  connect(conAHU.yHeaCoi, sysHysHea.u)
  connect(conAHU.yCooCoi, sysHysCoo.u)
  connect(conAHU.y1SupFan, sysHysHea.sysOn)
  connect(conAHU.y1SupFan, sysHysCoo.sysOn)
  connect(conAHU.yRetDam, damRet.y)
  connect(conAHU.yOutDam, damOut.y)
  connect(conAHU.ySupFan, fanSup.y)
  connect(hotWatPla.y, conVAV.u1HotPla)
  connect(conAHU.y1SupFan, conAHU.u1SupFan)
  connect(conVAV.yZonTemResReq, temResReq.u)
  connect(conVAV.yZonPreResReq, preRetReq.u)
  connect(preRetReq.y, conAHU.uZonPreResReq)
  connect(temResReq.y, conAHU.uZonTemResReq)
  connect(freSta.y, falEdg.u)
  connect(falEdg.y, conAHU.u1SofSwiRes)
  connect(opeModSel.yOpeMod, sumZon.uOpeMod[1])
  connect(opeModSel.yOpeMod, ahuMod.uOpeMod[1])
  connect(ahuMod.yAhuOpeMod, conAHU.uAhuOpeMod)
  connect(TUnoCooSet.y, groSta.TCooSetOff)
  connect(TUnoHeaSet.y, groSta.THeaSetOff)
  connect(truSta.y, groSta.u1Win)
end Guideline36;


within Buildings.Examples.VAVReheat.BaseClasses;
partial model HVACBuilding
  "Partial model that contains the HVAC and building model"

  replaceable package MediumA = Buildings.Media.Air "Medium model for air";
  replaceable package MediumW = Buildings.Media.Water "Medium model for water";

  final parameter Modelica.Units.SI.Volume VRooCor=flo.VRooCor
    "Room volume corridor";
  final parameter Modelica.Units.SI.Volume VRooSou=flo.VRooSou
    "Room volume south";
  final parameter Modelica.Units.SI.Volume VRooNor=flo.VRooNor
    "Room volume north";
  final parameter Modelica.Units.SI.Volume VRooEas=flo.VRooEas
    "Room volume east";
  final parameter Modelica.Units.SI.Volume VRooWes=flo.VRooWes
    "Room volume west";

  final parameter Modelica.Units.SI.Area AFloCor=flo.AFloCor
    "Floor area corridor";
  final parameter Modelica.Units.SI.Area AFloSou=flo.AFloSou "Floor area south";
  final parameter Modelica.Units.SI.Area AFloNor=flo.AFloNor "Floor area north";
  final parameter Modelica.Units.SI.Area AFloEas=flo.AFloEas "Floor area east";
  final parameter Modelica.Units.SI.Area AFloWes=flo.AFloWes "Floor area west";

  constant Real conv=1.2/3600 "Conversion factor for nominal mass flow rate";

  parameter Modelica.Units.SI.MassFlowRate mCor_flow_nominal
    "Design mass flow rate core";
  parameter Modelica.Units.SI.MassFlowRate mSou_flow_nominal
    "Design mass flow rate south";
  parameter Modelica.Units.SI.MassFlowRate mEas_flow_nominal
    "Design mass flow rate east";
  parameter Modelica.Units.SI.MassFlowRate mNor_flow_nominal
    "Design mass flow rate north";
  parameter Modelica.Units.SI.MassFlowRate mWes_flow_nominal
    "Design mass flow rate west";

  final parameter Modelica.Units.SI.MassFlowRate mCooVAV_flow_nominal[5]={
      mSou_flow_nominal,mEas_flow_nominal,mNor_flow_nominal,mWes_flow_nominal,
      mCor_flow_nominal} "Design mass flow rate of each zone";

  parameter Modelica.Units.SI.Temperature THeaWatInl_nominal(displayUnit="degC")=
       45 + 273.15 "Reheat coil nominal inlet water temperature";

  replaceable Buildings.Examples.VAVReheat.BaseClasses.PartialHVAC hvac
    constrainedby Buildings.Examples.VAVReheat.BaseClasses.PartialHVAC(
    redeclare final package MediumA = MediumA,
    redeclare final package MediumW = MediumW,
    final VRoo={VRooSou,VRooEas,VRooNor,VRooWes,VRooCor},
    final AFlo={AFloSou,AFloEas,AFloNor,AFloWes,AFloCor},
    final mCooVAV_flow_nominal=mCooVAV_flow_nominal,
    final THeaWatInl_nominal=THeaWatInl_nominal) "HVAC system"
  replaceable
  Buildings.Examples.VAVReheat.BaseClasses.PartialFloor flo
    constrainedby Buildings.Examples.VAVReheat.BaseClasses.PartialFloor(
      redeclare final package Medium = MediumA)
    "Building"

  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
   filNam=Modelica.Utilities.Files.loadResource(
        "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"),
      computeWetBulbTemperature=false) "Weather data reader"
  Fluid.Sources.Boundary_pT sinHea(
    redeclare package Medium = MediumW,
    p=300000,
    T=THeaWatInl_nominal,
    nPorts=1) "Sink for heating coil"
  Fluid.Sources.Boundary_pT souHea(
    redeclare package Medium = MediumW,
    p(displayUnit="Pa") = 300000 + 6000,
    T=THeaWatInl_nominal,
    nPorts=1) "Source for heating coil"
  Fluid.Sources.Boundary_pT sinCoo(
    redeclare package Medium = MediumW,
    p=300000,
    T=279.15,
    nPorts=1) "Sink for cooling coil"
  Fluid.Sources.Boundary_pT souCoo(
    redeclare package Medium = MediumW,
    p(displayUnit="Pa") = 300000 + 6000,
    T=279.15,
    nPorts=1) "Source for cooling coil loop"
  Fluid.Sources.Boundary_pT souHeaTer(
    redeclare package Medium = MediumW,
    p(displayUnit="Pa") = 300000 + 6000,
    T=THeaWatInl_nominal,
    nPorts=1) "Source for heating of terminal boxes"
  Fluid.Sources.Boundary_pT sinHeaTer(
    redeclare package Medium = MediumW,
    p(displayUnit="Pa") = 300000,
    T=THeaWatInl_nominal,
    nPorts=1) "Source for heating of terminal boxes"
equation
  connect(souHea.ports[1], hvac.portHeaCoiSup)
  connect(sinHea.ports[1], hvac.portHeaCoiRet)
  connect(hvac.portHeaTerSup, souHeaTer.ports[1])
  connect(hvac.portHeaTerRet, sinHeaTer.ports[1])
  connect(weaDat.weaBus, hvac.weaBus)
  connect(flo.TRooAir, hvac.TRoo)
  connect(hvac.port_supAir[1], flo.portsSou[1])
  connect(hvac.port_supAir[2], flo.portsEas[1])
  connect(hvac.port_supAir[3], flo.portsNor[1])
  connect(hvac.port_supAir[4], flo.portsWes[1])
  connect(hvac.port_supAir[5], flo.portsCor[1])
  connect(hvac.port_retAir[1], flo.portsSou[2])
  connect(hvac.port_retAir[2], flo.portsEas[2])
  connect(hvac.port_retAir[3], flo.portsNor[2])
  connect(hvac.port_retAir[4], flo.portsWes[2])
  connect(hvac.port_retAir[5], flo.portsCor[2])
  connect(weaDat.weaBus, flo.weaBus)
  connect(souCoo.ports[1], hvac.portCooCoiSup)
  connect(sinCoo.ports[1], hvac.portCooCoiRet)
end HVACBuilding;


within Buildings.Examples.VAVReheat;
package BaseClasses "Package with base classes for Buildings.Examples.VAVReheat"
extends Modelica.Icons.BasesPackage;
end BaseClasses;


within Buildings.Examples.VAVReheat.BaseClasses;
partial model PartialFloor "Interface for a model of a floor of a building"

  replaceable package Medium = Modelica.Media.Interfaces.PartialMedium
    "Medium model for air"

  parameter Boolean use_windPressure=true
    "Set to true to enable wind pressure";

  parameter Real kIntNor(min=0, max=1) = 1
    "Gain factor to scale internal heat gain in north zone";

  parameter Modelica.Units.SI.Volume VRooCor "Room volume corridor";
  parameter Modelica.Units.SI.Volume VRooSou "Room volume south";
  parameter Modelica.Units.SI.Volume VRooNor "Room volume north";
  parameter Modelica.Units.SI.Volume VRooEas "Room volume east";
  parameter Modelica.Units.SI.Volume VRooWes "Room volume west";

  parameter Modelica.Units.SI.Area AFloCor "Floor area corridor";
  parameter Modelica.Units.SI.Area AFloSou "Floor area south";
  parameter Modelica.Units.SI.Area AFloNor "Floor area north";
  parameter Modelica.Units.SI.Area AFloEas "Floor area east";
  parameter Modelica.Units.SI.Area AFloWes "Floor area west";

  Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b portsSou[2](
      redeclare package Medium = Medium) "Fluid inlets and outlets"

  Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b portsEas[2](
      redeclare package Medium = Medium) "Fluid inlets and outlets"

  Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b portsNor[2](
      redeclare package Medium = Medium) "Fluid inlets and outlets"

  Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b portsWes[2](
      redeclare package Medium = Medium) "Fluid inlets and outlets"

  Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b portsCor[2](
      redeclare package Medium = Medium) "Fluid inlets and outlets"

  Modelica.Blocks.Interfaces.RealOutput TRooAir[5](
    each unit="K",
    each displayUnit="degC") "Room air temperatures"

  Modelica.Blocks.Interfaces.RealOutput p_rel
    "Relative pressure signal of building static pressure"

  BoundaryConditions.WeatherData.Bus weaBus "Weather bus"

  Buildings.Examples.VAVReheat.BaseClasses.RoomLeakage leaSou(
    redeclare package Medium = Medium,
    VRoo=VRooSou,
    s=49.91/33.27,
    azi=Buildings.Types.Azimuth.S,
    final use_windPressure=use_windPressure)
    "Model for air infiltration through the envelope"
  Buildings.Examples.VAVReheat.BaseClasses.RoomLeakage leaEas(
    redeclare package Medium = Medium,
    VRoo=VRooEas,
    s=33.27/49.91,
    azi=Buildings.Types.Azimuth.E,
    final use_windPressure=use_windPressure)
    "Model for air infiltration through the envelope"

  Buildings.Examples.VAVReheat.BaseClasses.RoomLeakage leaNor(
    redeclare package Medium = Medium,
    VRoo=VRooNor,
    s=49.91/33.27,
    azi=Buildings.Types.Azimuth.N,
    final use_windPressure=use_windPressure)
    "Model for air infiltration through the envelope"

  Buildings.Examples.VAVReheat.BaseClasses.RoomLeakage leaWes(
    redeclare package Medium = Medium,
    VRoo=VRooWes,
    s=33.27/49.91,
    azi=Buildings.Types.Azimuth.W,
    final use_windPressure=use_windPressure)
    "Model for air infiltration through the envelope"

  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temAirSou
    "Air temperature sensor"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temAirEas
    "Air temperature sensor"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temAirNor
    "Air temperature sensor"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temAirWes
    "Air temperature sensor"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temAirCor
    "Air temperature sensor"
  Modelica.Blocks.Routing.Multiplex5 multiplex5_1

  Airflow.Multizone.DoorOpen opeSouCor(
    redeclare package Medium = Medium,
    wOpe=10)
    "Opening between perimeter1 and core"
  Airflow.Multizone.DoorOpen opeEasCor(
    redeclare package Medium = Medium,
    wOpe=10)
    "Opening between perimeter2 and core"
  Airflow.Multizone.DoorOpen opeNorCor(
    redeclare package Medium = Medium,
    wOpe=10)
    "Opening between perimeter3 and core"
  Airflow.Multizone.DoorOpen opeWesCor(redeclare package Medium =
        Medium, wOpe=10)
    "Opening between perimeter3 and core"
  Buildings.Fluid.Sensors.RelativePressure senRelPre(redeclare package Medium = Medium)
    "Building pressure measurement"
  Buildings.Fluid.Sources.Outside out(nPorts=1, redeclare package Medium = Medium)

equation
  connect(weaBus, leaSou.weaBus)
  connect(weaBus, leaEas.weaBus)
  connect(weaBus, leaNor.weaBus)
  connect(weaBus, leaWes.weaBus)
  connect(out.weaBus, weaBus)
  connect(multiplex5_1.y, TRooAir)
  connect(temAirSou.T, multiplex5_1.u1[1])
  connect(temAirEas.T, multiplex5_1.u2[1])
  connect(temAirNor.T, multiplex5_1.u3[1])
  connect(temAirWes.T, multiplex5_1.u4[1])
  connect(temAirCor.T, multiplex5_1.u5[1])
  connect(senRelPre.p_rel, p_rel)
  connect(out.ports[1], senRelPre.port_b)
end PartialFloor;