within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse;
model Radiator
  "Example model with an radiator that conditions a thermal zone in EnergyPlus"
  extends Modelica.Icons.Example;
  package MediumA=Buildings.Media.Air "Medium model for air";
  package MediumW=Buildings.Media.Water "Medium model for water";

  inner Building building(
    idfName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/SingleFamilyHouse_TwoSpeed_ZoneAirBalance/SingleFamilyHouse_TwoSpeed_ZoneAirBalance.idf"),
    weaName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"),
    epwName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw"),
    computeWetBulbTemperature=false)
      "Building model"
  constant Modelica.Units.SI.Volume VRoo=453.138 "Room volume";
  constant Modelica.Units.SI.Area AFlo=185.834
    "Floor area of the whole floor of the building";
  parameter Modelica.Units.SI.MassFlowRate mOut_flow_nominal=0.3*VRoo*1.2/3600
    "Outdoor air mass flow rate, assuming constant infiltration air flow rate";
  parameter Modelica.Units.SI.MassFlowRate mRec_flow_nominal=8*VRoo*1.2/3600
    "Nominal mass flow rate for recirculated air";

  parameter Modelica.Units.SI.HeatFlowRate QRad_flow_nominal = 10000
    "Radiator design heat flow rate (at 50/40)";
  parameter Modelica.Units.SI.Temperature TSup_nominal = 323.15
    "Water supply temperature";
  parameter Modelica.Units.SI.Temperature TRet_nominal = 313.15
    "Water return temperature";
  parameter Modelica.Units.SI.MassFlowRate mRad_flow_nominal = QRad_flow_nominal/4200/(TSup_nominal-TRet_nominal)
    "Radiator design water flow rate";
  parameter Modelica.Units.SI.PressureDifference dpVal_nominal=6000
    "Pressure difference of valve";

  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone zon(
    redeclare package Medium=MediumA,
    zoneName="LIVING ZONE",
    nPorts=2)
    "Thermal zone"
  Controls.OBC.CDL.Reals.Sources.Pulse TSet(
    shift(
      displayUnit="h")=21600,
    amplitude=6,
    period(
      displayUnit="d")=86400,
    offset=273.15+16,
    y(unit="K",
      displayUnit="degC"))
    "Setpoint for room air"
  Controls.OBC.CDL.Reals.PID conPID(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    k=0.2,
    Ti(displayUnit="min") = 600,
    yMax=1,
    yMin=0,
    u_s(
      unit="K",
      displayUnit="degC"),
    u_m(
      unit="K",
      displayUnit="degC"))
    "Controller for heater"
  Fluid.Sources.Boundary_pT pAtm(
    redeclare package Medium=MediumA,
    nPorts=1)
    "Boundary condition"
  Fluid.FixedResistances.PressureDrop duc(
    redeclare package Medium=MediumA,
    allowFlowReversal=false,
    linearized=true,
    from_dp=true,
    dp_nominal=100,
    m_flow_nominal=mOut_flow_nominal)
    "Duct resistance (to decouple room and outside pressure)"
  Fluid.Sources.MassFlowSource_WeatherData freshAir(
    redeclare package Medium=MediumA,
    m_flow=mOut_flow_nominal,
    nPorts=1)
    "Outside air supply"

  Modelica.Blocks.Sources.Constant qIntGai[3](each k=0)
    "Internal heat gains, set to zero because these are modeled in EnergyPlus"
  Fluid.HeatExchangers.Radiators.RadiatorEN442_2 rad(
    redeclare package Medium = MediumW,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    Q_flow_nominal=QRad_flow_nominal,
    T_a_nominal=TSup_nominal,
    T_b_nominal=TRet_nominal) "Radiator"
  Fluid.Sources.Boundary_pT sin(
    redeclare package Medium = MediumW,
    p=200000,
    T=TRet_nominal,
    nPorts=1) "Pressure source for sink"
  Fluid.Sources.Boundary_pT sou(
    redeclare package Medium = MediumW,
    p(displayUnit="Pa") = 2E5 + dpVal_nominal + 1000,
    use_T_in=true,
    nPorts=1) "Pressure source for sink"
  Fluid.Actuators.Valves.TwoWayEqualPercentage val(
    redeclare package Medium = MediumW,
    m_flow_nominal=mRad_flow_nominal,
    dpValve_nominal(displayUnit="Pa") = dpVal_nominal,
    dpFixed_nominal=1000,
    from_dp=true,
    use_strokeTime=false) "Radiator valve"
  Controls.OBC.Utilities.SetPoints.SupplyReturnTemperatureReset watRes(
    TSup_nominal=TSup_nominal,
    TRet_nominal=TRet_nominal,
    TOut_nominal=253.15)
  BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
initial equation
  // Stop simulation if the hard-coded values differ from the ones computed by EnergyPlus.
  assert(
    abs(
      VRoo-zon.V) < 0.01,
    "Zone volume VRoo differs from volume returned by EnergyPlus.");
  assert(
    abs(
      AFlo-zon.AFlo) < 0.01,
    "Zone floor area AFlo differs from area returned by EnergyPlus.");

equation
  connect(TSet.y,conPID.u_s)
  connect(conPID.u_m,zon.TAir)
  connect(duc.port_a,zon.ports[1])
  connect(freshAir.ports[1],zon.ports[2])
  connect(duc.port_b,pAtm.ports[1])
  connect(zon.qGai_flow, qIntGai.y)
  connect(rad.heatPortCon, zon.heaPorAir)
  connect(rad.heatPortRad, zon.heaPorRad)
  connect(sou.ports[1], val.port_a)
  connect(val.port_b, rad.port_a)
  connect(conPID.y, val.y)
  connect(sou.T_in, watRes.TSup)
  connect(building.weaBus, weaBus)
  connect(freshAir.weaBus, weaBus)
  connect(weaBus.TDryBul, watRes.TOut)

  connect(watRes.TSetZon, TSet.y)
  connect(sin.ports[1], rad.port_b)
end Radiator;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse;
model ShadeControl
  "Example model with one actuator that controls a shade in EnergyPlus"
  extends Modelica.Icons.Example;
  package Medium=Buildings.Media.Air
    "Medium model";
  inner Building building(
    idfName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/EMSWindowShadeControl/EMSWindowShadeControl.idf"),
    epwName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw"),
    weaName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Building model"
  parameter Modelica.Units.SI.MassFlowRate m_flow_nominal[:]=0.3*1.2/3600*{
      113.3,113.3,169.9} "Design mass flow rate";
  Modelica.Blocks.Sources.Constant qIntGai[3](
    each k=0)
    "Internal heat gains"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone zonWes(
    redeclare package Medium=Medium,
    zoneName="West Zone",
    nPorts=2)
    "West zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone zonEas(
    redeclare package Medium=Medium,
    zoneName="EAST ZONE",
    nPorts=2)
    "East zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone zonNor(
    redeclare package Medium=Medium,
    zoneName="NORTH ZONE",
    nPorts=2)
    "North zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.Actuator actSha(
    unit=Buildings.ThermalZones.EnergyPlus_9_6_0.Types.Units.Normalized,
    variableName="Zn001:Wall001:Win001",
    componentType="Window Shading Control",
    controlType="Control Status")
    "Actuator for window shade"
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable incBeaSou(
    name="Surface Outside Face Incident Beam Solar Radiation Rate per Area",
    key="Zn001:Wall001:Win001",
    y(final unit="W/m2"))
    "Block that reads incident beam solar radiation on south window from EnergyPlus"
  Buildings.Controls.OBC.Shade.Shade_T shaT(
    THigh=297.15,
    TLow=295.15)
    "Shade control signal based on room air temperature"
  Buildings.Controls.OBC.Shade.Shade_H shaH(
    HHigh=200,
    HLow=10)
    "Shade control decision based on direct solar irradiation"
  Buildings.Controls.OBC.CDL.Logical.And and2
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greEquT(
    t=0.5)
    "Output conversion"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greEquH(
    t=0.5)
    "Output conversion"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal booToRea(
    realTrue=6)
    "Type conversion (6 meaning shade is deployed)"
  Buildings.Fluid.Sources.MassFlowSource_WeatherData bou[3](
    redeclare each package Medium=Medium,
    m_flow=m_flow_nominal,
    each nPorts=1)
    "Infiltration, used to avoid that the absolute humidity is continuously increasing"
  Buildings.Fluid.Sources.Outside out(
    redeclare package Medium=Medium,
    nPorts=1)
    "Outside condition"
  Buildings.Fluid.FixedResistances.PressureDrop res(
    redeclare package Medium=Medium,
    m_flow_nominal=sum(m_flow_nominal),
    dp_nominal=10,
    linearized=true)
  Buildings.Fluid.FixedResistances.PressureDrop res1[3](
    redeclare each package Medium=Medium,
    m_flow_nominal=m_flow_nominal,
    each dp_nominal=10,
    each linearized=true)
    "Small flow resistance for inlet"
  Buildings.BoundaryConditions.WeatherData.Bus weaBus
    "Weather data bus"
  Cooling cooNor
    "Idealized cooling system"
  Cooling cooWes
    "Idealized cooling system"
  Cooling cooEas
    "Idealized cooling system"

equation
  connect(qIntGai.y,zonNor.qGai_flow)
  connect(qIntGai.y,zonEas.qGai_flow)
  connect(qIntGai.y,zonWes.qGai_flow)
  connect(shaT.y,greEquT.u)
  connect(shaH.y,greEquH.u)
  connect(greEquT.y,and2.u1)
  connect(greEquH.y,and2.u2)
  connect(and2.y,booToRea.u)
  connect(actSha.u,booToRea.y)
  connect(shaT.T,zonWes.TAir)
  connect(shaH.H,incBeaSou.y)
  connect(weaBus,out.weaBus)
  connect(bou[:].ports[1],res1[:].port_a)
  connect(weaBus,bou[1].weaBus)
  connect(weaBus,bou[2].weaBus)
  connect(weaBus,bou[3].weaBus)
  connect(building.weaBus,weaBus)
  connect(res1[1].port_b,zonNor.ports[1])
  connect(res1[2].port_b,zonWes.ports[1])
  connect(res1[3].port_b,zonEas.ports[1])
  connect(out.ports[1],res.port_b)
  connect(res.port_a,zonNor.ports[2])
  connect(res.port_a,zonWes.ports[2])
  connect(res.port_a,zonEas.ports[2])

protected
  model Cooling
    extends Modelica.Blocks.Icons.Block;
    HeatTransfer.Sources.PrescribedHeatFlow preHeaFlo
      "Prescribed heat flow rate"
    Controls.OBC.CDL.Reals.MultiplyByParameter gai(k=-5000) "Gain"
    Controls.OBC.CDL.Reals.PID conPID(
      Ti=120,
      reverseActing=false)
    Controls.OBC.CDL.Reals.Sources.Constant TSet(
      k=273.15+25)
      "Set point temperature"
    Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_b heaPor
      "Heat port"
    Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temSen
      "Temperature sensor"

  equation
    connect(TSet.y,conPID.u_s)
    connect(gai.u,conPID.y)
    connect(gai.y,preHeaFlo.Q_flow)
    connect(preHeaFlo.port,heaPor)
    connect(temSen.T,conPID.u_m)
    connect(temSen.port,preHeaFlo.port)
  end Cooling;

equation
  connect(cooNor.heaPor,zonNor.heaPorAir)
  connect(cooWes.heaPor,zonWes.heaPorAir)
  connect(cooEas.heaPor,zonEas.heaPorAir)
end ShadeControl;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse;
model Unconditioned
  "Example model with one unconditoned zone simulated in Modelica, and the other two unconditioned zones simulated in EnergyPlus"
  extends Modelica.Icons.Example;
  package Medium=Buildings.Media.Air
    "Medium model";
  inner Buildings.ThermalZones.EnergyPlus_9_6_0.Building building(
    idfName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/SingleFamilyHouse_TwoSpeed_ZoneAirBalance/SingleFamilyHouse_TwoSpeed_ZoneAirBalance.idf"),
    epwName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw"),
    weaName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"),
    usePrecompiledFMU=false,
    computeWetBulbTemperature=false)
    "Building model"
  parameter Modelica.Units.SI.Volume VRoo=453.1 "Room volume";
  parameter Modelica.Units.SI.MassFlowRate m_flow_nominal=VRoo*1.2*0.3/3600
    "Nominal mass flow rate";
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone zon(
    redeclare package Medium=Medium,
    zoneName="LIVING ZONE",
    nPorts=2)
    "Thermal zone"
  Buildings.Fluid.FixedResistances.PressureDrop duc(
    redeclare package Medium=Medium,
    allowFlowReversal=false,
    linearized=true,
    from_dp=true,
    dp_nominal=100,
    m_flow_nominal=m_flow_nominal)
    "Duct resistance (to decouple room and outside pressure)"
  Buildings.Fluid.Sources.MassFlowSource_WeatherData bou(
    redeclare package Medium=Medium,
    nPorts=1,
    m_flow=m_flow_nominal)
    "Boundary condition"
  Buildings.Fluid.Sources.Boundary_pT freshAir(
    redeclare package Medium=Medium,
    nPorts=1)
    "Boundary condition"
  Modelica.Blocks.Sources.Constant qIntGai[3](
    each k=0)
    "Internal heat gains, set to zero because these are modeled in EnergyPlus"

equation
  connect(freshAir.ports[1],duc.port_b)
  connect(duc.port_a,zon.ports[1])
  connect(bou.ports[1],zon.ports[2])
  connect(zon.qGai_flow,qIntGai.y)
  connect(building.weaBus,bou.weaBus)
end Unconditioned;


Variable air volume flow system with terminal reheat and five thermal zones using a control sequence published by ASHRAE in 2006. This is the same model as

Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.ASHRAE2006Winter
but configured for simulation of a few days in spring.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model ASHRAE2006Spring
  "Variable air volume flow system with terminal reheat and five thermal zones using a control sequence published by ASHRAE in 2006"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.ASHRAE2006Winter;
end ASHRAE2006Spring;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model ASHRAE2006Summer
  "Variable air volume flow system with terminal reheat and five thermal zones using a control sequence published by ASHRAE in 2006"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.ASHRAE2006Winter;
end ASHRAE2006Summer;


Variable air volume flow system with terminal reheat and five thermal zones using a control sequence published by ASHRAE in 2006. 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.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model ASHRAE2006Winter
  "Variable air volume flow system with terminal reheat and five thermal zones using a control sequence published by ASHRAE in 2006"
  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 Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.BaseClasses.Floor flo);

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


Variable air volume flow system with terminal reheat and five thermal zones controlled using an ASHRAE G36 controller. This is the same model as

Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.Guideline36Winter
but configured for simulation of a few days in spring.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model Guideline36Spring
  "Variable air volume flow system with terminal reheat and five thermal zones controlled using an ASHRAE G36 controller"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.Guideline36Winter;
end Guideline36Spring;


Variable air volume flow system with terminal reheat and five thermal zones controlled using an ASHRAE G36 controller. This is the same model as

Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.Guideline36Winter
but configured for simulation of a few days in summer.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model Guideline36Summer
  "Variable air volume flow system with terminal reheat and five thermal zones controlled using an ASHRAE G36 controller"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.Guideline36Winter;
end Guideline36Summer;


Variable air volume flow system with terminal reheat and five thermal zones controlled using an ASHRAE G36 controller. 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.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model Guideline36Winter
  "Variable air volume flow system with terminal reheat and five thermal zones controlled using an ASHRAE G36 controller"
  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.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.BaseClasses.Floor
      flo);

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


Building with constant fresh air and ideal heating/cooling that exactly meets set point. This is the same model as

Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.IdealHeatingCoolingWinter
but configured for simulation of a few days in summer.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model IdealHeatingCoolingSpring
  "Building with constant fresh air and ideal heating/cooling that exactly meets set point"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.IdealHeatingCoolingWinter;
end IdealHeatingCoolingSpring;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model IdealHeatingCoolingSummer
  "Building with constant fresh air and ideal heating/cooling that exactly meets set point"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.IdealHeatingCoolingWinter;
end IdealHeatingCoolingSummer;


Building with constant fresh air and ideal heating/cooling that exactly meets set point. Test case of the small office DOE reference building without an HVAC system
but an ideal heating/cooling device that exactly meets the load.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model IdealHeatingCoolingWinter
  "Building with constant fresh air and ideal heating/cooling that exactly meets set point"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.Unconditioned;
  Controls.OBC.CDL.Reals.Sources.Constant THeaSet[5](
    each k(
      final unit="K",
      displayUnit="degC")=293.15)
    "Set point temperature for heating"
  Controls.OBC.CDL.Reals.Sources.Constant THeaCoo[5](
    each k(
      final unit="K",
      displayUnit="degC")=299.15)
    "Set point temperature for cooling"
  BaseClasses.IdealHeaterCooler[5] hea(
    Q_flow_nominal=70*{flo.AFloSou,flo.AFloEas,flo.AFloNor,flo.AFloWes,flo.AFloCor})
    "Ideal heater"
  BaseClasses.IdealHeaterCooler[5] coo(
    Q_flow_nominal=-50*{flo.AFloSou,flo.AFloEas,flo.AFloNor,flo.AFloWes,flo.AFloCor})
    "Ideal cooling device for sensible cooling"
  Controls.OBC.CDL.Reals.MultiSum QHea_flow(
    nin=5)
    "Total heat flow rate"
  Modelica.Blocks.Continuous.Integrator EHea
    "Heating energy"
  Controls.OBC.CDL.Reals.MultiSum QCoo_flow(
    nin=5)
    "Total heat flow rate"
  Modelica.Blocks.Continuous.Integrator ECoo
    "Cooling energy"

equation
  connect(flo.TRooAir,hea.TMea)
  connect(THeaSet.y,hea.TSet)
  connect(coo[1].heaPor,flo.heaPorSou)
  connect(coo[2].heaPor,flo.heaPorEas)
  connect(coo[3].heaPor,flo.heaPorNor)
  connect(coo[4].heaPor,flo.heaPorWes)
  connect(coo[5].heaPor,flo.heaPorCor)
  connect(hea[1].heaPor,flo.heaPorSou)
  connect(hea[2].heaPor,flo.heaPorEas)
  connect(hea[3].heaPor,flo.heaPorNor)
  connect(hea[4].heaPor,flo.heaPorWes)
  connect(hea[5].heaPor,flo.heaPorCor)
  connect(THeaCoo.y,coo.TSet)
  connect(flo.TRooAir,coo.TMea)
  connect(QHea_flow.y,EHea.u)
  connect(hea.Q_flow,QHea_flow.u)
  connect(QCoo_flow.y,ECoo.u)
  connect(QCoo_flow.u[1:5],coo.Q_flow)
end IdealHeatingCoolingWinter;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples;
package SmallOffice "Package with VAV models for a small office building"
  extends Modelica.Icons.ExamplesPackage;
end SmallOffice;


Open loop model of one floor

within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
model Unconditioned
  "Open loop model of one floor"
  extends Modelica.Icons.Example;
  replaceable package Medium=Buildings.Media.Air
    "Medium for air";
  parameter String weaName=Modelica.Utilities.Files.loadResource(
    "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos")
    "Name of the weather file";
  final parameter Modelica.Units.SI.MassFlowRate mOut_flow[4]=0.3/3600*{flo.VRooSou,
      flo.VRooEas,flo.VRooNor,flo.VRooWes}*1.2
    "Outside air infiltration for each exterior room";
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    filNam=weaName,
    computeWetBulbTemperature=false)
    "Weather data reader"
  BoundaryConditions.WeatherData.Bus weaBus
    "Weather data bus"
  Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.BaseClasses.Floor flo(
    redeclare package Medium=Medium,
    nor(
      T_start=275.15),
    wes(
      T_start=275.15),
    eas(
      T_start=275.15),
    sou(
      T_start=275.15),
    cor(
      T_start=275.15))
    "One floor of the office building"
  // Above, the volume V is for Spawn obtained in the initial equation section.
  // Hence it is not known when the model is compiled. This leads to a
  // warning in Dymola and an error in Optimica (Modelon#2020031339000191)
  // if used in an expression for the nominal attribute of lea*(res(m_flow(nominal=....))).
  // Assigning the nominal attribute to a constant avoids this warning and error.
  Fluid.Sources.MassFlowSource_WeatherData bou[4](
    redeclare each package Medium=Medium,
    m_flow=mOut_flow,
    each nPorts=1)
    "Infiltration, used to avoid that the absolute humidity is continuously increasing"
  Fluid.Sources.Outside out(
    redeclare package Medium=Medium,
    nPorts=1)
    "Outside condition"
  Fluid.FixedResistances.PressureDrop res(
    redeclare package Medium=Medium,
    m_flow_nominal=sum(mOut_flow),
    dp_nominal=10,
    linearized=true)
    "Small flow resistance for inlet"
  Fluid.FixedResistances.PressureDrop res1[4](
    redeclare each package Medium=Medium,
    each m_flow_nominal=sum(mOut_flow),
    each dp_nominal=10,
    each linearized=true)
    "Small flow resistance for inlet"

equation
  connect(weaDat.weaBus,weaBus)
  connect(weaBus,flo.weaBus)
  connect(out.ports[1],res.port_a)
  connect(res.port_b,flo.portsCor[1])
  connect(weaBus,out.weaBus)
  connect(bou[:].ports[1],res1[:].port_a)
  connect(weaBus,bou[1].weaBus)
  connect(weaBus,bou[2].weaBus)
  connect(weaBus,bou[3].weaBus)
  connect(weaBus,bou[4].weaBus)
  connect(res1[1].port_b,flo.portsSou[1])
  connect(res1[2].port_b,flo.portsEas[1])
  connect(res1[3].port_b,flo.portsNor[1])
  connect(res1[4].port_b,flo.portsWes[1])
end Unconditioned;


Model of a floor of the building

within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.BaseClasses;
model Floor
  "Model of a floor of the building"
  extends Buildings.Examples.VAVReheat.BaseClasses.PartialFloor(
    VRooCor=456.455,
    VRooSou=346.022,
    VRooNor=346.022,
    VRooEas=205.265,
    VRooWes=205.265,
    AFloCor=cor.AFlo,
    AFloSou=sou.AFlo,
    AFloNor=nor.AFlo,
    AFloEas=eas.AFlo,
    AFloWes=wes.AFlo,
    opeWesCor(
      wOpe=4),
    opeSouCor(
      wOpe=9),
    opeNorCor(
      wOpe=9),
    opeEasCor(
      wOpe=4),
    leaWes(
      s=18.46/27.69),
    leaSou(
      s=27.69/18.46),
    leaNor(
      s=27.69/18.46),
    leaEas(
      s=18.46/27.69));

  final parameter Modelica.Units.SI.Area AFlo=AFloCor + AFloSou + AFloNor +
      AFloEas + AFloWes "Total floor area";
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heaPorSou
    "Heat port to air volume South"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heaPorEas
    "Heat port to air volume East"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heaPorNor
    "Heat port to air volume North"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heaPorWes
    "Heat port to air volume West"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heaPorCor
    "Heat port to air volume corridor"
  Modelica.Units.SI.Temperature TAirCor=cor.TAir "Air temperature corridor";
  Modelica.Units.SI.Temperature TAirSou=sou.TAir "Air temperature south zone";
  Modelica.Units.SI.Temperature TAirNor=nor.TAir "Air temperature north zone";
  Modelica.Units.SI.Temperature TAirEas=eas.TAir "Air temperature east zone";
  Modelica.Units.SI.Temperature TAirWes=wes.TAir "Air temperature west zone";
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone sou(
    redeclare package Medium=Medium,
    nPorts=5,
    zoneName="Perimeter_ZN_1")
    "South zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone eas(
    redeclare package Medium=Medium,
    nPorts=5,
    zoneName="Perimeter_ZN_2")
    "East zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone nor(
    redeclare package Medium=Medium,
    nPorts=5,
    zoneName="Perimeter_ZN_3")
    "North zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone wes(
    redeclare package Medium=Medium,
    nPorts=5,
    zoneName="Perimeter_ZN_4")
    "West zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone cor(
    redeclare package Medium=Medium,
    nPorts=11,
    zoneName="Core_ZN")
    "Core zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone att(
    redeclare package Medium=Medium,
    zoneName="Attic",
    T_start=275.15)
    "Attic zone"

  parameter String idfName=Modelica.Utilities.Files.loadResource(
    "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/RefBldgSmallOffice/RefBldgSmallOfficeNew2004_Chicago.idf")
    "Name of the IDF file";
  parameter String epwName=Modelica.Utilities.Files.loadResource(
    "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw")
    "Name of the weather file";
  parameter String weaName=Modelica.Utilities.Files.loadResource(
    "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos")
    "Name of the weather file";

protected
  inner Buildings.ThermalZones.EnergyPlus_9_6_0.Building building(
    idfName=idfName,
    epwName=epwName,
    weaName=weaName,
    computeWetBulbTemperature=false)
    "Building-level declarations"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant qGai_flow[3](
    k={0,0,0})
    "Internal heat gain (computed already in EnergyPlus)"

initial equation
  assert(
    abs(
      cor.V-VRooCor) < 0.01,
    "Volumes don't match. These had to be entered manually to avoid using a non-literal value.");
  assert(
    abs(
      sou.V-VRooSou) < 0.01,
    "Volumes don't match. These had to be entered manually to avoid using a non-literal value.");
  assert(
    abs(
      nor.V-VRooNor) < 0.01,
    "Volumes don't match. These had to be entered manually to avoid using a non-literal value.");
  assert(
    abs(
      eas.V-VRooEas) < 0.01,
    "Volumes don't match. These had to be entered manually to avoid using a non-literal value.");
  assert(
    abs(
      wes.V-VRooWes) < 0.01,
    "Volumes don't match. These had to be entered manually to avoid using a non-literal value.");

  // Other models may override the assignment for AFlo. Hence we check below for consistency.
  assert(
    abs(
      cor.AFlo-AFloCor) < 0.01,
    "Areas don't match. Make sure model that overrides these parameter defaults uses the same values as the idf file uses.");
  assert(
    abs(
      sou.AFlo-AFloSou) < 0.01,
    "Areas don't match. Make sure model that overrides these parameter defaults uses the same values as the idf file uses.");
  assert(
    abs(
      nor.AFlo-AFloNor) < 0.01,
    "Areas don't match. Make sure model that overrides these parameter defaults uses the same values as the idf file uses.");
  assert(
    abs(
      eas.AFlo-AFloEas) < 0.01,
    "Areas don't match. Make sure model that overrides these parameter defaults uses the same values as the idf file uses.");
  assert(
    abs(
      wes.AFlo-AFloWes) < 0.01,
    "Areas don't match. Make sure model that overrides these parameter defaults uses the same values as the idf file uses.");

equation
  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(sou.qGai_flow,qGai_flow.y)
  connect(wes.qGai_flow,qGai_flow.y)
  connect(eas.qGai_flow,qGai_flow.y)
  connect(cor.qGai_flow,qGai_flow.y)
  connect(nor.qGai_flow,qGai_flow.y)
  connect(att.qGai_flow,qGai_flow.y)
  connect(sou.heaPorAir,heaPorSou)
  connect(eas.heaPorAir,heaPorEas)
  connect(nor.heaPorAir,heaPorNor)
  connect(wes.heaPorAir,heaPorWes)
  connect(cor.heaPorAir,heaPorCor)
end Floor;


Model of ideal heater or cooler. Model of an ideal heater or cooler that tracks a set point using a PI controller.
The heater or cooler has a PID controller that regulates the heat added or removed.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice.BaseClasses;
model IdealHeaterCooler
  "Model of ideal heater or cooler"
  extends Modelica.Blocks.Icons.Block;
  parameter Modelica.Units.SI.HeatFlowRate Q_flow_nominal
    "Maximum heat flow rate (positive for heating; negative for cooling)";
  parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI
    "Type of controller"
  parameter Real k(
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=1
    "Gain of controller"
  parameter Real Ti(
    final quantity="Time",
    final unit="s",
    min=100*Buildings.Controls.OBC.CDL.Constants.eps)=120
    "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"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TSet
    "Set point temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TMea
    "Measured temperature"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput Q_flow(
    final unit="W")
    "Heat flow rate"
  HeatTransfer.Sources.PrescribedHeatFlow preHeaFlo
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_b heaPor
    "Heat port"
  Buildings.Controls.OBC.CDL.Reals.PID conPID(
    final controllerType=controllerType,
    final k=k,
    final Ti=Ti,
    final Td=Td,
    reverseActing=Q_flow_nominal > 0)
    "Controller for heat input"

protected
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k=Q_flow_nominal) "Gain for heat flow rate"

equation
  connect(conPID.u_s,TSet)
  connect(conPID.u_m,TMea)
  connect(preHeaFlo.Q_flow,gai.y)
  connect(gai.u,conPID.y)
  connect(preHeaFlo.port,heaPor)
  connect(gai.y,Q_flow)
end IdealHeaterCooler;


Package with base classes

within Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SmallOffice;
package BaseClasses "Package with base classes"
  extends Modelica.Icons.BasesPackage;
end BaseClasses;


Package with type definitions

within Buildings.ThermalZones.EnergyPlus_9_6_0;
package Types "Package with type definitions"
  extends Modelica.Icons.TypesPackage;
end Types;


Collection of validation models

within Buildings.ThermalZones.EnergyPlus_9_6_0;
package Validation "Collection of validation models"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation;
package MultipleBuildings "Collection of validation models for multiple EnergyPlus buildings"
  extends Modelica.Icons.Package;
end MultipleBuildings;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.MultipleBuildings;
model ThreeZonesTwoBuildings
  "Validation model for three zones that are in two buildings"
  extends Modelica.Icons.Example;
  package Medium=Buildings.Media.Air
    "Medium model";
  model OneZoneBuilding
    "Model with a building with one zone"
    extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned;
    extends Modelica.Blocks.Icons.Block;
  end OneZoneBuilding;

  model TwoZoneBuilding
    "Model with a building with two zones"
    extends Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone.TwoIdenticalZones;
    extends Modelica.Blocks.Icons.Block;
  end TwoZoneBuilding;
  OneZoneBuilding zon1
    "Building with one thermal zone"
  TwoZoneBuilding zon2
    "Building with two thermal zones"
end ThreeZonesTwoBuildings;


Validation model with two identical buildings, each having one thermal zone. Model that validates that multiple buildings can be simulated that use the same EnergyPlus idf file.
The model has two identical buildings, each having one thermal zone.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.MultipleBuildings;
model TwoIdenticalOneZoneBuildings
  "Validation model with two identical buildings, each having one thermal zone"
  extends Modelica.Icons.Example;
  constant Integer n=2
    "Number of buildings";
  Zone bui[n]
    "Buildings"
  model Zone
    "Model of a thermal zone"
    extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned;
    extends Modelica.Blocks.Icons.Block;
  end Zone;
end TwoIdenticalOneZoneBuildings;


Validation model with two identical buildings, each having two thermal zones. Model that validates that multiple buildings can be simulated that use the same EnergyPlus idf file.
The model has two identical buildings, each having two thermal zones.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.MultipleBuildings;
model TwoIdenticalTwoZoneBuildings
  "Validation model with two identical buildings, each having two thermal zones"
  extends Modelica.Icons.Example;
  constant Integer n=2
    "Number of buildings";
  Zone bui[n]
    "Buildings"
  model Zone
    "Model of a thermal zone"
    extends Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone.TwoIdenticalZones;
    extends Modelica.Blocks.Icons.Block;
  end Zone;
end TwoIdenticalTwoZoneBuildings;


Failing example caused by missing Output:Variable in the idf. This validation case tests whether Spawn works for an idf file that has no output variables declared.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable;
model NoOutputVariable
  "Failing example caused by missing Output:Variable in the idf"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned(
   building(idfName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/SingleFamilyHouse_TwoSpeed_ZoneAirBalance/SingleFamilyHouse_TwoSpeed_ZoneAirBalance_NoOutput.idf")));
end NoOutputVariable;


Validation model that has only one output variable from the environment conditions reported to Modelica. Simple test case for one building in which only an EnergyPlus output variable is read.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable;
model OneEnvironmentOutputVariable
  "Validation model that has only one output variable from the environment conditions reported to Modelica"
  extends Modelica.Icons.Example;
  inner Building building(
    idfName=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/SingleFamilyHouse_TwoSpeed_ZoneAirBalance/SingleFamilyHouse_TwoSpeed_ZoneAirBalance.idf"),
    epwName=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw"),
    weaName=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"),
    computeWetBulbTemperature=false)
    "Building model"

  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable TEnePlu(
    name="Site Outdoor Air Drybulb Temperature",
    key="Environment",
    y(final unit="K", displayUnit="degC"))
    "Block that reads an EnergyPlus output variable"
end OneEnvironmentOutputVariable;


Validation model for one zone with one output variable. Simple test case for one building with one thermal zone and one output variable.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable;
model OneZoneOneOutputVariable
  "Validation model for one zone with one output variable"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned;
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable equEle(
    name="Zone Electric Equipment Electricity Rate",
    key="LIVING ZONE",
    y(final unit="W"))
    "Block that reads output from EnergyPlus"
end OneZoneOneOutputVariable;


Validation model for one zone with one output variable for a summer period. Test case identical to

Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable.OneZoneOneOutputVariable
but simulating only a period in summer.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable;
model OneZoneOneOutputVariableSummer
  "Validation model for one zone with one output variable for a summer period"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable.OneZoneOneOutputVariable;
end OneZoneOneOutputVariableSummer;


Validation model that has only one output variable from a zone reported to Modelica. Simple test case for one building in which only an EnergyPlus output variable is read.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable;
model OneZoneOutputVariable
  "Validation model that has only one output variable from a zone reported to Modelica"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable.OneEnvironmentOutputVariable(TEnePlu(
        name="Zone Mean Air Temperature",
        key="LIVING ZONE"));
end OneZoneOutputVariable;


Validation model for one zone with two different output variables. Simple test case for one building with one thermal zone and two different output variables.
This test case validates that the outputs are correct if requested from different
EnergyPlus variables.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable;
model OneZoneTwoDifferentOutputVariables
  "Validation model for one zone with two different output variables"
  extends OneZoneOneOutputVariable;
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable incBeaSou(
    name="Surface Outside Face Incident Beam Solar Radiation Rate per Area",
    key="Living:South",
    y(final unit="W/m2"))
    "Block that reads incident beam solar radiation on south window from EnergyPlus"
end OneZoneTwoDifferentOutputVariables;


Validation model for one zone with two identical output variables. Simple test case for one building with one thermal zone and two identical output variables.
This test case validates that the outputs are correct even if requested twice
from the same EnergyPlus variable.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable;
model OneZoneTwoIdenticalOutputVariables
  "Validation model for one zone with two identical output variables"
  extends OneZoneOneOutputVariable;
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable equEle2(
    name="Zone Electric Equipment Electricity Rate",
    key="LIVING ZONE",
    y(final unit="W"))
    "Block that reads output from EnergyPlus"
end OneZoneTwoIdenticalOutputVariables;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation;
package OutputVariable "Collection of validation models for EnergyPlus output variables"
  extends Modelica.Icons.Package;
end OutputVariable;


Validation model for negative start time. Validation model for negative start time.
This test validates that EnergyPlus correctly simulates if it is started at a negative start time.
The model simulates the last two days of the year and the first day.
For comparison with the Modelica weather data, the model reads the solar irradiation and the outdoor drybulb temperature
from EnergyPlus.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.RunPeriod;
model NegativeStartTime "Validation model for negative start time"
  extends Examples.SingleFamilyHouse.Unconditioned;
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable sitDirSol(
    name="Site Direct Solar Radiation Rate per Area",
    key="Environment",
    y(final unit="W/m2"))
    "Block that reads direct solar radiation from EnergyPlus"
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable sitOutDryBul(
    name="Site Outdoor Air Drybulb Temperature",
    key="Environment",
    y(final unit="K",
      displayUnit="degC"))
    "Block that reads outside dry bulb temperature from EnergyPlus"
end NegativeStartTime;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation;
package RunPeriod "Collection of validation models for EnergyPlus run period"
  extends Modelica.Icons.Package;
end RunPeriod;


Validation model for the start day of the week. This validation case simulates two instances of

Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable.OneZoneOneOutputVariable,
a model that outputs the electricity consumption that is specified via an EnergyPlus schedule.
This schedule set the electricity consumption to zero for the whole day on Saturday and Sunday,
but not on other days.
In the instance sun, the start day of the year is left as the default, which is Sunday,
and in the instance mon, it is set to Monday.
Plotting the electricity consumption verifies that the setting is properly applied
in EnergyPlus.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.RunPeriod;
model StartDayOfYear "Validation model for the start day of the week"
  extends Modelica.Icons.Example;

  Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable.OneZoneOneOutputVariable sun
    "Model with first day of the week being Sunday"
  Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.OutputVariable.OneZoneOneOutputVariable mon(
    building(
      runPeriod(
        startDayOfYear=Buildings.ThermalZones.EnergyPlus_9_6_0.Types.WeekDays.Monday)))
    "Model with first day of the week being Monday"

  Modelica.Blocks.Sources.RealExpression sunEle(y(final unit="W")=sun.equEle.y)
    "Electricity consumption for model with Sunday as the first day of the week"
  Modelica.Blocks.Sources.RealExpression monEle(y(final unit="W") = mon.equEle.y)
    "Electricity consumption for model with Monday as the first day of the week"
end StartDayOfYear;


Validation case with a schedule that is not sampled, and output reader of the energy affected by the scheduled value. Simple test case that verifies whether the schedule for the internal loads
used by EnergyPlus is modified from Modelica, and the electrical equipment load
that is controlled by this schedule is reported correctly.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.Schedule;
model EquipmentScheduleOutputVariable
  "Validation case with a schedule that is not sampled, and output reader of the energy affected by the scheduled value"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.EquipmentSchedule;
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable equEle(
    name="Zone Electric Equipment Electricity Rate",
    key="LIVING ZONE",
    isDirectDependent=true,
    y(final unit="W"))
    "Block that reads output from EnergyPlus"
  Utilities.Diagnostics.AssertEquality assEqu(
    threShold=1E-6,
    message="EnergyPlus did not synchronize the output variable correctly")
    "Assertion to test whether the schedule and the EnergyPlus output variable are correctly synchronized"
  Controls.OBC.CDL.Reals.MultiplyByParameter gai(k=500)
    "Gain for internal heat gain"

equation
  connect(schInt.y,equEle.directDependency)
  connect(equEle.y,assEqu.u1)
  connect(assEqu.u2,gai.y)
  connect(gai.u,intLoaFra.y)
end EquipmentScheduleOutputVariable;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation;
package Schedule "Collection of validation models for EnergyPlus schedules"
  extends Modelica.Icons.Package;
end Schedule;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation;
package SurfaceComparison "Collection of models used to validate zone surface coupling against EnergyPlus"
  extends Modelica.Icons.Package;
end SurfaceComparison;


Validation model for reference surfaces and zone surfaces. This model validates that the
Buildings.ThermalZones.EnergyPlus_9_6_0.ZoneSurface objects results in similar surface heat
transfer to the equivalent EnergyPlus surface object.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison;
model SurfaceComparison
  "Validation model for reference surfaces and zone surfaces"
  extends Modelica.Icons.Example;

  Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison.BaseClasses.ReferenceSurfaces refSur
    "Building that models the envelope with EnergyPlus surfaces"
  Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison.BaseClasses.ZoneSurfaces zonSur
    "Building that models the envelope with Spawn surfaces"
end SurfaceComparison;


Model of an exterior wall with Spawn-controlled surface conditions. This is a model of the heat transfer through an exterior wall, which is connected
to an EnergyPlus Zone Heat Balance through

Buildings.ThermalZones.EnergyPlus_9_6_0.ZoneSurface object on the interior surface and a

Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable to read the exterior surface temperature.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison.BaseClasses;
model ExteriorWall "Model of an exterior wall with Spawn-controlled surface conditions"
  extends Buildings.HeatTransfer.Conduction.BaseClasses.PartialConstruction;

  parameter String surNam "Name of EnergyPlus Surface";

  parameter Modelica.Units.SI.Area A "Wall area";

  replaceable parameter Buildings.HeatTransfer.Data.OpaqueConstructions.Generic
    layers "Construction definition from Data.OpaqueConstructions"

  Buildings.ThermalZones.EnergyPlus_9_6_0.ZoneSurface sur(surfaceName=surNam)
    "Wall interior surface"
  HeatTransfer.Conduction.MultiLayer walCon(
    A=A,
    layers=layers) "Wall construction"
  HeatTransfer.Sources.PrescribedHeatFlow heaSurExt
    "Exterior surface heat transfer rate"

  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor TSurInt
    "Interior surface temperature"
  HeatTransfer.Sources.PrescribedHeatFlow heaSurInt
   "Prescribed heat flow rate"
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable extSurHea(
    name="Surface Outside Face Conduction Heat Transfer Rate",
    key=surNam)
  Modelica.Blocks.Math.Gain inv(k=-1) "Invert the sign of the heat flow signal"
equation
  connect(heaSurExt.port, walCon.port_a)
  connect(sur.Q_flow, heaSurInt.Q_flow)
  connect(heaSurInt.port, walCon.port_b)
  connect(TSurInt.port, walCon.port_b)
  connect(TSurInt.T, sur.T)
  connect(extSurHea.y, inv.u)
  connect(inv.y, heaSurExt.Q_flow)
end ExteriorWall;


Model of an interior wall with Spawn-controlled surface conditions. This is a model of the heat transfer through an interior wall, which is connected
to an EnergyPlus Zone Heat Balance through

Buildings.ThermalZones.EnergyPlus_9_6_0.ZoneSurface objects on both side of
the wall.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison.BaseClasses;
model InteriorWall "Model of an interior wall with Spawn-controlled surface conditions"
  extends Buildings.HeatTransfer.Conduction.BaseClasses.PartialConstruction;

  parameter String surNam_a "Name of EnergyPlus Surface (port a)";
  parameter String surNam_b "Name of EnergyPlus Surface (port b)";

  parameter Modelica.Units.SI.Area A "Wall area";

  replaceable parameter Buildings.HeatTransfer.Data.OpaqueConstructions.Generic
    layers "Construction definition from Data.OpaqueConstructions"

  Buildings.ThermalZones.EnergyPlus_9_6_0.ZoneSurface sur_a(surfaceName=surNam_a)
    "Wall surface (port a)"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ZoneSurface sur_b(surfaceName=surNam_b)
    "Wall surface (port b)"
  Buildings.HeatTransfer.Conduction.MultiLayer walCon(
    A=A,
    layers=layers) "Wall conduction"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor TSur_a
    "Surface temperature (port a)"
  Buildings.HeatTransfer.Sources.PrescribedHeatFlow heaSur_a
    "Surface heat transfer rate (port a)"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor TSur_b
    "Surface temperature (port b)"
  Buildings.HeatTransfer.Sources.PrescribedHeatFlow heaSur_b
    "Surface heat transfer rate (port b)"
equation
  connect(walCon.port_a, TSur_a.port)
  connect(TSur_a.T, sur_a.T)
  connect(sur_a.Q_flow, heaSur_a.Q_flow)
  connect(heaSur_a.port, walCon.port_a)
  connect(sur_b.Q_flow, heaSur_b.Q_flow)
  connect(heaSur_b.port, walCon.port_b)
  connect(TSur_b.port, walCon.port_b)
  connect(TSur_b.T, sur_b.T)
end InteriorWall;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison;
package BaseClasses "Package with base classes for Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison"
extends Modelica.Icons.BasesPackage;
end BaseClasses;


Model that contains Eplus OutputVariable used to validate ZoneSurface. This model simulates the envelope of a single family house with EnergyPlus and is used
as a baseline to the

Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison.SurfaceComparison
validation model which compare that baseline to the same building, but using Spawn connectors
for some interior and exterior walls.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison.BaseClasses;
model ReferenceSurfaces
  "Model that contains Eplus OutputVariable used to validate ZoneSurface"
  extends Modelica.Blocks.Icons.Block;

  inner Buildings.ThermalZones.EnergyPlus_9_6_0.Building building(
    idfName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/SingleFamilyHouse_TwoSpeed_ZoneAirBalance/SingleFamilyHouse_TwoSpeed_ZoneAirBalance.idf"),
    epwName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw"),
    weaName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"),
    usePrecompiledFMU=false,
    computeWetBulbTemperature=false)
    "Building model"

  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable TGarAir(
    name="Zone Mean Air Temperature",
    key="LIVING ZONE",
    y(unit="K")) "Garage air temperature"
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable TIntWalLivSur(
    name="Surface Inside Face Temperature",
    key="Living:Interior",
    y(unit="K")) "Interior wall living room surface temperature"
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable TIntWalGarSur(
    name="Surface Inside Face Temperature",
    key="Garage:Interior",
    y(unit="K")) "Interior wall garage surface temperature"
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable TWesWalGarSur(
    name="Surface Inside Face Temperature",
    key="Garage:WestWall",
    y(unit="K")) "West wall garage surface temperature"
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable TEasWalGarSur(
    name="Surface Inside Face Temperature",
    key="Garage:EastWall",
    y(unit="K")) "East wall garage surface temperature"
end ReferenceSurfaces;


Example model with two EnergyPlus unconditioned zones with their separating surfaces modeled in Modelica. This model simulates the envelope of a single family house with EnergyPlus but uses

Buildings.ThermalZones.EnergyPlus_9_6_0.ZoneSurface to model the heat
transfer through the garage exterior (east and west facing) and interior walls.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.SurfaceComparison.BaseClasses;
model ZoneSurfaces
  "Example model with two EnergyPlus unconditioned zones with their separating surfaces modeled in Modelica"
  extends BaseClasses.ReferenceSurfaces;

  parameter Integer nSta = 3 "Number of states";

  BaseClasses.InteriorWall int(
    layers=intWal,
    surNam_a="Garage:Interior",
    surNam_b="Living:Interior",
    A=16.87) "Interior wall between living room and garage"
  BaseClasses.ExteriorWall wes(
    layers=extWal,
    surNam="Garage:WestWall",
    A=14.87) "West wall of garage"
  BaseClasses.ExteriorWall eas(
    layers=extWal,
    surNam="Garage:EastWall",
    A=14.87) "East wall of garage"

protected
  parameter HeatTransfer.Data.Solids.GypsumBoard gyp(
    x=0.0127,
    k=0.16,
    c=837,
    d(displayUnit="kg/m3") = 801,
    nStaRef=nSta) "Gypsum or Plaster Board 1/2 in"
  parameter HeatTransfer.Data.Solids.InsulationBoard ins(
    x=0.09,
    k=0.043,
    c=837,
    d(displayUnit="kg/m3") = 10.0,
    nStaRef=nSta) "Mineral Wool/Fiber Batt R-11"
  parameter HeatTransfer.Data.Solids.Concrete CB11(
    x=0.2032000,
    k=1.048000,
    c=837,
    d(displayUnit="kg/m3") = 1105,
    nStaRef=nSta) "Concrete Block 8 in HW Hol."
  parameter HeatTransfer.Data.Solids.GypsumBoard stu(
    x=0.025389841,
    k=0.6918309,
    c=836.8000,
    d(displayUnit="kg/m3") = 1858.142,
    nStaRef=nSta) "Stucco layer 1 in"

  parameter HeatTransfer.Data.OpaqueConstructions.Generic intWal(
    nLay=3,
    material={gyp,ins,gyp},
    absSol_a=0.75,
    absSol_b=0.75) "Interior wall construction"
  parameter HeatTransfer.Data.OpaqueConstructions.Generic extWal(
    nLay=2,
    material={stu,CB11},
    absSol_a=0.92,
    absSol_b=0.92) "Exterior garage wall construction"
end ZoneSurfaces;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone;
model Infiltration
  "Validation model for outside air infiltration in zones not modeled in Modelica"
  extends Modelica.Icons.Example;
  package Medium=Buildings.Media.Air
    "Medium model";

  Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.RadiantHeatingCooling_TRoom defInf(
    building(
      idfName = Modelica.Utilities.Files.loadResource(
        "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/SingleFamilyHouse_TwoSpeed_ZoneAirBalance/SingleFamilyHouse_TwoSpeed_ZoneAirBalance_aboveSoil.idf")))
    "Model with default infiltration in attic"
  Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.RadiantHeatingCooling_TRoom higInf(
    building(
      idfName = Modelica.Utilities.Files.loadResource(
        "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/SingleFamilyHouse_TwoSpeed_ZoneAirBalance/SingleFamilyHouse_TwoSpeed_ZoneAirBalance_aboveSoilHighInfiltration.idf")))
    "Model with high infiltration in attic"
end Infiltration;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone;
model InternalGain
  "Validation model for one zone with and without internal heat gain"
  extends Modelica.Icons.Example;
  package Medium=Buildings.Media.Air
    "Medium model";
  OneZoneWithGainExposed noGai(
    qRad_flow=0,
    qSen_flow=0,
    qLat_flow=0)
    "Zone with no internal heat gains from Modelica"
  OneZoneWithGainExposed radOnl(
    qRad_flow=5,
    qSen_flow=0,
    qLat_flow=0)
    "Zone with only radiative heat gains from Modelica"
  OneZoneWithGainExposed conOnl(
    qRad_flow=0,
    qSen_flow=5,
    qLat_flow=0)
    "Zone with only convective heat gains from Modelica"
  OneZoneWithGainExposed latOnl(
    qRad_flow=0,
    qSen_flow=0,
    qLat_flow=5)
    "Zone with only latent heat gains from Modelica"

protected
  model OneZoneWithGainExposed
    "Internal model for building with one thermal zone"
    extends Modelica.Blocks.Icons.Block;
    parameter Modelica.Units.SI.HeatFlux qRad_flow
      "Radiative internal heat gain";
    parameter Modelica.Units.SI.HeatFlux qSen_flow
      "Convective sensible internal heat gain";
    parameter Modelica.Units.SI.HeatFlux qLat_flow "Latent internal heat gain";
    Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned bui(
      m_flow_nominal=bui.VRoo*10*0.3/3600,
      qIntGai(
        final k={qRad_flow,qSen_flow,qLat_flow}),
      bou(
        m_flow=bui.zon.V*1.2*10/3600))
      "Building model"
  end OneZoneWithGainExposed;
end InternalGain;


This example tests whether the zone mean air temperature is reported correctly as an EnergyPlus output. Simple test case that verifies whether the zone mean air temperature is reported correctly by EnergyPlus.
Note that Modelica solves the differential equation for this variable, but this test case
obtains its value from EnergyPlus.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone;
model OneZoneCompareZoneTemperatureOutput
  "This example tests whether the zone mean air temperature is reported correctly as an EnergyPlus output"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned;
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable zonMeaAirTem(
    name="Zone Mean Air Temperature",
    key="LIVING ZONE",
    y(final unit="K",
      displayUnit="degC"))
    "Block that reads output from EnergyPlus"
end OneZoneCompareZoneTemperatureOutput;


Validation model for one zone. Simple test case that simulates a building with
one thermal zone for one year.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone;
model OneZoneOneYear
  "Validation model for one zone"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned;
  Controls.OBC.CDL.Reals.MovingAverage TAirMea(
    delta(displayUnit="d")= 86400,
    y(final unit="K",
      displayUnit="degC"))
    "Moving mean of air temperature"

equation
  connect(TAirMea.u,zon.TAir)
end OneZoneOneYear;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation;
package ThermalZone "Collection of validation models for EnergyPlus thermal zones"
  extends Modelica.Icons.Package;
end ThermalZone;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone;
model RefBldgSmallOffice
  "Validation model for six zones small office building"
  extends Modelica.Icons.Example;
  package Medium=Buildings.Media.Air
    "Medium model";
  inner Building building(
    idfName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/RefBldgSmallOffice/RefBldgSmallOfficeNew2004_Chicago.idf"),
    epwName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw"),
    weaName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Building model"
  Modelica.Blocks.Sources.Constant qConGai_flow(
    k=0)
    "Convective heat gain"
  Modelica.Blocks.Sources.Constant qRadGai_flow(
    k=0)
    "Radiative heat gain"
  Modelica.Blocks.Routing.Multiplex3 mul
    "Multiplex for gains"
  Modelica.Blocks.Sources.Constant qLatGai_flow(
    k=0)
    "Latent heat gain"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone att(
    redeclare package Medium=Medium,
    zoneName="Attic")
    "Thermal zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone cor(
    redeclare package Medium=Medium,
    zoneName="Core_ZN")
    "Thermal zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone sou(
    redeclare package Medium=Medium,
    zoneName="Perimeter_ZN_1")
    "Thermal zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone eas(
    redeclare package Medium=Medium,
    zoneName="Perimeter_ZN_2")
    "Thermal zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone nor(
    redeclare package Medium=Medium,
    zoneName="Perimeter_ZN_3")
    "Thermal zone"
  Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone wes(
    redeclare package Medium=Medium,
    zoneName="Perimeter_ZN_4")
    "Thermal zone"
  Modelica.Blocks.Sources.CombiTimeTable datRea(
    tableOnFile=true,
    fileName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/RefBldgSmallOffice/RefBldgSmallOfficeNew2004_Chicago.dat"),
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    tableName="EnergyPlus",
    columns=2:9,
    extrapolation=Modelica.Blocks.Types.Extrapolation.HoldLastPoint)
    "Data reader with results from EnergyPlus"
  Modelica.Units.SI.Temperature TOutEP=datRea.y[1] + 273.15
    "Outside air temperature of EnergyPlus simulation";
  Real relHumEP(
    unit="1")=datRea.y[2]/100
    "Outside air relative humidity of EnergyPlus simulation";
  Modelica.Units.SI.Temperature TAttEP=datRea.y[3] + 273.15
    "Attic air temperature of EnergyPlus simulation";
  Modelica.Units.SI.Temperature TCorEP=datRea.y[4] + 273.15
    "Core zone air temperature of EnergyPlus simulation";
  Modelica.Units.SI.Temperature TSouEP=datRea.y[5] + 273.15
    "South zone air temperature of EnergyPlus simulation";
  Modelica.Units.SI.Temperature TEasEP=datRea.y[6] + 273.15
    "East zone air temperature of EnergyPlus simulation";
  Modelica.Units.SI.Temperature TNorEP=datRea.y[7] + 273.15
    "North zone air temperature of EnergyPlus simulation";
  Modelica.Units.SI.Temperature TWesEP=datRea.y[8] + 273.15
    "West zone air temperature of EnergyPlus simulation";

equation
  connect(qRadGai_flow.y,mul.u1[1])
  connect(qConGai_flow.y,mul.u2[1])
  connect(mul.u3[1],qLatGai_flow.y)
  connect(att.qGai_flow,mul.y)
  connect(cor.qGai_flow,mul.y)
  connect(mul.y,sou.qGai_flow)
  connect(eas.qGai_flow,mul.y)
  connect(nor.qGai_flow,mul.y)
  connect(mul.y,wes.qGai_flow)
end RefBldgSmallOffice;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone;
model TwoIdenticalZones
  "Validation model with two identical zones"
  extends Modelica.Icons.Example;
  inner Building building(
    idfName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Validation/TwoIdenticalZones/TwoIdenticalZones.idf"),
    epwName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw"),
    weaName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos"))
    "Building level declarations"
  Zone zon1(
    zoneName="Thermal Zone 1")
    "Thermal zone 1 (core zone of the office building with 5 zones)"
  Zone zon2(
    zoneName="Thermal Zone 2")
    "Thermal zone 2 (core zone of the office building with 5 zones)"
  // Models for cross validation
  Modelica.Blocks.Sources.CombiTimeTable datRea(
    tableOnFile=true,
    fileName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Validation/TwoIdenticalZones/TwoIdenticalZones.dat"),
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    tableName="EnergyPlus",
    columns=2:5,
    y(each unit="K",
      each displayUnit="degC"),
    extrapolation=Modelica.Blocks.Types.Extrapolation.HoldLastPoint)
    "Data reader with results from EnergyPlus"
  Controls.OBC.UnitConversions.From_degC TAirEnePlu
    "Room air temperature computed by EnergyPlus"
  Controls.OBC.CDL.Reals.MultiplyByParameter relHumEnePlu(k=0.01)
    "Relative humidity in the room computed by EnergyPlus"

  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable inf1(
    name="Zone Infiltration Current Density Volume Flow Rate",
    key="Thermal Zone 1")

  model Zone
    "Model of a thermal zone"
    extends Modelica.Blocks.Icons.Block;
    package Medium=Buildings.Media.Air
      "Medium model";
    parameter String zoneName=""
      "Name of the thermal zone";
    parameter Modelica.Units.SI.MassFlowRate mOut_flow=0.3/3600*zon.V*Buildings.Media.Air.dStp
      "Outside air mass flow rate with 0.3 ACH";
    Modelica.Blocks.Sources.Constant qConGai_flow(
      k=0)
      "Convective heat gain"
    Modelica.Blocks.Sources.Constant qRadGai_flow(
      k=0)
      "Radiative heat gain"
    Modelica.Blocks.Routing.Multiplex3 multiplex3_1
      "Multiplex to combine signals into a vector"
    Buildings.ThermalZones.EnergyPlus_9_6_0.ThermalZone zon(
      redeclare package Medium=Medium,
      zoneName=zoneName,
      nPorts=3)
      "Thermal zone (core zone of the office building with 5 zones)"
    Fluid.FixedResistances.PressureDrop duc(
      redeclare package Medium=Medium,
      allowFlowReversal=false,
      linearized=true,
      from_dp=false,
      dp_nominal=100,
      m_flow_nominal=47*6/3600*1.2)
      "Duct resistance (to decouple room and outside pressure)"
    Fluid.Sources.MassFlowSource_WeatherData bou(
      redeclare package Medium=Medium,
      m_flow=mOut_flow,
      nPorts=1)
      "Mass flow rate boundary condition"
    Fluid.Sources.Boundary_pT freshAir(
      redeclare package Medium=Medium,
      nPorts=1)
      "Pressure boundary condition"
    Modelica.Blocks.Sources.Constant qLatGai_flow(
      k=0)
      "Latent heat gain"
    Fluid.Sensors.RelativeHumidity senRelHum(
      redeclare package Medium=Medium,
      warnAboutOnePortConnection=false)
      "Relative humidity in the room as computed by Modelica"
    Modelica.Blocks.Interfaces.RealOutput TAir(
      final unit="K",
      displayUnit="degC")
      "Air temperature of the zone"
    Modelica.Blocks.Interfaces.RealOutput TRad(
      final unit="K",
      displayUnit="degC")
      "Radiative temperature of the zone"
    Modelica.Blocks.Interfaces.RealOutput phi(
      final unit="1")
      "Relative humidity of zone air"
    BoundaryConditions.WeatherData.Bus weaBus
      "Bus with weather data"

  equation
    connect(qRadGai_flow.y,multiplex3_1.u1[1])
    connect(qConGai_flow.y,multiplex3_1.u2[1])
    connect(zon.qGai_flow,multiplex3_1.y)
    connect(multiplex3_1.u3[1],qLatGai_flow.y)
    connect(freshAir.ports[1],duc.port_b)
    connect(zon.TAir,TAir)
    connect(zon.TRad,TRad)
    connect(senRelHum.phi,phi)
    connect(duc.port_a,zon.ports[1])
    connect(bou.ports[1],zon.ports[2])
    connect(senRelHum.port,zon.ports[3])
    connect(bou.weaBus,weaBus)
  end Zone;
equation
  connect(TAirEnePlu.u,datRea.y[3])
  connect(relHumEnePlu.u,datRea.y[4])
  connect(building.weaBus,zon1.weaBus)
  connect(building.weaBus,zon2.weaBus)
end TwoIdenticalZones;


Validation model for zone capacitance multiplier in Spawn. This validation case simulates two instances of

Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned.
In the instance mulCap, the case is modified by adding
the following snippet to the idf file:

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone;
model ZoneCapacitanceMultiplier
  "Validation model for zone capacitance multiplier in Spawn"
  extends Modelica.Icons.Example;
  Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned defCap
    "Default capacitance"
  Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned mulCap(
    building(
      idfName=Modelica.Utilities.Files.loadResource(
        "modelica://Buildings/Resources/Data/ThermalZones/EnergyPlus_9_6_0/Examples/SingleFamilyHouse_TwoSpeed_ZoneAirBalance/SingleFamilyHouse_TwoSpeed_ZoneAirBalance_zoneCapacitanceMultiplier.idf")))
        "Capacitance with a multiplier of 10"
end ZoneCapacitanceMultiplier;


This example tests whether the zone mean air temperature is initialized correctly in EnergyPlus. Simple test case that verifies whether the zone mean air temperature is
initialized correctly by EnergyPlus.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ThermalZone;
model ZoneTemperatureInitialization
  "This example tests whether the zone mean air temperature is initialized correctly in EnergyPlus"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned(
    zon(
      T_start=303.15));
  Buildings.ThermalZones.EnergyPlus_9_6_0.OutputVariable TRad(
    key="LIVING ZONE",
    name="Zone Mean Radiant Temperature",
    y(final unit="K"))
    "Block that reads output from EnergyPlus"
end ZoneTemperatureInitialization;


Validation model with one thermal zone with constant floor temperature. Model that uses EnergyPlus and sets the floor temperature to a constant value.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ZoneSurface;
model OneZoneConstantFloorTemperature
  "Validation model with one thermal zone with constant floor temperature"
  extends Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned;
  Buildings.ThermalZones.EnergyPlus_9_6_0.ZoneSurface flo(
    surfaceName="Living:Floor")
    "Floor surface of living room"
  Controls.OBC.CDL.Reals.Sources.Constant TFlo(
    k(final unit="K",
      displayUnit="degC")=298.15)
    "Floor temperature"

equation
  connect(TFlo.y,flo.T)
end OneZoneConstantFloorTemperature;


Validation model with one thermal zone with controlled floor temperature. Model that uses EnergyPlus and controls the floor temperature to a track a heating and cooling set point.

within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation.ZoneSurface;
model OneZoneControlledFloorTemperature
  "Validation model with one thermal zone with controlled floor temperature"
  extends
    Buildings.ThermalZones.EnergyPlus_9_6_0.Examples.SingleFamilyHouse.Unconditioned;
  Buildings.ThermalZones.EnergyPlus_9_6_0.ZoneSurface flo(
    surfaceName="Living:Floor")
    "Floor surface of living room"
  Controls.OBC.CDL.Reals.Sources.Constant TSetRooHea(
    k(final unit="K",
      displayUnit="degC")=293.15,
    y(final unit="K",
      displayUnit="degC"))
    "Room temperture set point for heating"
  Controls.OBC.CDL.Reals.PID conHea(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    k=0.25,
    Ti(
      displayUnit="min")=1800)
    "Controller for heating"
  Controls.OBC.CDL.Reals.Sources.Constant TSetRooCoo(
    k(final unit="K",
      displayUnit="degC")=297.15,
    y(final unit="K",
      displayUnit="degC"))
    "Room temperture set point for cooling"
  Controls.OBC.CDL.Reals.PID conCoo(
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    k=0.25,
    Ti(
      displayUnit="min")=1800,
    reverseActing=false)
    "Controller for cooling"
  Controls.OBC.CDL.Reals.Add dTSetFlo
    "Change in floor temperature compared to room air temperature"
  Controls.OBC.CDL.Reals.Add TFlo(
    y(final unit="K",
      displayUnit="degC"))
    "Floor temperature"
  Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    final k=-5) "Gain factor"
  Controls.OBC.CDL.Reals.MultiplyByParameter gai1(
    final k=5) "Gain factor"

equation
  connect(conHea.u_s,TSetRooHea.y)
  connect(zon.TAir,conHea.u_m)
  connect(TSetRooCoo.y,conCoo.u_s)
  connect(conCoo.u_m,zon.TAir)
  connect(zon.TAir,TFlo.u2)
  connect(dTSetFlo.y,TFlo.u1)
  connect(TFlo.y,flo.T)
  connect(conCoo.y, gai.u)
  connect(conHea.y, gai1.u)
  connect(gai1.y, dTSetFlo.u2)
  connect(gai.y, dTSetFlo.u1)
end OneZoneControlledFloorTemperature;


within Buildings.ThermalZones.EnergyPlus_9_6_0.Validation;
package ZoneSurface "Collection of validation models for EnergyPlus schedules"
  extends Modelica.Icons.Package;
end ZoneSurface;


Reduced order models based on ISO 13790

within Buildings.ThermalZones;
package ISO13790 "Reduced order models based on ISO 13790"
  extends Modelica.Icons.Package;
end ISO13790;


Mass node heat flow. This model calculates the heat gains injected to the mass node. More information
can be found in the documentation of
Buildings.ThermalZones.ISO13790.Zone5R1C.Zone

within Buildings.ThermalZones.ISO13790.BaseClasses;
model GainMass "Mass node heat flow"
  Modelica.Units.SI.Area AMas "Effective mass area (see Table 12 in standard)";
  parameter Modelica.Units.SI.Area ATot "Total area of building's surfaces facing the thermal zone";
  parameter Real facMas "Effective mass area factor";
  parameter Modelica.Units.SI.Area AFlo "Floor area";
  Modelica.Blocks.Interfaces.RealInput intSenGai(final unit="W") "Internal sensible heat gains"
  Modelica.Blocks.Interfaces.RealInput solGai(final unit="W") "Solar gains"
  Modelica.Blocks.Interfaces.RealOutput masGai(final unit="W") "Heat gain to mass node"

equation
  AMas  = facMas*AFlo;
  masGai=((AMas/ATot)*(0.5*intSenGai + solGai));
end GainMass;


Surface node heat flow. This model calculates the heat gains injected to the surface node. More information
can be found in the documentation of
Buildings.ThermalZones.ISO13790.Zone5R1C.Zone

within Buildings.ThermalZones.ISO13790.BaseClasses;
model GainSurface "Surface node heat flow"
  Modelica.Units.SI.Area AMas "Effective mass area (see Table 12 in standard)";
  parameter Modelica.Units.SI.Area ATot "Total area of building's surfaces facing the thermal zone";
  parameter Modelica.Units.SI.ThermalConductance HWinGai "Thermal conductance through windows";
  parameter Real facMas "Effective mass area factor";
  parameter Modelica.Units.SI.Area AFlo "Floor area";
  Modelica.Blocks.Interfaces.RealInput intSenGai(final unit="W") "Internal sensible heat gains"
  Modelica.Blocks.Interfaces.RealInput solGai(final unit="W") "Solar gains"
  Modelica.Blocks.Interfaces.RealOutput surGai(final unit="W") "Heat gain to surface node"

equation
  AMas  = facMas*AFlo;
  surGai= (1 - AMas/ATot - HWinGai/(9.1*ATot))*(0.5*intSenGai + solGai);
end GainSurface;


Area of windows. This model calculates the heat flow by solar gains through each glazed element <i>k</i>. The heat flow is given by

within Buildings.ThermalZones.ISO13790.BaseClasses;
model GlazedElements
  parameter Integer n;
  parameter Real AWin[:] "Area of windows";
  parameter Real surTil[:] "Tilt angle of surfaces";
  parameter Real surAzi[:] "Azimuth angle of surfaces";
  parameter Real gFac "Energy transmittance of glazings";
  parameter Real winFra "Frame fraction of windows";
  parameter Real shaRedFac(
    final min=0,
    final unit="1")= 0.9 "Shading reduction factor";

  Buildings.BoundaryConditions.WeatherData.Bus weaBus
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[n](
  final til=surTil,
  final azi=surAzi)
    "Direct solar irradiation on surface"
  Modelica.Blocks.Math.Gain solRad[n](final k=AWin*gFac*shaRedFac*(1 - winFra))
    "Solar radiation"
  Modelica.Blocks.Interfaces.RealOutput solRadWin
    "Solar radiation through windows"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil[n](
  final til=surTil,
  final azi=surAzi)
    "Diffuse solar irradiation on surface"
protected
  Modelica.Blocks.Math.Add irr[n]
    "Total of direct and diffuse radiation on surface"
  Modelica.Blocks.Math.MultiSum multiSum(final nu=n) "Sum of all orientations"

equation
  for i in 1:n loop
  connect(weaBus,HDifTil[i].weaBus)
  end for;

  for i in 1:n loop
  connect(weaBus,HDirTil[i].weaBus)
  end for;
  connect(solRad.y, multiSum.u)
  connect(multiSum.y, solRadWin)
  connect(HDirTil.H,irr. u1)
  connect(HDifTil.H,irr. u2)

  connect(irr.y, solRad.u)
end GlazedElements;


Area of external walls. This model calculates the heat flow by solar gains through each opaque building element <i>k</i>. The heat flow is given by

within Buildings.ThermalZones.ISO13790.BaseClasses;
model OpaqueElements
  parameter Integer n;
  parameter Real AWal[:] "Area of external walls";
  parameter Real ARoo "Area of roof";
  parameter Real UWal "U-value of external walls";
  parameter Real URoo "U-value of roof";
  parameter Real surTil[:] "Tilt angle of surfaces";
  parameter Real surAzi[:] "Azimuth angle of surfaces";
  parameter Real eps=0.9 "Emissivity of external surface";
  parameter Real alp=0.6 "Absorption coefficient";
  parameter Real surRes=0.04 "External surface heat resistance";

  Buildings.BoundaryConditions.WeatherData.Bus weaBus
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[n](
  final til=surTil,
  final azi=surAzi)
  Modelica.Blocks.Math.Gain solRadOpa[n](final k=AWal*alp*UWal*surRes)
    "Solar radiation on vertical opaque surfaces"
  Modelica.Blocks.Interfaces.RealOutput y "Solar radiation through windows"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil [n](
  final til=surTil,
  final azi=surAzi)
  Modelica.Blocks.Math.Add irrOpa[n]
    "Total of direct and diffuse radiation on surface"
  Modelica.Blocks.Math.Add addOpa[n](each k2=-1)
    "Total of direct and diffuse radiation on vertical surfaces"
  Modelica.Blocks.Math.Gain theRadOpa[n](each k=5*eps*11*0.5)
    "Extra thermal radiation through walls"
  Modelica.Blocks.Math.Add irrRoo
    "Total of direct and diffuse radiation on the south facade"
  Modelica.Blocks.Math.Gain solRadRoo(final k=ARoo*alp*URoo*surRes)
    "Solar radiation on roof"
  Modelica.Blocks.Math.Gain theRadRoo(final k=5*eps*11*1)
    "Extra thermal radiation through roof"
  Modelica.Blocks.Math.Add addRoo(k2=-1)
    "Total of direct and diffuse radiation on the roof"
  Modelica.Blocks.Math.MultiSum multiSum(nu=n)
  Modelica.Blocks.Math.Add addTot
    "Total of direct and diffuse radiation on the south facade"
protected
  Modelica.Blocks.Sources.RealExpression facOpa[n](y=UWal*AWal*surRes) "factor"
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTilRoo(til=0, azi=
       0)
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTilRof(til=0, azi=0)
protected
  Modelica.Blocks.Sources.RealExpression facRoo(y=URoo*ARoo*surRes) "factor"
equation
  for i in 1:n loop
  connect(weaBus,HDifTil[i].weaBus)
  end for;

  for i in 1:n loop
  connect(weaBus,HDirTil[i].weaBus)
  end for;
  connect(HDirTil.H, irrOpa.u1)
  connect(HDifTil.H, irrOpa.u2)

  connect(irrOpa.y, solRadOpa.u)
  connect(HDirTilRoo.H, irrRoo.u1)
  connect(HDifTilRof.H, irrRoo.u2)
  connect(HDirTilRoo.weaBus, weaBus)
  connect(HDifTilRof.weaBus, weaBus)
  connect(irrRoo.y, solRadRoo.u)
  connect(facRoo.y, theRadRoo.u)
  connect(addOpa.y, multiSum.u)
  connect(solRadOpa.y, addOpa.u1)
  connect(theRadRoo.y, addRoo.u2)
  connect(solRadRoo.y, addRoo.u1)
  connect(addTot.y, y)
  connect(addRoo.y, addTot.u2)
  connect(multiSum.y, addTot.u1)
  connect(facOpa.y, theRadOpa.u)
  connect(theRadOpa.y, addOpa.u2)
end OpaqueElements;


within Buildings.ThermalZones.ISO13790;
package BaseClasses "Package with base classes for Buildings.Fluid"
extends Modelica.Icons.BasesPackage;
end BaseClasses;


within Buildings.ThermalZones.ISO13790;
package Data "Package with pre-defined building thermal mass"
extends Modelica.Icons.MaterialPropertiesPackage;
end Data;


Illustrates the use of the 5R1C thermal zone in free-floating conditions. This model illustrates the use of
Buildings.ThermalZones.ISO13790.Zone5R1C.Zone in a free-floating case
(i.e. no heating or cooling)

within Buildings.ThermalZones.ISO13790.Examples;
model FreeFloating "Illustrates the use of the 5R1C thermal zone in free-floating conditions"
  extends Modelica.Icons.Example;

  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"
  Zone5R1C.Zone zon5R1C(
    airRat=0.5,
    AWin={0,0,3,0},
    UWin=1.8,
    AWal={12,12,9,12},
    ARoo=16,
    UWal=1.3,
    URoo=1.3,
    UFlo=1,
    AFlo=16,
    VRoo=16*3,
    redeclare replaceable Buildings.ThermalZones.ISO13790.Data.Light buiMas,
    nOrientations=4,
    surTil={1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949},
    surAzi={3.1415926535898,-1.5707963267949,0,1.5707963267949},
    gFac=0.5) "Thermal zone"
  Modelica.Blocks.Sources.Constant intGains(k=10) "internal heat gains in Watt"
equation
  connect(zon5R1C.weaBus, weaDat.weaBus)
  connect(zon5R1C.intSenGai, intGains.y)
end FreeFloating;


within Buildings.ThermalZones.ISO13790.Examples;
model FreeFloatingHVAC "Illustrates the use of the 5R1C HVAC thermal zone in free-floating conditions"
  extends Modelica.Icons.Example;
  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"
  Zone5R1C.ZoneHVAC zonHVAC(
    airRat=0.5,
    AWin={0,0,3,0},
    UWin=1.8,
    AWal={12,12,9,12},
    ARoo=16,
    UWal=1.3,
    URoo=1.3,
    UFlo=1,
    AFlo=16,
    VRoo=16*3,
    nOrientations=4,
    surTil={1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949},
    surAzi={3.1415926535898,-1.5707963267949,0,1.5707963267949},
    gFac=0.5,
    redeclare package Medium = Buildings.Media.Air,
    redeclare Buildings.ThermalZones.ISO13790.Data.Light buiMas) "Thermal zone"
  Modelica.Blocks.Sources.Constant intGains(k=10) "Internal heat gains"
  Modelica.Blocks.Sources.Constant latGains(k=0) "Latent gains"
equation
  connect(zonHVAC.weaBus, weaDat.weaBus)
  connect(latGains.y, zonHVAC.intLatGai)
  connect(intGains.y, zonHVAC.intSenGai)
end FreeFloatingHVAC;


Illustrates the use of the 5R1C thermal zone with heating and cooling. This model illustrates the use of
Buildings.ThermalZones.ISO13790.Zone5R1C.Zone with heating and cooling.

within Buildings.ThermalZones.ISO13790.Examples;
model HeatingCooling "Illustrates the use of the 5R1C thermal zone with heating and cooling"
  extends FreeFloating(zon5R1C(
      airRat=0.5,
      AWin={0,0,3,0},
      UWin=1.8,
      AWal={12,12,9,12},
      ARoo=16,
      UWal=1.3,
      URoo=1.3,
      AFlo=16,
      VRoo=16*3,
      redeclare Buildings.ThermalZones.ISO13790.Data.Light buiMas,
      gFac=0.5) "Thermal zone");
  Modelica.Blocks.Math.Sum sumHeaCoo(nin=2)
    "Sum of heating and cooling heat flow rate"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow preHeaCoo
    "Prescribed heat flow for heating and cooling"
  Modelica.Blocks.Math.Gain gaiHea(k=1E6) "Gain for heating"
  Buildings.Controls.Continuous.LimPID conHeaPID(
    Ti=300,
    k=0.1,
    reverseActing=true,
    strict=true) "Controller for heating"
  Modelica.Blocks.Sources.Constant TSetHea(k=273.15 + 20)
    "Set-point for heating"
  Modelica.Blocks.Sources.Constant TSetCoo(k=273.15 + 27)
    "Set-point for cooling"
  Modelica.Blocks.Routing.Multiplex2 multiplex2
  Modelica.Blocks.Math.Gain gaiCoo(k=-1E6) "Gain for cooling"
  Buildings.Controls.Continuous.LimPID conCooPID(
    Ti=300,
    k=0.1,
    reverseActing=false,
    strict=true) "Controller for cooling"
equation
  connect(sumHeaCoo.y, preHeaCoo.Q_flow)
  connect(conHeaPID.y, gaiHea.u)
  connect(TSetHea.y, conHeaPID.u_s)
  connect(multiplex2.y,sumHeaCoo. u)
  connect(conCooPID.u_s, TSetCoo.y)
  connect(conCooPID.y, gaiCoo.u)
  connect(conHeaPID.y, gaiHea.u)
  connect(gaiHea.y, multiplex2.u1[1])
  connect(gaiCoo.y, multiplex2.u2[1])
  connect(gaiCoo.u, conCooPID.y)
  connect(preHeaCoo.port, zon5R1C.heaPorAir)
  connect(zon5R1C.TAir, conCooPID.u_m)
  connect(zon5R1C.TAir, conHeaPID.u_m)
end HeatingCooling;


within Buildings.ThermalZones.ISO13790.Examples;
model HeatingCoolingHVAC "Illustrates the use of the 5R1C HVAC thermal zone connected to a ventilation system"
  extends FreeFloatingHVAC(zonHVAC(nPorts=2));

  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow preHeaCoo
    "Prescribed heat flow for heating and cooling"
  Modelica.Blocks.Math.Gain gaiHea(k=1E6) "Gain for heating"
  Controls.Continuous.LimPID conHeaPID(
    Ti=300,
    k=0.1,
    reverseActing=true,
    strict=true) "Controller for heating"
  Modelica.Blocks.Sources.Constant TSetHea(k=273.15 + 20) "Set-point for heating"
  Fluid.Sources.MassFlowSource_T sou(
    redeclare package Medium = Buildings.Media.Air,
    use_m_flow_in=true,
    T=280.15,
    nPorts=1) "source of air"
  Modelica.Blocks.Sources.Constant TSetCoo(k=273.15 + 27)
    "Set-point for cooling"
  Controls.Continuous.LimPID conCooPID(
    Ti=300,
    k=0.1,
    yMax=0.07,
    reverseActing=false,
    strict=true) "Controller for cooling"
  Modelica.Blocks.Math.Gain gaiCoo(k=1) "Gain for cooling"
  Fluid.Sources.Boundary_pT sin(
    redeclare package Medium = Buildings.Media.Air,
    nPorts=1) "sink"
equation
  connect(conHeaPID.y,gaiHea. u)
  connect(TSetHea.y,conHeaPID. u_s)
  connect(conHeaPID.y,gaiHea. u)
  connect(gaiHea.y, preHeaCoo.Q_flow)
  connect(conCooPID.u_s,TSetCoo. y)
  connect(gaiCoo.u,conCooPID. y)
  connect(sin.ports[1], zonHVAC.ports[1])
  connect(preHeaCoo.port, zonHVAC.heaPorAir)
  connect(sou.ports[1], zonHVAC.ports[2])
  connect(sou.m_flow_in, gaiCoo.y)
  connect(zonHVAC.TAir, conCooPID.u_m)
  connect(zonHVAC.TAir, conHeaPID.u_m)
end HeatingCoolingHVAC;


within Buildings.ThermalZones.ISO13790;
package Examples "Collection of models that illustrate model use and test models"
extends Modelica.Icons.ExamplesPackage;
end Examples;


Collection of validation models

within Buildings.ThermalZones.ISO13790;
package Validation "Collection of validation models"
extends Modelica.Icons.ExamplesPackage;
end Validation;


Case 600FF, but with dual-setpoint for heating and cooling. This model is used for the basic test case 600 of the BESTEST validation suite.
Case 600 is a light-weight building with room temperature control set to 20°C
for heating and 27°C for cooling. The room has no shade and a window that faces south.

within Buildings.ThermalZones.ISO13790.Validation.BESTEST;
model Case600 "Case 600FF, but with dual-setpoint for heating and cooling"
  extends Modelica.Icons.Example;
  Modelica.Blocks.Math.Sum sumHeaCoo(nin=2)
    "Sum of heating and cooling heat flow rate"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow preHeaCoo
    "Prescribed heat flow for heating and cooling"
  Modelica.Blocks.Math.Gain gaiHea(k=1E6) "Gain for heating"
  Buildings.Controls.Continuous.LimPID conHeaPID(
    Ti=300,
    k=0.1,
    reverseActing=true,
    strict=true) "Controller for heating"
  Modelica.Blocks.Sources.Constant TSetHea(k=273.15 + 20) "Set-point for heating"
  Modelica.Blocks.Sources.Constant TSetCoo(k=273.15 + 27) "Set-point for cooling"
  Modelica.Blocks.Routing.Multiplex2 multiplex2
  Modelica.Blocks.Math.Gain gaiCoo(k=-1E6) "Gain for cooling"
  Buildings.Controls.Continuous.LimPID conCooPID(
    Ti=300,
    k=0.1,
    reverseActing=false,
    strict=true) "Controller for cooling"
  Modelica.Blocks.Continuous.Integrator ECoo(
    k=1,
    initType=Modelica.Blocks.Types.Init.InitialState,
    y_start=0,
    u(unit="W"),
    y(unit="J")) "Cooling energy in Joules"
  Modelica.Blocks.Continuous.Integrator EHea(
    k=1,
    initType=Modelica.Blocks.Types.Init.InitialState,
    y_start=0,
    u(unit="W"),
    y(unit="J")) "Heating energy in Joules"
  Modelica.Blocks.Sources.CombiTimeTable daiComBESTEST(table=[0,0,0,0,0,0,0,0;
        259200,0,0,0,0,0,0,0; 262800,3250,3800,3930,4130,3930,3770,4230; 266400,
        3410,3910,4040,4260,4040,3870,4350; 270000,3390,3870,4010,4230,4000,
        3900,4320; 273600,3380,3920,4040,4220,4000,3890,4310; 277200,3420,3940,
        4050,4220,4000,3920,4300; 280800,3430,3930,4040,4220,4000,3930,4310;
        284400,3420,3940,4050,4220,4000,3930,4310; 288000,3340,3700,3860,4090,
        3900,3750,4170; 291600,2770,2680,2560,2900,2710,2420,2910; 295200,1500,
        1380,840,1280,1150,800,1470; 298800,150,0,0,0,0,-30,0; 302400,-770,-1230,
        -1550,-1070,-1040,-1440,-420; 306000,-2660,-2490,-2850,-2590,-2500,-2720,
        -2360; 309600,-3580,-2960,-3400,-3230,-3090,-3160,-2760; 313200,-3530,-2630,
        -3120,-2830,-2640,-2840,-2430; 316800,-2440,-1350,-1820,-1550,-1350,-1720,
        -1140; 320400,-360,0,0,0,0,0,0; 324000,240,950,780,800,880,770,1290;
        327600,1530,2380,2230,2340,2330,2300,2450; 331200,2320,2870,2930,2990,
        2950,2970,2940; 334800,2640,3210,3320,3370,3310,3280,3410; 338400,2900,
        3280,3490,3530,3350,3460,3590; 342000,3020,3330,3510,3610,3490,3500,
        3700; 345600,3010,3390,3560,3660,3530,3470,3770; 345600,0,0,0,0,0,0,0;
        3153600,0,0,0,0,0,0,0]) "Daily comparison BESTEST"
  Zone5R1C.Zone zon5R1C(
    airRat=0.5,
    AWin={0,0,12,0},
    UWin=2.984,
    AWal={21.6,16.2,9.6,16.2},
    ARoo=48,
    UWal=0.56,
    URoo=0.33,
    UFlo=1,
    b=0,
    AFlo=48,
    VRoo=129.6,
    hInt=2.74,
    redeclare replaceable Buildings.ThermalZones.ISO13790.Validation.BESTEST.Data.Case600Mass buiMas,
    nOrientations=4,
    surTil={1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949},
    surAzi={3.1415926535898,-1.5707963267949,0,1.5707963267949},
    gFac=0.789)
  Modelica.Blocks.Sources.Constant intGai(k=200) "Internal heat gains"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam=
    Modelica.Utilities.Files.loadResource(
        "modelica://Buildings/Resources/weatherdata/DRYCOLD.mos"))
    "Weather data"
  Buildings.ThermalZones.ISO13790.Validation.BESTEST.Data.Case600Results annComBESTEST "Annual comparison BESTEST "
equation
  connect(sumHeaCoo.y,preHeaCoo. Q_flow)
  connect(conHeaPID.y,gaiHea. u)
  connect(TSetHea.y,conHeaPID. u_s)
  connect(multiplex2.y,sumHeaCoo. u)
  connect(conCooPID.u_s,TSetCoo. y)
  connect(conCooPID.y,gaiCoo. u)
  connect(gaiHea.y,multiplex2. u1[1])
  connect(gaiCoo.y,multiplex2. u2[1])
  connect(gaiCoo.u,conCooPID. y)
  connect(EHea.u, gaiHea.y)
  connect(ECoo.u, gaiCoo.y)

  connect(preHeaCoo.port, zon5R1C.heaPorAir)
  connect(intGai.y, zon5R1C.intSenGai)
  connect(weaDat.weaBus, zon5R1C.weaBus)
  connect(zon5R1C.TAir, conCooPID.u_m)
  connect(zon5R1C.TAir, conHeaPID.u_m)
end Case600;


Basic test with light-weight construction and free floating temperature. This model is used for the test case 600FF of the BESTEST validation suite.
Case 600FF is a light-weight building.
The room temperature is free floating.


modelica://Buildings/Resources/Scripts/Dymola/ThermalZones/ISO13790/Validation/BESTEST/Case900.mos. This model is used for the basic test case 900 of the BESTEST validation suite.
Case 900 is a heavy-weight building with room temperature control set to 20°C
for heating and 27°C for cooling. The room has no shade and a window that faces south.


Test with heavy-weight construction and free floating temperature. This model is used for the test case 900FF of the BESTEST validation suite.
Case 900FF is a heavy-weight building.
The room temperature is free floating.


within Buildings.ThermalZones.ISO13790.Validation;
package BESTEST "Package with models for the BESTEST validation"
extends Modelica.Icons.ExamplesPackage;
end BESTEST;


Data records for BESTEST validation

within Buildings.ThermalZones.ISO13790.Validation.BESTEST;
package Data "Data records for BESTEST validation"
  extends Modelica.Icons.MaterialPropertiesPackage;
end Data;


within Buildings.ThermalZones.ISO13790;
package Zone5R1C "Package with reduced order thermal zones based on ISO 13790"
  extends Modelica.Icons.VariantsPackage;
end Zone5R1C;