Air-to-water heat pump group

within Buildings.Templates.Plants.HeatPumps.Components.HeatPumpGroups;
model AirToWater
  "Air-to-water heat pump group"
  extends Buildings.Templates.Plants.HeatPumps.Components.Interfaces.PartialHeatPumpGroup(
    redeclare final package MediumSou=MediumAir,
    final typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
    final typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit);
  Buildings.Templates.Components.HeatPumps.AirToWater hp[nHp](
    each final show_T=show_T,
    redeclare each final package MediumHeaWat = MediumHeaWat,
    redeclare each final package MediumAir = MediumAir,
    each final is_rev=is_rev,
    final dat=datHp,
    each final allowFlowReversal=allowFlowReversal,
    each final energyDynamics=energyDynamics,
    each final have_dpChiHeaWat=have_dpChiHeaWatHp,
    each final have_dpSou=have_dpSou) "Heat pump unit"
equation
  for i in 1:nHp loop
    connect(busWea, hp[i].busWea)
  end for;
  connect(ports_aChiHeaWat, hp.port_a)
  connect(hp.port_b, ports_bChiHeaWat)
  connect(busHp, hp.bus)
  connect(ports_aSou, hp.port_aSou)
  connect(ports_bSou, hp.port_bSou)
end AirToWater;


Models for heat pump groups

within Buildings.Templates.Plants.HeatPumps.Components;
package HeatPumpGroups "Models for heat pump groups"
  extends Modelica.Icons.VariantsPackage;
end HeatPumpGroups;


Interface classes

within Buildings.Templates.Plants.HeatPumps.Components;
package Interfaces "Interface classes"
  extends Modelica.Icons.InterfacesPackage;
end Interfaces;


Interface for heat pump plant controller. This partial class provides a standard interface for heat pump plant controllers.

within Buildings.Templates.Plants.HeatPumps.Components.Interfaces;
block PartialController "Interface for heat pump plant controller"
  /*
  The following bindings are for parameters that are propagated *up*
  from the controller to the plant configuration record.
  All other configuration parameters (e.g. nHp) are propagated *down*
  from the plant configuration record to the controller.
  */
  parameter Buildings.Templates.Plants.HeatPumps.Configuration.HeatPumpPlant cfg(
    typCtl=typ,
    nAirHan=nAirHan,
    nEquZon=nEquZon,
    have_senDpHeaWatRemWir=have_senDpHeaWatRemWir,
    nSenDpHeaWatRem=nSenDpHeaWatRem,
    have_senDpChiWatRemWir=have_senDpChiWatRemWir,
    nSenDpChiWatRem=nSenDpChiWatRem)
    "Plant configuration parameters"
  parameter Buildings.Templates.Plants.HeatPumps.Components.Data.Controller dat(
    cfg=cfg)
    "Parameter record for controller";
  final parameter Integer nHp=cfg.nHp
    "Number of heat pumps"
  parameter Buildings.Templates.Plants.HeatPumps.Types.Controller typ
    "Type of controller"
  parameter Integer nAirHan(
    final min=if typ <> Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop
      and nEquZon == 0 then 1 else 0,
    start=0)
    "Number of air handling units served by the plant"
  parameter Integer nEquZon(
    final min=if typ <> Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop
      and nAirHan == 0 then 1 else 0,
    start=0)
    "Number of terminal units (zone equipment) served by the plant"
  parameter Boolean have_senVHeaWatPri_select(start=false)=false
    "Set to true for plants with primary HW flow sensor"
  final parameter Boolean have_senVHeaWatPri=cfg.have_heaWat and
    (if cfg.have_hrc or not have_senVHeaWatSec
    or cfg.typDis==Buildings.Templates.Plants.HeatPumps.Types.Distribution.Variable1Only
    then true else have_senVHeaWatPri_select)
    "Set to true for plants with primary HW flow sensor"
  // Secondary flow sensor required for secondary HW pump staging.
  final parameter Boolean have_senVHeaWatSec=
    cfg.typPumHeaWatSec<>Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None
    "Set to true for plants with secondary HW flow sensor"
  parameter Boolean have_senVChiWatPri_select(start=false)=have_senVHeaWatPri_select
    "Set to true for plants with primary CHW flow sensor"
  final parameter Boolean have_senVChiWatPri=cfg.have_chiWat and
    (if cfg.have_hrc or not have_senVChiWatSec
     or cfg.typDis<>Buildings.Templates.Plants.HeatPumps.Types.Distribution.Variable1Only
     then true else have_senVChiWatPri_select)
    "Set to true for plants with primary CHW flow sensor"
  // Secondary flow sensor required for secondary CHW pump staging.
  final parameter Boolean have_senVChiWatSec=
    cfg.typPumChiWatSec<>Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None
    "Set to true for plants with secondary CHW flow sensor"
  parameter Boolean have_senTHeaWatPriRet_select(start=false)=false
    "Set to true for plants with primary HW return temperature sensor"
  final parameter Boolean have_senTHeaWatPriRet=cfg.have_heaWat and
    (if cfg.have_hrc or not have_senTHeaWatSecRet then true else have_senTHeaWatPriRet_select)
    "Set to true for plants with primary HW return temperature sensor"
  parameter Boolean have_senTChiWatPriRet_select(start=false)=have_senTHeaWatPriRet_select
    "Set to true for plants with primary CHW return temperature sensor"
  final parameter Boolean have_senTChiWatPriRet=cfg.have_chiWat and
    (if cfg.have_hrc or not have_senTChiWatSecRet then true else have_senTChiWatPriRet_select)
    "Set to true for plants with primary CHW return temperature sensor"
  // For primary-secondary plants, SHWST sensor is required for plant staging.
  final parameter Boolean have_senTHeaWatSecSup=
    cfg.typPumHeaWatSec<>Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None
    "Set to true for plants with secondary HW supply temperature sensor"
  // For primary-secondary plants, SCHWST sensor is required for plant staging.
  final parameter Boolean have_senTChiWatSecSup=
    cfg.typPumChiWatSec<>Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None
    "Set to true for plants with secondary CHW supply temperature sensor"

  // Following return temperature sensors are:
  // - optional for primary-secondary plants without HRC,
  // - required for plants with HRC: downstream of HRC.
  parameter Boolean have_senTHeaWatSecRet_select(start=false)=false
    "Set to true for plants with secondary HW return temperature sensor"
  parameter Boolean have_senTChiWatSecRet_select(start=false)=have_senTHeaWatSecRet_select
    "Set to true for plants with secondary CHW return temperature sensor"
  final parameter Boolean have_senTHeaWatSecRet=
    if cfg.have_hrc then true
    elseif cfg.typPumHeaWatSec==Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None then false
    else have_senTHeaWatSecRet_select
    "Set to true for plants with secondary HW return temperature sensor"
  final parameter Boolean have_senTChiWatSecRet(start=false)=
    if cfg.have_hrc then true
    elseif cfg.typPumChiWatSec==Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None then false
    else have_senTChiWatSecRet_select
    "Set to true for plants with secondary CHW return temperature sensor"
  parameter Boolean have_senDpHeaWatRemWir=false
    "Set to true for remote HW differential pressure sensor(s) hardwired to plant or pump controller"
  parameter Integer nSenDpHeaWatRem(
    final min=if typ <> Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop
      then 1 else 0)=1
    "Number of remote HW differential pressure sensors used for HW pump speed control"
  parameter Boolean have_senDpChiWatRemWir=have_senDpHeaWatRemWir
    "Set to true for remote CHW differential pressure sensor(s) hardwired to plant or pump controller"
  parameter Integer nSenDpChiWatRem(
    final min=if typ <> Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop
      then 1 else 0)=1
    "Number of remote CHW differential pressure sensors used for CHW pump speed control"
  parameter Boolean have_inpSch(start=false)=false
    "Set to true to provide schedule via software input point"
  final parameter Real schHea[:, 2]=dat.schHea
    "Heating mode enable schedule"
  final parameter Real schCoo[:, 2]=dat.schCoo
    "Cooling mode enable schedule"
  Buildings.Templates.Plants.HeatPumps.Interfaces.Bus bus
    "Plant control bus"
  Buildings.Templates.AirHandlersFans.Interfaces.Bus busAirHan[nAirHan]
    if nAirHan > 0
    "Air handling unit control bus"
  Buildings.Templates.ZoneEquipment.Interfaces.Bus busEquZon[nEquZon]
    if nEquZon > 0
    "Terminal unit control bus"
protected
  Buildings.Templates.Components.Interfaces.Bus busHp[nHp]
    "Heat pump control bus"
  Buildings.Templates.Components.Interfaces.Bus busPumHeaWatPri
    if cfg.typPumHeaWatPri<>Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.None
    "Primary HW pump control bus"
  Buildings.Templates.Components.Interfaces.Bus busPumHeaWatSec if cfg.typPumHeaWatSec
     == Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.Centralized
    "Secondary HW pump control bus"
  Buildings.Templates.Components.Interfaces.Bus busPumChiWatPri if cfg.typPumChiWatPri
     <> Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.None
    "Primary CHW pump control bus"
  Buildings.Templates.Components.Interfaces.Bus busPumChiWatSec if cfg.typPumHeaWatSec
     == Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.Centralized
    "Secondary CHW pump control bus"
  Buildings.Templates.Components.Interfaces.Bus busValHeaWatHpInlIso[nHp]
    if cfg.have_heaWat and cfg.have_valHpInlIso
    "Heat pump inlet HW isolation valve control bus"
  Buildings.Templates.Components.Interfaces.Bus busValHeaWatHpOutIso[nHp]
    if cfg.have_heaWat and cfg.have_valHpOutIso
    "Heat pump outlet HW isolation valve control bus"
  Buildings.Templates.Components.Interfaces.Bus busValChiWatHpInlIso[nHp]
    if cfg.have_chiWat and cfg.have_valHpInlIso
    "Heat pump inlet CHW isolation valve control bus"
  Buildings.Templates.Components.Interfaces.Bus busValChiWatHpOutIso[nHp]
    if cfg.have_chiWat and cfg.have_valHpOutIso
    "Heat pump outlet CHW isolation valve control bus"
  Buildings.Templates.Components.Interfaces.Bus busPumChiWatHrc if cfg.have_hrc
    "Sidestream HRC CHW pump control bus"
  Buildings.Templates.Components.Interfaces.Bus busPumHeaWatHrc if cfg.have_hrc
    "Sidestream HRC HW pump control bus"
  Buildings.Templates.Components.Interfaces.Bus busHrc if cfg.have_hrc
    "Sidestream HRC control bus"
  Buildings.Templates.Components.Interfaces.Bus busValHeaWatMinByp
    if cfg.have_valHeaWatMinByp "HW minimum flow bypass valve control bus"
  Buildings.Templates.Components.Interfaces.Bus busValChiWatMinByp
    if cfg.have_valChiWatMinByp "CHW minimum flow bypass valve control bus"
equation
  /* Control point connection - start */
  connect(busPumHeaWatPri, bus.pumHeaWatPri);
  connect(busPumChiWatPri, bus.pumChiWatPri);
  connect(busPumChiWatSec, bus.pumChiWatSec);
  connect(busPumHeaWatSec, bus.pumHeaWatSec);
  connect(busHp, bus.hp);
  connect(busValHeaWatHpInlIso, bus.valHeaWatHpInlIso);
  connect(busValHeaWatHpOutIso, bus.valHeaWatHpOutIso);
  connect(busValChiWatHpInlIso, bus.valChiWatHpInlIso);
  connect(busValChiWatHpOutIso, bus.valChiWatHpOutIso);
  connect(busValHeaWatMinByp, bus.valHeaWatMinByp);
  connect(busValChiWatMinByp, bus.valChiWatMinByp);
  connect(busHrc, bus.hrc);
  connect(busPumChiWatHrc, bus.pumChiWatHrc);
  connect(busPumHeaWatHrc, bus.pumHeaWatHrc);
  /* Control point connection - stop */
end PartialController;


Interface for heat pump group

within Buildings.Templates.Plants.HeatPumps.Components.Interfaces;
model PartialHeatPumpGroup "Interface for heat pump group"
  replaceable package MediumHeaWat=Buildings.Media.Water
    constrainedby Modelica.Media.Interfaces.PartialMedium
    "HW medium"
  /*
  MediumChiWat is for internal use only.
  It is the same as MediumHeaWat for reversible HP.
  Non-reversible HP that can be controlled to produce either HW or CHW
  shall be modeled with chiller components (as a chiller/heater).
  */
    final package MediumChiWat=MediumHeaWat
    "CHW medium";
  /*
  Derived classes representing AWHP shall use:
  redeclare final package MediumSou = MediumAir
  */
    replaceable package MediumSou=Buildings.Media.Water
    constrainedby Modelica.Media.Interfaces.PartialMedium
    "Source-side medium"
  replaceable package MediumAir=Buildings.Media.Air
    constrainedby Modelica.Media.Interfaces.PartialMedium
    "Air medium"
  parameter Integer nHp(
    final min=1)
    "Number of heat pumps"
  parameter Buildings.Templates.Components.Types.HeatPump typ
    "Equipment type"
  parameter Boolean is_rev
    "Set to true for reversible heat pumps, false for heating only"
  parameter Buildings.Templates.Components.Types.HeatPumpModel typMod=
    Buildings.Templates.Components.Types.HeatPumpModel.EquationFit
    "Type of heat pump model"
  parameter Buildings.Templates.Plants.HeatPumps.Components.Data.HeatPumpGroup dat(
    nHp=nHp,
    typ=typ,
    is_rev=is_rev,
    typMod=typMod,
    cpHeaWat_default=cpHeaWat_default,
    cpSou_default=cpSou_default)
    "Design and operating parameters"
  final parameter Buildings.Templates.Components.Data.HeatPump datHp[nHp](
    each final is_rev=is_rev,
    each final typ=typ,
    each final typMod=typMod,
    each final cpHeaWat_default=cpHeaWat_default,
    each final cpSou_default=cpSou_default,
    each final mHeaWat_flow_nominal=dat.mHeaWatHp_flow_nominal,
    each final mSouWwCoo_flow_nominal=dat.mSouWwCooHp_flow_nominal,
    each final TSouHea_nominal=dat.TSouHeaHp_nominal,
    each final mChiWat_flow_nominal=dat.mChiWatHp_flow_nominal,
    each final dpSouWwHea_nominal=dat.dpSouWwHeaHp_nominal,
    each final THeaWatSup_nominal=dat.THeaWatSupHp_nominal,
    each final dpHeaWat_nominal=dat.dpHeaWatHp_nominal,
    each final mSouWwHea_flow_nominal=dat.mSouWwHeaHp_flow_nominal,
    each final TSouCoo_nominal=dat.TSouCooHp_nominal,
    each final perFit=dat.perFitHp,
    each final capCoo_nominal=dat.capCooHp_nominal,
    each final TChiWatSup_nominal=dat.TChiWatSupHp_nominal,
    each final capHea_nominal=dat.capHeaHp_nominal)
    "Design and operating parameters - Each heat pump";
  final parameter Modelica.Units.SI.MassFlowRate mHeaWatHp_flow_nominal=dat.mHeaWatHp_flow_nominal
    "Design HW mass flow rate - Each heat pump";
  final parameter Modelica.Units.SI.HeatFlowRate capHeaHp_nominal=dat.capHeaHp_nominal
    "Design heating capacity - Each heat pump";
  final parameter Modelica.Units.SI.HeatFlowRate QHeaHp_flow_nominal=abs(capHeaHp_nominal)
    "Design heating heat flow rate - Each heat pump";
  final parameter Modelica.Units.SI.PressureDifference dpHeaWatHp_nominal=dat.dpHeaWatHp_nominal
    "Design HW pressure drop - Each heat pump";
  final parameter Modelica.Units.SI.Temperature THeaWatSupHp_nominal=dat.THeaWatSupHp_nominal
    "Design HW supply temperature - Each heat pump";
  final parameter Modelica.Units.SI.Temperature THeaWatRetHp_nominal=dat.THeaWatRetHp_nominal
    "Design HW return temperature - Each heat pump";
  final parameter Modelica.Units.SI.MassFlowRate mChiWatHp_flow_nominal=dat.mChiWatHp_flow_nominal
    "Design CHW mass flow rate - Each heat pump"
  final parameter Modelica.Units.SI.PressureDifference dpChiWatHp_nominal=dat.dpChiWatHp_nominal
    "Design CHW pressure drop - Each heat pump";
  final parameter Modelica.Units.SI.HeatFlowRate capCooHp_nominal=dat.capCooHp_nominal
    "Design cooling capacity - Each heat pump";
  final parameter Modelica.Units.SI.HeatFlowRate QCooHp_flow_nominal=- abs(capCooHp_nominal)
    "Design cooling heat flow rate - Each heat pump";
  final parameter Modelica.Units.SI.Temperature TChiWatSupHp_nominal=dat.TChiWatSupHp_nominal
    "Design CHW supply temperature - Each heat pump";
  final parameter Modelica.Units.SI.Temperature TChiWatRetHp_nominal=dat.TChiWatRetHp_nominal
    "Design CHW return temperature - Each heat pump";
  final parameter Modelica.Units.SI.MassFlowRate mSouHeaHp_flow_nominal=dat.mSouHeaHp_flow_nominal
    "Design source fluid mass flow rate in heating mode - Each heat pump";
  final parameter Modelica.Units.SI.PressureDifference dpSouHeaHp_nominal=dat.dpSouHeaHp_nominal
    "Design source fluid pressure drop in heating mode - Each heat pump";
  final parameter Modelica.Units.SI.MassFlowRate mSouCooHp_flow_nominal=dat.mSouCooHp_flow_nominal
    "Design source fluid mass flow rate in cooling mode - Each heat pump";
  final parameter Modelica.Units.SI.PressureDifference dpSouCooHp_nominal=dat.dpSouCooHp_nominal
    "Designs source fluid pressure drop in cooling mode - Each heat pump";
  final parameter Modelica.Units.SI.Temperature TSouCooHp_nominal=dat.TSouCooHp_nominal
    "Design OAT or source fluid supply temperature (condenser entering) in cooling mode - Each heat pump";
  final parameter Modelica.Units.SI.Temperature TSouHeaHp_nominal=dat.TSouHeaHp_nominal
    "Design OAT or source fluid supply temperature (evaporator entering) in heating mode - Each heat pump";
  parameter Modelica.Fluid.Types.Dynamics energyDynamics=Modelica.Fluid.Types.Dynamics.DynamicFreeInitial
    "Type of energy balance: dynamic (3 initialization options) or steady state"
  parameter Boolean allowFlowReversal=true
    "Load side flow reversal: false to simplify equations, assuming, but not enforcing, no flow reversal"
  parameter Boolean allowFlowReversalSou=true
    "Source side flow reversal: false to simplify equations, assuming, but not enforcing, no flow reversal"
  parameter Boolean have_dpChiHeaWatHp=true
    "Set to true for HP CHW/HW pressure drop computed by this model, false for external computation"
  parameter Boolean have_dpSou=true
    "Set to true for source fluid pressure drop computed by this model, false for external computation"
  final parameter MediumHeaWat.SpecificHeatCapacity cpHeaWat_default=
    MediumHeaWat.specificHeatCapacityCp(staHeaWat_default)
    "HW default specific heat capacity";
  final parameter MediumHeaWat.ThermodynamicState staHeaWat_default=MediumHeaWat.setState_pTX(
    T=THeaWatSupHp_nominal,
    p=MediumHeaWat.p_default,
    X=MediumHeaWat.X_default)
    "HW default state";
  final parameter MediumChiWat.SpecificHeatCapacity cpChiWat_default=
    MediumChiWat.specificHeatCapacityCp(staChiWat_default)
    "CHW default specific heat capacity";
  final parameter MediumChiWat.ThermodynamicState staChiWat_default=MediumChiWat.setState_pTX(
    T=TChiWatSupHp_nominal,
    p=MediumChiWat.p_default,
    X=MediumChiWat.X_default)
    "CHW default state";
  final parameter MediumSou.SpecificHeatCapacity cpSou_default=MediumSou.specificHeatCapacityCp(staSou_default)
    "Source fluid default specific heat capacity";
  final parameter MediumSou.ThermodynamicState staSou_default=MediumSou.setState_pTX(
    T=TSouHeaHp_nominal,
    p=MediumSou.p_default,
    X=MediumSou.X_default)
    "Source fluid default state";
  Modelica.Fluid.Interfaces.FluidPorts_b ports_bChiHeaWat[nHp](
    redeclare each final package Medium=MediumHeaWat,
    each m_flow(
      max=if allowFlowReversal then + Modelica.Constants.inf else 0),
    each h_outflow(
      start=MediumHeaWat.h_default,
      nominal=MediumHeaWat.h_default))
    "CHW/HW supply"
  Modelica.Fluid.Interfaces.FluidPorts_a ports_aChiHeaWat[nHp](
    redeclare each final package Medium=MediumHeaWat,
    each m_flow(
      min=if allowFlowReversal then - Modelica.Constants.inf else 0),
    each h_outflow(
      start=MediumHeaWat.h_default,
      nominal=MediumHeaWat.h_default))
    "CHW/HW return"
  Modelica.Fluid.Interfaces.FluidPorts_b ports_bSou[nHp](
    redeclare each final package Medium=MediumSou,
    each m_flow(
      max=if allowFlowReversalSou then + Modelica.Constants.inf else 0),
    each h_outflow(
      start=MediumSou.h_default,
      nominal=MediumSou.h_default))
    "Source fluid return (from heat pumps)"
  Modelica.Fluid.Interfaces.FluidPorts_a ports_aSou[nHp](
    redeclare each final package Medium=MediumSou,
    each m_flow(
      min=if allowFlowReversalSou then - Modelica.Constants.inf else 0),
    each h_outflow(
      start=MediumSou.h_default,
      nominal=MediumSou.h_default))
    "Source fluid supply (to heat pumps)"
  Buildings.Templates.Plants.HeatPumps.Interfaces.Bus bus
    "Plant control bus"
  Buildings.BoundaryConditions.WeatherData.Bus busWea
    if typ == Buildings.Templates.Components.Types.HeatPump.AirToWater
    "Weather bus"
  // Diagnostics
  parameter Boolean show_T=false
    "= true, if actual temperature at port is computed"
  MediumHeaWat.ThermodynamicState sta_aChiHeaWat[nHp]=MediumHeaWat.setState_phX(ports_aChiHeaWat.p, noEvent(actualStream(ports_aChiHeaWat.h_outflow)), noEvent(actualStream(ports_aChiHeaWat.Xi_outflow)))
    if show_T
    "CHW/HW medium properties in port_aChiHeaWat";
  MediumHeaWat.ThermodynamicState sta_bChiHeaWat[nHp]=MediumHeaWat.setState_phX(ports_bChiHeaWat.p, noEvent(actualStream(ports_bChiHeaWat.h_outflow)), noEvent(actualStream(ports_bChiHeaWat.Xi_outflow)))
    if show_T
    "CHW/HW medium properties in port_bChiHeaWat";
  MediumSou.ThermodynamicState sta_aSou[nHp]=MediumSou.setState_phX(ports_aSou.p, noEvent(actualStream(ports_aSou.h_outflow)), noEvent(actualStream(ports_aSou.Xi_outflow)))
    if show_T
    "Source medium properties in port_aSou";
  MediumSou.ThermodynamicState sta_bSou[nHp]=MediumSou.setState_phX(ports_bSou.p, noEvent(actualStream(ports_bSou.h_outflow)), noEvent(actualStream(ports_bSou.Xi_outflow)))
    if show_T
    "Source medium properties in port_bSou";
protected
  Buildings.Templates.Components.Interfaces.Bus busHp[nHp]
    "Heat pump control bus"
equation
  connect(bus.hp, busHp)
end PartialHeatPumpGroup;


Validation model for heat pump group

within Buildings.Templates.Plants.HeatPumps.Components.Validation;
model HeatPumpGroupAirToWater
  "Validation model for heat pump group"
  extends Modelica.Icons.Example;
  replaceable package Medium=Buildings.Media.Water
    constrainedby Modelica.Media.Interfaces.PartialMedium
    "CHW/HW medium";
  parameter Modelica.Fluid.Types.Dynamics energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial
    "Type of energy balance: dynamic (3 initialization options) or steady state"
  parameter Data.Controller datCtlPlaAwNrv(
    cfg(
      have_hrc = false,
      have_inpSch = false,
      have_chiWat=false,
      typPumHeaWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumChiWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.None,
      typPumHeaWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      typTanHeaWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typTanChiWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      have_pumHeaWatPriVar=true,
      have_pumChiWatPriVar=false,
      typDis=Buildings.Templates.Plants.HeatPumps.Types.Distribution.Constant1Only,
      have_pumChiWatPriDed=false,
      nPumChiWatSec=0,
      rhoHeaWat_default=Buildings.Media.Water.d_const,
      typCtl=Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop,
      is_rev=hpAwNrv.is_rev,
      typ=hpAwNrv.typ,
      rhoChiWat_default=Buildings.Media.Water.d_const,
      cpChiWat_default=hpAwNrv.cpChiWat_default,
      have_hotWat=false,
      have_valChiWatMinByp=false,
      have_valHeaWatMinByp=false,
      have_valHpInlIso=false,
      have_valHpOutIso=false,
      typMod=hpAwNrv.typMod,
      cpHeaWat_default=hpAwNrv.cpHeaWat_default,
      cpSou_default=hpAwNrv.cpSou_default,
      have_senDpChiWatRemWir=true,
      typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
      nHp=hpAwNrv.nHp,
      nPumHeaWatPri=hpAwNrv.nHp,
      have_heaWat=true,
      nPumHeaWatSec=0,
      rhoSou_default=Buildings.Media.Air.dStp,
      have_senDpHeaWatRemWir=true,
      typPumChiWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      nPumChiWatPri=hpAwNrv.nHp,
      nSenDpHeaWatRem=1,
      nSenDpChiWatRem=1,
      nAirHan=0,
      nEquZon=0),
    THeaWatSup_nominal=datHpAwNrv.THeaWatSupHp_nominal,
    dpChiWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpChiWatRemSet_max, datCtlPlaAwNrv.cfg.nSenDpChiWatRem),
    dpHeaWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpHeaWatRemSet_max, datCtlPlaAwNrv.cfg.nSenDpHeaWatRem),
    staEqu={fill(1, hpAwNrv.nHp)})
    "Controller parameters"
  parameter Data.Controller datCtlPlaAw(
    cfg(
      have_hrc = false,
      have_inpSch = false,
      have_chiWat=true,
      typPumHeaWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumChiWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumHeaWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      typTanHeaWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typTanChiWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      have_pumHeaWatPriVar=true,
      have_pumChiWatPriVar=true,
      typDis=Buildings.Templates.Plants.HeatPumps.Types.Distribution.Constant1Only,
      have_pumChiWatPriDed=false,
      nPumChiWatSec=0,
      rhoHeaWat_default=Buildings.Media.Water.d_const,
      typCtl=Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop,
      is_rev=hpAw.is_rev,
      typ=hpAw.typ,
      rhoChiWat_default=Buildings.Media.Water.d_const,
      cpChiWat_default=hpAw.cpChiWat_default,
      have_hotWat=false,
      have_valChiWatMinByp=false,
      have_valHeaWatMinByp=false,
      have_valHpInlIso=true,
      have_valHpOutIso=true,
      typMod=hpAw.typMod,
      cpHeaWat_default=hpAw.cpHeaWat_default,
      cpSou_default=hpAw.cpSou_default,
      have_senDpChiWatRemWir=true,
      typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
      nHp=hpAw.nHp,
      nPumHeaWatPri=hpAw.nHp,
      have_heaWat=true,
      nPumHeaWatSec=0,
      rhoSou_default=Buildings.Media.Air.dStp,
      have_senDpHeaWatRemWir=true,
      typPumChiWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      nPumChiWatPri=hpAw.nHp,
      nSenDpHeaWatRem=1,
      nSenDpChiWatRem=1,
      nAirHan=0,
      nEquZon=0),
    THeaWatSup_nominal=datHpAw.THeaWatSupHp_nominal,
    TChiWatSup_nominal=datHpAw.TChiWatSupHp_nominal,
    dpChiWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpChiWatRemSet_max, datCtlPlaAw.cfg.nSenDpChiWatRem),
    dpHeaWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpHeaWatRemSet_max, datCtlPlaAw.cfg.nSenDpHeaWatRem),
    staEqu={fill(1, hpAw.nHp)})
    "Controller parameters"

  parameter Buildings.Templates.Plants.HeatPumps.Components.Data.HeatPumpGroup datHpAwNrv(
    final cpHeaWat_default=hpAwNrv.cpHeaWat_default,
    final cpSou_default=hpAwNrv.cpSou_default,
    final nHp=hpAwNrv.nHp,
    final typ=hpAwNrv.typ,
    final is_rev=hpAwNrv.is_rev,
    final typMod=hpAwNrv.typMod,
    mHeaWatHp_flow_nominal=datHpAwNrv.capHeaHp_nominal / abs(datHpAwNrv.THeaWatSupHp_nominal -
      Buildings.Templates.Data.Defaults.THeaWatRetMed) / Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
    dpHeaWatHp_nominal=Buildings.Templates.Data.Defaults.dpHeaWatHp,
    capHeaHp_nominal=500E3,
    THeaWatSupHp_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TSouHeaHp_nominal=Buildings.Templates.Data.Defaults.TOutHpHeaLow,
    perFitHp(
      hea(
        P=datHpAwNrv.capHeaHp_nominal / Buildings.Templates.Data.Defaults.COPHpAwHea,
        coeQ={- 4.2670305442, - 0.7381077035, 6.0049480456, 0, 0},
        coeP={- 4.9107455513, 5.3665308366, 0.5447612754, 0, 0},
        TRefLoa=Buildings.Templates.Data.Defaults.THeaWatRetMed,
        TRefSou=Buildings.Templates.Data.Defaults.TOutHpHeaLow)))
    "Non-reversible AWHP parameters"
  parameter Buildings.Templates.Plants.HeatPumps.Components.Data.HeatPumpGroup datHpAw(
    final cpHeaWat_default=hpAw.cpHeaWat_default,
    final cpSou_default=hpAw.cpSou_default,
    final nHp=hpAw.nHp,
    final typ=hpAw.typ,
    final is_rev=hpAw.is_rev,
    final typMod=hpAw.typMod,
    mHeaWatHp_flow_nominal=datHpAw.capHeaHp_nominal / abs(datHpAw.THeaWatSupHp_nominal -
      Buildings.Templates.Data.Defaults.THeaWatRetMed) / Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
    dpHeaWatHp_nominal=Buildings.Templates.Data.Defaults.dpHeaWatHp,
    capHeaHp_nominal=500E3,
    THeaWatSupHp_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TSouHeaHp_nominal=Buildings.Templates.Data.Defaults.TOutHpHeaLow,
    mChiWatHp_flow_nominal=datHpAw.capCooHp_nominal / abs(datHpAw.TChiWatSupHp_nominal -
      Buildings.Templates.Data.Defaults.TChiWatRet) / Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
    capCooHp_nominal=500E3,
    TChiWatSupHp_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
    TSouCooHp_nominal=Buildings.Templates.Data.Defaults.TOutHpCoo,
    perFitHp(
      hea(
        P=datHpAw.capHeaHp_nominal / Buildings.Templates.Data.Defaults.COPHpAwHea,
        coeQ={- 4.2670305442, - 0.7381077035, 6.0049480456, 0, 0},
        coeP={- 4.9107455513, 5.3665308366, 0.5447612754, 0, 0},
        TRefLoa=Buildings.Templates.Data.Defaults.THeaWatRetMed,
        TRefSou=Buildings.Templates.Data.Defaults.TOutHpHeaLow),
      coo(
        P=datHpAw.capCooHp_nominal / Buildings.Templates.Data.Defaults.COPHpAwCoo,
        coeQ={- 2.2545246871, 6.9089257665, - 3.6548225094, 0, 0},
        coeP={- 5.8086010402, 1.6894933858, 5.1167787436, 0, 0},
        TRefLoa=Buildings.Templates.Data.Defaults.TChiWatRet,
        TRefSou=Buildings.Templates.Data.Defaults.TOutHpCoo)))
    "Reversible AWHP parameters"
  Fluid.Sources.Boundary_pT sup(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pHeaWat_rel_nominal + 101325,
    nPorts=hpAwNrv.nHp)
    "Boundary condition at distribution system supply"
  Fluid.Sources.Boundary_pT inlHp1(
    redeclare final package Medium=Medium,
    use_p_in=true,
    use_T_in=true,
    nPorts=hpAwNrv.nHp) "Boundary conditions at HP inlet"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
    filNam=Modelica.Utilities.Files.loadResource(
      "modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
  Fluid.Sensors.TemperatureTwoPort TRet1[hpAwNrv.nHp](
    redeclare each final package Medium=Medium,
    each final m_flow_nominal=datHpAwNrv.mHeaWatHp_flow_nominal)
    "Return temperature"
  Fluid.Sensors.TemperatureTwoPort TSup1[hpAwNrv.nHp](
    redeclare each final package Medium=Medium,
    each final m_flow_nominal=datHpAwNrv.mHeaWatHp_flow_nominal)
    "Supply temperature"
  Controls.OpenLoop ctlPlaAwNrv(
    final cfg=datCtlPlaAwNrv.cfg,
    final dat=datCtlPlaAwNrv)
    "Plant controller"
  HeatPumpGroups.AirToWater hpAwNrv(
    redeclare final package MediumHeaWat=Medium,
    nHp=3,
    is_rev=false,
    final dat=datHpAwNrv,
    final energyDynamics=energyDynamics)
    "Non reversible AWHP"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin THeaWatRet(
    amplitude=datHpAwNrv.THeaWatSupHp_nominal - datHpAwNrv.THeaWatRetHp_nominal,
    freqHz=3 / 3000,
    y(final unit="K",
      displayUnit="degC"),
    offset=datHpAwNrv.THeaWatRetHp_nominal,
    startTime=0)
    "HW return temperature value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant pHeaWatInl(
    k=sup.p + datHpAwNrv.dpHeaWatHp_nominal)
    "HW inlet pressure"
  HeatPumpGroups.AirToWater hpAw(
    redeclare final package MediumHeaWat=Medium,
    nHp=3,
    is_rev=true,
    final dat=datHpAw,
    final energyDynamics=energyDynamics)
    "Reversible AWHP"
  Controls.OpenLoop ctlPlaAw(
    final cfg=datCtlPlaAw.cfg,
    final dat=datCtlPlaAw)
    "Plant controller"
  Fluid.Sources.Boundary_pT inlHp(
    redeclare final package Medium=Medium,
    use_p_in=true,
    use_T_in=true,
    nPorts=hpAwNrv.nHp)
    "Boundary conditions at HP inlet"
  Fluid.Sensors.TemperatureTwoPort TRet[hpAw.nHp](
    redeclare each final package Medium=Medium,
    each final m_flow_nominal=datHpAw.mHeaWatHp_flow_nominal)
    "Return temperature"
  Fluid.Sources.Boundary_pT sup1(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pHeaWat_rel_nominal + 101325,
    nPorts=hpAwNrv.nHp)
    "Boundary condition at distribution system supply"
  Fluid.Sensors.TemperatureTwoPort TSup[hpAw.nHp](
    redeclare each final package Medium=Medium,
    each final m_flow_nominal=datHpAw.mHeaWatHp_flow_nominal)
    "Supply temperature"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin THeaWatRet1(
    amplitude=datHpAw.THeaWatSupHp_nominal - datHpAw.THeaWatRetHp_nominal,
    freqHz=3 / 3000,
    y(final unit="K",
      displayUnit="degC"),
    offset=datHpAw.THeaWatRetHp_nominal,
    startTime=0)
    "HW return temperature value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Sin TChiWatRet(
    amplitude=datHpAw.TChiWatRetHp_nominal - datHpAw.TChiWatSupHp_nominal,
    freqHz=3 / 3000,
    y(final unit="K",
      displayUnit="degC"),
    offset=datHpAw.TChiWatRetHp_nominal,
    startTime=0)
    "CHW return temperature value"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant pHeaWatInl1(
    k=sup.p + hpAw.dpHeaWatHp_nominal)
    "HW inlet pressure"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant pChiWatInl(
    k=sup.p + hpAw.dpChiWatHp_nominal)
    "CHW inlet pressure"
  Buildings.Controls.OBC.CDL.Reals.Switch TRetAct
    "Active return temperature"
  Buildings.Controls.OBC.CDL.Reals.Switch pInl_rel
    "Active inlet gaupe pressure"
  Buildings.Templates.Plants.HeatPumps.Interfaces.Bus busPla
    "Plant controller"
  Buildings.Templates.Components.Interfaces.Bus busHp[hpAw.nHp]
    "HP control bus"
equation
  connect(ctlPlaAwNrv.bus, hpAwNrv.bus)
  connect(inlHp1.ports, TRet1.port_a)
  connect(TRet1.port_b, hpAwNrv.ports_aChiHeaWat)
  connect(hpAwNrv.ports_bChiHeaWat, TSup1.port_a)
  connect(TSup1.port_b, sup.ports)
  connect(weaDat.weaBus, hpAwNrv.busWea)
  connect(THeaWatRet.y, inlHp1.T_in)
  connect(pHeaWatInl.y, inlHp1.p_in)
  connect(weaDat.weaBus, hpAw.busWea)
  connect(ctlPlaAw.bus, hpAw.bus)
  connect(inlHp.ports, TRet.port_a)
  connect(TRet.port_b, hpAw.ports_aChiHeaWat)
  connect(TSup.port_b, sup1.ports)
  connect(hpAw.ports_bChiHeaWat, TSup.port_a)
  connect(THeaWatRet1.y, TRetAct.u1)
  connect(TChiWatRet.y, TRetAct.u3)
  connect(pHeaWatInl1.y, pInl_rel.u1)
  connect(pChiWatInl.y, pInl_rel.u3)
  connect(pInl_rel.y, inlHp.p_in)
  connect(TRetAct.y, inlHp.T_in)
  connect(busPla, ctlPlaAw.bus)
  connect(busPla.hp, busHp)
  connect(busHp[1].y1Hea, pInl_rel.u2)
  connect(pInl_rel.u2, TRetAct.u2)
end HeatPumpGroupAirToWater;


within Buildings.Templates.Plants.HeatPumps.Components.Validation;
model HeatRecoveryChiller
  "Validation model for heat recovery chiller"
  extends Modelica.Icons.Example;
  replaceable package Medium=Buildings.Media.Water
    constrainedby Modelica.Media.Interfaces.PartialMedium
    "CHW/HW medium";
  parameter Modelica.Fluid.Types.Dynamics energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial
    "Type of energy balance: dynamic (3 initialization options) or steady state"
  parameter Buildings.Templates.Components.Data.Chiller datHrc(
    final typ=Buildings.Templates.Components.Types.Chiller.WaterCooled,
    redeclare Buildings.Fluid.Chillers.Data.ElectricReformulatedEIR.ReformEIRChiller_Trane_CGWD_207kW_3_99COP_None per,
    cap_nominal=500E3,
    COP_nominal=3.8,
    dpChiWat_nominal=Buildings.Templates.Data.Defaults.dpChiWatChi,
    dpCon_nominal=Buildings.Templates.Data.Defaults.dpConWatChi,
    TChiWatSup_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
    TConEnt_nominal=Buildings.Templates.Data.Defaults.THeaWatRetMed,
    mChiWat_flow_nominal=datHrc.cap_nominal / abs(datHrc.TChiWatSup_nominal -
      Buildings.Templates.Data.Defaults.TChiWatRet) / Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
    mCon_flow_nominal=datHrc.QCon_flow_nominal / abs(datHrc.TConEnt_nominal -
      Buildings.Templates.Data.Defaults.THeaWatSupMed) / Buildings.Utilities.Psychrometrics.Constants.cpWatLiq)
    "HRC parameters"
  parameter Buildings.Templates.Components.Data.PumpSingle datPumChiWatHrc(
    final typ=Buildings.Templates.Components.Types.Pump.Single,
    m_flow_nominal=datHrc.mChiWat_flow_nominal,
    dp_nominal=datHrc.dpChiWat_nominal)
    "HRC CHW pump parameters"
  parameter Buildings.Templates.Components.Data.PumpSingle datPumHeaWatHrc(
    final typ=Buildings.Templates.Components.Types.Pump.Single,
    m_flow_nominal=datHrc.mCon_flow_nominal,
    dp_nominal=datHrc.dpCon_nominal)
    "HRC HW pump parameters"
  Buildings.Templates.Plants.HeatPumps.Components.HeatRecoveryChiller hrc(
    redeclare final package MediumChiWat=Medium,
    redeclare final package MediumHeaWat=Medium,
    final datPumChiWat=datPumChiWatHrc,
    final datPumHeaWat=datPumHeaWatHrc,
    final datHrc=datHrc,
    final energyDynamics=energyDynamics)
  Fluid.Sources.Boundary_pT inlChiWat(
    redeclare final package Medium=Medium,
    T=datHrc.TChiWatRet_nominal,
    nPorts=1)
    "Boundary conditions for HRC entering CHW"
  Fluid.Sources.Boundary_pT inlHeaWat(
    redeclare final package Medium=Medium,
    T=datHrc.TConEnt_nominal,
    nPorts=1)
    "Boundary conditions for HRC entering HW"
  Fluid.Sources.Boundary_pT outHeaWat(
    redeclare final package Medium=Medium,
    nPorts=1)
    "Boundary conditions for HRC leaving HW"
  Fluid.Sources.Boundary_pT outChiWat(
    redeclare final package Medium=Medium,
    nPorts=1)
    "Boundary conditions for HRC leaving CHW"
  Buildings.Templates.Components.Interfaces.Bus busHrc
    "HRC control bus"
  Buildings.Templates.Components.Interfaces.Bus busPumChiWatHrc
    "HRC CHW pump control bus"
  Buildings.Templates.Components.Interfaces.Bus busPumHeaWatHrc
    "HRC HW pump control bus"
  Buildings.Controls.OBC.CDL.Logical.Sources.TimeTable y1(
    table=[
      0, 0, 0;
      0.1, 1, 1;
      0.5, 1, 0;
      0.9, 0, 0],
    timeScale=1000,
    period=1000)
    "Source for DO signals"
  Buildings.Controls.OBC.CDL.Reals.Switch TSupSet(
    y(
      unit="K",
      displayUnit="degC"))
    "HRC supply temperature setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant TChiWatSupSet(
    final k=datHrc.TChiWatSup_nominal)
    "CHW supply temperature setpoint"
  Buildings.Controls.OBC.CDL.Reals.Sources.Constant THeaWatSupSet(
    final k=datHrc.TConLvg_nominal)
    "HW supply temperature setpoint"
  Fluid.Sensors.TemperatureTwoPort THeaWatLvg(
    redeclare final package Medium=Medium,
    final m_flow_nominal=datHrc.mCon_flow_nominal)
    "HRC leaving HW temperature"
  Fluid.Sensors.TemperatureTwoPort TChiWatLvg(
    redeclare final package Medium=Medium,
    final m_flow_nominal=datHrc.mChiWat_flow_nominal)
    "HRC leaving CHW temperature"
  Buildings.Templates.Plants.HeatPumps.Interfaces.Bus bus
    "Plant control bus"
equation
  connect(inlHeaWat.ports[1], hrc.port_a1)
  connect(y1.y[1], busPumHeaWatHrc.y1)
  connect(y1.y[1], busPumChiWatHrc.y1)
  connect(y1.y[1], busHrc.y1)
  connect(y1.y[2], busHrc.y1Coo)
  connect(y1.y[2], TSupSet.u2)
  connect(TChiWatSupSet.y, TSupSet.u1)
  connect(THeaWatSupSet.y, TSupSet.u3)
  connect(TSupSet.y, busHrc.TSupSet)
  connect(outHeaWat.ports[1], THeaWatLvg.port_b)
  connect(THeaWatLvg.port_a, hrc.port_b1)
  connect(hrc.port_b2, TChiWatLvg.port_a)
  connect(TChiWatLvg.port_b, outChiWat.ports[1])
  connect(inlChiWat.ports[1], hrc.port_a2)
  connect(busHrc, bus.hrc)
  connect(bus, hrc.bus)
  connect(busPumChiWatHrc, bus.pumChiWatHrc)
  connect(busPumHeaWatHrc, bus.pumHeaWatHrc)
end HeatRecoveryChiller;


Package with validation models

within Buildings.Templates.Plants.HeatPumps.Components;
package Validation "Package with validation models"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


within Buildings.Templates.Plants.HeatPumps.Components.Validation;
model PumpsPrimaryDedicated
  "Validation model for dedicated primary pump component"
  extends Modelica.Icons.Example;
  replaceable package Medium=Buildings.Media.Water
    constrainedby Modelica.Media.Interfaces.PartialMedium
    "CHW/HW medium";
  parameter Boolean use_spePumIni = false
    "Set to true to compute pump speed at initialization, false to use default value"
  parameter Modelica.Fluid.Types.Dynamics energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial
    "Type of energy balance: dynamic (3 initialization options) or steady state"
  // Calculation of pump speed to meet design flow.
  parameter Real r_N[pumPriHea.nPum](
    each final fixed=false,
    each start=1,
    each final unit="1")
    "Relative revolution, r_N=N/N_nominal";
  parameter Real r_NDef[pumPriHea.nPum](
    each start=1,
    each final unit="1")=fill(0.85, pumPriHea.nPum)
    "Default value for relative revolution, r_N=N/N_nominal";
  parameter Data.Controller datCtl(
    cfg(
      have_pumHeaWatPriVar=false,
      have_pumChiWatPriVar=false,
      have_inpSch=false,
      have_hrc=false,
      have_valHpOutIso=false,
      have_valHpInlIso=true,
      have_chiWat=true,
      have_pumChiWatPriDed=false,
      typPumHeaWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumChiWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.None,
      typPumHeaWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      typTanHeaWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typTanChiWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typDis=Buildings.Templates.Plants.HeatPumps.Types.Distribution.Constant1Only,
      nPumChiWatSec=0,
      rhoHeaWat_default=Buildings.Media.Water.d_const,
      typCtl=Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop,
      is_rev=true,
      typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
      rhoChiWat_default=Buildings.Media.Water.d_const,
      cpChiWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_hotWat=false,
      have_valChiWatMinByp=false,
      have_valHeaWatMinByp=false,
      typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit,
      cpHeaWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      cpSou_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_senDpChiWatRemWir=true,
      typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
      nHp=2,
      nPumHeaWatPri=2,
      have_heaWat=true,
      nPumHeaWatSec=0,
      rhoSou_default=Buildings.Media.Air.dStp,
      have_senDpHeaWatRemWir=true,
      typPumChiWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      nPumChiWatPri=0,
      nSenDpHeaWatRem=0,
      nSenDpChiWatRem=0,
      nAirHan=0,
      nEquZon=0),
    THeaWatSup_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TChiWatSup_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
    dpChiWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpChiWatRemSet_max, datCtl.cfg.nSenDpChiWatRem),
    dpHeaWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpHeaWatRemSet_max, datCtl.cfg.nSenDpHeaWatRem),
    staEqu={fill(1, datCtl.cfg.nHp)})
    "Controller parameters"
  parameter Data.Controller datCtlNoDed(
    cfg(
      have_pumHeaWatPriVar=false,
      have_pumChiWatPriVar=false,
      have_inpSch=false,
      have_hrc=false,
      have_valHpOutIso=false,
      have_valHpInlIso=true,
      have_chiWat=true,
      have_pumChiWatPriDed=false,
      typPumHeaWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumChiWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumHeaWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      typTanHeaWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typTanChiWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typDis=Buildings.Templates.Plants.HeatPumps.Types.Distribution.Constant1Only,
      nPumChiWatSec=0,
      rhoHeaWat_default=Buildings.Media.Water.d_const,
      typCtl=Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop,
      is_rev=true,
      typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
      rhoChiWat_default=Buildings.Media.Water.d_const,
      cpChiWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_hotWat=false,
      have_valChiWatMinByp=false,
      have_valHeaWatMinByp=false,
      typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit,
      cpHeaWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      cpSou_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_senDpChiWatRemWir=true,
      typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Headered,
      nHp=2,
      nPumHeaWatPri=2,
      have_heaWat=true,
      nPumHeaWatSec=0,
      rhoSou_default=Buildings.Media.Air.dStp,
      have_senDpHeaWatRemWir=true,
      typPumChiWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      nPumChiWatPri=0,
      nSenDpHeaWatRem=0,
      nSenDpChiWatRem=0,
      nAirHan=0,
      nEquZon=0),
    THeaWatSup_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TChiWatSup_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
    dpChiWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpChiWatRemSet_max, datCtlNoDed.cfg.nSenDpChiWatRem),
    dpHeaWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpHeaWatRemSet_max, datCtlNoDed.cfg.nSenDpHeaWatRem),
    staEqu={fill(1, datCtlNoDed.cfg.nHp)})
    "Controller parameters"
  parameter Data.Controller datCtlSep(
    cfg(
      have_pumHeaWatPriVar=false,
      have_pumChiWatPriVar=false,
      have_inpSch=false,
      have_hrc=false,
      have_valHpOutIso=false,
      have_valHpInlIso=true,
      have_chiWat=true,
      have_pumChiWatPriDed=true,
      typPumHeaWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumChiWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumHeaWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      typTanHeaWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typTanChiWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typDis=Buildings.Templates.Plants.HeatPumps.Types.Distribution.Constant1Only,
      nPumChiWatSec=0,
      rhoHeaWat_default=Buildings.Media.Water.d_const,
      typCtl=Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop,
      is_rev=true,
      typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
      rhoChiWat_default=Buildings.Media.Water.d_const,
      cpChiWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_hotWat=false,
      have_valChiWatMinByp=false,
      have_valHeaWatMinByp=false,
      typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit,
      cpHeaWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      cpSou_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_senDpChiWatRemWir=true,
      typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
      nHp=2,
      nPumHeaWatPri=2,
      nPumChiWatPri=2,
      have_heaWat=true,
      nPumHeaWatSec=0,
      rhoSou_default=Buildings.Media.Air.dStp,
      have_senDpHeaWatRemWir=true,
      typPumChiWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      nSenDpHeaWatRem=0,
      nSenDpChiWatRem=0,
      nAirHan=0,
      nEquZon=0),
    THeaWatSup_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TChiWatSup_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
    dpChiWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpChiWatRemSet_max, datCtlSep.cfg.nSenDpChiWatRem),
    dpHeaWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpHeaWatRemSet_max, datCtlSep.cfg.nSenDpHeaWatRem),
    staEqu={fill(1, datCtlSep.cfg.nHp)})
    "Controller parameters"
  parameter Data.Controller datCtlHea(
    cfg(
      have_pumHeaWatPriVar=true,
      have_pumChiWatPriVar=false,
      have_inpSch=false,
      have_hrc=false,
      have_valHpOutIso=false,
      have_valHpInlIso=false,
      have_chiWat=false,
      have_pumChiWatPriDed=false,
      typPumHeaWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumChiWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.None,
      typPumHeaWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      typTanHeaWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typTanChiWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typDis=Buildings.Templates.Plants.HeatPumps.Types.Distribution.Constant1Only,
      nPumChiWatSec=0,
      rhoHeaWat_default=Buildings.Media.Water.d_const,
      typCtl=Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop,
      is_rev=false,
      typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
      rhoChiWat_default=Buildings.Media.Water.d_const,
      cpChiWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_hotWat=false,
      have_valChiWatMinByp=false,
      have_valHeaWatMinByp=false,
      typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit,
      cpHeaWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      cpSou_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_senDpChiWatRemWir=true,
      typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
      nHp=2,
      nPumHeaWatPri=2,
      nPumChiWatPri=0,
      have_heaWat=true,
      nPumHeaWatSec=0,
      rhoSou_default=Buildings.Media.Air.dStp,
      have_senDpHeaWatRemWir=true,
      typPumChiWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      nSenDpHeaWatRem=0,
      nSenDpChiWatRem=0,
      nAirHan=0,
      nEquZon=0),
    THeaWatSup_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    dpChiWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpChiWatRemSet_max, datCtlHea.cfg.nSenDpChiWatRem),
    dpHeaWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpHeaWatRemSet_max, datCtlHea.cfg.nSenDpHeaWatRem),
    staEqu={fill(1, datCtlHea.cfg.nHp)})
    "Controller parameters"
  parameter Data.HeatPumpGroup datHp(
    final nHp=2,
    final typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
    final is_rev=true,
    final typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit,
    mHeaWatHp_flow_nominal=datHp.capHeaHp_nominal / abs(datHp.THeaWatSupHp_nominal -
      Buildings.Templates.Data.Defaults.THeaWatRetMed) / Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
    dpHeaWatHp_nominal=Buildings.Templates.Data.Defaults.dpHeaWatHp,
    capHeaHp_nominal=500E3,
    THeaWatSupHp_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TSouHeaHp_nominal=Buildings.Templates.Data.Defaults.TOutHpHeaLow,
    mChiWatHp_flow_nominal=datHp.capCooHp_nominal / abs(datHp.TChiWatSupHp_nominal -
      Buildings.Templates.Data.Defaults.TChiWatRet) / Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
    capCooHp_nominal=500E3,
    TChiWatSupHp_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
    TSouCooHp_nominal=Buildings.Templates.Data.Defaults.TOutHpCoo,
    perFitHp(
      hea(
        P=datHp.capHeaHp_nominal / Buildings.Templates.Data.Defaults.COPHpAwHea,
        coeQ={- 4.2670305442, - 0.7381077035, 6.0049480456, 0, 0},
        coeP={- 4.9107455513, 5.3665308366, 0.5447612754, 0, 0},
        TRefLoa=Buildings.Templates.Data.Defaults.THeaWatRetMed,
        TRefSou=Buildings.Templates.Data.Defaults.TOutHpHeaLow),
      coo(
        P=datHp.capCooHp_nominal / Buildings.Templates.Data.Defaults.COPHpAwCoo,
        coeQ={- 2.2545246871, 6.9089257665, - 3.6548225094, 0, 0},
        coeP={- 5.8086010402, 1.6894933858, 5.1167787436, 0, 0},
        TRefLoa=Buildings.Templates.Data.Defaults.TChiWatRet,
        TRefSou=Buildings.Templates.Data.Defaults.TOutHpCoo)))
    "HP parameters"
  parameter Buildings.Templates.Components.Data.PumpMultiple datPumPriCom(
    typ=Buildings.Templates.Components.Types.Pump.Multiple,
    nPum=datHp.nHp,
    m_flow_nominal=fill(max(datHp.mHeaWatHp_flow_nominal, datHp.mChiWatHp_flow_nominal),
        datHp.nHp),
    dp_nominal=fill(max(datHp.dpHeaWatHp_nominal, datHp.dpChiWatHp_nominal) +
        Buildings.Templates.Data.Defaults.dpValChe + max(max(valChiWatIsoCom.dpValve_nominal),
        max(valHeaWatIsoCom.dpValve_nominal)), datHp.nHp))
    "Primary pump parameters"
  parameter Buildings.Templates.Components.Data.PumpMultiple datPumHeaWat(
    typ=Buildings.Templates.Components.Types.Pump.Multiple,
    nPum=datHp.nHp,
    m_flow_nominal=fill(datHp.mHeaWatHp_flow_nominal, datHp.nHp),
    dp_nominal=fill(datHp.dpHeaWatHp_nominal + Buildings.Templates.Data.Defaults.dpValChe
         + max(valHeaWatIsoCom.dpValve_nominal), datHp.nHp))
    "Dedicated primary HW pump parameters"
  parameter Buildings.Templates.Components.Data.PumpMultiple datPumChiWat(
    typ=Buildings.Templates.Components.Types.Pump.Multiple,
    nPum=datHp.nHp,
    m_flow_nominal=fill(datHp.mChiWatHp_flow_nominal, datHp.nHp),
    dp_nominal=fill(datHp.dpChiWatHp_nominal + Buildings.Templates.Data.Defaults.dpValChe
         + max(valHeaWatIsoCom.dpValve_nominal), datHp.nHp))
    "Dedicated primary CHW pump parameters"
  parameter Buildings.Templates.Components.Data.PumpMultiple datPumHeaWatHea(
    typ=Buildings.Templates.Components.Types.Pump.Multiple,
    nPum=datHp.nHp,
    m_flow_nominal=fill(datHp.mHeaWatHp_flow_nominal, datHp.nHp),
    dp_nominal=1.5 * fill(datHp.dpHeaWatHp_nominal + Buildings.Templates.Data.Defaults.dpValChe
         + max(valHeaWatIsoCom.dpValve_nominal), datHp.nHp))
    "Dedicated primary HW pump parameters – Heating-only system"
  final parameter Buildings.Templates.Components.Data.PumpSingle datPumSin[
    pumPriCom.nHp](
    each typ=datPumPriCom.typ,
    m_flow_nominal=datPumPriCom.m_flow_nominal,
    dp_nominal=datPumPriCom.dp_nominal,
    per=datPumPriCom.per,
    each rho_default=datPumPriCom.rho_default)
    "Cast multiple pump record into single pump record array";
  final parameter Buildings.Templates.Components.Data.PumpSingle datPumHeaWatHeaSin[pumPriHea.nHp](
    each typ=datPumHeaWatHea.typ,
    m_flow_nominal=datPumHeaWatHea.m_flow_nominal,
    dp_nominal=datPumHeaWatHea.dp_nominal,
    per=datPumHeaWatHea.per,
    each rho_default=datPumHeaWatHea.rho_default)
    "Cast multiple pump record into single pump record array";
  Buildings.Templates.Plants.HeatPumps.Components.PumpsPrimaryDedicated
    pumPriCom(
    redeclare final package Medium = Medium,
    nHp=2,
    typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
    have_pumChiWatPriDed=false,
    have_pumHeaWatPriVar=false,
    have_pumChiWatPriVar=false,
    datPumHeaWat=datPumPriCom,
    final energyDynamics=energyDynamics)
    "Primary pumps - Heating and cooling system with common constant speed dedicated primary pumps"
  Fluid.FixedResistances.PressureDrop hpCom[pumPriCom.nHp](
    redeclare each final package Medium = Medium,
    each m_flow_nominal=datHp.mHeaWatHp_flow_nominal,
    each dp_nominal=datHp.dpHeaWatHp_nominal) "Heat pump HX"
  Fluid.Sources.Boundary_pT ret(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pHeaWat_rel_nominal + 101325,
    nPorts=datHp.nHp)
    "Boundary condition at return"
  Controls.OpenLoop ctl(
    final cfg=datCtl.cfg,
    final dat=datCtl)
    "Plant controller"
  Buildings.Templates.Plants.HeatPumps.Components.PumpsPrimaryDedicated
    pumPriNoDed(
    redeclare final package Medium = Medium,
    nHp=2,
    typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Headered,
    have_pumChiWatPriDed=false,
    have_pumHeaWatPriVar=false,
    have_pumChiWatPriVar=false,
    datPumHeaWat=datPumPriCom,
    final energyDynamics=energyDynamics)
    "No dedicated primary pumps (headered pumps)"
  Fluid.FixedResistances.PressureDrop hpHdr[pumPriCom.nHp](
    redeclare each final package Medium = Medium,
    each m_flow_nominal=datHp.mHeaWatHp_flow_nominal,
    each dp_nominal=datHp.dpHeaWatHp_nominal)
    "Heat pump HX"
  Fluid.Sources.Boundary_pT ret1(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pHeaWat_rel_nominal + 101325,
    nPorts=datHp.nHp)
    "Boundary condition at return"
  Controls.OpenLoop ctlNoDed(
    final cfg=datCtlNoDed.cfg,
    final dat=datCtlNoDed)
    "Plant controller"
  Buildings.Templates.Components.Pumps.Multiple pumPriHdr(
    have_var=false,
    final energyDynamics=energyDynamics,
    nPum=2,
    dat=datPumPriCom) "Headered primary pumps"
  Buildings.Templates.Plants.HeatPumps.Interfaces.Bus busPla
    "Plant control bus"
  Buildings.Templates.Plants.HeatPumps.Components.PumpsPrimaryDedicated pumPriSep(
    redeclare final package Medium=Medium,
    nHp=2,
    typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
    have_pumChiWatPriDed=true,
    have_pumHeaWatPriVar=false,
    have_pumChiWatPriVar=false,
    datPumHeaWat=datPumHeaWat,
    final datPumChiWat=datPumChiWat,
    final energyDynamics=energyDynamics)
    "Primary pumps - Heating and cooling system with separate constant speed dedicated CHW pumps"
  Fluid.Sources.Boundary_pT ret2(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pHeaWat_rel_nominal + 101325,
    nPorts=datHp.nHp)
    "Boundary condition at return"
  Controls.OpenLoop ctlSep(
    final cfg=datCtlSep.cfg,
    final dat=datCtlSep)
    "Plant controller"
  Fluid.FixedResistances.PressureDrop hpSep[pumPriCom.nHp](
    redeclare each final package Medium = Medium,
    each m_flow_nominal=datHp.mHeaWatHp_flow_nominal,
    each dp_nominal=datHp.dpHeaWatHp_nominal) "Heat pump HX"
  Buildings.Templates.Components.Actuators.Valve valHeaWatIsoCom[datHp.nHp](
    redeclare each final package Medium = Medium,
    each typ=Buildings.Templates.Components.Types.Valve.TwoWayTwoPosition,
    dat(
      each m_flow_nominal=datHp.mHeaWatHp_flow_nominal,
      each dpValve_nominal=Buildings.Templates.Data.Defaults.dpValIso,
      dpFixed_nominal=
          Buildings.Templates.Utilities.computeBalancingPressureDrop(
          m_flow_nominal=fill(datHp.mHeaWatHp_flow_nominal, datHp.nHp),
          dp_nominal=pumPriCom.dpValCheHeaWat_nominal*(datHp.mHeaWatHp_flow_nominal
            /max(datHp.mHeaWatHp_flow_nominal, datHp.mChiWatHp_flow_nominal))^2 .+
            fill(datHp.dpHeaWatHp_nominal, datHp.nHp) .+ valHeaWatIsoCom.dpValve_nominal,
          datPum=datPumSin)),
    each from_dp=true) "Primary HW loop isolation valve"
  Buildings.Templates.Components.Actuators.Valve valChiWatIsoCom[datHp.nHp](
    redeclare each final package Medium = Medium,
    each typ=Buildings.Templates.Components.Types.Valve.TwoWayTwoPosition,
    dat(
      each m_flow_nominal=datHp.mChiWatHp_flow_nominal,
      each dpValve_nominal=Buildings.Templates.Data.Defaults.dpValIso,
      dpFixed_nominal=
          Buildings.Templates.Utilities.computeBalancingPressureDrop(
          m_flow_nominal=fill(datHp.mChiWatHp_flow_nominal, datHp.nHp),
          dp_nominal=pumPriCom.dpValCheHeaWat_nominal*(datHp.mChiWatHp_flow_nominal
            /max(datHp.mHeaWatHp_flow_nominal, datHp.mChiWatHp_flow_nominal))^2 .+
            fill(datHp.dpChiWatHp_nominal, datHp.nHp) .+ valChiWatIsoCom.dpValve_nominal,
          datPum=datPumSin)),
    each from_dp=true) "Primary CHW loop isolation valve"
  Buildings.Templates.Plants.HeatPumps.Interfaces.Bus busPla1
    "Plant control bus"
  Buildings.Templates.Components.Actuators.Valve valChiWatIsoHdr[datHp.nHp](
    redeclare each final package Medium = Medium,
    each typ=Buildings.Templates.Components.Types.Valve.TwoWayTwoPosition,
    dat(
      each m_flow_nominal=datHp.mChiWatHp_flow_nominal,
      each dpValve_nominal=Buildings.Templates.Data.Defaults.dpValIso,
      dpFixed_nominal=
          Buildings.Templates.Utilities.computeBalancingPressureDrop(
          m_flow_nominal=fill(datHp.mChiWatHp_flow_nominal, datHp.nHp),
          dp_nominal=pumPriHdr.dpValChe_nominal*(datHp.mChiWatHp_flow_nominal/
            max(datHp.mHeaWatHp_flow_nominal, datHp.mChiWatHp_flow_nominal))^2 .+
            fill(datHp.dpChiWatHp_nominal, datHp.nHp) .+ valChiWatIsoCom.dpValve_nominal,
          datPum=datPumSin)),
    each from_dp=true) "Primary CHW loop isolation valve"
  Buildings.Templates.Components.Actuators.Valve valHeaWatIsoHdr[datHp.nHp](
    redeclare each final package Medium = Medium,
    each typ=Buildings.Templates.Components.Types.Valve.TwoWayTwoPosition,
    dat(
      each m_flow_nominal=datHp.mHeaWatHp_flow_nominal,
      each dpValve_nominal=Buildings.Templates.Data.Defaults.dpValIso,
      dpFixed_nominal=
          Buildings.Templates.Utilities.computeBalancingPressureDrop(
          m_flow_nominal=fill(datHp.mHeaWatHp_flow_nominal, datHp.nHp),
          dp_nominal=pumPriHdr.dpValChe_nominal*(datHp.mHeaWatHp_flow_nominal/
            max(datHp.mHeaWatHp_flow_nominal, datHp.mChiWatHp_flow_nominal))^2 .+
            fill(datHp.dpHeaWatHp_nominal, datHp.nHp) .+ valHeaWatIsoCom.dpValve_nominal,
          datPum=datPumSin)),
    each from_dp=true) "Primary HW loop isolation valve"
  Buildings.Templates.Components.Actuators.Valve valHeaWatIsoSep[datHp.nHp](
    redeclare each final package Medium=Medium,
    each typ=Buildings.Templates.Components.Types.Valve.TwoWayTwoPosition,
    dat(
      each m_flow_nominal=datHp.mHeaWatHp_flow_nominal,
      each dpValve_nominal=Buildings.Templates.Data.Defaults.dpValIso),
    each from_dp=true,
    each linearized=true)
    "Primary HW loop isolation valve"
  Buildings.Templates.Components.Actuators.Valve valChiWatIsoSep[datHp.nHp](
    redeclare each final package Medium=Medium,
    each typ=Buildings.Templates.Components.Types.Valve.TwoWayTwoPosition,
    dat(
      each m_flow_nominal=datHp.mChiWatHp_flow_nominal,
      each dpValve_nominal=Buildings.Templates.Data.Defaults.dpValIso),
    each from_dp=true,
    each linearized=true)
    "Primary CHW loop isolation valve"
  Buildings.Templates.Plants.HeatPumps.Interfaces.Bus busPla2
    "Plant control bus"
  Buildings.Templates.Plants.HeatPumps.Components.PumpsPrimaryDedicated pumPriHea(
    redeclare final package Medium=Medium,
    nHp=2,
    typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
    have_pumChiWatPriDed=false,
    have_pumHeaWatPriVar=true,
    have_pumChiWatPriVar=false,
    datPumHeaWat=datPumHeaWatHea,
    final energyDynamics=energyDynamics)
    "Primary pumps - Heating-only system with variable speed dedicated primary pumps"
  Fluid.Sources.Boundary_pT ret3(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pHeaWat_rel_nominal + 101325,
    nPorts=1)
    "Boundary condition at return"
  Controls.OpenLoop ctlHea(
    final cfg=datCtlHea.cfg,
    final dat=datCtlHea,
    yPumHeaWatPriDed(k=r_N))
    "Plant controller"
  Fluid.FixedResistances.PressureDrop hpHea[pumPriCom.nHp](
    redeclare each final package Medium = Medium,
    each m_flow_nominal=datHp.mHeaWatHp_flow_nominal,
    each dp_nominal=datHp.dpHeaWatHp_nominal) "Heat pump HX"
  Fluid.FixedResistances.PressureDrop priHeaWat(
    redeclare final package Medium=Medium,
    final m_flow_nominal=sum(datPumHeaWat.m_flow_nominal),
    final dp_nominal=0)
    "Primary HW loop"
initial equation
  // Calculation of pump speed to provide design flow.
  if use_spePumIni then
    fill(0, pumPriHea.nHp)=Buildings.Templates.Utilities.computeBalancingPressureDrop(
      m_flow_nominal=fill(datHp.mHeaWatHp_flow_nominal, pumPriHea.nHp),
      dp_nominal=pumPriHea.dpValCheHeaWat_nominal .+ fill(datHp.dpHeaWatHp_nominal, pumPriHea.nHp) .+
        fill(Buildings.Templates.Data.Defaults.dpValIso, pumPriHea.nHp),
      datPum=datPumHeaWatHeaSin,
      r_N=r_N);
  else
    r_N=r_NDef;
  end if;
equation
  for i in 1:(pumPriHea.nHp) loop
    connect(pumPriHea.ports_bChiHeaWat[i], priHeaWat.port_a)
    connect(priHeaWat.port_b, pumPriHea.ports_aChiHeaWat[i])
  end for;
  connect(pumPriCom.ports_bChiHeaWatHp, hpCom.port_a)
  connect(hpCom.port_b, pumPriCom.ports_aChiHeaWatHp)
  connect(pumPriNoDed.ports_bChiHeaWatHp, hpHdr.port_a)
  connect(hpHdr.port_b, pumPriNoDed.ports_aChiHeaWatHp)
  connect(pumPriNoDed.ports_bChiHeaWat, pumPriHdr.ports_a)
  connect(ctlNoDed.bus, busPla)
  connect(busPla.pumHeaWatPri, pumPriHdr.bus)
  connect(pumPriSep.ports_bChiHeaWatHp, hpSep.port_a)
  connect(hpSep.port_b, pumPriSep.ports_aChiHeaWatHp)
  connect(pumPriCom.ports_bChiHeaWat, valHeaWatIsoCom.port_a)
  connect(valHeaWatIsoCom.port_b, pumPriCom.ports_aChiHeaWat)
  connect(pumPriCom.ports_bChiHeaWat, valChiWatIsoCom.port_a)
  connect(valChiWatIsoCom.port_b, pumPriCom.ports_aChiHeaWat)
  connect(ctl.bus, busPla1)
  connect(busPla1.valHeaWatHpInlIso, valHeaWatIsoCom.bus)
  connect(busPla1.valChiWatHpInlIso, valChiWatIsoCom.bus)
  connect(ret.ports, valHeaWatIsoCom.port_b)
  connect(pumPriHdr.ports_b, valChiWatIsoHdr.port_a)
  connect(pumPriHdr.ports_b, valHeaWatIsoHdr.port_a)
  connect(valHeaWatIsoHdr.port_b, pumPriNoDed.ports_aChiHeaWat)
  connect(valChiWatIsoHdr.port_b, pumPriNoDed.ports_aChiHeaWat)
  connect(ret1.ports, valHeaWatIsoHdr.port_b)
  connect(busPla.valHeaWatHpInlIso, valHeaWatIsoHdr.bus)
  connect(busPla.valChiWatHpInlIso, valChiWatIsoHdr.bus)
  connect(busPla1, pumPriCom.bus)
  connect(busPla2.valHeaWatHpInlIso, valHeaWatIsoSep.bus)
  connect(busPla2.valChiWatHpInlIso, valChiWatIsoSep.bus)
  connect(ctlSep.bus, busPla2)
  connect(pumPriSep.ports_bHeaWat, valHeaWatIsoSep.port_a)
  connect(pumPriSep.ports_bChiWat, valChiWatIsoSep.port_a)
  connect(valHeaWatIsoSep.port_b, pumPriSep.ports_aChiHeaWat)
  connect(valChiWatIsoSep.port_b, pumPriSep.ports_aChiHeaWat)
  connect(busPla2, pumPriSep.bus)
  connect(pumPriHea.ports_bChiHeaWatHp, hpHea.port_a)
  connect(hpHea.port_b, pumPriHea.ports_aChiHeaWatHp)
  connect(ctlHea.bus, pumPriHea.bus)
  connect(ret2.ports, valHeaWatIsoSep.port_b)
  connect(ret3.ports[1], priHeaWat.port_b)
end PumpsPrimaryDedicated;


within Buildings.Templates.Plants.HeatPumps.Components.Validation;
model ValvesIsolation
  "Validation model for isolation valve component"
  extends Modelica.Icons.Example;
  parameter Buildings.Templates.Plants.HeatPumps.Types.Controller typCtl=
    Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop;
  replaceable package Medium=Buildings.Media.Water
    constrainedby Modelica.Media.Interfaces.PartialMedium
    "CHW/HW medium";
  parameter Modelica.Fluid.Types.Dynamics energyDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial
    "Type of energy balance: dynamic (3 initialization options) or steady state"
  parameter Data.Controller datCtl(
    cfg(
      have_pumHeaWatPriVar=true,
      have_pumChiWatPriVar=false,
      have_inpSch=false,
      have_hrc=false,
      have_valHpOutIso=valIsoCom.have_valHpOutIso,
      have_valHpInlIso=valIsoCom.have_valHpInlIso,
      have_chiWat=valIsoCom.have_chiWat,
      have_pumChiWatPriDed=valIsoCom.have_pumChiWatPriDed,
      typPumHeaWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumChiWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.None,
      typPumHeaWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      typTanHeaWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typTanChiWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typDis=Buildings.Templates.Plants.HeatPumps.Types.Distribution.Constant1Only,
      nPumChiWatSec=0,
      rhoHeaWat_default=Buildings.Media.Water.d_const,
      typCtl=Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop,
      is_rev=true,
      typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
      rhoChiWat_default=Buildings.Media.Water.d_const,
      cpChiWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_hotWat=false,
      have_valChiWatMinByp=false,
      have_valHeaWatMinByp=false,
      typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit,
      cpHeaWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      cpSou_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_senDpChiWatRemWir=true,
      typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
      nHp=2,
      nPumHeaWatPri=2,
      have_heaWat=true,
      nPumHeaWatSec=0,
      rhoSou_default=Buildings.Media.Air.dStp,
      have_senDpHeaWatRemWir=true,
      typPumChiWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      nPumChiWatPri=0,
      nSenDpHeaWatRem=0,
      nSenDpChiWatRem=0,
      nAirHan=0,
      nEquZon=0),
    THeaWatSup_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TChiWatSup_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
    dpChiWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpChiWatRemSet_max,
        datCtl.cfg.nSenDpChiWatRem),
    dpHeaWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpHeaWatRemSet_max,
        datCtl.cfg.nSenDpHeaWatRem),
    staEqu={fill(1, datCtl.cfg.nHp)}) "Controller parameters"
  parameter Data.Controller datCtlHeaInl(
    cfg(
      have_pumHeaWatPriVar=true,
      have_pumChiWatPriVar=false,
      have_inpSch=false,
      have_hrc=false,
      have_valHpOutIso=valIsoHeaInl.have_valHpOutIso,
      have_valHpInlIso=valIsoHeaInl.have_valHpInlIso,
      have_chiWat=valIsoHeaInl.have_chiWat,
      have_pumChiWatPriDed=valIsoHeaInl.have_pumChiWatPriDed,
      typPumHeaWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumChiWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.None,
      typTanHeaWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typTanChiWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      is_rev=false,
      typPumHeaWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      typDis=Buildings.Templates.Plants.HeatPumps.Types.Distribution.Constant1Only,
      nPumChiWatSec=0,
      rhoHeaWat_default=Buildings.Media.Water.d_const,
      typCtl=Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop,
      typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
      rhoChiWat_default=Buildings.Media.Water.d_const,
      cpChiWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_hotWat=false,
      have_valChiWatMinByp=false,
      have_valHeaWatMinByp=false,
      typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit,
      cpHeaWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      cpSou_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_senDpChiWatRemWir=true,
      typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
      nHp=2,
      nPumHeaWatPri=2,
      have_heaWat=true,
      nPumHeaWatSec=0,
      rhoSou_default=Buildings.Media.Air.dStp,
      have_senDpHeaWatRemWir=true,
      typPumChiWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      nPumChiWatPri=0,
      nSenDpHeaWatRem=0,
      nSenDpChiWatRem=0,
      nAirHan=0,
      nEquZon=0),
    THeaWatSup_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TChiWatSup_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
        dpChiWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpChiWatRemSet_max, datCtlHeaInl.cfg.nSenDpChiWatRem),
    dpHeaWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpHeaWatRemSet_max, datCtlHeaInl.cfg.nSenDpHeaWatRem),
    staEqu={fill(1, datCtlHeaInl.cfg.nHp)})
    "Controller parameters"
  parameter Data.Controller datCtlSep(
    cfg(
      have_pumHeaWatPriVar=true,
      have_pumChiWatPriVar=false,
      have_inpSch=false,
      have_hrc=false,
      have_valHpOutIso=valIsoSep.have_valHpOutIso,
      have_valHpInlIso=valIsoSep.have_valHpInlIso,
      have_chiWat=valIsoSep.have_chiWat,
      have_pumChiWatPriDed=valIsoSep.have_pumChiWatPriDed,
      typPumHeaWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumChiWatPri=Buildings.Templates.Plants.HeatPumps.Types.PumpsPrimary.Variable,
      typPumHeaWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      typTanHeaWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typTanChiWat = Buildings.Templates.Components.Types.IntegrationPoint.None,
      typDis=Buildings.Templates.Plants.HeatPumps.Types.Distribution.Constant1Only,
      nPumChiWatSec=0,
      rhoHeaWat_default=Buildings.Media.Water.d_const,
      typCtl=Buildings.Templates.Plants.HeatPumps.Types.Controller.OpenLoop,
      is_rev=true,
      typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
      rhoChiWat_default=Buildings.Media.Water.d_const,
      cpChiWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_hotWat=false,
      have_valChiWatMinByp=false,
      have_valHeaWatMinByp=false,
      typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit,
      cpHeaWat_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      cpSou_default=Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
      have_senDpChiWatRemWir=true,
      typArrPumPri=Buildings.Templates.Components.Types.PumpArrangement.Dedicated,
      nHp=2,
      nPumHeaWatPri=2,
      have_heaWat=true,
      nPumHeaWatSec=0,
      rhoSou_default=Buildings.Media.Air.dStp,
      have_senDpHeaWatRemWir=true,
      typPumChiWatSec=Buildings.Templates.Plants.HeatPumps.Types.PumpsSecondary.None,
      nPumChiWatPri=2,
      nSenDpHeaWatRem=0,
      nSenDpChiWatRem=0,
      nAirHan=0,
      nEquZon=0),
    THeaWatSup_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TChiWatSup_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
    dpChiWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpChiWatRemSet_max, datCtlSep.cfg.nSenDpChiWatRem),
    dpHeaWatRemSet_max=fill(Buildings.Templates.Data.Defaults.dpHeaWatRemSet_max, datCtlSep.cfg.nSenDpHeaWatRem),
    staEqu={fill(1, datCtlSep.cfg.nHp)})
    "Controller parameters"
  parameter Data.HeatPumpGroup datHp(
    final nHp=2,
    final typ=Buildings.Templates.Components.Types.HeatPump.AirToWater,
    final is_rev=true,
    final typMod=Buildings.Templates.Components.Types.HeatPumpModel.EquationFit,
    mHeaWatHp_flow_nominal=datHp.capHeaHp_nominal / abs(datHp.THeaWatSupHp_nominal -
      Buildings.Templates.Data.Defaults.THeaWatRetMed) / Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
    dpHeaWatHp_nominal=Buildings.Templates.Data.Defaults.dpHeaWatHp,
    capHeaHp_nominal=500E3,
    THeaWatSupHp_nominal=Buildings.Templates.Data.Defaults.THeaWatSupMed,
    TSouHeaHp_nominal=Buildings.Templates.Data.Defaults.TOutHpHeaLow,
    mChiWatHp_flow_nominal=datHp.capCooHp_nominal / abs(datHp.TChiWatSupHp_nominal -
      Buildings.Templates.Data.Defaults.TChiWatRet) / Buildings.Utilities.Psychrometrics.Constants.cpWatLiq,
    capCooHp_nominal=500E3,
    TChiWatSupHp_nominal=Buildings.Templates.Data.Defaults.TChiWatSup,
    TSouCooHp_nominal=Buildings.Templates.Data.Defaults.TOutHpCoo,
    perFitHp(
      hea(
        P=datHp.capHeaHp_nominal / Buildings.Templates.Data.Defaults.COPHpAwHea,
        coeQ={- 4.2670305442, - 0.7381077035, 6.0049480456, 0, 0},
        coeP={- 4.9107455513, 5.3665308366, 0.5447612754, 0, 0},
        TRefLoa=Buildings.Templates.Data.Defaults.THeaWatRetMed,
        TRefSou=Buildings.Templates.Data.Defaults.TOutHpHeaLow),
      coo(
        P=datHp.capCooHp_nominal / Buildings.Templates.Data.Defaults.COPHpAwCoo,
        coeQ={- 2.2545246871, 6.9089257665, - 3.6548225094, 0, 0},
        coeP={- 5.8086010402, 1.6894933858, 5.1167787436, 0, 0},
        TRefLoa=Buildings.Templates.Data.Defaults.TChiWatRet,
        TRefSou=Buildings.Templates.Data.Defaults.TOutHpCoo)))
    "HP parameters"
  Buildings.Templates.Plants.HeatPumps.Components.ValvesIsolation valIsoCom(
    redeclare final package Medium = Medium,
    nHp=2,
    have_chiWat=true,
    have_valHpInlIso=true,
    have_valHpOutIso=true,
    have_pumChiWatPriDed=false,
    final mHeaWatHp_flow_nominal=fill(datHp.mHeaWatHp_flow_nominal, valIsoCom.nHp),
    dpHeaWatHp_nominal=fill(datHp.dpHeaWatHp_nominal, valIsoCom.nHp),
    mChiWatHp_flow_nominal=fill(datHp.mChiWatHp_flow_nominal, valIsoCom.nHp),
    final energyDynamics=energyDynamics,
    y_start=0)
    "Isolation valves - Heating and cooling system with common dedicated primary HW and CHW pumps"
  Fluid.FixedResistances.PressureDrop hpCom[valIsoCom.nHp](
    redeclare each final package Medium = Medium,
    m_flow_nominal=valIsoCom.mHeaWatHp_flow_nominal,
    dp_nominal=fill(0, valIsoCom.nHp))
    "Heat pump HX with zero fluid resistance: pressure drop computed in valve component"
  Fluid.Sources.Boundary_pT retChiWat(
    redeclare final package Medium = Medium,
    p=supChiWat.p + max(valIsoCom.dpChiWat_nominal),
    T=Buildings.Templates.Data.Defaults.TChiWatRet,
    nPorts=1) "Boundary condition at CHW return"
  Fluid.Sources.Boundary_pT retHeaWat(
    redeclare final package Medium = Medium,
    p=supHeaWat.p + max(valIsoCom.dpHeaWat_nominal),
    T=Buildings.Templates.Data.Defaults.THeaWatRetMed,
    nPorts=1) "Boundary condition at HW return"
  Fluid.Sources.Boundary_pT supChiWat(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pChiWat_rel_nominal + 101325,
    nPorts=1)
    "Boundary condition at CHW supply"
  Fluid.Sources.Boundary_pT supHeaWat(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pHeaWat_rel_nominal + 101325,
    nPorts=1)
    "Boundary condition at HW supply"
  Controls.OpenLoop ctl(
    final cfg=datCtl.cfg,
    final dat=datCtl)
    "Plant controller"
  Buildings.Templates.Plants.HeatPumps.Components.ValvesIsolation valIsoHeaInl(
    redeclare final package Medium = Medium,
    nHp=2,
    have_chiWat=false,
    have_pumChiWatPriDed=false,
    have_valHpInlIso=true,
    have_valHpOutIso=false,
    final mHeaWatHp_flow_nominal=fill(datHp.mHeaWatHp_flow_nominal, valIsoCom.nHp),
    dpHeaWatHp_nominal=fill(datHp.dpHeaWatHp_nominal, valIsoCom.nHp),
    mChiWatHp_flow_nominal=fill(datHp.mChiWatHp_flow_nominal, valIsoCom.nHp),
    final energyDynamics=energyDynamics,
    y_start=0)
    "Isolation valves - Heating-only system with isolation valves at HP inlet"
  Fluid.FixedResistances.PressureDrop hpHea[valIsoHeaInl.nHp](
    redeclare each final package Medium=Medium,
    m_flow_nominal=valIsoHeaInl.mHeaWatHp_flow_nominal,
    dp_nominal=fill(0, valIsoHeaInl.nHp))
    "Heat pump HX with zero fluid resistance: pressure drop computed in valve component"
  Fluid.Sources.Boundary_pT retHeaWat1(
    redeclare final package Medium=Medium,
    p=supHeaWat1.p + max(valIsoHeaInl.dpHeaWat_nominal),
    T=Buildings.Templates.Data.Defaults.THeaWatRetMed,
    nPorts=1)
    "Boundary condition at HW return"
  Fluid.Sources.Boundary_pT supHeaWat1(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pHeaWat_rel_nominal + 101325,
    nPorts=1)
    "Boundary condition at HW supply"
  Controls.OpenLoop ctlHeaInl(
    final cfg=datCtlHeaInl.cfg,
    final dat=datCtlHeaInl)
    "Plant controller"
  Buildings.Templates.Plants.HeatPumps.Components.ValvesIsolation valIsoSep(
    redeclare final package Medium = Medium,
    nHp=2,
    have_chiWat=true,
    have_valHpInlIso=true,
    have_valHpOutIso=false,
    have_pumChiWatPriDed=true,
    final mHeaWatHp_flow_nominal=fill(datHp.mHeaWatHp_flow_nominal, valIsoCom.nHp),
    dpHeaWatHp_nominal=fill(datHp.dpHeaWatHp_nominal, valIsoCom.nHp),
    mChiWatHp_flow_nominal=fill(datHp.mChiWatHp_flow_nominal, valIsoCom.nHp),
    final energyDynamics=energyDynamics,
    y_start=0,
    from_dp=false)
    "Isolation valves - Heating and cooling system with separate dedicated primary HW and CHW pumps"
  Fluid.FixedResistances.PressureDrop hpSep[valIsoSep.nHp](
    redeclare each final package Medium=Medium,
    m_flow_nominal=valIsoSep.mHeaWatHp_flow_nominal,
    dp_nominal=fill(0, valIsoSep.nHp))
    "Heat pump HX with zero fluid resistance: pressure drop computed in valve component"
  Fluid.Sources.Boundary_pT supHeaWat2(
    redeclare final package Medium=Medium,
    p=Buildings.Templates.Data.Defaults.pHeaWat_rel_nominal + 101325,
    nPorts=2)
    "Boundary condition at HW supply"
  Controls.OpenLoop ctlSep(
    final cfg=datCtlSep.cfg,
    final dat=datCtlSep)
    "Plant controller"
  Fluid.Movers.Preconfigured.SpeedControlled_y pumChiWatPri[2](
    redeclare each final package Medium=Medium,
    each addPowerToMedium=false,
    each m_flow_nominal=datHp.mChiWatHp_flow_nominal,
    each final energyDynamics=energyDynamics,
    dp_nominal=valIsoSep.dpChiWat_nominal + cheValChiWat.dpValve_nominal)
    "Primary CHW pump"
  Fluid.Movers.Preconfigured.SpeedControlled_y pumHeaWatPri[2](
    redeclare each final package Medium=Medium,
    each addPowerToMedium=false,
    each m_flow_nominal=datHp.mHeaWatHp_flow_nominal,
    each final energyDynamics=energyDynamics,
    dp_nominal=valIsoSep.dpHeaWat_nominal + cheValHeaWat.dpValve_nominal)
    "Primary HW pump"
  Buildings.Templates.Plants.HeatPumps.Interfaces.Bus busPla
    "Plant controller"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal yPumHeaWatPri[2]
    "Primary HW pump speed command"
  Buildings.Controls.OBC.CDL.Conversions.BooleanToReal yPumChiWatPri[2]
    "Primary CHW pump speed command"
  Buildings.Templates.Components.Interfaces.Bus busPumHeaWatPri
    "Primary HW pump control bus"
  Buildings.Templates.Components.Interfaces.Bus busPumChiWatPri
    "Primary CHW pump control bus"
  Fluid.FixedResistances.CheckValve cheValHeaWat[2](
    redeclare each final package Medium=Medium,
    each m_flow_nominal=datHp.mHeaWatHp_flow_nominal,
    each dpValve_nominal=Buildings.Templates.Data.Defaults.dpValChe)
    "Check valve"
  Fluid.FixedResistances.CheckValve cheValChiWat[2](
    redeclare each final package Medium=Medium,
    each m_flow_nominal=datHp.mChiWatHp_flow_nominal,
    each dpValve_nominal=Buildings.Templates.Data.Defaults.dpValChe)
    "Check valve"
equation
  connect(retHeaWat.ports[1], valIsoCom.port_aHeaWat)
  connect(retChiWat.ports[1], valIsoCom.port_aChiWat)
  connect(valIsoCom.port_bChiWat, supChiWat.ports[1])
  connect(valIsoCom.port_bHeaWat, supHeaWat.ports[1])
  connect(ctl.bus, valIsoCom.bus)
  connect(retHeaWat1.ports[1], valIsoHeaInl.port_aHeaWat)
  connect(valIsoHeaInl.port_bHeaWat, supHeaWat1.ports[1])
  connect(ctlHeaInl.bus, valIsoHeaInl.bus)
  connect(valIsoCom.ports_bChiHeaWatHp, hpCom.port_a)
  connect(hpCom.port_b, valIsoCom.ports_aChiHeaWatHp)
  connect(valIsoHeaInl.ports_bChiHeaWatHp, hpHea.port_a)
  connect(hpHea.port_b, valIsoHeaInl.ports_aChiHeaWatHp)
  connect(valIsoSep.port_bHeaWat, supHeaWat2.ports[1])
  connect(ctlSep.bus, valIsoSep.bus)
  connect(valIsoSep.ports_bChiHeaWatHp, hpSep.port_a)
  connect(supHeaWat2.ports[2], valIsoSep.port_aHeaWat)
  connect(ctlSep.bus, busPla)
  connect(busPla.pumHeaWatPri, busPumHeaWatPri)
  connect(busPumHeaWatPri.y1, yPumHeaWatPri.u)
  connect(yPumHeaWatPri.y, pumHeaWatPri.y)
  connect(busPla.pumChiWatPri, busPumChiWatPri)
  connect(busPumChiWatPri.y1, yPumChiWatPri.u)
  connect(yPumChiWatPri.y, pumChiWatPri.y)
  connect(pumHeaWatPri.port_b, cheValHeaWat.port_a)
  connect(cheValHeaWat.port_b, valIsoSep.ports_aHeaWatHp)
  connect(cheValChiWat.port_b, valIsoSep.ports_aChiWatHp)
  connect(pumChiWatPri.port_b, cheValChiWat.port_a)
  connect(hpSep.port_b, pumChiWatPri.port_a)
  connect(hpSep.port_b, pumHeaWatPri.port_a)
  connect(valIsoSep.port_bChiWat, valIsoSep.port_aChiWat)
end ValvesIsolation;


Records for configuration parameters

within Buildings.Templates.Plants.HeatPumps;
package Configuration "Records for configuration parameters"
  extends Modelica.Icons.MaterialPropertiesPackage;
end Configuration;


within Buildings.Templates.Plants.HeatPumps;
package Data "Records for design and operating parameters"
  extends Modelica.Icons.MaterialPropertiesPackage;
end Data;


Interface classes

within Buildings.Templates.Plants.HeatPumps;
package Interfaces "Interface classes"
  extends Modelica.Icons.InterfacesPackage;
end Interfaces;