Thermal zone based on 5R1C network. This is a lumped-capacity simplified building model based  on the 5R1C
network presented in the ISO 13790:2008 Standard. The simplified 5R1C model uses
five thermal resistances and one thermal capacity to reproduce the
transient thermal behaviour of buildings. The thermal zone is modeled with three
temperature nodes, the indoor air temperature TAir, the envelope internal
surface temperature TSur and the zone's mass temperature TMas
(the heat port is not shown in the figure), and two boundary
condition nodes, supply air temperature TSup and the external air temperature
TExt. The five resistances are related to heat transfer by ventilation HVen,
windows HWin, opaque components (split between HTra and HMas) and heat
transfer between the internal surfaces of walls and the air temperature HThe.
The thermal capacity Cm includes the thermal capacity of the entire zone. The heating and/or
cooling demand is found by calculating the heating and/or cooling power ΦHC that
needs to be supplied to, or extracted from, the internal air node to maintain a
certain set-point. Internal, Φint , and solar, Φsol, heat gains are input values,
which are split in three components.

within Buildings.ThermalZones.ISO13790.Zone5R1C;
model Zone "Thermal zone based on 5R1C network"
  parameter Real airRat(unit="1/h") "Air change rate"
  parameter Modelica.Units.SI.Area AWin[nOrientations] "Area of windows"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer UWin "U-value of windows"
  parameter Modelica.Units.SI.Area AWal[nOrientations] "Area of external walls (only opaque part)"
  parameter Modelica.Units.SI.Area ARoo "Area of roof"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer UWal "U-value of external walls"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer URoo "U-value of roof"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer UFlo "U-value of floor"
  parameter Real b=0.5 "Adjustment factor for ground heat transfer"
  parameter Modelica.Units.SI.Area AFlo "Net conditioned floor area";
  parameter Modelica.Units.SI.Volume VRoo "Volume of room";
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hInt=3.45
    "Heat transfer coefficient between surface and air nodes";
  replaceable parameter ISO13790.Data.Generic buiMas "Building mass"
  parameter Integer nOrientations(min=1) = 4 "Number of orientations for vertical walls";
  parameter Modelica.Units.SI.Angle surTil[nOrientations] "Tilt angle of surfaces";
  parameter Modelica.Units.SI.Angle surAzi[nOrientations] "Azimuth angle of surfaces";
  parameter Real winFra(min=0, max=1)=0.001 "Frame fraction of windows"
  parameter Real gFac(min=0, max=1) "Energy transmittance of glazings"

  Modelica.Blocks.Interfaces.RealInput intSenGai(final unit="W") "Internal sensible heat gains"

  Modelica.Blocks.Interfaces.RealOutput TAir(
    final unit="K",
    displayUnit="degC")
    "Room air temperature"
  Modelica.Blocks.Interfaces.RealOutput TSur(
    final unit="K",
    displayUnit="degC")
    "Average inside surface temperature"

  Buildings.BoundaryConditions.WeatherData.Bus weaBus
    "Weather data bus"

  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heaPorAir
    "Heat port to air node"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heaPorSur
    "Heat port to surface temperatures"

  Modelica.Thermal.HeatTransfer.Components.ThermalConductor HVen(
      G=airRat*VRoo*1005*1.2/3600) "Heat transfer due to ventilation"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor HTra(
      G=1/(1/(UWal*sum(AWal) + b*UFlo*AFlo + URoo*ARoo) - 1/(hSur*buiMas.facMas*AFlo)))
      "Heat transfer through opaque elements"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor HWin(
      G=UWin*sum(AWin)) "Heat transfer through glazed elements"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor HThe(G=hInt*AFlo*ratSur)
    "Coupling conductance betwee air and surface nodes"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor HMas(G=hSur*buiMas.facMas*AFlo)
    "Coupling conductance between surface and mass nodes"
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor capMas(
      C=buiMas.heaC*AFlo,
      T(displayUnit="degC",
      fixed=true,
      start=293.15)) "Zone thermal capacity"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TExt
    "External air temperature"
  Modelica.Blocks.Math.Add solGai "Total solar heat gains"
  BaseClasses.GlazedElements win(
    final n=nOrientations,
    final AWin=AWin,
    final surTil=surTil,
    final surAzi=surAzi,
    final gFac=gFac,
    final winFra=winFra) "Solar heat gains of glazed elements"
  BaseClasses.OpaqueElements opa(
    final n=nOrientations,
    final AWal=AWal,
    final ARoo=ARoo,
    final UWal=UWal,
    final URoo=URoo,
    final surTil=surTil,
    final surAzi=surAzi) "Solar heat gains of opaque elements"
  BaseClasses.GainSurface phiSur(
    ATot=AFlo*ratSur,
    facMas=buiMas.facMas,
    AFlo=AFlo,
    HWinGai=HWin.G) "Heat flow injected to surface node"
  Modelica.Blocks.Math.Gain phiAir(k=0.5) "Heat flow injected to air node"
  BaseClasses.GainMass phiMas(
    ATot=AFlo*ratSur,
    facMas=buiMas.facMas,
    AFlo=AFlo) "Heat flow injected to mass node"
  Buildings.HeatTransfer.Sources.PrescribedTemperature TVen "Supply air temperature"

protected
  parameter Real ratSur=4.5 "Ratio between the internal surfaces area and the floor area";
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hSur=9.1 "Heat transfer coefficient between mass and surface nodes";

  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor senTAir
    "Air temperature sensor"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor senTSur
    "Surface temperature sensor"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow heaAir
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow heaSur
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow heaMas
initial equation
  assert(size(AWin,1) == nOrientations, "The parameter AWin must have the same dimension of nOrientations.");
  assert(size(AWal,1) == nOrientations, "The parameter AWal must have the same dimension of nOrientations.");
  assert(size(surTil,1) == nOrientations, "The parameter surTil must have the same dimension of nOrientations.");
  assert(size(surAzi,1) == nOrientations, "The parameter surAzi must have the same dimension of nOrientations.");

equation

  connect(heaPorSur, HWin.port_b)
  connect(heaPorAir, HVen.port_b)
  connect(heaPorAir, HThe.port_b)
  connect(heaPorAir, heaAir.port)
  connect(heaSur.port, heaPorSur)
  connect(heaPorSur, HMas.port_b)
  connect(weaBus.TDryBul,TExt. T)
  connect(heaPorSur, HThe.port_a)
  connect(win.weaBus, weaBus)
  connect(opa.weaBus, weaBus)
  connect(HWin.port_a,TExt. port)
  connect(HTra.port_a, TExt.port)
  connect(heaMas.port, HTra.port_b)
  connect(capMas.port, HTra.port_b)
  connect(HMas.port_a, HTra.port_b)
  connect(TVen.port, HVen.port_a)
  connect(weaBus.TDryBul,TVen. T)
  connect(solGai.y, phiMas.solGai)
  connect(phiSur.solGai, solGai.y)
  connect(intSenGai, phiMas.intSenGai)
  connect(phiSur.intSenGai, intSenGai)
  connect(phiAir.u, intSenGai)
  connect(phiMas.masGai, heaMas.Q_flow)
  connect(phiAir.y, heaAir.Q_flow)
  connect(phiSur.surGai, heaSur.Q_flow)
  connect(win.solRadWin, solGai.u1)
  connect(opa.y, solGai.u2)
  connect(senTSur.port, heaPorSur)
  connect(senTAir.port, heaPorAir)
  connect(senTAir.T, TAir)
  connect(senTSur.T, TSur)
end Zone;


within Buildings.ThermalZones.ISO13790.Zone5R1C;
model ZoneHVAC "Thermal zone for HVAC based on 5R1C network"
  extends Zone(capMas(C=buiMas.heaC*AFlo - VRoo*1.2*1014));
  replaceable package Medium = Modelica.Media.Interfaces.PartialMedium
  parameter Integer nPorts=0 "Number of fluid ports"
  Modelica.Blocks.Interfaces.RealInput intLatGai(final unit="W") "Internal latent heat gains"
  Modelica.Blocks.Math.Gain mWat_flow(final k=1/h_fg) "Water flow rate due to latent heat gain"
  Fluid.MixingVolumes.MixingVolumeMoistAir vol(
    redeclare final package Medium = Medium,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    m_flow_nominal=VRoo*Buildings.Media.Air.dStp*3/3600,
    V=VRoo,
    nPorts=nPorts) "Air volume"
  Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b ports[nPorts](
      redeclare each final package Medium = Medium)
    "Fluid port for adding HVAC system, air infiltration and exfiltration"
protected
  constant Modelica.Units.SI.SpecificEnergy h_fg=
      Buildings.Media.Air.enthalpyOfCondensingGas(273.15 + 37) "Latent heat of water vapor";

equation
  connect(mWat_flow.y, vol.mWat_flow)
  connect(heaPorAir, vol.heatPort)
  connect(vol.ports, ports)
  connect(intLatGai, mWat_flow.u)
end ZoneHVAC;


Reduced order models based on VDI 6007

within Buildings.ThermalZones;
package ReducedOrder "Reduced order models based on VDI 6007"
  extends Modelica.Icons.Package;
end ReducedOrder;


within Buildings.ThermalZones.ReducedOrder;
package EquivalentAirTemperature "Package with models for equivalent air temperatures according to VDI 6007
  Part 1"
extends Modelica.Icons.VariantsPackage;

package UsersGuide "User's Guide"
  extends Modelica.Icons.Information;
end UsersGuide;
end EquivalentAirTemperature;


Equivalent air temperature as defined in VDI 6007 Part 1. VDI6007 is a strict implementation of the calculations defined
  in VDI 6007 Part 1. The sum of all weightfactors should be one.

within Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature;
model VDI6007 "Equivalent air temperature as defined in VDI 6007 Part 1"
  extends BaseClasses.PartialVDI6007;

initial equation
  assert(noEvent(abs(sum(wfWall) + sum(wfWin) + wfGro - 1) < 0.1),
  "The sum of the weighting factors (walls,windows and ground)  is
  <0.9 or >1.1. Normally, the sum should be 1.", level=AssertionLevel.warning);

equation
  delTEqLWWin=delTEqLW;
  TEqAir = TEqWall*wfWall + TEqWin*wfWin +  TGroSouSel.y*wfGro;
end VDI6007;


Equivalent air temperature as defined in VDI 6007 Part 1 with modifications. This model is a variant of the calculations defined in
  VDI 6007 Part 1. It adds a second equivalent air temperature for windows in
  case heat transfer through windows and exterior walls is handled separately in
  the Reduced Order Model. The sum of all weightfactors for windows should be
  one as well as the sum for all wall elements.

within Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature;
model VDI6007WithWindow
  "Equivalent air temperature as defined in VDI 6007 Part 1 with modifications"
  extends BaseClasses.PartialVDI6007;

  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hConWinOut
    "Windows' convective coefficient of heat transfer (outdoor)";

  Modelica.Blocks.Interfaces.RealOutput TEqAirWin(final unit="K")
    "Equivalent air temperature for windows (no short-wave radiation)"

initial equation
  assert(noEvent(abs(sum(wfWall) + wfGro - 1) < 0.1),
  "The sum of the weightfactors (walls and ground)  is <0.9 or >1.1.
   Normally, the sum should be 1.", level=AssertionLevel.warning);
  assert(noEvent(abs(sum(wfWin) - 1) < 0.1),
  "The sum of the weightfactors (windows)  is <0.9 or >1.1.
  Normally, the sum should be 1.", level=AssertionLevel.warning);

equation
  delTEqLWWin=(TBlaSky - TDryBul)*hRad/(hRad + hConWinOut);
  TEqAir = TEqWall*wfWall +  TGroSouSel.y*wfGro;
  TEqAirWin = TEqWin*wfWin;
end VDI6007WithWindow;


within Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature;
package BaseClasses "Package with base classes for the equivalent air temperature"
  extends Modelica.Icons.BasesPackage;
end BaseClasses;


Partial model for equivalent air temperature as defined in VDI 6007 Part 1. PartialVDI6007 is a partial model for EquivalentAirTemperature
  models.

within Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature.BaseClasses;
partial model PartialVDI6007
  "Partial model for equivalent air temperature as defined in VDI 6007 Part 1"

  parameter Modelica.Units.SI.Emissivity aExt
    "Coefficient of absorption of exterior walls (outdoor)";
  parameter Integer n "Number of orientations (without ground)";
  parameter Real wfWall[n](each final unit="1") "Weight factors of the walls";
  parameter Real wfWin[n](each final unit="1") "Weight factors of the windows";
  parameter Real wfGro(unit="1")
    "Weight factor of the ground (0 if not considered)";
  parameter Modelica.Units.SI.Temperature TGro
    "Constant temperature of the ground in contact with floor plate"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hConWallOut
    "Exterior walls convective coefficient of heat transfer (outdoor)";
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hRad
    "Coefficient of heat transfer for linearized radiation";
  parameter Boolean withLongwave=true
    "Set to true to include longwave radiation exchange"
  parameter Boolean TGroundFromInput=false
    "Set to true to use TGro_in input connector instead of TGro constant"

  Modelica.Units.SI.Temperature TEqWall[n] "Equivalent wall temperature";
  Modelica.Units.SI.Temperature TEqWin[n] "Equivalent window temperature";
  Modelica.Units.SI.TemperatureDifference delTEqLW
    "Equivalent long wave temperature";
  Modelica.Units.SI.TemperatureDifference delTEqLWWin
    "Equivalent long wave temperature for windows";
  Modelica.Units.SI.TemperatureDifference delTEqSW[n]
    "Equivalent short wave temperature";

  Modelica.Blocks.Interfaces.RealInput HSol[n](
    each final quantity="RadiantEnergyFluenceRate",
    each final unit="W/m2") "Solar radiation per unit area"
  Modelica.Blocks.Interfaces.RealInput TBlaSky(
    final quantity="ThermodynamicTemperature",
    displayUnit="degC",
    final unit="K") "Black-body sky temperature"
  Modelica.Blocks.Interfaces.RealInput TDryBul(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC") "Dry bulb temperature"
  Modelica.Blocks.Interfaces.RealOutput TEqAir(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC") "Equivalent air temperature"
  Modelica.Blocks.Interfaces.RealInput sunblind[n](
    each min=0,
    each max=1,
    each final unit="1")
    "Opening factor of sunblinds for each direction (0 - open to 1 - closed)"
  Modelica.Blocks.Interfaces.RealInput TGro_in(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC") if TGroundFromInput
    "Temperature of the ground in contact with floor plate"

protected
  SourceSelector TGroSouSel(final useInput=TGroundFromInput, p=TGro)
    "Input selector for ground temperature";

initial equation
  assert(noEvent(abs(sum(wfWall) + sum(wfWin) + wfGro) > 0.1),
 "The sum of the weighting factors (walls,windows and ground) in the
   equivalent air temperature calculation is close to 0.
   If there are no walls, windows and ground at all, this might be
   irrelevant.", level=AssertionLevel.warning);

equation
  delTEqLW=(TBlaSky - TDryBul)*hRad/(hRad + hConWallOut);
  delTEqSW=HSol*aExt/(hRad + hConWallOut);
  if withLongwave then
    TEqWin=TDryBul.+delTEqLWWin*(ones(n)-sunblind);
    TEqWall=TDryBul.+delTEqLW.+delTEqSW;
  else
    TEqWin=TDryBul*ones(n);
    TEqWall=TDryBul.+delTEqSW;
  end if;

  connect(TGro_in, TGroSouSel.uCon);
end PartialVDI6007;


Block that selects as its output either a parameter value or its input. Block that produces at its output the input value uCon
or the parameter value p depending on the parameter value
useInput.

within Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature.BaseClasses;
block SourceSelector
  "Block that selects as its output either a parameter value or its input"
  extends Modelica.Blocks.Interfaces.SO;
  parameter Boolean useInput "Use input (if true) or parameter value (if false)"
  parameter Real p "Parameter value";
  Modelica.Blocks.Interfaces.RealInput uCon if useInput
    "Input signal from input connector"
equation
  if not useInput then
    y = p;
  end if;
  connect(uCon, y);
end SourceSelector;


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


within Buildings.ThermalZones.ReducedOrder.Examples;
model SimpleRoomFourElements
  "Illustrates the use of a thermal zone with four heat conduction elements"
  extends Modelica.Icons.Example;

  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    calTSky=Buildings.BoundaryConditions.Types.SkyTemperatureCalculation.HorizontalRadiation,
    computeWetBulbTemperature=false,
    filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
    "Weather data reader"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil[2](
    each outSkyCon=true,
    each outGroCon=true,
    each til=1.5707963267949,
    azi={3.1415926535898,4.7123889803847})
    "Calculates diffuse solar radiation on titled surface for both directions"
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[2](
    each til=1.5707963267949,
    azi={3.1415926535898,4.7123889803847})
    "Calculates direct solar radiation on titled surface for both directions"
  SolarGain.CorrectionGDoublePane corGDouPan(UWin=2.1, n=2)
    "Correction factor for solar transmission"
  RC.FourElements thermalZoneFourElements(
    VAir=52.5,
    hConExt=2.7,
    hConWin=2.7,
    gWin=1,
    ratioWinConRad=0.09,
    nExt=1,
    RExt={0.00331421908725},
    CExt={5259932.23},
    hRad=5,
    AInt=60.5,
    hConInt=2.12,
    nInt=1,
    RInt={0.000668895639141},
    CInt={12391363.86},
    RWin=0.01642857143,
    RExtRem=0.1265217391,
    AFloor=11.5,
    hConFloor=2.7,
    nFloor=1,
    RFloor={0.00331421908725},
    RFloorRem=0.1265217391,
    CFloor={5259932.23},
    ARoof=11.5,
    hConRoof=2.7,
    nRoof=1,
    RRoof={0.00331421908725},
    RRoofRem=0.1265217391,
    CRoof={5259932.23},
    nOrientations=2,
    AWin={7,7},
    ATransparent={7,7},
    AExt={3.5,8},
    redeclare replaceable package Medium = Modelica.Media.Air.SimpleAir,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    extWallRC(thermCapExt(each der_T(fixed=true))),
    intWallRC(thermCapInt(each der_T(fixed=true))),
    floorRC(thermCapExt(each der_T(fixed=true))),
    T_start=295.15,
    roofRC(thermCapExt(each der_T(fixed=true)))) "Thermal zone"
  EquivalentAirTemperature.VDI6007WithWindow eqAirTemp(
    wfGro=0,
    withLongwave=true,
    aExt=0.7,
    hConWallOut=20,
    hRad=5,
    hConWinOut=20,
    n=2,
    wfWall={0.3043478260869566,0.6956521739130435},
    wfWin={0.5,0.5},
    TGro=285.15) "Computes equivalent air temperature"
  Modelica.Blocks.Math.Add solRad[2]
    "Sums up solar radiation of both directions"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTem
    "Prescribed temperature for exterior walls outdoor surface temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTem1
    "Prescribed temperature for windows outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection theConWin
    "Outdoor convective heat transfer of windows"
  Modelica.Thermal.HeatTransfer.Components.Convection theConWall
    "Outdoor convective heat transfer of walls"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow perRad
    "Radiative heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow perCon
    "Convective heat flow of persons"
  Modelica.Blocks.Sources.CombiTimeTable intGai(
    table=[0,0,0,0; 3600,0,0,0; 7200,0,0,0; 10800,0,0,0; 14400,0,0,0; 18000,0,0,
        0; 21600,0,0,0; 25200,0,0,0; 25200,80,80,200; 28800,80,80,200; 32400,80,
        80,200; 36000,80,80,200; 39600,80,80,200; 43200,80,80,200; 46800,80,80,200;
        50400,80,80,200; 54000,80,80,200; 57600,80,80,200; 61200,80,80,200; 61200,
        0,0,0; 64800,0,0,0; 72000,0,0,0; 75600,0,0,0; 79200,0,0,0; 82800,0,0,0;
        86400,0,0,0],
    columns={2,3,4},
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic) "Table with profiles for persons (radiative and convective) and machines
    (convective)"
  Modelica.Blocks.Sources.Constant const[2](each k=0)
    "Sets sunblind signal to zero (open)"
  BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow macConv
    "Convective heat flow of machines"
  Modelica.Blocks.Sources.Constant hConWall(k=25*11.5)
    "Outdoor coefficient of heat transfer for walls"
  Modelica.Blocks.Sources.Constant hConWin(k=20*14)
    "Outdoor coefficient of heat transfer for windows"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTemFloor
    "Prescribed temperature for floor plate outdoor surface temperature"
  Modelica.Blocks.Sources.Constant TSoil(k=283.15)
    "Outdoor surface temperature for floor plate"
  EquivalentAirTemperature.VDI6007 eqAirTempVDI(
    aExt=0.7,
    n=1,
    wfWall={1},
    wfWin={0},
    wfGro=0,
    hConWallOut=20,
    hRad=5,
    TGro=285.15) "Computes equivalent air temperature for roof"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTemRoof
    "Prescribed temperature for roof outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection theConRoof
    "Outdoor convective heat transfer of roof"
  Modelica.Blocks.Sources.Constant hConRoof(k=25*11.5)
    "Outdoor coefficient of heat transfer for roof"
  Modelica.Blocks.Sources.Constant const1(k=0)
    "Sets sunblind signal to zero (open)"

equation
  connect(eqAirTemp.TEqAirWin, preTem1.T)
  connect(eqAirTemp.TEqAir, preTem.T)
  connect(weaDat.weaBus, weaBus)
  connect(weaBus.TDryBul, eqAirTemp.TDryBul)
  connect(intGai.y[1], perRad.Q_flow)
  connect(intGai.y[2], perCon.Q_flow)
  connect(intGai.y[3], macConv.Q_flow)
  connect(const.y, eqAirTemp.sunblind)
  connect(HDifTil.HSkyDifTil, corGDouPan.HSkyDifTil)
  connect(HDirTil.H, corGDouPan.HDirTil)
  connect(HDirTil.H,solRad. u1)
  connect(HDifTil.H,solRad. u2)
  connect(HDifTil.HGroDifTil, corGDouPan.HGroDifTil)
  connect(solRad.y, eqAirTemp.HSol)
  connect(weaDat.weaBus, HDifTil[1].weaBus)
  connect(weaDat.weaBus, HDifTil[2].weaBus)
  connect(weaDat.weaBus, HDirTil[1].weaBus)
  connect(weaDat.weaBus, HDirTil[2].weaBus)
  connect(perRad.port, thermalZoneFourElements.intGainsRad)
  connect(theConWin.solid, thermalZoneFourElements.window)
  connect(preTem1.port, theConWin.fluid)
  connect(thermalZoneFourElements.extWall, theConWall.solid)
  connect(theConWall.fluid, preTem.port)
  connect(hConWall.y, theConWall.Gc)
  connect(hConWin.y, theConWin.Gc)
  connect(weaBus.TBlaSky, eqAirTemp.TBlaSky)
  connect(macConv.port, thermalZoneFourElements.intGainsConv)
  connect(perCon.port, thermalZoneFourElements.intGainsConv)
  connect(preTemFloor.port, thermalZoneFourElements.floor)
  connect(TSoil.y, preTemFloor.T)
  connect(preTemRoof.port, theConRoof.fluid)
  connect(theConRoof.solid, thermalZoneFourElements.roof)
  connect(eqAirTempVDI.TEqAir, preTemRoof.T)
  connect(theConRoof.Gc, hConRoof.y)
  connect(eqAirTempVDI.TDryBul, eqAirTemp.TDryBul)
  connect(eqAirTempVDI.TBlaSky, eqAirTemp.TBlaSky)
  connect(eqAirTempVDI.HSol[1], weaBus.HGloHor)
  connect(HDirTil.inc, corGDouPan.inc)
  connect(const1.y, eqAirTempVDI.sunblind[1])
  connect(corGDouPan.solarRadWinTrans, thermalZoneFourElements.solRad)
end SimpleRoomFourElements;


within Buildings.ThermalZones.ReducedOrder.Examples;
model SimpleRoomFourElementsTraceSubstance
  "Illustrates the use of a thermal zone considering a trace substance"
  extends Modelica.Icons.Example;
  extends Buildings.ThermalZones.ReducedOrder.Examples.SimpleRoomFourElements(thermalZoneFourElements(
      redeclare package Medium = Medium,
      use_C_flow=true,
      nPorts=2));

  replaceable package Medium = Buildings.Media.Air (
    extraPropertiesNames={"C_flow"}) "Medium model"

  parameter Real airChaRat(final unit="1/s") = 2/3600 "Air change rate";

  Modelica.Blocks.Sources.Pulse traSub(
    amplitude=10.4*2*(28.949/44.01),
    width=50,
    period=86400,
    offset=0) "Source of trace substance (for example CO2)"
  Buildings.Fluid.Sources.MassFlowSource_T souAir(
    redeclare package Medium = Medium,
    use_C_in=true,
    m_flow=airChaRat*rho_default*thermalZoneFourElements.VAir,
    nPorts=1) "Source of air"
  Buildings.Fluid.Sources.Boundary_pT sinAir(
    redeclare package Medium = Medium,
    C={400},
    nPorts=1) "Sink of air"
  Modelica.Blocks.Sources.Ramp traSubAmb(
    height=200,
    duration(displayUnit="d") = 259200,
    offset=200) "Source for CO2 concentration in fresh air"

protected
  final parameter Medium.ThermodynamicState state_default = Medium.setState_pTX(
      T=Medium.T_default,
      p=Medium.p_default,
      X=Medium.X_default[1:Medium.nXi]) "Medium state at default values";

  final parameter Modelica.Units.SI.Density rho_default=Medium.density(state=
      state_default) "Density, used to compute fluid mass";

equation
  connect(traSub.y, thermalZoneFourElements.C_flow[1])
  connect(souAir.ports[1], thermalZoneFourElements.ports[1])
  connect(sinAir.ports[1], thermalZoneFourElements.ports[2])
  connect(traSubAmb.y, souAir.C_in[1])
end SimpleRoomFourElementsTraceSubstance;


within Buildings.ThermalZones.ReducedOrder.Examples;
model SimpleRoomOneElement
  "Illustrates the use of a thermal zone with one heat conduction element"
  extends Modelica.Icons.Example;

  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    calTSky=Buildings.BoundaryConditions.Types.SkyTemperatureCalculation.HorizontalRadiation,
    computeWetBulbTemperature=false,
    filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
    "Weather data reader"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil[2](
    each outSkyCon=true,
    each outGroCon=true,
    each til=1.5707963267949,
    azi={3.1415926535898,4.7123889803847})
    "Calculates diffuse solar radiation on titled surface for both directions"
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[2](
    each til=1.5707963267949,
    azi={3.1415926535898,4.7123889803847})
    "Calculates direct solar radiation on titled surface for both directions"
  SolarGain.CorrectionGDoublePane corGDouPan(n=2, UWin=2.1)
    "Correction factor for solar transmission"
  RC.OneElement thermalZoneOneElement(
    VAir=52.5,
    hConExt=2.7,
    hConWin=2.7,
    gWin=1,
    ratioWinConRad=0.09,
    nExt=1,
    RExt={0.00331421908725},
    CExt={5259932.23},
    hRad=5,
    RWin=0.01642857143,
    RExtRem=0.1265217391,
    nOrientations=2,
    AWin={7,7},
    ATransparent={7,7},
    AExt={3.5,8},
    redeclare package Medium = Modelica.Media.Air.SimpleAir,
    extWallRC(thermCapExt(each der_T(fixed=true))),
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    T_start=295.15) "Thermal zone"
  EquivalentAirTemperature.VDI6007WithWindow eqAirTemp(
    n=2,
    wfGro=0,
    wfWall={0.3043478260869566,0.6956521739130435},
    wfWin={0.5,0.5},
    withLongwave=true,
    aExt=0.7,
    hConWallOut=20,
    hRad=5,
    hConWinOut=20,
    TGro=285.15) "Computes equivalent air temperature"
  Modelica.Blocks.Math.Add solRad[2]
    "Sums up solar radiation of both directions"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTem
    "Prescribed temperature for exterior walls outdoor surface temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTem1
    "Prescribed temperature for windows outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection theConWin
    "Outdoor convective heat transfer of windows"
  Modelica.Thermal.HeatTransfer.Components.Convection theConWall
    "Outdoor convective heat transfer of walls"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow perRad
    "Radiative heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow perCon
    "Convective heat flow of persons"
  Modelica.Blocks.Sources.CombiTimeTable intGai(
    table=[0,0,0,0; 3600,0,0,0; 7200,0,0,0; 10800,0,0,0; 14400,0,0,0; 18000,0,0,
        0; 21600,0,0,0; 25200,0,0,0; 25200,80,80,200; 28800,80,80,200; 32400,80,
        80,200; 36000,80,80,200; 39600,80,80,200; 43200,80,80,200; 46800,80,80,200;
        50400,80,80,200; 54000,80,80,200; 57600,80,80,200; 61200,80,80,200; 61200,
        0,0,0; 64800,0,0,0; 72000,0,0,0; 75600,0,0,0; 79200,0,0,0; 82800,0,0,0;
        86400,0,0,0],
    columns={2,3,4},
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic) "Table with profiles for persons (radiative and convective) and machines
    (convective)"
  Modelica.Blocks.Sources.Constant const[2](each k=0)
    "Sets sunblind signal to zero (open)"
  BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow macConv
    "Convective heat flow of machines"
  Modelica.Blocks.Sources.Constant hConWall(k=25*11.5)
    "Outdoor coefficient of heat transfer for walls"
  Modelica.Blocks.Sources.Constant hConWin(k=20*14)
    "Outdoor coefficient of heat transfer for windows"

equation
  connect(eqAirTemp.TEqAirWin, preTem1.T)
  connect(eqAirTemp.TEqAir, preTem.T)
  connect(weaDat.weaBus, weaBus)
  connect(weaBus.TDryBul, eqAirTemp.TDryBul)
  connect(intGai.y[1], perRad.Q_flow)
  connect(intGai.y[2], perCon.Q_flow)
  connect(intGai.y[3], macConv.Q_flow)
  connect(const.y, eqAirTemp.sunblind)
  connect(HDifTil.HSkyDifTil, corGDouPan.HSkyDifTil)
  connect(HDirTil.H, corGDouPan.HDirTil)
  connect(HDirTil.H,solRad. u1)
  connect(HDirTil.inc, corGDouPan.inc)
  connect(HDifTil.H,solRad. u2)
  connect(HDifTil.HGroDifTil, corGDouPan.HGroDifTil)
  connect(solRad.y, eqAirTemp.HSol)
  connect(weaDat.weaBus, HDifTil[1].weaBus)
  connect(weaDat.weaBus, HDifTil[2].weaBus)
  connect(weaDat.weaBus, HDirTil[1].weaBus)
  connect(weaDat.weaBus, HDirTil[2].weaBus)
  connect(perRad.port, thermalZoneOneElement.intGainsRad)
  connect(theConWin.solid, thermalZoneOneElement.window)
  connect(preTem1.port, theConWin.fluid)
  connect(thermalZoneOneElement.extWall, theConWall.solid)
  connect(theConWall.fluid, preTem.port)
  connect(hConWall.y, theConWall.Gc)
  connect(hConWin.y, theConWin.Gc)
  connect(weaBus.TBlaSky, eqAirTemp.TBlaSky)
  connect(macConv.port, thermalZoneOneElement.intGainsConv)
  connect(perCon.port, thermalZoneOneElement.intGainsConv)
  connect(corGDouPan.solarRadWinTrans, thermalZoneOneElement.solRad)
end SimpleRoomOneElement;


within Buildings.ThermalZones.ReducedOrder.Examples;
model SimpleRoomThreeElements
  "Illustrates the use of a thermal zone with three heat conduction elements"
  extends Modelica.Icons.Example;

  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    calTSky=Buildings.BoundaryConditions.Types.SkyTemperatureCalculation.HorizontalRadiation,
    computeWetBulbTemperature=false,
    filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
    "Weather data reader"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil[2](
    each outSkyCon=true,
    each outGroCon=true,
    each til=1.5707963267949,
    azi={3.1415926535898,4.7123889803847})
    "Calculates diffuse solar radiation on titled surface for both directions"
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[2](
      each til=1.5707963267949,
      azi={3.1415926535898,4.7123889803847})
    "Calculates direct solar radiation on titled surface for both directions"
  SolarGain.CorrectionGDoublePane corGDouPan(n=2, UWin=2.1)
    "Correction factor for solar transmission"
  RC.ThreeElements thermalZoneThreeElements(
    VAir=52.5,
    hConExt=2.7,
    hConWin=2.7,
    gWin=1,
    ratioWinConRad=0.09,
    nExt=1,
    RExt={0.00331421908725},
    CExt={5259932.23},
    hRad=5,
    AInt=60.5,
    hConInt=2.12,
    nInt=1,
    RInt={0.000668895639141},
    CInt={12391363.86},
    RWin=0.01642857143,
    RExtRem=0.1265217391,
    AFloor=11.5,
    hConFloor=2.7,
    nFloor=1,
    RFloor={0.00331421908725},
    RFloorRem=0.1265217391,
    CFloor={5259932.23},
    AWin={7,7},
    ATransparent={7,7},
    AExt={3.5,8},
    nOrientations=2,
    redeclare package Medium = Modelica.Media.Air.SimpleAir,
    extWallRC(thermCapExt(each der_T(fixed=true))),
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    intWallRC(thermCapInt(each der_T(fixed=true))),
    floorRC(thermCapExt(each der_T(fixed=true))),
    T_start=295.15) "Thermal zone"
  EquivalentAirTemperature.VDI6007WithWindow eqAirTemp(
    n=2,
    wfGro=0,
    wfWall={0.3043478260869566,0.6956521739130435},
    wfWin={0.5,0.5},
    withLongwave=true,
    aExt=0.7,
    hConWallOut=20,
    hRad=5,
    hConWinOut=20,
    TGro=285.15) "Computes equivalent air temperature"
  Modelica.Blocks.Math.Add solRad[2]
    "Sums up solar radiation of both directions"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTem
    "Prescribed temperature for exterior walls outdoor surface temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTem1
    "Prescribed temperature for windows outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection theConWin
    "Outdoor convective heat transfer of windows"
  Modelica.Thermal.HeatTransfer.Components.Convection theConWall
    "Outdoor convective heat transfer of walls"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow perRad
    "Radiative heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow perCon
    "Convective heat flow of persons"
  Modelica.Blocks.Sources.CombiTimeTable intGai(
    table=[0,0,0,0; 3600,0,0,0; 7200,0,0,0; 10800,0,0,0; 14400,0,0,0; 18000,0,0,
        0; 21600,0,0,0; 25200,0,0,0; 25200,80,80,200; 28800,80,80,200; 32400,80,
        80,200; 36000,80,80,200; 39600,80,80,200; 43200,80,80,200; 46800,80,80,200;
        50400,80,80,200; 54000,80,80,200; 57600,80,80,200; 61200,80,80,200; 61200,
        0,0,0; 64800,0,0,0; 72000,0,0,0; 75600,0,0,0; 79200,0,0,0; 82800,0,0,0;
        86400,0,0,0],
    columns={2,3,4},
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic) "Table with profiles for persons (radiative and convective) and machines
    (convective)"
  Modelica.Blocks.Sources.Constant const[2](each k=0)
    "Sets sunblind signal to zero (open)"
  BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow macConv
    "Convective heat flow of machines"
  Modelica.Blocks.Sources.Constant hConWall(k=25*11.5)
    "Outdoor coefficient of heat transfer for walls"
  Modelica.Blocks.Sources.Constant hConWin(k=20*14)
    "Outdoor coefficient of heat transfer for windows"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTemFloor
    "Prescribed temperature for floor plate outdoor surface temperature"
  Modelica.Blocks.Sources.Constant TSoil(k=283.15)
    "Outdoor surface temperature for floor plate"

equation
  connect(eqAirTemp.TEqAirWin, preTem1.T)
  connect(eqAirTemp.TEqAir, preTem.T)
  connect(weaDat.weaBus, weaBus)
  connect(weaBus.TDryBul, eqAirTemp.TDryBul)
  connect(intGai.y[1], perRad.Q_flow)
  connect(intGai.y[2], perCon.Q_flow)
  connect(intGai.y[3], macConv.Q_flow)
  connect(const.y, eqAirTemp.sunblind)
  connect(HDifTil.HSkyDifTil, corGDouPan.HSkyDifTil)
  connect(HDirTil.H, corGDouPan.HDirTil)
  connect(HDirTil.H,solRad. u1)
  connect(HDirTil.inc, corGDouPan.inc)
  connect(HDifTil.H,solRad. u2)
  connect(HDifTil.HGroDifTil, corGDouPan.HGroDifTil)
  connect(solRad.y, eqAirTemp.HSol)
  connect(weaDat.weaBus, HDifTil[1].weaBus)
  connect(weaDat.weaBus, HDifTil[2].weaBus)
  connect(weaDat.weaBus, HDirTil[1].weaBus)
  connect(weaDat.weaBus, HDirTil[2].weaBus)
  connect(perRad.port, thermalZoneThreeElements.intGainsRad)
  connect(theConWin.solid, thermalZoneThreeElements.window)
  connect(preTem1.port, theConWin.fluid)
  connect(thermalZoneThreeElements.extWall, theConWall.solid)
  connect(theConWall.fluid, preTem.port)
  connect(hConWall.y, theConWall.Gc)
  connect(hConWin.y, theConWin.Gc)
  connect(weaBus.TBlaSky, eqAirTemp.TBlaSky)
  connect(macConv.port, thermalZoneThreeElements.intGainsConv)
  connect(perCon.port, thermalZoneThreeElements.intGainsConv)
  connect(preTemFloor.port, thermalZoneThreeElements.floor)
  connect(TSoil.y, preTemFloor.T)
  connect(corGDouPan.solarRadWinTrans, thermalZoneThreeElements.solRad)
end SimpleRoomThreeElements;


within Buildings.ThermalZones.ReducedOrder.Examples;
model SimpleRoomTwoElements
 "Illustrates the use of a thermal zone with two heat conduction elements"
  extends Modelica.Icons.Example;

  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    calTSky=Buildings.BoundaryConditions.Types.SkyTemperatureCalculation.HorizontalRadiation,
    computeWetBulbTemperature=false,
    filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
    "Weather data reader"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil[2](
    each outSkyCon=true,
    each outGroCon=true,
    each til=1.5707963267949,
    azi={3.1415926535898,4.7123889803847})
    "Calculates diffuse solar radiation on titled surface for both directions"
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[2](
    each til(displayUnit="deg") = 1.5707963267949,
    azi={3.1415926535898, 4.7123889803847})
    "Calculates direct solar radiation on titled surface for both directions"
  SolarGain.CorrectionGDoublePane corGDouPan(n=2, UWin=2.1)
    "Correction factor for solar transmission"
  RC.TwoElements thermalZoneTwoElements(
    VAir=52.5,
    hConExt=2.7,
    hConWin=2.7,
    gWin=1,
    ratioWinConRad=0.09,
    nExt=1,
    RExt={0.00331421908725},
    CExt={5259932.23},
    hRad=5,
    AInt=60.5,
    hConInt=2.12,
    nInt=1,
    RInt={0.000668895639141},
    CInt={12391363.86},
    RWin=0.01642857143,
    RExtRem=0.1265217391,
    nOrientations=2,
    AWin={7,7},
    ATransparent={7,7},
    AExt={3.5,8},
    redeclare package Medium = Modelica.Media.Air.SimpleAir,
    extWallRC(thermCapExt(each der_T(fixed=true))),
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    T_start=295.15,
    intWallRC(thermCapInt(each der_T(fixed=true)))) "Thermal zone"
  EquivalentAirTemperature.VDI6007WithWindow eqAirTemp(
    n=2,
    wfGro=0,
    wfWall={0.3043478260869566,0.6956521739130435},
    wfWin={0.5,0.5},
    withLongwave=true,
    aExt=0.7,
    hConWallOut=20,
    hRad=5,
    hConWinOut=20,
    TGro=285.15) "Computes equivalent air temperature"
  Modelica.Blocks.Math.Add solRad[2]
    "Sums up solar radiation of both directions"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTem
    "Prescribed temperature for exterior walls outdoor surface temperature"
  Buildings.HeatTransfer.Sources.PrescribedTemperature preTem1
    "Prescribed temperature for windows outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection theConWin
    "Outdoor convective heat transfer of windows"
  Modelica.Thermal.HeatTransfer.Components.Convection theConWall
    "Outdoor convective heat transfer of walls"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow perRad
    "Radiative heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow perCon
    "Convective heat flow of persons"
  Modelica.Blocks.Sources.CombiTimeTable intGai(
    table=[0,0,0,0; 3600,0,0,0; 7200,0,0,0; 10800,0,0,0; 14400,0,0,0; 18000,0,0,
        0; 21600,0,0,0; 25200,0,0,0; 25200,80,80,200; 28800,80,80,200; 32400,80,
        80,200; 36000,80,80,200; 39600,80,80,200; 43200,80,80,200; 46800,80,80,200;
        50400,80,80,200; 54000,80,80,200; 57600,80,80,200; 61200,80,80,200; 61200,
        0,0,0; 64800,0,0,0; 72000,0,0,0; 75600,0,0,0; 79200,0,0,0; 82800,0,0,0;
        86400,0,0,0],
    columns={2,3,4},
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic) "Table with profiles for persons (radiative and convective) and machines
    (convective)"
  Modelica.Blocks.Sources.Constant const[2](each k=0)
    "Sets sunblind signal to zero (open)"
  BoundaryConditions.WeatherData.Bus weaBus "Weather data bus"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow macConv
    "Convective heat flow of machines"
  Modelica.Blocks.Sources.Constant hConWall(k=25*11.5)
    "Outdoor coefficient of heat transfer for walls"
  Modelica.Blocks.Sources.Constant hConWin(k=20*14)
    "Outdoor coefficient of heat transfer for windows"

equation
  connect(eqAirTemp.TEqAirWin, preTem1.T)
  connect(eqAirTemp.TEqAir, preTem.T)
  connect(weaDat.weaBus, weaBus)
  connect(weaBus.TDryBul, eqAirTemp.TDryBul)
  connect(intGai.y[1], perRad.Q_flow)
  connect(intGai.y[2], perCon.Q_flow)
  connect(intGai.y[3], macConv.Q_flow)
  connect(const.y, eqAirTemp.sunblind)
  connect(HDifTil.HSkyDifTil, corGDouPan.HSkyDifTil)
  connect(HDirTil.H, corGDouPan.HDirTil)
  connect(HDirTil.H,solRad. u1)
  connect(HDirTil.inc, corGDouPan.inc)
  connect(HDifTil.H,solRad. u2)
  connect(HDifTil.HGroDifTil, corGDouPan.HGroDifTil)
  connect(solRad.y, eqAirTemp.HSol)
  connect(weaDat.weaBus, HDifTil[1].weaBus)
  connect(weaDat.weaBus, HDifTil[2].weaBus)
  connect(weaDat.weaBus, HDirTil[1].weaBus)
  connect(weaDat.weaBus, HDirTil[2].weaBus)
  connect(perRad.port, thermalZoneTwoElements.intGainsRad)
  connect(theConWin.solid, thermalZoneTwoElements.window)
  connect(preTem1.port, theConWin.fluid)
  connect(thermalZoneTwoElements.extWall, theConWall.solid)
  connect(theConWall.fluid, preTem.port)
  connect(hConWall.y, theConWall.Gc)
  connect(hConWin.y, theConWin.Gc)
  connect(weaBus.TBlaSky, eqAirTemp.TBlaSky)
  connect(macConv.port, thermalZoneTwoElements.intGainsConv)
  connect(perCon.port, thermalZoneTwoElements.intGainsConv)
  connect(corGDouPan.solarRadWinTrans, thermalZoneTwoElements.solRad)
end SimpleRoomTwoElements;


Illustrates the use of non-constant ground temperature for equivalent air temperature calculation. This example shows the application of

Buildings.ThermalZones.ReducedOrder.RC.TwoElements
in connection with equivalent air temperature calculation in

Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature.VDI6007WithWindow,
where the ground temperature is not a constant, but has a trapezoid source.
Apart from that, it is identical to
Buildings.ThermalZones.ReducedOrder.Examples.SimpleRoomTwoElements.

References

VDI. German Association of Engineers Guideline VDI 6007-1
March 2012. Calculation of transient thermal response of rooms
and buildings - modelling of rooms.

within Buildings.ThermalZones.ReducedOrder.Examples;
model SimpleRoomTwoElementsNonConstantTGround
  "Illustrates the use of non-constant ground temperature for equivalent air temperature calculation"
  extends Modelica.Icons.Example;
  extends Buildings.ThermalZones.ReducedOrder.Examples.SimpleRoomTwoElements(
    eqAirTemp(
      wfWall={0.15,0.35},
      wfGro=0.5,
      TGroundFromInput=true));

  Modelica.Blocks.Sources.Trapezoid TGro(
    amplitude(unit="K") = 10,
    rising(displayUnit="d") = 7884000,
    width(displayUnit="d") = 7884000,
    falling(displayUnit="d") = 7884000,
    period(displayUnit="d") = 31536000,
    offset(
      unit="K",
      displayUnit="degC") = 280.15,
    startTime(displayUnit="d") = 5184000)
    "Trapezoid-shaped source for ground temperature"
equation

  connect(TGro.y, eqAirTemp.TGro_in)
end SimpleRoomTwoElementsNonConstantTGround;


Thermal Zone with four elements for exterior walls,
  interior walls, floor plate and roof. This model adds another element for the roof. Roofs commonly
  exhibit the same excitations as exterior walls but have different coefficients
  of heat transfer due to their orientation. Adding an extra element for the roof
  might lead to a finer resolution of the dynamic behaviour but increases
  calculation times. The roof is parameterized via the length of the RC-chain
  nRoof,
  the vector of capacities CRoof[nRoof], the vector of resistances
  RRoof[nRoof] and remaining resistances RRoofRem.

within Buildings.ThermalZones.ReducedOrder.RC;
model FourElements "Thermal Zone with four elements for exterior walls,
  interior walls, floor plate and roof"
  extends ThreeElements(AArray={ATotExt,ATotWin,AInt,AFloor,ARoof});

  parameter Modelica.Units.SI.Area ARoof "Area of roof"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hConRoof
    "Convective coefficient of heat transfer of roof (indoor)"
  parameter Integer nRoof(min = 1) "Number of RC-elements of roof"
  parameter Modelica.Units.SI.ThermalResistance RRoof[nRoof](each min=Modelica.Constants.small)
    "Vector of resistances of roof, from inside to outside"
  parameter Modelica.Units.SI.ThermalResistance RRoofRem(min=Modelica.Constants.small)
    "Resistance of remaining resistor RRoofRem between capacity n and outside"
  parameter Modelica.Units.SI.HeatCapacity CRoof[nRoof](each min=Modelica.Constants.small)
    "Vector of heat capacities of roof, from inside to outside"
  parameter Boolean indoorPortRoof = false
    "Additional heat port at indoor surface of roof"

  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a roof if ARoof > 0
    "Ambient port for roof"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a roofIndoorSurface
  if indoorPortRoof "Auxiliary port at indoor surface of roof"
  BaseClasses.ExteriorWall roofRC(
    final RExt=RRoof,
    final RExtRem=RRoofRem,
    final CExt=CRoof,
    final n=nRoof,
    final T_start=T_start) if ARoof > 0 "RC-element for roof"

protected
  Modelica.Thermal.HeatTransfer.Components.Convection convRoof
  if ARoof > 0 "Convective heat transfer of roof"
  Modelica.Blocks.Sources.Constant hConRoof_const(
  final k=ARoof*hConRoof)
    if ARoof > 0 "Coefficient of convective heat transfer for roof"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resIntRoof(
    final G=min(AInt, ARoof)*hRad)
    if AInt > 0 and ARoof > 0 "Resistor between interior walls and roof"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resRoofWin(
    final G=min(ARoof, ATotWin)*hRad)
    if ARoof > 0 and ATotWin > 0 "Resistor between roof and windows"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resRoofFloor(
    final G=min(ARoof, AFloor)*hRad)
    if ARoof > 0 and AFloor > 0 "Resistor between floor plate and roof"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resExtWallRoof(
    final G=min(ATotExt, ARoof)*hRad)
   if ATotExt > 0 and ARoof > 0 "Resistor between exterior walls and roof"

equation
  connect(convRoof.solid, roofRC.port_a)
  connect(roofRC.port_b, roof)
  connect(resRoofWin.port_a, convWin.solid)
  connect(resRoofWin.port_b, convRoof.solid)
  connect(resRoofFloor.port_a, convRoof.solid)
  connect(resRoofFloor.port_b, resExtWallFloor.port_b)
  connect(resIntRoof.port_b, intWallRC.port_a)
  connect(resIntRoof.port_a, convRoof.solid)
  connect(resExtWallRoof.port_a, convExtWall.solid)
  connect(resExtWallRoof.port_b, convRoof.solid)
  if not ATotExt > 0 and not ATotWin > 0 and not AInt > 0 and not AFloor > 0
    and ARoof > 0 then
    connect(thermSplitterIntGains.portOut[1], roofRC.port_a);
    connect(roofRC.port_a, thermSplitterSolRad.portOut[1]);
  elseif ATotExt > 0 and not ATotWin > 0 and not AInt > 0 and not AFloor > 0
    and ARoof > 0
     or not ATotExt > 0 and ATotWin > 0 and not AInt > 0 and not AFloor > 0
     and ARoof > 0
     or not ATotExt > 0 and not ATotWin > 0 and AInt > 0 and not AFloor > 0
     and ARoof > 0
     or not ATotExt > 0 and not ATotWin > 0 and not AInt > 0 and AFloor > 0
     and ARoof > 0 then
    connect(thermSplitterIntGains.portOut[2], roofRC.port_a);
    connect(roofRC.port_a, thermSplitterSolRad.portOut[2]);
  elseif ATotExt > 0 and ATotWin > 0 and not AInt > 0 and not AFloor > 0 and ARoof > 0
     or ATotExt > 0 and not ATotWin > 0 and AInt > 0 and not AFloor > 0 and ARoof > 0
     or ATotExt > 0 and not ATotWin > 0 and not AInt > 0 and AFloor > 0 and ARoof > 0
     or not ATotExt > 0 and ATotWin > 0 and AInt > 0 and not AFloor > 0 and ARoof > 0
     or not ATotExt > 0 and ATotWin > 0 and not AInt > 0 and AFloor > 0 and ARoof > 0
     or not ATotExt > 0 and not ATotWin > 0 and AInt > 0 and AFloor > 0
     and ARoof > 0 then
    connect(thermSplitterIntGains.portOut[3], roofRC.port_a);
    connect(roofRC.port_a, thermSplitterSolRad.portOut[3]);
  elseif not ATotExt > 0 and ATotWin > 0 and AInt > 0 and AFloor > 0 and ARoof > 0
     or ATotExt > 0 and not ATotWin > 0 and AInt > 0 and AFloor > 0 and ARoof > 0
     or ATotExt > 0 and ATotWin > 0 and not AInt > 0 and AFloor > 0 and ARoof > 0
     or ATotExt > 0 and ATotWin > 0 and AInt > 0 and not AFloor > 0 and ARoof > 0 then
    connect(thermSplitterIntGains.portOut[4], roofRC.port_a);
    connect(roofRC.port_a, thermSplitterSolRad.portOut[4]);
  elseif ATotExt > 0 and ATotWin > 0 and AInt > 0 and AFloor > 0 and ARoof > 0 then
    connect(thermSplitterSolRad.portOut[5], roofRC.port_a)
    connect(thermSplitterIntGains.portOut[5], roofRC.port_a)
  end if;
  connect(hConRoof_const.y, convRoof.Gc)
  connect(convRoof.fluid, senTAir.port)
  connect(roofRC.port_a, roofIndoorSurface)
end FourElements;


within Buildings.ThermalZones.ReducedOrder.RC;
model OneElement "Thermal Zone with one element for exterior walls"
  extends Buildings.Fluid.Interfaces.LumpedVolumeDeclarations(
    final massDynamics=energyDynamics);

  parameter Modelica.Units.SI.Volume VAir "Air volume of the zone"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hRad
    "Coefficient of heat transfer for linearized radiation exchange between walls"
  parameter Integer nOrientations(min=1) "Number of orientations"
  parameter Integer nPorts=0 "Number of fluid ports"
  parameter Modelica.Units.SI.Area AWin[nOrientations]
    "Vector of areas of windows by orientations"
  parameter Modelica.Units.SI.Area ATransparent[nOrientations] "Vector of areas of transparent (solar radiation transmittend) elements by
    orientations"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hConWin
    "Convective coefficient of heat transfer of windows (indoor)"
  parameter Modelica.Units.SI.ThermalResistance RWin "Resistor for windows"
  parameter Modelica.Units.SI.TransmissionCoefficient gWin
    "Total energy transmittance of windows"
  parameter Real ratioWinConRad
    "Ratio for windows between indoor convective and radiative heat emission"
  parameter Boolean indoorPortWin = false
    "Additional heat port at indoor surface of windows"
  parameter Modelica.Units.SI.Area AExt[nOrientations]
    "Vector of areas of exterior walls by orientations"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hConExt
    "Convective coefficient of heat transfer of exterior walls (indoor)"
  parameter Integer nExt(min = 1) "Number of RC-elements of exterior walls"
  parameter Modelica.Units.SI.ThermalResistance RExt[nExt](each min=Modelica.Constants.small)
    "Vector of resistances of exterior walls, from inside to outside"
  parameter Modelica.Units.SI.ThermalResistance RExtRem(min=Modelica.Constants.small)
    "Resistance of remaining resistor RExtRem between capacity n and outside"
  parameter Modelica.Units.SI.HeatCapacity CExt[nExt](each min=Modelica.Constants.small)
    "Vector of heat capacities of exterior walls, from inside to outside"
  parameter Boolean indoorPortExtWalls = false
    "Additional heat port at indoor surface of exterior walls"
  parameter Boolean use_moisture_balance = false
    "If true, input connector QLat_flow is enabled and room air computes moisture balance"

  parameter Boolean use_C_flow = false
    "Set to true to enable input connector for trace substance"

  Modelica.Blocks.Interfaces.RealInput solRad[nOrientations](
    each final quantity="RadiantEnergyFluenceRate",
    each final unit="W/m2") if sum(ATransparent) > 0
    "Solar radiation transmitted through windows"

  Modelica.Blocks.Interfaces.RealInput QLat_flow(final unit="W")
 if use_moisture_balance and ATot >0
    "Latent heat gains for the room"

  Modelica.Blocks.Interfaces.RealOutput TAir(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC") if ATot > 0 or VAir > 0 "Indoor air temperature"

  Modelica.Blocks.Interfaces.RealOutput TRad(
    final quantity="ThermodynamicTemperature",
    final unit="K",
    displayUnit="degC") if ATot > 0 "Mean indoor radiation temperature"

  Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b ports[nPorts](
    redeclare each final package Medium = Medium)
    "Auxiliary fluid inlets and outlets to indoor air volume"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a extWall if ATotExt > 0
    "Ambient port for exterior walls"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a window if ATotWin > 0
    "Ambient port for windows"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a intGainsConv
 if ATot > 0 or VAir > 0
    "Auxiliary port for sensible internal convective gains"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a intGainsRad if ATot > 0
    "Auxiliary port for internal radiative gains"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a windowIndoorSurface
 if indoorPortWin "Auxiliary port at indoor surface of windows"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a extWallIndoorSurface
 if indoorPortExtWalls "Auxiliary port at indoor surface of exterior walls"

  Fluid.MixingVolumes.MixingVolume volAir(
    redeclare final package Medium = Medium,
    final nPorts=nPorts,
    m_flow_nominal=VAir*6/3600*1.2,
    final V=VAir,
    final energyDynamics=energyDynamics,
    final massDynamics=energyDynamics,
    final p_start=p_start,
    final T_start=T_start,
    final X_start=X_start,
    final C_start=C_start,
    final C_nominal=C_nominal,
    final mSenFac=mSenFac,
    final use_C_flow=use_C_flow) if VAir > 0 and not use_moisture_balance
    "Indoor air volume"
  Fluid.MixingVolumes.MixingVolumeMoistAir volMoiAir(
    redeclare final package Medium = Medium,
    final nPorts=nPorts,
    m_flow_nominal=VAir*6/3600*1.2,
    final V=VAir,
    final energyDynamics=energyDynamics,
    final massDynamics=energyDynamics,
    final p_start=p_start,
    final T_start=T_start,
    final X_start=X_start,
    final C_start=C_start,
    final C_nominal=C_nominal,
    final mSenFac=mSenFac,
    final use_C_flow=use_C_flow) if VAir > 0 and use_moisture_balance
    "Indoor air volume"
  Modelica.Thermal.HeatTransfer.Components.ThermalResistor resWin(final R=RWin)
 if ATotWin > 0 "Resistor for windows"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow convHeatSol(
    final alpha=0)
 if ratioWinConRad > 0 and (ATot > 0 or VAir > 0) and sum(ATransparent) > 0
    "Solar heat considered as convection"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow radHeatSol[
    nOrientations](each final alpha=0) if ATot > 0 and sum(ATransparent) > 0
    "Solar heat considered as radiation"
  BaseClasses.ThermSplitter thermSplitterIntGains(
    final splitFactor=splitFactor,
    final nOut=dimension,
    final nIn=1) if ATot > 0
    "Splits incoming internal gains into separate gains for each wall element,
    weighted by their area"
  BaseClasses.ThermSplitter thermSplitterSolRad(
    final splitFactor=splitFactorSolRad,
    final nOut=dimension,
    final nIn=nOrientations) if ATot > 0 and sum(ATransparent) > 0
    "Splits incoming solar radiation into separate gains for each wall element,
    weighted by their area"
  BaseClasses.ExteriorWall extWallRC(
    final n=nExt,
    final RExt=RExt,
    final CExt=CExt,
    final RExtRem=RExtRem,
    final T_start=T_start) if ATotExt > 0 "RC-element for exterior walls"

  Modelica.Blocks.Interfaces.RealInput[Medium.nC] C_flow if use_C_flow
    "Trace substance mass flow rate added to the thermal zone"

protected
  constant Modelica.Units.SI.SpecificEnergy h_fg=
      Buildings.Media.Air.enthalpyOfCondensingGas(273.15 + 37)
    "Latent heat of water vapor";
  parameter Modelica.Units.SI.Area ATot=sum(AArray) "Sum of wall surface areas";
  parameter Modelica.Units.SI.Area ATotExt=sum(AExt)
    "Sum of exterior wall surface areas";
  parameter Modelica.Units.SI.Area ATotWin=sum(AWin)
    "Sum of window surface areas";
  parameter Modelica.Units.SI.Area[:] AArray={ATotExt,ATotWin}
    "List of all wall surface areas";
  parameter Integer dimension = sum({if A>0 then 1 else 0 for A in AArray})
    "Number of non-zero wall surface areas";
  parameter Real splitFactor[dimension, 1]=
    BaseClasses.splitFacVal(dimension, 1, AArray, fill(0, 1), fill(0, 1))
    "Share of each wall surface area that is non-zero";
  parameter Real splitFactorSolRad[dimension, nOrientations]=
    BaseClasses.splitFacVal(dimension, nOrientations, AArray, AExt, AWin)
    "Share of each wall surface area that is non-zero, for each orientation separately";
  Modelica.Thermal.HeatTransfer.Components.Convection convExtWall(dT(start=0))
                                                                  if ATotExt > 0
    "Convective heat transfer of exterior walls"
  Modelica.Blocks.Sources.Constant hConExtWall_const(
  final k=ATotExt*hConExt) if ATotExt > 0
    "Coefficient of convective heat transfer for exterior walls"
  Modelica.Thermal.HeatTransfer.Components.Convection convWin if ATotWin > 0
    "Convective heat transfer of windows"
  Modelica.Blocks.Sources.Constant hConWin_const(final k=ATotWin*hConWin)
    "Coefficient of convective heat transfer for windows"
  Modelica.Blocks.Math.Gain eRadSol[nOrientations](
    final k(each unit="m2")=gWin*(1 - ratioWinConRad)*ATransparent,
    u(each final unit="W/m2"),
    y(each final unit="W")) if sum(ATransparent) > 0
    "Emission coefficient of solar radiation considered as radiation"
  Modelica.Blocks.Math.Gain eConvSol[nOrientations](
    final k(each unit="m2")=gWin*ratioWinConRad*ATransparent,
    u(each final unit="W/m2"),
    y(each final unit="W")) if ratioWinConRad > 0 and sum(ATransparent) > 0
    "Emission coefficient of solar radiation considered as convection"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resExtWallWin(
      final G=min(ATotExt, ATotWin)*hRad) if ATotExt > 0 and ATotWin > 0
    "Resistor between exterior walls and windows"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor senTAir
 if ATot > 0 or VAir > 0 "Indoor air temperature sensor"
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor senTRad
 if ATot > 0 "Mean indoor radiation temperatur sensor"
  Modelica.Blocks.Math.Sum sumSolRad(final nin=nOrientations)
 if ratioWinConRad > 0 and sum(ATransparent) > 0
    "Sums up solar radiation from different directions"

  Modelica.Blocks.Math.Gain mWat_flow(
    final k(unit="kg/J") = 1/h_fg,
    u(final unit="W"),
    y(final unit="kg/s"))
    if use_moisture_balance and ATot >0 "Water flow rate due to latent heat gain"

  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow conQLat_flow
 if use_moisture_balance and ATot >0
    "Converter for latent heat flow rate"
equation
  connect(volAir.ports, ports)

  connect(volMoiAir.ports, ports)

  connect(resWin.port_a, window)
  connect(resWin.port_b, convWin.solid)
  connect(eRadSol.y, radHeatSol.Q_flow)
  connect(thermSplitterIntGains.portIn[1], intGainsRad)
  connect(radHeatSol.port, thermSplitterSolRad.portIn)
  connect(extWallRC.port_b, extWall)
  connect(extWallRC.port_a, convExtWall.solid)
  if ATotExt > 0 and ATotWin > 0 then
    connect(thermSplitterSolRad.portOut[1], convExtWall.solid)
    connect(thermSplitterIntGains.portOut[1], convExtWall.solid)
    connect(thermSplitterSolRad.portOut[2], convWin.solid)
    connect(thermSplitterIntGains.portOut[2], convWin.solid)
  elseif not ATotExt > 0 and ATotWin > 0 then
    connect(thermSplitterSolRad.portOut[1], convWin.solid);
    connect(thermSplitterIntGains.portOut[1], convWin.solid);
  elseif ATotExt > 0 and not ATotWin > 0 then
    connect(thermSplitterSolRad.portOut[1], convExtWall.solid);
    connect(thermSplitterIntGains.portOut[1], convExtWall.solid);
  end if;
  connect(eRadSol.u, solRad)
  connect(resExtWallWin.port_b, convExtWall.solid)
  connect(resExtWallWin.port_a, convWin.solid)
  connect(hConWin_const.y, convWin.Gc)
  connect(hConExtWall_const.y, convExtWall.Gc)
  connect(convExtWall.fluid, senTAir.port)
  connect(convHeatSol.port, senTAir.port)
  connect(intGainsConv, senTAir.port)
  connect(convWin.fluid, senTAir.port)
  connect(volAir.heatPort, senTAir.port)
  connect(volMoiAir.heatPort, senTAir.port)
  connect(senTAir.T, TAir)
  connect(convWin.solid, windowIndoorSurface)
  connect(convExtWall.solid, extWallIndoorSurface)
  connect(senTRad.port, thermSplitterIntGains.portIn[1])
  connect(senTRad.T, TRad)
  connect(solRad, eConvSol.u)
  connect(eConvSol.y, sumSolRad.u)
  connect(sumSolRad.y, convHeatSol.Q_flow)
  connect(mWat_flow.y, volMoiAir.mWat_flow)

  connect(conQLat_flow.port, volMoiAir.heatPort)
  connect(mWat_flow.u, QLat_flow)
  connect(conQLat_flow.Q_flow, QLat_flow)
  connect(volMoiAir.C_flow, C_flow)
  connect(volAir.C_flow, C_flow)
end OneElement;


within Buildings.ThermalZones.ReducedOrder;
package RC "Package with reduced order thermal zones based on VDI 6007 Part 1"
  extends Modelica.Icons.VariantsPackage;

  package UsersGuide "User's Guide"
    extends Modelica.Icons.Information;
  end UsersGuide;
end RC;


Thermal Zone with three elements for exterior walls,
  interior walls and floor plate. This model adds one further element for
  the floor plate. Long-term effects dominate the excitation of the floor plate
  and thus the excitation fundamentally differs from excitation of outer walls.
  Adding an extra element for the floor plate leads to a finer resolution of the
  dynamic behaviour but increases calculation times. The floor plate is
  parameterized via the length of the RC-chain nFloor,
  the vector of the capacities
  CFloor[nFloor], the vector of the resistances
  RFloor[nFloor]
  and the remaining resistance RFloorRem.

within Buildings.ThermalZones.ReducedOrder.RC;
model ThreeElements "Thermal Zone with three elements for exterior walls,
  interior walls and floor plate"
    extends TwoElements(AArray={ATotExt,ATotWin,AInt,AFloor});

  parameter Modelica.Units.SI.Area AFloor "Area of floor plate"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hConFloor
    "Convective coefficient of heat transfer of floor plate (indoor)"
  parameter Integer nFloor(min = 1) "Number of RC-elements of floor plate"
  parameter Modelica.Units.SI.ThermalResistance RFloor[nFloor](each min=
        Modelica.Constants.small)
    "Vector of resistances of floor plate, from inside to outside"
  parameter Modelica.Units.SI.ThermalResistance RFloorRem(min=Modelica.Constants.small)
    "Resistance of remaining resistor RFloorRem between capacity n and outside"
  parameter Modelica.Units.SI.HeatCapacity CFloor[nFloor](each min=Modelica.Constants.small)
    "Vector of heat capacities of floor plate, from inside to outside"
  parameter Boolean indoorPortFloor = false
    "Additional heat port at indoor surface of floor plate"

  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a floor  if AFloor > 0
    "Ambient port for floor plate"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a floorIndoorSurface
 if indoorPortFloor "Auxiliary port at indoor surface of floor plate"
  BaseClasses.ExteriorWall floorRC(
    final n=nFloor,
    final RExt=RFloor,
    final RExtRem=RFloorRem,
    final CExt=CFloor,
    final T_start=T_start) if AFloor > 0 "RC-element for floor plate"

protected
  Modelica.Thermal.HeatTransfer.Components.Convection convFloor if AFloor > 0
    "Convective heat transfer of floor"
  Modelica.Blocks.Sources.Constant hConFloor_const(final k=AFloor*hConFloor)
 if AFloor > 0 "Coefficient of convective heat transfer for floor"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resExtWallFloor(
      final G=min(ATotExt, AFloor)*hRad) if ATotExt > 0 and AFloor > 0
    "Resistor between exterior walls and floor"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resIntWallFloor(
      final G=min(AFloor, AInt)*hRad) if AInt > 0 and AFloor > 0
    "Resistor between interior walls and floor"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resFloorWin(
    final G=min(ATotWin, AFloor)*hRad) if ATotWin > 0 and AFloor > 0
    "Resistor between floor plate and windows"

equation
  connect(floorRC.port_a, convFloor.solid)
  connect(floorRC.port_a, resExtWallFloor.port_b)
  connect(floorRC.port_a, resIntWallFloor.port_b)
  connect(floorRC.port_b, floor)
  connect(resFloorWin.port_a, convWin.solid)
  if not ATotExt > 0 and not ATotWin > 0 and not AInt > 0 and AFloor > 0 then
    connect(thermSplitterIntGains.portOut[1], floorRC.port_a);
    connect(floorRC.port_a, thermSplitterSolRad.portOut[1]);
  elseif ATotExt > 0 and not ATotWin > 0 and not AInt > 0 and AFloor > 0
    or not ATotExt > 0 and ATotWin > 0 and not AInt > 0 and AFloor > 0
    or not ATotExt > 0 and not ATotWin > 0 and AInt > 0 and AFloor > 0 then
    connect(thermSplitterIntGains.portOut[2], floorRC.port_a);
    connect(floorRC.port_a, thermSplitterSolRad.portOut[2]);
  elseif not ATotExt > 0 and ATotWin > 0 and AInt > 0 and AFloor > 0
    or ATotExt > 0 and not ATotWin > 0 and AInt > 0 and AFloor > 0
    or ATotExt > 0 and ATotWin > 0 and not AInt > 0 and AFloor > 0 then
    connect(thermSplitterIntGains.portOut[3], floorRC.port_a);
    connect(floorRC.port_a, thermSplitterSolRad.portOut[3]);
  elseif ATotExt > 0 and ATotWin > 0 and AInt > 0 and AFloor > 0 then
    connect(thermSplitterIntGains.portOut[4], floorRC.port_a)
    connect(floorRC.port_a, thermSplitterSolRad.portOut[4])
  end if;
  connect(intWallRC.port_a, resIntWallFloor.port_a)
  connect(resFloorWin.port_b, resExtWallFloor.port_b)
  connect(resExtWallFloor.port_a, convExtWall.solid)
  connect(hConFloor_const.y, convFloor.Gc)
  connect(convFloor.fluid, senTAir.port)
  connect(floorRC.port_a, floorIndoorSurface)
end ThreeElements;


Thermal Zone with two elements for exterior and interior walls. This model distinguishes between internal
  thermal masses and exterior walls. While exterior walls contribute to heat
  transfer to the ambient, adiabatic conditions apply to internal masses.
  Parameters for the internal wall element are the length of the RC-chain
  nInt, the vector of the capacities
  CInt[nInt] and the vector of the resistances RInt[nInt].
  This approach allows considering the dynamic behaviour induced by internal
  heat storage.

within Buildings.ThermalZones.ReducedOrder.RC;
model TwoElements
  "Thermal Zone with two elements for exterior and interior walls"
  extends OneElement(AArray={ATotExt,ATotWin,AInt});

  parameter Modelica.Units.SI.Area AInt "Area of interior walls"
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer hConInt
    "Convective coefficient of heat transfer of interior walls (indoor)"
  parameter Integer nInt(min = 1) "Number of RC-elements of interior walls"
  parameter Modelica.Units.SI.ThermalResistance RInt[nInt](each min=Modelica.Constants.small)
    "Vector of resistances of interior walls, from port to center"
  parameter Modelica.Units.SI.HeatCapacity CInt[nInt](each min=Modelica.Constants.small)
    "Vector of heat capacities of interior walls, from port to center"
  parameter Boolean indoorPortIntWalls = false
    "Additional heat port at indoor surface of interior walls"

  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a intWallIndoorSurface
 if indoorPortIntWalls "Auxiliary port at indoor surface of interior walls"
  BaseClasses.InteriorWall intWallRC(
    final n=nInt,
    final RInt=RInt,
    final CInt=CInt,
    final T_start=T_start) if AInt > 0 "RC-element for interior walls"

protected
  Modelica.Thermal.HeatTransfer.Components.Convection convIntWall(dT(start=0))
                                                                  if AInt > 0
    "Convective heat transfer of interior walls"
  Modelica.Blocks.Sources.Constant hConIntWall(k=AInt*hConInt) if AInt > 0
    "Coefficient of convective heat transfer for interior walls"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resExtWallIntWall(
    final G=min(ATotExt, AInt)*hRad, dT(start=0))
                                          if ATotExt > 0 and AInt > 0
    "Resistor between exterior walls and interior walls"
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor resIntWallWin(
    final G=min(ATotWin, AInt)*hRad, dT(start=0))
                                          if ATotWin > 0 and AInt > 0
    "Resistor between interior walls and windows"

equation
  connect(resExtWallIntWall.port_a, convExtWall.solid)
  connect(convIntWall.solid, intWallRC.port_a)
  connect(intWallRC.port_a, resExtWallIntWall.port_b)
  if not ATotExt > 0 and not ATotWin > 0 and AInt > 0 then
    connect(thermSplitterIntGains.portOut[1], intWallRC.port_a);
    connect(thermSplitterSolRad.portOut[1], intWallRC.port_a);
  elseif ATotExt > 0 and not ATotWin > 0 and AInt > 0 or not ATotExt > 0 and ATotWin > 0
    and AInt > 0 then
    connect(thermSplitterIntGains.portOut[2], intWallRC.port_a);
    connect(thermSplitterSolRad.portOut[2], intWallRC.port_a);
  elseif ATotExt > 0 and ATotWin > 0 and AInt > 0 then
    connect(thermSplitterIntGains.portOut[3], intWallRC.port_a)
    connect(thermSplitterSolRad.portOut[3], intWallRC.port_a)
  end if;
  connect(resIntWallWin.port_b, intWallRC.port_a)
  connect(resIntWallWin.port_a, convWin.solid)
  connect(hConIntWall.y, convIntWall.Gc)
  connect(intWallRC.port_a, intWallIndoorSurface)
  connect(convIntWall.fluid, senTAir.port)
end TwoElements;


Exterior wall consisting of variable number of RC elements. ExteriorWall represents heat conduction and heat storage
  within walls. It links a variable number n of thermal resistances
  and capacities to a series connection. n thus defines the spatial
  discretization of thermal effects within the wall. All effects are considered
  as one-dimensional normal to the wall's surface. This model is thought
  for exterior wall elements that contribute to heat transfer to the outdoor.
  The RC-chain is defined via a vector of capacities CExt[n] and a
  vector of resistances RExt[n]. Resistances and capacities are
  connected alternately, starting with the first resistance RExt[1],
  from heat port_a to heat port_b. RExtRem
  is the resistance between the last capacity CExt[end] and the
  heat port_b.

within Buildings.ThermalZones.ReducedOrder.RC.BaseClasses;
model ExteriorWall "Exterior wall consisting of variable number of RC elements"

  parameter Integer n(min = 1) "Number of RC-elements";
  parameter Modelica.Units.SI.ThermalResistance RExt[n](each min=Modelica.Constants.small)
    "Vector of resistors, from port_a to port_b"
  parameter Modelica.Units.SI.ThermalResistance RExtRem(min=Modelica.Constants.small)
    "Resistance of remaining resistor RExtRem between capacitor n and port_b"
  parameter Modelica.Units.SI.HeatCapacity CExt[n](each min=Modelica.Constants.small)
    "Vector of heat capacities, from port_a to port_b"
  parameter Modelica.Units.SI.Temperature T_start
    "Initial temperature of capacities"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a port_a "interior port"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_b port_b "exterior port"
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor thermCapExt[n](
    final C=CExt, each T(start=T_start)) "vector of thermal capacitors"

protected
  Modelica.Thermal.HeatTransfer.Components.ThermalResistor thermResExt[n](
    final R=RExt)
    "vector of thermal resistors connecting port_a and capacitors"
  Modelica.Thermal.HeatTransfer.Components.ThermalResistor thermResExtRem(
    final R=RExtRem)
    "single thermal resistor connecting least capacitor to port_b"

equation
  // Connecting inner elements thermResExt[i]--thermCapExt[i] to n groups
  for i in 1:n loop
    connect(thermResExt[i].port_b,thermCapExt[i].port)
  end for;
  // Connecting groups between each other thermCapExt[i] -- thermResExt[i+1]
  for i in 1:n-1 loop
    connect(thermCapExt[i].port,thermResExt[i+1].port_a)
  end for;
  // Connecting first RC element to port_a ,
  // last RC-element to RExtRem and RExtRem to port_b
  connect(port_a,thermResExt[1].port_a)
  connect(thermCapExt[n].port,thermResExtRem.port_a)

  connect(thermResExtRem.port_b, port_b)
end ExteriorWall;


Interior wall consisting of variable number of RC elements. InteriorWall represents heat storage within walls. It links a
  variable number n of thermal resistances and capacities to a
  series connection. n thus defines the spatial discretization of
  thermal effects within the wall. All effects are considered as one-dimensional
  normal to the wall's surface. This model is thought for interior wall
  elements that only serve as heat storage elements. The RC-chain is defined via
  a vector of capacities CInt[n] and a vector of resistances
  RInt[n].
  Resistances and capacities are connected alternately, starting with the first
  resistance RInt[1], from heat port_a into the wall.

within Buildings.ThermalZones.ReducedOrder.RC.BaseClasses;
model InteriorWall "Interior wall consisting of variable number of RC elements"

  parameter Integer n(min = 1) "Number of RC-elements";
  parameter Modelica.Units.SI.ThermalResistance RInt[n](each min=Modelica.Constants.small)
    "Vector of resistors, from port to capacitor"
  parameter Modelica.Units.SI.HeatCapacity CInt[n](each min=Modelica.Constants.small)
    "Vector of heat capacitors, from port to center"
  parameter Modelica.Units.SI.Temperature T_start
    "Initial temperature of capacities"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a port_a "interior port"
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor thermCapInt[n](
    final C=CInt, each T(start=T_start)) "vector of capacitors"

protected
  Modelica.Thermal.HeatTransfer.Components.ThermalResistor thermResInt[n](
    final R=RInt) "vector of resistors connecting port and capacitors"

equation
  // Connecting inner elements thermResInt[i]--thermCapInt[i] to n groups
  for i in 1:n loop
    connect(thermResInt[i].port_b,thermCapInt[i].port)
  end for;
  // Connecting groups between each other thermCapInt[i] -- thermResInt[i+1]
  for i in 1:n-1 loop
    connect(thermCapInt[i].port,thermResInt[i+1].port_a)
  end for;
  // Connecting first RC element to port_a port_a--thermResInt[1]
  connect(port_a,thermResInt[1].port_a)
end InteriorWall;


Package with base classes for ROM

within Buildings.ThermalZones.ReducedOrder.RC;
package BaseClasses "Package with base classes for ROM"
  extends Modelica.Icons.BasesPackage;
end BaseClasses;


A simple model which weights a given set of thermal inputs
  to calculate an average temperature and aggregated heat flow per output. This model is used to weight thermal ports (inputs) according to given split
  factors per output port.

within Buildings.ThermalZones.ReducedOrder.RC.BaseClasses;
model ThermSplitter "A simple model which weights a given set of thermal inputs
  to calculate an average temperature and aggregated heat flow per output"

  parameter Integer nOut "Number of splitter outputs";
  parameter Integer nIn "Number of splitter inputs";
  parameter Real splitFactor[nOut, nIn]= fill(1/nOut, nOut, nIn)
    "Matrix of split factor for outputs (between 0 and 1 for each row)";
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a portIn[nIn]
    "Single thermal input"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a portOut[nOut]
    "Set of thermal outputs"

equation
  portOut.Q_flow = - portIn.Q_flow * transpose(splitFactor)
    "Connecting the output vector according to desired dimension";

  portIn.T = portOut.T * splitFactor
    "Equivalent building temperature rerouted to SignalInput";
end ThermSplitter;


Double pane window solar correction. This model computes short-wave radiation through
  transparent elements with any orientation and inclination by means of
  solar transmission correction factors. Transmission properties of transparent
  elements are in general dependent on the solar incidence angle. To take this
  dependency into account, correction factors can be multiplied with the solar
  radiation. These factors should not be mistaken as calculation of solar
  radiation on tilted surfaces, calculation of <i>g</i>-values or consideration of
  sunblinds, as it is an additional step. The implemented calculations are
  defined in the German Guideline VDI 6007 Part 3 (VDI, 2015). The given model
  is only valid for double pane windows. The guideline describes also
  calculations for single pane and triple pane windows.

within Buildings.ThermalZones.ReducedOrder.SolarGain;
model CorrectionGDoublePane
  "Double pane window solar correction"
  extends BaseClasses.PartialCorrectionG;
  import con = Modelica.Units.Conversions;

  // Parameters for the transmission correction factor based on VDI 6007 Part 3
  // A0 to A6 are experimental constants VDI 6007 Part 3 page 20
protected
  parameter Real A0=0.918 "Constant 0 to calculate reference transmission";
  parameter Real A1=2.21*10^(-4)
    "Constant 1 to calculate reference transmission";
  parameter Real A2=-2.75*10^(-5)
    "Constant 2 to calculate reference transmission";
  parameter Real A3=-3.82*10^(-7)
    "Constant 3 to calculate reference transmission";
  parameter Real A4=5.83*10^(-8)
    "Constant 4 to calculate reference transmission";
  parameter Real A5=-1.15*10^(-9)
    "Constant 5 to calculate reference transmission";
  parameter Real A6=4.74*10^(-12)
    "Constant 6 to calculate reference transmission";
  parameter Modelica.Units.SI.TransmissionCoefficient g_dir0=0.7537 "Reference vertical parallel transmission coefficient for direct radiation
    for double pane window";
  parameter Modelica.Units.SI.TransmissionCoefficient Ta_diff=0.84 "Energetic degree of transmission for diffuse radiation for uniformly
    overcast sky";
  parameter Modelica.Units.SI.TransmissionCoefficient Tai_diff=0.903
    "Pure degree of transmission for diffuse radiation";
  parameter Modelica.Units.SI.TransmissionCoefficient Ta1_diff=Ta_diff*Tai_diff
    "Degreee of transmission for single pane window";
  parameter Modelica.Units.SI.ReflectionCoefficient rho_T1_diff=1 - (Ta_diff)
    "Part of degree of transmission for single pane window related to Ta1_diff";
  parameter Modelica.Units.SI.ReflectionCoefficient rho_11_diff=rho_T1_diff/(2
       - (rho_T1_diff)) "Part of degree of transmission for single pane window
    related to rho_T1_diff";
  parameter Modelica.Units.SI.ReflectionCoefficient rho_1_diff=rho_11_diff + ((
      (1 - rho_11_diff)*Tai_diff)^2*rho_11_diff)/(1 - (rho_11_diff*Tai_diff)^2)
    "Degree of reflection for single pane window";
  parameter Modelica.Units.SI.ReflectionCoefficient XN2_diff=1 - rho_1_diff^2
    "Calculation factor to simplify equations";
  parameter Modelica.Units.SI.TransmissionCoefficient Ta2_diff=(Ta1_diff^2)/
      XN2_diff "Energetic dregree of transmission for second pane";
  parameter Modelica.Units.SI.Emissivity a1_diff=1 - Ta1_diff - rho_1_diff
    "Degree of absorption for single pane window";
  parameter Real Q21_diff=a1_diff*(1 + (
      Ta1_diff*rho_1_diff/XN2_diff))*UWin/25
    "Auxiliary parameter for heat transfer of exterior pane of double pane window";
  parameter Real Q22_diff=a1_diff*(
      Ta1_diff/XN2_diff)*(1 - (UWin/7.7))
    "Auxiliary parameter for heat transfer of interior pane of double pane window";
  parameter Real Qsek2_diff=Q21_diff + Q22_diff
    "Overall auxiliary parameter for heat transfer of double pane window";
  parameter Modelica.Units.SI.TransmissionCoefficient CorG_diff=(Ta2_diff +
      Qsek2_diff)/g_dir0
    "Transmission coefficient correction factor for diffuse radiation";
  parameter Modelica.Units.SI.TransmissionCoefficient CorG_gr=(Ta2_diff +
      Qsek2_diff)/g_dir0
    "Transmission coefficient correction factor for irradiations from ground";

  //Calculating the correction factor for direct solar radiation
  Modelica.Units.SI.TransmissionCoefficient[n] Ta_dir
    "Energetic degree of transmission for direct radiation";
  Modelica.Units.SI.TransmissionCoefficient[n] Tai_dir
    "Pure degree of transmission for direct radiation";
  Modelica.Units.SI.TransmissionCoefficient[n] Ta1_dir
    "Pure degree of transmission for single pane window";
  Modelica.Units.SI.ReflectionCoefficient[n] rho_T1_dir
    "Part of degree of transmission for single pane window related to Ta1_dir";
  Modelica.Units.SI.ReflectionCoefficient[n] rho_11_dir
    "Part of degree of transmission for single pane window related to T1_dir";
  Modelica.Units.SI.ReflectionCoefficient[n] rho_1_dir
    "Degree of reflection for single pane window";
  Modelica.Units.SI.ReflectionCoefficient[n] XN2_dir
    "Calculation factor to simplify equations";
  Modelica.Units.SI.TransmissionCoefficient[n] Ta2_dir
    "Energetic dregree of transmission for second pane";
  Modelica.Units.SI.Emissivity[n] a1_dir
    "Degree of absorption for single pane window";
  Real[n] Q21_dir
    "Coefficient of heat transfer for exterior pane of double pane window";
  Real[n] Q22_dir
    "Coefficient of heat transfer for interior pane of double pane window";
  Real[n] Qsek2_dir
    "Overall coefficient of heat transfer for double pane window";
  Modelica.Units.SI.TransmissionCoefficient[n] CorG_dir
    "Transmission coefficient correction factor for direct radiation";

equation
  for i in 1:n loop
    Ta_dir[i]= (((((A6*con.to_deg(inc[i])+A5)*con.to_deg(inc[i])+A4)*con.to_deg(inc[i])+A3)*
    con.to_deg(inc[i])+A2)*con.to_deg(inc[i])+A1)*con.to_deg(inc[i])+A0;
    Tai_dir[i]= 0.907^(1/sqrt(1-(sin(inc[i])/1.515)^2));
    Ta1_dir[i]= Ta_dir[i]*Tai_dir[i];
    rho_T1_dir[i]= 1-Ta_dir[i];
    rho_11_dir[i]= rho_T1_dir[i]/(2-rho_T1_dir[i]);
    rho_1_dir[i]=rho_11_dir[i]+(((1-rho_11_dir[i])*Tai_dir[i])^2*rho_11_dir[i])/
    (1-(rho_11_dir[i]*Tai_dir[i])^2);
    a1_dir[i]= 1-Ta1_dir[i]-rho_1_dir[i];
    XN2_dir[i]= 1+10^(-20)-rho_1_dir[i]^2;
    Q21_dir[i]=a1_dir[i]*(1+(Ta1_dir[i]*rho_1_dir[i]/XN2_dir[i]))*UWin/25;
    Q22_dir[i]= a1_dir[i]*(Ta1_dir[i]/XN2_dir[i])*(1-(UWin/7.7));
    Qsek2_dir[i]=Q21_dir[i]+Q22_dir[i];
    Ta2_dir[i]= Ta1_dir[i]^2/XN2_dir[i];
    CorG_dir[i]= (Ta2_dir[i]+Qsek2_dir[i])/g_dir0;

    //Calculating the input thermal energy due to solar radiation
    solarRadWinTrans[i] = ((HDirTil[i]*CorG_dir[i])+(HSkyDifTil[i]*CorG_diff)+
    (HGroDifTil[i]*CorG_gr));
  end for;
end CorrectionGDoublePane;


within Buildings.ThermalZones.ReducedOrder;
package SolarGain "Package with models for solar gain corrections according to VDI 6007 Part 3"
  extends Modelica.Icons.VariantsPackage;
end SolarGain;


Package with base classes for SolarGain

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


Partial model for correction of the solar gain factor. Partial model for correction factors for transmitted solar radiation
  through a transparent element.

within Buildings.ThermalZones.ReducedOrder.SolarGain.BaseClasses;
partial model PartialCorrectionG
  "Partial model for correction of the solar gain factor"

  parameter Integer n(min = 1) "Vector size for input and output";
  parameter Modelica.Units.SI.CoefficientOfHeatTransfer UWin
    "Thermal transmission coefficient of whole window";

  Modelica.Blocks.Interfaces.RealInput HSkyDifTil[n](
    each final quantity="RadiantEnergyFluenceRate",
    each final unit="W/m2")
    "Hemispherical diffuse solar irradiation on a tilted surface from the sky"
  Modelica.Blocks.Interfaces.RealInput HDirTil[n](
    each final quantity="RadiantEnergyFluenceRate",
    each final unit="W/m2")
    "Direct solar radiation on a tilted surface per unit area"
  Modelica.Blocks.Interfaces.RealInput HGroDifTil[n](
    each final quantity="RadiantEnergyFluenceRate",
    each final unit="W/m2")
    "Hemispherical diffuse solar irradiation on a tilted surface from the ground"
  Modelica.Blocks.Interfaces.RealInput inc[n](
    each final quantity="Angle",
    each final unit="rad",
    each displayUnit="deg") "Incidence angles"
  Modelica.Blocks.Interfaces.RealOutput solarRadWinTrans[n](
    each final quantity="RadiantEnergyFluenceRate",
    each final unit="W/m2") "transmitted solar radiation through windows"
end PartialCorrectionG;


Collection of validation models

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


Validation model that checks whether all weather data is set to a constant. This model validates that the RC network model starts at and remains at exactly <i>20</i>°C
if there is no solar radiation and constant outdoor conditions.

within Buildings.ThermalZones.ReducedOrder.Validation;
model RoomSteadyState
  "Validation model that checks whether all weather data is set to a constant"
  extends ThermalZones.ReducedOrder.Examples.SimpleRoomOneElement(
    weaDat(
      pAtmSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      ceiHeiSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      totSkyCovSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      opaSkyCovSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      TDryBulSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      TDewPoiSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      TBlaSkySou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      TBlaSky=293.15,
      relHumSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      winSpeSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      winDirSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      HInfHorSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
      HSou=Buildings.BoundaryConditions.Types.RadiationDataSource.Input_HGloHor_HDifHor),
    intGai(table=[0,0,0,0; 86400,0,0,0]),
    thermalZoneOneElement(T_start=293.15));

  Modelica.Blocks.Sources.Constant zer(k=0) "Zero input signal"
equation
  connect(zer.y, weaDat.HDifHor_in)
  connect(zer.y, weaDat.HGloHor_in)
end RoomSteadyState;


within Buildings.ThermalZones.ReducedOrder.Validation;
model RoomWithLatentGain
  "Test case based on VDI 6007 Case 12, with latent heat gain added"
  extends VDI6007.TestCase12(
    redeclare package Medium = Buildings.Media.Air,
    thermalZoneTwoElements(use_moisture_balance=true,
    nPorts=4,
    VAir=52.5),
    assEqu(
      startTime=0,
      endTime=0,
      startTime2=0,
      endTime2=0,
      startTime3=0,
      endTime3=0));
  Fluid.Sensors.RelativeHumidity senRelHum(
    redeclare package Medium = Medium,
    warnAboutOnePortConnection = false)
    "Relative humidity of room air"
  Fluid.Sensors.MassFraction senMasFra(
    redeclare package Medium = Medium,
    warnAboutOnePortConnection = false)
    "Absolute humidity of room air in kg/kg total air"
equation
  connect(senRelHum.port, thermalZoneTwoElements.ports[3])
  connect(senMasFra.port, thermalZoneTwoElements.ports[4])
  connect(intGai.y[2], thermalZoneTwoElements.QLat_flow)
end RoomWithLatentGain;


within Buildings.ThermalZones.ReducedOrder.Validation;
model RoomWithoutLatentGain
  "Test case based on VDI 6007 Case 12, with zero latent heat gain added"
  extends VDI6007.TestCase12(
    redeclare package Medium = Buildings.Media.Air,
    thermalZoneTwoElements(
      use_moisture_balance=true,
      nPorts=4,
      VAir=52.5),
    assEqu(
      startTime=0,
      endTime=0,
      startTime2=0,
      endTime2=0,
      startTime3=0,
      endTime3=0));
  Modelica.Blocks.Sources.Constant QLat_flow(k=0) "Zero latent heat gain"
  Fluid.Sensors.RelativeHumidity senRelHum(
    redeclare package Medium = Medium,
    warnAboutOnePortConnection = false)
    "Relative humidity of room air"
  Fluid.Sensors.MassFraction senMasFra(
    redeclare package Medium = Medium,
    warnAboutOnePortConnection = false)
    "Absolute humidity of room air in kg/kg total air"
equation
  connect(QLat_flow.y, thermalZoneTwoElements.QLat_flow)
  connect(senRelHum.port, thermalZoneTwoElements.ports[3])
  connect(senMasFra.port, thermalZoneTwoElements.ports[4])
end RoomWithoutLatentGain;


Validation according to VDI 6007-1

within Buildings.ThermalZones.ReducedOrder.Validation;
package VDI6007 "Validation according to VDI 6007-1"
  extends Modelica.Icons.ExamplesPackage;
end VDI6007;


VDI 6007 Test Case 1 model

within Buildings.ThermalZones.ReducedOrder.Validation.VDI6007;
model TestCase1 "VDI 6007 Test Case 1 model"
  extends Modelica.Icons.Example;

  RC.TwoElements thermalZoneTwoElements(
    redeclare package Medium = Modelica.Media.Air.SimpleAir,
    hConExt=2.7,
    hConWin=2.7,
    gWin=1,
    nExt=1,
    hRad=5,
    nInt=1,
    ratioWinConRad=0,
    AInt=75.5,
    hConInt=2.24,
    RWin=0.00000001,
    RExt={0.00436791293674},
    RExtRem=0.03895919557,
    CExt={1600848.94},
    RInt={0.000595693407511},
    CInt={14836354.6282},
    VAir=0,
    nOrientations=1,
    AWin={0},
    ATransparent={0},
    AExt={10.5},
    extWallRC(thermCapExt(each der_T(fixed=true))),
    intWallRC(thermCapInt(each der_T(fixed=true))),
    T_start=295.15)
    "Thermal zone"
  Buildings.HeatTransfer.Sources.FixedTemperature preTem(T=295.15)
    "Outdoor air temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection theConWall
    "Outdoor convective heat transfer"
  Modelica.Blocks.Sources.CombiTimeTable intGai(
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    table=[0,0; 3600,0; 7200,0; 10800,0; 14400,0; 18000,0; 21600,0; 21600,1000;
        25200,1000; 28800,1000; 32400,1000; 36000,1000; 39600,1000; 43200,1000;
        46800,1000; 50400,1000; 54000,1000; 57600,1000; 61200,1000; 64800,1000;
        64800,0; 68400,0; 72000,0; 75600,0; 79200,0; 82800,0; 86400,0],
    columns={2})
    "Table with internal gains"
  Modelica.Blocks.Sources.CombiTimeTable reference(
    tableOnFile=false,
    columns={2},
    extrapolation=Modelica.Blocks.Types.Extrapolation.HoldLastPoint,
    smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments,
    offset={273.15},
    table=[0,22; 3600,22; 7200,22; 10800,22; 14400,22; 18000,22; 21600,22;
        25200,27.7; 28800,27.9; 32400,28.1; 36000,28.4; 39600,28.6; 43200,28.8;
        46800,29; 50400,29.2; 54000,29.4; 57600,29.6; 61200,29.8; 64800,30;
        68400,24.5; 72000,24.5; 75600,24.5; 79200,24.5; 82800,24.5; 86400,24.5;
        781200,37.7; 784800,37.6; 788400,37.5; 792000,37.5; 795600,37.4; 799200,
        37.3; 802800,43; 806400,43.2; 810000,43.3; 813600,43.5; 817200,43.6;
        820800,43.8; 824400,43.9; 828000,44.1; 831600,44.3; 835200,44.4; 838800,
        44.6; 842400,44.7; 846000,39.1; 849600,39.1; 853200,39; 856800,38.9;
        860400,38.9; 864000,38.8; 5101200,49.9; 5104800,49.8; 5108400,49.7;
        5112000,49.6; 5115600,49.4; 5119200,49.3; 5122800,54.9; 5126400,55.1;
        5130000,55.2; 5133600,55.3; 5137200,55.4; 5140800,55.5; 5144400,55.6;
        5148000,55.7; 5151600,55.8; 5155200,55.9; 5158800,56.1; 5162400,56.2;
        5166000,50.6; 5169600,50.4; 5173200,50.3; 5176800,50.2; 5180400,50.1;
        5184000,50])
    "Reference results"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow macConv
    "Convective heat flow machines"
  Modelica.Blocks.Sources.Constant hConWall(k=25*10.5)
    "Outdoor coefficient of heat transfer for walls"
  Modelica.Blocks.Sources.Constant const(k=0)
    "Solar radiation"
  BaseClasses.VerifyDifferenceThreePeriods assEqu(
    startTime=3600,
    endTime=86400,
    startTime2=781200,
    endTime2=864000,
    startTime3=5101200,
    endTime3=5184000,
    threShold=0.15)
    "Checks validation criteria"
  Modelica.Blocks.Math.Mean mean(f=1/3600)
    "Hourly mean of indoor air temperature"
equation
  connect(theConWall.fluid, preTem.port)
  connect(thermalZoneTwoElements.extWall, theConWall.solid)
  connect(hConWall.y, theConWall.Gc)
  connect(intGai.y[1], macConv.Q_flow)
  connect(thermalZoneTwoElements.intGainsConv, macConv.port)
  connect(const.y, thermalZoneTwoElements.solRad[1])
  connect(thermalZoneTwoElements.TAir, mean.u)
  connect(mean.y, assEqu.u2)
  connect(reference.y[1], assEqu.u1)
end TestCase1;


VDI 6007 Test Case 10 model