within Buildings.DHC.Loads.BaseClasses.Examples.BaseClasses.GeojsonExportRC.OfficeBuilding;
model Meeting
  "This is the simulation model of Meeting within building OfficeBuilding"
  Buildings.BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil[6](
    each outSkyCon=true,
    each outGroCon=true,
    til={1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949,0,0},
    azi={3.1415926535898,0,1.5707963267949,-1.5707963267949,0,0})
    "Calculates diffuse solar radiation on titled surface for all directions"
  Buildings.BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[6](til={
        1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949,0,0},
      azi={3.1415926535898,0,1.5707963267949,-1.5707963267949,0,0})
    "Calculates direct solar radiation on titled surface for all directions"
  Buildings.ThermalZones.ReducedOrder.SolarGain.CorrectionGDoublePane corGDoublePane(
    n=6,
    UWin=1.8936557576825384)
    "Correction factor for solar transmission"
  Buildings.ThermalZones.ReducedOrder.RC.TwoElements thermalZoneTwoElements(
    redeclare package Medium=Buildings.Media.Air,
    VAir=521.8867414172162,
    hConExt=2.0490178828959125,
    hConWin=2.7000000000000006,
    gWin=0.6700000000000002,
    ratioWinConRad=0.030000000000000002,
    nExt=1,
    RExt={0.00014484269741541823},
    CExt={65319165.36689455},
    hRad=5.000000000000001,
    AInt=514.606606548608,
    hConInt=2.207073495341845,
    nInt=1,
    RInt={0.0001055947003212644},
    CInt={74230169.14357185},
    RWin=0.013742118823297953,
    RExtRem=0.007828793990537798,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    extWallRC(
      thermCapExt(
        each der_T(
          fixed=true))),
    intWallRC(
      thermCapInt(
        each der_T(
          fixed=true))),
    nOrientations=6,
    AWin={11.92763144924453,11.92763144924453,1.1056190934805288,1.1056190934805288,0.0,0.0},
    ATransparent={11.92763144924453,11.92763144924453,1.1056190934805288,1.1056190934805288,0.0,0.0},
    AExt={35.782894347733595,35.782894347733595,3.316857280441586,3.316857280441586,72.92818030400002,72.92818030400002})
    "Thermal zone"
  Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature.VDI6007WithWindow eqAirTemp(
    n=6,
    wfGro=0.3626976838332763,
    wfWall={0.15582361279765056,0.15582361279765056,0.014443903825944524,0.014443903825944524,0.2967672829195336,0.0},
    wfWin={0.45758467583140006,0.45758467583140006,0.04241532416859994,0.04241532416859994,0.0,0.0},
    withLongwave=true,
    aExt=0.5,
    hConWallOut=20.0,
    hRad=5.0,
    hConWinOut=20.0,
    TGro=286.15)
    "Computes equivalent air temperature"
  Modelica.Blocks.Math.Add solRad[6]
    "Sums up solar radiation of both directions"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature prescribedTemperature
    "Prescribed temperature for exterior walls outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature prescribedTemperature1
    "Prescribed temperature for windows outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection thermalConductorWin
    "Outdoor convective heat transfer of windows"
  Modelica.Thermal.HeatTransfer.Components.Convection thermalConductorWall
    "Outdoor convective heat transfer of walls"
  Modelica.Blocks.Sources.Constant const[6](
    each k=0)
    "Sets sunblind signal to zero (open)"
  Buildings.BoundaryConditions.WeatherData.Bus weaBus
    "Weather data bus"
  Modelica.Blocks.Sources.Constant hConWall(
    k=25.000000000000004*224.0558638643504)
    "Outdoor coefficient of heat transfer for walls"
  Modelica.Blocks.Sources.Constant hConWin(
    k=24.999999999999996*26.066501085450113)
    "Outdoor coefficient of heat transfer for windows"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow personsRad
    "Radiative heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow personsConv
    "Convective heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow machinesConv
    "Convective heat flow of machines"
  Modelica.Blocks.Sources.CombiTimeTable internalGains(
    tableOnFile=true,
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    tableName="Internals",
    fileName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/DHC/Loads/Examples/BaseClasses/GeojsonExportRC/OfficeBuilding/InternalGains_Meeting.txt"),
    columns={2,3,4})
    "Table with profiles for persons (radiative and convective) and machines (convective)"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a port_a
    "Heat port for sensible convective gains"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TAir(
    quantity="ThermodynamicTemperature",
    unit="K",
    displayUnit="degC")
    "Room air temperature"
equation
  connect(eqAirTemp.TEqAirWin,prescribedTemperature1.T)
  connect(eqAirTemp.TEqAir,prescribedTemperature.T)
  connect(weaBus.TDryBul,eqAirTemp.TDryBul)
  connect(internalGains.y[1],personsRad.Q_flow)
  connect(internalGains.y[2],personsConv.Q_flow)
  connect(internalGains.y[3],machinesConv.Q_flow)
  connect(const.y,eqAirTemp.sunblind)
  connect(HDifTil.HSkyDifTil,corGDoublePane.HSkyDifTil)
  connect(HDirTil.H,corGDoublePane.HDirTil)
  connect(HDirTil.H,solRad.u1)
  connect(HDirTil.inc,corGDoublePane.inc)
  connect(HDifTil.H,solRad.u2)
  connect(HDifTil.HGroDifTil,corGDoublePane.HGroDifTil)
  connect(solRad.y,eqAirTemp.HSol)
  connect(weaBus,HDifTil[1].weaBus)
  connect(weaBus,HDirTil[1].weaBus)
  connect(weaBus,HDifTil[2].weaBus)
  connect(weaBus,HDirTil[2].weaBus)
  connect(weaBus,HDifTil[3].weaBus)
  connect(weaBus,HDirTil[3].weaBus)
  connect(weaBus,HDifTil[4].weaBus)
  connect(weaBus,HDirTil[4].weaBus)
  connect(weaBus,HDifTil[5].weaBus)
  connect(weaBus,HDirTil[5].weaBus)
  connect(weaBus,HDifTil[6].weaBus)
  connect(weaBus,HDirTil[6].weaBus)
  connect(personsRad.port,thermalZoneTwoElements.intGainsRad)
  connect(thermalConductorWin.solid,thermalZoneTwoElements.window)
  connect(prescribedTemperature1.port,thermalConductorWin.fluid)
  connect(thermalZoneTwoElements.extWall,thermalConductorWall.solid)
  connect(thermalConductorWall.fluid,prescribedTemperature.port)
  connect(hConWall.y,thermalConductorWall.Gc)
  connect(hConWin.y,thermalConductorWin.Gc)
  connect(weaBus.TBlaSky,eqAirTemp.TBlaSky)
  connect(machinesConv.port,thermalZoneTwoElements.intGainsConv)
  connect(personsConv.port,thermalZoneTwoElements.intGainsConv)
  connect(corGDoublePane.solarRadWinTrans,thermalZoneTwoElements.solRad)
  connect(port_a,thermalZoneTwoElements.intGainsConv)
  connect(thermalZoneTwoElements.TAir,TAir)
end Meeting;


within Buildings.DHC.Loads.BaseClasses.Examples.BaseClasses.GeojsonExportRC.OfficeBuilding;
model Office
  "This is the simulation model of Office within building OfficeBuilding"
  Buildings.BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil[6](
    each outSkyCon=true,
    each outGroCon=true,
    til={1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949,0,0},
    azi={3.1415926535898,0,1.5707963267949,-1.5707963267949,0,0})
    "Calculates diffuse solar radiation on titled surface for all directions"
  Buildings.BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[6](til={
        1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949,0,0},
      azi={3.1415926535898,0,1.5707963267949,-1.5707963267949,0,0})
    "Calculates direct solar radiation on titled surface for all directions"
  Buildings.ThermalZones.ReducedOrder.SolarGain.CorrectionGDoublePane corGDoublePane(
    n=6,
    UWin=1.8936557576825381)
    "Correction factor for solar transmission"
  Buildings.ThermalZones.ReducedOrder.RC.TwoElements thermalZoneTwoElements(
    redeclare package Medium=Buildings.Media.Air,
    VAir=6523.584267715201,
    hConExt=2.0490178828959134,
    hConWin=2.7000000000000006,
    gWin=0.6699999999999999,
    ratioWinConRad=0.029999999999999995,
    nExt=1,
    RExt={1.1587415793233466e-05},
    CExt={816489567.0861814},
    hRad=4.999999999999999,
    AInt=6432.582581857601,
    hConInt=2.2070734953418447,
    nInt=1,
    RInt={8.447576025701151e-06},
    CInt={927877114.2946483},
    RWin=0.001099369505863836,
    RExtRem=0.0006263035192430239,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    extWallRC(
      thermCapExt(
        each der_T(
          fixed=true))),
    intWallRC(
      thermCapInt(
        each der_T(
          fixed=true))),
    nOrientations=6,
    AWin={149.09539311555662,149.09539311555662,13.82023866850661,13.82023866850661,0.0,0.0},
    ATransparent={149.09539311555662,149.09539311555662,13.82023866850661,13.82023866850661,0.0,0.0},
    AExt={447.28617934666994,447.28617934666994,41.46071600551983,41.46071600551983,911.6022538000002,911.6022538000002})
    "Thermal zone"
  Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature.VDI6007WithWindow eqAirTemp(
    n=6,
    wfGro=0.3626976838332763,
    wfWall={0.15582361279765053,0.15582361279765053,0.014443903825944522,0.014443903825944522,0.2967672829195336,0.0},
    wfWin={0.4575846758314001,0.4575846758314001,0.04241532416859994,0.04241532416859994,0.0,0.0},
    withLongwave=true,
    aExt=0.5,
    hConWallOut=20.0,
    hRad=5.0,
    hConWinOut=20.0,
    TGro=286.15)
    "Computes equivalent air temperature"
  Modelica.Blocks.Math.Add solRad[6]
    "Sums up solar radiation of both directions"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature prescribedTemperature
    "Prescribed temperature for exterior walls outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature prescribedTemperature1
    "Prescribed temperature for windows outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection thermalConductorWin
    "Outdoor convective heat transfer of windows"
  Modelica.Thermal.HeatTransfer.Components.Convection thermalConductorWall
    "Outdoor convective heat transfer of walls"
  Modelica.Blocks.Sources.Constant const[6](
    each k=0)
    "Sets sunblind signal to zero (open)"
  Buildings.BoundaryConditions.WeatherData.Bus weaBus
    "Weather data bus"
  Modelica.Blocks.Sources.Constant hConWall(
    k=25.0*2800.69829830438)
    "Outdoor coefficient of heat transfer for walls"
  Modelica.Blocks.Sources.Constant hConWin(
    k=25.0*325.8312635681265)
    "Outdoor coefficient of heat transfer for windows"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow personsRad
    "Radiative heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow personsConv
    "Convective heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow machinesConv
    "Convective heat flow of machines"
  Modelica.Blocks.Sources.CombiTimeTable internalGains(
    tableOnFile=true,
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    tableName="Internals",
    fileName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/DHC/Loads/Examples/BaseClasses/GeojsonExportRC/OfficeBuilding/InternalGains_Office.txt"),
    columns={2,3,4})
    "Table with profiles for persons (radiative and convective) and machines (convective)"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a port_a
    "Heat port for sensible convective gains"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TAir(
    quantity="ThermodynamicTemperature",
    unit="K",
    displayUnit="degC")
    "Room air temperature"
equation
  connect(eqAirTemp.TEqAirWin,prescribedTemperature1.T)
  connect(eqAirTemp.TEqAir,prescribedTemperature.T)
  connect(weaBus.TDryBul,eqAirTemp.TDryBul)
  connect(internalGains.y[1],personsRad.Q_flow)
  connect(internalGains.y[2],personsConv.Q_flow)
  connect(internalGains.y[3],machinesConv.Q_flow)
  connect(const.y,eqAirTemp.sunblind)
  connect(HDifTil.HSkyDifTil,corGDoublePane.HSkyDifTil)
  connect(HDirTil.H,corGDoublePane.HDirTil)
  connect(HDirTil.H,solRad.u1)
  connect(HDirTil.inc,corGDoublePane.inc)
  connect(HDifTil.H,solRad.u2)
  connect(HDifTil.HGroDifTil,corGDoublePane.HGroDifTil)
  connect(solRad.y,eqAirTemp.HSol)
  connect(weaBus,HDifTil[1].weaBus)
  connect(weaBus,HDirTil[1].weaBus)
  connect(weaBus,HDifTil[2].weaBus)
  connect(weaBus,HDirTil[2].weaBus)
  connect(weaBus,HDifTil[3].weaBus)
  connect(weaBus,HDirTil[3].weaBus)
  connect(weaBus,HDifTil[4].weaBus)
  connect(weaBus,HDirTil[4].weaBus)
  connect(weaBus,HDifTil[5].weaBus)
  connect(weaBus,HDirTil[5].weaBus)
  connect(weaBus,HDifTil[6].weaBus)
  connect(weaBus,HDirTil[6].weaBus)
  connect(personsRad.port,thermalZoneTwoElements.intGainsRad)
  connect(thermalConductorWin.solid,thermalZoneTwoElements.window)
  connect(prescribedTemperature1.port,thermalConductorWin.fluid)
  connect(thermalZoneTwoElements.extWall,thermalConductorWall.solid)
  connect(thermalConductorWall.fluid,prescribedTemperature.port)
  connect(hConWall.y,thermalConductorWall.Gc)
  connect(hConWin.y,thermalConductorWin.Gc)
  connect(weaBus.TBlaSky,eqAirTemp.TBlaSky)
  connect(machinesConv.port,thermalZoneTwoElements.intGainsConv)
  connect(personsConv.port,thermalZoneTwoElements.intGainsConv)
  connect(corGDoublePane.solarRadWinTrans,thermalZoneTwoElements.solRad)
  connect(port_a,thermalZoneTwoElements.intGainsConv)
  connect(thermalZoneTwoElements.TAir,TAir)
end Office;


Package with RC building zone models

within Buildings.DHC.Loads.BaseClasses.Examples.BaseClasses.GeojsonExportRC;
package OfficeBuilding "Package with RC building zone models"
  extends Modelica.Icons.Package;
end OfficeBuilding;


within Buildings.DHC.Loads.BaseClasses.Examples.BaseClasses.GeojsonExportRC.OfficeBuilding;
model Restroom
  "This is the simulation model of Restroom within building OfficeBuilding"
  Buildings.BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil[6](
    each outSkyCon=true,
    each outGroCon=true,
    til={1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949,0,0},
    azi={3.1415926535898,0,1.5707963267949,-1.5707963267949,0,0})
    "Calculates diffuse solar radiation on titled surface for all directions"
  Buildings.BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[6](til={
        1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949,0,0},
      azi={3.1415926535898,0,1.5707963267949,-1.5707963267949,0,0})
    "Calculates direct solar radiation on titled surface for all directions"
  Buildings.ThermalZones.ReducedOrder.SolarGain.CorrectionGDoublePane corGDoublePane(
    n=6,
    UWin=1.8936557576825384)
    "Correction factor for solar transmission"
  Buildings.ThermalZones.ReducedOrder.RC.TwoElements thermalZoneTwoElements(
    redeclare package Medium=Buildings.Media.Air,
    VAir=521.8867414172162,
    hConExt=2.0490178828959125,
    hConWin=2.7000000000000006,
    gWin=0.6700000000000002,
    ratioWinConRad=0.030000000000000002,
    nExt=1,
    RExt={0.00014484269741541823},
    CExt={65319165.36689455},
    hRad=5.000000000000001,
    AInt=688.5688536876802,
    hConInt=2.3316080309449254,
    nInt=1,
    RInt={9.201439908964808e-05},
    CInt={84275425.00414628},
    RWin=0.013742118823297953,
    RExtRem=0.007828793990537798,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    extWallRC(
      thermCapExt(
        each der_T(
          fixed=true))),
    intWallRC(
      thermCapInt(
        each der_T(
          fixed=true))),
    nOrientations=6,
    AWin={11.92763144924453,11.92763144924453,1.1056190934805288,1.1056190934805288,0.0,0.0},
    ATransparent={11.92763144924453,11.92763144924453,1.1056190934805288,1.1056190934805288,0.0,0.0},
    AExt={35.782894347733595,35.782894347733595,3.316857280441586,3.316857280441586,72.92818030400002,72.92818030400002})
    "Thermal zone"
  Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature.VDI6007WithWindow eqAirTemp(
    n=6,
    wfGro=0.3626976838332763,
    wfWall={0.15582361279765056,0.15582361279765056,0.014443903825944524,0.014443903825944524,0.2967672829195336,0.0},
    wfWin={0.45758467583140006,0.45758467583140006,0.04241532416859994,0.04241532416859994,0.0,0.0},
    withLongwave=true,
    aExt=0.5,
    hConWallOut=20.0,
    hRad=5.0,
    hConWinOut=20.0,
    TGro=286.15)
    "Computes equivalent air temperature"
  Modelica.Blocks.Math.Add solRad[6]
    "Sums up solar radiation of both directions"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature prescribedTemperature
    "Prescribed temperature for exterior walls outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature prescribedTemperature1
    "Prescribed temperature for windows outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection thermalConductorWin
    "Outdoor convective heat transfer of windows"
  Modelica.Thermal.HeatTransfer.Components.Convection thermalConductorWall
    "Outdoor convective heat transfer of walls"
  Modelica.Blocks.Sources.Constant const[6](
    each k=0)
    "Sets sunblind signal to zero (open)"
  Buildings.BoundaryConditions.WeatherData.Bus weaBus
    "Weather data bus"
  Modelica.Blocks.Sources.Constant hConWall(
    k=25.000000000000004*224.0558638643504)
    "Outdoor coefficient of heat transfer for walls"
  Modelica.Blocks.Sources.Constant hConWin(
    k=24.999999999999996*26.066501085450113)
    "Outdoor coefficient of heat transfer for windows"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow personsRad
    "Radiative heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow personsConv
    "Convective heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow machinesConv
    "Convective heat flow of machines"
  Modelica.Blocks.Sources.CombiTimeTable internalGains(
    tableOnFile=true,
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    tableName="Internals",
    fileName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/DHC/Loads/Examples/BaseClasses/GeojsonExportRC/OfficeBuilding/InternalGains_Restroom.txt"),
    columns={2,3,4})
    "Table with profiles for persons (radiative and convective) and machines (convective)"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a port_a
    "Heat port for sensible convective gains"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TAir(
    quantity="ThermodynamicTemperature",
    unit="K",
    displayUnit="degC")
    "Room air temperature"
equation
  connect(eqAirTemp.TEqAirWin,prescribedTemperature1.T)
  connect(eqAirTemp.TEqAir,prescribedTemperature.T)
  connect(weaBus.TDryBul,eqAirTemp.TDryBul)
  connect(internalGains.y[1],personsRad.Q_flow)
  connect(internalGains.y[2],personsConv.Q_flow)
  connect(internalGains.y[3],machinesConv.Q_flow)
  connect(const.y,eqAirTemp.sunblind)
  connect(HDifTil.HSkyDifTil,corGDoublePane.HSkyDifTil)
  connect(HDirTil.H,corGDoublePane.HDirTil)
  connect(HDirTil.H,solRad.u1)
  connect(HDirTil.inc,corGDoublePane.inc)
  connect(HDifTil.H,solRad.u2)
  connect(HDifTil.HGroDifTil,corGDoublePane.HGroDifTil)
  connect(solRad.y,eqAirTemp.HSol)
  connect(weaBus,HDifTil[1].weaBus)
  connect(weaBus,HDirTil[1].weaBus)
  connect(weaBus,HDifTil[2].weaBus)
  connect(weaBus,HDirTil[2].weaBus)
  connect(weaBus,HDifTil[3].weaBus)
  connect(weaBus,HDirTil[3].weaBus)
  connect(weaBus,HDifTil[4].weaBus)
  connect(weaBus,HDirTil[4].weaBus)
  connect(weaBus,HDifTil[5].weaBus)
  connect(weaBus,HDirTil[5].weaBus)
  connect(weaBus,HDifTil[6].weaBus)
  connect(weaBus,HDirTil[6].weaBus)
  connect(personsRad.port,thermalZoneTwoElements.intGainsRad)
  connect(thermalConductorWin.solid,thermalZoneTwoElements.window)
  connect(prescribedTemperature1.port,thermalConductorWin.fluid)
  connect(thermalZoneTwoElements.extWall,thermalConductorWall.solid)
  connect(thermalConductorWall.fluid,prescribedTemperature.port)
  connect(hConWall.y,thermalConductorWall.Gc)
  connect(hConWin.y,thermalConductorWin.Gc)
  connect(weaBus.TBlaSky,eqAirTemp.TBlaSky)
  connect(machinesConv.port,thermalZoneTwoElements.intGainsConv)
  connect(personsConv.port,thermalZoneTwoElements.intGainsConv)
  connect(corGDoublePane.solarRadWinTrans,thermalZoneTwoElements.solRad)
  connect(port_a,thermalZoneTwoElements.intGainsConv)
  connect(thermalZoneTwoElements.TAir,TAir)
end Restroom;


within Buildings.DHC.Loads.BaseClasses.Examples.BaseClasses.GeojsonExportRC.OfficeBuilding;
model Storage
  "This is the simulation model of Storage within building OfficeBuilding"
  Buildings.BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil[6](
    each outSkyCon=true,
    each outGroCon=true,
    til={1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949,0,0},
    azi={3.1415926535898,0,1.5707963267949,-1.5707963267949,0,0})
    "Calculates diffuse solar radiation on titled surface for all directions"
  Buildings.BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil[6](til={
        1.5707963267949,1.5707963267949,1.5707963267949,1.5707963267949,0,0},
      azi={3.1415926535898,0,1.5707963267949,-1.5707963267949,0,0})
    "Calculates direct solar radiation on titled surface for all directions"
  Buildings.ThermalZones.ReducedOrder.SolarGain.CorrectionGDoublePane corGDoublePane(
    n=6,
    UWin=1.8936557576825388)
    "Correction factor for solar transmission"
  Buildings.ThermalZones.ReducedOrder.RC.TwoElements thermalZoneTwoElements(
    redeclare package Medium=Buildings.Media.Air,
    VAir=1957.0752803145606,
    hConExt=2.049017882895913,
    hConWin=2.7,
    gWin=0.67,
    ratioWinConRad=0.03,
    nExt=1,
    RExt={3.86247193107782e-05},
    CExt={244946870.12585458},
    hRad=4.999999999999999,
    AInt=1929.7747745572801,
    hConInt=2.207073495341845,
    nInt=1,
    RInt={2.8158586752337178e-05},
    CInt={278363134.2883944},
    RWin=0.0036645650195461206,
    RExtRem=0.0020876783974767463,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    extWallRC(
      thermCapExt(
        each der_T(
          fixed=true))),
    intWallRC(
      thermCapInt(
        each der_T(
          fixed=true))),
    nOrientations=6,
    AWin={44.728617934666985,44.728617934666985,4.146071600551982,4.146071600551982,0.0,0.0},
    ATransparent={44.728617934666985,44.728617934666985,4.146071600551982,4.146071600551982,0.0,0.0},
    AExt={134.185853804001,134.185853804001,12.438214801655947,12.438214801655947,273.48067614000007,273.48067614000007})
    "Thermal zone"
  Buildings.ThermalZones.ReducedOrder.EquivalentAirTemperature.VDI6007WithWindow eqAirTemp(
    n=6,
    wfGro=0.36269768383327633,
    wfWall={0.15582361279765056,0.15582361279765056,0.014443903825944526,0.014443903825944526,0.2967672829195335,0.0},
    wfWin={0.4575846758314,0.4575846758314,0.04241532416859994,0.04241532416859994,0.0,0.0},
    withLongwave=true,
    aExt=0.5,
    hConWallOut=20.000000000000004,
    hRad=4.999999999999999,
    hConWinOut=19.999999999999996,
    TGro=286.15)
    "Computes equivalent air temperature"
  Modelica.Blocks.Math.Add solRad[6]
    "Sums up solar radiation of both directions"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature prescribedTemperature
    "Prescribed temperature for exterior walls outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedTemperature prescribedTemperature1
    "Prescribed temperature for windows outdoor surface temperature"
  Modelica.Thermal.HeatTransfer.Components.Convection thermalConductorWin
    "Outdoor convective heat transfer of windows"
  Modelica.Thermal.HeatTransfer.Components.Convection thermalConductorWall
    "Outdoor convective heat transfer of walls"
  Modelica.Blocks.Sources.Constant const[6](
    each k=0)
    "Sets sunblind signal to zero (open)"
  Buildings.BoundaryConditions.WeatherData.Bus weaBus
    "Weather data bus"
  Modelica.Blocks.Sources.Constant hConWall(
    k=25.000000000000004*840.2094894913139)
    "Outdoor coefficient of heat transfer for walls"
  Modelica.Blocks.Sources.Constant hConWin(
    k=25.000000000000004*97.74937907043793)
    "Outdoor coefficient of heat transfer for windows"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow personsRad
    "Radiative heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow personsConv
    "Convective heat flow of persons"
  Modelica.Thermal.HeatTransfer.Sources.PrescribedHeatFlow machinesConv
    "Convective heat flow of machines"
  Modelica.Blocks.Sources.CombiTimeTable internalGains(
    tableOnFile=true,
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    tableName="Internals",
    fileName=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/DHC/Loads/Examples/BaseClasses/GeojsonExportRC/OfficeBuilding/InternalGains_Storage.txt"),
    columns={2,3,4})
    "Table with profiles for persons (radiative and convective) and machines (convective)"
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a port_a
    "Heat port for sensible convective gains"
  Buildings.Controls.OBC.CDL.Interfaces.RealOutput TAir(
    quantity="ThermodynamicTemperature",
    unit="K",
    displayUnit="degC")
    "Room air temperature"
equation
  connect(eqAirTemp.TEqAirWin,prescribedTemperature1.T)
  connect(eqAirTemp.TEqAir,prescribedTemperature.T)
  connect(weaBus.TDryBul,eqAirTemp.TDryBul)
  connect(internalGains.y[1],personsRad.Q_flow)
  connect(internalGains.y[2],personsConv.Q_flow)
  connect(internalGains.y[3],machinesConv.Q_flow)
  connect(const.y,eqAirTemp.sunblind)
  connect(HDifTil.HSkyDifTil,corGDoublePane.HSkyDifTil)
  connect(HDirTil.H,corGDoublePane.HDirTil)
  connect(HDirTil.H,solRad.u1)
  connect(HDirTil.inc,corGDoublePane.inc)
  connect(HDifTil.H,solRad.u2)
  connect(HDifTil.HGroDifTil,corGDoublePane.HGroDifTil)
  connect(solRad.y,eqAirTemp.HSol)
  connect(weaBus,HDifTil[1].weaBus)
  connect(weaBus,HDirTil[1].weaBus)
  connect(weaBus,HDifTil[2].weaBus)
  connect(weaBus,HDirTil[2].weaBus)
  connect(weaBus,HDifTil[3].weaBus)
  connect(weaBus,HDirTil[3].weaBus)
  connect(weaBus,HDifTil[4].weaBus)
  connect(weaBus,HDirTil[4].weaBus)
  connect(weaBus,HDifTil[5].weaBus)
  connect(weaBus,HDirTil[5].weaBus)
  connect(weaBus,HDifTil[6].weaBus)
  connect(weaBus,HDirTil[6].weaBus)
  connect(personsRad.port,thermalZoneTwoElements.intGainsRad)
  connect(thermalConductorWin.solid,thermalZoneTwoElements.window)
  connect(prescribedTemperature1.port,thermalConductorWin.fluid)
  connect(thermalZoneTwoElements.extWall,thermalConductorWall.solid)
  connect(thermalConductorWall.fluid,prescribedTemperature.port)
  connect(hConWall.y,thermalConductorWall.Gc)
  connect(hConWin.y,thermalConductorWin.Gc)
  connect(weaBus.TBlaSky,eqAirTemp.TBlaSky)
  connect(machinesConv.port,thermalZoneTwoElements.intGainsConv)
  connect(personsConv.port,thermalZoneTwoElements.intGainsConv)
  connect(corGDoublePane.solarRadWinTrans,thermalZoneTwoElements.solRad)
  connect(port_a,thermalZoneTwoElements.intGainsConv)
  connect(thermalZoneTwoElements.TAir,TAir)
end Storage;


within Buildings.DHC.Loads.BaseClasses.Validation;
model BenchmarkFlowDistribution1
  "Performance benchmark of building heating water flow distribution modeling"
  extends Modelica.Icons.Example;
  package Medium1=Buildings.Media.Water
    "Source side medium";
  package Medium2=Buildings.Media.Air
    "Load side medium";
  parameter String filNam="modelica://Buildings/Resources/Data/DHC/Loads/Examples/SwissResidential_20190916.mos"
    "File name with thermal loads as time series";
  parameter Integer nLoa=5
    "Number of served loads"
  parameter Modelica.Units.SI.Temperature T_aHeaWat_nominal(
    min=273.15,
    displayUnit="degC") = 273.15 + 40
    "Heating water inlet temperature at nominal conditions"
  parameter Modelica.Units.SI.Temperature T_bHeaWat_nominal(
    min=273.15,
    displayUnit="degC") = T_aHeaWat_nominal - 5
    "Heating water outlet temperature at nominal conditions"
  parameter Modelica.Units.SI.Temperature T_aLoaHea_nominal(
    min=273.15,
    displayUnit="degC") = 273.15 + 20
    "Load side inlet temperature at nominal conditions in heating mode"
  parameter Modelica.Units.SI.MassFlowRate mLoaHea_flow_nominal(min=0) = 1
    "Load side mass flow rate at nominal conditions in heating mode"
  parameter Modelica.Units.SI.PressureDifference dp_nominal=nLoa*1500*2 + 2*500
       + 30000 "Nominal pressure drop in the distribution line";
  parameter Real facMul=10
    "Mulitplier factor for terminal units"
  final parameter Modelica.Units.SI.MassFlowRate m_flow_nominal=sum(ter.mHeaWat_flow_nominal)
      *facMul "Nominal mass flow rate in the distribution line";
  final parameter Modelica.Units.SI.HeatFlowRate QHea_flow_nominal(min=Modelica.Constants.eps)
     = Buildings.DHC.Loads.BaseClasses.getPeakLoad(string=
    "#Peak space heating load", filNam=Modelica.Utilities.Files.loadResource(
    filNam))/facMul "Design heating heat flow rate (>=0)"
  Buildings.DHC.Loads.BaseClasses.FlowDistribution disFloHea(
    redeclare package Medium=Medium1,
    m_flow_nominal=m_flow_nominal,
    have_pum=true,
    dp_nominal=dp_nominal,
    nPorts_a1=nLoa,
    nPorts_b1=nLoa)
    "Heating water distribution system"
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.FanCoil2PipeHeating ter[nLoa](
    each final facMul=facMul,
    redeclare each final package Medium1=Medium1,
    redeclare each final package Medium2=Medium2,
    each final QHea_flow_nominal=QHea_flow_nominal,
    each final mLoaHea_flow_nominal=mLoaHea_flow_nominal,
    each final T_aHeaWat_nominal=T_aHeaWat_nominal,
    each final T_bHeaWat_nominal=T_bHeaWat_nominal,
    each final T_aLoaHea_nominal=T_aLoaHea_nominal)
    "Heating terminal unit"
  Modelica.Blocks.Sources.CombiTimeTable loa(
    tableOnFile=true,
    tableName="tab1",
    fileName=Modelica.Utilities.Files.loadResource(
      filNam),
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    y(each unit="W"),
    offset={0,0,0},
    columns={2,3,4},
    smoothness=Modelica.Blocks.Types.Smoothness.MonotoneContinuousDerivative1)
    "Reader for thermal loads (y[1] is cooling load, y[2] is heating load)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minTSet(
    k=293.15,
    y(final unit="K",
      displayUnit="degC"))
    "Minimum temperature set point"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator reaRep(
    nout=nLoa)
    "Repeat input to output an array"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator reaRep1(
    nout=nLoa)
    "Repeat input to output an array"
  Fluid.Sources.Boundary_pT supHeaWat(
    redeclare package Medium=Medium1,
    use_T_in=true,
    nPorts=1)
    "Heating water supply"
  Fluid.Sources.Boundary_pT sinHeaWat(
    redeclare package Medium=Medium1,
    p=300000,
    nPorts=1)
    "Sink for heating water"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaWatSup(
    k=max(
      ter.T_aHeaWat_nominal))
    "Supply temperature"
equation
  connect(ter.port_bHeaWat,disFloHea.ports_a1)
  connect(disFloHea.ports_b1,ter.port_aHeaWat)
  connect(reaRep.y,ter.TSetHea)
  connect(loa.y[2],reaRep1.u)
  connect(reaRep1.y,ter.QReqHea_flow)
  connect(supHeaWat.ports[1],disFloHea.port_a)
  connect(disFloHea.port_b,sinHeaWat.ports[1])
  connect(ter.mReqHeaWat_flow,disFloHea.mReq_flow)
  connect(THeaWatSup.y,supHeaWat.T_in)
  connect(minTSet.y,reaRep.u)
end BenchmarkFlowDistribution1;


within Buildings.DHC.Loads.BaseClasses.Validation;
model BenchmarkFlowDistribution2
  "Performance benchmark of building heating water flow distribution modeling"
  extends Modelica.Icons.Example;
  package Medium1=Buildings.Media.Water
    "Source side medium";
  package Medium2=Buildings.Media.Air
    "Load side medium";
  parameter String filNam="modelica://Buildings/Resources/Data/DHC/Loads/Examples/SwissResidential_20190916.mos"
    "File name with thermal loads as time series";
  parameter Integer nLoa=5
    "Number of served loads"
  parameter Modelica.Units.SI.Temperature T_aHeaWat_nominal=273.15 + 40
    "Heating water inlet temperature at nominal conditions"
  parameter Modelica.Units.SI.Temperature T_bHeaWat_nominal(
    min=273.15,
    displayUnit="degC") = T_aHeaWat_nominal - 5
    "Heating water outlet temperature at nominal conditions"
  parameter Modelica.Units.SI.Temperature T_aLoaHea_nominal=273.15 + 20
    "Load side inlet temperature at nominal conditions in heating mode"
  parameter Modelica.Units.SI.MassFlowRate mLoaHea_flow_nominal=1
    "Load side mass flow rate at nominal conditions in heating mode"
  parameter Modelica.Units.SI.Time tau=120
    "Time constant of fluid temperature variation at nominal flow rate"
  parameter Real facMul=10
    "Mulitplier factor for terminal units"
  final parameter Modelica.Units.SI.MassFlowRate mCon_flow_nominal[nLoa]=ter.mHeaWat_flow_nominal
      *facMul "Nominal mass flow rate in each connection line";
  final parameter Modelica.Units.SI.MassFlowRate m_flow_nominal=sum(
      mCon_flow_nominal) "Nominal mass flow rate in the distribution line";
  final parameter Modelica.Units.SI.PressureDifference dp_nominal=sum(dis.con.pipDisSup.dp_nominal)
       + sum(dis.con.pipDisRet.dp_nominal) + max(ter.dpSou_nominal)
    "Nominal pressure drop in the distribution line";
  final parameter Modelica.Units.SI.HeatFlowRate QHea_flow_nominal=
      Buildings.DHC.Loads.BaseClasses.getPeakLoad(string="#Peak space heating load", filNam=
      Modelica.Utilities.Files.loadResource(filNam))/facMul
    "Design heating heat flow rate (>=0)"
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.FanCoil2PipeHeatingValve ter[nLoa](
    each final facMul=facMul,
    redeclare each final package Medium1=Medium1,
    redeclare each final package Medium2=Medium2,
    each final QHea_flow_nominal=QHea_flow_nominal,
    each final mLoaHea_flow_nominal=mLoaHea_flow_nominal,
    each final T_aHeaWat_nominal=T_aHeaWat_nominal,
    each final T_bHeaWat_nominal=T_bHeaWat_nominal,
    each final T_aLoaHea_nominal=T_aLoaHea_nominal)
    "Heating terminal unit"
  Modelica.Blocks.Sources.CombiTimeTable loa(
    tableOnFile=true,
    tableName="tab1",
    fileName=Modelica.Utilities.Files.loadResource(
      filNam),
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    y(each unit="W"),
    offset={0,0,0},
    columns={2,3,4},
    smoothness=Modelica.Blocks.Types.Smoothness.MonotoneContinuousDerivative1)
    "Reader for thermal loads (y[1] is cooling load, y[2] is heating load)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minTSet(
    k=293.15,
    y(final unit="K",
      displayUnit="degC"))
    "Minimum temperature set point"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator reaRep(
    nout=nLoa)
    "Repeat input to output an array"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator reaRep1(
    nout=nLoa)
    "Repeat input to output an array"
  Fluid.Sources.Boundary_pT supHeaWat(
    redeclare package Medium=Medium1,
    use_T_in=true,
    nPorts=2)
    "Heating water supply"
  Buildings.DHC.Networks.Distribution2Pipe_R dis(
    redeclare final package Medium = Medium1,
    nCon=nLoa,
    allowFlowReversal=false,
    mDis_flow_nominal=m_flow_nominal,
    mCon_flow_nominal=mCon_flow_nominal,
    mEnd_flow_nominal=m_flow_nominal,
    lDis=fill(6, nLoa),
    lEnd=1)
  Fluid.Movers.FlowControlled_dp pum(
    redeclare package Medium = Medium1,
    per(final motorCooledByFluid=false),
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState,
    m_flow_nominal=m_flow_nominal,
    addPowerToMedium=false,
    nominalValuesDefineDefaultPressureCurve=true,
    use_riseTime=false,
    dp_nominal=dp_nominal)
  Fluid.MixingVolumes.MixingVolume vol(
    final prescribedHeatFlowRate=true,
    redeclare final package Medium=Medium1,
    V=m_flow_nominal*tau/rho_default,
    final mSenFac=1,
    final m_flow_nominal=m_flow_nominal,
    final energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    nPorts=2)
    "Volume for fluid stream"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant dpPum(
    k=dp_nominal)
    "Prescribed head"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaWatSup(
    k=max(
      ter.T_aHeaWat_nominal))
    "Supply temperature"
protected
  parameter Medium1.ThermodynamicState sta_default=Medium1.setState_pTX(
    T=Medium1.T_default,
    p=Medium1.p_default,
    X=Medium1.X_default);
  parameter Modelica.Units.SI.Density rho_default=Medium1.density(sta_default)
    "Density, used to compute fluid volume";
equation
  connect(loa.y[2],reaRep1.u)
  connect(reaRep.y,ter.TSetHea)
  connect(reaRep1.y,ter.QReqHea_flow)
  connect(ter.port_bHeaWat,dis.ports_aCon)
  connect(dis.ports_bCon,ter.port_aHeaWat)
  connect(pum.port_b,dis.port_aDisSup)
  connect(dis.port_bDisRet,supHeaWat.ports[1])
  connect(vol.ports[1],pum.port_a)
  connect(supHeaWat.ports[2],vol.ports[2])
  connect(THeaWatSup.y,supHeaWat.T_in)
  connect(dpPum.y,pum.dp_in)
  connect(reaRep.u,minTSet.y)
end BenchmarkFlowDistribution2;


within Buildings.DHC.Loads.BaseClasses.Validation;
model BuildingWithETS
  "Validation of the base class PartialBuildingWithPartialETS"
  extends Modelica.Icons.Example;
  import TypDisSys=Buildings.DHC.Types.DistrictSystemType
    "District system type enumeration";
  package MediumW=Buildings.Media.Water
    "Water";
  package MediumS=Modelica.Media.Water.WaterIF97_ph (
    h_default=2770E3)
    "Steam";
  parameter Modelica.Units.SI.MassFlowRate m_flow_nominal=1
    "Nominal mass flow rate";
  parameter Modelica.Units.SI.HeatFlowRate QHeaWat_flow_nominal=1E4
    "Nominal mass flow rate";
  parameter Modelica.Units.SI.HeatFlowRate QChiWat_flow_nominal=-1E4
    "Nominal mass flow rate";
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.BuildingWithETS buiHeaGen1(
    redeclare final package MediumSerHea_a=MediumS,
    redeclare final package MediumSer=MediumW,
    redeclare final package MediumBui=MediumW,
    nPorts_heaWat=1,
    bui(
      final have_heaWat=true),
    ets(
      final typ=TypDisSys.HeatingGeneration1,
      final m_flow_nominal=m_flow_nominal,
      final have_heaWat=true,
      QHeaWat_flow_nominal=QHeaWat_flow_nominal))
    "Building and ETS component - Heating only (steam)"
  Fluid.Sources.MassFlowSource_T souDisSup(
    redeclare final package Medium=MediumS,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet(
    redeclare final package Medium=MediumW,
    nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo(
    redeclare final package Medium1=MediumS,
    redeclare final package Medium2=MediumW,
    final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.BuildingWithETS buiComGen1(
    redeclare final package MediumSerHea_a=MediumS,
    redeclare final package MediumSer=MediumW,
    redeclare final package MediumBui=MediumW,
    nPorts_heaWat=1,
    nPorts_chiWat=1,
    bui(
      final have_heaWat=true,
      final have_chiWat=true),
    ets(
      final typ=TypDisSys.CombinedGeneration1,
      final m_flow_nominal=m_flow_nominal,
      final have_heaWat=true,
      final have_chiWat=true,
      QHeaWat_flow_nominal=QHeaWat_flow_nominal,
      QChiWat_flow_nominal=QChiWat_flow_nominal))
    "Building and ETS component - Buildings.DHC.Loads.Combined heating (steam) and cooling"
  Fluid.Sources.MassFlowSource_T souDisSup1(
    redeclare final package Medium=MediumS,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet1(
    redeclare final package Medium=MediumW,
    nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo1(
    redeclare final package Medium1=MediumS,
    redeclare final package Medium2 = Media.Water,
    final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Fluid.Sources.MassFlowSource_T souDisSup2(
    redeclare final package Medium=MediumW,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet2(
    redeclare final package Medium=MediumW,
    nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo2(
    redeclare final package Medium1=MediumW,
    final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Fluid.Sources.MassFlowSource_T souDisSup3(
    redeclare final package Medium=MediumW,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet3(
    redeclare final package Medium=MediumW,
    nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo3(
    redeclare final package Medium1=MediumW,
    final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.BuildingWithETS buiCoo(
    redeclare final package MediumSer=MediumW,
    redeclare final package MediumBui=MediumW,
    nPorts_chiWat=1,
    bui(
      final have_chiWat=true),
    ets(
      final typ=TypDisSys.Cooling,
      final m_flow_nominal=m_flow_nominal,
      final have_chiWat=true,
      QChiWat_flow_nominal=QChiWat_flow_nominal))
    "Building and ETS component - Buildings.DHC.Loads.Cooling only"
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.BuildingWithETS buiComGen2to4(
    redeclare final package MediumSer = MediumW,
    redeclare final package MediumBui = MediumW,
    nPorts_heaWat=1,
    nPorts_chiWat=1,
    bui(
      final have_heaWat=true,
      final have_chiWat=true),
    ets(
      final typ=TypDisSys.CombinedGeneration2to4,
      final m_flow_nominal=m_flow_nominal,
      final have_heaWat=true,
      final have_chiWat=true,
      QHeaWat_flow_nominal=QHeaWat_flow_nominal,
      QChiWat_flow_nominal=QChiWat_flow_nominal))
    "Building and ETS component - Buildings.DHC.Loads.Combined heating and cooling"
  Fluid.Sources.MassFlowSource_T souDisSup5(
    redeclare final package Medium = MediumW,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet5(
    redeclare final package Medium = MediumW,
    nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo5(
    redeclare final package Medium1 = MediumW,
    final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Fluid.Sources.MassFlowSource_T souDisSup6(
    redeclare final package Medium =MediumW,
    m_flow=m_flow_nominal,                   nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet6(
    redeclare final package Medium = MediumW,
    nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo6(
    redeclare final package Medium1 = MediumW,
    final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.BuildingWithETS buiHeaGen2to4(
    redeclare final package MediumSer = MediumW,
    redeclare final package MediumBui = MediumW,
    nPorts_heaWat=1,
    bui(
      final have_heaWat=true),
    ets(
      final typ=TypDisSys.HeatingGeneration2to4,
      final m_flow_nominal= m_flow_nominal,
      final have_heaWat=true,
      QHeaWat_flow_nominal=QHeaWat_flow_nominal))
    "Building and ETS component - Heating only"
  Fluid.Sources.MassFlowSource_T souDisSup7(
    redeclare final package Medium = MediumW,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet7(
    redeclare final package Medium = MediumW,
    nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo7(
    redeclare final package Medium1 = MediumW,
    final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Fluid.Sources.MassFlowSource_T souDisSup4(
    redeclare final package Medium = MediumW,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet4(redeclare final package Medium = MediumW,
      nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo4(redeclare
      final package Medium1 = MediumW, final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.BuildingWithETS buiComGen5(
    redeclare final package MediumSer = MediumW,
    redeclare final package MediumBui = MediumW,
    nPorts_heaWat=1,
    nPorts_chiWat=1,
    bui(final have_heaWat=true, final have_chiWat=true),
    ets(
      final typ=TypDisSys.CombinedGeneration5,
      final m_flow_nominal=m_flow_nominal,
      final have_heaWat=true,
      final have_chiWat=true,
      QHeaWat_flow_nominal=QHeaWat_flow_nominal,
      QChiWat_flow_nominal=QChiWat_flow_nominal))
    "Building and ETS component - Buildings.DHC.Loads.Combined heating and cooling (ambient)"
  Fluid.Sources.MassFlowSource_T souDisSup8(
    redeclare final package Medium = MediumW,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet8(redeclare final package Medium = MediumW,
      nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo8(redeclare
      final package Medium1 = MediumW, final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.BuildingWithETS buiTesOutETS(
    redeclare final package MediumSer = MediumW,
    redeclare final package MediumBui = MediumW,
    nPorts_heaWat=1,
    nPorts_chiWat=1,
    bui(final have_heaWat=true, final have_chiWat=true),
    ets(
      final typ=TypDisSys.CombinedGeneration5,
      final m_flow_nominal=m_flow_nominal,
      final have_heaWat=true,
      final have_chiWat=true,
      QHeaWat_flow_nominal=QHeaWat_flow_nominal,
      QChiWat_flow_nominal=QChiWat_flow_nominal,
      final have_fan=true,
      final have_pum=true,
      final have_eleHea=true,
      final have_eleCoo=true))
    "Building and ETS component - Testing ETS output connectors"
  Fluid.Sources.MassFlowSource_T souDisSup9(
    redeclare final package Medium = MediumW,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet9(redeclare final package Medium = MediumW,
      nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo9(redeclare
      final package Medium1 = MediumW, final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.BuildingWithETS buiTesOutETSBui(
    redeclare final package MediumSer = MediumW,
    redeclare final package MediumBui = MediumW,
    nPorts_heaWat=1,
    nPorts_chiWat=1,
    bui(
      final have_heaWat=true,
      final have_chiWat=true,
      final have_fan=true,
      final have_pum=true,
      final have_eleHea=true,
      final have_eleCoo=true),
    ets(
      final typ=TypDisSys.CombinedGeneration5,
      final m_flow_nominal=m_flow_nominal,
      final have_heaWat=true,
      final have_chiWat=true,
      QHeaWat_flow_nominal=QHeaWat_flow_nominal,
      QChiWat_flow_nominal=QChiWat_flow_nominal,
      final have_fan=true,
      final have_pum=true,
      final have_eleHea=true,
      final have_eleCoo=true))
    "Building and ETS component - Testing ETS and building output connectors"
  Fluid.Sources.MassFlowSource_T souDisSup10(
    redeclare final package Medium = MediumW,
    m_flow=m_flow_nominal,
    nPorts=1)
    "Source for district supply"
  Fluid.Sources.Boundary_pT sinDisRet10(redeclare final package Medium =
        MediumW, nPorts=1)
    "Sink for district return"
  Buildings.DHC.Networks.BaseClasses.DifferenceEnthalpyFlowRate senDifEntFlo10(redeclare
      final package Medium1 = MediumW, final m_flow_nominal=m_flow_nominal)
    "Change in enthalpy flow rate "
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.BuildingWithETS buiTesFacMul(
    redeclare final package MediumSer = MediumW,
    redeclare final package MediumBui = MediumW,
    nPorts_heaWat=1,
    nPorts_chiWat=1,
    facMul=2,
    bui(
      final have_heaWat=true,
      final have_chiWat=true,
      final have_fan=true,
      final have_pum=true,
      final have_eleHea=true,
      final have_eleCoo=true),
    ets(
      final typ=TypDisSys.CombinedGeneration5,
      final m_flow_nominal=m_flow_nominal,
      final have_heaWat=true,
      final have_chiWat=true,
      QHeaWat_flow_nominal=QHeaWat_flow_nominal,
      QChiWat_flow_nominal=QChiWat_flow_nominal,
      final have_fan=true,
      final have_pum=true,
      final have_eleHea=true,
      final have_eleCoo=true))
    "Building and ETS component - Testing scaling factor"
equation
  connect(souDisSup.ports[1],senDifEntFlo.port_a1)
  connect(senDifEntFlo.port_b2,sinDisRet.ports[1])
  connect(souDisSup1.ports[1],senDifEntFlo1.port_a1)
  connect(senDifEntFlo1.port_b2,sinDisRet1.ports[1])
  connect(souDisSup2.ports[1],senDifEntFlo2.port_a1)
  connect(senDifEntFlo2.port_b2,sinDisRet2.ports[1])
  connect(souDisSup3.ports[1],senDifEntFlo3.port_a1)
  connect(sinDisRet3.ports[1],senDifEntFlo3.port_b2)
  connect(senDifEntFlo.port_b1, buiHeaGen1.port_aSerHea)
  connect(senDifEntFlo.port_a2, buiHeaGen1.port_bSerHea)
  connect(senDifEntFlo1.port_b1, buiComGen1.port_aSerHea)
  connect(buiComGen1.port_bSerHea, senDifEntFlo1.port_a2)
  connect(senDifEntFlo2.port_b1, buiComGen1.port_aSerCoo)
  connect(buiComGen1.port_bSerCoo, senDifEntFlo2.port_a2)
  connect(senDifEntFlo3.port_b1, buiCoo.port_aSerCoo)
  connect(buiCoo.port_bSerCoo, senDifEntFlo3.port_a2)
  connect(souDisSup5.ports[1],senDifEntFlo5.port_a1)
  connect(senDifEntFlo5.port_b2,sinDisRet5.ports[1])
  connect(souDisSup6.ports[1],senDifEntFlo6.port_a1)
  connect(senDifEntFlo6.port_b2,sinDisRet6.ports[1])
  connect(senDifEntFlo5.port_b1, buiComGen2to4.port_aSerHea)
  connect(buiComGen2to4.port_bSerHea, senDifEntFlo5.port_a2)
  connect(senDifEntFlo6.port_b1, buiComGen2to4.port_aSerCoo)
  connect(buiComGen2to4.port_bSerCoo, senDifEntFlo6.port_a2)
  connect(souDisSup7.ports[1], senDifEntFlo7.port_a1)
  connect(senDifEntFlo7.port_b2, sinDisRet7.ports[1])
  connect(senDifEntFlo7.port_b1, buiHeaGen2to4.port_aSerHea)
  connect(senDifEntFlo7.port_a2, buiHeaGen2to4.port_bSerHea)
  connect(souDisSup4.ports[1],senDifEntFlo4.port_a1)
  connect(sinDisRet4.ports[1],senDifEntFlo4.port_b2)
  connect(senDifEntFlo4.port_b1,buiComGen5. port_aSerAmb)
  connect(buiComGen5.port_bSerAmb,senDifEntFlo4. port_a2)
  connect(souDisSup8.ports[1],senDifEntFlo8.port_a1)
  connect(sinDisRet8.ports[1],senDifEntFlo8.port_b2)
  connect(senDifEntFlo8.port_b1,buiTesOutETS. port_aSerAmb)
  connect(buiTesOutETS.port_bSerAmb,senDifEntFlo8. port_a2)
  connect(souDisSup9.ports[1],senDifEntFlo9.port_a1)
  connect(sinDisRet9.ports[1],senDifEntFlo9.port_b2)
  connect(senDifEntFlo9.port_b1,buiTesOutETSBui. port_aSerAmb)
  connect(buiTesOutETSBui.port_bSerAmb,senDifEntFlo9. port_a2)
  connect(souDisSup10.ports[1],senDifEntFlo10. port_a1)
  connect(sinDisRet10.ports[1],senDifEntFlo10. port_b2)
  connect(senDifEntFlo10.port_b1,buiTesFacMul. port_aSerAmb)
  connect(buiTesFacMul.port_bSerAmb,senDifEntFlo10. port_a2)
end BuildingWithETS;


within Buildings.DHC.Loads.BaseClasses.Validation;
model FlowDistributionPumpControl
  "Validation of the pump head computation in FlowDistribution"
  extends Modelica.Icons.Example;
  package Medium1=Buildings.Media.Water
    "Source side medium";
  package Medium2=Buildings.Media.Air
    "Load side medium";
  parameter String filNam="modelica://Buildings/Resources/Data/DHC/Loads/Examples/SwissResidential_20190916.mos"
    "File name with thermal loads as time series";
  parameter Integer nLoa=5
    "Number of served loads"
  parameter Real facMul=10
    "Scaling factor for terminal units"
  parameter Modelica.Units.SI.MassFlowRate mLoaHea_flow_nominal=1
    "Load side mass flow rate at nominal conditions in heating mode"
  parameter Modelica.Units.SI.Temperature T_aHeaWat_nominal=273.15 + 40
    "Heating water inlet temperature at nominal conditions"
  parameter Modelica.Units.SI.Temperature T_bHeaWat_nominal(
    min=273.15,
    displayUnit="degC") = T_aHeaWat_nominal - 5
    "Heating water outlet temperature at nominal conditions"
  parameter Modelica.Units.SI.Temperature T_aLoaHea_nominal=273.15 + 20
    "Load side inlet temperature at nominal conditions in heating mode"
  parameter Modelica.Units.SI.Time tau=120
    "Time constant of fluid temperature variation at nominal flow rate"
  parameter Modelica.Units.SI.PressureDifference dpSet=max(terUniHea.dpSou_nominal)
    "Pressure difference set point";
  final parameter Modelica.Units.SI.MassFlowRate mCon_flow_nominal[nLoa]=
      terUniHea.mHeaWat_flow_nominal*facMul
    "Nominal mass flow rate in each connection line";
  final parameter Modelica.Units.SI.MassFlowRate m_flow_nominal=sum(
      mCon_flow_nominal) "Nominal mass flow rate in the distribution line";
  final parameter Modelica.Units.SI.PressureDifference dp_nominal=max(terUniHea.dpSou_nominal)
       + 2*nLoa*5000 "Nominal pressure drop in the distribution line";
  final parameter Modelica.Units.SI.HeatFlowRate QHea_flow_nominal=
      Buildings.DHC.Loads.BaseClasses.getPeakLoad(string="#Peak space heating load", filNam=
      Modelica.Utilities.Files.loadResource(filNam))/facMul
    "Design heating heat flow rate (>=0)"
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.FanCoil2PipeHeatingValve terUniHea[nLoa](
    redeclare each final package Medium1=Medium1,
    redeclare each final package Medium2=Medium2,
    each final facMul=facMul,
    each final QHea_flow_nominal=QHea_flow_nominal,
    each final mLoaHea_flow_nominal=mLoaHea_flow_nominal,
    each final T_aHeaWat_nominal=T_aHeaWat_nominal,
    each final T_bHeaWat_nominal=T_bHeaWat_nominal,
    each final T_aLoaHea_nominal=T_aLoaHea_nominal,
    each final have_speVar=false)
    "Heating terminal unit"
  Modelica.Blocks.Sources.CombiTimeTable loa(
    tableOnFile=true,
    tableName="tab1",
    fileName=Modelica.Utilities.Files.loadResource(
      filNam),
    extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic,
    y(each unit="W"),
    offset={0,0,0},
    columns={2,3,4},
    smoothness=Modelica.Blocks.Types.Smoothness.MonotoneContinuousDerivative1)
    "Reader for thermal loads (y[1] is cooling load, y[2] is heating load)"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minTSet(
    k=20+273.15,
    y(final unit="K",
      displayUnit="degC"))
    "Minimum temperature set point"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator reaRep(
    nout=nLoa)
    "Repeat input to output an array"
  Buildings.Controls.OBC.CDL.Routing.RealScalarReplicator reaRep1(
    nout=nLoa)
    "Repeat input to output an array"
  Buildings.DHC.Networks.Distribution2Pipe_R dis(
    redeclare final package Medium = Medium1,
    final nCon=nLoa,
    final allowFlowReversal=false,
    final iConDpSen=nLoa,
    final mDis_flow_nominal=m_flow_nominal,
    final mCon_flow_nominal=mCon_flow_nominal,
    mEnd_flow_nominal=m_flow_nominal,
    lDis=fill(25, nLoa),
    lEnd=1) "Distribution network"
  Buildings.Fluid.Movers.Preconfigured.FlowControlled_dp pumCstDp(
    redeclare package Medium=Medium1,
    m_flow_nominal=m_flow_nominal,
    dp_nominal=dp_nominal)
    "Pump controlled to track a pressure drop over the last connected load"
  Fluid.MixingVolumes.MixingVolume vol(
    final prescribedHeatFlowRate=true,
    redeclare final package Medium=Medium1,
    V=m_flow_nominal*tau/rho_default,
    final mSenFac=1,
    final m_flow_nominal=m_flow_nominal,
    final energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    nPorts=2)
    "Volume for fluid stream"
  Fluid.Sources.Boundary_pT supHeaWat1(
    redeclare package Medium=Medium1,
    use_T_in=true,
    nPorts=3)
    "Heating water source"
  Buildings.DHC.Loads.BaseClasses.FlowDistribution disCstDp(
    redeclare package Medium=Medium1,
    m_flow_nominal=m_flow_nominal,
    have_pum=true,
    typCtr=Buildings.DHC.Loads.BaseClasses.Types.PumpControlType.ConstantDp,
    dp_nominal=dp_nominal,
    dpMin=dpSet,
    mUni_flow_nominal=mCon_flow_nominal,
    nPorts_a1=nLoa,
    nPorts_b1=nLoa)
    "Distribution system with pump controlled to track a pressure drop over the last connected unit"
  Fluid.Sources.Boundary_pT sinHeaWat(
    redeclare package Medium=Medium1,
    p=300000,
    nPorts=3)
    "Sink for heating water"
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.FanCoil2PipeHeating terUniHea1[nLoa](
    redeclare each final package Medium1=Medium1,
    redeclare each final package Medium2=Medium2,
    each final facMul=facMul,
    each final QHea_flow_nominal=QHea_flow_nominal,
    each final mLoaHea_flow_nominal=mLoaHea_flow_nominal,
    each final T_aHeaWat_nominal=T_aHeaWat_nominal,
    each final T_bHeaWat_nominal=T_bHeaWat_nominal,
    each final T_aLoaHea_nominal=T_aLoaHea_nominal,
    each final have_speVar=false)
    "Heating terminal unit"
  Buildings.Fluid.Movers.Preconfigured.SpeedControlled_y pumCstSpe(
    redeclare package Medium=Medium1,
    m_flow_nominal=m_flow_nominal,
    dp_nominal=dp_nominal)
    "Pump controlled at constant speed"
  Fluid.Movers.BaseClasses.IdealSource pipPre(
    redeclare final package Medium=Medium1,
    dp_start=dp_nominal,
    m_flow_start=m_flow_nominal,
    m_flow_small=1E-4*m_flow_nominal,
    final show_T=false,
    final show_V_flow=false,
    final control_m_flow=true,
    final control_dp=false)
    "Fictitious pipe used to prescribe pump flow rate"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one1(
    k=1)
    "Constant one"
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.FanCoil2PipeHeating terUniHea2[nLoa](
    redeclare each final package Medium1=Medium1,
    redeclare each final package Medium2=Medium2,
    each final facMul=facMul,
    each final QHea_flow_nominal=QHea_flow_nominal,
    each final mLoaHea_flow_nominal=mLoaHea_flow_nominal,
    each final T_aHeaWat_nominal=T_aHeaWat_nominal,
    each final T_bHeaWat_nominal=T_bHeaWat_nominal,
    each final T_aLoaHea_nominal=T_aLoaHea_nominal,
    each final have_speVar=false)
    "Heating terminal unit"
  Buildings.DHC.Loads.BaseClasses.FlowDistribution disCstSpe(
    redeclare package Medium=Medium1,
    m_flow_nominal=m_flow_nominal,
    have_pum=true,
    typCtr=Buildings.DHC.Loads.BaseClasses.Types.PumpControlType.ConstantSpeed,
    dp_nominal=dp_nominal,
    dpMin=dpSet,
    mUni_flow_nominal=mCon_flow_nominal,
    nPorts_a1=5,
    nPorts_b1=5)
    "Distribution system with pump controlled at constant speed"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaWatSup(
    k=T_aHeaWat_nominal)
    "Heating water supply temperature"
  Fluid.Sources.Boundary_pT supHeaWat(
    redeclare package Medium=Medium1,
    use_T_in=true,
    nPorts=2)
    "Heating water source"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant setDp(
    k=dpSet)
    "Pressure difference set-point"
protected
  parameter Medium1.ThermodynamicState sta_default=Medium1.setState_pTX(
    T=Medium1.T_default,
    p=Medium1.p_default,
    X=Medium1.X_default);
  parameter Modelica.Units.SI.Density rho_default=Medium1.density(sta_default)
    "Density, used to compute fluid volume";
equation
  connect(loa.y[2],reaRep1.u)
  connect(reaRep.y,terUniHea.TSetHea)
  connect(reaRep1.y,terUniHea.QReqHea_flow)
  connect(terUniHea.port_bHeaWat,dis.ports_aCon)
  connect(dis.ports_bCon,terUniHea.port_aHeaWat)
  connect(pumCstDp.port_b,dis.port_aDisSup)
  connect(vol.ports[1],pumCstDp.port_a)
  connect(disCstDp.port_b,sinHeaWat.ports[1])
  connect(supHeaWat1.ports[1],disCstDp.port_a)
  connect(terUniHea1.port_bHeaWat,disCstDp.ports_a1)
  connect(disCstDp.ports_b1,terUniHea1.port_aHeaWat)
  connect(reaRep.y,terUniHea1.TSetHea)
  connect(reaRep1.y,terUniHea1.QReqHea_flow)
  connect(terUniHea1.mReqHeaWat_flow,disCstDp.mReq_flow)
  connect(supHeaWat1.ports[2],pumCstSpe.port_a)
  connect(pumCstSpe.port_b,pipPre.port_a)
  connect(pipPre.port_b,sinHeaWat.ports[2])
  connect(one1.y,pumCstSpe.y)
  connect(supHeaWat1.ports[3],disCstSpe.port_a)
  connect(disCstSpe.port_b,sinHeaWat.ports[3])
  connect(disCstSpe.ports_b1[1:5],terUniHea2.port_aHeaWat)
  connect(terUniHea2.port_bHeaWat,disCstSpe.ports_a1[1:5])
  connect(terUniHea2.mReqHeaWat_flow,disCstSpe.mReq_flow)
  connect(reaRep.y,terUniHea2.TSetHea)
  connect(reaRep1.y,terUniHea2.QReqHea_flow)
  connect(disCstSpe.mReqTot_flow,pipPre.m_flow_in)
  connect(THeaWatSup.y,supHeaWat1.T_in)
  connect(dis.port_bDisRet,supHeaWat.ports[1])
  connect(supHeaWat.ports[2],vol.ports[2])
  connect(THeaWatSup.y,supHeaWat.T_in)
  connect(minTSet.y,reaRep.u)
  connect(dis.dp,pumCstDp.dpMea)
  connect(setDp.y,pumCstDp.dp_in)
end FlowDistributionPumpControl;


Model that validates the getPeakLoad function. This model tests reading the peak loads from the load file.
If the wrong values are read, then the simulation stops with an error.

within Buildings.DHC.Loads.BaseClasses.Validation;
model GetPeakLoad
  "Model that validates the getPeakLoad function"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.HeatFlowRate QCoo_flow=
      Buildings.DHC.Loads.BaseClasses.getPeakLoad(string=
      "#Peak space cooling load", filNam=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/DHC/Loads/BaseClasses/Validation/RefBldgLargeOfficeNew2004_7.1_5.0_3C_USA_CA_SAN_FRANCISCO.mos"))
    "Peak heat flow rate";
  parameter Modelica.Units.SI.HeatFlowRate QHea_flow=
      Buildings.DHC.Loads.BaseClasses.getPeakLoad(string=
      "#Peak space heating load", filNam=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/DHC/Loads/BaseClasses/Validation/RefBldgLargeOfficeNew2004_7.1_5.0_3C_USA_CA_SAN_FRANCISCO.mos"))
    "Peak heat flow rate";
  parameter Modelica.Units.SI.HeatFlowRate QWatHea_flow=
      Buildings.DHC.Loads.BaseClasses.getPeakLoad(string=
      "#Peak water heating load", filNam=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/Data/DHC/Loads/BaseClasses/Validation/RefBldgLargeOfficeNew2004_7.1_5.0_3C_USA_CA_SAN_FRANCISCO.mos"))
    "Peak water heating flow rate";
equation
  assert(
    abs(
      QCoo_flow-(-383165.6989)) < 1E-3,
    "Error in reading the peak heating load. Read "+String(
      QCoo_flow));
  assert(
    abs(
      QHea_flow-893931.4335) < 1E-3,
    "Error in reading the peak heating load. Read "+String(
      QHea_flow));
  assert(
    abs(
      QWatHea_flow-19496.90012) < 1E-3,
    "Error in reading the peak water heating load. Read "+String(
      QWatHea_flow));
end GetPeakLoad;


Collection of validation models

within Buildings.DHC.Loads.BaseClasses;
package Validation "Collection of validation models"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


Validation of the model SimpleRoomODE

within Buildings.DHC.Loads.BaseClasses.Validation;
model SimpleRoomODE
  "Validation of the model SimpleRoomODE"
  extends Modelica.Icons.Example;
  package Medium1=Buildings.Media.Water
    "Source side medium";
  package Medium2=Buildings.Media.Air
    "Load side medium";
  parameter Modelica.Units.SI.HeatFlowRate QHea_flow_nominal=112000 "Design heating heat flow rate (for TInd=TIndHea_nominal, TOut=TOutHea_nominal,
    with no internal gains, no solar radiation)"
  parameter Modelica.Units.SI.HeatFlowRate QCoo_flow_nominal=-200000
    "Design cooling heat flow rate"
  parameter Modelica.Units.SI.Time tau=1800
    "Time constant of the indoor temperature";
  Buildings.DHC.Loads.BaseClasses.Examples.BaseClasses.GeojsonExportRC.OfficeBuilding.Office romHeaMet
    "ROM where the heating load is always met"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    TDryBulSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
    TDryBul=276.15,
    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"
  Buildings.Controls.Continuous.LimPID conHea(
    controllerType=Modelica.Blocks.Types.SimpleController.PI,
    Ti=10)
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant minTSet(
    k=293.15,
    y(final unit="K",
      displayUnit="degC"))
    "Minimum temperature set point"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(k=
        QHea_flow_nominal) "Scaling"
  HeatTransfer.Sources.PrescribedHeatFlow prescribedHeatFlow
    "Prescribed heat flow rate"
  Buildings.DHC.Loads.BaseClasses.Examples.BaseClasses.GeojsonExportRC.OfficeBuilding.Office romHeaUnm
    "ROM where the heating load is not met"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai1(k=0.7)
    "Scaling "
  HeatTransfer.Sources.PrescribedHeatFlow prescribedHeatFlow1
    "Prescribed heat flow rate"
  Buildings.DHC.Loads.BaseClasses.SimpleRoomODE rooOdeHea(
    dTEnv_nominal=20,
    TAir_start=293.15,
    QEnv_flow_nominal=QHea_flow_nominal,
    tau=tau)
    "ODE heated room model"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant maxTSet(
    k=297.15,
    y(final unit="K",
      displayUnit="degC"))
    "Maximum temperature set point"
  Buildings.Controls.Continuous.LimPID conCoo(
    controllerType=Modelica.Blocks.Types.SimpleController.PI,
    Ti=10,
    reverseActing=false)
    "PI controller tracking the room maximum temperature"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai2(k=
        QCoo_flow_nominal) "Scaling"
  Buildings.DHC.Loads.BaseClasses.SimpleRoomODE rooOdeCoo(
    dTEnv_nominal=20,
    TAir_start=293.15,
    QEnv_flow_nominal=QHea_flow_nominal,
    tau=tau)
    "ODE cooled room model"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai3(k=0.8)
    "Scaling"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat1(
    TDryBulSou=Buildings.BoundaryConditions.Types.DataSource.Parameter,
    TDryBul=293.15,
    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"
  Buildings.DHC.Loads.BaseClasses.Examples.BaseClasses.GeojsonExportRC.OfficeBuilding.Office romCooMet
    "ROM where the cooling load is always met"
  Buildings.DHC.Loads.BaseClasses.Examples.BaseClasses.GeojsonExportRC.OfficeBuilding.Office romCooUnm
    "ROM where the cooling load is not met"
  HeatTransfer.Sources.PrescribedHeatFlow prescribedHeatFlow2
    "Prescribed heat flow rate"
  HeatTransfer.Sources.PrescribedHeatFlow prescribedHeatFlow3
    "Prescribed heat flow rate"
equation
  connect(weaDat.weaBus,romHeaMet.weaBus)
  connect(romHeaMet.TAir,conHea.u_m)
  connect(conHea.y,gai.u)
  connect(gai.y,prescribedHeatFlow.Q_flow)
  connect(prescribedHeatFlow.port,romHeaMet.port_a)
  connect(conCoo.y,gai2.u)
  connect(gai1.y,prescribedHeatFlow1.Q_flow)
  connect(gai1.y,rooOdeHea.QAct_flow)
  connect(gai2.y,rooOdeCoo.QReq_flow)
  connect(prescribedHeatFlow1.port,romHeaUnm.port_a)
  connect(gai2.y,gai3.u)
  connect(gai3.y,rooOdeCoo.QAct_flow)
  connect(weaDat.weaBus,romHeaUnm.weaBus)
  connect(weaDat1.weaBus,romCooMet.weaBus)
  connect(weaDat1.weaBus,romCooUnm.weaBus)
  connect(romCooMet.TAir,conCoo.u_m)
  connect(gai.y,gai1.u)
  connect(gai.y,rooOdeHea.QReq_flow)
  connect(gai3.y,prescribedHeatFlow2.Q_flow)
  connect(prescribedHeatFlow2.port,romCooUnm.port_a)
  connect(gai2.y,prescribedHeatFlow3.Q_flow)
  connect(prescribedHeatFlow3.port,romCooMet.port_a)
  connect(minTSet.y,conHea.u_s)
  connect(minTSet.y,rooOdeHea.TSet)
  connect(maxTSet.y,conCoo.u_s)
  connect(maxTSet.y,rooOdeCoo.TSet)
end SimpleRoomODE;


within Buildings.DHC.Loads.BaseClasses.Validation;
model TerminalUnitScaling
  "Validation of the scaling factor of the terminal unit model"
  extends Modelica.Icons.Example;
  package Medium1=Buildings.Media.Water
    "Source side medium";
  package Medium2=Buildings.Media.Air
    "Load side medium";
  parameter Real facMul=2
    "Multiplier factor";
  parameter Modelica.Units.SI.Temperature T_aHeaWat_nominal(
    min=273.15,
    displayUnit="degC") = 273.15 + 40
    "Heating water inlet temperature at nominal conditions"
  parameter Modelica.Units.SI.Temperature T_bHeaWat_nominal(
    min=273.15,
    displayUnit="degC") = T_aHeaWat_nominal - 5
    "Heating water outlet temperature at nominal conditions"
  parameter Modelica.Units.SI.Temperature T_aLoaHea_nominal(
    min=273.15,
    displayUnit="degC") = 273.15 + 20
    "Load side inlet temperature at nominal conditions in heating mode"
  parameter Modelica.Units.SI.Temperature T_bLoaHea_nominal(
    min=273.15,
    displayUnit="degC") = T_aLoaHea_nominal + 12
    "Load side ourtlet temperature at nominal conditions in heating mode"
  parameter Modelica.Units.SI.MassFlowRate mLoaHeaUni_flow_nominal(min=0) =
    QHeaUni_flow_nominal/(T_bLoaHea_nominal - T_aLoaHea_nominal)/
    Medium2.specificHeatCapacityCp(Medium2.setState_pTX(Medium2.p_default,
    T_aLoaHea_nominal))
    "Load side mass flow rate at nominal conditions for 1 unit"
  final parameter Modelica.Units.SI.MassFlowRate mLoaHea_flow_nominal(min=0) =
    mLoaHeaUni_flow_nominal*facMul
    "Load side mass flow rate at nominal conditions"
  parameter Modelica.Units.SI.HeatFlowRate QHeaUni_flow_nominal(min=0) = 1000
    "Design heating heat flow rate (>=0) for 1 unit"
  final parameter Modelica.Units.SI.HeatFlowRate QHea_flow_nominal=
      QHeaUni_flow_nominal*facMul "Design heating heat flow rate (>=0)"
  Buildings.Fluid.Sources.MassFlowSource_T supHeaWat(
    use_m_flow_in=true,
    redeclare package Medium=Medium1,
    use_T_in=false,
    T=T_aHeaWat_nominal,
    nPorts=1)
    "Heating water supply"
  Buildings.Fluid.Sources.Boundary_pT sinHeaWat(
    redeclare package Medium=Medium1,
    p=300000,
    nPorts=3)
    "Sink for heating water"
  Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.FanCoil2PipeHeating ter(
    have_speVar=false,
    redeclare package Medium1 = Medium1,
    redeclare package Medium2 = Medium2,
    final QHea_flow_nominal=QHea_flow_nominal,
    final mLoaHea_flow_nominal=mLoaHea_flow_nominal,
    final T_aHeaWat_nominal=T_aHeaWat_nominal,
    final T_bHeaWat_nominal=T_bHeaWat_nominal,
    final T_aLoaHea_nominal=T_aLoaHea_nominal)
    "Terminal unit with no multiplier"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TSet(k=293.15, y(
        final unit="K", displayUnit="degC")) "Temperature set point"
 Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.FanCoil2PipeHeating terUniMul(
    have_speVar=false,
    redeclare package Medium1=Medium1,
    redeclare package Medium2=Medium2,
    final QHea_flow_nominal=QHeaUni_flow_nominal,
    final facMul=facMul,
    final mLoaHea_flow_nominal=mLoaHeaUni_flow_nominal,
    final T_aHeaWat_nominal=T_aHeaWat_nominal,
    final T_bHeaWat_nominal=T_bHeaWat_nominal,
    final T_aLoaHea_nominal=T_aLoaHea_nominal)
    "Terminal unit with unit multiplier"
  Fluid.Sources.MassFlowSource_T supHeaWat1(
    use_m_flow_in=true,
    redeclare package Medium=Medium1,
    use_T_in=false,
    T=T_aHeaWat_nominal,
    nPorts=1)
    "Heating water supply"
  Buildings.Controls.OBC.CDL.Reals.Sources.Ramp ram(
    height=1.2*QHea_flow_nominal,
    duration=500)
    "Required heat flow rate"
 Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses.FanCoil2PipeHeating terUniMulZonMul(
    facMulZon=facMul,
    have_speVar=false,
    redeclare package Medium1 = Medium1,
    redeclare package Medium2 = Medium2,
    final QHea_flow_nominal=QHeaUni_flow_nominal,
    final facMul=facMul,
    final mLoaHea_flow_nominal=mLoaHeaUni_flow_nominal,
    final T_aHeaWat_nominal=T_aHeaWat_nominal,
    final T_bHeaWat_nominal=T_bHeaWat_nominal,
    final T_aLoaHea_nominal=T_aLoaHea_nominal)
    "Terminal unit with unit multiplier and zone multiplier"
  Fluid.Sources.MassFlowSource_T supHeaWat2(
    use_m_flow_in=true,
    redeclare package Medium = Medium1,
    use_T_in=false,
    T=T_aHeaWat_nominal,
    nPorts=1)
    "Heating water supply"
equation
  connect(ter.mReqHeaWat_flow, supHeaWat.m_flow_in)
  connect(supHeaWat.ports[1], ter.port_aHeaWat)
  connect(ter.port_bHeaWat, sinHeaWat.ports[1])
  connect(terUniMul.port_bHeaWat,sinHeaWat.ports[2])
  connect(supHeaWat1.ports[1],terUniMul.port_aHeaWat)
  connect(terUniMul.mReqHeaWat_flow,supHeaWat1.m_flow_in)
  connect(ram.y, ter.QReqHea_flow)
  connect(ram.y,terUniMul.QReqHea_flow)
  connect(TSet.y, ter.TSetHea)
  connect(TSet.y, terUniMul.TSetHea)
  connect(terUniMulZonMul.port_bHeaWat, sinHeaWat.ports[3])
  connect(supHeaWat2.ports[1], terUniMulZonMul.port_aHeaWat)
  connect(TSet.y, terUniMulZonMul.TSetHea)
  connect(ram.y, terUniMulZonMul.QReqHea_flow)
  connect(terUniMulZonMul.mReqHeaWat_flow, supHeaWat2.m_flow_in)
end TerminalUnitScaling;


within Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses;
model Building
  "Dummy building model for validation purposes"
  extends Buildings.DHC.Loads.BaseClasses.PartialBuilding;
  parameter Modelica.Units.SI.HeatFlowRate QChiWat_flow_nominal
    "Design heat flow rate for chilled water production (<0)"
  parameter Modelica.Units.SI.HeatFlowRate QHeaWat_flow_nominal
    "Design heat flow rate for heating water production (>0)"
  parameter Modelica.Units.SI.MassFlowRate m_flow_nominal
    "Nominal mass flow rate";
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant souPHea(
    k=1)
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant souPCoo(
    k=1)
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant souPFan(
    k=1)
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant souPPum(
    k=1)
  Fluid.HeatExchangers.HeaterCooler_u loaHea(
    redeclare final package Medium=Medium,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final Q_flow_nominal=-QHeaWat_flow_nominal,
    final m_flow_nominal=m_flow_nominal,
    dp_nominal=0) if have_heaWat
    "Heating load"
  Fluid.HeatExchangers.HeaterCooler_u loaCoo(
    redeclare final package Medium = Medium,
    energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    final Q_flow_nominal=-QChiWat_flow_nominal,
    final m_flow_nominal=m_flow_nominal,
    dp_nominal=0)  if have_chiWat
    "Cooling load"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one(k=1) "One"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai(
    k=-1)  if have_heaWat
    "Opposite"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai1(
    k=-1)  if have_chiWat
    "Opposite"
equation
  connect(souPHea.y, mulPHea.u)
  connect(souPCoo.y, mulPCoo.u)
  connect(souPFan.y, mulPFan.u)
  connect(souPPum.y, mulPPum.u)
  connect(mulHeaWatInl[1].port_b, loaHea.port_a)
  connect(loaHea.port_b, mulHeaWatOut[1].port_a)
  connect(loaCoo.port_b, mulChiWatOut[1].port_a)
  connect(mulChiWatInl[1].port_b, loaCoo.port_a)
  connect(loaHea.Q_flow, gai.u)
  connect(loaCoo.Q_flow, gai1.u)
  connect(gai.y, mulQHea_flow.u)
  connect(gai1.y, mulQCoo_flow.u)
  connect(one.y, loaHea.u)
  connect(one.y, loaCoo.u)
end Building;


Dummy building with ETS model for validation purposes. This is a minimum example of a class extending

Buildings.DHC.Loads.BaseClasses.PartialBuildingWithPartialETS
developed for testing purposes only.

within Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses;
model BuildingWithETS
  "Dummy building with ETS model for validation purposes"
  extends
    Buildings.DHC.Loads.BaseClasses.PartialBuildingWithPartialETS(
    redeclare ETS ets,
    redeclare Building bui(
      final QChiWat_flow_nominal=QChiWat_flow_nominal,
      final QHeaWat_flow_nominal=QHeaWat_flow_nominal,
      final m_flow_nominal=ets.m_flow_nominal));
end BuildingWithETS;


Dummy ETS model for validation purposes

within Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses;
model ETS
  "Dummy ETS model for validation purposes"
  extends
    Buildings.DHC.ETS.BaseClasses.PartialETS;
  parameter Modelica.Units.SI.MassFlowRate m_flow_nominal
    "Nominal mass flow rate";
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant souPHea(
    k=1)
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant souPCoo(
    k=1)
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant souPFan(
    k=1)
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant souPPum(
    k=1)
  Fluid.Sources.Boundary_pT sinSerAmbSup(
    redeclare final package Medium = MediumSer,
    nPorts=1) if typ == Buildings.DHC.Types.DistrictSystemType.CombinedGeneration5
    "Sink for service supply"
  Fluid.Sources.MassFlowSource_T souSerAmbRet(
    redeclare final package Medium = MediumSer,
    m_flow=m_flow_nominal,
    nPorts=1) if typ == Buildings.DHC.Types.DistrictSystemType.CombinedGeneration5
    "Source for service return"
  Fluid.Sources.Boundary_pT sinSerHeaSup(
    redeclare final package Medium = MediumSerHea_a,
    nPorts=1) if typ <> Buildings.DHC.Types.DistrictSystemType.Cooling and
    typ <> Buildings.DHC.Types.DistrictSystemType.CombinedGeneration5
    "Sink for service supply"
  Fluid.Sources.MassFlowSource_T souSerHeaReat(
    redeclare final package Medium = MediumSer,
    m_flow=m_flow_nominal,
    nPorts=1) if typ <> Buildings.DHC.Types.DistrictSystemType.Cooling and
    typ <> Buildings.DHC.Types.DistrictSystemType.CombinedGeneration5
    "Source for service return"
  Fluid.Sources.Boundary_pT sinHeaWat(
    redeclare final package Medium =MediumBui,
    nPorts=nPorts_aHeaWat) if have_heaWat
    "Sink for heating water"
  Fluid.Sources.Boundary_pT sinChiWat(
    redeclare final package Medium = MediumBui,
    nPorts=nPorts_aChiWat) if have_chiWat
    "Sink for chilled water"
  Fluid.Sources.MassFlowSource_T souHeaWat(
    redeclare final package Medium = MediumBui,
    m_flow=m_flow_nominal,
    nPorts=nPorts_bHeaWat) if have_heaWat
    "Source for heating water"
  Fluid.Sources.MassFlowSource_T souChiWat(
    redeclare final package Medium = MediumBui,
    m_flow=m_flow_nominal,
    nPorts=nPorts_bChiWat) if have_chiWat
    "Source for chilled water"
equation
  connect(port_aSerCoo, port_bSerCoo)
  connect(souPCoo.y,PCoo)
  connect(souPFan.y,PFan)
  connect(souPPum.y,PPum)
  connect(souPHea.y,PHea)
  connect(port_aSerAmb, sinSerAmbSup.ports[1])
  connect(souSerAmbRet.ports[1], port_bSerAmb)
  connect(port_aSerHea, sinSerHeaSup.ports[1])
  connect(souSerHeaReat.ports[1], port_bSerHea)
  connect(ports_aChiWat, sinChiWat.ports)
  connect(ports_aHeaWat, sinHeaWat.ports)
  connect(souChiWat.ports, ports_bChiWat)
  connect(souHeaWat.ports, ports_bHeaWat)
end ETS;


within Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses;
model FanCoil2PipeCooling
  "Model of a sensible only two-pipe fan coil unit for cooling,
  computing a required chilled water mass flow rate"
  extends Buildings.DHC.Loads.BaseClasses.PartialTerminalUnit(
    redeclare package Medium1=Buildings.Media.Water,
    redeclare package Medium2=Buildings.Media.Air,
    final have_heaPor=false,
    final have_fluPor=false,
    final have_fan=true,
    final have_heaWat=false,
    final have_chiWat=true,
    final have_QReq_flow=true,
    allowFlowReversal=false,
    final allowFlowReversalLoa=false,
    final have_chaOve=false,
    final have_eleHea=false,
    final have_eleCoo=false,
    final have_TSen=false,
    final have_weaBus=false,
    final have_pum=false,
    mChiWat_flow_nominal=abs(
      QCoo_flow_nominal/cpChiWat_nominal/(T_aChiWat_nominal-T_bChiWat_nominal)));
  import hexConfiguration=Buildings.Fluid.Types.HeatExchangerConfiguration;
  parameter Real k(
    min=0)=1
    "Gain of controller";
  parameter Modelica.Units.SI.Time Ti(min=Modelica.Constants.small) = 10
    "Time constant of integrator block";
  parameter Modelica.Units.SI.PressureDifference dpLoa_nominal(displayUnit="Pa")=
       250 "Load side pressure drop"
  final parameter hexConfiguration hexConCoo=hexConfiguration.CounterFlow
    "Cooling heat exchanger configuration";
  parameter Boolean have_speVar=true
    "Set to true for a variable speed fan (otherwise fan is always on)"
  parameter Modelica.Units.SI.HeatFlowRate QEnv_flow_nominal(min=0)
    "Nominal envelope heat loss (for room air temperature prediction)"
  parameter Modelica.Units.SI.TemperatureDifference dTEnv_nominal = 15
    "Design temperature difference at which envelope heat loss is QEnv_flow_nominal"

  Buildings.Controls.OBC.CDL.Reals.PIDWithReset con(
    final k=k,
    final Ti=Ti,
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    final reverseActing=true)
    "PI controller"
  Buildings.Fluid.Movers.FlowControlled_m_flow fan(
    redeclare final package Medium = Medium2,
    final allowFlowReversal=allowFlowReversalLoa,
    final m_flow_nominal=mLoaCoo_flow_nominal,
    redeclare final Fluid.Movers.Data.Generic per,
    nominalValuesDefineDefaultPressureCurve=true,
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState,
    use_riseTime=false,
    final dp_nominal=dpLoa_nominal) "Fan"
  Fluid.HeatExchangers.WetCoilEffectivenessNTU hexWetNtu(
    redeclare final package Medium1=Medium1,
    redeclare final package Medium2=Medium2,
    final configuration=hexConCoo,
    final m1_flow_nominal=mChiWat_flow_nominal,
    final m2_flow_nominal=mLoaCoo_flow_nominal,
    final dp1_nominal=0,
    final dp2_nominal=0,
    use_Q_flow_nominal=true,
    final Q_flow_nominal=QCoo_flow_nominal,
    final T_a1_nominal=T_aChiWat_nominal,
    final T_a2_nominal=T_aLoaCoo_nominal,
    final allowFlowReversal1=allowFlowReversal,
    final allowFlowReversal2=allowFlowReversalLoa,
    final w_a2_nominal=w_aLoaCoo_nominal)
    "Cooling coil"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiMasFlo(k=
        mChiWat_flow_nominal) "Scale water flow rate"
  Modelica.Blocks.Sources.RealExpression Q_flowCoo(
    final y=hexWetNtu.Q2_flow)
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiFloNom2(k=
        mLoaCoo_flow_nominal) "Scale air flow rate"
  Fluid.Sources.Boundary_pT sinAir(
    redeclare package Medium=Medium2,
    use_T_in=false,
    nPorts=1)
    "Sink for supply air"
  Fluid.Sources.Boundary_pT retAir(
    redeclare package Medium=Medium2,
    use_T_in=true,
    nPorts=1)
    "Source for return air"
  Buildings.DHC.Loads.BaseClasses.SimpleRoomODE TLoaODE(
    final dTEnv_nominal=dTEnv_nominal,
    TAir_start=297.15,
    final QEnv_flow_nominal=QEnv_flow_nominal) "Predicted room air temperature"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiHeaFlo(k=1/
        QCoo_flow_nominal)
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiHeaFlo1(k=1/
        QCoo_flow_nominal)
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    t=1E-4,
    h=0.5E-4)
    "Reset when demand rises from zero"
  Fluid.FixedResistances.PressureDrop resLoa(
    redeclare final package Medium = Medium2,
    final allowFlowReversal=allowFlowReversalLoa,
    final m_flow_nominal=mLoaCoo_flow_nominal,
    final dp_nominal=dpLoa_nominal)
    "Load side pressure drop"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one(k=1)
    "One constant"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con1(k=have_speVar)
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Logical switch"
equation
  connect(gaiFloNom2.y,fan.m_flow_in)
  connect(con.y,gaiMasFlo.u)
  connect(fan.P,mulPFan.u)
  connect(fan.port_b, hexWetNtu.port_a2)
  connect(hexWetNtu.port_b2, sinAir.ports[1])
  connect(Q_flowCoo.y,TLoaODE.QAct_flow)
  connect(TLoaODE.TAir,retAir.T_in)
  connect(gaiMasFlo.y,mulMasFloReqChiWat.u)
  connect(mulQReqCoo_flow.y,TLoaODE.QReq_flow)
  connect(Q_flowCoo.y,mulQActCoo_flow.u)
  connect(TSetCoo,TLoaODE.TSet)
  connect(mulQReqCoo_flow.y,gaiHeaFlo.u)
  connect(gaiHeaFlo.y,con.u_s)
  connect(con.u_m,gaiHeaFlo1.y)
  connect(Q_flowCoo.y,gaiHeaFlo1.u)
  connect(greThr.y,con.trigger)
  connect(gaiHeaFlo.y,greThr.u)
  connect(mulChiWatFloInl.port_b, hexWetNtu.port_a1)
  connect(hexWetNtu.port_b1, mulChiWatFloOut.port_a)
  connect(retAir.ports[1], resLoa.port_a)
  connect(resLoa.port_b, fan.port_a)
  connect(gaiFloNom2.u, swi.y)
  connect(con.y, swi.u1)
  connect(con1.y, swi.u2)
  connect(one.y, swi.u3)
end FanCoil2PipeCooling;


within Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses;
model FanCoil2PipeHeating
  "Model of a two-pipe fan coil unit for heating,
  computing a required heating water mass flow rate"
  extends Buildings.DHC.Loads.BaseClasses.PartialTerminalUnit(
    redeclare package Medium1=Buildings.Media.Water,
    redeclare package Medium2=Buildings.Media.Air,
    final have_heaPor=false,
    final have_fluPor=false,
    final have_fan=true,
    final have_heaWat=true,
    final have_chiWat=false,
    final have_QReq_flow=true,
    allowFlowReversal=false,
    final allowFlowReversalLoa=false,
    final have_chaOve=false,
    final have_eleHea=false,
    final have_eleCoo=false,
    final have_TSen=false,
    final have_weaBus=false,
    final have_pum=false,
    mHeaWat_flow_nominal=abs(
      QHea_flow_nominal/cpHeaWat_nominal/(T_aHeaWat_nominal-T_bHeaWat_nominal)));
  import hexConfiguration=Buildings.Fluid.Types.HeatExchangerConfiguration;
  parameter Real k(
    min=0)=1
    "Gain of controller";
  parameter Modelica.Units.SI.Time Ti(min=Modelica.Constants.small) = 10
    "Time constant of integrator block";
  parameter Modelica.Units.SI.PressureDifference dpLoa_nominal(displayUnit="Pa")=
       250 "Load side pressure drop"
  final parameter hexConfiguration hexConHea=hexConfiguration.CounterFlow
    "Heating heat exchanger configuration";
  parameter Boolean have_speVar=true
    "Set to true for a variable speed fan (otherwise fan is always on)"
  Buildings.Fluid.Movers.FlowControlled_m_flow fan(
    redeclare final package Medium = Medium2,
    final allowFlowReversal=allowFlowReversalLoa,
    final m_flow_nominal=mLoaHea_flow_nominal,
    redeclare final Fluid.Movers.Data.Generic per,
    nominalValuesDefineDefaultPressureCurve=true,
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState,
    use_riseTime=false,
    final dp_nominal=dpLoa_nominal) "Fan"
  Buildings.Controls.OBC.CDL.Reals.PIDWithReset con(
    final k=k,
    final Ti=Ti,
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    final reverseActing=true)
    "PI controller"
  Buildings.Fluid.HeatExchangers.DryCoilEffectivenessNTU hex(
    redeclare final package Medium1=Medium1,
    redeclare final package Medium2=Medium2,
    final configuration=hexConHea,
    final m1_flow_nominal=mHeaWat_flow_nominal,
    final m2_flow_nominal=mLoaHea_flow_nominal,
    final dp1_nominal=0,
    final dp2_nominal=0,
    final Q_flow_nominal=QHea_flow_nominal,
    final T_a1_nominal=T_aHeaWat_nominal,
    final T_a2_nominal=T_aLoaHea_nominal,
    final allowFlowReversal1=allowFlowReversal,
    final allowFlowReversal2=allowFlowReversalLoa)
    "Heating coil"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiMasFlo(k=
        mHeaWat_flow_nominal) "Scale water flow rate"
  Modelica.Blocks.Sources.RealExpression Q_flowHea(
    y=hex.Q2_flow)
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiFloNom2(k=
        mLoaHea_flow_nominal) "Scale air flow rate"
  Fluid.Sources.Boundary_pT sinAir(
    redeclare package Medium=Medium2,
    use_p_in=false,
    nPorts=1)
    "Sink for supply air"
  Fluid.Sources.Boundary_pT retAir(
    redeclare package Medium=Medium2,
    p(displayUnit="Pa"),
    use_T_in=true,
    nPorts=1)
    "Source for return air"
  Buildings.DHC.Loads.BaseClasses.SimpleRoomODE TLoaODE(
    dTEnv_nominal=25,
    TAir_start=293.15,
    QEnv_flow_nominal=QHea_flow_nominal) "Predicted room air temperature"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiHeaFlo(k=1/
        QHea_flow_nominal)
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiHeaFlo1(k=1/
        QHea_flow_nominal)
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Logical switch"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one(
    k=1)
    "One constant"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con1(
    k=have_speVar)
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold greThr(
    t=1E-4,
    h=0.5E-4)
    "Reset when demand rises from zero"
  Fluid.FixedResistances.PressureDrop resLoa(
    redeclare final package Medium = Medium2,
    final allowFlowReversal=allowFlowReversalLoa,
    final m_flow_nominal=mLoaHea_flow_nominal,
    final dp_nominal=dpLoa_nominal)
    "Load side pressure drop"
equation
  connect(gaiFloNom2.y,fan.m_flow_in)
  connect(con.y,gaiMasFlo.u)
  connect(gaiMasFlo.y,mulMasFloReqHeaWat.u)
  connect(fan.P,mulPFan.u)
  connect(Q_flowHea.y,mulQActHea_flow.u)
  connect(fan.port_b,hex.port_a2)
  connect(hex.port_b2,sinAir.ports[1])
  connect(TSetHea,TLoaODE.TSet)
  connect(TLoaODE.TAir,retAir.T_in)
  connect(gaiHeaFlo.y,con.u_s)
  connect(con.u_m,gaiHeaFlo1.y)
  connect(swi.y,gaiFloNom2.u)
  connect(con.y,swi.u1)
  connect(one.y,swi.u3)
  connect(con1.y,swi.u2)
  connect(mulQReqHea_flow.y,gaiHeaFlo.u)
  connect(mulQReqHea_flow.y,TLoaODE.QReq_flow)
  connect(Q_flowHea.y,gaiHeaFlo1.u)
  connect(Q_flowHea.y,TLoaODE.QAct_flow)
  connect(mulHeaWatFloInl.port_b,hex.port_a1)
  connect(hex.port_b1,mulHeaWatFloOut.port_a)
  connect(gaiHeaFlo.y,greThr.u)
  connect(greThr.y,con.trigger)
  connect(retAir.ports[1], resLoa.port_a)
  connect(resLoa.port_b, fan.port_a)
end FanCoil2PipeHeating;


within Buildings.DHC.Loads.BaseClasses.Validation.BaseClasses;
model FanCoil2PipeHeatingValve
  "Model of a two-pipe fan coil unit for heating, with a two-way control valve"
  extends Buildings.DHC.Loads.BaseClasses.PartialTerminalUnit(
    redeclare package Medium1=Buildings.Media.Water,
    redeclare package Medium2=Buildings.Media.Air,
    final have_heaPor=false,
    final have_fluPor=false,
    final have_fan=true,
    final have_heaWat=true,
    final have_chiWat=false,
    final have_QReq_flow=true,
    final allowFlowReversal=false,
    final allowFlowReversalLoa=false,
    final have_chaOve=false,
    final have_eleHea=false,
    final have_eleCoo=false,
    final have_TSen=false,
    final have_weaBus=false,
    final have_pum=false,
    final mHeaWat_flow_nominal=abs(
      QHea_flow_nominal/cpHeaWat_nominal/(T_aHeaWat_nominal-T_bHeaWat_nominal)));
  import hexConfiguration=Buildings.Fluid.Types.HeatExchangerConfiguration;
  final parameter hexConfiguration hexConHea=hexConfiguration.CounterFlow
    "Heating heat exchanger configuration";
  parameter Boolean have_speVar=true
    "Set to true for a variable speed fan (otherwise fan is always on)";
  parameter Modelica.Units.SI.PressureDifference dpLoa_nominal(displayUnit="Pa")=
       250 "Load side pressure drop"
  parameter Modelica.Units.SI.PressureDifference dpSou_nominal=30000
    "Nominal pressure drop on source side";
  Buildings.Fluid.Movers.FlowControlled_m_flow fan(
    redeclare final package Medium = Medium2,
    final allowFlowReversal=allowFlowReversalLoa,
    final m_flow_nominal=mLoaHea_flow_nominal,
    redeclare final Fluid.Movers.Data.Generic per,
    addPowerToMedium=true,
    nominalValuesDefineDefaultPressureCurve=true,
    energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyState,
    use_riseTime=false,
    final dp_nominal=dpLoa_nominal) "Fan"
  Buildings.Controls.OBC.CDL.Reals.PID con(
    Ti=10,
    yMax=1,
    controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI,
    reverseActing=true,
    yMin=0)
    "PI controller"
  Buildings.Fluid.HeatExchangers.DryCoilEffectivenessNTU hex(
    redeclare final package Medium1=Medium1,
    redeclare final package Medium2=Medium2,
    final configuration=hexConHea,
    final m1_flow_nominal=mHeaWat_flow_nominal,
    final m2_flow_nominal=mLoaHea_flow_nominal,
    final dp1_nominal=0,
    final dp2_nominal=0,
    final Q_flow_nominal=QHea_flow_nominal,
    final T_a1_nominal=T_aHeaWat_nominal,
    final T_a2_nominal=T_aLoaHea_nominal,
    final allowFlowReversal1=allowFlowReversal,
    final allowFlowReversal2=allowFlowReversalLoa)
    "Heating coil"
  Modelica.Blocks.Sources.RealExpression Q_flowHea(
    y=hex.Q2_flow)
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiFloNom2(k=
        mLoaHea_flow_nominal)
  Fluid.Sources.Boundary_pT sinAir(
    redeclare package Medium=Medium2,
    use_T_in=false,
    nPorts=1)
    "Sink for supply air"
  Fluid.Sources.Boundary_pT retAir(
    redeclare package Medium=Medium2,
    use_T_in=true,
    nPorts=1)
    "Source for return air"
  Buildings.DHC.Loads.BaseClasses.SimpleRoomODE TLoaODE(
    dTEnv_nominal=25,
    TAir_start=293.15,
    QEnv_flow_nominal=QHea_flow_nominal) "Predicted room air temperature"
  Fluid.Actuators.Valves.TwoWayEqualPercentage val(
    redeclare final package Medium=Medium1,
    final m_flow_nominal=mHeaWat_flow_nominal,
    dpValve_nominal=10000,
    use_strokeTime=false,
    final allowFlowReversal=allowFlowReversal,
    dpFixed_nominal=dpSou_nominal-10000)
  Fluid.Sensors.MassFlowRate senMasFlo(
    redeclare final package Medium=Medium1,
    final allowFlowReversal=allowFlowReversal)
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiHeaFlo(k=1/
        QHea_flow_nominal)
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gaiHeaFlo1(k=1/
        QHea_flow_nominal)
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant one(
    k=1)
    "One constant"
  Buildings.Controls.OBC.CDL.Logical.Sources.Constant con1(
    k=have_speVar)
  Buildings.Controls.OBC.CDL.Reals.Switch swi
    "Logical switch"
  Fluid.FixedResistances.PressureDrop resLoa(
    redeclare final package Medium = Medium2,
    final allowFlowReversal=allowFlowReversalLoa,
    final m_flow_nominal=mLoaHea_flow_nominal,
    final dp_nominal=dpLoa_nominal)
    "Load side pressure drop"
equation
  connect(gaiFloNom2.y,fan.m_flow_in)
  connect(fan.P,mulPFan.u)
  connect(Q_flowHea.y,mulQActHea_flow.u)
  connect(fan.port_b,hex.port_a2)
  connect(hex.port_b2,sinAir.ports[1])
  connect(TSetHea,TLoaODE.TSet)
  connect(mulQReqHea_flow.y,TLoaODE.QReq_flow)
  connect(Q_flowHea.y,TLoaODE.QAct_flow)
  connect(TLoaODE.TAir,retAir.T_in)
  connect(hex.port_b1,val.port_a)
  connect(val.port_b,senMasFlo.port_a)
  connect(con.y,val.y)
  connect(senMasFlo.m_flow,mulMasFloReqHeaWat.u)
  connect(mulQReqHea_flow.y,gaiHeaFlo.u)
  connect(gaiHeaFlo.y,con.u_s)
  connect(Q_flowHea.y,gaiHeaFlo1.u)
  connect(con.u_m,gaiHeaFlo1.y)
  connect(gaiFloNom2.u,swi.y)
  connect(con.y,swi.u1)
  connect(con1.y,swi.u2)
  connect(one.y,swi.u3)
  connect(senMasFlo.port_b,mulHeaWatFloOut.port_a)
  connect(mulHeaWatFloInl.port_b,hex.port_a1)
  connect(retAir.ports[1], resLoa.port_a)
  connect(resLoa.port_b, fan.port_a)
end FanCoil2PipeHeatingValve;


Package with base classes

within Buildings.DHC.Loads.BaseClasses.Validation;
package BaseClasses "Package with base classes"
  extends Modelica.Icons.BasesPackage;
end BaseClasses;


Model of a building with loads provided as time series, connected to an ETS. This model is composed of a heat pump based energy transfer station model

Buildings.DHC.ETS.Combined.HeatPumpHeatExchanger
connected to a simplified building model where the space heating, cooling
and hot water loads are provided as time series.

within Buildings.DHC.Loads.Combined;
model BuildingTimeSeriesWithETS
  "Model of a building with loads provided as time series, connected to an ETS"
  extends
    Buildings.DHC.Loads.Combined.BaseClasses.PartialBuildingWithETS(
    redeclare Buildings.DHC.Loads.BaseClasses.BuildingTimeSeries bui(
      filNam=filNam,
      have_hotWat=true,
      T_aHeaWat_nominal=ets.THeaWatSup_nominal,
      T_bHeaWat_nominal=ets.THeaWatRet_nominal,
      T_aChiWat_nominal=ets.TChiWatSup_nominal,
      T_bChiWat_nominal=ets.TChiWatRet_nominal),
    redeclare
      Buildings.DHC.ETS.Combined.HeatPumpHeatExchanger
      ets(
      final dT_nominal=dT_nominal,
      final TDisWatMin=TDisWatMin,
      final TDisWatMax=TDisWatMax,
      final TChiWatSup_nominal=TChiWatSup_nominal,
      final THeaWatSup_nominal=THeaWatSup_nominal,
      final THotWatSup_nominal=THotWatSup_nominal,
      final TColWat_nominal=TColWat_nominal,
      final dp_nominal=dp_nominal,
      final COPHeaWat_nominal=COPHeaWat_nominal,
      final COPHotWat_nominal=COPHotWat_nominal,
      have_hotWat=true,
      QChiWat_flow_nominal=QCoo_flow_nominal,
      QHeaWat_flow_nominal=QHea_flow_nominal,
      QHotWat_flow_nominal=QHot_flow_nominal));
  parameter String filNam
    "Library path of the file with thermal loads as time series";
  final parameter Modelica.Units.SI.HeatFlowRate QCoo_flow_nominal(
    max=-Modelica.Constants.eps)=
    bui.facMul * bui.QCoo_flow_nominal
    "Space cooling design load (<=0)"
  final parameter Modelica.Units.SI.HeatFlowRate QHea_flow_nominal(
    min=Modelica.Constants.eps)=
    bui.facMul * bui.QHea_flow_nominal
    "Space heating design load (>=0)"
  final parameter Modelica.Units.SI.HeatFlowRate QHot_flow_nominal(
    min=Modelica.Constants.eps)=
    bui.facMul * Buildings.DHC.Loads.BaseClasses.getPeakLoad(
      string="#Peak water heating load",
      filNam=Modelica.Utilities.Files.loadResource(filNam))
    "Hot water design load (>=0)"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput THotWatSupSet(
    final unit="K",
    displayUnit="degC")
    "Service hot water supply temperature set point"
  Buildings.Controls.OBC.CDL.Interfaces.RealInput TColWat(
    final unit="K",
    displayUnit="degC")
    "Cold water temperature"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter loaHeaNor(
    k=1/QHea_flow_nominal) "Normalized heating load"
  Buildings.Controls.OBC.CDL.Reals.GreaterThreshold enaHeaCoo[2](each t=1e-4)
    "Threshold comparison to enable heating and cooling"
  Modelica.Blocks.Sources.BooleanConstant enaSHW(
    final k=true) if have_hotWat
    "SHW production enable signal"
  Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter loaCooNor(k=1/
        QCoo_flow_nominal) "Normalized cooling load"
equation
  connect(bui.QReqHotWat_flow, ets.QReqHotWat_flow)
  connect(THotWatSupSet, ets.THotWatSupSet)
  connect(TColWat, ets.TColWat)
  connect(enaHeaCoo[1].y, ets.uHea)
  connect(enaHeaCoo[2].y, ets.uCoo)
  connect(enaSHW.y, ets.uSHW)
  connect(loaHeaNor.y, enaHeaCoo[1].u)
  connect(loaCooNor.y, enaHeaCoo[2].u)
  connect(bui.QReqHea_flow, loaHeaNor.u)
  connect(bui.QReqCoo_flow, loaCooNor.u)
  connect(loaHeaNor.y, resTHeaWatSup.u)
end BuildingTimeSeriesWithETS;