LCOV - code coverage report
Current view: top level - EnergyPlus - HVACVariableRefrigerantFlow.cc (source / functions) Coverage Total Hit
Test: lcov.output.filtered Lines: 61.6 % 8096 4988
Test Date: 2025-06-02 07:23:51 Functions: 79.4 % 68 54

            Line data    Source code
       1              : // EnergyPlus, Copyright (c) 1996-2025, The Board of Trustees of the University of Illinois,
       2              : // The Regents of the University of California, through Lawrence Berkeley National Laboratory
       3              : // (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
       4              : // National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
       5              : // contributors. All rights reserved.
       6              : //
       7              : // NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
       8              : // U.S. Government consequently retains certain rights. As such, the U.S. Government has been
       9              : // granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
      10              : // worldwide license in the Software to reproduce, distribute copies to the public, prepare
      11              : // derivative works, and perform publicly and display publicly, and to permit others to do so.
      12              : //
      13              : // Redistribution and use in source and binary forms, with or without modification, are permitted
      14              : // provided that the following conditions are met:
      15              : //
      16              : // (1) Redistributions of source code must retain the above copyright notice, this list of
      17              : //     conditions and the following disclaimer.
      18              : //
      19              : // (2) Redistributions in binary form must reproduce the above copyright notice, this list of
      20              : //     conditions and the following disclaimer in the documentation and/or other materials
      21              : //     provided with the distribution.
      22              : //
      23              : // (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
      24              : //     the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
      25              : //     used to endorse or promote products derived from this software without specific prior
      26              : //     written permission.
      27              : //
      28              : // (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
      29              : //     without changes from the version obtained under this License, or (ii) Licensee makes a
      30              : //     reference solely to the software portion of its product, Licensee must refer to the
      31              : //     software as "EnergyPlus version X" software, where "X" is the version number Licensee
      32              : //     obtained under this License and may not use a different name for the software. Except as
      33              : //     specifically required in this Section (4), Licensee shall not use in a company name, a
      34              : //     product name, in advertising, publicity, or other promotional activities any name, trade
      35              : //     name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
      36              : //     similar designation, without the U.S. Department of Energy's prior written consent.
      37              : //
      38              : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
      39              : // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
      40              : // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
      41              : // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      42              : // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
      43              : // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      44              : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      45              : // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      46              : // POSSIBILITY OF SUCH DAMAGE.
      47              : 
      48              : // C++ Headers
      49              : #include <array>
      50              : #include <cassert>
      51              : #include <cmath>
      52              : #include <string>
      53              : 
      54              : // ObjexxFCL Headers
      55              : #include <ObjexxFCL/Array.functions.hh>
      56              : #include <ObjexxFCL/Fmath.hh>
      57              : 
      58              : // EnergyPlus Headers
      59              : #include <EnergyPlus/Autosizing/All_Simple_Sizing.hh>
      60              : #include <EnergyPlus/Autosizing/CoolingAirFlowSizing.hh>
      61              : #include <EnergyPlus/Autosizing/CoolingCapacitySizing.hh>
      62              : #include <EnergyPlus/Autosizing/HeatingAirFlowSizing.hh>
      63              : #include <EnergyPlus/Autosizing/HeatingCapacitySizing.hh>
      64              : #include <EnergyPlus/Autosizing/SystemAirFlowSizing.hh>
      65              : #include <EnergyPlus/Autosizing/WaterHeatingCapacitySizing.hh>
      66              : #include <EnergyPlus/BranchNodeConnections.hh>
      67              : #include <EnergyPlus/CurveManager.hh>
      68              : #include <EnergyPlus/DXCoils.hh>
      69              : #include <EnergyPlus/Data/EnergyPlusData.hh>
      70              : #include <EnergyPlus/DataAirSystems.hh>
      71              : #include <EnergyPlus/DataDefineEquip.hh>
      72              : #include <EnergyPlus/DataGlobalConstants.hh>
      73              : #include <EnergyPlus/DataHVACGlobals.hh>
      74              : #include <EnergyPlus/DataHeatBalFanSys.hh>
      75              : #include <EnergyPlus/DataHeatBalance.hh>
      76              : #include <EnergyPlus/DataIPShortCuts.hh>
      77              : #include <EnergyPlus/DataLoopNode.hh>
      78              : #include <EnergyPlus/DataSizing.hh>
      79              : #include <EnergyPlus/DataZoneControls.hh>
      80              : #include <EnergyPlus/DataZoneEnergyDemands.hh>
      81              : #include <EnergyPlus/DataZoneEquipment.hh>
      82              : #include <EnergyPlus/EMSManager.hh>
      83              : #include <EnergyPlus/Fans.hh>
      84              : #include <EnergyPlus/FluidProperties.hh>
      85              : #include <EnergyPlus/General.hh>
      86              : #include <EnergyPlus/GeneralRoutines.hh>
      87              : #include <EnergyPlus/GlobalNames.hh>
      88              : #include <EnergyPlus/HVACVariableRefrigerantFlow.hh>
      89              : #include <EnergyPlus/HeatingCoils.hh>
      90              : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
      91              : #include <EnergyPlus/MixedAir.hh>
      92              : #include <EnergyPlus/NodeInputManager.hh>
      93              : #include <EnergyPlus/OutAirNodeManager.hh>
      94              : #include <EnergyPlus/OutputProcessor.hh>
      95              : #include <EnergyPlus/Plant/DataPlant.hh>
      96              : #include <EnergyPlus/Plant/PlantLocation.hh>
      97              : #include <EnergyPlus/PlantUtilities.hh>
      98              : #include <EnergyPlus/Psychrometrics.hh>
      99              : #include <EnergyPlus/ScheduleManager.hh>
     100              : #include <EnergyPlus/SteamCoils.hh>
     101              : #include <EnergyPlus/UnitarySystem.hh>
     102              : #include <EnergyPlus/UtilityRoutines.hh>
     103              : #include <EnergyPlus/WaterCoils.hh>
     104              : #include <EnergyPlus/WaterManager.hh>
     105              : #include <EnergyPlus/ZoneTempPredictorCorrector.hh>
     106              : 
     107              : namespace EnergyPlus::HVACVariableRefrigerantFlow {
     108              : // Module containing the Variable Refrigerant Flow (VRF or VRV) simulation routines
     109              : 
     110              : // MODULE INFORMATION:
     111              : //       AUTHOR         Richard Raustad, FSEC
     112              : //       DATE WRITTEN   August 2010
     113              : //       MODIFIED       Apr 2012, R. Raustad, FSEC, Added Heat Recovery Operating Mode
     114              : //                      Jul 2015, RP Zhang, XF Pang, LBNL, Added a new physics based VRF model applicable for Fluid Temperature Control
     115              : //       RE-ENGINEERED  na
     116              : 
     117              : // PURPOSE OF THIS MODULE:
     118              : // To encapsulate the data and algorithms required to
     119              : // manage the VRF System Component
     120              : 
     121              : using namespace DataZoneEnergyDemands;
     122              : using namespace Psychrometrics;
     123              : using namespace DataPlant;
     124              : 
     125              : constexpr std::array<std::string_view, (int)TUType::Num> tuTypeNames = {"ZoneHVAC:TerminalUnit:VariableRefrigerantFlow"};
     126              : 
     127       244151 : void SimulateVRF(EnergyPlusData &state,
     128              :                  std::string_view CompName,
     129              :                  bool const FirstHVACIteration,
     130              :                  int const ZoneNum,
     131              :                  int &CompIndex,
     132              :                  bool &HeatingActive,
     133              :                  bool &CoolingActive,
     134              :                  [[maybe_unused]] int const OAUnitNum,         // If the system is an equipment of OutdoorAirUnit
     135              :                  [[maybe_unused]] Real64 const OAUCoilOutTemp, // the coil inlet temperature of OutdoorAirUnit
     136              :                  [[maybe_unused]] bool const ZoneEquipment,    // TRUE if called as zone equipment
     137              :                  Real64 &SysOutputProvided,
     138              :                  Real64 &LatOutputProvided)
     139              : {
     140              : 
     141              :     // SUBROUTINE INFORMATION:
     142              :     // AUTHOR         Richard Raustad, FSEC
     143              :     // DATE WRITTEN   August 2010
     144              :     // MODIFIED       Jul 2015, RP Zhang (LBNL), XF Pang (LBNL), Y Yura (Daikin Inc). Add a physics-based VRF model applicable for Fluid
     145              :     // Temperature Control RE-ENGINEERED  na
     146              : 
     147              :     // PURPOSE OF THIS SUBROUTINE:
     148              :     // This subroutine manages VRF terminal unit simulation.
     149              : 
     150              :     // METHODOLOGY EMPLOYED:
     151              :     // Simulate all terminal units
     152              :     // Once all terminal units have been simulated, simulate VRF condenser
     153              : 
     154              :     int VRFTUNum;             // current VRF system terminal unit index
     155              :     int VRFCondenser;         // index to VRF AC system object - AirConditioner:VariableRefrigerantFlow
     156              :     int TUListNum;            // index to VRF AC system terminal unit list
     157              :     int IndexToTUInTUList;    // index to pointer in VRF AC system terminal unit list
     158              :     Real64 OnOffAirFlowRatio; // ratio of compressor ON airflow to average airflow over timestep
     159              :     int DXCoolingCoilIndex;   // index to this terminal units DX cooling coil
     160              :     int DXHeatingCoilIndex;   // index to this terminal units DX heating coil
     161              :     Real64 QZnReq;
     162              : 
     163              :     // Obtains and Allocates VRF system related parameters from input file
     164       244151 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) { // First time subroutine has been entered
     165           12 :         GetVRFInput(state);
     166           12 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
     167              :     }
     168              : 
     169              :     // CompIndex accounting
     170       244151 :     if (CompIndex == 0) {
     171           62 :         VRFTUNum = Util::FindItemInList(CompName, state.dataHVACVarRefFlow->VRFTU);
     172           62 :         if (VRFTUNum == 0) {
     173            0 :             ShowFatalError(state, format("SimulateVRF: VRF Terminal Unit not found={}", CompName));
     174              :         }
     175           62 :         CompIndex = VRFTUNum;
     176              : 
     177              :     } else {
     178       244089 :         VRFTUNum = CompIndex;
     179       244089 :         if (VRFTUNum > state.dataHVACVarRefFlow->NumVRFTU || VRFTUNum < 1) {
     180            0 :             ShowFatalError(state,
     181            0 :                            format("SimulateVRF: Invalid CompIndex passed={}, Number of VRF Terminal Units = {}, VRF Terminal Unit name = {}",
     182              :                                   VRFTUNum,
     183            0 :                                   state.dataHVACVarRefFlow->NumVRFTU,
     184              :                                   CompName));
     185              :         }
     186       244089 :         if (state.dataHVACVarRefFlow->CheckEquipName(VRFTUNum)) {
     187           62 :             if (!CompName.empty() && CompName != state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name) {
     188            0 :                 ShowFatalError(state,
     189            0 :                                format("SimulateVRF: Invalid CompIndex passed={}, VRF Terminal Unit name={}, stored VRF TU Name for that index={}",
     190              :                                       VRFTUNum,
     191              :                                       CompName,
     192            0 :                                       state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
     193              :             }
     194           62 :             state.dataHVACVarRefFlow->CheckEquipName(VRFTUNum) = false;
     195              :         }
     196              :     }
     197              : 
     198              :     // the VRF condenser index
     199       244151 :     VRFCondenser = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum;
     200              : 
     201       259227 :     if ((state.dataHVACVarRefFlow->VRF(VRFCondenser).CondenserType == DataHeatBalance::RefrigCondenserType::Water) &&
     202        15076 :         (state.dataHVACVarRefFlow->VRF(VRFCondenser).checkPlantCondTypeOneTime)) {
     203              :         // scan for loop connection data
     204            1 :         bool errFlag = false;
     205            3 :         PlantUtilities::ScanPlantLoopsForObject(state,
     206            1 :                                                 state.dataHVACVarRefFlow->VRF(VRFCondenser).Name,
     207            1 :                                                 state.dataHVACVarRefFlow->VRF(VRFCondenser).VRFType,
     208            1 :                                                 state.dataHVACVarRefFlow->VRF(VRFCondenser).SourcePlantLoc,
     209              :                                                 errFlag,
     210              :                                                 _,
     211              :                                                 _,
     212              :                                                 _,
     213            1 :                                                 state.dataHVACVarRefFlow->VRF(VRFCondenser).CondenserNodeNum,
     214              :                                                 _);
     215              : 
     216            1 :         if (errFlag) {
     217            0 :             ShowSevereError(state, "GetVRFInput: Error scanning for plant loop data");
     218              :         }
     219              : 
     220            1 :         state.dataHVACVarRefFlow->VRF(VRFCondenser).checkPlantCondTypeOneTime = false;
     221              :     }
     222              : 
     223              :     // the terminal unit list object index
     224       244151 :     TUListNum = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TUListIndex;
     225              :     // the entry number in the terminal unit list (which item in the terminal unit list, e.g. second in list)
     226       244151 :     IndexToTUInTUList = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).IndexToTUInTUList;
     227              :     // index to cooling coil (coil is optional but at least one must be present)
     228       244151 :     DXCoolingCoilIndex = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolCoilIndex;
     229              :     // index to heating coil (coil is optional but at least one must be present)
     230       244151 :     DXHeatingCoilIndex = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatCoilIndex;
     231       244151 :     QZnReq = 0.0;
     232              : 
     233              :     // Initialize terminal unit
     234       244151 :     InitVRF(state, VRFTUNum, ZoneNum, FirstHVACIteration, OnOffAirFlowRatio, QZnReq); // Initialize all VRFTU related parameters
     235              : 
     236              :     // Simulate terminal unit
     237       244151 :     SimVRF(state, VRFTUNum, FirstHVACIteration, OnOffAirFlowRatio, SysOutputProvided, LatOutputProvided, QZnReq);
     238              : 
     239              :     // mark this terminal unit as simulated
     240       244151 :     state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).IsSimulated(IndexToTUInTUList) = true;
     241              : 
     242              :     // keep track of individual coil loads
     243       244151 :     if (DXCoolingCoilIndex > 0) {
     244       244151 :         state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(IndexToTUInTUList) =
     245       244151 :             state.dataDXCoils->DXCoilTotalCooling(DXCoolingCoilIndex);
     246              :     } else {
     247            0 :         state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(IndexToTUInTUList) = 0.0;
     248              :     }
     249       244151 :     if (DXHeatingCoilIndex > 0) {
     250       244151 :         state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(IndexToTUInTUList) =
     251       244151 :             state.dataDXCoils->DXCoilTotalHeating(DXHeatingCoilIndex);
     252              :     } else {
     253            0 :         state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(IndexToTUInTUList) = 0.0;
     254              :     }
     255              : 
     256              :     // Report the current VRF terminal unit
     257       244151 :     ReportVRFTerminalUnit(state, VRFTUNum);
     258              : 
     259       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalCoolingRate > 0.0) {
     260       105666 :         CoolingActive = true;
     261              :     }
     262       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalHeatingRate > 0.0) {
     263       103726 :         HeatingActive = true;
     264              :     }
     265              : 
     266              :     // make sure all TU in a list are able to get simulated, otherwise condenser is never simulated **
     267              :     // either fatal on GetInput, or keep track of unused TU's and set their respective flag to TRUE **
     268              :     // after all VRF terminal units have been simulated, call the VRF condenser model
     269       244151 :     if (all(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).IsSimulated)) {
     270              : 
     271        55680 :         if (state.dataHVACVarRefFlow->VRF(VRFCondenser).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
     272              :             // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
     273        14999 :             state.dataHVACVarRefFlow->VRF(VRFCondenser).CalcVRFCondenser_FluidTCtrl(state, FirstHVACIteration);
     274              :         } else {
     275              :             // Algorithm Type: VRF model based on system curve
     276        40681 :             CalcVRFCondenser(state, VRFCondenser);
     277              :         }
     278              : 
     279        55680 :         ReportVRFCondenser(state, VRFCondenser);
     280              : 
     281        55680 :         if (state.dataHVACVarRefFlow->VRF(VRFCondenser).CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
     282         3769 :             UpdateVRFCondenser(state, VRFCondenser);
     283              :         }
     284              :     }
     285       244151 : }
     286              : 
     287            1 : PlantComponent *VRFCondenserEquipment::factory(EnergyPlusData &state, std::string const &objectName)
     288              : {
     289              :     // Process the input data if it hasn't been done already
     290            1 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) {
     291            1 :         GetVRFInput(state);
     292            1 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
     293              :     }
     294              :     // Now look for this object in the list
     295            1 :     for (auto &obj : state.dataHVACVarRefFlow->VRF) {
     296            1 :         if (obj.Name == objectName) {
     297            1 :             return &obj;
     298              :         }
     299            2 :     }
     300              :     // If we didn't find it, fatal
     301              :     ShowFatalError(state, format("LocalVRFCondenserFactory: Error getting inputs for object named: {}", objectName)); // LCOV_EXCL_LINE
     302              :     // Shut up the compiler
     303              :     return nullptr; // LCOV_EXCL_LINE
     304              : }
     305              : 
     306            5 : void VRFCondenserEquipment::onInitLoopEquip(EnergyPlusData &state, [[maybe_unused]] const PlantLocation &calledFromLocation)
     307              : {
     308            5 :     this->SizeVRFCondenser(state);
     309            5 : }
     310              : 
     311            5 : void VRFCondenserEquipment::getDesignCapacities([[maybe_unused]] EnergyPlusData &state,
     312              :                                                 [[maybe_unused]] const PlantLocation &calledFromLocation,
     313              :                                                 Real64 &MaxLoad,
     314              :                                                 Real64 &MinLoad,
     315              :                                                 Real64 &OptLoad)
     316              : {
     317            5 :     MinLoad = 0.0;
     318            5 :     MaxLoad = max(this->CoolingCapacity, this->HeatingCapacity); // greater of cooling and heating capacity
     319            5 :     OptLoad = max(this->CoolingCapacity,
     320              :                   this->HeatingCapacity); // connects to single loop, need to switch between cooling/heating capacity?
     321            5 : }
     322              : 
     323        15053 : void VRFCondenserEquipment::simulate(EnergyPlusData &state,
     324              :                                      const PlantLocation &calledFromLocation,
     325              :                                      bool FirstHVACIteration,
     326              :                                      [[maybe_unused]] Real64 &CurLoad,
     327              :                                      [[maybe_unused]] bool RunFlag)
     328              : {
     329        15053 :     if (calledFromLocation.loopNum == this->SourcePlantLoc.loopNum) { // condenser loop
     330        15053 :         PlantUtilities::UpdateChillerComponentCondenserSide(state,
     331              :                                                             this->SourcePlantLoc.loopNum,
     332              :                                                             this->SourcePlantLoc.loopSideNum,
     333              :                                                             PlantEquipmentType::HeatPumpVRF,
     334              :                                                             this->CondenserNodeNum,
     335              :                                                             this->CondenserOutletNodeNum,
     336              :                                                             this->QCondenser,
     337              :                                                             this->CondenserInletTemp,
     338              :                                                             this->CondenserSideOutletTemp,
     339              :                                                             this->WaterCondenserMassFlow,
     340              :                                                             FirstHVACIteration);
     341              :     } else {
     342            0 :         ShowFatalError(state, format("SimVRFCondenserPlant:: Invalid loop connection {}", cVRFTypes(VRF_HeatPump)));
     343              :     }
     344        15053 : }
     345              : 
     346        40681 : void CalcVRFCondenser(EnergyPlusData &state, int const VRFCond)
     347              : {
     348              : 
     349              :     // SUBROUTINE INFORMATION:
     350              :     //       AUTHOR         R. Raustad, FSEC
     351              :     //       DATE WRITTEN   September 2010
     352              : 
     353              :     // PURPOSE OF THIS SUBROUTINE:
     354              :     // Model the interactions of VRF terminal units with a single variable-speed condenser.
     355              :     // The terminal units are simulated first, and then the condenser is simulated.
     356              :     // If terminal units require more capacity than can be delivered by condenser, a limit is set.
     357              : 
     358              :     using Curve::CurveValue;
     359              :     using PlantUtilities::SetComponentFlowRate;
     360              :     using Psychrometrics::RhoH2O;
     361              : 
     362              :     static constexpr std::string_view RoutineName("VRFCondenser");
     363              : 
     364              :     int NumTU; // loop counter
     365              : 
     366              :     Real64 TotCoolCapTempModFac;      // cooling CAPFT curve output
     367              :     Real64 TotHeatCapTempModFac;      // heating CAPFT curve output
     368              :     Real64 TotCoolEIRTempModFac;      // cooling EIRFT curve output
     369              :     Real64 TotHeatEIRTempModFac;      // heating EIRFT curve output
     370              :     Real64 InletAirWetBulbC;          // coil inlet air wet-bulb temperature (C)
     371              :     Real64 InletAirDryBulbC;          // coil inlet air dry-bulb temperature (C)
     372        40681 :     Real64 CondInletTemp(0.0);        // condenser inlet air temperature (C)
     373              :     Real64 CondInletHumRat;           // condenser inlet air humidity ratio (kg/kg)
     374              :     Real64 OutdoorDryBulb;            // outdoor dry-bulb temperature (C)
     375              :     Real64 OutdoorHumRat;             // outdoor humidity ratio (kg/kg)
     376              :     Real64 OutdoorPressure;           // outdoor pressure (Pa)
     377              :     Real64 OutdoorWetBulb;            // outdoor wet-bulb temperature (C)
     378              :     Real64 CoolOABoundary;            // output of cooling boundary curve (outdoor temperature, C)
     379              :     Real64 HeatOABoundary;            // output of heating boundary curve (outdoor temperature, C)
     380              :     Real64 EIRFPLRModFac;             // EIRFPLR curve output
     381              :     Real64 UpperStageCompressorRatio; // used for crankcase heater power calculation
     382              :     Real64 RhoAir;                    // Density of air [kg/m3]
     383              :     Real64 RhoWater;                  // Density of water [kg/m3]
     384              :     Real64 CpCond;                    // Specific Heat of water [J/kg-k]
     385              :     Real64 CondAirMassFlow;           // Condenser air mass flow rate [kg/s]
     386              :     Real64 CondWaterMassFlow;         // Condenser water mass flow rate [kg/s]
     387              :     Real64 PartLoadFraction;          // Part load fraction from PLFFPLR curve
     388              :     Real64 VRFRTF;                    // VRF runtime fraction when cycling below MINPLR
     389              :     Real64 OutdoorCoilT;              // Outdoor coil temperature (C)
     390              :     Real64 OutdoorCoildw;             // Outdoor coil delta w assuming coil temp of OutdoorCoilT (kg/kg)
     391              :     Real64 FractionalDefrostTime;     // Fraction of time step system is in defrost
     392              :     Real64 HeatingCapacityMultiplier; // Multiplier for heating capacity when system is in defrost
     393              :     Real64 InputPowerMultiplier;      // Multiplier for power when system is in defrost
     394              :     Real64 LoadDueToDefrost;          // Additional load due to defrost
     395              :     Real64 DefrostEIRTempModFac;      // EIR modifier for defrost (function of entering drybulb, outside wetbulb)
     396              :     Real64 HRCAPFTConst;              // stead-state capacity fraction
     397              :     Real64 HRInitialCapFrac;          // Fractional cooling degradation at the start of heat recovery from cooling mode
     398              :     Real64 HRCapTC;                   // Time constant used to recover from initial degradation in cooling heat recovery
     399              :     Real64 HREIRFTConst;              // stead-state EIR fraction
     400              :     Real64 HRInitialEIRFrac;          // Fractional cooling degradation at the start of heat recovery from cooling mode
     401              :     Real64 HREIRTC;                   // Time constant used to recover from initial degradation in cooling heat recovery
     402              :     Real64 CurrentEndTime;            // end time of current time step
     403              :     Real64 SUMultiplier;              // multiplier for simulating mode changes
     404              :     Real64 CondPower;                 // condenser power [W]
     405              :     Real64 CondCapacity;              // condenser heat rejection [W]
     406              :     Real64 CondOutletTemp;            // Outlet temperature from VRF condenser [C]
     407              :     Real64 TotPower;                  // total condenser power use [W]
     408              :     bool HRHeatRequestFlag;           // flag indicating VRF TU could operate in heating mode
     409              :     bool HRCoolRequestFlag;           // flag indicating VRF TU could operate in cooling mode
     410              : 
     411        40681 :     auto &vrf = state.dataHVACVarRefFlow->VRF(VRFCond);
     412              : 
     413              :     // variable initializations
     414        40681 :     int TUListNum = vrf.ZoneTUListPtr;
     415        40681 :     int NumTUInList = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList;
     416        40681 :     int NumTUInCoolingMode = 0;            // number of terminal units actually cooling
     417        40681 :     int NumTUInHeatingMode = 0;            // number of terminal units actually heating
     418        40681 :     Real64 TUCoolingLoad = 0.0;            // sum of TU's cooling coil load (W)
     419        40681 :     Real64 TUHeatingLoad = 0.0;            // sum of TU's heating coil load (W)
     420        40681 :     Real64 TUParasiticPower = 0.0;         // total terminal unit parasitic power (W)
     421        40681 :     Real64 TUFanPower = 0.0;               // total terminal unit fan power (W)
     422        40681 :     Real64 CoolingPLR = 0.0;               // condenser cooling PLR
     423        40681 :     Real64 HeatingPLR = 0.0;               // condenser heating PLR
     424        40681 :     Real64 CyclingRatio = 1.0;             // cycling ratio of condenser's compressors
     425        40681 :     Real64 SumCoolInletWB = 0.0;           // sum of active TU's DX cooling coil inlet air wet-bulb temperature
     426        40681 :     Real64 SumHeatInletDB = 0.0;           // sum of active TU's DX heating coil inlet air dry-bulb temperature
     427        40681 :     Real64 SumHeatInletWB = 0.0;           // sum of active TU's DX heating coil inlet air wet-bulb temperature
     428        40681 :     Real64 TotalCondCoolingCapacity = 0.0; // total available condenser cooling capacity (W)
     429        40681 :     Real64 TotalCondHeatingCapacity = 0.0; // total available condenser heating capacity (W)
     430        40681 :     Real64 TotalTUCoolingCapacity = 0.0;   // sum of TU's cooling capacity including piping losses (W)
     431        40681 :     Real64 TotalTUHeatingCapacity = 0.0;   // sum of TU's heating capacity including piping losses (W)
     432              : 
     433        40681 :     vrf.ElecCoolingPower = 0.0;
     434        40681 :     vrf.ElecHeatingPower = 0.0;
     435        40681 :     vrf.CrankCaseHeaterPower = 0.0;
     436        40681 :     vrf.EvapCondPumpElecPower = 0.0;
     437        40681 :     vrf.EvapWaterConsumpRate = 0.0;
     438        40681 :     vrf.DefrostPower = 0.0;
     439        40681 :     vrf.OperatingCoolingCOP = 0.0;
     440        40681 :     vrf.OperatingHeatingCOP = 0.0;
     441        40681 :     vrf.OperatingCOP = 0.0;
     442        40681 :     vrf.SCHE = 0.0;
     443        40681 :     vrf.BasinHeaterPower = 0.0;
     444        40681 :     vrf.VRFHeatRec = 0.0;
     445              : 
     446              :     // set condenser entering air conditions
     447        40681 :     if (vrf.CondenserNodeNum != 0) {
     448        40681 :         OutdoorDryBulb = state.dataLoopNodes->Node(vrf.CondenserNodeNum).Temp;
     449        40681 :         if (vrf.CondenserType != DataHeatBalance::RefrigCondenserType::Water) {
     450        36912 :             OutdoorHumRat = state.dataLoopNodes->Node(vrf.CondenserNodeNum).HumRat;
     451        36912 :             OutdoorPressure = state.dataLoopNodes->Node(vrf.CondenserNodeNum).Press;
     452        36912 :             OutdoorWetBulb = state.dataLoopNodes->Node(vrf.CondenserNodeNum).OutAirWetBulb;
     453              :         } else {
     454         3769 :             OutdoorHumRat = state.dataEnvrn->OutHumRat;
     455         3769 :             OutdoorPressure = state.dataEnvrn->OutBaroPress;
     456         3769 :             OutdoorWetBulb = state.dataEnvrn->OutWetBulbTemp;
     457              :         }
     458              :     } else {
     459            0 :         OutdoorDryBulb = state.dataEnvrn->OutDryBulbTemp;
     460            0 :         OutdoorHumRat = state.dataEnvrn->OutHumRat;
     461            0 :         OutdoorPressure = state.dataEnvrn->OutBaroPress;
     462            0 :         OutdoorWetBulb = state.dataEnvrn->OutWetBulbTemp;
     463              :     }
     464              : 
     465        40681 :     if (vrf.CondenserType == DataHeatBalance::RefrigCondenserType::Air) {
     466        36912 :         CondInletTemp = OutdoorDryBulb; // Outdoor dry-bulb temp
     467         3769 :     } else if (vrf.CondenserType == DataHeatBalance::RefrigCondenserType::Evap) {
     468            0 :         RhoAir = PsyRhoAirFnPbTdbW(state, OutdoorPressure, OutdoorDryBulb, OutdoorHumRat);
     469            0 :         CondAirMassFlow = RhoAir * vrf.EvapCondAirVolFlowRate;
     470              :         // (Outdoor wet-bulb temp from DataEnvironment) + (1.0-EvapCondEffectiveness) * (drybulb - wetbulb)
     471            0 :         CondInletTemp = OutdoorWetBulb + (OutdoorDryBulb - OutdoorWetBulb) * (1.0 - vrf.EvapCondEffectiveness);
     472            0 :         CondInletHumRat = PsyWFnTdbTwbPb(state, CondInletTemp, OutdoorWetBulb, OutdoorPressure);
     473         3769 :     } else if (vrf.CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
     474         3769 :         CondInletTemp = OutdoorDryBulb; // node inlet temp from above
     475         3769 :         OutdoorWetBulb = CondInletTemp; // for watercooled
     476         3769 :         CondWaterMassFlow = vrf.WaterCondenserDesignMassFlow;
     477              :     } else {
     478            0 :         assert(false);
     479              :     }
     480        40681 :     vrf.CondenserInletTemp = CondInletTemp;
     481              : 
     482              :     // sum loads on TU coils
     483       228429 :     for (NumTU = 1; NumTU <= NumTUInList; ++NumTU) {
     484       187748 :         TUCoolingLoad += state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU);
     485       187748 :         TUHeatingLoad += state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU);
     486              :     }
     487              : 
     488        40681 :     vrf.TUCoolingLoad = TUCoolingLoad;
     489        40681 :     vrf.TUHeatingLoad = TUHeatingLoad;
     490              : 
     491              :     // no need to do anything else if the terminal units are off
     492        40681 :     if (TUCoolingLoad == 0.0 && TUHeatingLoad == 0.0) {
     493         6746 :         vrf.SUMultiplier = 0.0;
     494         6746 :         vrf.VRFCondPLR = 0.0;
     495         6746 :         vrf.VRFCondRTF = 0.0;
     496         6746 :         vrf.VRFCondCyclingRatio = 0.0;
     497         6746 :         vrf.QCondenser = 0.0;
     498         6746 :         vrf.TotalCoolingCapacity = 0.0;
     499         6746 :         vrf.TotalHeatingCapacity = 0.0;
     500         6746 :         vrf.OperatingMode = 0.0;
     501         6746 :         vrf.HRHeatingActive = false;
     502         6746 :         vrf.HRCoolingActive = false;
     503         6746 :         state.dataHVACVarRefFlow->CurrentEndTimeLast = double((state.dataGlobal->DayOfSim - 1) * 24) + state.dataGlobal->CurrentTime -
     504         6746 :                                                        state.dataGlobal->TimeStepZone + state.dataHVACGlobal->SysTimeElapsed;
     505         6746 :         if (vrf.CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
     506          487 :             state.dataHVACVarRefFlow->CondenserWaterMassFlowRate = 0.0;
     507          974 :             SetComponentFlowRate(
     508          487 :                 state, state.dataHVACVarRefFlow->CondenserWaterMassFlowRate, vrf.CondenserNodeNum, vrf.CondenserOutletNodeNum, vrf.SourcePlantLoc);
     509          487 :             vrf.WaterCondenserMassFlow = state.dataHVACVarRefFlow->CondenserWaterMassFlowRate;
     510          487 :             vrf.CondenserSideOutletTemp = CondInletTemp;
     511              :         }
     512         6746 :         return;
     513              :     }
     514              : 
     515              :     // switch modes if summed coil capacity shows opposite operating mode
     516              :     // if total TU heating exceeds total TU cooling * ( 1 + 1/COP) then system is in heating mode
     517        33935 :     if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && TUHeatingLoad > (TUCoolingLoad * (1.0 + 1.0 / vrf.CoolingCOP))) {
     518            0 :         state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
     519            0 :         state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
     520            0 :         vrf.ModeChange = true;
     521            0 :         if (!state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) {
     522            0 :             state.dataHVACVarRefFlow->LastModeHeating(VRFCond) = true;
     523              :             // reset heat recovery startup timer
     524            0 :             vrf.HRTimer = 0.0;
     525            0 :             vrf.HRHeatingActive = false;
     526            0 :             vrf.HRCoolingActive = false;
     527              :         }
     528        33935 :     } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) && (TUCoolingLoad * (1.0 + 1.0 / vrf.CoolingCOP)) > TUHeatingLoad) {
     529            1 :         state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
     530            1 :         state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
     531            1 :         vrf.ModeChange = true;
     532            1 :         if (!state.dataHVACVarRefFlow->LastModeCooling(VRFCond)) {
     533            1 :             state.dataHVACVarRefFlow->LastModeCooling(VRFCond) = true;
     534              :             // reset heat recovery startup timer
     535            1 :             vrf.HRTimer = 0.0;
     536            1 :             vrf.HRHeatingActive = false;
     537            1 :             vrf.HRCoolingActive = false;
     538              :         }
     539        33934 :     } else if (TUCoolingLoad > 0.0 && TUHeatingLoad > 0.0 &&
     540            0 :                ((state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) ||
     541            0 :                 (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) && state.dataHVACVarRefFlow->LastModeCooling(VRFCond)))) {
     542            0 :         vrf.ModeChange = true;
     543              :         // reset heat recovery startup timer
     544            0 :         vrf.HRTimer = 0.0;
     545            0 :         vrf.HRHeatingActive = false;
     546            0 :         vrf.HRCoolingActive = false;
     547              :     }
     548              : 
     549              :     // loop through TU's and calculate average inlet conditions for active coils
     550       190977 :     for (NumTU = 1; NumTU <= NumTUInList; ++NumTU) {
     551       157042 :         int TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
     552       157042 :         int CoolCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolCoilIndex;
     553       157042 :         int HeatCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).HeatCoilIndex;
     554       157042 :         TUParasiticPower +=
     555       157042 :             state.dataHVACVarRefFlow->VRFTU(TUIndex).ParasiticCoolElecPower + state.dataHVACVarRefFlow->VRFTU(TUIndex).ParasiticHeatElecPower;
     556       157042 :         TUFanPower += state.dataHVACVarRefFlow->VRFTU(TUIndex).FanPower;
     557              : 
     558       157042 :         if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) > 0.0) {
     559        79736 :             SumCoolInletWB += state.dataDXCoils->DXCoilCoolInletAirWBTemp(CoolCoilIndex) *
     560        79736 :                               state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) / TUCoolingLoad;
     561        79736 :             ++NumTUInCoolingMode;
     562              :         }
     563       157042 :         if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) > 0.0) {
     564        65924 :             SumHeatInletDB += state.dataDXCoils->DXCoilHeatInletAirDBTemp(HeatCoilIndex) *
     565        65924 :                               state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) / TUHeatingLoad;
     566        65924 :             SumHeatInletWB += state.dataDXCoils->DXCoilHeatInletAirWBTemp(HeatCoilIndex) *
     567        65924 :                               state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) / TUHeatingLoad;
     568        65924 :             ++NumTUInHeatingMode;
     569              :         }
     570              :     }
     571              : 
     572        33935 :     bool CoolingCoilAvailableFlag = any(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).CoolingCoilAvailable);
     573        33935 :     bool HeatingCoilAvailableFlag = any(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).HeatingCoilAvailable);
     574              : 
     575              :     // calculate capacities and energy use
     576        33935 :     if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && CoolingCoilAvailableFlag) {
     577        18818 :         InletAirWetBulbC = SumCoolInletWB;
     578        18818 :         TotCoolCapTempModFac = CurveValue(state, vrf.CoolCapFT, InletAirWetBulbC, CondInletTemp);
     579        18818 :         TotCoolEIRTempModFac = CurveValue(state, vrf.CoolEIRFT, InletAirWetBulbC, CondInletTemp);
     580              : 
     581              :         // recalculate cooling Cap and EIR curve output if using boundary curve along with dual Cap and EIR curves.
     582        18818 :         if (vrf.CoolBoundaryCurvePtr > 0) {
     583        18818 :             CoolOABoundary = CurveValue(state, vrf.CoolBoundaryCurvePtr, InletAirWetBulbC);
     584        18818 :             if (OutdoorDryBulb > CoolOABoundary) {
     585        18817 :                 if (vrf.CoolCapFTHi > 0) {
     586        18817 :                     TotCoolCapTempModFac = CurveValue(state, vrf.CoolCapFTHi, InletAirWetBulbC, CondInletTemp);
     587              :                 }
     588              :             }
     589              :         }
     590        18818 :         if (vrf.EIRCoolBoundaryCurvePtr > 0) {
     591        18818 :             CoolOABoundary = CurveValue(state, vrf.EIRCoolBoundaryCurvePtr, InletAirWetBulbC);
     592        18818 :             if (OutdoorDryBulb > CoolOABoundary) {
     593        18817 :                 if (vrf.CoolEIRFTHi > 0) {
     594        18817 :                     TotCoolEIRTempModFac = CurveValue(state, vrf.CoolEIRFTHi, InletAirWetBulbC, CondInletTemp);
     595              :                 }
     596              :             }
     597              :         }
     598              : 
     599              :         //   Warn user if curve output goes negative
     600        18818 :         if (TotCoolCapTempModFac < 0.0) {
     601            0 :             if (!state.dataGlobal->WarmupFlag && NumTUInCoolingMode > 0) {
     602            0 :                 if (vrf.CoolCapFTErrorIndex == 0) {
     603            0 :                     ShowSevereMessage(state, format("{} \"{}\":", cVRFTypes(VRF_HeatPump), vrf.Name));
     604            0 :                     ShowContinueError(
     605              :                         state,
     606            0 :                         format(" Cooling Capacity Modifier curve (function of temperature) output is negative ({:.3T}).", TotCoolCapTempModFac));
     607            0 :                     ShowContinueError(state,
     608            0 :                                       format(" Negative value occurs using an outdoor air temperature of {:.1T} C and an average indoor air "
     609              :                                              "wet-bulb temperature of {:.1T} C.",
     610              :                                              CondInletTemp,
     611              :                                              InletAirWetBulbC));
     612            0 :                     ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
     613              :                 }
     614            0 :                 ShowRecurringWarningErrorAtEnd(
     615              :                     state,
     616            0 :                     format("{} \"{}\": Cooling Capacity Modifier curve (function of temperature) output is negative warning continues...",
     617            0 :                            PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
     618            0 :                            vrf.Name),
     619            0 :                     vrf.CoolCapFTErrorIndex,
     620              :                     TotCoolCapTempModFac,
     621              :                     TotCoolCapTempModFac);
     622            0 :                 TotCoolCapTempModFac = 0.0;
     623              :             }
     624              :         }
     625              : 
     626              :         //   Warn user if curve output goes negative
     627        18818 :         if (TotCoolEIRTempModFac < 0.0) {
     628            0 :             if (!state.dataGlobal->WarmupFlag && NumTUInCoolingMode > 0) {
     629            0 :                 if (vrf.EIRFTempCoolErrorIndex == 0) {
     630            0 :                     ShowSevereMessage(state, format("{} \"{}\":", cVRFTypes(VRF_HeatPump), vrf.Name));
     631            0 :                     ShowContinueError(state,
     632            0 :                                       format(" Cooling Energy Input Ratio Modifier curve (function of temperature) output is negative ({:.3T}).",
     633              :                                              TotCoolEIRTempModFac));
     634            0 :                     ShowContinueError(state,
     635            0 :                                       format(" Negative value occurs using an outdoor air temperature of {:.1T} C and an average indoor air "
     636              :                                              "wet-bulb temperature of {:.1T} C.",
     637              :                                              CondInletTemp,
     638              :                                              InletAirWetBulbC));
     639            0 :                     ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
     640              :                 }
     641            0 :                 ShowRecurringWarningErrorAtEnd(
     642              :                     state,
     643            0 :                     format("{} \"{}\": Cooling Energy Input Ratio Modifier curve (function of temperature) output is negative warning continues...",
     644            0 :                            PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
     645            0 :                            vrf.Name),
     646            0 :                     vrf.EIRFTempCoolErrorIndex,
     647              :                     TotCoolEIRTempModFac,
     648              :                     TotCoolEIRTempModFac);
     649            0 :                 TotCoolEIRTempModFac = 0.0;
     650              :             }
     651              :         }
     652              : 
     653        18818 :         TotalCondCoolingCapacity = vrf.CoolingCapacity * state.dataHVACVarRefFlow->CoolCombinationRatio(VRFCond) * TotCoolCapTempModFac;
     654        18818 :         TotalTUCoolingCapacity = TotalCondCoolingCapacity * vrf.PipingCorrectionCooling;
     655              : 
     656        18818 :         if (TotalCondCoolingCapacity > 0.0) {
     657        18818 :             CoolingPLR = (TUCoolingLoad / vrf.PipingCorrectionCooling) / TotalCondCoolingCapacity;
     658              :         } else {
     659            0 :             CoolingPLR = 0.0;
     660              :         }
     661              : 
     662              :         //   Warn user if curve output goes negative
     663        18818 :         if (TotCoolCapTempModFac < 0.0) {
     664            0 :             if (!state.dataGlobal->WarmupFlag && NumTUInCoolingMode > 0) {
     665            0 :                 if (vrf.CoolCapFTErrorIndex == 0) {
     666            0 :                     ShowSevereMessage(state, format("{} \"{}\":", cVRFTypes(VRF_HeatPump), vrf.Name));
     667            0 :                     ShowContinueError(
     668              :                         state,
     669            0 :                         format(" Cooling Capacity Modifier curve (function of temperature) output is negative ({:.3T}).", TotCoolCapTempModFac));
     670            0 :                     ShowContinueError(state,
     671            0 :                                       format(" Negative value occurs using an outdoor air temperature of {:.1T} C and an average indoor air "
     672              :                                              "wet-bulb temperature of {:.1T} C.",
     673              :                                              CondInletTemp,
     674              :                                              InletAirWetBulbC));
     675            0 :                     ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
     676              :                 }
     677            0 :                 ShowRecurringWarningErrorAtEnd(
     678              :                     state,
     679            0 :                     format("{} \"{}\": Cooling Capacity Modifier curve (function of temperature) output is negative warning continues...",
     680            0 :                            PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
     681            0 :                            vrf.Name),
     682            0 :                     vrf.CoolCapFTErrorIndex,
     683              :                     TotCoolCapTempModFac,
     684              :                     TotCoolCapTempModFac);
     685            0 :                 TotCoolCapTempModFac = 0.0;
     686              :             }
     687              :         }
     688              :         //   Warn user if curve output goes negative
     689        18818 :         if (TotCoolEIRTempModFac < 0.0) {
     690            0 :             if (!state.dataGlobal->WarmupFlag && NumTUInCoolingMode > 0) {
     691            0 :                 if (vrf.EIRFTempCoolErrorIndex == 0) {
     692            0 :                     ShowSevereMessage(state, format("{} \"{}\":", cVRFTypes(VRF_HeatPump), vrf.Name));
     693            0 :                     ShowContinueError(state,
     694            0 :                                       format(" Cooling Energy Input Ratio Modifier curve (function of temperature) output is negative ({:.3T}).",
     695              :                                              TotCoolEIRTempModFac));
     696            0 :                     ShowContinueError(state,
     697            0 :                                       format(" Negative value occurs using an outdoor air temperature of {:.1T} C and an average indoor air "
     698              :                                              "wet-bulb temperature of {:.1T} C.",
     699              :                                              CondInletTemp,
     700              :                                              InletAirWetBulbC));
     701            0 :                     ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
     702              :                 }
     703            0 :                 ShowRecurringWarningErrorAtEnd(
     704              :                     state,
     705            0 :                     format("{} \"{}\": Cooling Energy Input Ratio Modifier curve (function of temperature) output is negative warning continues...",
     706            0 :                            PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
     707            0 :                            vrf.Name),
     708            0 :                     vrf.EIRFTempCoolErrorIndex,
     709              :                     TotCoolEIRTempModFac,
     710              :                     TotCoolEIRTempModFac);
     711            0 :                 TotCoolEIRTempModFac = 0.0;
     712              :             }
     713              :         }
     714              : 
     715        15117 :     } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) && HeatingCoilAvailableFlag) {
     716        15112 :         InletAirDryBulbC = SumHeatInletDB;
     717        15112 :         InletAirWetBulbC = SumHeatInletWB;
     718        15112 :         switch (vrf.HeatingPerformanceOATType) {
     719         1453 :         case HVAC::OATType::DryBulb: {
     720         1453 :             TotHeatCapTempModFac = CurveValue(state, vrf.HeatCapFT, InletAirDryBulbC, CondInletTemp);
     721         1453 :             TotHeatEIRTempModFac = CurveValue(state, vrf.HeatEIRFT, InletAirDryBulbC, CondInletTemp);
     722         1453 :         } break;
     723        13659 :         case HVAC::OATType::WetBulb: {
     724        13659 :             TotHeatCapTempModFac = CurveValue(state, vrf.HeatCapFT, InletAirDryBulbC, OutdoorWetBulb);
     725        13659 :             TotHeatEIRTempModFac = CurveValue(state, vrf.HeatEIRFT, InletAirDryBulbC, OutdoorWetBulb);
     726        13659 :         } break;
     727            0 :         default: {
     728            0 :             TotHeatCapTempModFac = 1.0;
     729            0 :             TotHeatEIRTempModFac = 1.0;
     730            0 :         } break;
     731              :         }
     732              :         // recalculate heating Cap and EIR curve output if using boundary curve along with dual Cap and EIR curves.
     733        15112 :         if (vrf.HeatBoundaryCurvePtr > 0) {
     734        15112 :             HeatOABoundary = CurveValue(state, vrf.HeatBoundaryCurvePtr, InletAirDryBulbC);
     735        15112 :             switch (vrf.HeatingPerformanceOATType) {
     736         1453 :             case HVAC::OATType::DryBulb: {
     737         1453 :                 if (OutdoorDryBulb > HeatOABoundary) {
     738         1453 :                     if (vrf.HeatCapFTHi > 0) {
     739         1453 :                         TotHeatCapTempModFac = CurveValue(state, vrf.HeatCapFTHi, InletAirDryBulbC, CondInletTemp);
     740              :                     }
     741              :                 }
     742         1453 :             } break;
     743        13659 :             case HVAC::OATType::WetBulb: {
     744        13659 :                 if (OutdoorWetBulb > HeatOABoundary) {
     745         2670 :                     if (vrf.HeatCapFTHi > 0) {
     746         2670 :                         TotHeatCapTempModFac = CurveValue(state, vrf.HeatCapFTHi, InletAirDryBulbC, OutdoorWetBulb);
     747              :                     }
     748              :                 }
     749        13659 :             } break;
     750            0 :             default: {
     751            0 :                 TotHeatCapTempModFac = 1.0;
     752            0 :             } break;
     753              :             }
     754              :         }
     755        15112 :         if (vrf.EIRHeatBoundaryCurvePtr > 0) {
     756        15112 :             HeatOABoundary = CurveValue(state, vrf.EIRHeatBoundaryCurvePtr, InletAirDryBulbC);
     757        15112 :             switch (vrf.HeatingPerformanceOATType) {
     758         1453 :             case HVAC::OATType::DryBulb: {
     759         1453 :                 if (OutdoorDryBulb > HeatOABoundary) {
     760         1453 :                     if (vrf.HeatEIRFTHi > 0) {
     761         1453 :                         TotHeatEIRTempModFac = CurveValue(state, vrf.HeatEIRFTHi, InletAirDryBulbC, CondInletTemp);
     762              :                     }
     763              :                 }
     764         1453 :             } break;
     765        13659 :             case HVAC::OATType::WetBulb: {
     766        13659 :                 if (OutdoorWetBulb > HeatOABoundary) {
     767         2670 :                     if (vrf.HeatEIRFTHi > 0) {
     768         2670 :                         TotHeatEIRTempModFac = CurveValue(state, vrf.HeatEIRFTHi, InletAirDryBulbC, OutdoorWetBulb);
     769              :                     }
     770              :                 }
     771        13659 :             } break;
     772            0 :             default: {
     773            0 :                 TotHeatEIRTempModFac = 1.0;
     774            0 :             } break;
     775              :             }
     776              :         }
     777              : 
     778              :         //   Warn user if curve output goes negative
     779        15112 :         if (TotHeatCapTempModFac < 0.0) {
     780            0 :             if (!state.dataGlobal->WarmupFlag && NumTUInHeatingMode > 0) {
     781            0 :                 if (vrf.HeatCapFTErrorIndex == 0) {
     782            0 :                     ShowSevereMessage(state, format("{} \"{}\":", cVRFTypes(VRF_HeatPump), vrf.Name));
     783            0 :                     ShowContinueError(
     784              :                         state,
     785            0 :                         format(" Heating Capacity Modifier curve (function of temperature) output is negative ({:.3T}).", TotHeatCapTempModFac));
     786              : 
     787            0 :                     switch (vrf.HeatingPerformanceOATType) {
     788            0 :                     case HVAC::OATType::DryBulb: {
     789            0 :                         ShowContinueError(state,
     790            0 :                                           format(" Negative value occurs using an outdoor air temperature of {:.1T} C and an average indoor air "
     791              :                                                  "dry-bulb temperature of {:.1T} C.",
     792              :                                                  CondInletTemp,
     793              :                                                  InletAirDryBulbC));
     794            0 :                     } break;
     795            0 :                     case HVAC::OATType::WetBulb: {
     796            0 :                         ShowContinueError(state,
     797            0 :                                           format(" Negative value occurs using an outdoor air wet-bulb temperature of {:.1T} C and an average "
     798              :                                                  "indoor air wet-bulb temperature of {:.1T} C.",
     799              :                                                  OutdoorWetBulb,
     800              :                                                  InletAirWetBulbC));
     801            0 :                     } break;
     802            0 :                     default:
     803              :                         // should never get here
     804            0 :                         break;
     805              :                     }
     806              : 
     807            0 :                     ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
     808              :                 }
     809            0 :                 ShowRecurringWarningErrorAtEnd(
     810              :                     state,
     811            0 :                     format("{} \"{}\": Heating Capacity Ratio Modifier curve (function of temperature) output is negative warning continues...",
     812            0 :                            PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
     813            0 :                            vrf.Name),
     814            0 :                     vrf.HeatCapFTErrorIndex,
     815              :                     TotHeatCapTempModFac,
     816              :                     TotHeatCapTempModFac);
     817            0 :                 TotHeatCapTempModFac = 0.0;
     818              :             }
     819              :         }
     820              :         //   Warn user if curve output goes negative
     821        15112 :         if (TotHeatEIRTempModFac < 0.0) {
     822            0 :             if (!state.dataGlobal->WarmupFlag && NumTUInHeatingMode > 0) {
     823            0 :                 if (vrf.EIRFTempHeatErrorIndex == 0) {
     824            0 :                     ShowSevereMessage(state, format("{} \"{}\":", cVRFTypes(VRF_HeatPump), vrf.Name));
     825            0 :                     ShowContinueError(state,
     826            0 :                                       format(" Heating Energy Input Ratio Modifier curve (function of temperature) output is negative ({:.3T}).",
     827              :                                              TotHeatEIRTempModFac));
     828            0 :                     switch (vrf.HeatingPerformanceOATType) {
     829            0 :                     case HVAC::OATType::DryBulb: {
     830            0 :                         ShowContinueError(state,
     831            0 :                                           format(" Negative value occurs using an outdoor air dry-bulb temperature of {:.1T} C and an "
     832              :                                                  "average indoor air dry-bulb temperature of {:.1T} C.",
     833              :                                                  CondInletTemp,
     834              :                                                  InletAirDryBulbC));
     835            0 :                     } break;
     836            0 :                     case HVAC::OATType::WetBulb: {
     837            0 :                         ShowContinueError(state,
     838            0 :                                           format(" Negative value occurs using an outdoor air wet-bulb temperature of {:.1T} C and an "
     839              :                                                  "average indoor air wet-bulb temperature of {:.1T} C.",
     840              :                                                  OutdoorWetBulb,
     841              :                                                  InletAirWetBulbC));
     842            0 :                     } break;
     843            0 :                     default:
     844            0 :                         break;
     845              :                     }
     846            0 :                     ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
     847              :                 }
     848            0 :                 ShowRecurringWarningErrorAtEnd(
     849              :                     state,
     850            0 :                     format("{} \"{}\": Heating Energy Input Ratio Modifier curve (function of temperature) output is negative warning continues...",
     851            0 :                            PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
     852            0 :                            vrf.Name),
     853            0 :                     vrf.EIRFTempHeatErrorIndex,
     854              :                     TotHeatEIRTempModFac,
     855              :                     TotHeatEIRTempModFac);
     856            0 :                 TotHeatEIRTempModFac = 0.0;
     857              :             }
     858              :         }
     859              : 
     860              :         // Initializing defrost adjustment factors
     861        15112 :         LoadDueToDefrost = 0.0;
     862        15112 :         HeatingCapacityMultiplier = 1.0;
     863        15112 :         FractionalDefrostTime = 0.0;
     864        15112 :         InputPowerMultiplier = 1.0;
     865              : 
     866              :         // Check outdoor temperature to determine of defrost is active
     867        15112 :         if (OutdoorDryBulb <= vrf.MaxOATDefrost && vrf.CondenserType != DataHeatBalance::RefrigCondenserType::Water) {
     868              : 
     869              :             // Calculating adjustment factors for defrost
     870              :             // Calculate delta w through outdoor coil by assuming a coil temp of 0.82*DBT-9.7(F) per DOE2.1E
     871         2871 :             OutdoorCoilT = 0.82 * OutdoorDryBulb - 8.589;
     872         2871 :             OutdoorCoildw = max(1.0e-6, (OutdoorHumRat - PsyWFnTdpPb(state, OutdoorCoilT, OutdoorPressure)));
     873              : 
     874              :             // Calculate defrost adjustment factors depending on defrost control type
     875         2871 :             if (vrf.DefrostControl == StandardRatings::HPdefrostControl::Timed) {
     876         2871 :                 FractionalDefrostTime = vrf.DefrostFraction;
     877         2871 :                 if (FractionalDefrostTime > 0.0) {
     878         2871 :                     HeatingCapacityMultiplier = 0.909 - 107.33 * OutdoorCoildw;
     879         2871 :                     InputPowerMultiplier = 0.90 - 36.45 * OutdoorCoildw;
     880              :                 }
     881              :             } else { // else defrost control is on-demand
     882            0 :                 FractionalDefrostTime = 1.0 / (1.0 + 0.01446 / OutdoorCoildw);
     883            0 :                 HeatingCapacityMultiplier = 0.875 * (1.0 - FractionalDefrostTime);
     884            0 :                 InputPowerMultiplier = 0.954 * (1.0 - FractionalDefrostTime);
     885              :             }
     886              : 
     887         2871 :             if (FractionalDefrostTime > 0.0) {
     888              :                 // Calculate defrost adjustment factors depending on defrost control strategy
     889         2871 :                 if (vrf.DefrostStrategy == StandardRatings::DefrostStrat::ReverseCycle) {
     890            0 :                     LoadDueToDefrost = (0.01 * FractionalDefrostTime) * (7.222 - OutdoorDryBulb) * (vrf.HeatingCapacity / 1.01667);
     891            0 :                     DefrostEIRTempModFac = CurveValue(state, vrf.DefrostEIRPtr, max(15.555, InletAirWetBulbC), max(15.555, OutdoorDryBulb));
     892              : 
     893              :                     //         Warn user if curve output goes negative
     894            0 :                     if (DefrostEIRTempModFac < 0.0) {
     895            0 :                         if (!state.dataGlobal->WarmupFlag) {
     896            0 :                             if (vrf.DefrostHeatErrorIndex == 0) {
     897            0 :                                 ShowSevereMessage(state, format("{} \"{}\":", cVRFTypes(VRF_HeatPump), vrf.Name));
     898            0 :                                 ShowContinueError(
     899              :                                     state,
     900            0 :                                     format(" Defrost Energy Input Ratio Modifier curve (function of temperature) output is negative ({:.3T}).",
     901              :                                            DefrostEIRTempModFac));
     902            0 :                                 ShowContinueError(state,
     903            0 :                                                   format(" Negative value occurs using an outdoor air dry-bulb temperature of {:.1T} C and an "
     904              :                                                          "average indoor air wet-bulb temperature of {:.1T} C.",
     905              :                                                          OutdoorDryBulb,
     906              :                                                          InletAirWetBulbC));
     907            0 :                                 ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
     908              :                             }
     909            0 :                             ShowRecurringWarningErrorAtEnd(state,
     910            0 :                                                            format("{} \"{}\": Defrost Energy Input Ratio Modifier curve (function of temperature) "
     911              :                                                                   "output is negative warning continues...",
     912            0 :                                                                   PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
     913            0 :                                                                   vrf.Name),
     914            0 :                                                            vrf.DefrostHeatErrorIndex,
     915              :                                                            DefrostEIRTempModFac,
     916              :                                                            DefrostEIRTempModFac);
     917            0 :                             DefrostEIRTempModFac = 0.0;
     918              :                         }
     919              :                     }
     920              : 
     921            0 :                     vrf.DefrostPower = DefrostEIRTempModFac * (vrf.HeatingCapacity / 1.01667) * FractionalDefrostTime;
     922              : 
     923              :                 } else { // Defrost strategy is resistive
     924         2871 :                     vrf.DefrostPower = vrf.DefrostCapacity * FractionalDefrostTime;
     925              :                 }
     926              :             }
     927              :         }
     928              : 
     929        15112 :         TotalCondHeatingCapacity =
     930        15112 :             vrf.HeatingCapacity * state.dataHVACVarRefFlow->HeatCombinationRatio(VRFCond) * TotHeatCapTempModFac * HeatingCapacityMultiplier;
     931        15112 :         TotalTUHeatingCapacity = TotalCondHeatingCapacity * vrf.PipingCorrectionHeating;
     932        15112 :         if (TotalCondHeatingCapacity > 0.0) {
     933        15112 :             HeatingPLR = (TUHeatingLoad / vrf.PipingCorrectionHeating) / TotalCondHeatingCapacity;
     934        15112 :             HeatingPLR += (LoadDueToDefrost * HeatingPLR) / TotalCondHeatingCapacity;
     935              :         } else {
     936            0 :             HeatingPLR = 0.0;
     937              :         }
     938              :     }
     939              : 
     940        33935 :     vrf.VRFCondPLR = max(CoolingPLR, HeatingPLR);
     941        33935 :     Real64 tmpVRFCondPLR = 0.0;
     942        33935 :     if (CoolingPLR > 0.0 || HeatingPLR > 0.0) {
     943        33930 :         tmpVRFCondPLR = max(vrf.MinPLR, vrf.VRFCondPLR);
     944              :     }
     945              : 
     946        33935 :     HRHeatRequestFlag = any(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).HRHeatRequest);
     947        33935 :     HRCoolRequestFlag = any(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).HRCoolRequest);
     948        33935 :     HREIRFTConst = 1.0;
     949        33935 :     Real64 HREIRAdjustment = 1.0;
     950              : 
     951        33935 :     if (!state.dataGlobal->DoingSizing && !state.dataGlobal->WarmupFlag) {
     952         4784 :         if (HRHeatRequestFlag && HRCoolRequestFlag) {
     953              :             // determine operating mode change
     954            0 :             if (!vrf.HRCoolingActive && !vrf.HRHeatingActive) {
     955            0 :                 vrf.ModeChange = true;
     956            0 :                 vrf.HRTimer = 0.0;
     957              :             }
     958            0 :             if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) {
     959            0 :                 if (vrf.HRHeatingActive && !vrf.HRCoolingActive) {
     960            0 :                     vrf.HRModeChange = true;
     961              :                 }
     962            0 :                 vrf.HRCoolingActive = true;
     963            0 :                 vrf.HRHeatingActive = false;
     964            0 :                 int HRCAPFT = vrf.HRCAPFTCool; // Index to cool capacity as a function of temperature\PLR curve for heat recovery
     965            0 :                 if (HRCAPFT > 0) {
     966              :                     //         VRF(VRFCond)%HRCAPFTCoolConst = 0.9d0 ! initialized to 0.9
     967            0 :                     if (state.dataCurveManager->curves(vrf.HRCAPFTCool)->numDims == 2) { // Curve type for HRCAPFTCool
     968            0 :                         vrf.HRCAPFTCoolConst = CurveValue(state, HRCAPFT, InletAirWetBulbC, CondInletTemp);
     969              :                     } else {
     970            0 :                         vrf.HRCAPFTCoolConst = CurveValue(state, HRCAPFT, tmpVRFCondPLR);
     971              :                     }
     972              :                 }
     973            0 :                 HRCAPFTConst = vrf.HRCAPFTCoolConst;
     974            0 :                 HRInitialCapFrac = vrf.HRInitialCoolCapFrac; // Fractional cooling degradation at the start of heat recovery from cooling mode
     975            0 :                 HRCapTC = vrf.HRCoolCapTC;                   // Time constant used to recover from initial degradation in cooling heat recovery
     976              : 
     977            0 :                 int HREIRFT = vrf.HREIRFTCool; // Index to cool EIR as a function of temperature curve for heat recovery
     978            0 :                 if (HREIRFT > 0) {
     979              :                     //         VRF(VRFCond)%HREIRFTCoolConst = 1.1d0 ! initialized to 1.1
     980            0 :                     if (state.dataCurveManager->curves(vrf.HREIRFTCool)->numDims == 2) { // Curve type for HREIRFTCool
     981            0 :                         vrf.HREIRFTCoolConst = CurveValue(state, HREIRFT, InletAirWetBulbC, CondInletTemp);
     982              :                     } else {
     983            0 :                         vrf.HREIRFTCoolConst = CurveValue(state, HREIRFT, tmpVRFCondPLR);
     984              :                     }
     985              :                 }
     986            0 :                 HREIRFTConst = vrf.HREIRFTCoolConst;
     987            0 :                 HRInitialEIRFrac = vrf.HRInitialCoolEIRFrac; // Fractional cooling degradation at the start of heat recovery from cooling mode
     988            0 :                 HREIRTC = vrf.HRCoolEIRTC;                   // Time constant used to recover from initial degradation in cooling heat recovery
     989            0 :             } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) {
     990            0 :                 if (!vrf.HRHeatingActive && vrf.HRCoolingActive) {
     991            0 :                     vrf.HRModeChange = true;
     992              :                 }
     993            0 :                 vrf.HRCoolingActive = false;
     994            0 :                 vrf.HRHeatingActive = true;
     995            0 :                 int HRCAPFT = vrf.HRCAPFTHeat; // Index to heat capacity as a function of temperature\PLR curve for heat recovery
     996            0 :                 if (HRCAPFT > 0) {
     997              :                     //         VRF(VRFCond)%HRCAPFTHeatConst = 1.1d0 ! initialized to 1.1
     998            0 :                     if (state.dataCurveManager->curves(vrf.HRCAPFTHeat)->numDims == 2) { // Curve type for HRCAPFTCool
     999            0 :                         switch (vrf.HeatingPerformanceOATType) {
    1000            0 :                         case HVAC::OATType::DryBulb: {
    1001            0 :                             vrf.HRCAPFTHeatConst = CurveValue(state, HRCAPFT, InletAirDryBulbC, CondInletTemp);
    1002            0 :                         } break;
    1003            0 :                         case HVAC::OATType::WetBulb: {
    1004            0 :                             vrf.HRCAPFTHeatConst = CurveValue(state, HRCAPFT, InletAirDryBulbC, OutdoorWetBulb);
    1005            0 :                         } break;
    1006            0 :                         default: {
    1007            0 :                             vrf.HRCAPFTHeatConst = 1.0;
    1008            0 :                         } break;
    1009              :                         }
    1010              :                     } else {
    1011            0 :                         vrf.HRCAPFTHeatConst = CurveValue(state, HRCAPFT, tmpVRFCondPLR);
    1012              :                     }
    1013              :                 }
    1014            0 :                 HRCAPFTConst = vrf.HRCAPFTHeatConst;
    1015            0 :                 HRInitialCapFrac = vrf.HRInitialHeatCapFrac; // Fractional heating degradation at the start of heat recovery from cooling mode
    1016            0 :                 HRCapTC = vrf.HRHeatCapTC;                   // Time constant used to recover from initial degradation in heating heat recovery
    1017              : 
    1018            0 :                 int HREIRFT = vrf.HREIRFTHeat; // Index to cool EIR as a function of temperature curve for heat recovery
    1019            0 :                 if (HREIRFT > 0) {
    1020              :                     //         VRF(VRFCond)%HREIRFTCoolConst = 1.1d0 ! initialized to 1.1
    1021            0 :                     if (state.dataCurveManager->curves(vrf.HREIRFTHeat)->numDims == 2) { // Curve type for HREIRFTHeat
    1022            0 :                         switch (vrf.HeatingPerformanceOATType) {
    1023            0 :                         case HVAC::OATType::DryBulb: {
    1024            0 :                             vrf.HREIRFTHeatConst = CurveValue(state, HREIRFT, InletAirDryBulbC, CondInletTemp);
    1025            0 :                         } break;
    1026            0 :                         case HVAC::OATType::WetBulb: {
    1027            0 :                             vrf.HREIRFTHeatConst = CurveValue(state, HREIRFT, InletAirDryBulbC, OutdoorWetBulb);
    1028            0 :                         } break;
    1029            0 :                         default: {
    1030            0 :                             vrf.HREIRFTHeatConst = 1.0;
    1031            0 :                         } break;
    1032              :                         }
    1033              :                     } else {
    1034            0 :                         vrf.HREIRFTHeatConst = CurveValue(state, HREIRFT, tmpVRFCondPLR);
    1035              :                     }
    1036              :                 }
    1037            0 :                 HREIRFTConst = vrf.HREIRFTHeatConst;
    1038            0 :                 HRInitialEIRFrac = vrf.HRInitialHeatEIRFrac; // Fractional heating degradation at the start of heat recovery from heating mode
    1039            0 :                 HREIRTC = vrf.HRHeatEIRTC;                   // Time constant used to recover from initial degradation in heating heat recovery
    1040              :             } else {
    1041              :                 //   zone thermostats satisfied, condenser is off. Set values anyway
    1042            0 :                 HRCAPFTConst = 1.0;
    1043            0 :                 HRInitialCapFrac = 1.0;
    1044            0 :                 HRCapTC = 1.0;
    1045            0 :                 HREIRFTConst = 1.0;
    1046            0 :                 HRInitialEIRFrac = 1.0;
    1047            0 :                 HREIRTC = 1.0;
    1048            0 :                 if (vrf.HRHeatingActive || vrf.HRCoolingActive) {
    1049            0 :                     vrf.HRModeChange = true;
    1050              :                 }
    1051            0 :                 vrf.HRCoolingActive = false;
    1052            0 :                 vrf.HRHeatingActive = false;
    1053              :             }
    1054              : 
    1055            0 :         } else { // IF(HRHeatRequestFlag .AND. HRCoolRequestFlag)THEN -- Heat recovery turned off
    1056         4784 :             HRCAPFTConst = 1.0;
    1057         4784 :             HRInitialCapFrac = 1.0;
    1058         4784 :             HRCapTC = 0.0;
    1059         4784 :             HREIRFTConst = 1.0;
    1060         4784 :             HRInitialEIRFrac = 1.0;
    1061         4784 :             HREIRTC = 0.0;
    1062         4784 :             vrf.HRModeChange = false;
    1063         4784 :             vrf.HRCoolingActive = false;
    1064         4784 :             vrf.HRHeatingActive = false;
    1065         4784 :             vrf.HRTimer = 0.0;
    1066              :         }
    1067              : 
    1068              :         // Calculate the capacity modification factor (SUMultiplier) for the HR mode transition period
    1069         4784 :         CurrentEndTime = double((state.dataGlobal->DayOfSim - 1) * 24) + state.dataGlobal->CurrentTime - state.dataGlobal->TimeStepZone +
    1070         4784 :                          state.dataHVACGlobal->SysTimeElapsed;
    1071              : 
    1072         4784 :         if (vrf.ModeChange || vrf.HRModeChange) {
    1073            0 :             if (vrf.HRCoolingActive && vrf.HRTimer == 0.0) {
    1074            0 :                 vrf.HRTimer = state.dataHVACVarRefFlow->CurrentEndTimeLast;
    1075            0 :             } else if (vrf.HRHeatingActive && vrf.HRTimer == 0.0) {
    1076            0 :                 vrf.HRTimer = state.dataHVACVarRefFlow->CurrentEndTimeLast;
    1077            0 :             } else if (!vrf.HRCoolingActive && !vrf.HRHeatingActive) {
    1078            0 :                 vrf.HRTimer = 0.0;
    1079              :             }
    1080              :         }
    1081              : 
    1082         4784 :         vrf.HRTime = max(0.0, CurrentEndTime - vrf.HRTimer);
    1083         4784 :         if (vrf.HRTime < (HRCapTC * 5.0)) {
    1084            0 :             if (HRCapTC > 0.0) {
    1085            0 :                 SUMultiplier = min(1.0, 1.0 - std::exp(-vrf.HRTime / HRCapTC));
    1086              :             } else {
    1087            0 :                 SUMultiplier = 1.0;
    1088              :             }
    1089              :         } else {
    1090         4784 :             SUMultiplier = 1.0;
    1091         4784 :             vrf.ModeChange = false;
    1092         4784 :             vrf.HRModeChange = false;
    1093              :         }
    1094         4784 :         vrf.SUMultiplier = SUMultiplier;
    1095              : 
    1096         4784 :         state.dataHVACVarRefFlow->CurrentEndTimeLast = CurrentEndTime;
    1097              : 
    1098         4784 :         if (vrf.HeatRecoveryUsed && vrf.HRCoolingActive) {
    1099            0 :             TotalCondCoolingCapacity *= HRCAPFTConst;
    1100            0 :             TotalCondCoolingCapacity =
    1101            0 :                 HRInitialCapFrac * TotalCondCoolingCapacity + (1.0 - HRInitialCapFrac) * TotalCondCoolingCapacity * SUMultiplier;
    1102            0 :             TotalTUCoolingCapacity = TotalCondCoolingCapacity * vrf.PipingCorrectionCooling;
    1103            0 :             if (TotalCondCoolingCapacity > 0.0) {
    1104            0 :                 CoolingPLR = min(1.0, (TUCoolingLoad / vrf.PipingCorrectionCooling) / TotalCondCoolingCapacity);
    1105              :             } else {
    1106            0 :                 CoolingPLR = 0.0;
    1107              :             }
    1108            0 :             HREIRAdjustment = HRInitialEIRFrac + (HREIRFTConst - HRInitialEIRFrac) * SUMultiplier;
    1109            0 :             vrf.VRFHeatRec = TUHeatingLoad;
    1110         4784 :         } else if (vrf.HeatRecoveryUsed && vrf.HRHeatingActive) {
    1111            0 :             TotalCondHeatingCapacity *= HRCAPFTConst;
    1112            0 :             TotalCondHeatingCapacity =
    1113            0 :                 HRInitialCapFrac * TotalCondHeatingCapacity + (1.0 - HRInitialCapFrac) * TotalCondHeatingCapacity * SUMultiplier;
    1114            0 :             TotalTUHeatingCapacity = TotalCondHeatingCapacity * vrf.PipingCorrectionHeating;
    1115            0 :             if (TotalCondHeatingCapacity > 0.0) {
    1116            0 :                 HeatingPLR = min(1.0, (TUHeatingLoad / vrf.PipingCorrectionHeating) / TotalCondHeatingCapacity);
    1117              :             } else {
    1118            0 :                 HeatingPLR = 0.0;
    1119              :             }
    1120            0 :             HREIRAdjustment = HRInitialEIRFrac + (HREIRFTConst - HRInitialEIRFrac) * SUMultiplier;
    1121            0 :             vrf.VRFHeatRec = TUCoolingLoad;
    1122              :         }
    1123         4784 :         vrf.VRFCondPLR = max(CoolingPLR, HeatingPLR);
    1124              :     }
    1125              : 
    1126        33935 :     if (vrf.MinPLR > 0.0) {
    1127        33935 :         CyclingRatio = min(1.0, vrf.VRFCondPLR / vrf.MinPLR);
    1128        33935 :         if (vrf.VRFCondPLR < vrf.MinPLR && vrf.VRFCondPLR > 0.0) {
    1129        17695 :             vrf.VRFCondPLR = vrf.MinPLR;
    1130        17695 :             if (CoolingPLR > 0.0) {
    1131         7196 :                 CoolingPLR = vrf.MinPLR; // also adjust local PLR variables
    1132              :             }
    1133        17695 :             if (HeatingPLR > 0.0) {
    1134        10499 :                 HeatingPLR = vrf.MinPLR; // also adjust local PLR variables
    1135              :             }
    1136              :         }
    1137              :     }
    1138        33935 :     vrf.VRFCondCyclingRatio = CyclingRatio; // report variable for cycling rate
    1139        33935 :     vrf.TotalCoolingCapacity = TotalCondCoolingCapacity * CoolingPLR * CyclingRatio;
    1140        33935 :     vrf.TotalHeatingCapacity = TotalCondHeatingCapacity * HeatingPLR * CyclingRatio;
    1141              : 
    1142        33935 :     vrf.OperatingMode = 0; // report variable for heating or cooling mode
    1143        33935 :     EIRFPLRModFac = 1.0;
    1144        33935 :     VRFRTF = 0.0;
    1145              :     // cooling and heating is optional (only one may exist), if so then performance curve for missing coil are not required
    1146        33935 :     if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && CoolingPLR > 0.0) {
    1147        18818 :         vrf.OperatingMode = ModeCoolingOnly;
    1148        18818 :         if (CoolingPLR > 1.0) {
    1149          434 :             if (vrf.CoolEIRFPLR2 > 0) {
    1150          434 :                 EIRFPLRModFac = CurveValue(state, vrf.CoolEIRFPLR2, max(vrf.MinPLR, CoolingPLR));
    1151              :             }
    1152              :         } else {
    1153        18384 :             if (vrf.CoolEIRFPLR1 > 0) {
    1154        18384 :                 EIRFPLRModFac = CurveValue(state, vrf.CoolEIRFPLR1, max(vrf.MinPLR, CoolingPLR));
    1155              :             }
    1156              :         }
    1157              : 
    1158        18818 :         if (EIRFPLRModFac < 0.0) {
    1159            0 :             if (vrf.CoolEIRFPLRErrorIndex == 0) {
    1160            0 :                 ShowSevereMessage(state, fmt::format("{} \"{}\":", std::string(cVRFTypes(VRF_HeatPump)), vrf.Name));
    1161            0 :                 ShowContinueError(state, format(" Cooling EIR Modifier curve (function of PLR) output is negative ({:.3T}).", EIRFPLRModFac));
    1162            0 :                 ShowContinueError(state, format(" Negative value occurs using a cooling Part Load Ratio (PLR) of {:.2T}.", CoolingPLR));
    1163            0 :                 ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
    1164              :             }
    1165            0 :             ShowRecurringWarningErrorAtEnd(
    1166              :                 state,
    1167            0 :                 fmt::format("{} \"{}\": Cooling EIR Modifier curve (function of PLR) output is negative warning continues...",
    1168            0 :                             PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
    1169            0 :                             vrf.Name),
    1170            0 :                 vrf.CoolEIRFPLRErrorIndex,
    1171              :                 EIRFPLRModFac,
    1172              :                 EIRFPLRModFac);
    1173            0 :             EIRFPLRModFac = 0.0;
    1174              :         }
    1175              : 
    1176              :         // find part load fraction to calculate RTF
    1177        18818 :         if (vrf.CoolPLFFPLR > 0) {
    1178        18818 :             PartLoadFraction = max(0.7, CurveValue(state, vrf.CoolPLFFPLR, CyclingRatio));
    1179              :         } else {
    1180            0 :             PartLoadFraction = 1.0;
    1181              :         }
    1182        18818 :         VRFRTF = min(1.0, (CyclingRatio / PartLoadFraction));
    1183              : 
    1184        18818 :         vrf.ElecCoolingPower = (vrf.RatedCoolingPower * TotCoolCapTempModFac) * TotCoolEIRTempModFac * EIRFPLRModFac * HREIRAdjustment * VRFRTF;
    1185              :     }
    1186        33935 :     if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) && HeatingPLR > 0.0) {
    1187        15112 :         vrf.OperatingMode = ModeHeatingOnly;
    1188        15112 :         if (HeatingPLR > 1.0) {
    1189          990 :             if (vrf.HeatEIRFPLR2 > 0) {
    1190          990 :                 EIRFPLRModFac = CurveValue(state, vrf.HeatEIRFPLR2, max(vrf.MinPLR, HeatingPLR));
    1191              :             }
    1192              :         } else {
    1193        14122 :             if (vrf.HeatEIRFPLR1 > 0) {
    1194        14122 :                 EIRFPLRModFac = CurveValue(state, vrf.HeatEIRFPLR1, max(vrf.MinPLR, HeatingPLR));
    1195              :             }
    1196              :         }
    1197              : 
    1198        15112 :         if (EIRFPLRModFac < 0.0) {
    1199            0 :             if (vrf.HeatEIRFPLRErrorIndex == 0) {
    1200            0 :                 ShowSevereMessage(state, fmt::format("{} \"{}\":", std::string(cVRFTypes(VRF_HeatPump)), vrf.Name));
    1201            0 :                 ShowContinueError(state, format(" Heating EIR Modifier curve (function of PLR) output is negative ({:.3T}).", EIRFPLRModFac));
    1202            0 :                 ShowContinueError(state, format(" Negative value occurs using a heating Part Load Ratio (PLR) of {:.2T}.", HeatingPLR));
    1203            0 :                 ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
    1204              :             }
    1205            0 :             ShowRecurringWarningErrorAtEnd(
    1206              :                 state,
    1207            0 :                 fmt::format("{} \"{}\": Heating EIR Modifier curve (function of PLR) output is negative warning continues...",
    1208            0 :                             PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
    1209            0 :                             vrf.Name),
    1210            0 :                 vrf.HeatEIRFPLRErrorIndex,
    1211              :                 EIRFPLRModFac,
    1212              :                 EIRFPLRModFac);
    1213            0 :             EIRFPLRModFac = 0.0;
    1214              :         }
    1215              : 
    1216              :         // find part load fraction to calculate RTF
    1217        15112 :         if (vrf.HeatPLFFPLR > 0) {
    1218        15112 :             PartLoadFraction = max(0.7, CurveValue(state, vrf.HeatPLFFPLR, CyclingRatio));
    1219              :         } else {
    1220            0 :             PartLoadFraction = 1.0;
    1221              :         }
    1222        15112 :         VRFRTF = min(1.0, (CyclingRatio / PartLoadFraction));
    1223              : 
    1224        15112 :         vrf.ElecHeatingPower =
    1225        15112 :             (vrf.RatedHeatingPower * TotHeatCapTempModFac) * TotHeatEIRTempModFac * EIRFPLRModFac * HREIRAdjustment * VRFRTF * InputPowerMultiplier;
    1226              :     }
    1227              :     // adjust defrost power based on RTF
    1228        33935 :     vrf.DefrostPower *= VRFRTF;
    1229        33935 :     vrf.VRFCondRTF = VRFRTF;
    1230              : 
    1231              :     // calculate crankcase heater power
    1232        33935 :     if (vrf.MaxOATCCHeater > OutdoorDryBulb) {
    1233              :         // calculate crankcase heater power
    1234         2871 :         vrf.CrankCaseHeaterPower = vrf.CCHeaterPower * (1.0 - VRFRTF);
    1235         2871 :         if (vrf.NumCompressors > 1) {
    1236         2871 :             UpperStageCompressorRatio = (1.0 - vrf.CompressorSizeRatio) / (vrf.NumCompressors - 1);
    1237         4289 :             for (int Stage = 1; Stage <= vrf.NumCompressors - 2; ++Stage) {
    1238         1418 :                 if (vrf.VRFCondPLR < (vrf.CompressorSizeRatio + Stage * UpperStageCompressorRatio)) {
    1239            5 :                     vrf.CrankCaseHeaterPower += vrf.CCHeaterPower;
    1240              :                 }
    1241              :             }
    1242              :         }
    1243              :     } else {
    1244        31064 :         vrf.CrankCaseHeaterPower = 0.0;
    1245              :     }
    1246              : 
    1247        33935 :     CondCapacity = max(vrf.TotalCoolingCapacity, vrf.TotalHeatingCapacity);
    1248        33935 :     CondPower = max(vrf.ElecCoolingPower, vrf.ElecHeatingPower);
    1249        33935 :     if (vrf.ElecCoolingPower > 0.0) {
    1250        18818 :         vrf.QCondenser = CondCapacity + CondPower - vrf.TUHeatingLoad / vrf.PipingCorrectionHeating;
    1251        15117 :     } else if (vrf.ElecHeatingPower > 0.0) {
    1252        15112 :         vrf.QCondenser = -CondCapacity + CondPower + vrf.TUCoolingLoad / vrf.PipingCorrectionCooling;
    1253              :     } else {
    1254            5 :         vrf.QCondenser = 0.0;
    1255              :     }
    1256              : 
    1257        33935 :     if (vrf.CondenserType == DataHeatBalance::RefrigCondenserType::Evap) {
    1258              :         // Calculate basin heater power
    1259            0 :         CalcBasinHeaterPower(state, vrf.BasinHeaterPowerFTempDiff, vrf.basinHeaterSched, vrf.BasinHeaterSetPointTemp, vrf.BasinHeaterPower);
    1260            0 :         vrf.BasinHeaterPower *= (1.0 - VRFRTF);
    1261              : 
    1262              :         // calculate evaporative condenser pump power and water consumption
    1263            0 :         if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && CoolingPLR > 0.0) {
    1264              :             //******************
    1265              :             // WATER CONSUMPTION IN m3 OF WATER FOR DIRECT
    1266              :             // H2O [m3/s] = Delta W[kgWater/kgDryAir]*Mass Flow Air[kgDryAir/s]
    1267              :             //                    /RhoWater [kgWater/m3]
    1268              :             //******************
    1269            0 :             RhoWater = RhoH2O(OutdoorDryBulb);
    1270            0 :             vrf.EvapWaterConsumpRate = (CondInletHumRat - OutdoorHumRat) * CondAirMassFlow / RhoWater * vrf.VRFCondPLR;
    1271            0 :             vrf.EvapCondPumpElecPower = vrf.EvapCondPumpPower * VRFRTF;
    1272              :         }
    1273        33935 :     } else if (vrf.CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    1274              : 
    1275         3282 :         if (CondCapacity > 0.0) {
    1276         3281 :             state.dataHVACVarRefFlow->CondenserWaterMassFlowRate = CondWaterMassFlow;
    1277              :         } else {
    1278            1 :             state.dataHVACVarRefFlow->CondenserWaterMassFlowRate = 0.0;
    1279              :         }
    1280         6564 :         SetComponentFlowRate(
    1281         3282 :             state, state.dataHVACVarRefFlow->CondenserWaterMassFlowRate, vrf.CondenserNodeNum, vrf.CondenserOutletNodeNum, vrf.SourcePlantLoc);
    1282              : 
    1283              :         // should be the same as above just entering this function
    1284              :         //            VRF( VRFCond ).CondenserInletTemp = state.dataLoopNodes->Node(VRF(VRFCond).CondenserNodeNum).Temp;
    1285         3282 :         vrf.WaterCondenserMassFlow = state.dataLoopNodes->Node(vrf.CondenserNodeNum).MassFlowRate;
    1286              : 
    1287         3282 :         CpCond = state.dataPlnt->PlantLoop(vrf.SourcePlantLoc.loopNum).glycol->getSpecificHeat(state, vrf.CondenserInletTemp, RoutineName);
    1288         3282 :         if (CondWaterMassFlow > 0.0) {
    1289         3281 :             CondOutletTemp = vrf.QCondenser / (CondWaterMassFlow * CpCond) + CondInletTemp;
    1290              :         } else {
    1291            1 :             CondOutletTemp = CondInletTemp;
    1292              :         }
    1293         3282 :         vrf.CondenserSideOutletTemp = CondOutletTemp;
    1294              :     }
    1295              : 
    1296              :     // calculate operating COP
    1297        33935 :     if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && CoolingPLR > 0.0) {
    1298        18818 :         if (vrf.ElecCoolingPower != 0.0) {
    1299              :             // this calc should use delivered capacity, not condenser capacity, use VRF(VRFCond)%TUCoolingLoad
    1300        18818 :             vrf.OperatingCoolingCOP =
    1301        18818 :                 (vrf.TotalCoolingCapacity) / (vrf.ElecCoolingPower + vrf.CrankCaseHeaterPower + vrf.EvapCondPumpElecPower + vrf.DefrostPower);
    1302              :         } else {
    1303            0 :             vrf.OperatingCoolingCOP = 0.0;
    1304              :         }
    1305              :     }
    1306        33935 :     if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) && HeatingPLR > 0.0) {
    1307        15112 :         if (vrf.ElecHeatingPower != 0.0) {
    1308              :             // this calc should use delivered capacity, not condenser capacity, use VRF(VRFCond)%TUHeatingLoad
    1309        15112 :             vrf.OperatingHeatingCOP =
    1310        15112 :                 (vrf.TotalHeatingCapacity) / (vrf.ElecHeatingPower + vrf.CrankCaseHeaterPower + vrf.EvapCondPumpElecPower + vrf.DefrostPower);
    1311              :         } else {
    1312            0 :             vrf.OperatingHeatingCOP = 0.0;
    1313              :         }
    1314              :     }
    1315              : 
    1316        33935 :     TotPower = TUParasiticPower + TUFanPower + vrf.ElecHeatingPower + vrf.ElecCoolingPower + vrf.CrankCaseHeaterPower + vrf.EvapCondPumpElecPower +
    1317        33935 :                vrf.DefrostPower;
    1318        33935 :     if (TotPower > 0.0) {
    1319        33935 :         vrf.OperatingCOP = (vrf.TUCoolingLoad + vrf.TUHeatingLoad) / TotPower;
    1320        33935 :         vrf.SCHE = vrf.OperatingCOP * 3.412141633; // see StandardRatings::ConvFromSIToIP
    1321              :     }
    1322              : 
    1323              :     // limit the TU capacity when the condenser is maxed out on capacity
    1324              :     // I think this next line will make the max cap report variable match the coil objects, will probably change the answer though
    1325              :     //  IF(CoolingLoad(VRFCond) .AND. NumTUInCoolingMode .GT. 0 .AND. MaxCoolingCapacity(VRFCond) == MaxCap)THEN
    1326        33935 :     if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && NumTUInCoolingMode > 0) {
    1327              : 
    1328              :         //   IF TU capacity is greater than condenser capacity find maximum allowed TU capacity (i.e., conserve energy)
    1329        18820 :         if (TUCoolingLoad > TotalTUCoolingCapacity) {
    1330          436 :             LimitTUCapacity(state,
    1331              :                             VRFCond,
    1332              :                             NumTUInList,
    1333              :                             TotalTUCoolingCapacity,
    1334          436 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad,
    1335          436 :                             state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond),
    1336              :                             TotalTUHeatingCapacity,
    1337          436 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad,
    1338          436 :                             state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond));
    1339              :         }
    1340        15115 :     } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) && NumTUInHeatingMode > 0) {
    1341              :         //   IF TU capacity is greater than condenser capacity
    1342        15115 :         if (TUHeatingLoad > TotalTUHeatingCapacity) {
    1343          993 :             LimitTUCapacity(state,
    1344              :                             VRFCond,
    1345              :                             NumTUInList,
    1346              :                             TotalTUHeatingCapacity,
    1347          993 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad,
    1348          993 :                             state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond),
    1349              :                             TotalTUCoolingCapacity,
    1350          993 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad,
    1351          993 :                             state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond));
    1352              :         }
    1353              :     } else {
    1354              :     }
    1355              : }
    1356              : 
    1357           13 : void GetVRFInput(EnergyPlusData &state)
    1358              : {
    1359              : 
    1360              :     // SUBROUTINE INFORMATION:
    1361              :     //       AUTHOR         Richard Raustad, FSEC
    1362              :     //       DATE WRITTEN   August 2015
    1363              :     //       MODIFIED       na
    1364              :     //       RE-ENGINEERED  na
    1365              : 
    1366              :     // PURPOSE OF THIS SUBROUTINE:
    1367              :     // Manages GetInput processing and program termination
    1368              : 
    1369              :     // METHODOLOGY EMPLOYED:
    1370              :     // Calls "Get" routines to read in data.
    1371              : 
    1372              :     // SUBROUTINE PARAMETER DEFINITIONS:
    1373              :     static constexpr std::string_view RoutineName("GetVRFInput: "); // include trailing blank space
    1374              : 
    1375              :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
    1376           13 :     bool ErrorsFound(false); // If errors detected in input
    1377              : 
    1378           13 :     GetVRFInputData(state, ErrorsFound);
    1379              : 
    1380           13 :     if (ErrorsFound) {
    1381            0 :         ShowFatalError(
    1382              :             state,
    1383            0 :             format("{}Errors found in getting AirConditioner:VariableRefrigerantFlow system input. Preceding condition(s) causes termination.",
    1384              :                    RoutineName));
    1385              :     }
    1386           13 : }
    1387              : 
    1388           13 : void GetVRFInputData(EnergyPlusData &state, bool &ErrorsFound)
    1389              : {
    1390              : 
    1391              :     // SUBROUTINE INFORMATION:
    1392              :     //       AUTHOR         Richard Raustad, FSEC
    1393              :     //       DATE WRITTEN   August 2010
    1394              :     //       MODIFIED       July 2012, Chandan Sharma - FSEC: Added zone sys avail managers
    1395              :     //       RE-ENGINEERED  na
    1396              : 
    1397              :     // PURPOSE OF THIS SUBROUTINE:
    1398              :     // Obtains input data for VRF systems and stores it in data structures
    1399              : 
    1400              :     using namespace DataLoopNode;
    1401              :     using BranchNodeConnections::SetUpCompSets;
    1402              :     using BranchNodeConnections::TestCompSet;
    1403              :     using Curve::checkCurveIsNormalizedToOne;
    1404              :     using Curve::CurveValue;
    1405              :     using Curve::GetCurveIndex;
    1406              :     using DXCoils::GetDXCoilIndex;
    1407              : 
    1408              :     using DataSizing::AutoSize;
    1409              :     using DXCoils::GetCoilCondenserInletNode;
    1410              :     using DXCoils::GetCoilTypeNum;
    1411              :     using DXCoils::GetDXCoilCapFTCurveIndex;
    1412              :     using DXCoils::GetDXCoilName;
    1413              :     using DXCoils::RatedInletAirTempHeat;
    1414              :     using DXCoils::RatedInletWetBulbTemp;
    1415              :     using DXCoils::RatedOutdoorAirTemp;
    1416              :     using DXCoils::RatedOutdoorAirTempHeat;
    1417              :     using DXCoils::RatedOutdoorWetBulbTempHeat;
    1418              :     using DXCoils::SetDXCoolingCoilData;
    1419              :     using MixedAir::GetOAMixerNodeNumbers;
    1420              :     using NodeInputManager::GetOnlySingleNode;
    1421              :     using OutAirNodeManager::CheckOutAirNodeNumber;
    1422              :     using SingleDuct::GetATMixer;
    1423              :     using WaterManager::SetupTankDemandComponent;
    1424              :     using WaterManager::SetupTankSupplyComponent;
    1425              : 
    1426              :     static constexpr std::string_view RoutineName("GetVRFInput: "); // include trailing blank space
    1427              :     static constexpr std::string_view routineName = "GetVRFInput";
    1428              : 
    1429           13 :     std::string cCurrentModuleObject;
    1430              : 
    1431           13 :     Array1D_int OANodeNums(4); // Node numbers of OA mixer (OA, EA, RA, MA)
    1432              : 
    1433              :     // InputProcessor routines
    1434           13 :     int NumParams = 0; // Number of arguments
    1435           13 :     int NumAlphas = 0; // Number of alpha arguments
    1436           13 :     int NumNums = 0;   // Number of real arguments
    1437              :     int IOStat;        // Status
    1438              :     bool errFlag;      // error flag for mining functions
    1439              :     bool IsNotOK;      // Flag to verify name
    1440              : 
    1441              :     // Compute for allocation
    1442           13 :     int MaxAlphas = 0;
    1443           13 :     int MaxNumbers = 0;
    1444              : 
    1445              :     {
    1446              :         // Terminal Units
    1447              : 
    1448              :         // The number of VRF constant volume TUs (anticipating different types of TU's)
    1449           13 :         int NumVRFCTU = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, "ZoneHVAC:TerminalUnit:VariableRefrigerantFlow");
    1450           13 :         if (NumVRFCTU > 0) {
    1451           13 :             state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(
    1452              :                 state, "ZoneHVAC:TerminalUnit:VariableRefrigerantFlow", NumParams, NumAlphas, NumNums);
    1453           13 :             MaxAlphas = max(MaxAlphas, NumAlphas);
    1454           13 :             MaxNumbers = max(MaxNumbers, NumNums);
    1455              :         }
    1456              : 
    1457           13 :         state.dataHVACVarRefFlow->NumVRFTU = NumVRFCTU;
    1458           13 :         if (state.dataHVACVarRefFlow->NumVRFTU > 0) {
    1459           13 :             state.dataHVACVarRefFlow->VRFTU.allocate(state.dataHVACVarRefFlow->NumVRFTU);
    1460           13 :             state.dataHVACVarRefFlow->CheckEquipName.dimension(state.dataHVACVarRefFlow->NumVRFTU, true);
    1461           13 :             state.dataHVACVarRefFlow->VRFTUNumericFields.allocate(state.dataHVACVarRefFlow->NumVRFTU);
    1462              :         }
    1463              :     }
    1464              : 
    1465              :     {
    1466              :         // VRF AirConditioners
    1467              : 
    1468           26 :         state.dataHVACVarRefFlow->NumVRFCond_SysCurve =
    1469           13 :             state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, "AirConditioner:VariableRefrigerantFlow");
    1470           13 :         if (state.dataHVACVarRefFlow->NumVRFCond_SysCurve > 0) {
    1471            9 :             state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(
    1472              :                 state, "AirConditioner:VariableRefrigerantFlow", NumParams, NumAlphas, NumNums);
    1473            9 :             MaxAlphas = max(MaxAlphas, NumAlphas);
    1474            9 :             MaxNumbers = max(MaxNumbers, NumNums);
    1475              :         }
    1476              : 
    1477           26 :         state.dataHVACVarRefFlow->NumVRFCond_FluidTCtrl_HP =
    1478           13 :             state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, "AirConditioner:VariableRefrigerantFlow:FluidTemperatureControl");
    1479           13 :         if (state.dataHVACVarRefFlow->NumVRFCond_FluidTCtrl_HP > 0) {
    1480            3 :             state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(
    1481              :                 state, "AirConditioner:VariableRefrigerantFlow:FluidTemperatureControl", NumParams, NumAlphas, NumNums);
    1482            3 :             MaxAlphas = max(MaxAlphas, NumAlphas);
    1483            3 :             MaxNumbers = max(MaxNumbers, NumNums);
    1484              :         }
    1485              : 
    1486           26 :         state.dataHVACVarRefFlow->NumVRFCond_FluidTCtrl_HR =
    1487           13 :             state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, "AirConditioner:VariableRefrigerantFlow:FluidTemperatureControl:HR");
    1488           13 :         if (state.dataHVACVarRefFlow->NumVRFCond_FluidTCtrl_HR > 0) {
    1489            1 :             state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(
    1490              :                 state, "AirConditioner:VariableRefrigerantFlow:FluidTemperatureControl:HR", NumParams, NumAlphas, NumNums);
    1491            1 :             MaxAlphas = max(MaxAlphas, NumAlphas);
    1492            1 :             MaxNumbers = max(MaxNumbers, NumNums);
    1493              :         }
    1494              : 
    1495           13 :         state.dataHVACVarRefFlow->NumVRFCond = state.dataHVACVarRefFlow->NumVRFCond_SysCurve + state.dataHVACVarRefFlow->NumVRFCond_FluidTCtrl_HP +
    1496           13 :                                                state.dataHVACVarRefFlow->NumVRFCond_FluidTCtrl_HR;
    1497              : 
    1498           13 :         if (state.dataHVACVarRefFlow->NumVRFCond > 0) {
    1499           13 :             state.dataHVACVarRefFlow->VRF.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    1500           13 :             state.dataHVACVarRefFlow->VrfUniqueNames.reserve(static_cast<unsigned>(state.dataHVACVarRefFlow->NumVRFCond));
    1501           13 :             state.dataHVACVarRefFlow->MaxCoolingCapacity.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    1502           13 :             state.dataHVACVarRefFlow->MaxHeatingCapacity.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    1503           13 :             state.dataHVACVarRefFlow->CoolCombinationRatio.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    1504           13 :             state.dataHVACVarRefFlow->HeatCombinationRatio.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    1505           13 :             state.dataHVACVarRefFlow->MaxCoolingCapacity = Constant::MaxCap;
    1506           13 :             state.dataHVACVarRefFlow->MaxHeatingCapacity = Constant::MaxCap;
    1507           13 :             state.dataHVACVarRefFlow->CoolCombinationRatio = 1.0;
    1508           13 :             state.dataHVACVarRefFlow->HeatCombinationRatio = 1.0;
    1509              :         }
    1510              :     }
    1511              : 
    1512              :     {
    1513              :         // ZoneTerminalUnitList
    1514              : 
    1515           13 :         state.dataHVACVarRefFlow->NumVRFTULists = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, "ZoneTerminalUnitList");
    1516           13 :         if (state.dataHVACVarRefFlow->NumVRFTULists > 0) {
    1517           13 :             state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(state, "ZoneTerminalUnitList", NumParams, NumAlphas, NumNums);
    1518           13 :             MaxAlphas = max(MaxAlphas, NumAlphas);
    1519           13 :             MaxNumbers = max(MaxNumbers, NumNums);
    1520              : 
    1521           13 :             state.dataHVACVarRefFlow->TerminalUnitList.allocate(state.dataHVACVarRefFlow->NumVRFTULists);
    1522              :         }
    1523              :     }
    1524              : 
    1525           13 :     Array1D_string cAlphaFieldNames;
    1526           13 :     cAlphaFieldNames.allocate(MaxAlphas);
    1527           13 :     Array1D_string cAlphaArgs;
    1528           13 :     cAlphaArgs.allocate(MaxAlphas);
    1529           13 :     Array1D_bool lAlphaFieldBlanks;
    1530           13 :     lAlphaFieldBlanks.dimension(MaxAlphas, false);
    1531              : 
    1532           13 :     Array1D_string cNumericFieldNames;
    1533           13 :     cNumericFieldNames.allocate(MaxNumbers);
    1534           13 :     Array1D<Real64> rNumericArgs;
    1535           13 :     rNumericArgs.dimension(MaxNumbers, 0.0);
    1536           13 :     Array1D_bool lNumericFieldBlanks;
    1537           13 :     lNumericFieldBlanks.dimension(MaxNumbers, false);
    1538              : 
    1539              :     // read all terminal unit list objects
    1540           13 :     cCurrentModuleObject = "ZoneTerminalUnitList";
    1541           27 :     for (int TUListNum = 1; TUListNum <= state.dataHVACVarRefFlow->NumVRFTULists; ++TUListNum) {
    1542           14 :         state.dataInputProcessing->inputProcessor->getObjectItem(state,
    1543              :                                                                  cCurrentModuleObject,
    1544              :                                                                  TUListNum,
    1545              :                                                                  cAlphaArgs,
    1546              :                                                                  NumAlphas,
    1547              :                                                                  rNumericArgs,
    1548              :                                                                  NumNums,
    1549              :                                                                  IOStat,
    1550              :                                                                  lNumericFieldBlanks,
    1551              :                                                                  lAlphaFieldBlanks,
    1552              :                                                                  cAlphaFieldNames,
    1553              :                                                                  cNumericFieldNames);
    1554           14 :         Util::IsNameEmpty(state, cAlphaArgs(1), cCurrentModuleObject, ErrorsFound);
    1555              : 
    1556           14 :         auto &thisTUList = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum);
    1557           14 :         thisTUList.Name = cAlphaArgs(1);
    1558           14 :         thisTUList.NumTUInList = NumAlphas - 1;
    1559           14 :         thisTUList.ZoneTUPtr.allocate(thisTUList.NumTUInList);
    1560           14 :         thisTUList.ZoneTUName.allocate(thisTUList.NumTUInList);
    1561           14 :         thisTUList.IsSimulated.allocate(thisTUList.NumTUInList);
    1562           14 :         thisTUList.TotalCoolLoad.allocate(thisTUList.NumTUInList);
    1563           14 :         thisTUList.TotalHeatLoad.allocate(thisTUList.NumTUInList);
    1564           14 :         thisTUList.CoolingCoilPresent.allocate(thisTUList.NumTUInList);
    1565           14 :         thisTUList.HeatingCoilPresent.allocate(thisTUList.NumTUInList);
    1566           14 :         thisTUList.TerminalUnitNotSizedYet.allocate(thisTUList.NumTUInList);
    1567           14 :         thisTUList.HRHeatRequest.allocate(thisTUList.NumTUInList);
    1568           14 :         thisTUList.HRCoolRequest.allocate(thisTUList.NumTUInList);
    1569           14 :         thisTUList.CoolingCoilAvailable.allocate(thisTUList.NumTUInList);
    1570           14 :         thisTUList.HeatingCoilAvailable.allocate(thisTUList.NumTUInList);
    1571           14 :         thisTUList.coolingCoilAvailScheds.allocate(thisTUList.NumTUInList);
    1572           14 :         thisTUList.heatingCoilAvailScheds.allocate(thisTUList.NumTUInList);
    1573           14 :         thisTUList.ZoneTUPtr = 0;
    1574           14 :         thisTUList.IsSimulated = false;
    1575           14 :         thisTUList.TotalCoolLoad = 0.0;
    1576           14 :         thisTUList.TotalHeatLoad = 0.0;
    1577           14 :         thisTUList.CoolingCoilPresent = true;
    1578           14 :         thisTUList.HeatingCoilPresent = true;
    1579           14 :         thisTUList.TerminalUnitNotSizedYet = true;
    1580           14 :         thisTUList.HRHeatRequest = false;
    1581           14 :         thisTUList.HRCoolRequest = false;
    1582           14 :         thisTUList.CoolingCoilAvailable = false;
    1583           14 :         thisTUList.HeatingCoilAvailable = false;
    1584           14 :         thisTUList.coolingCoilAvailScheds = nullptr;
    1585           14 :         thisTUList.heatingCoilAvailScheds = nullptr;
    1586              : 
    1587           76 :         for (int TUNum = 1; TUNum <= thisTUList.NumTUInList; ++TUNum) {
    1588           62 :             thisTUList.ZoneTUName(TUNum) = cAlphaArgs(TUNum + 1);
    1589              :         }
    1590              :     }
    1591              : 
    1592           20 :     auto checkCurveMinMaxOutput = [&state](int CurveIndex) -> std::array<Real64, 4> {
    1593           20 :         Real64 MinCurveVal = 999.0;
    1594           20 :         Real64 MaxCurveVal = -999.0;
    1595           20 :         Real64 MinCurvePLR = 0.0;
    1596           20 :         Real64 MaxCurvePLR = 1.0;
    1597              : 
    1598         2040 :         for (int i = 0; i <= 100; ++i) { // 0 to 1.0 with 0.01 increment
    1599         2020 :             const Real64 CurveInput = i / 100.0;
    1600         2020 :             Real64 CurveVal = CurveValue(state, CurveIndex, CurveInput);
    1601         2020 :             if (CurveVal < MinCurveVal) {
    1602           20 :                 MinCurveVal = CurveVal;
    1603           20 :                 MinCurvePLR = CurveInput;
    1604              :             }
    1605         2020 :             if (CurveVal > MaxCurveVal) {
    1606         2020 :                 MaxCurveVal = CurveVal;
    1607         2020 :                 MaxCurvePLR = CurveInput;
    1608              :             }
    1609              :         }
    1610           20 :         return {MinCurvePLR, MinCurveVal, MaxCurvePLR, MaxCurveVal};
    1611           13 :     };
    1612              : 
    1613              :     // read all VRF condenser objects: Algorithm Type 1_system curve based model
    1614           13 :     cCurrentModuleObject = "AirConditioner:VariableRefrigerantFlow";
    1615           23 :     for (int VRFNum = 1; VRFNum <= state.dataHVACVarRefFlow->NumVRFCond_SysCurve; ++VRFNum) {
    1616           10 :         state.dataInputProcessing->inputProcessor->getObjectItem(state,
    1617              :                                                                  cCurrentModuleObject,
    1618              :                                                                  VRFNum,
    1619              :                                                                  cAlphaArgs,
    1620              :                                                                  NumAlphas,
    1621              :                                                                  rNumericArgs,
    1622              :                                                                  NumNums,
    1623              :                                                                  IOStat,
    1624              :                                                                  lNumericFieldBlanks,
    1625              :                                                                  lAlphaFieldBlanks,
    1626              :                                                                  cAlphaFieldNames,
    1627              :                                                                  cNumericFieldNames);
    1628              : 
    1629           10 :         ErrorObjectHeader eoh{routineName, cCurrentModuleObject, cAlphaArgs(1)};
    1630           10 :         GlobalNames::VerifyUniqueInterObjectName(
    1631           20 :             state, state.dataHVACVarRefFlow->VrfUniqueNames, cAlphaArgs(1), cCurrentModuleObject, cAlphaFieldNames(1), ErrorsFound);
    1632              : 
    1633           10 :         auto &thisVrfSys = state.dataHVACVarRefFlow->VRF(VRFNum);
    1634           10 :         thisVrfSys.Name = cAlphaArgs(1);
    1635           10 :         thisVrfSys.VRFSystemTypeNum = VRF_HeatPump;
    1636           10 :         thisVrfSys.VRFAlgorithmType = AlgorithmType::SysCurve;
    1637              : 
    1638           10 :         if (lAlphaFieldBlanks(2)) {
    1639            2 :             thisVrfSys.availSched = Sched::GetScheduleAlwaysOn(state);
    1640            8 :         } else if ((thisVrfSys.availSched = Sched::GetSchedule(state, cAlphaArgs(2))) == nullptr) {
    1641            0 :             ShowSevereItemNotFound(state, eoh, cAlphaFieldNames(2), cAlphaArgs(2));
    1642            0 :             ErrorsFound = true;
    1643              :         }
    1644              : 
    1645           10 :         thisVrfSys.CoolingCapacity = rNumericArgs(1);
    1646           10 :         thisVrfSys.CoolingCOP = rNumericArgs(2);
    1647           10 :         thisVrfSys.MinOATCooling = rNumericArgs(3);
    1648           10 :         thisVrfSys.MaxOATCooling = rNumericArgs(4);
    1649              : 
    1650           10 :         thisVrfSys.CoolCapFT = GetCurveIndex(state, cAlphaArgs(3));
    1651           10 :         if (thisVrfSys.CoolCapFT > 0) {
    1652              :             // Verify Curve Object, only legal type is biquadratic
    1653           20 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1654              :                                                  thisVrfSys.CoolCapFT, // Curve index
    1655              :                                                  {2},                  // Valid dimensions
    1656              :                                                  RoutineName,          // Routine name
    1657              :                                                  cCurrentModuleObject, // Object Type
    1658              :                                                  thisVrfSys.Name,      // Object Name
    1659           10 :                                                  cAlphaFieldNames(3)); // Field Name
    1660              : 
    1661           10 :             if (!ErrorsFound) {
    1662           10 :                 checkCurveIsNormalizedToOne(state,
    1663           30 :                                             std::string{RoutineName} + cCurrentModuleObject,
    1664           10 :                                             thisVrfSys.Name,
    1665              :                                             thisVrfSys.CoolCapFT,
    1666           10 :                                             cAlphaFieldNames(3),
    1667           10 :                                             cAlphaArgs(3),
    1668              :                                             RatedInletWetBulbTemp,
    1669              :                                             RatedOutdoorAirTemp);
    1670              :             }
    1671              :         }
    1672              : 
    1673           10 :         thisVrfSys.CoolBoundaryCurvePtr = GetCurveIndex(state, cAlphaArgs(4));
    1674           10 :         if (thisVrfSys.CoolBoundaryCurvePtr > 0) {
    1675              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1676           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1677              :                                                  thisVrfSys.CoolBoundaryCurvePtr, // Curve index
    1678              :                                                  {1},                             // Valid dimensions
    1679              :                                                  RoutineName,                     // Routine name
    1680              :                                                  cCurrentModuleObject,            // Object Type
    1681              :                                                  thisVrfSys.Name,                 // Object Name
    1682           10 :                                                  cAlphaFieldNames(4));            // Field Name
    1683              :         }
    1684              : 
    1685           10 :         thisVrfSys.CoolCapFTHi = GetCurveIndex(state, cAlphaArgs(5));
    1686           10 :         if (thisVrfSys.CoolCapFTHi > 0) {
    1687              :             // Verify Curve Object, only legal type is biquadratic
    1688           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1689              :                                                  thisVrfSys.CoolCapFTHi, // Curve index
    1690              :                                                  {2},                    // Valid dimensions
    1691              :                                                  RoutineName,            // Routine name
    1692              :                                                  cCurrentModuleObject,   // Object Type
    1693              :                                                  thisVrfSys.Name,        // Object Name
    1694           10 :                                                  cAlphaFieldNames(5));   // Field Name
    1695              :         }
    1696              : 
    1697           10 :         thisVrfSys.CoolEIRFT = GetCurveIndex(state, cAlphaArgs(6));
    1698           10 :         if (thisVrfSys.CoolEIRFT > 0) {
    1699              :             // Verify Curve Object, only legal type is biquadratic
    1700           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1701              :                                                  thisVrfSys.CoolEIRFT, // Curve index
    1702              :                                                  {2},                  // Valid dimensions
    1703              :                                                  RoutineName,          // Routine name
    1704              :                                                  cCurrentModuleObject, // Object Type
    1705              :                                                  thisVrfSys.Name,      // Object Name
    1706           10 :                                                  cAlphaFieldNames(6)); // Field Name
    1707              :         }
    1708              : 
    1709           10 :         thisVrfSys.EIRCoolBoundaryCurvePtr = GetCurveIndex(state, cAlphaArgs(7));
    1710           10 :         if (thisVrfSys.EIRCoolBoundaryCurvePtr > 0) {
    1711              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1712           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1713              :                                                  thisVrfSys.EIRCoolBoundaryCurvePtr, // Curve index
    1714              :                                                  {1},                                // Valid dimensions
    1715              :                                                  RoutineName,                        // Routine name
    1716              :                                                  cCurrentModuleObject,               // Object Type
    1717              :                                                  thisVrfSys.Name,                    // Object Name
    1718           10 :                                                  cAlphaFieldNames(7));               // Field Name
    1719              :         }
    1720              : 
    1721           10 :         thisVrfSys.CoolEIRFTHi = GetCurveIndex(state, cAlphaArgs(8));
    1722           10 :         if (thisVrfSys.CoolEIRFTHi > 0) {
    1723              :             // Verify Curve Object, only legal type is biquadratic
    1724           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1725              :                                                  thisVrfSys.CoolEIRFTHi, // Curve index
    1726              :                                                  {2},                    // Valid dimensions
    1727              :                                                  RoutineName,            // Routine name
    1728              :                                                  cCurrentModuleObject,   // Object Type
    1729              :                                                  thisVrfSys.Name,        // Object Name
    1730           10 :                                                  cAlphaFieldNames(8));   // Field Name
    1731              :         }
    1732              : 
    1733           10 :         thisVrfSys.CoolEIRFPLR1 = GetCurveIndex(state, cAlphaArgs(9));
    1734           10 :         if (thisVrfSys.CoolEIRFPLR1 > 0) {
    1735              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1736           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1737              :                                                  thisVrfSys.CoolEIRFPLR1, // Curve index
    1738              :                                                  {1},                     // Valid dimensions
    1739              :                                                  RoutineName,             // Routine name
    1740              :                                                  cCurrentModuleObject,    // Object Type
    1741              :                                                  thisVrfSys.Name,         // Object Name
    1742           10 :                                                  cAlphaFieldNames(9));    // Field Name
    1743              :         }
    1744              : 
    1745           10 :         thisVrfSys.CoolEIRFPLR2 = GetCurveIndex(state, cAlphaArgs(10));
    1746           10 :         if (thisVrfSys.CoolEIRFPLR2 > 0) {
    1747              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1748           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1749              :                                                  thisVrfSys.CoolEIRFPLR2, // Curve index
    1750              :                                                  {1},                     // Valid dimensions
    1751              :                                                  RoutineName,             // Routine name
    1752              :                                                  cCurrentModuleObject,    // Object Type
    1753              :                                                  thisVrfSys.Name,         // Object Name
    1754           10 :                                                  cAlphaFieldNames(10));   // Field Name
    1755              :         }
    1756              : 
    1757           10 :         thisVrfSys.CoolCombRatioPTR = GetCurveIndex(state, cAlphaArgs(11));
    1758           10 :         if (thisVrfSys.CoolCombRatioPTR > 0) {
    1759              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1760           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1761              :                                                  thisVrfSys.CoolCombRatioPTR, // Curve index
    1762              :                                                  {1},                         // Valid dimensions
    1763              :                                                  RoutineName,                 // Routine name
    1764              :                                                  cCurrentModuleObject,        // Object Type
    1765              :                                                  thisVrfSys.Name,             // Object Name
    1766           10 :                                                  cAlphaFieldNames(11));       // Field Name
    1767              :         }
    1768              : 
    1769           10 :         thisVrfSys.CoolPLFFPLR = GetCurveIndex(state, cAlphaArgs(12));
    1770           10 :         if (thisVrfSys.CoolPLFFPLR > 0) {
    1771              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1772           20 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1773              :                                                  thisVrfSys.CoolPLFFPLR, // Curve index
    1774              :                                                  {1},                    // Valid dimensions
    1775              :                                                  RoutineName,            // Routine name
    1776              :                                                  cCurrentModuleObject,   // Object Type
    1777              :                                                  thisVrfSys.Name,        // Object Name
    1778           10 :                                                  cAlphaFieldNames(12));  // Field Name
    1779           10 :             if (!ErrorsFound) {
    1780              :                 //     Test PLF curve minimum and maximum. Cap if less than 0.7 or greater than 1.0.
    1781           10 :                 auto [MinCurvePLR, MinCurveVal, MaxCurvePLR, MaxCurveVal] = checkCurveMinMaxOutput(thisVrfSys.CoolPLFFPLR);
    1782              : 
    1783           10 :                 if (MinCurveVal < 0.7) {
    1784            0 :                     ShowWarningError(state, format("{}{}=\"{}\", invalid", RoutineName, cCurrentModuleObject, thisVrfSys.Name));
    1785            0 :                     ShowContinueError(state, format("...{}=\"{}\" has out of range values.", cAlphaFieldNames(12), cAlphaArgs(12)));
    1786            0 :                     ShowContinueError(state,
    1787            0 :                                       format("...Curve minimum must be >= 0.7, curve min at PLR = {:.2T} is {:.3T}", MinCurvePLR, MinCurveVal));
    1788            0 :                     ShowContinueError(state, "...Setting curve minimum to 0.7 and simulation continues.");
    1789            0 :                     Curve::SetCurveOutputMinValue(state, thisVrfSys.CoolPLFFPLR, ErrorsFound, 0.7);
    1790              :                 }
    1791              : 
    1792           10 :                 if (MaxCurveVal > 1.0) {
    1793            0 :                     ShowWarningError(state, format("{}{}=\"{}\", invalid", RoutineName, cCurrentModuleObject, thisVrfSys.Name));
    1794            0 :                     ShowContinueError(state, format("...{}=\"{}\" has out of range values.", cAlphaFieldNames(12), cAlphaArgs(12)));
    1795            0 :                     ShowContinueError(state,
    1796            0 :                                       format("...Curve maximum must be <= 1.0, curve max at PLR = {:.2T} is {:.3T}", MaxCurvePLR, MaxCurveVal));
    1797            0 :                     ShowContinueError(state, "...Setting curve maximum to 1.0 and simulation continues.");
    1798            0 :                     Curve::SetCurveOutputMaxValue(state, thisVrfSys.CoolPLFFPLR, ErrorsFound, 1.0);
    1799              :                 }
    1800              :             }
    1801              :         }
    1802              : 
    1803           10 :         thisVrfSys.HeatingCapacity = rNumericArgs(5);
    1804           10 :         thisVrfSys.HeatingCapacitySizeRatio = rNumericArgs(6);
    1805           10 :         if (!lNumericFieldBlanks(6) && thisVrfSys.HeatingCapacity == AutoSize) {
    1806            2 :             thisVrfSys.LockHeatingCapacity = true;
    1807              :         }
    1808           10 :         thisVrfSys.HeatingCOP = rNumericArgs(7);
    1809           10 :         thisVrfSys.MinOATHeating = rNumericArgs(8);
    1810           10 :         thisVrfSys.MaxOATHeating = rNumericArgs(9);
    1811           10 :         if (thisVrfSys.MinOATHeating >= thisVrfSys.MaxOATHeating) {
    1812            0 :             ShowSevereError(state, format("{}, \"{}\"", cCurrentModuleObject, thisVrfSys.Name));
    1813            0 :             ShowContinueError(state,
    1814            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    1815              :                                      cNumericFieldNames(8),
    1816            0 :                                      thisVrfSys.MinOATHeating,
    1817            0 :                                      thisVrfSys.MaxOATHeating));
    1818            0 :             ErrorsFound = true;
    1819              :         }
    1820              : 
    1821           10 :         thisVrfSys.HeatCapFT = GetCurveIndex(state, cAlphaArgs(13));
    1822           10 :         if (thisVrfSys.HeatCapFT > 0) {
    1823              :             // Verify Curve Object, only legal type is biquadratic
    1824           20 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1825              :                                                  thisVrfSys.HeatCapFT,  // Curve index
    1826              :                                                  {2},                   // Valid dimensions
    1827              :                                                  RoutineName,           // Routine name
    1828              :                                                  cCurrentModuleObject,  // Object Type
    1829              :                                                  thisVrfSys.Name,       // Object Name
    1830           10 :                                                  cAlphaFieldNames(13)); // Field Name
    1831              : 
    1832           10 :             if (!ErrorsFound) {
    1833           10 :                 if (Util::SameString(cAlphaArgs(19), "WETBULBTEMPERATURE")) {
    1834            9 :                     checkCurveIsNormalizedToOne(state,
    1835           27 :                                                 std::string{RoutineName} + cCurrentModuleObject,
    1836            9 :                                                 thisVrfSys.Name,
    1837              :                                                 thisVrfSys.HeatCapFT,
    1838            9 :                                                 cAlphaFieldNames(13),
    1839            9 :                                                 cAlphaArgs(13),
    1840              :                                                 RatedInletAirTempHeat,
    1841              :                                                 RatedOutdoorWetBulbTempHeat);
    1842            1 :                 } else if (Util::SameString(cAlphaArgs(19), "DRYBULBTEMPERATURE")) {
    1843            1 :                     checkCurveIsNormalizedToOne(state,
    1844            3 :                                                 std::string{RoutineName} + cCurrentModuleObject,
    1845            1 :                                                 thisVrfSys.Name,
    1846              :                                                 thisVrfSys.HeatCapFT,
    1847            1 :                                                 cAlphaFieldNames(13),
    1848            1 :                                                 cAlphaArgs(13),
    1849              :                                                 RatedInletAirTempHeat,
    1850              :                                                 RatedOutdoorAirTempHeat);
    1851              :                 }
    1852              :             }
    1853              :         }
    1854              : 
    1855           10 :         thisVrfSys.HeatBoundaryCurvePtr = GetCurveIndex(state, cAlphaArgs(14));
    1856           10 :         if (thisVrfSys.HeatBoundaryCurvePtr > 0) {
    1857              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1858           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1859              :                                                  thisVrfSys.HeatBoundaryCurvePtr, // Curve index
    1860              :                                                  {1},                             // Valid dimensions
    1861              :                                                  RoutineName,                     // Routine name
    1862              :                                                  cCurrentModuleObject,            // Object Type
    1863              :                                                  thisVrfSys.Name,                 // Object Name
    1864           10 :                                                  cAlphaFieldNames(14));           // Field Name
    1865              :         }
    1866              : 
    1867           10 :         thisVrfSys.HeatCapFTHi = GetCurveIndex(state, cAlphaArgs(15));
    1868           10 :         if (thisVrfSys.HeatCapFTHi > 0) {
    1869              :             // Verify Curve Object, only legal type is biquadratic
    1870           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1871              :                                                  thisVrfSys.HeatCapFTHi, // Curve index
    1872              :                                                  {2},                    // Valid dimensions
    1873              :                                                  RoutineName,            // Routine name
    1874              :                                                  cCurrentModuleObject,   // Object Type
    1875              :                                                  thisVrfSys.Name,        // Object Name
    1876           10 :                                                  cAlphaFieldNames(15));  // Field Name
    1877              :         }
    1878              : 
    1879           10 :         thisVrfSys.HeatEIRFT = GetCurveIndex(state, cAlphaArgs(16));
    1880           10 :         if (thisVrfSys.HeatEIRFT > 0) {
    1881              :             // Verify Curve Object, only legal type is biquadratic
    1882           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1883              :                                                  thisVrfSys.HeatEIRFT,  // Curve index
    1884              :                                                  {2},                   // Valid dimensions
    1885              :                                                  RoutineName,           // Routine name
    1886              :                                                  cCurrentModuleObject,  // Object Type
    1887              :                                                  thisVrfSys.Name,       // Object Name
    1888           10 :                                                  cAlphaFieldNames(16)); // Field Name
    1889              :         }
    1890              : 
    1891           10 :         thisVrfSys.EIRHeatBoundaryCurvePtr = GetCurveIndex(state, cAlphaArgs(17));
    1892           10 :         if (thisVrfSys.EIRHeatBoundaryCurvePtr > 0) {
    1893              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1894           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1895              :                                                  thisVrfSys.EIRHeatBoundaryCurvePtr, // Curve index
    1896              :                                                  {1},                                // Valid dimensions
    1897              :                                                  RoutineName,                        // Routine name
    1898              :                                                  cCurrentModuleObject,               // Object Type
    1899              :                                                  thisVrfSys.Name,                    // Object Name
    1900           10 :                                                  cAlphaFieldNames(17));              // Field Name
    1901              :         }
    1902              : 
    1903           10 :         thisVrfSys.HeatEIRFTHi = GetCurveIndex(state, cAlphaArgs(18));
    1904           10 :         if (thisVrfSys.HeatEIRFTHi > 0) {
    1905              :             // Verify Curve Object, only legal type is biquadratic
    1906           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1907              :                                                  thisVrfSys.HeatEIRFTHi, // Curve index
    1908              :                                                  {2},                    // Valid dimensions
    1909              :                                                  RoutineName,            // Routine name
    1910              :                                                  cCurrentModuleObject,   // Object Type
    1911              :                                                  thisVrfSys.Name,        // Object Name
    1912           10 :                                                  cAlphaFieldNames(18));  // Field Name
    1913              :         }
    1914              : 
    1915           10 :         if (Util::SameString(cAlphaArgs(19), "WETBULBTEMPERATURE")) {
    1916            9 :             thisVrfSys.HeatingPerformanceOATType = HVAC::OATType::WetBulb;
    1917            1 :         } else if (Util::SameString(cAlphaArgs(19), "DRYBULBTEMPERATURE")) {
    1918            1 :             thisVrfSys.HeatingPerformanceOATType = HVAC::OATType::DryBulb;
    1919              :         } else {
    1920            0 :             ShowSevereError(
    1921              :                 state,
    1922            0 :                 format(
    1923            0 :                     "{}, \"{}\" illegal {} input for this object = {}", cCurrentModuleObject, thisVrfSys.Name, cAlphaFieldNames(19), cAlphaArgs(19)));
    1924            0 :             ShowContinueError(state, "... input must be WETBULBTEMPERATURE or DRYBULBTEMPERATURE.");
    1925            0 :             ErrorsFound = true;
    1926              :         }
    1927              : 
    1928           10 :         thisVrfSys.HeatEIRFPLR1 = GetCurveIndex(state, cAlphaArgs(20));
    1929           10 :         if (thisVrfSys.HeatEIRFPLR1 > 0) {
    1930              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1931           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1932              :                                                  thisVrfSys.HeatEIRFPLR1, // Curve index
    1933              :                                                  {1},                     // Valid dimensions
    1934              :                                                  RoutineName,             // Routine name
    1935              :                                                  cCurrentModuleObject,    // Object Type
    1936              :                                                  thisVrfSys.Name,         // Object Name
    1937           10 :                                                  cAlphaFieldNames(20));   // Field Name
    1938              :         }
    1939              : 
    1940           10 :         thisVrfSys.HeatEIRFPLR2 = GetCurveIndex(state, cAlphaArgs(21));
    1941           10 :         if (thisVrfSys.HeatEIRFPLR2 > 0) {
    1942              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1943           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1944              :                                                  thisVrfSys.HeatEIRFPLR2, // Curve index
    1945              :                                                  {1},                     // Valid dimensions
    1946              :                                                  RoutineName,             // Routine name
    1947              :                                                  cCurrentModuleObject,    // Object Type
    1948              :                                                  thisVrfSys.Name,         // Object Name
    1949           10 :                                                  cAlphaFieldNames(21));   // Field Name
    1950              :         }
    1951              : 
    1952           10 :         thisVrfSys.HeatCombRatioPTR = GetCurveIndex(state, cAlphaArgs(22));
    1953           10 :         if (thisVrfSys.HeatCombRatioPTR > 0) {
    1954              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1955           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1956              :                                                  thisVrfSys.HeatCombRatioPTR, // Curve index
    1957              :                                                  {1},                         // Valid dimensions
    1958              :                                                  RoutineName,                 // Routine name
    1959              :                                                  cCurrentModuleObject,        // Object Type
    1960              :                                                  thisVrfSys.Name,             // Object Name
    1961           10 :                                                  cAlphaFieldNames(22));       // Field Name
    1962              :         }
    1963           10 :         thisVrfSys.HeatPLFFPLR = GetCurveIndex(state, cAlphaArgs(23));
    1964           10 :         if (thisVrfSys.HeatPLFFPLR > 0) {
    1965              :             // Verify Curve Object, only legal type is linear, quadratic, or cubic
    1966           20 :             ErrorsFound |= Curve::CheckCurveDims(state,
    1967              :                                                  thisVrfSys.HeatPLFFPLR, // Curve index
    1968              :                                                  {1},                    // Valid dimensions
    1969              :                                                  RoutineName,            // Routine name
    1970              :                                                  cCurrentModuleObject,   // Object Type
    1971              :                                                  thisVrfSys.Name,        // Object Name
    1972           10 :                                                  cAlphaFieldNames(23));  // Field Name
    1973              : 
    1974           10 :             if (!ErrorsFound) {
    1975           10 :                 auto [MinCurvePLR, MinCurveVal, MaxCurvePLR, MaxCurveVal] = checkCurveMinMaxOutput(thisVrfSys.HeatPLFFPLR);
    1976              : 
    1977           10 :                 if (MinCurveVal < 0.7) {
    1978            0 :                     ShowWarningError(state, format("{}{}=\"{}\", invalid", RoutineName, cCurrentModuleObject, thisVrfSys.Name));
    1979            0 :                     ShowContinueError(state, format("...{}=\"{}\" has out of range values.", cAlphaFieldNames(23), cAlphaArgs(23)));
    1980            0 :                     ShowContinueError(state,
    1981            0 :                                       format("...Curve minimum must be >= 0.7, curve min at PLR = {:.2T} is {:.3T}", MinCurvePLR, MinCurveVal));
    1982            0 :                     ShowContinueError(state, "...Setting curve minimum to 0.7 and simulation continues.");
    1983            0 :                     Curve::SetCurveOutputMinValue(state, thisVrfSys.HeatPLFFPLR, ErrorsFound, 0.7);
    1984              :                 }
    1985              : 
    1986           10 :                 if (MaxCurveVal > 1.0) {
    1987            0 :                     ShowWarningError(state, format("{}{}=\"{}\", invalid", RoutineName, cCurrentModuleObject, thisVrfSys.Name));
    1988            0 :                     ShowContinueError(state, format("...{}=\"{}\" has out of range values.", cAlphaFieldNames(23), cAlphaArgs(23)));
    1989            0 :                     ShowContinueError(state,
    1990            0 :                                       format("...Curve maximum must be <= 1.0, curve max at PLR = {:.2T} is {:.3T}", MaxCurvePLR, MaxCurveVal));
    1991            0 :                     ShowContinueError(state, "...Setting curve maximum to 1.0 and simulation continues.");
    1992            0 :                     Curve::SetCurveOutputMaxValue(state, thisVrfSys.HeatPLFFPLR, ErrorsFound, 1.0);
    1993              :                 }
    1994              :             }
    1995              :         }
    1996              : 
    1997           10 :         thisVrfSys.MinPLR = rNumericArgs(10);
    1998           10 :         Real64 minEIRfLowPLRXInput = 0.0;
    1999           10 :         Real64 maxEIRfLowPLRXInput = 0.0;
    2000              : 
    2001           10 :         if (thisVrfSys.CoolEIRFPLR1 > 0) {
    2002           10 :             Curve::GetCurveMinMaxValues(state, thisVrfSys.CoolEIRFPLR1, minEIRfLowPLRXInput, maxEIRfLowPLRXInput);
    2003           10 :             if (minEIRfLowPLRXInput > thisVrfSys.MinPLR) {
    2004            0 :                 ShowWarningError(state, format("{}{}=\"{}\", invalid", RoutineName, cCurrentModuleObject, thisVrfSys.Name));
    2005            0 :                 ShowContinueError(state, format("...{} = {} has out of range value.", cAlphaFieldNames(9), cAlphaArgs(9)));
    2006            0 :                 ShowContinueError(state,
    2007            0 :                                   format("...Curve minimum value of X = {:.3T} must be <= Minimum Heat Pump Part-Load Ratio = {:.3T}.",
    2008              :                                          minEIRfLowPLRXInput,
    2009            0 :                                          thisVrfSys.MinPLR));
    2010            0 :                 ErrorsFound = true;
    2011              :             }
    2012           10 :             if (maxEIRfLowPLRXInput < 1.0) {
    2013            0 :                 ShowWarningError(state, format("{}{}=\"{}\", suspicious", RoutineName, cCurrentModuleObject, thisVrfSys.Name));
    2014            0 :                 ShowContinueError(state, format("...{} = {} has unexpected value.", cAlphaFieldNames(9), cAlphaArgs(9)));
    2015            0 :                 ShowContinueError(state,
    2016            0 :                                   format("...Curve maximum value of X = {:.3T} should be 1 and will result in lower energy use than expected.",
    2017              :                                          maxEIRfLowPLRXInput));
    2018              :             }
    2019           10 :             minEIRfLowPLRXInput = 0.0;
    2020           10 :             maxEIRfLowPLRXInput = 0.0;
    2021              :         }
    2022           10 :         if (thisVrfSys.HeatEIRFPLR1 > 0) {
    2023           10 :             Curve::GetCurveMinMaxValues(state, thisVrfSys.HeatEIRFPLR1, minEIRfLowPLRXInput, maxEIRfLowPLRXInput);
    2024           10 :             if (minEIRfLowPLRXInput > thisVrfSys.MinPLR) {
    2025            0 :                 ShowWarningError(state, format("{}{}=\"{}\", invalid", RoutineName, cCurrentModuleObject, thisVrfSys.Name));
    2026            0 :                 ShowContinueError(state, format("...{} = {} has out of range value.", cAlphaFieldNames(20), cAlphaArgs(20)));
    2027            0 :                 ShowContinueError(state,
    2028            0 :                                   format("...Curve minimum value of X = {:.3T} must be <= Minimum Heat Pump Part-Load Ratio = {:.3T}.",
    2029              :                                          minEIRfLowPLRXInput,
    2030            0 :                                          thisVrfSys.MinPLR));
    2031            0 :                 ErrorsFound = true;
    2032              :             }
    2033           10 :             if (maxEIRfLowPLRXInput < 1.0) {
    2034            0 :                 ShowWarningError(state, format("{}{}=\"{}\", suspicious", RoutineName, cCurrentModuleObject, thisVrfSys.Name));
    2035            0 :                 ShowContinueError(state, format("...{} = {} has unexpected value.", cAlphaFieldNames(20), cAlphaArgs(20)));
    2036            0 :                 ShowContinueError(state,
    2037            0 :                                   format("...Curve maximum value of X = {:.3T} should be 1 and will result in lower energy use than expected.",
    2038              :                                          maxEIRfLowPLRXInput));
    2039              :             }
    2040              :         }
    2041              : 
    2042           10 :         thisVrfSys.MasterZonePtr = Util::FindItemInList(cAlphaArgs(24), state.dataHeatBal->Zone);
    2043              : 
    2044           10 :         thisVrfSys.ThermostatPriority = static_cast<ThermostatCtrlType>(getEnumValue(ThermostatCtrlTypeUC, cAlphaArgs(25)));
    2045              : 
    2046           10 :         if (thisVrfSys.ThermostatPriority == ThermostatCtrlType::MasterThermostatPriority) {
    2047            1 :             if (thisVrfSys.MasterZonePtr == 0) {
    2048            0 :                 ShowSevereError(state, format("{} = \"{}\"", cCurrentModuleObject, thisVrfSys.Name));
    2049            0 :                 ShowContinueError(state, format("{} must be entered when {} = {}", cAlphaFieldNames(24), cAlphaFieldNames(25), cAlphaArgs(25)));
    2050            0 :                 ErrorsFound = true;
    2051              :             }
    2052            9 :         } else if (thisVrfSys.ThermostatPriority == ThermostatCtrlType::Invalid) {
    2053            0 :             ShowSevereError(state, format("{} = \"{}\"", cCurrentModuleObject, thisVrfSys.Name));
    2054            0 :             ShowContinueError(state, format("Illegal {} = {}", cAlphaFieldNames(25), cAlphaArgs(25)));
    2055            0 :             ErrorsFound = true;
    2056              :         }
    2057              : 
    2058           10 :         if (thisVrfSys.ThermostatPriority == ThermostatCtrlType::ScheduledPriority) {
    2059            0 :             if (lAlphaFieldBlanks(26)) {
    2060            0 :                 ShowSevereEmptyField(state, eoh, cAlphaFieldNames(26), cAlphaFieldNames(25), cAlphaArgs(25));
    2061            0 :             } else if ((thisVrfSys.prioritySched = Sched::GetSchedule(state, cAlphaArgs(26))) == nullptr) {
    2062            0 :                 ShowSevereItemNotFound(state, eoh, cAlphaFieldNames(26), cAlphaArgs(26));
    2063            0 :                 ErrorsFound = true;
    2064              :             }
    2065              :         }
    2066              : 
    2067           10 :         thisVrfSys.ZoneTUListPtr = Util::FindItemInList(cAlphaArgs(27), state.dataHVACVarRefFlow->TerminalUnitList);
    2068           10 :         if (thisVrfSys.ZoneTUListPtr == 0) {
    2069            0 :             ShowSevereError(state, format("{} = \"{}\"", cCurrentModuleObject, thisVrfSys.Name));
    2070            0 :             ShowContinueError(state, format("{} = {} not found.", cAlphaFieldNames(27), cAlphaArgs(27)));
    2071            0 :             ErrorsFound = true;
    2072              :         }
    2073              : 
    2074           10 :         thisVrfSys.HeatRecoveryUsed = false;
    2075           10 :         if (!lAlphaFieldBlanks(28)) {
    2076           10 :             if (Util::SameString(cAlphaArgs(28), "No")) {
    2077            9 :                 thisVrfSys.HeatRecoveryUsed = false;
    2078            1 :             } else if (Util::SameString(cAlphaArgs(28), "Yes")) {
    2079            1 :                 thisVrfSys.HeatRecoveryUsed = true;
    2080              :             } else {
    2081            0 :                 ShowSevereError(state, format("{} = \"{}\"", cCurrentModuleObject, thisVrfSys.Name));
    2082            0 :                 ShowContinueError(state, format("Illegal {} = {}", cAlphaFieldNames(28), cAlphaArgs(28)));
    2083            0 :                 ErrorsFound = true;
    2084              :             }
    2085              :         }
    2086              : 
    2087           10 :         thisVrfSys.EquivPipeLngthCool = rNumericArgs(11);
    2088           10 :         thisVrfSys.VertPipeLngth = rNumericArgs(12);
    2089           10 :         thisVrfSys.PCFLengthCoolPtr = GetCurveIndex(state, cAlphaArgs(29));
    2090           10 :         if (thisVrfSys.PCFLengthCoolPtr > 0) {
    2091              :             // Verify Curve Object, only legal type is linear, quadratic, cubic, or biquadratic
    2092           30 :             ErrorsFound |= Curve::CheckCurveDims(state,
    2093              :                                                  thisVrfSys.PCFLengthCoolPtr, // Curve index
    2094              :                                                  {1, 2},                      // Valid dimensions  // MULTIPLECURVEDIMS
    2095              :                                                  RoutineName,                 // Routine name
    2096              :                                                  cCurrentModuleObject,        // Object Type
    2097              :                                                  thisVrfSys.Name,             // Object Name
    2098           10 :                                                  cAlphaFieldNames(29));       // Field Name
    2099              :         }
    2100           10 :         thisVrfSys.PCFHeightCool = rNumericArgs(13);
    2101              : 
    2102           10 :         thisVrfSys.EquivPipeLngthHeat = rNumericArgs(14);
    2103           10 :         thisVrfSys.PCFLengthHeatPtr = GetCurveIndex(state, cAlphaArgs(30));
    2104           10 :         if (thisVrfSys.PCFLengthHeatPtr > 0) {
    2105              :             // Verify Curve Object, only legal type is linear, quadratic, cubic, or biquadratic
    2106            0 :             ErrorsFound |= Curve::CheckCurveDims(state,
    2107              :                                                  thisVrfSys.PCFLengthHeatPtr, // Curve index
    2108              :                                                  {1, 2},                      // Valid dimensions  // MULTIPLECURVEDIMS
    2109              :                                                  RoutineName,                 // Routine name
    2110              :                                                  cCurrentModuleObject,        // Object Type
    2111              :                                                  thisVrfSys.Name,             // Object Name
    2112            0 :                                                  cAlphaFieldNames(30));       // Field Name
    2113              :         }
    2114              : 
    2115           10 :         thisVrfSys.PCFHeightHeat = rNumericArgs(15);
    2116              : 
    2117           10 :         thisVrfSys.CCHeaterPower = rNumericArgs(16);
    2118           10 :         thisVrfSys.NumCompressors = rNumericArgs(17);
    2119           10 :         thisVrfSys.CompressorSizeRatio = rNumericArgs(18);
    2120           10 :         thisVrfSys.MaxOATCCHeater = rNumericArgs(19);
    2121              : 
    2122           10 :         if (!lAlphaFieldBlanks(31)) {
    2123           10 :             thisVrfSys.DefrostStrategy = static_cast<StandardRatings::DefrostStrat>(getEnumValue(StandardRatings::DefrostStratUC, cAlphaArgs(31)));
    2124           10 :             if (thisVrfSys.DefrostStrategy == StandardRatings::DefrostStrat::Invalid) {
    2125            0 :                 ShowSevereError(state,
    2126            0 :                                 format("{}, \"{}\" {} not found: {}", cCurrentModuleObject, thisVrfSys.Name, cAlphaFieldNames(31), cAlphaArgs(31)));
    2127            0 :                 ErrorsFound = true;
    2128              :             }
    2129              :         } else {
    2130            0 :             thisVrfSys.DefrostStrategy = StandardRatings::DefrostStrat::ReverseCycle;
    2131              :         }
    2132              : 
    2133           10 :         if (!lAlphaFieldBlanks(32)) {
    2134           10 :             thisVrfSys.DefrostControl =
    2135           10 :                 static_cast<StandardRatings::HPdefrostControl>(getEnumValue(StandardRatings::HPdefrostControlUC, cAlphaArgs(32)));
    2136              : 
    2137           10 :             if (thisVrfSys.DefrostControl == StandardRatings::HPdefrostControl::Invalid) {
    2138            0 :                 ShowSevereError(state,
    2139            0 :                                 format("{}, \"{}\" {} not found: {}", cCurrentModuleObject, thisVrfSys.Name, cAlphaFieldNames(32), cAlphaArgs(32)));
    2140              : 
    2141            0 :                 ErrorsFound = true;
    2142              :             }
    2143              :         } else {
    2144            0 :             thisVrfSys.DefrostControl = StandardRatings::HPdefrostControl::Timed;
    2145              :         }
    2146              : 
    2147           10 :         if (!lAlphaFieldBlanks(33)) {
    2148            0 :             thisVrfSys.DefrostEIRPtr = GetCurveIndex(state, cAlphaArgs(33));
    2149            0 :             if (thisVrfSys.DefrostEIRPtr > 0) {
    2150              :                 // Verify Curve Object, expected type is BiQuadratic
    2151            0 :                 ErrorsFound |= Curve::CheckCurveDims(state,
    2152              :                                                      thisVrfSys.DefrostEIRPtr, // Curve index
    2153              :                                                      {2},                      // Valid dimensions
    2154              :                                                      RoutineName,              // Routine name
    2155              :                                                      cCurrentModuleObject,     // Object Type
    2156              :                                                      thisVrfSys.Name,          // Object Name
    2157            0 :                                                      cAlphaFieldNames(33));    // Field Name
    2158              :             } else {
    2159            0 :                 if (thisVrfSys.DefrostStrategy == StandardRatings::DefrostStrat::ReverseCycle) {
    2160            0 :                     ShowSevereError(
    2161            0 :                         state, format("{}, \"{}\" {} not found: {}", cCurrentModuleObject, thisVrfSys.Name, cAlphaFieldNames(33), cAlphaArgs(33)));
    2162            0 :                     ErrorsFound = true;
    2163              :                 }
    2164              :             }
    2165              :         } else {
    2166           10 :             if (thisVrfSys.DefrostStrategy == StandardRatings::DefrostStrat::ReverseCycle) {
    2167            0 :                 ShowSevereError(state,
    2168            0 :                                 format("{}, \"{}\" {} not found: {}", cCurrentModuleObject, thisVrfSys.Name, cAlphaFieldNames(33), cAlphaArgs(33)));
    2169            0 :                 ErrorsFound = true;
    2170              :             }
    2171              :         }
    2172              : 
    2173           10 :         thisVrfSys.DefrostFraction = rNumericArgs(20);
    2174           10 :         thisVrfSys.DefrostCapacity = rNumericArgs(21);
    2175           10 :         if (thisVrfSys.DefrostCapacity == 0.0 && thisVrfSys.DefrostStrategy == StandardRatings::DefrostStrat::Resistive) {
    2176            0 :             ShowWarningError(
    2177              :                 state,
    2178            0 :                 format("{}, \"{}\" {} = 0.0 for defrost strategy = RESISTIVE.", cCurrentModuleObject, thisVrfSys.Name, cNumericFieldNames(21)));
    2179              :         }
    2180              : 
    2181           10 :         thisVrfSys.MaxOATDefrost = rNumericArgs(22);
    2182              : 
    2183           10 :         if (!lAlphaFieldBlanks(35)) {
    2184           10 :             if (Util::SameString(cAlphaArgs(34), "AirCooled")) {
    2185            9 :                 thisVrfSys.CondenserType = DataHeatBalance::RefrigCondenserType::Air;
    2186              :             }
    2187           10 :             if (Util::SameString(cAlphaArgs(34), "EvaporativelyCooled")) {
    2188            0 :                 thisVrfSys.CondenserType = DataHeatBalance::RefrigCondenserType::Evap;
    2189              :             }
    2190           10 :             if (Util::SameString(cAlphaArgs(34), "WaterCooled")) {
    2191            1 :                 thisVrfSys.CondenserType = DataHeatBalance::RefrigCondenserType::Water;
    2192            1 :                 thisVrfSys.VRFType = PlantEquipmentType::HeatPumpVRF;
    2193            1 :                 if (thisVrfSys.HeatingPerformanceOATType == HVAC::OATType::WetBulb) {
    2194            0 :                     ShowSevereError(state, format("{} = {}", cCurrentModuleObject, thisVrfSys.Name));
    2195            0 :                     ShowContinueError(state, format("{} = {}", cAlphaFieldNames(34), cAlphaArgs(34)));
    2196            0 :                     ShowContinueError(state, format("Illegal {} input for this object = {}", cAlphaFieldNames(19), cAlphaArgs(19)));
    2197            0 :                     ShowContinueError(state, "... input must be DRYBULBTEMPERATURE when Condenser Type is WaterCooled.");
    2198            0 :                     ShowContinueError(state, format("... {} will be reset to DRYBULBTEMPERATURE and simulation continues.", cAlphaFieldNames(19)));
    2199              :                 }
    2200              :             }
    2201           10 :             if (thisVrfSys.CondenserType == DataHeatBalance::RefrigCondenserType::Invalid) {
    2202            0 :                 ShowSevereError(state, cCurrentModuleObject + " = " + thisVrfSys.Name);
    2203            0 :                 ShowContinueError(state, "Illegal " + cAlphaFieldNames(34) + " = " + cAlphaArgs(34));
    2204            0 :                 ErrorsFound = true;
    2205              :             }
    2206              :         } else {
    2207            0 :             thisVrfSys.CondenserType = DataHeatBalance::RefrigCondenserType::Air;
    2208              :         }
    2209              : 
    2210              :         // outdoor condenser node
    2211           10 :         if (lAlphaFieldBlanks(35)) {
    2212            0 :             thisVrfSys.CondenserNodeNum = 0;
    2213              :         } else {
    2214           10 :             switch (thisVrfSys.CondenserType) {
    2215            9 :             case DataHeatBalance::RefrigCondenserType::Air:
    2216              :             case DataHeatBalance::RefrigCondenserType::Evap: {
    2217            9 :                 thisVrfSys.CondenserNodeNum = GetOnlySingleNode(state,
    2218            9 :                                                                 cAlphaArgs(35),
    2219              :                                                                 ErrorsFound,
    2220              :                                                                 DataLoopNode::ConnectionObjectType::AirConditionerVariableRefrigerantFlow,
    2221            9 :                                                                 thisVrfSys.Name,
    2222              :                                                                 DataLoopNode::NodeFluidType::Air,
    2223              :                                                                 DataLoopNode::ConnectionType::OutsideAirReference,
    2224              :                                                                 NodeInputManager::CompFluidStream::Primary,
    2225              :                                                                 ObjectIsNotParent);
    2226            9 :                 if (!CheckOutAirNodeNumber(state, thisVrfSys.CondenserNodeNum)) {
    2227            0 :                     ShowSevereError(state,
    2228            0 :                                     format("{}, \"{}\" {} not a valid Outdoor Air Node = {}",
    2229              :                                            cCurrentModuleObject,
    2230            0 :                                            thisVrfSys.Name,
    2231              :                                            cAlphaFieldNames(35),
    2232              :                                            cAlphaArgs(35)));
    2233            0 :                     ShowContinueError(state, "...node name does not appear in an OutdoorAir:NodeList or as an OutdoorAir:Node.");
    2234            0 :                     ErrorsFound = true;
    2235              :                 }
    2236            9 :             } break;
    2237            1 :             case DataHeatBalance::RefrigCondenserType::Water: {
    2238            1 :                 thisVrfSys.CondenserNodeNum = GetOnlySingleNode(state,
    2239            1 :                                                                 cAlphaArgs(35),
    2240              :                                                                 ErrorsFound,
    2241              :                                                                 DataLoopNode::ConnectionObjectType::AirConditionerVariableRefrigerantFlow,
    2242            1 :                                                                 thisVrfSys.Name,
    2243              :                                                                 DataLoopNode::NodeFluidType::Water,
    2244              :                                                                 DataLoopNode::ConnectionType::Inlet,
    2245              :                                                                 NodeInputManager::CompFluidStream::Secondary,
    2246              :                                                                 ObjectIsNotParent);
    2247            1 :             } break;
    2248            0 :             default:
    2249            0 :                 break;
    2250              :             }
    2251              :         }
    2252              : 
    2253           10 :         if (!lAlphaFieldBlanks(36) && thisVrfSys.CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    2254            2 :             thisVrfSys.CondenserOutletNodeNum = GetOnlySingleNode(state,
    2255            1 :                                                                   cAlphaArgs(36),
    2256              :                                                                   ErrorsFound,
    2257              :                                                                   DataLoopNode::ConnectionObjectType::AirConditionerVariableRefrigerantFlow,
    2258            1 :                                                                   thisVrfSys.Name,
    2259              :                                                                   DataLoopNode::NodeFluidType::Water,
    2260              :                                                                   DataLoopNode::ConnectionType::Outlet,
    2261              :                                                                   NodeInputManager::CompFluidStream::Secondary,
    2262              :                                                                   ObjectIsNotParent);
    2263            2 :             TestCompSet(state, cCurrentModuleObject, thisVrfSys.Name, cAlphaArgs(35), cAlphaArgs(36), "Condenser Water Nodes");
    2264            9 :         } else if (lAlphaFieldBlanks(36) && thisVrfSys.CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    2265            0 :             ShowSevereError(state, format("{}, \"{}\" {} is blank.", cCurrentModuleObject, thisVrfSys.Name, cAlphaFieldNames(36)));
    2266            0 :             ShowContinueError(state, "...node name must be entered when Condenser Type = WaterCooled.");
    2267            0 :             ErrorsFound = true;
    2268              :         }
    2269              : 
    2270           10 :         if (lAlphaFieldBlanks(23)) {
    2271            0 :             if (thisVrfSys.CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    2272            0 :                 ShowSevereError(state, format("{}, \"{}\" {} is blank.", cCurrentModuleObject, thisVrfSys.Name, cNumericFieldNames(23)));
    2273            0 :                 ShowContinueError(state, format("...input is required when {} = {}", cAlphaFieldNames(34), cAlphaArgs(34)));
    2274            0 :                 ErrorsFound = true;
    2275              :             }
    2276              :         } else {
    2277           10 :             thisVrfSys.WaterCondVolFlowRate = rNumericArgs(23);
    2278              :         }
    2279           10 :         thisVrfSys.EvapCondEffectiveness = rNumericArgs(24);
    2280           10 :         thisVrfSys.EvapCondAirVolFlowRate = rNumericArgs(25);
    2281           10 :         thisVrfSys.EvapCondPumpPower = rNumericArgs(26);
    2282              : 
    2283              :         // Get Water System tank connections
    2284              :         // A37, \field Supply Water Storage Tank Name
    2285           10 :         thisVrfSys.EvapWaterSupplyName = cAlphaArgs(37);
    2286           10 :         if (lAlphaFieldBlanks(37)) {
    2287           10 :             thisVrfSys.EvapWaterSupplyMode = EvapWaterSupply::FromMains;
    2288              :         } else {
    2289            0 :             thisVrfSys.EvapWaterSupplyMode = EvapWaterSupply::FromTank;
    2290            0 :             SetupTankDemandComponent(state,
    2291              :                                      thisVrfSys.Name,
    2292              :                                      cCurrentModuleObject,
    2293              :                                      thisVrfSys.EvapWaterSupplyName,
    2294              :                                      ErrorsFound,
    2295            0 :                                      thisVrfSys.EvapWaterSupTankID,
    2296            0 :                                      thisVrfSys.EvapWaterTankDemandARRID);
    2297              :         }
    2298              : 
    2299              :         //   Basin heater power as a function of temperature must be greater than or equal to 0
    2300           10 :         thisVrfSys.BasinHeaterPowerFTempDiff = rNumericArgs(27);
    2301           10 :         if (rNumericArgs(27) < 0.0) {
    2302            0 :             ShowSevereError(state, format("{}, \"{}\" {} must be >= 0", cCurrentModuleObject, thisVrfSys.Name, cNumericFieldNames(27)));
    2303            0 :             ErrorsFound = true;
    2304              :         }
    2305              : 
    2306           10 :         thisVrfSys.BasinHeaterSetPointTemp = rNumericArgs(28);
    2307           10 :         if (thisVrfSys.BasinHeaterPowerFTempDiff > 0.0) {
    2308            0 :             if (NumNums < 27) {
    2309            0 :                 thisVrfSys.BasinHeaterSetPointTemp = 2.0;
    2310              :             }
    2311            0 :             if (thisVrfSys.BasinHeaterSetPointTemp < 2.0) {
    2312            0 :                 ShowWarningError(
    2313              :                     state,
    2314            0 :                     format(
    2315            0 :                         "{}, \"{}\" {} is less than 2 deg C. Freezing could occur.", cCurrentModuleObject, thisVrfSys.Name, cNumericFieldNames(28)));
    2316              :             }
    2317              :         }
    2318              : 
    2319           10 :         if (!lAlphaFieldBlanks(38)) {
    2320            0 :             if ((thisVrfSys.basinHeaterSched = Sched::GetSchedule(state, cAlphaArgs(38))) == nullptr) {
    2321            0 :                 ShowWarningItemNotFound(
    2322            0 :                     state, eoh, cAlphaFieldNames(38), cAlphaArgs(38), "Basin heater will be available to operate throughout the simulation.");
    2323              :             }
    2324              :         }
    2325              : 
    2326           10 :         if (!lAlphaFieldBlanks(39)) {
    2327              :             // A39; \field Fuel type, Validate fuel type input
    2328           10 :             if ((thisVrfSys.fuel = static_cast<Constant::eFuel>(getEnumValue(Constant::eFuelNamesUC, cAlphaArgs(39)))) == Constant::eFuel::Invalid) {
    2329            0 :                 ShowSevereInvalidKey(state, eoh, cAlphaFieldNames(39), cAlphaArgs(39));
    2330            0 :                 ErrorsFound = true;
    2331              :             }
    2332              :         }
    2333              : 
    2334           10 :         if (thisVrfSys.HeatRecoveryUsed) {
    2335            1 :             if (lAlphaFieldBlanks(29)) {
    2336            0 :                 thisVrfSys.MinOATHeatRecovery = max(thisVrfSys.MinOATCooling, thisVrfSys.MinOATHeating);
    2337              :             } else {
    2338            1 :                 thisVrfSys.MinOATHeatRecovery = rNumericArgs(29);
    2339            1 :                 if (thisVrfSys.MinOATHeatRecovery < thisVrfSys.MinOATCooling || thisVrfSys.MinOATHeatRecovery < thisVrfSys.MinOATHeating) {
    2340            0 :                     ShowWarningError(state,
    2341            0 :                                      format("{} = \"{}\", {} is less than the minimum temperature in heat pump mode.",
    2342              :                                             cCurrentModuleObject,
    2343            0 :                                             thisVrfSys.Name,
    2344              :                                             cNumericFieldNames(29)));
    2345            0 :                     ShowContinueError(state, format("...{} = {:.2T} C", cNumericFieldNames(29), thisVrfSys.MinOATHeatRecovery));
    2346            0 :                     ShowContinueError(state, format("...Minimum Outdoor Temperature in Cooling Mode = {:.2T} C", thisVrfSys.MinOATCooling));
    2347            0 :                     ShowContinueError(state, format("...Minimum Outdoor Temperature in Heating Mode = {:.2T} C", thisVrfSys.MinOATHeating));
    2348            0 :                     ShowContinueError(state,
    2349              :                                       "...Minimum Outdoor Temperature in Heat Recovery Mode reset to greater of cooling or heating minimum "
    2350              :                                       "temperature and simulation continues.");
    2351            0 :                     thisVrfSys.MinOATHeatRecovery = max(thisVrfSys.MinOATCooling, thisVrfSys.MinOATHeating);
    2352            0 :                     ShowContinueError(state, format("... adjusted {} = {:.2T} C", cNumericFieldNames(29), thisVrfSys.MinOATHeatRecovery));
    2353              :                 }
    2354              :             }
    2355            1 :             if (lAlphaFieldBlanks(30)) {
    2356            1 :                 thisVrfSys.MaxOATHeatRecovery = min(thisVrfSys.MaxOATCooling, thisVrfSys.MaxOATHeating);
    2357              :             } else {
    2358            0 :                 thisVrfSys.MaxOATHeatRecovery = rNumericArgs(30);
    2359            0 :                 if (thisVrfSys.MaxOATHeatRecovery > thisVrfSys.MaxOATCooling || thisVrfSys.MaxOATHeatRecovery > thisVrfSys.MaxOATHeating) {
    2360            0 :                     ShowWarningError(state,
    2361            0 :                                      format("{} = \"{}\", {} is greater than the maximum temperature in heat pump mode.",
    2362              :                                             cCurrentModuleObject,
    2363            0 :                                             thisVrfSys.Name,
    2364              :                                             cNumericFieldNames(30)));
    2365            0 :                     ShowContinueError(state, format("...{} = {:.2T} C", cNumericFieldNames(30), thisVrfSys.MaxOATHeatRecovery));
    2366            0 :                     ShowContinueError(state, format("...Maximum Outdoor Temperature in Cooling Mode = {:.2T} C", thisVrfSys.MaxOATCooling));
    2367            0 :                     ShowContinueError(state, format("...Maximum Outdoor Temperature in Heating Mode = {:.2T} C", thisVrfSys.MaxOATHeating));
    2368            0 :                     ShowContinueError(state,
    2369              :                                       "...Maximum Outdoor Temperature in Heat Recovery Mode reset to lesser of cooling or heating minimum "
    2370              :                                       "temperature and simulation continues.");
    2371            0 :                     thisVrfSys.MaxOATHeatRecovery = min(thisVrfSys.MaxOATCooling, thisVrfSys.MaxOATHeating);
    2372            0 :                     ShowContinueError(state, format("... adjusted {} = {:.2T} C", cNumericFieldNames(30), thisVrfSys.MaxOATHeatRecovery));
    2373              :                 }
    2374              :             }
    2375              : 
    2376            1 :             thisVrfSys.HRCAPFTCool = GetCurveIndex(state, cAlphaArgs(40));
    2377            1 :             if (thisVrfSys.HRCAPFTCool > 0) {
    2378              :                 // Verify Curve Object, only legal type is bi-quadratic or linear, quadratic, or cubic
    2379            0 :                 ErrorsFound |= Curve::CheckCurveDims(state,
    2380              :                                                      thisVrfSys.HRCAPFTCool, // Curve index
    2381              :                                                      {1, 2},                 // Valid dimensions  // MULTIPLECURVEDIMS
    2382              :                                                      RoutineName,            // Routine name
    2383              :                                                      cCurrentModuleObject,   // Object Type
    2384              :                                                      thisVrfSys.Name,        // Object Name
    2385            0 :                                                      cAlphaFieldNames(40));  // Field Name
    2386              :             }
    2387            1 :             if (!lNumericFieldBlanks(31)) {
    2388            0 :                 thisVrfSys.HRInitialCoolCapFrac = rNumericArgs(31);
    2389              :             }
    2390            1 :             thisVrfSys.HRCoolCapTC = rNumericArgs(32);
    2391            1 :             thisVrfSys.HREIRFTCool = GetCurveIndex(state, cAlphaArgs(41));
    2392            1 :             if (thisVrfSys.HREIRFTCool > 0) {
    2393              :                 // Verify Curve Object, only legal type is bi-quadratic or linear, quadratic, or cubic
    2394            0 :                 ErrorsFound |= Curve::CheckCurveDims(state,
    2395              :                                                      thisVrfSys.HREIRFTCool, // Curve index
    2396              :                                                      {1, 2},                 // Valid dimensions  // MULTIPLECURVEDIMS
    2397              :                                                      RoutineName,            // Routine name
    2398              :                                                      cCurrentModuleObject,   // Object Type
    2399              :                                                      thisVrfSys.Name,        // Object Name
    2400            0 :                                                      cAlphaFieldNames(41));  // Field Name
    2401              :             }
    2402            1 :             thisVrfSys.HRInitialCoolEIRFrac = rNumericArgs(33);
    2403            1 :             thisVrfSys.HRCoolEIRTC = rNumericArgs(34);
    2404              : 
    2405              :             //  INTEGER      :: HRCAPFTHeat                =0   ! Index to heat capacity as a function of temperature curve for heat recovery
    2406              :             //  REAL(r64)    :: HRInitialHeatCapFrac       =0.0d0 ! Fractional heating degradation at the start of heat recovery from heating mode
    2407              :             //  REAL(r64)    :: HRHeatCapTC                =0.0d0 ! Time constant used to recover from initial degradation in heating heat
    2408              :             //  recovery
    2409            1 :             thisVrfSys.HRCAPFTHeat = GetCurveIndex(state, cAlphaArgs(42));
    2410            1 :             if (thisVrfSys.HRCAPFTHeat > 0) {
    2411              :                 // Verify Curve Object, only legal type is bi-quadratic or linear, quadratic, or cubic
    2412            0 :                 ErrorsFound |= Curve::CheckCurveDims(state,
    2413              :                                                      thisVrfSys.HRCAPFTHeat, // Curve index
    2414              :                                                      {1, 2},                 // Valid dimensions  // MULTIPLECURVEDIMS
    2415              :                                                      RoutineName,            // Routine name
    2416              :                                                      cCurrentModuleObject,   // Object Type
    2417              :                                                      thisVrfSys.Name,        // Object Name
    2418            0 :                                                      cAlphaFieldNames(42));  // Field Name
    2419              :             }
    2420            1 :             thisVrfSys.HRInitialHeatCapFrac = rNumericArgs(35);
    2421            1 :             thisVrfSys.HRHeatCapTC = rNumericArgs(36);
    2422              : 
    2423              :             //  INTEGER      :: HREIRFTHeat                =0   ! Index to heat EIR as a function of temperature curve for heat recovery
    2424              :             //  REAL(r64)    :: HRInitialHeatEIRFrac       =0.0d0 ! Fractional EIR degradation at the start of heat recovery from heating mode
    2425              :             //  REAL(r64)    :: HRHeatEIRTC                =0.0d0 ! Time constant used to recover from initial degradation in heating heat
    2426              :             //  recovery
    2427            1 :             thisVrfSys.HREIRFTHeat = GetCurveIndex(state, cAlphaArgs(43));
    2428            1 :             if (thisVrfSys.HREIRFTHeat > 0) {
    2429              :                 // Verify Curve Object, only legal type is bi-quadratic or linear, quadratic, or cubic
    2430            0 :                 ErrorsFound |= Curve::CheckCurveDims(state,
    2431              :                                                      thisVrfSys.HREIRFTHeat, // Curve index
    2432              :                                                      {1, 2},                 // Valid dimensions  // MULTIPLECURVEDIMS
    2433              :                                                      RoutineName,            // Routine name
    2434              :                                                      cCurrentModuleObject,   // Object Type
    2435              :                                                      thisVrfSys.Name,        // Object Name
    2436            0 :                                                      cAlphaFieldNames(43));  // Field Name
    2437              :             }
    2438            1 :             thisVrfSys.HRInitialHeatEIRFrac = rNumericArgs(37);
    2439            1 :             thisVrfSys.HRHeatEIRTC = rNumericArgs(38);
    2440              :         }
    2441              :     }
    2442              : 
    2443              :     // Read all VRF condenser objects: Algorithm Type 2_physics based model (VRF-FluidTCtrl-HP)
    2444           13 :     cCurrentModuleObject = "AirConditioner:VariableRefrigerantFlow:FluidTemperatureControl";
    2445           16 :     for (int thisNum = 1; thisNum <= state.dataHVACVarRefFlow->NumVRFCond_FluidTCtrl_HP; ++thisNum) {
    2446              : 
    2447            3 :         state.dataInputProcessing->inputProcessor->getObjectItem(state,
    2448              :                                                                  cCurrentModuleObject,
    2449              :                                                                  thisNum,
    2450              :                                                                  cAlphaArgs,
    2451              :                                                                  NumAlphas,
    2452              :                                                                  rNumericArgs,
    2453              :                                                                  NumNums,
    2454              :                                                                  IOStat,
    2455              :                                                                  lNumericFieldBlanks,
    2456              :                                                                  lAlphaFieldBlanks,
    2457              :                                                                  cAlphaFieldNames,
    2458              :                                                                  cNumericFieldNames);
    2459              : 
    2460            3 :         ErrorObjectHeader eoh{routineName, cCurrentModuleObject, cAlphaArgs(1)};
    2461              : 
    2462            3 :         GlobalNames::VerifyUniqueInterObjectName(
    2463            6 :             state, state.dataHVACVarRefFlow->VrfUniqueNames, cAlphaArgs(1), cCurrentModuleObject, cAlphaFieldNames(1), ErrorsFound);
    2464              : 
    2465            3 :         int VRFNum = state.dataHVACVarRefFlow->NumVRFCond_SysCurve + thisNum;
    2466            3 :         auto &thisVrfFluidCtrl = state.dataHVACVarRefFlow->VRF(VRFNum);
    2467            3 :         thisVrfFluidCtrl.Name = cAlphaArgs(1);
    2468            3 :         thisVrfFluidCtrl.VRFSystemTypeNum = VRF_HeatPump;
    2469            3 :         thisVrfFluidCtrl.VRFAlgorithmType = AlgorithmType::FluidTCtrl;
    2470            3 :         thisVrfFluidCtrl.fuel = Constant::eFuel::Electricity;
    2471              : 
    2472            3 :         if (lAlphaFieldBlanks(2)) {
    2473            0 :             thisVrfFluidCtrl.availSched = Sched::GetScheduleAlwaysOn(state);
    2474            3 :         } else if ((thisVrfFluidCtrl.availSched = Sched::GetSchedule(state, cAlphaArgs(2))) == nullptr) {
    2475            0 :             ShowSevereItemNotFound(state, eoh, cAlphaFieldNames(2), cAlphaArgs(2));
    2476            0 :             ErrorsFound = true;
    2477              :         }
    2478              : 
    2479            3 :         thisVrfFluidCtrl.ZoneTUListPtr =
    2480            3 :             Util::FindItemInList(cAlphaArgs(3), state.dataHVACVarRefFlow->TerminalUnitList, state.dataHVACVarRefFlow->NumVRFTULists);
    2481            3 :         if (thisVrfFluidCtrl.ZoneTUListPtr == 0) {
    2482            0 :             ShowSevereError(state, cCurrentModuleObject + " = \"" + thisVrfFluidCtrl.Name + "\"");
    2483            0 :             ShowContinueError(state, cAlphaFieldNames(3) + " = " + cAlphaArgs(3) + " not found.");
    2484            0 :             ErrorsFound = true;
    2485              :         }
    2486              : 
    2487              :         // Refrigerant type
    2488            3 :         thisVrfFluidCtrl.refrigName = cAlphaArgs(4);
    2489            3 :         thisVrfFluidCtrl.refrig = Fluid::GetRefrig(state, thisVrfFluidCtrl.refrigName);
    2490            3 :         if (thisVrfFluidCtrl.refrig == nullptr) {
    2491            0 :             ShowSevereItemNotFound(state, eoh, cAlphaFieldNames(4), cAlphaArgs(4));
    2492            0 :             ErrorsFound = true;
    2493              :         }
    2494              : 
    2495            3 :         thisVrfFluidCtrl.RatedEvapCapacity = rNumericArgs(1);
    2496            3 :         thisVrfFluidCtrl.RatedCompPowerPerCapcity = rNumericArgs(2);
    2497            3 :         thisVrfFluidCtrl.RatedCompPower = thisVrfFluidCtrl.RatedCompPowerPerCapcity * thisVrfFluidCtrl.RatedEvapCapacity;
    2498            3 :         thisVrfFluidCtrl.CoolingCapacity = thisVrfFluidCtrl.RatedEvapCapacity;
    2499            3 :         thisVrfFluidCtrl.RatedHeatCapacity = thisVrfFluidCtrl.RatedEvapCapacity * (1 + thisVrfFluidCtrl.RatedCompPowerPerCapcity);
    2500            3 :         thisVrfFluidCtrl.HeatingCapacity = thisVrfFluidCtrl.RatedHeatCapacity;
    2501              : 
    2502              :         // Reference system COP
    2503            3 :         thisVrfFluidCtrl.CoolingCOP = 1 / thisVrfFluidCtrl.RatedCompPowerPerCapcity;
    2504            3 :         thisVrfFluidCtrl.HeatingCOP = 1 / thisVrfFluidCtrl.RatedCompPowerPerCapcity + 1;
    2505              : 
    2506              :         // OA temperature range for VRF-HP operations
    2507            3 :         thisVrfFluidCtrl.MinOATCooling = rNumericArgs(3);
    2508            3 :         thisVrfFluidCtrl.MaxOATCooling = rNumericArgs(4);
    2509            3 :         thisVrfFluidCtrl.MinOATHeating = rNumericArgs(5);
    2510            3 :         thisVrfFluidCtrl.MaxOATHeating = rNumericArgs(6);
    2511            3 :         if (thisVrfFluidCtrl.MinOATCooling >= thisVrfFluidCtrl.MaxOATCooling) {
    2512            0 :             ShowSevereError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\"");
    2513            0 :             ShowContinueError(state,
    2514            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    2515              :                                      cNumericFieldNames(3),
    2516            0 :                                      thisVrfFluidCtrl.MinOATCooling,
    2517            0 :                                      thisVrfFluidCtrl.MaxOATCooling));
    2518            0 :             ErrorsFound = true;
    2519              :         }
    2520            3 :         if (thisVrfFluidCtrl.MinOATHeating >= thisVrfFluidCtrl.MaxOATHeating) {
    2521            0 :             ShowSevereError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\"");
    2522            0 :             ShowContinueError(state,
    2523            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    2524              :                                      cNumericFieldNames(5),
    2525            0 :                                      thisVrfFluidCtrl.MinOATHeating,
    2526            0 :                                      thisVrfFluidCtrl.MaxOATHeating));
    2527            0 :             ErrorsFound = true;
    2528              :         }
    2529              : 
    2530              :         // Reference OU SH/SC
    2531            3 :         thisVrfFluidCtrl.SH = rNumericArgs(7);
    2532            3 :         thisVrfFluidCtrl.SC = rNumericArgs(8);
    2533              : 
    2534            3 :         if (Util::SameString(cAlphaArgs(5), "VariableTemp")) {
    2535            1 :             thisVrfFluidCtrl.AlgorithmIUCtrl = 1;
    2536            2 :         } else if (Util::SameString(cAlphaArgs(5), "ConstantTemp")) {
    2537            2 :             thisVrfFluidCtrl.AlgorithmIUCtrl = 2;
    2538              :         } else {
    2539            0 :             thisVrfFluidCtrl.AlgorithmIUCtrl = 1;
    2540              :         }
    2541              : 
    2542              :         // Reference IU Te/Tc for IU Control Algorithm: ConstantTemp
    2543            3 :         thisVrfFluidCtrl.EvapTempFixed = rNumericArgs(9);
    2544            3 :         thisVrfFluidCtrl.CondTempFixed = rNumericArgs(10);
    2545              : 
    2546              :         // Bounds of Te/Tc for IU Control Algorithm: VariableTemp
    2547            3 :         thisVrfFluidCtrl.IUEvapTempLow = rNumericArgs(11);
    2548            3 :         thisVrfFluidCtrl.IUEvapTempHigh = rNumericArgs(12);
    2549            3 :         thisVrfFluidCtrl.IUCondTempLow = rNumericArgs(13);
    2550            3 :         thisVrfFluidCtrl.IUCondTempHigh = rNumericArgs(14);
    2551            3 :         if (thisVrfFluidCtrl.IUEvapTempLow >= thisVrfFluidCtrl.IUEvapTempHigh) {
    2552            0 :             ShowSevereError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\"");
    2553            0 :             ShowContinueError(state,
    2554            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    2555              :                                      cNumericFieldNames(11),
    2556            0 :                                      thisVrfFluidCtrl.IUEvapTempLow,
    2557            0 :                                      thisVrfFluidCtrl.IUEvapTempHigh));
    2558            0 :             ErrorsFound = true;
    2559              :         }
    2560            3 :         if (thisVrfFluidCtrl.IUCondTempLow >= thisVrfFluidCtrl.IUCondTempHigh) {
    2561            0 :             ShowSevereError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\"");
    2562            0 :             ShowContinueError(state,
    2563            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    2564              :                                      cNumericFieldNames(13),
    2565            0 :                                      thisVrfFluidCtrl.IUCondTempLow,
    2566            0 :                                      thisVrfFluidCtrl.IUCondTempHigh));
    2567            0 :             ErrorsFound = true;
    2568              :         }
    2569              : 
    2570              :         // Get OU fan data
    2571            3 :         thisVrfFluidCtrl.RatedOUFanPowerPerCapcity = rNumericArgs(15);
    2572            3 :         thisVrfFluidCtrl.OUAirFlowRatePerCapcity = rNumericArgs(16);
    2573            3 :         thisVrfFluidCtrl.RatedOUFanPower = thisVrfFluidCtrl.RatedOUFanPowerPerCapcity * thisVrfFluidCtrl.RatedEvapCapacity;
    2574            3 :         thisVrfFluidCtrl.OUAirFlowRate = thisVrfFluidCtrl.OUAirFlowRatePerCapcity * thisVrfFluidCtrl.RatedEvapCapacity;
    2575              : 
    2576              :         // OUEvapTempCurve
    2577            3 :         int indexOUEvapTempCurve = GetCurveIndex(state, cAlphaArgs(6)); // convert curve name to index number
    2578              :         // Verify curve name and type
    2579            3 :         if (indexOUEvapTempCurve == 0) {
    2580            0 :             if (lAlphaFieldBlanks(6)) {
    2581            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", missing");
    2582            0 :                 ShowContinueError(state, "...required " + cAlphaFieldNames(6) + " is blank.");
    2583              :             } else {
    2584            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", invalid");
    2585            0 :                 ShowContinueError(state, "...not found " + cAlphaFieldNames(6) + "=\"" + cAlphaArgs(6) + "\".");
    2586              :             }
    2587            0 :             ErrorsFound = true;
    2588              :         } else {
    2589              :             {
    2590            3 :                 if (state.dataCurveManager->curves(indexOUEvapTempCurve)->curveType == Curve::CurveType::Quadratic) {
    2591            3 :                     thisVrfFluidCtrl.C1Te = state.dataCurveManager->curves(indexOUEvapTempCurve)->coeff[0];
    2592            3 :                     thisVrfFluidCtrl.C2Te = state.dataCurveManager->curves(indexOUEvapTempCurve)->coeff[1];
    2593            3 :                     thisVrfFluidCtrl.C3Te = state.dataCurveManager->curves(indexOUEvapTempCurve)->coeff[2];
    2594              : 
    2595              :                 } else {
    2596            0 :                     ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", invalid");
    2597            0 :                     ShowContinueError(state,
    2598            0 :                                       format("...illegal {} type for this object = {}",
    2599              :                                              cAlphaFieldNames(6),
    2600            0 :                                              Curve::objectNames[static_cast<int>(state.dataCurveManager->curves(indexOUEvapTempCurve)->curveType)]));
    2601            0 :                     ShowContinueError(state, "... Curve type must be Quadratic.");
    2602            0 :                     ErrorsFound = true;
    2603              :                 }
    2604              :             }
    2605              :         }
    2606              : 
    2607              :         // OUCondTempCurve
    2608            3 :         int indexOUCondTempCurve = GetCurveIndex(state, cAlphaArgs(7)); // convert curve name to index number
    2609              :         // Verify curve name and type
    2610            3 :         if (indexOUCondTempCurve == 0) {
    2611            0 :             if (lAlphaFieldBlanks(7)) {
    2612            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", missing");
    2613            0 :                 ShowContinueError(state, "...required " + cAlphaFieldNames(7) + " is blank.");
    2614              :             } else {
    2615            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", invalid");
    2616            0 :                 ShowContinueError(state, "...not found " + cAlphaFieldNames(7) + "=\"" + cAlphaArgs(7) + "\".");
    2617              :             }
    2618            0 :             ErrorsFound = true;
    2619              :         } else {
    2620              :             {
    2621            3 :                 if (state.dataCurveManager->curves(indexOUCondTempCurve)->curveType == Curve::CurveType::Quadratic) {
    2622            3 :                     thisVrfFluidCtrl.C1Tc = state.dataCurveManager->curves(indexOUCondTempCurve)->coeff[0];
    2623            3 :                     thisVrfFluidCtrl.C2Tc = state.dataCurveManager->curves(indexOUCondTempCurve)->coeff[1];
    2624            3 :                     thisVrfFluidCtrl.C3Tc = state.dataCurveManager->curves(indexOUCondTempCurve)->coeff[2];
    2625              : 
    2626              :                 } else {
    2627            0 :                     ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", invalid");
    2628            0 :                     ShowContinueError(state,
    2629            0 :                                       format("...illegal {} type for this object = {}",
    2630              :                                              cAlphaFieldNames(7),
    2631            0 :                                              Curve::objectNames[static_cast<int>(state.dataCurveManager->curves(indexOUCondTempCurve)->curveType)]));
    2632            0 :                     ShowContinueError(state, "... Curve type must be Quadratic.");
    2633            0 :                     ErrorsFound = true;
    2634              :                 }
    2635              :             }
    2636              :         }
    2637              : 
    2638              :         // Pipe parameters
    2639            3 :         thisVrfFluidCtrl.RefPipDiaSuc = rNumericArgs(17);
    2640            3 :         thisVrfFluidCtrl.RefPipDiaDis = rNumericArgs(17);
    2641            3 :         thisVrfFluidCtrl.RefPipLen = rNumericArgs(18);
    2642            3 :         thisVrfFluidCtrl.RefPipEquLen = rNumericArgs(19);
    2643            3 :         thisVrfFluidCtrl.RefPipHei = rNumericArgs(20);
    2644            3 :         thisVrfFluidCtrl.RefPipInsThi = rNumericArgs(21);
    2645            3 :         thisVrfFluidCtrl.RefPipInsCon = rNumericArgs(22);
    2646              : 
    2647              :         // Check the RefPipEquLen
    2648            3 :         if (lNumericFieldBlanks(19) && !lNumericFieldBlanks(18)) {
    2649            0 :             thisVrfFluidCtrl.RefPipEquLen = 1.2 * thisVrfFluidCtrl.RefPipLen;
    2650            0 :             ShowWarningError(
    2651            0 :                 state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\", \" " + cNumericFieldNames(19) + "\" is calculated based on");
    2652            0 :             ShowContinueError(state, "...the provided \"" + cNumericFieldNames(18) + "\" value.");
    2653              :         }
    2654            3 :         if (thisVrfFluidCtrl.RefPipEquLen < thisVrfFluidCtrl.RefPipLen) {
    2655            0 :             thisVrfFluidCtrl.RefPipEquLen = 1.2 * thisVrfFluidCtrl.RefPipLen;
    2656            0 :             ShowWarningError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\", invalid \" " + cNumericFieldNames(19) + "\" value.");
    2657            0 :             ShowContinueError(state, "...Equivalent length of main pipe should be greater than or equal to the actual length.");
    2658            0 :             ShowContinueError(state, format("...The value is recalculated based on the provided \"{}\" value.", cNumericFieldNames(18)));
    2659              :         }
    2660              : 
    2661              :         // Crank case
    2662            3 :         thisVrfFluidCtrl.CCHeaterPower = rNumericArgs(23);
    2663            3 :         thisVrfFluidCtrl.NumCompressors = rNumericArgs(24);
    2664            3 :         thisVrfFluidCtrl.CompressorSizeRatio = rNumericArgs(25);
    2665            3 :         thisVrfFluidCtrl.MaxOATCCHeater = rNumericArgs(26);
    2666              : 
    2667              :         // Defrost
    2668            3 :         if (!lAlphaFieldBlanks(8)) {
    2669            0 :             if (Util::SameString(cAlphaArgs(8), "ReverseCycle")) {
    2670            0 :                 thisVrfFluidCtrl.DefrostStrategy = StandardRatings::DefrostStrat::ReverseCycle;
    2671              :             }
    2672            0 :             if (Util::SameString(cAlphaArgs(8), "Resistive")) {
    2673            0 :                 thisVrfFluidCtrl.DefrostStrategy = StandardRatings::DefrostStrat::Resistive;
    2674              :             }
    2675            0 :             if (thisVrfFluidCtrl.DefrostStrategy == StandardRatings::DefrostStrat::Invalid) {
    2676            0 :                 ShowSevereError(state,
    2677            0 :                                 cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\" " + cAlphaFieldNames(8) + " not found: " + cAlphaArgs(8));
    2678            0 :                 ErrorsFound = true;
    2679              :             }
    2680              :         } else {
    2681            3 :             thisVrfFluidCtrl.DefrostStrategy = StandardRatings::DefrostStrat::ReverseCycle;
    2682              :         }
    2683              : 
    2684            3 :         if (!lAlphaFieldBlanks(9)) {
    2685            0 :             if (Util::SameString(cAlphaArgs(9), "Timed")) {
    2686            0 :                 thisVrfFluidCtrl.DefrostControl = StandardRatings::HPdefrostControl::Timed;
    2687              :             }
    2688            0 :             if (Util::SameString(cAlphaArgs(9), "OnDemand")) {
    2689            0 :                 thisVrfFluidCtrl.DefrostControl = StandardRatings::HPdefrostControl::OnDemand;
    2690              :             }
    2691            0 :             if (thisVrfFluidCtrl.DefrostControl == StandardRatings::HPdefrostControl::Invalid) {
    2692            0 :                 ShowSevereError(state,
    2693            0 :                                 cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\" " + cAlphaFieldNames(9) + " not found: " + cAlphaArgs(9));
    2694            0 :                 ErrorsFound = true;
    2695              :             }
    2696              :         } else {
    2697            3 :             thisVrfFluidCtrl.DefrostControl = StandardRatings::HPdefrostControl::Timed;
    2698              :         }
    2699              : 
    2700            3 :         if (!lAlphaFieldBlanks(10)) {
    2701            0 :             thisVrfFluidCtrl.DefrostEIRPtr = GetCurveIndex(state, cAlphaArgs(10));
    2702            0 :             if (thisVrfFluidCtrl.DefrostEIRPtr > 0) {
    2703              :                 // Verify Curve Object, expected type is BiQuadratic
    2704            0 :                 ErrorsFound |= Curve::CheckCurveDims(state,
    2705              :                                                      thisVrfFluidCtrl.DefrostEIRPtr, // Curve index
    2706              :                                                      {2},                            // Valid dimensions
    2707              :                                                      RoutineName,                    // Routine name
    2708              :                                                      cCurrentModuleObject,           // Object Type
    2709              :                                                      thisVrfFluidCtrl.Name,          // Object Name
    2710            0 :                                                      cAlphaFieldNames(10));          // Field Name
    2711              :             } else {
    2712            0 :                 if (thisVrfFluidCtrl.DefrostStrategy == StandardRatings::DefrostStrat::ReverseCycle &&
    2713            0 :                     thisVrfFluidCtrl.DefrostControl == StandardRatings::HPdefrostControl::OnDemand) {
    2714            0 :                     ShowSevereError(
    2715            0 :                         state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\" " + cAlphaFieldNames(10) + " not found:" + cAlphaArgs(10));
    2716            0 :                     ErrorsFound = true;
    2717              :                 }
    2718              :             }
    2719              :         } else {
    2720            3 :             if (thisVrfFluidCtrl.DefrostStrategy == StandardRatings::DefrostStrat::ReverseCycle &&
    2721            3 :                 thisVrfFluidCtrl.DefrostControl == StandardRatings::HPdefrostControl::OnDemand) {
    2722            0 :                 ShowSevereError(
    2723            0 :                     state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\" " + cAlphaFieldNames(10) + " not found:" + cAlphaArgs(10));
    2724            0 :                 ErrorsFound = true;
    2725              :             }
    2726              :         }
    2727              : 
    2728            3 :         thisVrfFluidCtrl.DefrostFraction = rNumericArgs(27);
    2729            3 :         thisVrfFluidCtrl.DefrostCapacity = rNumericArgs(28);
    2730            3 :         thisVrfFluidCtrl.MaxOATDefrost = rNumericArgs(29);
    2731            3 :         if (thisVrfFluidCtrl.DefrostCapacity == 0.0 && thisVrfFluidCtrl.DefrostStrategy == StandardRatings::DefrostStrat::Resistive) {
    2732            0 :             ShowWarningError(state,
    2733            0 :                              cCurrentModuleObject + ", \"" + thisVrfFluidCtrl.Name + "\" " + cNumericFieldNames(28) +
    2734              :                                  " = 0.0 for defrost strategy = RESISTIVE.");
    2735              :         }
    2736              : 
    2737            3 :         thisVrfFluidCtrl.CompMaxDeltaP = rNumericArgs(30);
    2738              : 
    2739              :         //@@ The control type
    2740            3 :         std::string ThermostatPriorityType = "LoadPriority"; // cAlphaArgs( 25 )
    2741            3 :         if (Util::SameString(ThermostatPriorityType, "LoadPriority")) {
    2742            3 :             thisVrfFluidCtrl.ThermostatPriority = ThermostatCtrlType::LoadPriority;
    2743            0 :         } else if (Util::SameString(ThermostatPriorityType, "ZonePriority")) {
    2744            0 :             thisVrfFluidCtrl.ThermostatPriority = ThermostatCtrlType::ZonePriority;
    2745            0 :         } else if (Util::SameString(ThermostatPriorityType, "ThermostatOffsetPriority")) {
    2746            0 :             thisVrfFluidCtrl.ThermostatPriority = ThermostatCtrlType::ThermostatOffsetPriority;
    2747            0 :         } else if (Util::SameString(ThermostatPriorityType, "Scheduled")) {
    2748            0 :             thisVrfFluidCtrl.ThermostatPriority = ThermostatCtrlType::ScheduledPriority;
    2749            0 :         } else if (Util::SameString(ThermostatPriorityType, "MasterThermostatPriority")) {
    2750            0 :             thisVrfFluidCtrl.ThermostatPriority = ThermostatCtrlType::MasterThermostatPriority;
    2751            0 :             if (thisVrfFluidCtrl.MasterZonePtr == 0) {
    2752            0 :                 ShowSevereError(state, cCurrentModuleObject + " = \"" + thisVrfFluidCtrl.Name + "\"");
    2753              :                 //** ShowContinueError(state,  cAlphaFieldNames( 24 ) + " must be entered when " + cAlphaFieldNames( 25 ) + " = " + cAlphaArgs( 25 )
    2754              :                 //);
    2755            0 :                 ErrorsFound = true;
    2756              :             }
    2757              :         } else {
    2758            0 :             ShowSevereError(state, cCurrentModuleObject + " = " + thisVrfFluidCtrl.Name);
    2759              :             // ShowContinueError(state,  "Illegal " + cAlphaFieldNames( 25 ) + " = " + cAlphaArgs( 25 ) );
    2760            0 :             ErrorsFound = true;
    2761              :         }
    2762              : 
    2763              :         // The new VRF model is Air cooled
    2764            3 :         thisVrfFluidCtrl.CondenserType = DataHeatBalance::RefrigCondenserType::Air;
    2765            3 :         thisVrfFluidCtrl.CondenserNodeNum = 0;
    2766              : 
    2767              :         // Evaporative Capacity & Compressor Power Curves corresponding to each Loading Index / compressor speed
    2768            3 :         int NumOfCompSpd = rNumericArgs(31);
    2769            3 :         thisVrfFluidCtrl.CompressorSpeed.dimension(NumOfCompSpd);
    2770            3 :         thisVrfFluidCtrl.OUCoolingCAPFT.dimension(NumOfCompSpd);
    2771            3 :         thisVrfFluidCtrl.OUCoolingPWRFT.dimension(NumOfCompSpd);
    2772            3 :         int Count1Index = 31; // the index of the last numeric field before compressor speed entries
    2773            3 :         int Count2Index = 9;  // the index of the last alpha field before capacity/power curves
    2774           17 :         for (int NumCompSpd = 1; NumCompSpd <= NumOfCompSpd; NumCompSpd++) {
    2775           14 :             thisVrfFluidCtrl.CompressorSpeed(NumCompSpd) = rNumericArgs(Count1Index + NumCompSpd);
    2776              : 
    2777              :             // Evaporating Capacity Curve
    2778           14 :             if (!lAlphaFieldBlanks(Count2Index + 2 * NumCompSpd)) {
    2779           14 :                 int indexOUEvapCapCurve = GetCurveIndex(state, cAlphaArgs(Count2Index + 2 * NumCompSpd)); // convert curve name to index number
    2780           14 :                 if (indexOUEvapCapCurve == 0) {                                                           // Verify curve name and type
    2781            0 :                     if (lAlphaFieldBlanks(Count2Index + 2 * NumCompSpd)) {
    2782            0 :                         ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", missing");
    2783            0 :                         ShowContinueError(state, "...required " + cAlphaFieldNames(Count2Index + 2 * NumCompSpd) + " is blank.");
    2784              :                     } else {
    2785            0 :                         ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", invalid");
    2786            0 :                         ShowContinueError(state,
    2787            0 :                                           format("...not found {}=\"{}\".",
    2788            0 :                                                  cAlphaFieldNames(Count2Index + 2 * NumCompSpd),
    2789            0 :                                                  cAlphaArgs(Count2Index + 2 * NumCompSpd)));
    2790              :                     }
    2791            0 :                     ErrorsFound = true;
    2792              :                 } else {
    2793           28 :                     ErrorsFound |= Curve::CheckCurveDims(state,
    2794              :                                                          indexOUEvapCapCurve,                             // Curve index
    2795              :                                                          {2},                                             // Valid dimensions
    2796              :                                                          RoutineName,                                     // Routine name
    2797              :                                                          cCurrentModuleObject,                            // Object Type
    2798              :                                                          thisVrfFluidCtrl.Name,                           // Object Name
    2799           14 :                                                          cAlphaFieldNames(Count2Index + 2 * NumCompSpd)); // Field Name
    2800              : 
    2801           14 :                     if (!ErrorsFound) {
    2802           14 :                         thisVrfFluidCtrl.OUCoolingCAPFT(NumCompSpd) = indexOUEvapCapCurve;
    2803              :                     }
    2804              :                 }
    2805              :             }
    2806              : 
    2807              :             // Compressor Power Curve
    2808           14 :             if (!lAlphaFieldBlanks(Count2Index + 2 * NumCompSpd + 1)) {
    2809           14 :                 int indexOUCompPwrCurve = GetCurveIndex(state, cAlphaArgs(Count2Index + 2 * NumCompSpd + 1)); // convert curve name to index number
    2810           14 :                 if (indexOUCompPwrCurve == 0) {                                                               // Verify curve name and type
    2811            0 :                     if (lAlphaFieldBlanks(Count2Index + 2 * NumCompSpd + 1)) {
    2812            0 :                         ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", missing");
    2813            0 :                         ShowContinueError(state, "...required " + cAlphaFieldNames(Count2Index + 2 * NumCompSpd + 1) + " is blank.");
    2814              :                     } else {
    2815            0 :                         ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrl.Name + "\", invalid");
    2816            0 :                         ShowContinueError(state,
    2817            0 :                                           format("...not found {}=\"{}\".",
    2818            0 :                                                  cAlphaFieldNames(Count2Index + 2 * NumCompSpd + 1),
    2819            0 :                                                  cAlphaArgs(Count2Index + 2 * NumCompSpd + 1)));
    2820              :                     }
    2821            0 :                     ErrorsFound = true;
    2822              :                 } else {
    2823           28 :                     ErrorsFound |= Curve::CheckCurveDims(state,
    2824              :                                                          indexOUCompPwrCurve,                                 // Curve index
    2825              :                                                          {2},                                                 // Valid dimensions
    2826              :                                                          RoutineName,                                         // Routine name
    2827              :                                                          cCurrentModuleObject,                                // Object Type
    2828              :                                                          thisVrfFluidCtrl.Name,                               // Object Name
    2829           14 :                                                          cAlphaFieldNames(Count2Index + 2 * NumCompSpd + 1)); // Field Name
    2830              : 
    2831           14 :                     if (!ErrorsFound) {
    2832           14 :                         thisVrfFluidCtrl.OUCoolingPWRFT(NumCompSpd) = indexOUCompPwrCurve;
    2833              :                     }
    2834              :                 }
    2835              :             }
    2836              :         }
    2837            3 :     }
    2838              : 
    2839              :     // Read all VRF condenser objects: Algorithm Type 2_physics based model (VRF-FluidTCtrl-HR)
    2840           13 :     cCurrentModuleObject = "AirConditioner:VariableRefrigerantFlow:FluidTemperatureControl:HR";
    2841           14 :     for (int thisNum = 1; thisNum <= state.dataHVACVarRefFlow->NumVRFCond_FluidTCtrl_HR; ++thisNum) {
    2842              : 
    2843            1 :         state.dataInputProcessing->inputProcessor->getObjectItem(state,
    2844              :                                                                  cCurrentModuleObject,
    2845              :                                                                  thisNum,
    2846              :                                                                  cAlphaArgs,
    2847              :                                                                  NumAlphas,
    2848              :                                                                  rNumericArgs,
    2849              :                                                                  NumNums,
    2850              :                                                                  IOStat,
    2851              :                                                                  lNumericFieldBlanks,
    2852              :                                                                  lAlphaFieldBlanks,
    2853              :                                                                  cAlphaFieldNames,
    2854              :                                                                  cNumericFieldNames);
    2855              : 
    2856            1 :         ErrorObjectHeader eoh{routineName, cCurrentModuleObject, cAlphaArgs(1)};
    2857              : 
    2858            1 :         GlobalNames::VerifyUniqueInterObjectName(
    2859            2 :             state, state.dataHVACVarRefFlow->VrfUniqueNames, cAlphaArgs(1), cCurrentModuleObject, cAlphaFieldNames(1), ErrorsFound);
    2860              : 
    2861            1 :         int VRFNum = state.dataHVACVarRefFlow->NumVRFCond_SysCurve + state.dataHVACVarRefFlow->NumVRFCond_FluidTCtrl_HP + thisNum;
    2862            1 :         auto &thisVrfFluidCtrlHR = state.dataHVACVarRefFlow->VRF(VRFNum);
    2863              : 
    2864            1 :         thisVrfFluidCtrlHR.Name = cAlphaArgs(1);
    2865              : 
    2866            1 :         thisVrfFluidCtrlHR.ThermostatPriority = ThermostatCtrlType::LoadPriority;
    2867            1 :         thisVrfFluidCtrlHR.HeatRecoveryUsed = true;
    2868            1 :         thisVrfFluidCtrlHR.VRFSystemTypeNum = VRF_HeatPump;
    2869            1 :         thisVrfFluidCtrlHR.VRFAlgorithmType = AlgorithmType::FluidTCtrl;
    2870            1 :         thisVrfFluidCtrlHR.fuel = Constant::eFuel::Electricity;
    2871              : 
    2872            1 :         if (lAlphaFieldBlanks(2)) {
    2873            0 :             thisVrfFluidCtrlHR.availSched = Sched::GetScheduleAlwaysOn(state);
    2874            1 :         } else if ((thisVrfFluidCtrlHR.availSched = Sched::GetSchedule(state, cAlphaArgs(2))) == nullptr) {
    2875            0 :             ShowSevereItemNotFound(state, eoh, cAlphaFieldNames(2), cAlphaArgs(2));
    2876            0 :             ErrorsFound = true;
    2877              :         }
    2878              : 
    2879            1 :         thisVrfFluidCtrlHR.ZoneTUListPtr =
    2880            1 :             Util::FindItemInList(cAlphaArgs(3), state.dataHVACVarRefFlow->TerminalUnitList, state.dataHVACVarRefFlow->NumVRFTULists);
    2881            1 :         if (thisVrfFluidCtrlHR.ZoneTUListPtr == 0) {
    2882            0 :             ShowSevereError(state, cCurrentModuleObject + " = \"" + thisVrfFluidCtrlHR.Name + "\"");
    2883            0 :             ShowContinueError(state, cAlphaFieldNames(3) + " = " + cAlphaArgs(3) + " not found.");
    2884            0 :             ErrorsFound = true;
    2885              :         }
    2886              : 
    2887              :         // Refrigerant type
    2888            1 :         thisVrfFluidCtrlHR.refrigName = cAlphaArgs(4);
    2889            1 :         if ((thisVrfFluidCtrlHR.refrig = Fluid::GetRefrig(state, thisVrfFluidCtrlHR.refrigName)) == nullptr) {
    2890            0 :             ShowSevereItemNotFound(state, eoh, cAlphaFieldNames(4), cAlphaArgs(4));
    2891            0 :             ErrorsFound = true;
    2892              :         }
    2893              : 
    2894            1 :         thisVrfFluidCtrlHR.RatedEvapCapacity = rNumericArgs(1);
    2895            1 :         thisVrfFluidCtrlHR.RatedCompPowerPerCapcity = rNumericArgs(2);
    2896            1 :         thisVrfFluidCtrlHR.RatedCompPower = thisVrfFluidCtrlHR.RatedCompPowerPerCapcity * thisVrfFluidCtrlHR.RatedEvapCapacity;
    2897            1 :         thisVrfFluidCtrlHR.CoolingCapacity = thisVrfFluidCtrlHR.RatedEvapCapacity;
    2898            1 :         thisVrfFluidCtrlHR.HeatingCapacity = thisVrfFluidCtrlHR.RatedEvapCapacity * (1 + thisVrfFluidCtrlHR.RatedCompPowerPerCapcity);
    2899            1 :         thisVrfFluidCtrlHR.RatedHeatCapacity = thisVrfFluidCtrlHR.HeatingCapacity;
    2900              : 
    2901              :         // Reference system COP
    2902            1 :         thisVrfFluidCtrlHR.CoolingCOP = 1 / thisVrfFluidCtrlHR.RatedCompPowerPerCapcity;
    2903            1 :         thisVrfFluidCtrlHR.HeatingCOP = 1 / thisVrfFluidCtrlHR.RatedCompPowerPerCapcity + 1;
    2904              : 
    2905              :         // OA temperature range for VRF-HP operations
    2906            1 :         thisVrfFluidCtrlHR.MinOATCooling = rNumericArgs(3);
    2907            1 :         thisVrfFluidCtrlHR.MaxOATCooling = rNumericArgs(4);
    2908            1 :         thisVrfFluidCtrlHR.MinOATHeating = rNumericArgs(5);
    2909            1 :         thisVrfFluidCtrlHR.MaxOATHeating = rNumericArgs(6);
    2910            1 :         thisVrfFluidCtrlHR.MinOATHeatRecovery = rNumericArgs(7);
    2911            1 :         thisVrfFluidCtrlHR.MaxOATHeatRecovery = rNumericArgs(8);
    2912            1 :         if (thisVrfFluidCtrlHR.MinOATCooling >= thisVrfFluidCtrlHR.MaxOATCooling) {
    2913            0 :             ShowSevereError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\"");
    2914            0 :             ShowContinueError(state,
    2915            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    2916              :                                      cNumericFieldNames(3),
    2917            0 :                                      thisVrfFluidCtrlHR.MinOATCooling,
    2918            0 :                                      thisVrfFluidCtrlHR.MaxOATCooling));
    2919            0 :             ErrorsFound = true;
    2920              :         }
    2921            1 :         if (thisVrfFluidCtrlHR.MinOATHeating >= thisVrfFluidCtrlHR.MaxOATHeating) {
    2922            0 :             ShowSevereError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\"");
    2923            0 :             ShowContinueError(state,
    2924            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    2925              :                                      cNumericFieldNames(5),
    2926            0 :                                      thisVrfFluidCtrlHR.MinOATHeating,
    2927            0 :                                      thisVrfFluidCtrlHR.MaxOATHeating));
    2928            0 :             ErrorsFound = true;
    2929              :         }
    2930            1 :         if (thisVrfFluidCtrlHR.MinOATHeatRecovery >= thisVrfFluidCtrlHR.MaxOATHeatRecovery) {
    2931            0 :             ShowSevereError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\"");
    2932            0 :             ShowContinueError(state,
    2933            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    2934              :                                      cNumericFieldNames(7),
    2935            0 :                                      thisVrfFluidCtrlHR.MinOATHeating,
    2936            0 :                                      thisVrfFluidCtrlHR.MaxOATHeating));
    2937            0 :             ErrorsFound = true;
    2938              :         }
    2939            1 :         if (thisVrfFluidCtrlHR.MinOATHeatRecovery < thisVrfFluidCtrlHR.MinOATCooling &&
    2940            1 :             thisVrfFluidCtrlHR.MinOATHeatRecovery < thisVrfFluidCtrlHR.MinOATHeating) {
    2941            0 :             ShowWarningError(state,
    2942            0 :                              cCurrentModuleObject + " = \"" + thisVrfFluidCtrlHR.Name + "\", " + cNumericFieldNames(7) +
    2943              :                                  " is less than the minimum temperature in heat pump mode.");
    2944            0 :             ShowContinueError(state, format("...{} = {:.2T} C", cNumericFieldNames(7), thisVrfFluidCtrlHR.MinOATHeatRecovery));
    2945            0 :             ShowContinueError(state, format("...Minimum Outdoor Temperature in Cooling Mode = {:.2T} C", thisVrfFluidCtrlHR.MinOATCooling));
    2946            0 :             ShowContinueError(state, format("...Minimum Outdoor Temperature in Heating Mode = {:.2T} C", thisVrfFluidCtrlHR.MinOATHeating));
    2947            0 :             ShowContinueError(state,
    2948              :                               "...Minimum Outdoor Temperature in Heat Recovery Mode reset to lesser of cooling or heating minimum temperature "
    2949              :                               "and simulation continues.");
    2950            0 :             thisVrfFluidCtrlHR.MinOATHeatRecovery = min(thisVrfFluidCtrlHR.MinOATCooling, thisVrfFluidCtrlHR.MinOATHeating);
    2951            0 :             ShowContinueError(state, format("... adjusted {} = {:.2T} C", cNumericFieldNames(7), thisVrfFluidCtrlHR.MinOATHeatRecovery));
    2952              :         }
    2953            1 :         if (thisVrfFluidCtrlHR.MaxOATHeatRecovery > thisVrfFluidCtrlHR.MaxOATCooling &&
    2954            0 :             thisVrfFluidCtrlHR.MaxOATHeatRecovery > thisVrfFluidCtrlHR.MaxOATHeating) {
    2955            0 :             ShowWarningError(state,
    2956            0 :                              cCurrentModuleObject + " = \"" + thisVrfFluidCtrlHR.Name + "\", " + cNumericFieldNames(8) +
    2957              :                                  " is greater than the maximum temperature in heat pump mode.");
    2958            0 :             ShowContinueError(state, format("...{} = {:.2T} C", cNumericFieldNames(8), thisVrfFluidCtrlHR.MaxOATHeatRecovery));
    2959            0 :             ShowContinueError(state, format("...Maximum Outdoor Temperature in Cooling Mode = {:.2T} C", thisVrfFluidCtrlHR.MaxOATCooling));
    2960            0 :             ShowContinueError(state, format("...Maximum Outdoor Temperature in Heating Mode = {:.2T} C", thisVrfFluidCtrlHR.MaxOATHeating));
    2961            0 :             ShowContinueError(state,
    2962              :                               "...Maximum Outdoor Temperature in Heat Recovery Mode reset to greater of cooling or heating maximum temperature "
    2963              :                               "and simulation continues.");
    2964            0 :             thisVrfFluidCtrlHR.MaxOATHeatRecovery = max(thisVrfFluidCtrlHR.MaxOATCooling, thisVrfFluidCtrlHR.MaxOATHeating);
    2965            0 :             ShowContinueError(state, format("... adjusted {} = {:.2T} C", cNumericFieldNames(8), thisVrfFluidCtrlHR.MaxOATHeatRecovery));
    2966              :         }
    2967              : 
    2968              :         // IU Control Type
    2969            1 :         if (Util::SameString(cAlphaArgs(5), "VariableTemp")) {
    2970            1 :             thisVrfFluidCtrlHR.AlgorithmIUCtrl = 1;
    2971            0 :         } else if (Util::SameString(cAlphaArgs(5), "ConstantTemp")) {
    2972            0 :             thisVrfFluidCtrlHR.AlgorithmIUCtrl = 2;
    2973              :         } else {
    2974            0 :             thisVrfFluidCtrlHR.AlgorithmIUCtrl = 1;
    2975              :         }
    2976              : 
    2977              :         // Reference IU Te/Tc for IU Control Algorithm: ConstantTemp
    2978            1 :         thisVrfFluidCtrlHR.EvapTempFixed = rNumericArgs(9);
    2979            1 :         thisVrfFluidCtrlHR.CondTempFixed = rNumericArgs(10);
    2980              : 
    2981              :         // Bounds of Te/Tc for IU Control Algorithm: VariableTemp
    2982            1 :         thisVrfFluidCtrlHR.IUEvapTempLow = rNumericArgs(11);
    2983            1 :         thisVrfFluidCtrlHR.IUEvapTempHigh = rNumericArgs(12);
    2984            1 :         thisVrfFluidCtrlHR.IUCondTempLow = rNumericArgs(13);
    2985            1 :         thisVrfFluidCtrlHR.IUCondTempHigh = rNumericArgs(14);
    2986            1 :         if (thisVrfFluidCtrlHR.IUEvapTempLow >= thisVrfFluidCtrlHR.IUEvapTempHigh) {
    2987            0 :             ShowSevereError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\"");
    2988            0 :             ShowContinueError(state,
    2989            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    2990              :                                      cNumericFieldNames(11),
    2991            0 :                                      thisVrfFluidCtrlHR.IUEvapTempLow,
    2992            0 :                                      thisVrfFluidCtrlHR.IUEvapTempHigh));
    2993            0 :             ErrorsFound = true;
    2994              :         }
    2995            1 :         if (thisVrfFluidCtrlHR.IUCondTempLow >= thisVrfFluidCtrlHR.IUCondTempHigh) {
    2996            0 :             ShowSevereError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\"");
    2997            0 :             ShowContinueError(state,
    2998            0 :                               format("... {} ({:.3T}) must be less than maximum ({:.3T}).",
    2999              :                                      cNumericFieldNames(13),
    3000            0 :                                      thisVrfFluidCtrlHR.IUCondTempLow,
    3001            0 :                                      thisVrfFluidCtrlHR.IUCondTempHigh));
    3002            0 :             ErrorsFound = true;
    3003              :         }
    3004              : 
    3005              :         // Reference OU SH/SC
    3006            1 :         thisVrfFluidCtrlHR.SH = rNumericArgs(15);
    3007            1 :         thisVrfFluidCtrlHR.SC = rNumericArgs(16);
    3008            1 :         if (thisVrfFluidCtrlHR.SH > 20) {
    3009            0 :             ShowWarningError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\", \" " + cNumericFieldNames(15));
    3010            0 :             ShowContinueError(state, "...is higher than 20C, which is usually the maximum of normal range.");
    3011              :         }
    3012            1 :         if (thisVrfFluidCtrlHR.SC > 20) {
    3013            0 :             ShowWarningError(state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\", \" " + cNumericFieldNames(15));
    3014            0 :             ShowContinueError(state, "...is higher than 20C, which is usually the maximum of normal range.");
    3015              :         }
    3016              : 
    3017              :         // OU Heat Exchanger Rated Bypass Factor
    3018            1 :         thisVrfFluidCtrlHR.RateBFOUEvap = rNumericArgs(17);
    3019            1 :         thisVrfFluidCtrlHR.RateBFOUCond = rNumericArgs(18);
    3020              : 
    3021              :         // Difference between Outdoor Unit Te and OAT during Simultaneous Heating and Cooling operations
    3022            1 :         thisVrfFluidCtrlHR.DiffOUTeTo = rNumericArgs(19);
    3023              : 
    3024              :         // HR OU Heat Exchanger Capacity Ratio
    3025            1 :         thisVrfFluidCtrlHR.HROUHexRatio = rNumericArgs(20);
    3026              : 
    3027              :         // Get OU fan data
    3028            1 :         thisVrfFluidCtrlHR.RatedOUFanPowerPerCapcity = rNumericArgs(21);
    3029            1 :         thisVrfFluidCtrlHR.OUAirFlowRatePerCapcity = rNumericArgs(22);
    3030            1 :         thisVrfFluidCtrlHR.RatedOUFanPower = thisVrfFluidCtrlHR.RatedOUFanPowerPerCapcity * thisVrfFluidCtrlHR.RatedEvapCapacity;
    3031            1 :         thisVrfFluidCtrlHR.OUAirFlowRate = thisVrfFluidCtrlHR.OUAirFlowRatePerCapcity * thisVrfFluidCtrlHR.RatedEvapCapacity;
    3032              : 
    3033              :         // OUEvapTempCurve
    3034            1 :         int indexOUEvapTempCurve = GetCurveIndex(state, cAlphaArgs(6)); // convert curve name to index number
    3035              :         // Verify curve name and type
    3036            1 :         if (indexOUEvapTempCurve == 0) {
    3037            0 :             if (lAlphaFieldBlanks(6)) {
    3038            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", missing");
    3039            0 :                 ShowContinueError(state, "...required " + cAlphaFieldNames(6) + " is blank.");
    3040              :             } else {
    3041            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", invalid");
    3042            0 :                 ShowContinueError(state, "...not found " + cAlphaFieldNames(6) + "=\"" + cAlphaArgs(6) + "\".");
    3043              :             }
    3044            0 :             ErrorsFound = true;
    3045              :         } else {
    3046            1 :             if (state.dataCurveManager->curves(indexOUEvapTempCurve)->curveType == Curve::CurveType::Quadratic) {
    3047            1 :                 thisVrfFluidCtrlHR.C1Te = state.dataCurveManager->curves(indexOUEvapTempCurve)->coeff[0];
    3048            1 :                 thisVrfFluidCtrlHR.C2Te = state.dataCurveManager->curves(indexOUEvapTempCurve)->coeff[1];
    3049            1 :                 thisVrfFluidCtrlHR.C3Te = state.dataCurveManager->curves(indexOUEvapTempCurve)->coeff[2];
    3050              :             } else {
    3051            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", invalid");
    3052            0 :                 ShowContinueError(state,
    3053            0 :                                   format("...illegal {} type for this object = {}",
    3054              :                                          cAlphaFieldNames(6),
    3055            0 :                                          Curve::objectNames[static_cast<int>(state.dataCurveManager->curves(indexOUEvapTempCurve)->curveType)]));
    3056            0 :                 ShowContinueError(state, "... Curve type must be Quadratic.");
    3057            0 :                 ErrorsFound = true;
    3058              :             }
    3059              :         }
    3060              : 
    3061              :         // OUCondTempCurve
    3062            1 :         int indexOUCondTempCurve = GetCurveIndex(state, cAlphaArgs(7)); // convert curve name to index number
    3063              :         // Verify curve name and type
    3064            1 :         if (indexOUCondTempCurve == 0) {
    3065            0 :             if (lAlphaFieldBlanks(7)) {
    3066            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", missing");
    3067            0 :                 ShowContinueError(state, "...required " + cAlphaFieldNames(7) + " is blank.");
    3068              :             } else {
    3069            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", invalid");
    3070            0 :                 ShowContinueError(state, "...not found " + cAlphaFieldNames(7) + "=\"" + cAlphaArgs(7) + "\".");
    3071              :             }
    3072            0 :             ErrorsFound = true;
    3073              :         } else {
    3074            1 :             if (state.dataCurveManager->curves(indexOUCondTempCurve)->curveType == Curve::CurveType::Quadratic) {
    3075            1 :                 thisVrfFluidCtrlHR.C1Tc = state.dataCurveManager->curves(indexOUCondTempCurve)->coeff[0];
    3076            1 :                 thisVrfFluidCtrlHR.C2Tc = state.dataCurveManager->curves(indexOUCondTempCurve)->coeff[1];
    3077            1 :                 thisVrfFluidCtrlHR.C3Tc = state.dataCurveManager->curves(indexOUCondTempCurve)->coeff[2];
    3078              :             } else {
    3079            0 :                 ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", invalid");
    3080            0 :                 ShowContinueError(state,
    3081            0 :                                   format("...illegal {} type for this object = {}",
    3082              :                                          cAlphaFieldNames(7),
    3083            0 :                                          Curve::objectNames[static_cast<int>(state.dataCurveManager->curves(indexOUCondTempCurve)->curveType)]));
    3084            0 :                 ShowContinueError(state, "... Curve type must be Quadratic.");
    3085            0 :                 ErrorsFound = true;
    3086              :             }
    3087              :         }
    3088              : 
    3089              :         // Pipe parameters
    3090            1 :         thisVrfFluidCtrlHR.RefPipDiaSuc = rNumericArgs(23);
    3091            1 :         thisVrfFluidCtrlHR.RefPipDiaDis = rNumericArgs(24);
    3092            1 :         thisVrfFluidCtrlHR.RefPipLen = rNumericArgs(25);
    3093            1 :         thisVrfFluidCtrlHR.RefPipEquLen = rNumericArgs(26);
    3094            1 :         thisVrfFluidCtrlHR.RefPipHei = rNumericArgs(27);
    3095            1 :         thisVrfFluidCtrlHR.RefPipInsThi = rNumericArgs(28);
    3096            1 :         thisVrfFluidCtrlHR.RefPipInsCon = rNumericArgs(29);
    3097              : 
    3098              :         // Check the RefPipEquLen
    3099            1 :         if (lNumericFieldBlanks(26) && !lNumericFieldBlanks(25)) {
    3100            0 :             thisVrfFluidCtrlHR.RefPipEquLen = 1.2 * thisVrfFluidCtrlHR.RefPipLen;
    3101            0 :             ShowWarningError(
    3102            0 :                 state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\", \" " + cNumericFieldNames(26) + "\" is calculated based on");
    3103            0 :             ShowContinueError(state, "...the provided \"" + cNumericFieldNames(25) + "\" value.");
    3104              :         }
    3105            1 :         if (thisVrfFluidCtrlHR.RefPipEquLen < thisVrfFluidCtrlHR.RefPipLen) {
    3106            0 :             thisVrfFluidCtrlHR.RefPipEquLen = 1.2 * thisVrfFluidCtrlHR.RefPipLen;
    3107            0 :             ShowWarningError(state,
    3108            0 :                              cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\", invalid \" " + cNumericFieldNames(26) + "\" value.");
    3109            0 :             ShowContinueError(state, "...Equivalent length of main pipe should be greater than or equal to the actual length.");
    3110            0 :             ShowContinueError(state, format("...The value is recalculated based on the provided \"{}\" value.", cNumericFieldNames(25)));
    3111              :         }
    3112              : 
    3113              :         // Crank case
    3114            1 :         thisVrfFluidCtrlHR.CCHeaterPower = rNumericArgs(30);
    3115            1 :         thisVrfFluidCtrlHR.NumCompressors = rNumericArgs(31);
    3116            1 :         thisVrfFluidCtrlHR.CompressorSizeRatio = rNumericArgs(32);
    3117            1 :         thisVrfFluidCtrlHR.MaxOATCCHeater = rNumericArgs(33);
    3118              : 
    3119              :         // Defrost
    3120            1 :         if (!lAlphaFieldBlanks(8)) {
    3121            0 :             if (Util::SameString(cAlphaArgs(8), "ReverseCycle")) {
    3122            0 :                 thisVrfFluidCtrlHR.DefrostStrategy = StandardRatings::DefrostStrat::ReverseCycle;
    3123              :             }
    3124            0 :             if (Util::SameString(cAlphaArgs(8), "Resistive")) {
    3125            0 :                 thisVrfFluidCtrlHR.DefrostStrategy = StandardRatings::DefrostStrat::Resistive;
    3126              :             }
    3127            0 :             if (thisVrfFluidCtrlHR.DefrostStrategy == StandardRatings::DefrostStrat::Invalid) {
    3128            0 :                 ShowSevereError(
    3129            0 :                     state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\" " + cAlphaFieldNames(8) + " not found: " + cAlphaArgs(8));
    3130            0 :                 ErrorsFound = true;
    3131              :             }
    3132              :         } else {
    3133            1 :             thisVrfFluidCtrlHR.DefrostStrategy = StandardRatings::DefrostStrat::ReverseCycle;
    3134              :         }
    3135              : 
    3136            1 :         if (!lAlphaFieldBlanks(9)) {
    3137            0 :             if (Util::SameString(cAlphaArgs(9), "Timed")) {
    3138            0 :                 thisVrfFluidCtrlHR.DefrostControl = StandardRatings::HPdefrostControl::Timed;
    3139              :             }
    3140            0 :             if (Util::SameString(cAlphaArgs(9), "OnDemand")) {
    3141            0 :                 thisVrfFluidCtrlHR.DefrostControl = StandardRatings::HPdefrostControl::OnDemand;
    3142              :             }
    3143            0 :             if (thisVrfFluidCtrlHR.DefrostControl == StandardRatings::HPdefrostControl::Invalid) {
    3144            0 :                 ShowSevereError(
    3145            0 :                     state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\" " + cAlphaFieldNames(9) + " not found: " + cAlphaArgs(9));
    3146            0 :                 ErrorsFound = true;
    3147              :             }
    3148              :         } else {
    3149            1 :             thisVrfFluidCtrlHR.DefrostControl = StandardRatings::HPdefrostControl::Timed;
    3150              :         }
    3151              : 
    3152            1 :         if (!lAlphaFieldBlanks(10)) {
    3153            0 :             thisVrfFluidCtrlHR.DefrostEIRPtr = GetCurveIndex(state, cAlphaArgs(10));
    3154            0 :             if (thisVrfFluidCtrlHR.DefrostEIRPtr > 0) {
    3155              :                 // Verify Curve Object, expected type is BiQuadratic
    3156            0 :                 ErrorsFound |= Curve::CheckCurveDims(state,
    3157              :                                                      thisVrfFluidCtrlHR.DefrostEIRPtr, // Curve index
    3158              :                                                      {2},                              // Valid dimensions
    3159              :                                                      RoutineName,                      // Routine name
    3160              :                                                      cCurrentModuleObject,             // Object Type
    3161              :                                                      thisVrfFluidCtrlHR.Name,          // Object Name
    3162            0 :                                                      cAlphaFieldNames(10));            // Field Name
    3163              :             } else {
    3164            0 :                 if (thisVrfFluidCtrlHR.DefrostStrategy == StandardRatings::DefrostStrat::ReverseCycle &&
    3165            0 :                     thisVrfFluidCtrlHR.DefrostControl == StandardRatings::HPdefrostControl::OnDemand) {
    3166            0 :                     ShowSevereError(state,
    3167            0 :                                     cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\" " + cAlphaFieldNames(10) +
    3168            0 :                                         " not found:" + cAlphaArgs(10));
    3169            0 :                     ErrorsFound = true;
    3170              :                 }
    3171              :             }
    3172              :         } else {
    3173            1 :             if (thisVrfFluidCtrlHR.DefrostStrategy == StandardRatings::DefrostStrat::ReverseCycle &&
    3174            1 :                 thisVrfFluidCtrlHR.DefrostControl == StandardRatings::HPdefrostControl::OnDemand) {
    3175            0 :                 ShowSevereError(
    3176            0 :                     state, cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\" " + cAlphaFieldNames(10) + " not found:" + cAlphaArgs(10));
    3177            0 :                 ErrorsFound = true;
    3178              :             }
    3179              :         }
    3180              : 
    3181            1 :         thisVrfFluidCtrlHR.DefrostFraction = rNumericArgs(34);
    3182            1 :         thisVrfFluidCtrlHR.DefrostCapacity = rNumericArgs(35);
    3183            1 :         thisVrfFluidCtrlHR.MaxOATDefrost = rNumericArgs(36);
    3184            1 :         if (thisVrfFluidCtrlHR.DefrostCapacity == 0.0 && thisVrfFluidCtrlHR.DefrostStrategy == StandardRatings::DefrostStrat::Resistive) {
    3185            0 :             ShowWarningError(state,
    3186            0 :                              cCurrentModuleObject + ", \"" + thisVrfFluidCtrlHR.Name + "\" " + cNumericFieldNames(35) +
    3187              :                                  " = 0.0 for defrost strategy = RESISTIVE.");
    3188              :         }
    3189              : 
    3190              :         // HR mode transition
    3191            1 :         thisVrfFluidCtrlHR.HRInitialCoolCapFrac = rNumericArgs(37);
    3192            1 :         thisVrfFluidCtrlHR.HRCoolCapTC = rNumericArgs(38);
    3193            1 :         thisVrfFluidCtrlHR.HRInitialCoolEIRFrac = rNumericArgs(39);
    3194            1 :         thisVrfFluidCtrlHR.HRCoolEIRTC = rNumericArgs(40);
    3195            1 :         thisVrfFluidCtrlHR.HRInitialHeatCapFrac = rNumericArgs(41);
    3196            1 :         thisVrfFluidCtrlHR.HRHeatCapTC = rNumericArgs(42);
    3197            1 :         thisVrfFluidCtrlHR.HRInitialHeatEIRFrac = rNumericArgs(43);
    3198            1 :         thisVrfFluidCtrlHR.HRHeatEIRTC = rNumericArgs(44);
    3199              : 
    3200              :         // Compressor configuration
    3201            1 :         thisVrfFluidCtrlHR.CompMaxDeltaP = rNumericArgs(45);
    3202            1 :         thisVrfFluidCtrlHR.EffCompInverter = rNumericArgs(46);
    3203            1 :         thisVrfFluidCtrlHR.CoffEvapCap = rNumericArgs(47);
    3204              : 
    3205              :         // The new VRF model is Air cooled
    3206            1 :         thisVrfFluidCtrlHR.CondenserType = DataHeatBalance::RefrigCondenserType::Air;
    3207            1 :         thisVrfFluidCtrlHR.CondenserNodeNum = 0;
    3208              : 
    3209              :         // Evaporative Capacity & Compressor Power Curves corresponding to each Loading Index / compressor speed
    3210            1 :         int NumOfCompSpd = rNumericArgs(48);
    3211            1 :         thisVrfFluidCtrlHR.CompressorSpeed.dimension(NumOfCompSpd);
    3212            1 :         thisVrfFluidCtrlHR.OUCoolingCAPFT.dimension(NumOfCompSpd);
    3213            1 :         thisVrfFluidCtrlHR.OUCoolingPWRFT.dimension(NumOfCompSpd);
    3214            1 :         int Count1Index = 48; // the index of the last numeric field before compressor speed entries
    3215            1 :         int Count2Index = 9;  // the index of the last alpha field before capacity/power curves
    3216            4 :         for (int NumCompSpd = 1; NumCompSpd <= NumOfCompSpd; NumCompSpd++) {
    3217            3 :             thisVrfFluidCtrlHR.CompressorSpeed(NumCompSpd) = rNumericArgs(Count1Index + NumCompSpd);
    3218              : 
    3219              :             // Evaporating Capacity Curve
    3220            3 :             if (!lAlphaFieldBlanks(Count2Index + 2 * NumCompSpd)) {
    3221            3 :                 int indexOUEvapCapCurve = GetCurveIndex(state, cAlphaArgs(Count2Index + 2 * NumCompSpd)); // convert curve name to index number
    3222            3 :                 if (indexOUEvapCapCurve == 0) {                                                           // Verify curve name and type
    3223            0 :                     if (lAlphaFieldBlanks(Count2Index + 2 * NumCompSpd)) {
    3224            0 :                         ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", missing");
    3225            0 :                         ShowContinueError(state, "...required " + cAlphaFieldNames(Count2Index + 2 * NumCompSpd) + " is blank.");
    3226              :                     } else {
    3227            0 :                         ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", invalid");
    3228            0 :                         ShowContinueError(state,
    3229            0 :                                           format("...not found {}=\"{}\".",
    3230            0 :                                                  cAlphaFieldNames(Count2Index + 2 * NumCompSpd),
    3231            0 :                                                  cAlphaArgs(Count2Index + 2 * NumCompSpd)));
    3232              :                     }
    3233            0 :                     ErrorsFound = true;
    3234              :                 } else {
    3235            6 :                     ErrorsFound |= Curve::CheckCurveDims(state,
    3236              :                                                          indexOUEvapCapCurve,                             // Curve index
    3237              :                                                          {2},                                             // Valid dimensions
    3238              :                                                          RoutineName,                                     // Routine name
    3239              :                                                          cCurrentModuleObject,                            // Object Type
    3240              :                                                          thisVrfFluidCtrlHR.Name,                         // Object Name
    3241            3 :                                                          cAlphaFieldNames(Count2Index + 2 * NumCompSpd)); // Field Name
    3242              : 
    3243            3 :                     if (!ErrorsFound) {
    3244            3 :                         thisVrfFluidCtrlHR.OUCoolingCAPFT(NumCompSpd) = indexOUEvapCapCurve;
    3245              :                     }
    3246              :                 }
    3247              :             }
    3248              : 
    3249              :             // Compressor Power Curve
    3250            3 :             if (!lAlphaFieldBlanks(Count2Index + 2 * NumCompSpd + 1)) {
    3251            3 :                 int indexOUCompPwrCurve = GetCurveIndex(state, cAlphaArgs(Count2Index + 2 * NumCompSpd + 1)); // convert curve name to index number
    3252            3 :                 if (indexOUCompPwrCurve == 0) {                                                               // Verify curve name and type
    3253            0 :                     if (lAlphaFieldBlanks(Count2Index + 2 * NumCompSpd + 1)) {
    3254            0 :                         ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", missing");
    3255            0 :                         ShowContinueError(state, "...required " + cAlphaFieldNames(Count2Index + 2 * NumCompSpd + 1) + " is blank.");
    3256              :                     } else {
    3257            0 :                         ShowSevereError(state, std::string{RoutineName} + cCurrentModuleObject + "=\"" + thisVrfFluidCtrlHR.Name + "\", invalid");
    3258            0 :                         ShowContinueError(state,
    3259            0 :                                           format("...not found {}=\"{}\".",
    3260            0 :                                                  cAlphaFieldNames(Count2Index + 2 * NumCompSpd + 1),
    3261            0 :                                                  cAlphaArgs(Count2Index + 2 * NumCompSpd + 1)));
    3262              :                     }
    3263            0 :                     ErrorsFound = true;
    3264              :                 } else {
    3265            6 :                     ErrorsFound |= Curve::CheckCurveDims(state,
    3266              :                                                          indexOUCompPwrCurve,                                 // Curve index
    3267              :                                                          {2},                                                 // Valid dimensions
    3268              :                                                          RoutineName,                                         // Routine name
    3269              :                                                          cCurrentModuleObject,                                // Object Type
    3270              :                                                          thisVrfFluidCtrlHR.Name,                             // Object Name
    3271            3 :                                                          cAlphaFieldNames(Count2Index + 2 * NumCompSpd + 1)); // Field Name
    3272              : 
    3273            3 :                     if (!ErrorsFound) {
    3274            3 :                         thisVrfFluidCtrlHR.OUCoolingPWRFT(NumCompSpd) = indexOUCompPwrCurve;
    3275              :                     }
    3276              :                 }
    3277              :             }
    3278              :         }
    3279              :     }
    3280              : 
    3281           13 :     cCurrentModuleObject = "ZoneHVAC:TerminalUnit:VariableRefrigerantFlow";
    3282           75 :     for (int VRFTUNum = 1; VRFTUNum <= state.dataHVACVarRefFlow->NumVRFTU; ++VRFTUNum) {
    3283              : 
    3284              :         //     initialize local node number variables
    3285           62 :         int CCoilInletNodeNum = 0;
    3286           62 :         int CCoilOutletNodeNum = 0;
    3287           62 :         int HCoilInletNodeNum = 0;
    3288           62 :         int HCoilOutletNodeNum = 0;
    3289           62 :         OANodeNums = 0;
    3290              : 
    3291           62 :         state.dataInputProcessing->inputProcessor->getObjectItem(state,
    3292              :                                                                  cCurrentModuleObject,
    3293              :                                                                  VRFTUNum,
    3294              :                                                                  cAlphaArgs,
    3295              :                                                                  NumAlphas,
    3296              :                                                                  rNumericArgs,
    3297              :                                                                  NumNums,
    3298              :                                                                  IOStat,
    3299              :                                                                  lNumericFieldBlanks,
    3300              :                                                                  lAlphaFieldBlanks,
    3301              :                                                                  cAlphaFieldNames,
    3302              :                                                                  cNumericFieldNames);
    3303              : 
    3304           62 :         ErrorObjectHeader eoh{routineName, cCurrentModuleObject, cAlphaArgs(1)};
    3305              : 
    3306           62 :         state.dataHVACVarRefFlow->VRFTUNumericFields(VRFTUNum).FieldNames.allocate(NumNums);
    3307           62 :         state.dataHVACVarRefFlow->VRFTUNumericFields(VRFTUNum).FieldNames = cNumericFieldNames;
    3308           62 :         Util::IsNameEmpty(state, cAlphaArgs(1), cCurrentModuleObject, ErrorsFound);
    3309              : 
    3310           62 :         auto &thisVrfTU = state.dataHVACVarRefFlow->VRFTU(VRFTUNum);
    3311           62 :         thisVrfTU.Name = cAlphaArgs(1);
    3312           63 :         for (int NumList = 1; NumList <= state.dataHVACVarRefFlow->NumVRFTULists; ++NumList) {
    3313           63 :             int ZoneTerminalUnitListNum = Util::FindItemInList(thisVrfTU.Name,
    3314           63 :                                                                state.dataHVACVarRefFlow->TerminalUnitList(NumList).ZoneTUName,
    3315           63 :                                                                state.dataHVACVarRefFlow->TerminalUnitList(NumList).NumTUInList);
    3316           63 :             if (ZoneTerminalUnitListNum > 0) {
    3317           62 :                 thisVrfTU.IndexToTUInTUList = ZoneTerminalUnitListNum;
    3318           62 :                 state.dataHVACVarRefFlow->TerminalUnitList(NumList).ZoneTUPtr(ZoneTerminalUnitListNum) = VRFTUNum;
    3319           62 :                 thisVrfTU.TUListIndex = NumList;
    3320           62 :                 break;
    3321              :             }
    3322              :         }
    3323           62 :         if (thisVrfTU.TUListIndex == 0) {
    3324            0 :             ShowSevereError(state, cCurrentModuleObject + " = " + thisVrfTU.Name);
    3325            0 :             ShowContinueError(state, "Terminal unit not found on any ZoneTerminalUnitList.");
    3326            0 :             ErrorsFound = true;
    3327              :         }
    3328              : 
    3329           63 :         for (int NumCond = 1; NumCond <= state.dataHVACVarRefFlow->NumVRFCond; ++NumCond) {
    3330           63 :             if (state.dataHVACVarRefFlow->VRF(NumCond).ZoneTUListPtr != thisVrfTU.TUListIndex) {
    3331            1 :                 continue;
    3332              :             }
    3333           62 :             thisVrfTU.VRFSysNum = NumCond;
    3334           62 :             break;
    3335              :         }
    3336           62 :         thisVrfTU.type = TUType::ConstantVolume;
    3337           62 :         if (lAlphaFieldBlanks(2)) {
    3338            5 :             thisVrfTU.availSched = Sched::GetScheduleAlwaysOn(state);
    3339           57 :         } else if ((thisVrfTU.availSched = Sched::GetSchedule(state, cAlphaArgs(2))) == nullptr) {
    3340            0 :             ShowSevereItemNotFound(state, eoh, cAlphaFieldNames(2), cAlphaArgs(2));
    3341            0 :             ErrorsFound = true;
    3342              :         }
    3343              : 
    3344           62 :         thisVrfTU.VRFTUInletNodeNum = GetOnlySingleNode(state,
    3345           62 :                                                         cAlphaArgs(3),
    3346              :                                                         ErrorsFound,
    3347              :                                                         DataLoopNode::ConnectionObjectType::ZoneHVACTerminalUnitVariableRefrigerantFlow,
    3348           62 :                                                         thisVrfTU.Name,
    3349              :                                                         DataLoopNode::NodeFluidType::Air,
    3350              :                                                         DataLoopNode::ConnectionType::Inlet,
    3351              :                                                         NodeInputManager::CompFluidStream::Primary,
    3352              :                                                         ObjectIsParent);
    3353              : 
    3354           62 :         thisVrfTU.VRFTUOutletNodeNum = GetOnlySingleNode(state,
    3355           62 :                                                          cAlphaArgs(4),
    3356              :                                                          ErrorsFound,
    3357              :                                                          DataLoopNode::ConnectionObjectType::ZoneHVACTerminalUnitVariableRefrigerantFlow,
    3358           62 :                                                          thisVrfTU.Name,
    3359              :                                                          DataLoopNode::NodeFluidType::Air,
    3360              :                                                          DataLoopNode::ConnectionType::Outlet,
    3361              :                                                          NodeInputManager::CompFluidStream::Primary,
    3362              :                                                          ObjectIsParent);
    3363              : 
    3364           62 :         thisVrfTU.MaxCoolAirVolFlow = rNumericArgs(1);
    3365           62 :         thisVrfTU.MaxNoCoolAirVolFlow = rNumericArgs(2);
    3366           62 :         thisVrfTU.MaxHeatAirVolFlow = rNumericArgs(3);
    3367           62 :         thisVrfTU.MaxNoHeatAirVolFlow = rNumericArgs(4);
    3368           62 :         thisVrfTU.CoolOutAirVolFlow = rNumericArgs(5);
    3369           62 :         thisVrfTU.HeatOutAirVolFlow = rNumericArgs(6);
    3370           62 :         thisVrfTU.NoCoolHeatOutAirVolFlow = rNumericArgs(7);
    3371              : 
    3372           62 :         if (lAlphaFieldBlanks(5)) {
    3373            1 :             thisVrfTU.fanOp = HVAC::FanOp::Continuous;
    3374           61 :         } else if ((thisVrfTU.fanOpModeSched = Sched::GetSchedule(state, cAlphaArgs(5))) == nullptr) {
    3375            0 :             ShowWarningItemNotFound(
    3376            0 :                 state, eoh, cAlphaFieldNames(5), cAlphaArgs(5), "Defaulting to constant fan operating mode and simulation continues.");
    3377            0 :             thisVrfTU.fanOp = HVAC::FanOp::Continuous;
    3378              :         }
    3379              : 
    3380           62 :         thisVrfTU.fanPlace = static_cast<HVAC::FanPlace>(getEnumValue(HVAC::fanPlaceNamesUC, cAlphaArgs(6)));
    3381           62 :         assert(thisVrfTU.fanPlace != HVAC::FanPlace::Invalid);
    3382              : 
    3383           62 :         if (!lAlphaFieldBlanks(7) && !lAlphaFieldBlanks(8)) {
    3384              :             // Get fan data
    3385           61 :             std::string FanName = cAlphaArgs(8);
    3386              : 
    3387           61 :             thisVrfTU.fanType = static_cast<HVAC::FanType>(getEnumValue(HVAC::fanTypeNamesUC, cAlphaArgs(7)));
    3388              : 
    3389           61 :             if (thisVrfTU.fanType != HVAC::FanType::OnOff && thisVrfTU.fanType != HVAC::FanType::Constant &&
    3390           33 :                 thisVrfTU.fanType != HVAC::FanType::VAV && thisVrfTU.fanType != HVAC::FanType::SystemModel) {
    3391            0 :                 ShowSevereInvalidKey(state,
    3392              :                                      eoh,
    3393            0 :                                      cAlphaFieldNames(7),
    3394            0 :                                      cAlphaArgs(7),
    3395              :                                      "Only types Fan:ConstantVolume, Fan:VAV, Fan:OnOff, and Fan:SystemModel are supported");
    3396            0 :                 ErrorsFound = true;
    3397              :             }
    3398              : 
    3399           61 :             if ((thisVrfTU.FanIndex = Fans::GetFanIndex(state, FanName)) == 0) {
    3400            0 :                 ShowSevereItemNotFound(state, eoh, cAlphaFieldNames(8), FanName);
    3401            0 :                 ErrorsFound = true;
    3402              : 
    3403           61 :             } else if (thisVrfTU.fanType != state.dataFans->fans(thisVrfTU.FanIndex)->type) {
    3404            0 :                 ShowSevereError(state, cCurrentModuleObject + " = " + thisVrfTU.Name);
    3405            0 :                 ShowContinueError(state, "Fan type specified = " + cAlphaArgs(7));
    3406            0 :                 ShowContinueError(state, format("Actual type of fan {} = {}", FanName, HVAC::fanTypeNames[(int)thisVrfTU.fanType]));
    3407            0 :                 ErrorsFound = true;
    3408              :             }
    3409              : 
    3410           61 :             if (thisVrfTU.VRFSysNum > 0) {
    3411              :                 // VRFTU Supply Air Fan Object Type must be Fan:VariableVolume if VRF Algorithm Type is AlgorithmTypeFluidTCtrl
    3412           77 :                 if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFAlgorithmType == AlgorithmType::FluidTCtrl &&
    3413           16 :                     !(thisVrfTU.fanType == HVAC::FanType::VAV || thisVrfTU.fanType == HVAC::FanType::SystemModel)) {
    3414            0 :                     ShowSevereError(state, cCurrentModuleObject + " = " + thisVrfTU.Name);
    3415            0 :                     ShowContinueError(state, "Fan type specified = " + cAlphaArgs(7));
    3416            0 :                     ShowContinueError(
    3417              :                         state, "Fan Object Type must be Fan:VariableVolume if VRF AirConditioner:VariableRefrigerantFlow:FluidTemperatureControl");
    3418            0 :                     ShowContinueError(state, "is used to model VRF outdoor unit.");
    3419            0 :                     ErrorsFound = true;
    3420              :                 }
    3421              :                 // VRFTU Supply Air Fan Object Type must be Fan:OnOff or Fan:ConstantVolume if VRF Algorithm Type is AlgorithmTypeSysCurve
    3422          106 :                 if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFAlgorithmType == AlgorithmType::SysCurve &&
    3423           45 :                     !(thisVrfTU.fanType == HVAC::FanType::OnOff || thisVrfTU.fanType == HVAC::FanType::Constant ||
    3424           17 :                       thisVrfTU.fanType == HVAC::FanType::SystemModel)) {
    3425            0 :                     ShowSevereError(state, cCurrentModuleObject + " = " + thisVrfTU.Name);
    3426            0 :                     ShowContinueError(state, "Fan type specified = " + cAlphaArgs(7));
    3427            0 :                     ShowContinueError(state,
    3428              :                                       "Fan Object Type must be Fan:SystemModel, Fan:OnOff, or Fan:ConstantVolume if VRF "
    3429              :                                       "AirConditioner:VariableRefrigerantFlow");
    3430            0 :                     ShowContinueError(state, "is used to model VRF outdoor unit.");
    3431            0 :                     ErrorsFound = true;
    3432              :                 }
    3433              :             }
    3434              : 
    3435           61 :             auto *fan = state.dataFans->fans(thisVrfTU.FanIndex);
    3436              : 
    3437           61 :             thisVrfTU.fanInletNode = fan->inletNodeNum;
    3438           61 :             thisVrfTU.fanOutletNode = fan->outletNodeNum;
    3439              : 
    3440           61 :             Real64 FanVolFlowRate = fan->maxAirFlowRate;
    3441           61 :             thisVrfTU.ActualFanVolFlowRate = FanVolFlowRate;
    3442           61 :             int FanInletNodeNum = fan->inletNodeNum;
    3443           61 :             int FanOutletNodeNum = fan->outletNodeNum;
    3444           61 :             thisVrfTU.fanAvailSched = fan->availSched;
    3445              : 
    3446              :             // Check fan's schedule for cycling fan operation if constant volume fan is used
    3447           61 :             if (thisVrfTU.fanOpModeSched != nullptr && thisVrfTU.fanType == HVAC::FanType::Constant) {
    3448            8 :                 if (!thisVrfTU.fanOpModeSched->checkMinMaxVals(state, Clusive::Ex, 0.0, Clusive::In, 1.0)) {
    3449            0 :                     Sched::ShowSevereBadMinMax(state,
    3450              :                                                eoh,
    3451            0 :                                                cAlphaFieldNames(5),
    3452            0 :                                                cAlphaArgs(5),
    3453              :                                                Clusive::Ex,
    3454              :                                                0.0,
    3455              :                                                Clusive::In,
    3456              :                                                1.0,
    3457            0 :                                                format("For fan type = {}, operating mode must be continuous (schedule values > 0).",
    3458            0 :                                                       HVAC::fanTypeNames[(int)HVAC::FanType::Constant]));
    3459            0 :                     ErrorsFound = true;
    3460              :                 }
    3461              :             } // IF (FanType_Num == HVAC::FanType_SimpleOnOff .OR. FanType_Num == HVAC::FanType_SimpleConstVolume)THEN
    3462              : 
    3463              :             // Add TU to component sets array
    3464          183 :             SetUpCompSets(state,
    3465              :                           cCurrentModuleObject,
    3466              :                           thisVrfTU.Name,
    3467           61 :                           HVAC::fanTypeNames[(int)thisVrfTU.fanType],
    3468              :                           FanName,
    3469           61 :                           state.dataLoopNodes->NodeID(FanInletNodeNum),
    3470           61 :                           state.dataLoopNodes->NodeID(FanOutletNodeNum));
    3471              : 
    3472           61 :         } else {
    3473            1 :             thisVrfTU.fanPlace = HVAC::FanPlace::Invalid; // reset fan placement when fan is not used so as not to call the fan
    3474            1 :             thisVrfTU.fanAvailSched =
    3475            1 :                 Sched::GetScheduleAlwaysOn(state); // A missing fan is the same as a fan that is always on for availability purposes
    3476              :         }
    3477              : 
    3478              :         // Get OA mixer data
    3479           62 :         std::string OAMixerType = cAlphaArgs(9);
    3480              : 
    3481           62 :         if (!lAlphaFieldBlanks(10)) {
    3482           51 :             thisVrfTU.OAMixerName = cAlphaArgs(10);
    3483           51 :             errFlag = false;
    3484           51 :             OANodeNums = GetOAMixerNodeNumbers(state, thisVrfTU.OAMixerName, errFlag);
    3485              : 
    3486              :             //       OANodeNums(1) = OAMixer(OAMixerNum)%InletNode
    3487              :             //       OANodeNums(2) = OAMixer(OAMixerNum)%RelNode
    3488              :             //       OANodeNums(3) = OAMixer(OAMixerNum)%RetNode
    3489              :             //       OANodeNums(4) = OAMixer(OAMixerNum)%MixNode
    3490              : 
    3491           51 :             if (errFlag) {
    3492            0 :                 ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    3493            0 :                 ErrorsFound = true;
    3494              :             } else {
    3495           51 :                 thisVrfTU.OAMixerUsed = true;
    3496              :             }
    3497           51 :             thisVrfTU.VRFTUOAMixerOANodeNum = OANodeNums(1);
    3498           51 :             thisVrfTU.VRFTUOAMixerRelNodeNum = OANodeNums(2);
    3499           51 :             thisVrfTU.VRFTUOAMixerRetNodeNum = OANodeNums(3);
    3500           51 :             thisVrfTU.VRFTUOAMixerMixedNodeNum = OANodeNums(4);
    3501              :         }
    3502              : 
    3503              :         // Get DX cooling coil data
    3504           62 :         std::string DXCoolingCoilType = cAlphaArgs(11);
    3505              : 
    3506           62 :         errFlag = false;
    3507           62 :         thisVrfTU.DXCoolCoilType_Num = GetCoilTypeNum(state, DXCoolingCoilType, cAlphaArgs(12), errFlag, false);
    3508           62 :         if (thisVrfTU.DXCoolCoilType_Num == 0) {
    3509            0 :             thisVrfTU.CoolingCoilPresent = false;
    3510            0 :             if (thisVrfTU.TUListIndex > 0 && thisVrfTU.IndexToTUInTUList > 0) {
    3511            0 :                 state.dataHVACVarRefFlow->TerminalUnitList(thisVrfTU.TUListIndex).CoolingCoilPresent(thisVrfTU.IndexToTUInTUList) = false;
    3512              :             }
    3513              :         } else {
    3514           62 :             if (thisVrfTU.VRFSysNum > 0) {
    3515           62 :                 if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    3516              :                     // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    3517              : 
    3518           16 :                     if (Util::SameString(HVAC::cAllCoilTypes(thisVrfTU.DXCoolCoilType_Num), HVAC::cAllCoilTypes(HVAC::CoilVRF_FluidTCtrl_Cooling))) {
    3519           16 :                         errFlag = false;
    3520           16 :                         if (thisVrfTU.TUListIndex > 0 && thisVrfTU.IndexToTUInTUList > 0) {
    3521           16 :                             state.dataHVACVarRefFlow->TerminalUnitList(thisVrfTU.TUListIndex).coolingCoilAvailScheds(thisVrfTU.IndexToTUInTUList) =
    3522           32 :                                 DXCoils::GetDXCoilAvailSched(state, DXCoolingCoilType, cAlphaArgs(12), errFlag);
    3523              :                         }
    3524           32 :                         GetDXCoilIndex(
    3525           16 :                             state, cAlphaArgs(12), thisVrfTU.CoolCoilIndex, errFlag, HVAC::cAllCoilTypes(HVAC::CoilVRF_FluidTCtrl_Cooling));
    3526              :                         CCoilInletNodeNum =
    3527           16 :                             DXCoils::GetCoilInletNode(state, HVAC::cAllCoilTypes(HVAC::CoilVRF_FluidTCtrl_Cooling), cAlphaArgs(12), errFlag);
    3528              :                         CCoilOutletNodeNum =
    3529           16 :                             DXCoils::GetCoilOutletNode(state, HVAC::cAllCoilTypes(HVAC::CoilVRF_FluidTCtrl_Cooling), cAlphaArgs(12), errFlag);
    3530           16 :                         thisVrfTU.coolCoilAirInNode = CCoilInletNodeNum;
    3531           16 :                         thisVrfTU.coolCoilAirOutNode = CCoilOutletNodeNum;
    3532              : 
    3533           16 :                         if (errFlag) {
    3534            0 :                             ShowContinueError(state, "...occurs in " + cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3535              :                         }
    3536              : 
    3537           16 :                         if (thisVrfTU.VRFSysNum > 0) {
    3538           32 :                             SetDXCoolingCoilData(
    3539           16 :                                 state, thisVrfTU.CoolCoilIndex, ErrorsFound, _, state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CondenserType);
    3540           32 :                             SetDXCoolingCoilData(state,
    3541              :                                                  thisVrfTU.CoolCoilIndex,
    3542              :                                                  ErrorsFound,
    3543              :                                                  _,
    3544              :                                                  _,
    3545           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CondenserNodeNum);
    3546           32 :                             SetDXCoolingCoilData(state,
    3547              :                                                  thisVrfTU.CoolCoilIndex,
    3548              :                                                  ErrorsFound,
    3549              :                                                  _,
    3550              :                                                  _,
    3551              :                                                  _,
    3552           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MaxOATCCHeater);
    3553           32 :                             SetDXCoolingCoilData(state,
    3554              :                                                  thisVrfTU.CoolCoilIndex,
    3555              :                                                  ErrorsFound,
    3556              :                                                  _,
    3557              :                                                  _,
    3558              :                                                  _,
    3559              :                                                  _,
    3560           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MinOATCooling);
    3561           32 :                             SetDXCoolingCoilData(state,
    3562              :                                                  thisVrfTU.CoolCoilIndex,
    3563              :                                                  ErrorsFound,
    3564              :                                                  _,
    3565              :                                                  _,
    3566              :                                                  _,
    3567              :                                                  _,
    3568              :                                                  _,
    3569           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MaxOATCooling);
    3570              : 
    3571           16 :                             state.dataDXCoils->DXCoil(thisVrfTU.CoolCoilIndex).VRFIUPtr = VRFTUNum;
    3572           16 :                             state.dataDXCoils->DXCoil(thisVrfTU.CoolCoilIndex).VRFOUPtr = thisVrfTU.VRFSysNum;
    3573           16 :                             state.dataDXCoils->DXCoil(thisVrfTU.CoolCoilIndex).SupplyFanIndex = thisVrfTU.FanIndex;
    3574              : 
    3575           16 :                             if (thisVrfTU.FanIndex > 0) {
    3576           16 :                                 state.dataDXCoils->DXCoil(thisVrfTU.CoolCoilIndex).RatedAirVolFlowRate(1) =
    3577           16 :                                     state.dataFans->fans(thisVrfTU.FanIndex)->maxAirFlowRate;
    3578              :                             } else {
    3579            0 :                                 state.dataDXCoils->DXCoil(thisVrfTU.CoolCoilIndex).RatedAirVolFlowRate(1) = AutoSize;
    3580              :                             }
    3581              : 
    3582              :                         } else {
    3583            0 :                             ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3584            0 :                             ShowContinueError(
    3585            0 :                                 state, "... when checking " + HVAC::cAllCoilTypes(thisVrfTU.DXCoolCoilType_Num) + " \"" + cAlphaArgs(12) + "\"");
    3586            0 :                             ShowContinueError(state, "... terminal unit not connected to condenser.");
    3587            0 :                             ShowContinueError(state, "... check that terminal unit is specified in a terminal unit list object.");
    3588            0 :                             ShowContinueError(state,
    3589              :                                               "... also check that the terminal unit list name is specified in an "
    3590              :                                               "AirConditioner:VariableRefrigerantFlow object.");
    3591            0 :                             ErrorsFound = true;
    3592              :                         }
    3593              :                     } else {
    3594            0 :                         ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3595            0 :                         ShowContinueError(state, "... illegal " + cAlphaFieldNames(12) + " = " + cAlphaArgs(12));
    3596            0 :                         ErrorsFound = true;
    3597              :                     }
    3598              : 
    3599              :                 } else {
    3600              :                     // Algorithm Type: VRF model based on system curve
    3601              : 
    3602           46 :                     if (Util::SameString(HVAC::cAllCoilTypes(thisVrfTU.DXCoolCoilType_Num), HVAC::cAllCoilTypes(HVAC::CoilVRF_Cooling))) {
    3603           46 :                         if (thisVrfTU.TUListIndex > 0 && thisVrfTU.IndexToTUInTUList > 0) {
    3604           46 :                             state.dataHVACVarRefFlow->TerminalUnitList(thisVrfTU.TUListIndex).coolingCoilAvailScheds(thisVrfTU.IndexToTUInTUList) =
    3605           92 :                                 DXCoils::GetDXCoilAvailSched(state, DXCoolingCoilType, cAlphaArgs(12), errFlag);
    3606              :                         } else {
    3607            0 :                             thisVrfTU.CoolingCoilPresent = false;
    3608              :                         }
    3609           46 :                         errFlag = false;
    3610           46 :                         GetDXCoilIndex(state, cAlphaArgs(12), thisVrfTU.CoolCoilIndex, errFlag, HVAC::cAllCoilTypes(HVAC::CoilVRF_Cooling));
    3611           46 :                         CCoilInletNodeNum = DXCoils::GetCoilInletNode(state, HVAC::cAllCoilTypes(HVAC::CoilVRF_Cooling), cAlphaArgs(12), errFlag);
    3612           46 :                         CCoilOutletNodeNum = DXCoils::GetCoilOutletNode(state, HVAC::cAllCoilTypes(HVAC::CoilVRF_Cooling), cAlphaArgs(12), errFlag);
    3613           46 :                         thisVrfTU.coolCoilAirInNode = CCoilInletNodeNum;
    3614           46 :                         thisVrfTU.coolCoilAirOutNode = CCoilOutletNodeNum;
    3615              : 
    3616           46 :                         if (errFlag) {
    3617            0 :                             ShowContinueError(state, "...occurs in " + cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3618              :                         }
    3619              : 
    3620           92 :                         SetDXCoolingCoilData(
    3621           46 :                             state, thisVrfTU.CoolCoilIndex, ErrorsFound, _, state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CondenserType);
    3622           92 :                         SetDXCoolingCoilData(
    3623           46 :                             state, thisVrfTU.CoolCoilIndex, ErrorsFound, _, _, state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CondenserNodeNum);
    3624           92 :                         SetDXCoolingCoilData(
    3625           46 :                             state, thisVrfTU.CoolCoilIndex, ErrorsFound, _, _, _, state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MaxOATCCHeater);
    3626           92 :                         SetDXCoolingCoilData(state,
    3627              :                                              thisVrfTU.CoolCoilIndex,
    3628              :                                              ErrorsFound,
    3629              :                                              _,
    3630              :                                              _,
    3631              :                                              _,
    3632              :                                              _,
    3633           46 :                                              state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MinOATCooling);
    3634           92 :                         SetDXCoolingCoilData(state,
    3635              :                                              thisVrfTU.CoolCoilIndex,
    3636              :                                              ErrorsFound,
    3637              :                                              _,
    3638              :                                              _,
    3639              :                                              _,
    3640              :                                              _,
    3641              :                                              _,
    3642           46 :                                              state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MaxOATCooling);
    3643              : 
    3644              :                     } else {
    3645            0 :                         ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3646            0 :                         ShowContinueError(state, "... illegal " + cAlphaFieldNames(12) + " = " + cAlphaArgs(12));
    3647            0 :                         ErrorsFound = true;
    3648              :                     }
    3649              :                 }
    3650              :             } else {
    3651            0 :                 ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3652            0 :                 ShowContinueError(state, "... when checking " + HVAC::cAllCoilTypes(thisVrfTU.DXCoolCoilType_Num) + " \"" + cAlphaArgs(12) + "\"");
    3653            0 :                 ShowContinueError(state, "... terminal unit not connected to condenser.");
    3654            0 :                 ShowContinueError(state, "... check that terminal unit is specified in a terminal unit list object.");
    3655            0 :                 ShowContinueError(
    3656              :                     state, "... also check that the terminal unit list name is specified in an AirConditioner:VariableRefrigerantFlow object.");
    3657            0 :                 ErrorsFound = true;
    3658              :             }
    3659              :         }
    3660              : 
    3661              :         // Get DX heating coil data
    3662           62 :         std::string DXHeatingCoilType = cAlphaArgs(13);
    3663              : 
    3664              :         // Get the heating to cooling sizing ratio input before writing to DX heating coil data
    3665           62 :         if (!lNumericFieldBlanks(10)) {
    3666            0 :             thisVrfTU.HeatingCapacitySizeRatio = rNumericArgs(10);
    3667              :         }
    3668              : 
    3669           62 :         errFlag = false;
    3670           62 :         thisVrfTU.DXHeatCoilType_Num = GetCoilTypeNum(state, DXHeatingCoilType, cAlphaArgs(14), errFlag, false);
    3671           62 :         if (thisVrfTU.DXHeatCoilType_Num == 0) {
    3672            0 :             thisVrfTU.HeatingCoilPresent = false;
    3673            0 :             if (thisVrfTU.TUListIndex > 0 && thisVrfTU.IndexToTUInTUList > 0) {
    3674            0 :                 state.dataHVACVarRefFlow->TerminalUnitList(thisVrfTU.TUListIndex).HeatingCoilPresent(thisVrfTU.IndexToTUInTUList) = false;
    3675              :             }
    3676              :         } else {
    3677           62 :             if (thisVrfTU.VRFSysNum > 0) {
    3678           62 :                 if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    3679              :                     // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    3680              : 
    3681           16 :                     if (Util::SameString(HVAC::cAllCoilTypes(thisVrfTU.DXHeatCoilType_Num), HVAC::cAllCoilTypes(HVAC::CoilVRF_FluidTCtrl_Heating))) {
    3682           16 :                         errFlag = false;
    3683           16 :                         if (thisVrfTU.TUListIndex > 0 && thisVrfTU.IndexToTUInTUList > 0) {
    3684           16 :                             state.dataHVACVarRefFlow->TerminalUnitList(thisVrfTU.TUListIndex).heatingCoilAvailScheds(thisVrfTU.IndexToTUInTUList) =
    3685           32 :                                 DXCoils::GetDXCoilAvailSched(state, DXHeatingCoilType, cAlphaArgs(14), errFlag);
    3686              :                         }
    3687           32 :                         GetDXCoilIndex(
    3688           16 :                             state, cAlphaArgs(14), thisVrfTU.HeatCoilIndex, errFlag, HVAC::cAllCoilTypes(HVAC::CoilVRF_FluidTCtrl_Heating));
    3689              :                         HCoilInletNodeNum =
    3690           16 :                             DXCoils::GetCoilInletNode(state, HVAC::cAllCoilTypes(HVAC::CoilVRF_FluidTCtrl_Heating), cAlphaArgs(14), errFlag);
    3691              :                         HCoilOutletNodeNum =
    3692           16 :                             DXCoils::GetCoilOutletNode(state, HVAC::cAllCoilTypes(HVAC::CoilVRF_FluidTCtrl_Heating), cAlphaArgs(14), errFlag);
    3693           16 :                         thisVrfTU.heatCoilAirInNode = HCoilInletNodeNum;
    3694           16 :                         thisVrfTU.heatCoilAirOutNode = HCoilOutletNodeNum;
    3695              : 
    3696           16 :                         if (errFlag) {
    3697            0 :                             ShowContinueError(state, "...occurs in " + cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3698              :                         }
    3699              : 
    3700           16 :                         if (thisVrfTU.VRFSysNum > 0) {
    3701           32 :                             SetDXCoolingCoilData(
    3702           16 :                                 state, thisVrfTU.HeatCoilIndex, ErrorsFound, _, state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CondenserType);
    3703           32 :                             SetDXCoolingCoilData(state,
    3704              :                                                  thisVrfTU.HeatCoilIndex,
    3705              :                                                  ErrorsFound,
    3706              :                                                  _,
    3707              :                                                  _,
    3708           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CondenserNodeNum);
    3709           32 :                             SetDXCoolingCoilData(state,
    3710              :                                                  thisVrfTU.HeatCoilIndex,
    3711              :                                                  ErrorsFound,
    3712              :                                                  _,
    3713              :                                                  _,
    3714              :                                                  _,
    3715           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MaxOATCCHeater);
    3716           32 :                             SetDXCoolingCoilData(state,
    3717              :                                                  thisVrfTU.HeatCoilIndex,
    3718              :                                                  ErrorsFound,
    3719              :                                                  _,
    3720              :                                                  _,
    3721              :                                                  _,
    3722              :                                                  _,
    3723              :                                                  _,
    3724              :                                                  _,
    3725           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MinOATHeating);
    3726           32 :                             SetDXCoolingCoilData(state,
    3727              :                                                  thisVrfTU.HeatCoilIndex,
    3728              :                                                  ErrorsFound,
    3729              :                                                  _,
    3730              :                                                  _,
    3731              :                                                  _,
    3732              :                                                  _,
    3733              :                                                  _,
    3734              :                                                  _,
    3735              :                                                  _,
    3736           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MaxOATHeating);
    3737           32 :                             SetDXCoolingCoilData(state,
    3738              :                                                  thisVrfTU.HeatCoilIndex,
    3739              :                                                  ErrorsFound,
    3740              :                                                  _,
    3741              :                                                  _,
    3742              :                                                  _,
    3743              :                                                  _,
    3744              :                                                  _,
    3745              :                                                  _,
    3746              :                                                  _,
    3747              :                                                  _,
    3748           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingPerformanceOATType);
    3749              :                             // Set defrost controls in child object to trip child object defrost calculations
    3750           32 :                             SetDXCoolingCoilData(state,
    3751              :                                                  thisVrfTU.HeatCoilIndex,
    3752              :                                                  ErrorsFound,
    3753              :                                                  _,
    3754              :                                                  _,
    3755              :                                                  _,
    3756              :                                                  _,
    3757              :                                                  _,
    3758              :                                                  _,
    3759              :                                                  _,
    3760              :                                                  _,
    3761              :                                                  _,
    3762           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).DefrostStrategy);
    3763           32 :                             SetDXCoolingCoilData(state,
    3764              :                                                  thisVrfTU.HeatCoilIndex,
    3765              :                                                  ErrorsFound,
    3766              :                                                  _,
    3767              :                                                  _,
    3768              :                                                  _,
    3769              :                                                  _,
    3770              :                                                  _,
    3771              :                                                  _,
    3772              :                                                  _,
    3773              :                                                  _,
    3774              :                                                  _,
    3775              :                                                  _,
    3776           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).DefrostControl);
    3777           32 :                             SetDXCoolingCoilData(state,
    3778              :                                                  thisVrfTU.HeatCoilIndex,
    3779              :                                                  ErrorsFound,
    3780              :                                                  _,
    3781              :                                                  _,
    3782              :                                                  _,
    3783              :                                                  _,
    3784              :                                                  _,
    3785              :                                                  _,
    3786              :                                                  _,
    3787              :                                                  _,
    3788              :                                                  _,
    3789              :                                                  _,
    3790              :                                                  _,
    3791           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).DefrostEIRPtr);
    3792           32 :                             SetDXCoolingCoilData(state,
    3793              :                                                  thisVrfTU.HeatCoilIndex,
    3794              :                                                  ErrorsFound,
    3795              :                                                  _,
    3796              :                                                  _,
    3797              :                                                  _,
    3798              :                                                  _,
    3799              :                                                  _,
    3800              :                                                  _,
    3801              :                                                  _,
    3802              :                                                  _,
    3803              :                                                  _,
    3804              :                                                  _,
    3805              :                                                  _,
    3806              :                                                  _,
    3807           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).DefrostFraction);
    3808           32 :                             SetDXCoolingCoilData(state,
    3809              :                                                  thisVrfTU.HeatCoilIndex,
    3810              :                                                  ErrorsFound,
    3811              :                                                  _,
    3812              :                                                  _,
    3813              :                                                  _,
    3814              :                                                  _,
    3815              :                                                  _,
    3816              :                                                  _,
    3817              :                                                  _,
    3818              :                                                  _,
    3819              :                                                  _,
    3820              :                                                  _,
    3821              :                                                  _,
    3822              :                                                  _,
    3823              :                                                  _,
    3824              :                                                  _,
    3825           16 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MaxOATDefrost);
    3826              :                             // If defrost is disabled in the VRF condenser, it must be disabled in the DX coil
    3827              :                             // Defrost primarily handled in parent object, set defrost capacity to 1 to avoid autosizing.
    3828              :                             // Defrost capacity is used for nothing more than setting defrost power/consumption report
    3829              :                             // variables which are not reported. The coil's defrost algorithm IS used to derate the coil
    3830           48 :                             SetDXCoolingCoilData(state,
    3831              :                                                  thisVrfTU.HeatCoilIndex,
    3832              :                                                  ErrorsFound,
    3833              :                                                  _,
    3834              :                                                  _,
    3835              :                                                  _,
    3836              :                                                  _,
    3837              :                                                  _,
    3838              :                                                  _,
    3839              :                                                  _,
    3840              :                                                  _,
    3841              :                                                  _,
    3842              :                                                  _,
    3843              :                                                  _,
    3844              :                                                  _,
    3845              :                                                  _,
    3846           32 :                                                  1.0); // DefrostCapacity=1.0
    3847              : 
    3848           16 :                             state.dataDXCoils->DXCoil(thisVrfTU.HeatCoilIndex).VRFIUPtr = VRFTUNum;
    3849           16 :                             state.dataDXCoils->DXCoil(thisVrfTU.HeatCoilIndex).VRFOUPtr = thisVrfTU.VRFSysNum;
    3850           16 :                             state.dataDXCoils->DXCoil(thisVrfTU.HeatCoilIndex).SupplyFanIndex = thisVrfTU.FanIndex;
    3851              : 
    3852           16 :                             if (thisVrfTU.FanIndex > 0) {
    3853           16 :                                 state.dataDXCoils->DXCoil(thisVrfTU.HeatCoilIndex).RatedAirVolFlowRate(1) =
    3854           16 :                                     state.dataFans->fans(thisVrfTU.FanIndex)->maxAirFlowRate;
    3855              :                             } else {
    3856            0 :                                 state.dataDXCoils->DXCoil(thisVrfTU.HeatCoilIndex).RatedAirVolFlowRate(1) = AutoSize;
    3857              :                             }
    3858              : 
    3859              :                             // Terminal unit heating to cooling sizing ratio has precedence over VRF system sizing ratio
    3860           16 :                             if (thisVrfTU.HeatingCapacitySizeRatio > 1.0) {
    3861            0 :                                 SetDXCoolingCoilData(state,
    3862              :                                                      thisVrfTU.HeatCoilIndex,
    3863              :                                                      ErrorsFound,
    3864              :                                                      _,
    3865              :                                                      _,
    3866              :                                                      _,
    3867              :                                                      _,
    3868              :                                                      _,
    3869              :                                                      _,
    3870              :                                                      _,
    3871              :                                                      _,
    3872              :                                                      _,
    3873              :                                                      _,
    3874              :                                                      _,
    3875              :                                                      _,
    3876              :                                                      _,
    3877              :                                                      _,
    3878              :                                                      _,
    3879              :                                                      _,
    3880              :                                                      _,
    3881            0 :                                                      thisVrfTU.HeatingCapacitySizeRatio);
    3882           16 :                             } else if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingCapacitySizeRatio > 1.0) {
    3883            0 :                                 SetDXCoolingCoilData(state,
    3884              :                                                      thisVrfTU.HeatCoilIndex,
    3885              :                                                      ErrorsFound,
    3886              :                                                      _,
    3887              :                                                      _,
    3888              :                                                      _,
    3889              :                                                      _,
    3890              :                                                      _,
    3891              :                                                      _,
    3892              :                                                      _,
    3893              :                                                      _,
    3894              :                                                      _,
    3895              :                                                      _,
    3896              :                                                      _,
    3897              :                                                      _,
    3898              :                                                      _,
    3899              :                                                      _,
    3900              :                                                      _,
    3901              :                                                      _,
    3902              :                                                      _,
    3903            0 :                                                      state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingCapacitySizeRatio);
    3904              :                             }
    3905              :                         } else {
    3906            0 :                             ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3907            0 :                             ShowContinueError(
    3908            0 :                                 state, "... when checking " + HVAC::cAllCoilTypes(thisVrfTU.DXHeatCoilType_Num) + " \"" + cAlphaArgs(14) + "\"");
    3909            0 :                             ShowContinueError(state, "... terminal unit not connected to condenser.");
    3910            0 :                             ShowContinueError(state, "... check that terminal unit is specified in a terminal unit list object.");
    3911            0 :                             ShowContinueError(state,
    3912              :                                               "... also check that the terminal unit list name is specified in an "
    3913              :                                               "AirConditioner:VariableRefrigerantFlow object.");
    3914            0 :                             ErrorsFound = true;
    3915              :                         }
    3916              :                     } else {
    3917            0 :                         ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3918            0 :                         ShowContinueError(state, "... illegal " + cAlphaFieldNames(14) + " = " + cAlphaArgs(14));
    3919            0 :                         ErrorsFound = true;
    3920              :                     }
    3921              : 
    3922              :                 } else {
    3923              :                     // Algorithm Type: VRF model based on system curve
    3924           46 :                     if (Util::SameString(HVAC::cAllCoilTypes(thisVrfTU.DXHeatCoilType_Num), HVAC::cAllCoilTypes(HVAC::CoilVRF_Heating))) {
    3925           46 :                         if (thisVrfTU.TUListIndex > 0 && thisVrfTU.IndexToTUInTUList > 0) {
    3926           46 :                             state.dataHVACVarRefFlow->TerminalUnitList(thisVrfTU.TUListIndex).heatingCoilAvailScheds(thisVrfTU.IndexToTUInTUList) =
    3927           92 :                                 DXCoils::GetDXCoilAvailSched(state, DXHeatingCoilType, cAlphaArgs(14), errFlag);
    3928              :                         } else {
    3929            0 :                             thisVrfTU.HeatingCoilPresent = false;
    3930              :                         }
    3931           46 :                         errFlag = false;
    3932           46 :                         GetDXCoilIndex(state, cAlphaArgs(14), thisVrfTU.HeatCoilIndex, errFlag, HVAC::cAllCoilTypes(HVAC::CoilVRF_Heating));
    3933           46 :                         HCoilInletNodeNum = DXCoils::GetCoilInletNode(state, HVAC::cAllCoilTypes(HVAC::CoilVRF_Heating), cAlphaArgs(14), errFlag);
    3934           46 :                         HCoilOutletNodeNum = DXCoils::GetCoilOutletNode(state, HVAC::cAllCoilTypes(HVAC::CoilVRF_Heating), cAlphaArgs(14), errFlag);
    3935           46 :                         thisVrfTU.heatCoilAirInNode = HCoilInletNodeNum;
    3936           46 :                         thisVrfTU.heatCoilAirOutNode = HCoilOutletNodeNum;
    3937              : 
    3938           46 :                         if (errFlag) {
    3939            0 :                             ShowContinueError(state, "...occurs in " + cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    3940              :                         }
    3941              : 
    3942           92 :                         SetDXCoolingCoilData(
    3943           46 :                             state, thisVrfTU.HeatCoilIndex, ErrorsFound, _, state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CondenserType);
    3944           92 :                         SetDXCoolingCoilData(
    3945           46 :                             state, thisVrfTU.HeatCoilIndex, ErrorsFound, _, _, state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CondenserNodeNum);
    3946           92 :                         SetDXCoolingCoilData(
    3947           46 :                             state, thisVrfTU.HeatCoilIndex, ErrorsFound, _, _, _, state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MaxOATCCHeater);
    3948           92 :                         SetDXCoolingCoilData(state,
    3949              :                                              thisVrfTU.HeatCoilIndex,
    3950              :                                              ErrorsFound,
    3951              :                                              _,
    3952              :                                              _,
    3953              :                                              _,
    3954              :                                              _,
    3955              :                                              _,
    3956              :                                              _,
    3957           46 :                                              state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MinOATHeating);
    3958           92 :                         SetDXCoolingCoilData(state,
    3959              :                                              thisVrfTU.HeatCoilIndex,
    3960              :                                              ErrorsFound,
    3961              :                                              _,
    3962              :                                              _,
    3963              :                                              _,
    3964              :                                              _,
    3965              :                                              _,
    3966              :                                              _,
    3967              :                                              _,
    3968              :                                              _,
    3969           46 :                                              state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingPerformanceOATType);
    3970              :                         // Set defrost controls in child object to trip child object defrost calculations
    3971           92 :                         SetDXCoolingCoilData(state,
    3972              :                                              thisVrfTU.HeatCoilIndex,
    3973              :                                              ErrorsFound,
    3974              :                                              _,
    3975              :                                              _,
    3976              :                                              _,
    3977              :                                              _,
    3978              :                                              _,
    3979              :                                              _,
    3980              :                                              _,
    3981              :                                              _,
    3982              :                                              _,
    3983           46 :                                              state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).DefrostStrategy);
    3984           92 :                         SetDXCoolingCoilData(state,
    3985              :                                              thisVrfTU.HeatCoilIndex,
    3986              :                                              ErrorsFound,
    3987              :                                              _,
    3988              :                                              _,
    3989              :                                              _,
    3990              :                                              _,
    3991              :                                              _,
    3992              :                                              _,
    3993              :                                              _,
    3994              :                                              _,
    3995              :                                              _,
    3996              :                                              _,
    3997           46 :                                              state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).DefrostControl);
    3998           92 :                         SetDXCoolingCoilData(state,
    3999              :                                              thisVrfTU.HeatCoilIndex,
    4000              :                                              ErrorsFound,
    4001              :                                              _,
    4002              :                                              _,
    4003              :                                              _,
    4004              :                                              _,
    4005              :                                              _,
    4006              :                                              _,
    4007              :                                              _,
    4008              :                                              _,
    4009              :                                              _,
    4010              :                                              _,
    4011              :                                              _,
    4012           46 :                                              state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).DefrostEIRPtr);
    4013           92 :                         SetDXCoolingCoilData(state,
    4014              :                                              thisVrfTU.HeatCoilIndex,
    4015              :                                              ErrorsFound,
    4016              :                                              _,
    4017              :                                              _,
    4018              :                                              _,
    4019              :                                              _,
    4020              :                                              _,
    4021              :                                              _,
    4022              :                                              _,
    4023              :                                              _,
    4024              :                                              _,
    4025              :                                              _,
    4026              :                                              _,
    4027              :                                              _,
    4028           46 :                                              state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).DefrostFraction);
    4029           92 :                         SetDXCoolingCoilData(state,
    4030              :                                              thisVrfTU.HeatCoilIndex,
    4031              :                                              ErrorsFound,
    4032              :                                              _,
    4033              :                                              _,
    4034              :                                              _,
    4035              :                                              _,
    4036              :                                              _,
    4037              :                                              _,
    4038              :                                              _,
    4039              :                                              _,
    4040              :                                              _,
    4041              :                                              _,
    4042              :                                              _,
    4043              :                                              _,
    4044              :                                              _,
    4045              :                                              _,
    4046           46 :                                              state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).MaxOATDefrost);
    4047              :                         // If defrost is disabled in the VRF condenser, it must be disabled in the DX coil
    4048              :                         // Defrost primarily handled in parent object, set defrost capacity to 1 to avoid autosizing.
    4049              :                         // Defrost capacity is used for nothing more than setting defrost power/consumption report
    4050              :                         // variables which are not reported. The coil's defrost algorithm IS used to derate the coil
    4051          138 :                         SetDXCoolingCoilData(state,
    4052              :                                              thisVrfTU.HeatCoilIndex,
    4053              :                                              ErrorsFound,
    4054              :                                              _,
    4055              :                                              _,
    4056              :                                              _,
    4057              :                                              _,
    4058              :                                              _,
    4059              :                                              _,
    4060              :                                              _,
    4061              :                                              _,
    4062              :                                              _,
    4063              :                                              _,
    4064              :                                              _,
    4065              :                                              _,
    4066              :                                              _,
    4067           92 :                                              1.0); // DefrostCapacity=1.0
    4068              :                         // Terminal unit heating to cooling sizing ratio has precedence over VRF system sizing ratio
    4069           46 :                         if (thisVrfTU.HeatingCapacitySizeRatio > 1.0) {
    4070            0 :                             SetDXCoolingCoilData(state,
    4071              :                                                  thisVrfTU.HeatCoilIndex,
    4072              :                                                  ErrorsFound,
    4073              :                                                  _,
    4074              :                                                  _,
    4075              :                                                  _,
    4076              :                                                  _,
    4077              :                                                  _,
    4078              :                                                  _,
    4079              :                                                  _,
    4080              :                                                  _,
    4081              :                                                  _,
    4082              :                                                  _,
    4083              :                                                  _,
    4084              :                                                  _,
    4085              :                                                  _,
    4086              :                                                  _,
    4087              :                                                  _,
    4088              :                                                  _,
    4089              :                                                  _,
    4090            0 :                                                  thisVrfTU.HeatingCapacitySizeRatio);
    4091           46 :                         } else if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingCapacitySizeRatio > 1.0) {
    4092            0 :                             SetDXCoolingCoilData(state,
    4093              :                                                  thisVrfTU.HeatCoilIndex,
    4094              :                                                  ErrorsFound,
    4095              :                                                  _,
    4096              :                                                  _,
    4097              :                                                  _,
    4098              :                                                  _,
    4099              :                                                  _,
    4100              :                                                  _,
    4101              :                                                  _,
    4102              :                                                  _,
    4103              :                                                  _,
    4104              :                                                  _,
    4105              :                                                  _,
    4106              :                                                  _,
    4107              :                                                  _,
    4108              :                                                  _,
    4109              :                                                  _,
    4110              :                                                  _,
    4111              :                                                  _,
    4112            0 :                                                  state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingCapacitySizeRatio);
    4113              :                         }
    4114              :                         // Check VRF DX heating coil heating capacity as a function of temperature performance curve. Only report here for
    4115              :                         // biquadratic curve type.
    4116           92 :                         if (thisVrfTU.VRFSysNum > 0 && thisVrfTU.HeatCoilIndex > 0 &&
    4117           46 :                             state.dataCurveManager->curves(GetDXCoilCapFTCurveIndex(state, thisVrfTU.HeatCoilIndex, ErrorsFound))->numDims == 2) {
    4118           15 :                             if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingPerformanceOATType == HVAC::OATType::WetBulb) {
    4119           30 :                                 checkCurveIsNormalizedToOne(
    4120              :                                     state,
    4121           30 :                                     "GetDXCoils: " + HVAC::cAllCoilTypes(thisVrfTU.DXHeatCoilType_Num),
    4122           15 :                                     DXCoils::GetDXCoilName(
    4123           15 :                                         state, thisVrfTU.HeatCoilIndex, ErrorsFound, HVAC::cAllCoilTypes(thisVrfTU.DXHeatCoilType_Num)),
    4124              :                                     GetDXCoilCapFTCurveIndex(state, thisVrfTU.HeatCoilIndex, ErrorsFound),
    4125              :                                     "Heating Capacity Ratio Modifier Function of Temperature Curve Name",
    4126           30 :                                     Curve::GetCurveName(state, GetDXCoilCapFTCurveIndex(state, thisVrfTU.HeatCoilIndex, ErrorsFound)),
    4127              :                                     RatedInletAirTempHeat,
    4128              :                                     RatedOutdoorWetBulbTempHeat);
    4129            0 :                             } else if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingPerformanceOATType == HVAC::OATType::DryBulb) {
    4130            0 :                                 checkCurveIsNormalizedToOne(
    4131              :                                     state,
    4132            0 :                                     "GetDXCoils: " + HVAC::cAllCoilTypes(thisVrfTU.DXHeatCoilType_Num),
    4133            0 :                                     DXCoils::GetDXCoilName(
    4134            0 :                                         state, thisVrfTU.HeatCoilIndex, ErrorsFound, HVAC::cAllCoilTypes(thisVrfTU.DXHeatCoilType_Num)),
    4135              :                                     GetDXCoilCapFTCurveIndex(state, thisVrfTU.HeatCoilIndex, ErrorsFound),
    4136              :                                     "Heating Capacity Ratio Modifier Function of Temperature Curve Name",
    4137            0 :                                     Curve::GetCurveName(state, GetDXCoilCapFTCurveIndex(state, thisVrfTU.HeatCoilIndex, ErrorsFound)),
    4138              :                                     RatedInletAirTempHeat,
    4139              :                                     RatedOutdoorAirTempHeat);
    4140              :                             }
    4141              :                         }
    4142              : 
    4143              :                     } else {
    4144            0 :                         ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    4145            0 :                         ShowContinueError(state, "... illegal " + cAlphaFieldNames(14) + " = " + cAlphaArgs(14));
    4146            0 :                         ErrorsFound = true;
    4147              :                     }
    4148              :                 }
    4149              :             } else {
    4150            0 :                 ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    4151            0 :                 ShowContinueError(state, "... when checking " + HVAC::cAllCoilTypes(thisVrfTU.DXHeatCoilType_Num) + " \"" + cAlphaArgs(14) + "\"");
    4152            0 :                 ShowContinueError(state, "... terminal unit not connected to condenser.");
    4153            0 :                 ShowContinueError(state, "... check that terminal unit is specified in a terminal unit list object.");
    4154            0 :                 ShowContinueError(
    4155              :                     state, "... also check that the terminal unit list name is specified in an AirConditioner:VariableRefrigerantFlow object.");
    4156            0 :                 ErrorsFound = true;
    4157              :             }
    4158              :         }
    4159              : 
    4160           62 :         if (!thisVrfTU.CoolingCoilPresent && thisVrfTU.DXCoolCoilType_Num == 0 && !thisVrfTU.HeatingCoilPresent &&
    4161            0 :             thisVrfTU.DXHeatCoilType_Num == 0) {
    4162            0 :             ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    4163            0 :             ShowContinueError(state, "... no valid coils entered for this terminal unit. Simulation will not proceed.");
    4164            0 :             ErrorsFound = true;
    4165              :         }
    4166              : 
    4167           62 :         if (!lAlphaFieldBlanks(15)) {
    4168            1 :             thisVrfTU.AvailManagerListName = cAlphaArgs(15);
    4169              :         }
    4170           62 :         thisVrfTU.ParasiticElec = rNumericArgs(8);
    4171           62 :         thisVrfTU.ParasiticOffElec = rNumericArgs(9);
    4172              : 
    4173           62 :         thisVrfTU.HVACSizingIndex = 0;
    4174           62 :         if (!lAlphaFieldBlanks(16)) {
    4175            1 :             thisVrfTU.HVACSizingIndex = Util::FindItemInList(cAlphaArgs(16), state.dataSize->ZoneHVACSizing);
    4176            1 :             if (thisVrfTU.HVACSizingIndex == 0) {
    4177            0 :                 ShowSevereError(state, cAlphaFieldNames(16) + " = " + cAlphaArgs(16) + " not found.");
    4178            0 :                 ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4179            0 :                 ErrorsFound = true;
    4180              :             }
    4181              :         }
    4182              : 
    4183              :         // supplemental heating coil
    4184           62 :         if (!lAlphaFieldBlanks(17) && !lAlphaFieldBlanks(18)) {
    4185              : 
    4186           11 :             thisVrfTU.SuppHeatCoilType = cAlphaArgs(17);
    4187           11 :             thisVrfTU.SuppHeatCoilName = cAlphaArgs(18);
    4188              : 
    4189           11 :             errFlag = false;
    4190           11 :             if (Util::SameString(thisVrfTU.SuppHeatCoilType, "Coil:Heating:Water")) {
    4191            2 :                 thisVrfTU.SuppHeatCoilType_Num = HVAC::Coil_HeatingWater;
    4192            9 :             } else if (Util::SameString(thisVrfTU.SuppHeatCoilType, "Coil:Heating:Steam")) {
    4193            2 :                 thisVrfTU.SuppHeatCoilType_Num = HVAC::Coil_HeatingSteam;
    4194           10 :             } else if (Util::SameString(thisVrfTU.SuppHeatCoilType, "Coil:Heating:Fuel") ||
    4195           10 :                        Util::SameString(thisVrfTU.SuppHeatCoilType, "Coil:Heating:Electric")) {
    4196            7 :                 thisVrfTU.SuppHeatCoilType_Num =
    4197            7 :                     HeatingCoils::GetHeatingCoilTypeNum(state, thisVrfTU.SuppHeatCoilType, thisVrfTU.SuppHeatCoilName, errFlag);
    4198              :             }
    4199              : 
    4200           11 :             thisVrfTU.SuppHeatingCoilPresent = true;
    4201              : 
    4202           11 :             if (thisVrfTU.SuppHeatCoilType_Num == HVAC::Coil_HeatingGasOrOtherFuel || thisVrfTU.SuppHeatCoilType_Num == HVAC::Coil_HeatingElectric) {
    4203            7 :                 errFlag = false;
    4204            7 :                 thisVrfTU.SuppHeatCoilType_Num =
    4205            7 :                     HeatingCoils::GetHeatingCoilTypeNum(state, thisVrfTU.SuppHeatCoilType, thisVrfTU.SuppHeatCoilName, errFlag);
    4206            7 :                 if (errFlag) {
    4207            0 :                     ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4208            0 :                     ErrorsFound = true;
    4209              :                 } else {
    4210            7 :                     ValidateComponent(state, thisVrfTU.SuppHeatCoilType, thisVrfTU.SuppHeatCoilName, IsNotOK, cCurrentModuleObject);
    4211            7 :                     if (IsNotOK) {
    4212            0 :                         ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4213            0 :                         ErrorsFound = true;
    4214              :                     } else { // mine data from supplemental heating coil
    4215              :                         // Get the supplemental heating coil index
    4216            7 :                         thisVrfTU.SuppHeatCoilIndex =
    4217            7 :                             HeatingCoils::GetHeatingCoilIndex(state, thisVrfTU.SuppHeatCoilType, thisVrfTU.SuppHeatCoilName, IsNotOK);
    4218            7 :                         if (IsNotOK) {
    4219            0 :                             ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4220            0 :                             ErrorsFound = true;
    4221              :                         }
    4222              :                         // Get the design supplemental heating capacity
    4223            7 :                         errFlag = false;
    4224            7 :                         thisVrfTU.DesignSuppHeatingCapacity =
    4225            7 :                             HeatingCoils::GetCoilCapacity(state, thisVrfTU.SuppHeatCoilType, thisVrfTU.SuppHeatCoilName, errFlag);
    4226            7 :                         if (errFlag) {
    4227            0 :                             ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4228            0 :                             ErrorsFound = true;
    4229              :                         }
    4230              :                         // Get the supplemental heating Coil air inlet node
    4231            7 :                         errFlag = false;
    4232            7 :                         thisVrfTU.SuppHeatCoilAirInletNode =
    4233            7 :                             HeatingCoils::GetCoilInletNode(state, thisVrfTU.SuppHeatCoilType, thisVrfTU.SuppHeatCoilName, errFlag);
    4234            7 :                         if (errFlag) {
    4235            0 :                             ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4236            0 :                             ErrorsFound = true;
    4237              :                         }
    4238              :                         // Get the supplemental heating Coil air outlet node
    4239            7 :                         errFlag = false;
    4240            7 :                         thisVrfTU.SuppHeatCoilAirOutletNode =
    4241            7 :                             HeatingCoils::GetCoilOutletNode(state, thisVrfTU.SuppHeatCoilType, thisVrfTU.SuppHeatCoilName, errFlag);
    4242            7 :                         if (errFlag) {
    4243            0 :                             ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4244            0 :                             ErrorsFound = true;
    4245              :                         }
    4246              :                     } // IF (IsNotOK) THEN
    4247              :                 }
    4248              : 
    4249            4 :             } else if (thisVrfTU.SuppHeatCoilType_Num == HVAC::Coil_HeatingWater) {
    4250              : 
    4251            2 :                 ValidateComponent(state, thisVrfTU.SuppHeatCoilType, thisVrfTU.SuppHeatCoilName, IsNotOK, cCurrentModuleObject);
    4252            2 :                 if (IsNotOK) {
    4253            0 :                     ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4254            0 :                     ErrorsFound = true;
    4255              :                 } else { // mine data from heating coil object
    4256              : 
    4257              :                     // Get the supplemental heating coil water Inlet or control node number
    4258            2 :                     errFlag = false;
    4259            2 :                     thisVrfTU.SuppHeatCoilFluidInletNode =
    4260            2 :                         WaterCoils::GetCoilWaterInletNode(state, "Coil:Heating:Water", thisVrfTU.SuppHeatCoilName, errFlag);
    4261            2 :                     if (errFlag) {
    4262            0 :                         ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4263            0 :                         ErrorsFound = true;
    4264              :                     }
    4265              :                     // Get the supplemental heating coil hot water max volume flow rate
    4266            2 :                     errFlag = false;
    4267            2 :                     thisVrfTU.SuppHeatCoilFluidMaxFlow =
    4268            2 :                         WaterCoils::GetCoilMaxWaterFlowRate(state, "Coil:Heating:Water", thisVrfTU.SuppHeatCoilName, errFlag);
    4269            2 :                     if (errFlag) {
    4270            0 :                         ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4271            0 :                         ErrorsFound = true;
    4272              :                     }
    4273              :                     // Get the supplemental heating Coil air inlet node
    4274            2 :                     errFlag = false;
    4275            2 :                     thisVrfTU.SuppHeatCoilAirInletNode =
    4276            2 :                         WaterCoils::GetCoilInletNode(state, "Coil:Heating:Water", thisVrfTU.SuppHeatCoilName, errFlag);
    4277            2 :                     if (errFlag) {
    4278            0 :                         ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4279            0 :                         ErrorsFound = true;
    4280              :                     }
    4281              :                     // Get the supplemental heating coil air outlet node
    4282            2 :                     errFlag = false;
    4283            2 :                     thisVrfTU.SuppHeatCoilAirOutletNode =
    4284            2 :                         WaterCoils::GetCoilOutletNode(state, "Coil:Heating:Water", thisVrfTU.SuppHeatCoilName, errFlag);
    4285            2 :                     if (errFlag) {
    4286            0 :                         ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4287            0 :                         ErrorsFound = true;
    4288              :                     }
    4289              :                 }
    4290              : 
    4291            2 :             } else if (thisVrfTU.SuppHeatCoilType_Num == HVAC::Coil_HeatingSteam) {
    4292              : 
    4293            2 :                 ValidateComponent(state, thisVrfTU.SuppHeatCoilType, thisVrfTU.SuppHeatCoilName, IsNotOK, cCurrentModuleObject);
    4294            2 :                 if (IsNotOK) {
    4295            0 :                     ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4296            0 :                     ErrorsFound = true;
    4297              :                 } else { // mine data from supplemental heating coil object
    4298            2 :                     errFlag = false;
    4299            2 :                     thisVrfTU.SuppHeatCoilIndex = SteamCoils::GetSteamCoilIndex(state, "COIL:HEATING:STEAM", thisVrfTU.SuppHeatCoilName, errFlag);
    4300            2 :                     if (thisVrfTU.SuppHeatCoilIndex == 0) {
    4301            0 :                         ShowSevereError(state, cCurrentModuleObject + " = " + thisVrfTU.Name);
    4302            0 :                         ErrorsFound = true;
    4303              :                     }
    4304              :                     // Get the supplemental heating Coil steam inlet node number
    4305            2 :                     errFlag = false;
    4306            2 :                     thisVrfTU.SuppHeatCoilFluidInletNode =
    4307            4 :                         SteamCoils::GetCoilSteamInletNode(state, "Coil:Heating:Steam", thisVrfTU.SuppHeatCoilName, errFlag);
    4308            2 :                     if (errFlag) {
    4309            0 :                         ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4310            0 :                         ErrorsFound = true;
    4311              :                     }
    4312              :                     // Get the supplemental heating coil steam max volume flow rate
    4313            2 :                     thisVrfTU.SuppHeatCoilFluidMaxFlow = SteamCoils::GetCoilMaxSteamFlowRate(state, thisVrfTU.SuppHeatCoilIndex, errFlag);
    4314            2 :                     if (thisVrfTU.SuppHeatCoilFluidMaxFlow > 0.0) {
    4315            0 :                         Real64 TempSteamIn = 100.0;
    4316            0 :                         Real64 SteamDensity = Fluid::GetSteam(state)->getSatDensity(state, TempSteamIn, 1.0, RoutineName);
    4317            0 :                         thisVrfTU.SuppHeatCoilFluidMaxFlow =
    4318            0 :                             SteamCoils::GetCoilMaxSteamFlowRate(state, thisVrfTU.SuppHeatCoilIndex, errFlag) * SteamDensity;
    4319              :                     }
    4320              :                     // Get the supplemental heating coil air inlet node
    4321            2 :                     errFlag = false;
    4322            2 :                     thisVrfTU.SuppHeatCoilAirInletNode =
    4323            2 :                         SteamCoils::GetCoilAirInletNode(state, thisVrfTU.SuppHeatCoilIndex, thisVrfTU.SuppHeatCoilName, errFlag);
    4324            2 :                     if (errFlag) {
    4325            0 :                         ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4326            0 :                         ErrorsFound = true;
    4327              :                     }
    4328              :                     // Get the supplemental heating coil air outlet node
    4329            2 :                     errFlag = false;
    4330            2 :                     thisVrfTU.SuppHeatCoilAirOutletNode =
    4331            2 :                         SteamCoils::GetCoilAirOutletNode(state, thisVrfTU.SuppHeatCoilIndex, thisVrfTU.SuppHeatCoilName, errFlag);
    4332            2 :                     if (errFlag) {
    4333            0 :                         ShowContinueError(state, "Occurs in " + cCurrentModuleObject + " = " + thisVrfTU.Name);
    4334            0 :                         ErrorsFound = true;
    4335              :                     }
    4336              :                 }
    4337              :             }
    4338              :         } else { // if (!lAlphaFieldBlanks(17) && !lAlphaFieldBlanks(18)) {
    4339           51 :             if (!lAlphaFieldBlanks(17) && lAlphaFieldBlanks(18)) {
    4340            0 :                 ShowWarningError(state, cCurrentModuleObject + " = " + thisVrfTU.Name + "\"");
    4341            0 :                 ShowContinueError(state, "...Supplemental heating coil type = " + cAlphaArgs(17));
    4342            0 :                 ShowContinueError(state, "...But missing the associated supplemental heating coil name. ");
    4343            0 :                 ShowContinueError(state, "...The supplemental heating coil will not be simulated. ");
    4344              :             }
    4345           51 :             if (lAlphaFieldBlanks(17) && !lAlphaFieldBlanks(18)) {
    4346            0 :                 ShowWarningError(state, cCurrentModuleObject + " = " + thisVrfTU.Name + "\"");
    4347            0 :                 ShowContinueError(state, "...Supplemental heating coil name = " + cAlphaArgs(18));
    4348            0 :                 ShowContinueError(state, "...But missing the associated supplemental heating coil type. ");
    4349            0 :                 ShowContinueError(state, "...The supplemental heating coil will not be simulated. ");
    4350              :             }
    4351              :         }
    4352              : 
    4353           62 :         if (!lAlphaFieldBlanks(19)) {
    4354            1 :             thisVrfTU.ZoneNum = Util::FindItemInList(cAlphaArgs(19), state.dataHeatBal->Zone);
    4355            1 :             if (thisVrfTU.ZoneNum == 0) {
    4356            0 :                 ShowSevereError(state, cCurrentModuleObject + " = " + cAlphaArgs(1));
    4357            0 :                 ShowContinueError(state, "Illegal " + cAlphaFieldNames(19) + " = " + cAlphaArgs(19));
    4358            0 :                 ErrorsFound = true;
    4359              :             }
    4360              :         }
    4361              : 
    4362           62 :         auto &vrfTU = state.dataHVACVarRefFlow->VRFTU(VRFTUNum);
    4363           62 :         if (!lAlphaFieldBlanks(20) && !lAlphaFieldBlanks(21)) {
    4364            1 :             vrfTU.DesignSpecMultispeedHPType = cAlphaArgs(20);
    4365            1 :             vrfTU.DesignSpecMultispeedHPName = cAlphaArgs(21);
    4366            1 :             vrfTU.DesignSpecMSHPIndex = UnitarySystems::getDesignSpecMSHPIndex(state, cAlphaArgs(21));
    4367            1 :             auto const &designSpecFan = state.dataUnitarySystems->designSpecMSHP[vrfTU.DesignSpecMSHPIndex];
    4368            1 :             if (vrfTU.DXCoolCoilType_Num == HVAC::CoilVRF_Cooling) {
    4369            1 :                 int NumSpeeds = designSpecFan.numOfSpeedCooling;
    4370            1 :                 vrfTU.NumOfSpeedCooling = NumSpeeds;
    4371            1 :                 vrfTU.CoolVolumeFlowRate.resize(NumSpeeds + 1);
    4372            1 :                 vrfTU.CoolMassFlowRate.resize(NumSpeeds + 1);
    4373            1 :                 if (vrfTU.MaxCoolAirVolFlow != DataSizing::AutoSize) {
    4374            0 :                     Real64 AirFlowRate = vrfTU.MaxCoolAirVolFlow;
    4375            0 :                     for (int i = 1; i <= vrfTU.NumOfSpeedCooling; ++i) {
    4376            0 :                         if (state.dataUnitarySystems->designSpecMSHP[vrfTU.DesignSpecMSHPIndex].coolingVolFlowRatio[i] == DataSizing::AutoSize) {
    4377            0 :                             vrfTU.CoolVolumeFlowRate[i] = double(i) / double(vrfTU.NumOfSpeedCooling) * AirFlowRate;
    4378              :                         } else {
    4379            0 :                             vrfTU.CoolVolumeFlowRate[i] =
    4380            0 :                                 state.dataUnitarySystems->designSpecMSHP[vrfTU.DesignSpecMSHPIndex].coolingVolFlowRatio[i] * AirFlowRate;
    4381              :                         }
    4382            0 :                         vrfTU.CoolMassFlowRate[i] = vrfTU.CoolVolumeFlowRate[i] * state.dataEnvrn->StdRhoAir;
    4383              :                     }
    4384              :                 }
    4385              :             }
    4386            1 :             if (vrfTU.DXHeatCoilType_Num == HVAC::CoilVRF_Heating) {
    4387            1 :                 int NumSpeeds = designSpecFan.numOfSpeedHeating;
    4388            1 :                 vrfTU.NumOfSpeedHeating = NumSpeeds;
    4389            1 :                 vrfTU.HeatVolumeFlowRate.resize(NumSpeeds + 1);
    4390            1 :                 vrfTU.HeatMassFlowRate.resize(NumSpeeds + 1);
    4391            1 :                 if (vrfTU.MaxHeatAirVolFlow != DataSizing::AutoSize) {
    4392            0 :                     Real64 AirFlowRate = vrfTU.MaxHeatAirVolFlow;
    4393            0 :                     for (int i = 1; i <= vrfTU.NumOfSpeedHeating; ++i) {
    4394            0 :                         if (state.dataUnitarySystems->designSpecMSHP[vrfTU.DesignSpecMSHPIndex].heatingVolFlowRatio[i] == DataSizing::AutoSize) {
    4395            0 :                             vrfTU.HeatVolumeFlowRate[i] = double(i) / double(vrfTU.NumOfSpeedHeating) * AirFlowRate;
    4396              :                         } else {
    4397            0 :                             vrfTU.HeatVolumeFlowRate[i] =
    4398            0 :                                 state.dataUnitarySystems->designSpecMSHP[vrfTU.DesignSpecMSHPIndex].heatingVolFlowRatio[i] * AirFlowRate;
    4399              :                         }
    4400            0 :                         vrfTU.HeatMassFlowRate[i] = vrfTU.HeatVolumeFlowRate[i] * state.dataEnvrn->StdRhoAir;
    4401              :                     }
    4402              :                 }
    4403              :             }
    4404              :         } else {
    4405           61 :             if (vrfTU.fanType == HVAC::FanType::SystemModel) {
    4406           32 :                 auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(vrfTU.FanIndex));
    4407           32 :                 assert(fanSystem != nullptr);
    4408              : 
    4409           32 :                 if (fanSystem->speedControl == Fans::SpeedControl::Discrete) {
    4410           16 :                     if (fanSystem->numSpeeds > 1) {
    4411            1 :                         if (vrfTU.DXCoolCoilType_Num == HVAC::CoilVRF_Cooling) {
    4412            1 :                             vrfTU.NumOfSpeedCooling = fanSystem->numSpeeds;
    4413            1 :                             vrfTU.CoolVolumeFlowRate.resize(fanSystem->numSpeeds + 1);
    4414            1 :                             vrfTU.CoolMassFlowRate.resize(fanSystem->numSpeeds + 1);
    4415              :                         }
    4416            1 :                         if (vrfTU.DXHeatCoilType_Num == HVAC::CoilVRF_Heating) {
    4417            1 :                             vrfTU.NumOfSpeedHeating = fanSystem->numSpeeds;
    4418            1 :                             vrfTU.HeatVolumeFlowRate.resize(fanSystem->numSpeeds + 1);
    4419            1 :                             vrfTU.HeatMassFlowRate.resize(fanSystem->numSpeeds + 1);
    4420              :                         }
    4421            2 :                         ShowWarningError(state,
    4422            2 :                                          cCurrentModuleObject + " = " + thisVrfTU.Name + " with Fan:SystemModel is used in  " + cAlphaArgs(8) + "\"");
    4423            1 :                         ShowContinueError(state, format("...The number of speed = {:.0R}.", double(fanSystem->numSpeeds)));
    4424            3 :                         ShowContinueError(state, "...Multiple speed fan will be applied to this unit. The speed number is determined by load.");
    4425              :                     }
    4426              :                 }
    4427              :             }
    4428              :         }
    4429              : 
    4430              :         // set supplemental heating coil operation temperature limits
    4431           62 :         if (thisVrfTU.SuppHeatingCoilPresent) {
    4432              :             // Set maximum supply air temperature for supplemental heating coil
    4433           11 :             if (NumNums < 11) {
    4434            0 :                 thisVrfTU.MaxSATFromSuppHeatCoil = DataSizing::AutoSize;
    4435              :             } else {
    4436           11 :                 thisVrfTU.MaxSATFromSuppHeatCoil = rNumericArgs(11);
    4437              :             }
    4438              :             // set maximum outdoor dry-bulb temperature for supplemental heating coil operation
    4439           11 :             if (NumNums < 12) {
    4440            0 :                 thisVrfTU.MaxOATSuppHeatingCoil = 21.0;
    4441              :             } else {
    4442           11 :                 thisVrfTU.MaxOATSuppHeatingCoil = rNumericArgs(12);
    4443              :             }
    4444              :         }
    4445              : 
    4446              :         // Add cooling coil to component sets array
    4447           62 :         if (thisVrfTU.CoolingCoilPresent) {
    4448              : 
    4449          124 :             SetUpCompSets(state,
    4450              :                           cCurrentModuleObject,
    4451              :                           thisVrfTU.Name,
    4452           62 :                           HVAC::cAllCoilTypes(thisVrfTU.DXCoolCoilType_Num),
    4453           62 :                           cAlphaArgs(12),
    4454           62 :                           state.dataLoopNodes->NodeID(CCoilInletNodeNum),
    4455           62 :                           state.dataLoopNodes->NodeID(CCoilOutletNodeNum));
    4456              :             //     set heating coil present flag
    4457          124 :             SetDXCoolingCoilData(
    4458           62 :                 state, thisVrfTU.CoolCoilIndex, ErrorsFound, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, thisVrfTU.HeatingCoilPresent);
    4459              : 
    4460              :             //   check that curve types are present in VRF Condenser if cooling coil is present in terminal unit (can be blank)
    4461              :             //   all curves are checked for correct type if a curve name is entered in the VRF condenser object. Check that the
    4462              :             //   curve is present if the corresponding coil is entered in the terminal unit.
    4463           62 :             if (thisVrfTU.VRFSysNum > 0) {
    4464              : 
    4465           62 :                 if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFAlgorithmType != AlgorithmType::FluidTCtrl) {
    4466              : 
    4467           92 :                     if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CoolingCapacity <= 0 &&
    4468           46 :                         state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).CoolingCapacity != AutoSize) {
    4469            0 :                         ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    4470            0 :                         ShowContinueError(state,
    4471              :                                           "...This terminal unit contains a cooling coil and rated cooling capacity is also required in the "
    4472              :                                           "associated condenser object.");
    4473            0 :                         ShowContinueError(state,
    4474            0 :                                           "...Rated Cooling Capacity must also be specified for condenser = " +
    4475            0 :                                               std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFSystemTypeNum)) + " \"" +
    4476            0 :                                               state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).Name + "\".");
    4477            0 :                         ErrorsFound = true;
    4478              :                     }
    4479              :                 }
    4480              :             }
    4481              :         }
    4482              : 
    4483              :         // Add heating coil to component sets array
    4484           62 :         if (thisVrfTU.HeatingCoilPresent) {
    4485              : 
    4486          124 :             SetUpCompSets(state,
    4487              :                           cCurrentModuleObject,
    4488              :                           thisVrfTU.Name,
    4489           62 :                           HVAC::cAllCoilTypes(thisVrfTU.DXHeatCoilType_Num),
    4490           62 :                           cAlphaArgs(14),
    4491           62 :                           state.dataLoopNodes->NodeID(HCoilInletNodeNum),
    4492           62 :                           state.dataLoopNodes->NodeID(HCoilOutletNodeNum));
    4493              :             //     set cooling coil present flag
    4494          124 :             SetDXCoolingCoilData(
    4495           62 :                 state, thisVrfTU.HeatCoilIndex, ErrorsFound, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, thisVrfTU.CoolingCoilPresent);
    4496              : 
    4497           62 :             if (thisVrfTU.VRFSysNum > 0) {
    4498              : 
    4499           62 :                 if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFAlgorithmType != AlgorithmType::FluidTCtrl) {
    4500              : 
    4501           92 :                     if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingCapacity <= 0 &&
    4502           46 :                         state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatingCapacity != AutoSize) {
    4503            0 :                         ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    4504            0 :                         ShowContinueError(state,
    4505              :                                           "...This terminal unit contains a heating coil and rated heating capacity is also required in the "
    4506              :                                           "associated condenser object.");
    4507            0 :                         ShowContinueError(state,
    4508            0 :                                           "...Rated Heating Capacity must also be specified for condenser = " +
    4509            0 :                                               std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFSystemTypeNum)) + " \"" +
    4510            0 :                                               state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).Name + "\".");
    4511            0 :                         ErrorsFound = true;
    4512              :                     }
    4513              : 
    4514           46 :                     if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatCapFT == 0) {
    4515            0 :                         ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    4516            0 :                         ShowContinueError(state,
    4517              :                                           "...This terminal unit contains a heating coil and heating performance curves are also required in the "
    4518              :                                           "associated condenser object.");
    4519            0 :                         ShowContinueError(
    4520              :                             state,
    4521            0 :                             "...Heating Capacity Ratio Modifier Function of Low Temperature Curve must also be specified for condenser = " +
    4522            0 :                                 std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFSystemTypeNum)) + " \"" +
    4523            0 :                                 state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).Name + "\".");
    4524            0 :                         ErrorsFound = true;
    4525              :                     }
    4526              : 
    4527           46 :                     if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatEIRFT == 0) {
    4528            0 :                         ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    4529            0 :                         ShowContinueError(state,
    4530              :                                           "...This terminal unit contains a heating coil and heating performance curves are also required in the "
    4531              :                                           "associated condenser object.");
    4532            0 :                         ShowContinueError(
    4533              :                             state,
    4534            0 :                             "...Heating Energy Input Ratio Modifier Function of Low Temperature Curve must also be specified for condenser = " +
    4535            0 :                                 std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFSystemTypeNum)) + " \"" +
    4536            0 :                                 state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).Name + "\".");
    4537            0 :                         ErrorsFound = true;
    4538              :                     }
    4539              : 
    4540           46 :                     if (state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).HeatEIRFPLR1 == 0) {
    4541            0 :                         ShowSevereError(state, cCurrentModuleObject + " \"" + thisVrfTU.Name + "\"");
    4542            0 :                         ShowContinueError(state,
    4543              :                                           "...This terminal unit contains a heating coil and heating performance curves are also required in the "
    4544              :                                           "associated condenser object.");
    4545            0 :                         ShowContinueError(state,
    4546              :                                           "...Heating Energy Input Ratio Modifier Function of Low Part-Load Ratio Curve must also be specified "
    4547            0 :                                           "for condenser = " +
    4548            0 :                                               std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).VRFSystemTypeNum)) + " \"" +
    4549            0 :                                               state.dataHVACVarRefFlow->VRF(thisVrfTU.VRFSysNum).Name + "\".");
    4550              :                     }
    4551              :                 }
    4552              :             }
    4553              :         }
    4554              : 
    4555              :         // Add supplemental heating coil to component sets array
    4556           62 :         if (thisVrfTU.SuppHeatingCoilPresent) {
    4557           33 :             SetUpCompSets(state,
    4558              :                           cCurrentModuleObject,
    4559              :                           thisVrfTU.Name,
    4560           11 :                           HVAC::cAllCoilTypes(thisVrfTU.SuppHeatCoilType_Num),
    4561              :                           thisVrfTU.SuppHeatCoilName,
    4562           11 :                           state.dataLoopNodes->NodeID(thisVrfTU.SuppHeatCoilAirInletNode),
    4563           11 :                           state.dataLoopNodes->NodeID(thisVrfTU.SuppHeatCoilAirOutletNode));
    4564              :         }
    4565              :         // Set up component set for OA mixer - use OA node and Mixed air node
    4566           62 :         if (thisVrfTU.OAMixerUsed) {
    4567          102 :             SetUpCompSets(state,
    4568              :                           cCurrentModuleObject,
    4569              :                           thisVrfTU.Name,
    4570              :                           "UNDEFINED",
    4571              :                           thisVrfTU.OAMixerName,
    4572           51 :                           state.dataLoopNodes->NodeID(OANodeNums(1)),
    4573           51 :                           state.dataLoopNodes->NodeID(OANodeNums(4)));
    4574              :         }
    4575              : 
    4576              :         // Get AirTerminal mixer data
    4577           62 :         GetATMixer(state,
    4578           62 :                    thisVrfTU.Name,
    4579           62 :                    thisVrfTU.ATMixerName,
    4580           62 :                    thisVrfTU.ATMixerIndex,
    4581           62 :                    thisVrfTU.ATMixerType,
    4582           62 :                    thisVrfTU.ATMixerPriNode,
    4583           62 :                    thisVrfTU.ATMixerSecNode,
    4584           62 :                    thisVrfTU.ATMixerOutNode,
    4585              :                    thisVrfTU.VRFTUOutletNodeNum);
    4586           62 :         if (thisVrfTU.ATMixerType == HVAC::MixerType::InletSide || thisVrfTU.ATMixerType == HVAC::MixerType::SupplySide) {
    4587           10 :             thisVrfTU.ATMixerExists = true;
    4588              :         }
    4589              :         // check that the VRF TU have local outside air and DOA
    4590           62 :         if (thisVrfTU.ATMixerExists && OANodeNums(4) > 0) {
    4591            0 :             ShowSevereError(
    4592            0 :                 state, cCurrentModuleObject + " = \"" + thisVrfTU.Name + "\". VRF terminal unit has local as well as central outdoor air specified");
    4593            0 :             ErrorsFound = true;
    4594              :         }
    4595              : 
    4596              :         // for ZoneHVAC check that TU inlet node is a zone exhaust node otherwise ZoneAirNode and ZoneNum = 0
    4597           62 :         if (!thisVrfTU.ATMixerExists || thisVrfTU.ATMixerType == HVAC::MixerType::SupplySide) {
    4598          389 :             for (int CtrlZone = 1; CtrlZone <= state.dataGlobal->NumOfZones; ++CtrlZone) {
    4599          333 :                 if (!state.dataZoneEquip->ZoneEquipConfig(CtrlZone).IsControlled) {
    4600           57 :                     continue;
    4601              :                 }
    4602          492 :                 for (int NodeNum = 1; NodeNum <= state.dataZoneEquip->ZoneEquipConfig(CtrlZone).NumExhaustNodes; ++NodeNum) {
    4603          270 :                     if (thisVrfTU.VRFTUInletNodeNum == state.dataZoneEquip->ZoneEquipConfig(CtrlZone).ExhaustNode(NodeNum)) {
    4604           54 :                         thisVrfTU.ZoneAirNode = state.dataZoneEquip->ZoneEquipConfig(CtrlZone).ZoneNode;
    4605           54 :                         thisVrfTU.ZoneNum = CtrlZone;
    4606           54 :                         break;
    4607              :                     }
    4608              :                 }
    4609              :             }
    4610           62 :         } else if (thisVrfTU.ATMixerType == HVAC::MixerType::InletSide) {
    4611           42 :             for (int CtrlZone = 1; CtrlZone <= state.dataGlobal->NumOfZones; ++CtrlZone) {
    4612           36 :                 if (!state.dataZoneEquip->ZoneEquipConfig(CtrlZone).IsControlled) {
    4613            6 :                     continue;
    4614              :                 }
    4615           54 :                 for (int NodeNum = 1; NodeNum <= state.dataZoneEquip->ZoneEquipConfig(CtrlZone).NumInletNodes; ++NodeNum) {
    4616           30 :                     if (thisVrfTU.VRFTUOutletNodeNum == state.dataZoneEquip->ZoneEquipConfig(CtrlZone).InletNode(NodeNum)) {
    4617            6 :                         thisVrfTU.ZoneAirNode = state.dataZoneEquip->ZoneEquipConfig(CtrlZone).ZoneNode;
    4618            6 :                         thisVrfTU.ZoneNum = CtrlZone;
    4619            6 :                         break;
    4620              :                     }
    4621              :                 }
    4622              :             }
    4623              :         }
    4624           62 :         CheckVRFTUNodeConnections(state, VRFTUNum, ErrorsFound);
    4625           62 :     } // end Number of VRF Terminal Unit Loop
    4626              : 
    4627              :     //   perform additional error checking
    4628           27 :     for (auto const &thisTUList : state.dataHVACVarRefFlow->TerminalUnitList) {
    4629           76 :         for (int VRFTUNum = 1; VRFTUNum <= thisTUList.NumTUInList; ++VRFTUNum) {
    4630           62 :             int const tuPtr = thisTUList.ZoneTUPtr(VRFTUNum);
    4631           62 :             if (tuPtr == 0) {
    4632              :                 // TU name in zone terminal unit list not found
    4633            0 :                 ShowSevereError(state, format("ZoneTerminalUnitList \"{}\"", thisTUList.Name));
    4634            0 :                 ShowContinueError(state, format("...Zone Terminal Unit = {} improperly connected to system.", thisTUList.ZoneTUName(VRFTUNum)));
    4635            0 :                 ShowContinueError(state, "...either the ZoneHVAC:TerminalUnit:VariableRefrigerantFlow object does not exist,");
    4636            0 :                 ShowContinueError(state, "...the ZoneHVAC:TerminalUnit:VariableRefrigerantFlow object name is misspelled,");
    4637            0 :                 ShowContinueError(state, "...or the ZoneTerminalUnitList object is not named in an AirConditioner:VariableRefrigerantFlow object.");
    4638            0 :                 ErrorsFound = true;
    4639              :             } else {
    4640           62 :                 int const sysNum = state.dataHVACVarRefFlow->VRFTU(tuPtr).VRFSysNum;
    4641           62 :                 if (sysNum > 0) {
    4642           62 :                     auto &thisVRFSys = state.dataHVACVarRefFlow->VRF(sysNum);
    4643           62 :                     if (thisTUList.NumTUInList == 1 && thisVRFSys.VRFAlgorithmType == AlgorithmType::SysCurve) {
    4644            1 :                         if (thisVRFSys.HeatRecoveryUsed) {
    4645            0 :                             ShowWarningError(state, format("ZoneTerminalUnitList \"{}\"", thisTUList.Name));
    4646            0 :                             ShowWarningError(state, "...Only 1 Terminal Unit connected to system and heat recovery is selected.");
    4647            0 :                             ShowContinueError(state, format("...Heat recovery will be disabled for {}.", thisVRFSys.Name));
    4648            0 :                             thisVRFSys.HeatRecoveryUsed = false;
    4649              :                         }
    4650              :                     }
    4651              :                 }
    4652              :             }
    4653              :         }
    4654           13 :     }
    4655              : 
    4656              :     //   warn when number of ZoneTerminalUnitList different from number of AirConditioner:VariableRefrigerantFlow
    4657           13 :     if (state.dataHVACVarRefFlow->NumVRFTULists != state.dataHVACVarRefFlow->NumVRFCond) {
    4658            0 :         ShowSevereError(state,
    4659            0 :                         format("The number of AirConditioner:VariableRefrigerantFlow objects ({}) does not match the number of "
    4660              :                                "ZoneTerminalUnitList objects ({}).",
    4661            0 :                                state.dataHVACVarRefFlow->NumVRFCond,
    4662            0 :                                state.dataHVACVarRefFlow->NumVRFTULists));
    4663            0 :         for (int NumCond = 1; NumCond <= state.dataHVACVarRefFlow->NumVRFCond; ++NumCond) {
    4664            0 :             if (state.dataHVACVarRefFlow->VRF(NumCond).ZoneTUListPtr > 0) {
    4665            0 :                 ShowContinueError(state,
    4666            0 :                                   format("...AirConditioner:VariableRefrigerantFlow = {} specifies Zone Terminal Unit List Name = {}",
    4667            0 :                                          state.dataHVACVarRefFlow->VRF(NumCond).Name,
    4668            0 :                                          state.dataHVACVarRefFlow->TerminalUnitList(state.dataHVACVarRefFlow->VRF(NumCond).ZoneTUListPtr).Name));
    4669              :             } else {
    4670            0 :                 ShowContinueError(state,
    4671            0 :                                   format("...AirConditioner:VariableRefrigerantFlow = {} Zone Terminal Unit List Name not found.",
    4672            0 :                                          state.dataHVACVarRefFlow->VRF(NumCond).Name));
    4673              :             }
    4674              :         }
    4675            0 :         ShowContinueError(state, "...listing ZoneTerminalUnitList objects.");
    4676            0 :         for (int NumList = 1; NumList <= state.dataHVACVarRefFlow->NumVRFTULists; ++NumList) {
    4677            0 :             ShowContinueError(state, "...ZoneTerminalUnitList = " + state.dataHVACVarRefFlow->TerminalUnitList(NumList).Name);
    4678              :         }
    4679            0 :         ErrorsFound = true;
    4680              :     }
    4681              : 
    4682              :     // Set up output variables
    4683           75 :     for (int VRFTUNum = 1; VRFTUNum <= state.dataHVACVarRefFlow->NumVRFTU; ++VRFTUNum) {
    4684           62 :         auto &thisVrfTU = state.dataHVACVarRefFlow->VRFTU(VRFTUNum);
    4685           62 :         if (thisVrfTU.CoolingCoilPresent) {
    4686          124 :             SetupOutputVariable(state,
    4687              :                                 "Zone VRF Air Terminal Cooling Electricity Rate",
    4688              :                                 Constant::Units::W,
    4689           62 :                                 thisVrfTU.ParasiticCoolElecPower,
    4690              :                                 OutputProcessor::TimeStepType::System,
    4691              :                                 OutputProcessor::StoreType::Average,
    4692           62 :                                 thisVrfTU.Name);
    4693          124 :             SetupOutputVariable(state,
    4694              :                                 "Zone VRF Air Terminal Cooling Electricity Energy",
    4695              :                                 Constant::Units::J,
    4696           62 :                                 thisVrfTU.ParasiticElecCoolConsumption,
    4697              :                                 OutputProcessor::TimeStepType::System,
    4698              :                                 OutputProcessor::StoreType::Sum,
    4699           62 :                                 thisVrfTU.Name,
    4700              :                                 Constant::eResource::Electricity,
    4701              :                                 OutputProcessor::Group::HVAC,
    4702              :                                 OutputProcessor::EndUseCat::Cooling);
    4703          124 :             SetupOutputVariable(state,
    4704              :                                 "Zone VRF Air Terminal Total Cooling Rate",
    4705              :                                 Constant::Units::W,
    4706           62 :                                 thisVrfTU.TotalCoolingRate,
    4707              :                                 OutputProcessor::TimeStepType::System,
    4708              :                                 OutputProcessor::StoreType::Average,
    4709           62 :                                 thisVrfTU.Name);
    4710          124 :             SetupOutputVariable(state,
    4711              :                                 "Zone VRF Air Terminal Sensible Cooling Rate",
    4712              :                                 Constant::Units::W,
    4713           62 :                                 thisVrfTU.SensibleCoolingRate,
    4714              :                                 OutputProcessor::TimeStepType::System,
    4715              :                                 OutputProcessor::StoreType::Average,
    4716           62 :                                 thisVrfTU.Name);
    4717          124 :             SetupOutputVariable(state,
    4718              :                                 "Zone VRF Air Terminal Latent Cooling Rate",
    4719              :                                 Constant::Units::W,
    4720           62 :                                 thisVrfTU.LatentCoolingRate,
    4721              :                                 OutputProcessor::TimeStepType::System,
    4722              :                                 OutputProcessor::StoreType::Average,
    4723           62 :                                 thisVrfTU.Name);
    4724          124 :             SetupOutputVariable(state,
    4725              :                                 "Zone VRF Air Terminal Total Cooling Energy",
    4726              :                                 Constant::Units::J,
    4727           62 :                                 thisVrfTU.TotalCoolingEnergy,
    4728              :                                 OutputProcessor::TimeStepType::System,
    4729              :                                 OutputProcessor::StoreType::Sum,
    4730           62 :                                 thisVrfTU.Name);
    4731          124 :             SetupOutputVariable(state,
    4732              :                                 "Zone VRF Air Terminal Sensible Cooling Energy",
    4733              :                                 Constant::Units::J,
    4734           62 :                                 thisVrfTU.SensibleCoolingEnergy,
    4735              :                                 OutputProcessor::TimeStepType::System,
    4736              :                                 OutputProcessor::StoreType::Sum,
    4737           62 :                                 thisVrfTU.Name);
    4738          124 :             SetupOutputVariable(state,
    4739              :                                 "Zone VRF Air Terminal Latent Cooling Energy",
    4740              :                                 Constant::Units::J,
    4741           62 :                                 thisVrfTU.LatentCoolingEnergy,
    4742              :                                 OutputProcessor::TimeStepType::System,
    4743              :                                 OutputProcessor::StoreType::Sum,
    4744           62 :                                 thisVrfTU.Name);
    4745              :         }
    4746           62 :         if (thisVrfTU.HeatingCoilPresent) {
    4747          124 :             SetupOutputVariable(state,
    4748              :                                 "Zone VRF Air Terminal Heating Electricity Rate",
    4749              :                                 Constant::Units::W,
    4750           62 :                                 thisVrfTU.ParasiticHeatElecPower,
    4751              :                                 OutputProcessor::TimeStepType::System,
    4752              :                                 OutputProcessor::StoreType::Average,
    4753           62 :                                 thisVrfTU.Name);
    4754          124 :             SetupOutputVariable(state,
    4755              :                                 "Zone VRF Air Terminal Heating Electricity Energy",
    4756              :                                 Constant::Units::J,
    4757           62 :                                 thisVrfTU.ParasiticElecHeatConsumption,
    4758              :                                 OutputProcessor::TimeStepType::System,
    4759              :                                 OutputProcessor::StoreType::Sum,
    4760           62 :                                 thisVrfTU.Name,
    4761              :                                 Constant::eResource::Electricity,
    4762              :                                 OutputProcessor::Group::HVAC,
    4763              :                                 OutputProcessor::EndUseCat::Heating);
    4764          124 :             SetupOutputVariable(state,
    4765              :                                 "Zone VRF Air Terminal Total Heating Rate",
    4766              :                                 Constant::Units::W,
    4767           62 :                                 thisVrfTU.TotalHeatingRate,
    4768              :                                 OutputProcessor::TimeStepType::System,
    4769              :                                 OutputProcessor::StoreType::Average,
    4770           62 :                                 thisVrfTU.Name);
    4771          124 :             SetupOutputVariable(state,
    4772              :                                 "Zone VRF Air Terminal Sensible Heating Rate",
    4773              :                                 Constant::Units::W,
    4774           62 :                                 thisVrfTU.SensibleHeatingRate,
    4775              :                                 OutputProcessor::TimeStepType::System,
    4776              :                                 OutputProcessor::StoreType::Average,
    4777           62 :                                 thisVrfTU.Name);
    4778          124 :             SetupOutputVariable(state,
    4779              :                                 "Zone VRF Air Terminal Latent Heating Rate",
    4780              :                                 Constant::Units::W,
    4781           62 :                                 thisVrfTU.LatentHeatingRate,
    4782              :                                 OutputProcessor::TimeStepType::System,
    4783              :                                 OutputProcessor::StoreType::Average,
    4784           62 :                                 thisVrfTU.Name);
    4785          124 :             SetupOutputVariable(state,
    4786              :                                 "Zone VRF Air Terminal Total Heating Energy",
    4787              :                                 Constant::Units::J,
    4788           62 :                                 thisVrfTU.TotalHeatingEnergy,
    4789              :                                 OutputProcessor::TimeStepType::System,
    4790              :                                 OutputProcessor::StoreType::Sum,
    4791           62 :                                 thisVrfTU.Name);
    4792          124 :             SetupOutputVariable(state,
    4793              :                                 "Zone VRF Air Terminal Sensible Heating Energy",
    4794              :                                 Constant::Units::J,
    4795           62 :                                 thisVrfTU.SensibleHeatingEnergy,
    4796              :                                 OutputProcessor::TimeStepType::System,
    4797              :                                 OutputProcessor::StoreType::Sum,
    4798           62 :                                 thisVrfTU.Name);
    4799          124 :             SetupOutputVariable(state,
    4800              :                                 "Zone VRF Air Terminal Latent Heating Energy",
    4801              :                                 Constant::Units::J,
    4802           62 :                                 thisVrfTU.LatentHeatingEnergy,
    4803              :                                 OutputProcessor::TimeStepType::System,
    4804              :                                 OutputProcessor::StoreType::Sum,
    4805           62 :                                 thisVrfTU.Name);
    4806              :         }
    4807           62 :         SetupOutputVariable(state,
    4808              :                             "Zone VRF Air Terminal Fan Availability Status",
    4809              :                             Constant::Units::None,
    4810           62 :                             (int &)thisVrfTU.availStatus,
    4811              :                             OutputProcessor::TimeStepType::System,
    4812              :                             OutputProcessor::StoreType::Average,
    4813           62 :                             thisVrfTU.Name);
    4814           62 :         if (state.dataGlobal->AnyEnergyManagementSystemInModel) {
    4815            0 :             SetupEMSActuator(state,
    4816              :                              "Variable Refrigerant Flow Terminal Unit",
    4817              :                              thisVrfTU.Name,
    4818              :                              "Part Load Ratio",
    4819              :                              "[fraction]",
    4820            0 :                              thisVrfTU.EMSOverridePartLoadFrac,
    4821            0 :                              thisVrfTU.EMSValueForPartLoadFrac);
    4822              :         }
    4823           62 :         if (thisVrfTU.NumOfSpeedCooling > 1 || thisVrfTU.NumOfSpeedHeating > 1) {
    4824            4 :             SetupOutputVariable(state,
    4825              :                                 "Zone VRF Air Terminal Multispeed Fan Cycling Ratio",
    4826              :                                 Constant::Units::None,
    4827            2 :                                 thisVrfTU.CycRatio,
    4828              :                                 OutputProcessor::TimeStepType::System,
    4829              :                                 OutputProcessor::StoreType::Average,
    4830            2 :                                 thisVrfTU.Name);
    4831            4 :             SetupOutputVariable(state,
    4832              :                                 "Zone VRF Air Terminal Multispeed Fan Speed Ratio",
    4833              :                                 Constant::Units::None,
    4834            2 :                                 thisVrfTU.SpeedRatio,
    4835              :                                 OutputProcessor::TimeStepType::System,
    4836              :                                 OutputProcessor::StoreType::Average,
    4837            2 :                                 thisVrfTU.Name);
    4838            2 :             SetupOutputVariable(state,
    4839              :                                 "Zone VRF Air Terminal Multispeed Fan Speed Level",
    4840              :                                 Constant::Units::None,
    4841            2 :                                 thisVrfTU.SpeedNum,
    4842              :                                 OutputProcessor::TimeStepType::System,
    4843              :                                 OutputProcessor::StoreType::Average,
    4844            2 :                                 thisVrfTU.Name);
    4845              :         }
    4846              :     }
    4847              : 
    4848           27 :     for (int NumCond = 1; NumCond <= state.dataHVACVarRefFlow->NumVRFCond; ++NumCond) {
    4849           14 :         auto &thisVrf = state.dataHVACVarRefFlow->VRF(NumCond);
    4850           14 :         std::string_view const sFuelType = Constant::eFuelNames[static_cast<int>(thisVrf.fuel)];
    4851           28 :         SetupOutputVariable(state,
    4852              :                             "VRF Heat Pump Total Cooling Rate",
    4853              :                             Constant::Units::W,
    4854           14 :                             thisVrf.TotalCoolingCapacity,
    4855              :                             OutputProcessor::TimeStepType::System,
    4856              :                             OutputProcessor::StoreType::Average,
    4857           14 :                             thisVrf.Name);
    4858           28 :         SetupOutputVariable(state,
    4859              :                             "VRF Heat Pump Total Heating Rate",
    4860              :                             Constant::Units::W,
    4861           14 :                             thisVrf.TotalHeatingCapacity,
    4862              :                             OutputProcessor::TimeStepType::System,
    4863              :                             OutputProcessor::StoreType::Average,
    4864           14 :                             thisVrf.Name);
    4865           42 :         SetupOutputVariable(state,
    4866           28 :                             format("VRF Heat Pump Cooling {} Rate", sFuelType),
    4867              :                             Constant::Units::W,
    4868           14 :                             thisVrf.ElecCoolingPower,
    4869              :                             OutputProcessor::TimeStepType::System,
    4870              :                             OutputProcessor::StoreType::Average,
    4871           14 :                             thisVrf.Name);
    4872           42 :         SetupOutputVariable(state,
    4873           28 :                             format("VRF Heat Pump Cooling {} Energy", sFuelType),
    4874              :                             Constant::Units::J,
    4875           14 :                             thisVrf.CoolElecConsumption,
    4876              :                             OutputProcessor::TimeStepType::System,
    4877              :                             OutputProcessor::StoreType::Sum,
    4878           14 :                             thisVrf.Name,
    4879           14 :                             Constant::eFuel2eResource[(int)thisVrf.fuel],
    4880              :                             OutputProcessor::Group::HVAC,
    4881              :                             OutputProcessor::EndUseCat::Cooling);
    4882           42 :         SetupOutputVariable(state,
    4883           28 :                             format("VRF Heat Pump Heating {} Rate", sFuelType),
    4884              :                             Constant::Units::W,
    4885           14 :                             thisVrf.ElecHeatingPower,
    4886              :                             OutputProcessor::TimeStepType::System,
    4887              :                             OutputProcessor::StoreType::Average,
    4888           14 :                             thisVrf.Name);
    4889           42 :         SetupOutputVariable(state,
    4890           28 :                             format("VRF Heat Pump Heating {} Energy", sFuelType),
    4891              :                             Constant::Units::J,
    4892           14 :                             thisVrf.HeatElecConsumption,
    4893              :                             OutputProcessor::TimeStepType::System,
    4894              :                             OutputProcessor::StoreType::Sum,
    4895           14 :                             thisVrf.Name,
    4896           14 :                             Constant::eFuel2eResource[(int)thisVrf.fuel],
    4897              :                             OutputProcessor::Group::HVAC,
    4898              :                             OutputProcessor::EndUseCat::Heating);
    4899              : 
    4900           28 :         SetupOutputVariable(state,
    4901              :                             "VRF Heat Pump Cooling COP",
    4902              :                             Constant::Units::None,
    4903           14 :                             thisVrf.OperatingCoolingCOP,
    4904              :                             OutputProcessor::TimeStepType::System,
    4905              :                             OutputProcessor::StoreType::Average,
    4906           14 :                             thisVrf.Name);
    4907           28 :         SetupOutputVariable(state,
    4908              :                             "VRF Heat Pump Heating COP",
    4909              :                             Constant::Units::None,
    4910           14 :                             thisVrf.OperatingHeatingCOP,
    4911              :                             OutputProcessor::TimeStepType::System,
    4912              :                             OutputProcessor::StoreType::Average,
    4913           14 :                             thisVrf.Name);
    4914           28 :         SetupOutputVariable(state,
    4915              :                             "VRF Heat Pump COP",
    4916              :                             Constant::Units::None,
    4917           14 :                             thisVrf.OperatingCOP,
    4918              :                             OutputProcessor::TimeStepType::System,
    4919              :                             OutputProcessor::StoreType::Average,
    4920           14 :                             thisVrf.Name);
    4921              : 
    4922           14 :         if (thisVrf.VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    4923              :             // For VRF_FluidTCtrl Model
    4924            8 :             SetupOutputVariable(state,
    4925              :                                 "VRF Heat Pump Compressor Electricity Rate",
    4926              :                                 Constant::Units::W,
    4927            4 :                                 thisVrf.Ncomp,
    4928              :                                 OutputProcessor::TimeStepType::System,
    4929              :                                 OutputProcessor::StoreType::Average,
    4930            4 :                                 thisVrf.Name);
    4931            8 :             SetupOutputVariable(state,
    4932              :                                 "VRF Heat Pump Outdoor Unit Fan Power",
    4933              :                                 Constant::Units::W,
    4934            4 :                                 thisVrf.OUFanPower,
    4935              :                                 OutputProcessor::TimeStepType::System,
    4936              :                                 OutputProcessor::StoreType::Average,
    4937            4 :                                 thisVrf.Name);
    4938            8 :             SetupOutputVariable(state,
    4939              :                                 "VRF Heat Pump Compressor Rotating Speed",
    4940              :                                 Constant::Units::rev_min,
    4941            4 :                                 thisVrf.CompActSpeed,
    4942              :                                 OutputProcessor::TimeStepType::System,
    4943              :                                 OutputProcessor::StoreType::Average,
    4944            4 :                                 thisVrf.Name);
    4945            8 :             SetupOutputVariable(state,
    4946              :                                 "VRF Heat Pump Indoor Unit Evaporating Temperature",
    4947              :                                 Constant::Units::C,
    4948            4 :                                 thisVrf.IUEvaporatingTemp,
    4949              :                                 OutputProcessor::TimeStepType::System,
    4950              :                                 OutputProcessor::StoreType::Average,
    4951            4 :                                 thisVrf.Name);
    4952            8 :             SetupOutputVariable(state,
    4953              :                                 "VRF Heat Pump Outdoor Unit Condensing Temperature",
    4954              :                                 Constant::Units::C,
    4955            4 :                                 thisVrf.CondensingTemp,
    4956              :                                 OutputProcessor::TimeStepType::System,
    4957              :                                 OutputProcessor::StoreType::Average,
    4958            4 :                                 thisVrf.Name);
    4959            8 :             SetupOutputVariable(state,
    4960              :                                 "VRF Heat Pump Indoor Unit Condensing Temperature",
    4961              :                                 Constant::Units::C,
    4962            4 :                                 thisVrf.IUCondensingTemp,
    4963              :                                 OutputProcessor::TimeStepType::System,
    4964              :                                 OutputProcessor::StoreType::Average,
    4965            4 :                                 thisVrf.Name);
    4966            8 :             SetupOutputVariable(state,
    4967              :                                 "VRF Heat Pump Outdoor Unit Evaporating Temperature",
    4968              :                                 Constant::Units::C,
    4969            4 :                                 thisVrf.EvaporatingTemp,
    4970              :                                 OutputProcessor::TimeStepType::System,
    4971              :                                 OutputProcessor::StoreType::Average,
    4972            4 :                                 thisVrf.Name);
    4973            8 :             SetupOutputVariable(state,
    4974              :                                 "VRF Heat Pump Cooling Capacity at Max Compressor Speed",
    4975              :                                 Constant::Units::W,
    4976            4 :                                 thisVrf.CoolingCapacity,
    4977              :                                 OutputProcessor::TimeStepType::System,
    4978              :                                 OutputProcessor::StoreType::Average,
    4979            4 :                                 thisVrf.Name);
    4980            8 :             SetupOutputVariable(state,
    4981              :                                 "VRF Heat Pump Heating Capacity at Max Compressor Speed",
    4982              :                                 Constant::Units::W,
    4983            4 :                                 thisVrf.HeatingCapacity,
    4984              :                                 OutputProcessor::TimeStepType::System,
    4985              :                                 OutputProcessor::StoreType::Average,
    4986            4 :                                 thisVrf.Name);
    4987            8 :             SetupOutputVariable(state,
    4988              :                                 "VRF Heat Pump Indoor Unit Piping Correction for Cooling",
    4989              :                                 Constant::Units::None,
    4990            4 :                                 thisVrf.PipingCorrectionCooling,
    4991              :                                 OutputProcessor::TimeStepType::System,
    4992              :                                 OutputProcessor::StoreType::Average,
    4993            4 :                                 thisVrf.Name);
    4994            8 :             SetupOutputVariable(state,
    4995              :                                 "VRF Heat Pump Indoor Unit Piping Correction for Heating",
    4996              :                                 Constant::Units::None,
    4997            4 :                                 thisVrf.PipingCorrectionHeating,
    4998              :                                 OutputProcessor::TimeStepType::System,
    4999              :                                 OutputProcessor::StoreType::Average,
    5000            4 :                                 thisVrf.Name);
    5001            8 :             SetupOutputVariable(state,
    5002              :                                 "VRF Heat Pump Outdoor Unit Evaporator Heat Extract Rate",
    5003              :                                 Constant::Units::W,
    5004            4 :                                 thisVrf.OUEvapHeatRate,
    5005              :                                 OutputProcessor::TimeStepType::System,
    5006              :                                 OutputProcessor::StoreType::Average,
    5007            4 :                                 thisVrf.Name);
    5008            8 :             SetupOutputVariable(state,
    5009              :                                 "VRF Heat Pump Outdoor Unit Condenser Heat Release Rate",
    5010              :                                 Constant::Units::W,
    5011            4 :                                 thisVrf.OUCondHeatRate,
    5012              :                                 OutputProcessor::TimeStepType::System,
    5013              :                                 OutputProcessor::StoreType::Average,
    5014            4 :                                 thisVrf.Name);
    5015              : 
    5016              :         } else {
    5017              :             // For VRF_SysCurve Model
    5018           20 :             SetupOutputVariable(state,
    5019              :                                 "VRF Heat Pump Maximum Capacity Cooling Rate",
    5020              :                                 Constant::Units::W,
    5021           10 :                                 state.dataHVACVarRefFlow->MaxCoolingCapacity(NumCond),
    5022              :                                 OutputProcessor::TimeStepType::System,
    5023              :                                 OutputProcessor::StoreType::Average,
    5024           10 :                                 thisVrf.Name);
    5025           20 :             SetupOutputVariable(state,
    5026              :                                 "VRF Heat Pump Maximum Capacity Heating Rate",
    5027              :                                 Constant::Units::W,
    5028           10 :                                 state.dataHVACVarRefFlow->MaxHeatingCapacity(NumCond),
    5029              :                                 OutputProcessor::TimeStepType::System,
    5030              :                                 OutputProcessor::StoreType::Average,
    5031           10 :                                 thisVrf.Name);
    5032              :         }
    5033              : 
    5034           14 :         if (thisVrf.DefrostStrategy == StandardRatings::DefrostStrat::Resistive ||
    5035            4 :             (thisVrf.DefrostStrategy == StandardRatings::DefrostStrat::ReverseCycle && thisVrf.fuel == Constant::eFuel::Electricity)) {
    5036           28 :             SetupOutputVariable(state,
    5037              :                                 "VRF Heat Pump Defrost Electricity Rate",
    5038              :                                 Constant::Units::W,
    5039           14 :                                 thisVrf.DefrostPower,
    5040              :                                 OutputProcessor::TimeStepType::System,
    5041              :                                 OutputProcessor::StoreType::Average,
    5042           14 :                                 thisVrf.Name);
    5043           28 :             SetupOutputVariable(state,
    5044              :                                 "VRF Heat Pump Defrost Electricity Energy",
    5045              :                                 Constant::Units::J,
    5046           14 :                                 thisVrf.DefrostConsumption,
    5047              :                                 OutputProcessor::TimeStepType::System,
    5048              :                                 OutputProcessor::StoreType::Sum,
    5049           14 :                                 thisVrf.Name,
    5050              :                                 Constant::eResource::Electricity,
    5051              :                                 OutputProcessor::Group::HVAC,
    5052              :                                 OutputProcessor::EndUseCat::Heating);
    5053              : 
    5054              :         } else { // defrost energy applied to fuel type
    5055            0 :             SetupOutputVariable(state,
    5056            0 :                                 format("VRF Heat Pump Defrost {} Rate", sFuelType),
    5057              :                                 Constant::Units::W,
    5058            0 :                                 thisVrf.DefrostPower,
    5059              :                                 OutputProcessor::TimeStepType::System,
    5060              :                                 OutputProcessor::StoreType::Average,
    5061            0 :                                 thisVrf.Name);
    5062            0 :             SetupOutputVariable(state,
    5063            0 :                                 format("VRF Heat Pump Defrost {} Energy", sFuelType),
    5064              :                                 Constant::Units::J,
    5065            0 :                                 thisVrf.DefrostConsumption,
    5066              :                                 OutputProcessor::TimeStepType::System,
    5067              :                                 OutputProcessor::StoreType::Sum,
    5068            0 :                                 thisVrf.Name,
    5069            0 :                                 Constant::eFuel2eResource[(int)thisVrf.fuel],
    5070              :                                 OutputProcessor::Group::HVAC,
    5071              :                                 OutputProcessor::EndUseCat::Heating);
    5072              :         }
    5073              : 
    5074           28 :         SetupOutputVariable(state,
    5075              :                             "VRF Heat Pump Part Load Ratio",
    5076              :                             Constant::Units::None,
    5077           14 :                             thisVrf.VRFCondPLR,
    5078              :                             OutputProcessor::TimeStepType::System,
    5079              :                             OutputProcessor::StoreType::Average,
    5080           14 :                             thisVrf.Name);
    5081           28 :         SetupOutputVariable(state,
    5082              :                             "VRF Heat Pump Runtime Fraction",
    5083              :                             Constant::Units::None,
    5084           14 :                             thisVrf.VRFCondRTF,
    5085              :                             OutputProcessor::TimeStepType::System,
    5086              :                             OutputProcessor::StoreType::Average,
    5087           14 :                             thisVrf.Name);
    5088           28 :         SetupOutputVariable(state,
    5089              :                             "VRF Heat Pump Cycling Ratio",
    5090              :                             Constant::Units::None,
    5091           14 :                             thisVrf.VRFCondCyclingRatio,
    5092              :                             OutputProcessor::TimeStepType::System,
    5093              :                             OutputProcessor::StoreType::Average,
    5094           14 :                             thisVrf.Name);
    5095              : 
    5096           14 :         SetupOutputVariable(state,
    5097              :                             "VRF Heat Pump Operating Mode",
    5098              :                             Constant::Units::None,
    5099           14 :                             thisVrf.OperatingMode,
    5100              :                             OutputProcessor::TimeStepType::System,
    5101              :                             OutputProcessor::StoreType::Average,
    5102           14 :                             thisVrf.Name);
    5103           28 :         SetupOutputVariable(state,
    5104              :                             "VRF Heat Pump Condenser Inlet Temperature",
    5105              :                             Constant::Units::C,
    5106           14 :                             thisVrf.CondenserInletTemp,
    5107              :                             OutputProcessor::TimeStepType::System,
    5108              :                             OutputProcessor::StoreType::Average,
    5109           14 :                             thisVrf.Name);
    5110              : 
    5111           28 :         SetupOutputVariable(state,
    5112              :                             "VRF Heat Pump Crankcase Heater Electricity Rate",
    5113              :                             Constant::Units::W,
    5114           14 :                             thisVrf.CrankCaseHeaterPower,
    5115              :                             OutputProcessor::TimeStepType::System,
    5116              :                             OutputProcessor::StoreType::Average,
    5117           14 :                             thisVrf.Name);
    5118           28 :         SetupOutputVariable(state,
    5119              :                             "VRF Heat Pump Crankcase Heater Electricity Energy",
    5120              :                             Constant::Units::J,
    5121           14 :                             thisVrf.CrankCaseHeaterElecConsumption,
    5122              :                             OutputProcessor::TimeStepType::System,
    5123              :                             OutputProcessor::StoreType::Sum,
    5124           14 :                             thisVrf.Name,
    5125              :                             Constant::eResource::Electricity,
    5126              :                             OutputProcessor::Group::HVAC,
    5127              :                             OutputProcessor::EndUseCat::Cooling);
    5128           28 :         SetupOutputVariable(state,
    5129              :                             "VRF Heat Pump Terminal Unit Cooling Load Rate",
    5130              :                             Constant::Units::W,
    5131           14 :                             thisVrf.TUCoolingLoad,
    5132              :                             OutputProcessor::TimeStepType::System,
    5133              :                             OutputProcessor::StoreType::Average,
    5134           14 :                             thisVrf.Name);
    5135           28 :         SetupOutputVariable(state,
    5136              :                             "VRF Heat Pump Terminal Unit Heating Load Rate",
    5137              :                             Constant::Units::W,
    5138           14 :                             thisVrf.TUHeatingLoad,
    5139              :                             OutputProcessor::TimeStepType::System,
    5140              :                             OutputProcessor::StoreType::Average,
    5141           14 :                             thisVrf.Name);
    5142           14 :         if (thisVrf.HeatRecoveryUsed) {
    5143            4 :             SetupOutputVariable(state,
    5144              :                                 "VRF Heat Pump Heat Recovery Status Change Multiplier",
    5145              :                                 Constant::Units::None,
    5146            2 :                                 thisVrf.SUMultiplier,
    5147              :                                 OutputProcessor::TimeStepType::System,
    5148              :                                 OutputProcessor::StoreType::Average,
    5149            2 :                                 thisVrf.Name);
    5150            4 :             SetupOutputVariable(state,
    5151              :                                 "VRF Heat Pump Simultaneous Cooling and Heating Efficiency",
    5152              :                                 Constant::Units::Btu_h_W,
    5153            2 :                                 thisVrf.SCHE,
    5154              :                                 OutputProcessor::TimeStepType::System,
    5155              :                                 OutputProcessor::StoreType::Average,
    5156            2 :                                 thisVrf.Name);
    5157            4 :             SetupOutputVariable(state,
    5158              :                                 "VRF Heat Pump Heat Recovery Rate",
    5159              :                                 Constant::Units::W,
    5160            2 :                                 thisVrf.VRFHeatRec,
    5161              :                                 OutputProcessor::TimeStepType::System,
    5162              :                                 OutputProcessor::StoreType::Average,
    5163            2 :                                 thisVrf.Name);
    5164            4 :             SetupOutputVariable(state,
    5165              :                                 "VRF Heat Pump Heat Recovery Energy",
    5166              :                                 Constant::Units::J,
    5167            2 :                                 thisVrf.VRFHeatEnergyRec,
    5168              :                                 OutputProcessor::TimeStepType::System,
    5169              :                                 OutputProcessor::StoreType::Sum,
    5170            2 :                                 thisVrf.Name,
    5171              :                                 Constant::eResource::EnergyTransfer,
    5172              :                                 OutputProcessor::Group::Plant,
    5173              :                                 OutputProcessor::EndUseCat::HeatRecovery);
    5174              :         }
    5175              : 
    5176           14 :         if (thisVrf.CondenserType == DataHeatBalance::RefrigCondenserType::Evap) {
    5177            0 :             SetupOutputVariable(state,
    5178              :                                 "VRF Heat Pump Evaporative Condenser Water Use Volume",
    5179              :                                 Constant::Units::m3,
    5180            0 :                                 thisVrf.EvapWaterConsumpRate,
    5181              :                                 OutputProcessor::TimeStepType::System,
    5182              :                                 OutputProcessor::StoreType::Sum,
    5183            0 :                                 thisVrf.Name,
    5184              :                                 Constant::eResource::Water,
    5185              :                                 OutputProcessor::Group::HVAC,
    5186              :                                 OutputProcessor::EndUseCat::Cooling);
    5187            0 :             SetupOutputVariable(state,
    5188              :                                 "VRF Heat Pump Evaporative Condenser Pump Electricity Rate",
    5189              :                                 Constant::Units::W,
    5190            0 :                                 thisVrf.EvapCondPumpElecPower,
    5191              :                                 OutputProcessor::TimeStepType::System,
    5192              :                                 OutputProcessor::StoreType::Average,
    5193            0 :                                 thisVrf.Name);
    5194            0 :             SetupOutputVariable(state,
    5195              :                                 "VRF Heat Pump Evaporative Condenser Pump Electricity Energy",
    5196              :                                 Constant::Units::J,
    5197            0 :                                 thisVrf.EvapCondPumpElecConsumption,
    5198              :                                 OutputProcessor::TimeStepType::System,
    5199              :                                 OutputProcessor::StoreType::Sum,
    5200            0 :                                 thisVrf.Name,
    5201              :                                 Constant::eResource::Electricity,
    5202              :                                 OutputProcessor::Group::HVAC,
    5203              :                                 OutputProcessor::EndUseCat::Cooling);
    5204              : 
    5205            0 :             if (thisVrf.BasinHeaterPowerFTempDiff > 0.0) {
    5206            0 :                 SetupOutputVariable(state,
    5207              :                                     "VRF Heat Pump Basin Heater Electricity Rate",
    5208              :                                     Constant::Units::W,
    5209            0 :                                     thisVrf.BasinHeaterPower,
    5210              :                                     OutputProcessor::TimeStepType::System,
    5211              :                                     OutputProcessor::StoreType::Average,
    5212            0 :                                     thisVrf.Name);
    5213            0 :                 SetupOutputVariable(state,
    5214              :                                     "VRF Heat Pump Basin Heater Electricity Energy",
    5215              :                                     Constant::Units::J,
    5216            0 :                                     thisVrf.BasinHeaterConsumption,
    5217              :                                     OutputProcessor::TimeStepType::System,
    5218              :                                     OutputProcessor::StoreType::Sum,
    5219            0 :                                     thisVrf.Name,
    5220              :                                     Constant::eResource::Electricity,
    5221              :                                     OutputProcessor::Group::HVAC,
    5222              :                                     OutputProcessor::EndUseCat::Cooling);
    5223              :             }
    5224              : 
    5225           14 :         } else if (thisVrf.CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    5226            2 :             SetupOutputVariable(state,
    5227              :                                 "VRF Heat Pump Condenser Outlet Temperature",
    5228              :                                 Constant::Units::C,
    5229            1 :                                 thisVrf.CondenserSideOutletTemp,
    5230              :                                 OutputProcessor::TimeStepType::System,
    5231              :                                 OutputProcessor::StoreType::Average,
    5232            1 :                                 thisVrf.Name);
    5233            2 :             SetupOutputVariable(state,
    5234              :                                 "VRF Heat Pump Condenser Mass Flow Rate",
    5235              :                                 Constant::Units::kg_s,
    5236            1 :                                 thisVrf.WaterCondenserMassFlow,
    5237              :                                 OutputProcessor::TimeStepType::System,
    5238              :                                 OutputProcessor::StoreType::Average,
    5239            1 :                                 thisVrf.Name);
    5240            2 :             SetupOutputVariable(state,
    5241              :                                 "VRF Heat Pump Condenser Heat Transfer Rate",
    5242              :                                 Constant::Units::W,
    5243            1 :                                 thisVrf.QCondenser,
    5244              :                                 OutputProcessor::TimeStepType::System,
    5245              :                                 OutputProcessor::StoreType::Average,
    5246            1 :                                 thisVrf.Name);
    5247            2 :             SetupOutputVariable(state,
    5248              :                                 "VRF Heat Pump Condenser Heat Transfer Energy",
    5249              :                                 Constant::Units::J,
    5250            1 :                                 thisVrf.QCondEnergy,
    5251              :                                 OutputProcessor::TimeStepType::System,
    5252              :                                 OutputProcessor::StoreType::Sum,
    5253            1 :                                 thisVrf.Name);
    5254              :         }
    5255              : 
    5256           14 :         if (state.dataGlobal->AnyEnergyManagementSystemInModel) {
    5257            0 :             SetupEMSActuator(state,
    5258              :                              "Variable Refrigerant Flow Heat Pump",
    5259              :                              thisVrf.Name,
    5260              :                              "Operating Mode",
    5261              :                              "[integer]",
    5262            0 :                              thisVrf.EMSOverrideHPOperatingMode,
    5263            0 :                              thisVrf.EMSValueForHPOperatingMode);
    5264              :         }
    5265              :     }
    5266           13 : }
    5267              : 
    5268           62 : void CheckVRFTUNodeConnections(EnergyPlusData &state, int const VRFTUNum, bool &ErrorsFound)
    5269              : {
    5270              : 
    5271              :     constexpr static std::string_view cTerminalUnitType("ZoneHVAC:TerminalUnit:VariableRefrigerantFlow");
    5272           62 :     auto const &nodeID = state.dataLoopNodes->NodeID;
    5273           62 :     auto &vrfTU = state.dataHVACVarRefFlow->VRFTU(VRFTUNum);
    5274           62 :     std::string const cTUName(vrfTU.Name);
    5275           62 :     bool const CoolingCoilPresent = vrfTU.CoolingCoilPresent;
    5276           62 :     bool const HeatingCoilPresent = vrfTU.HeatingCoilPresent;
    5277           62 :     bool const SuppHeatingCoilPresent = vrfTU.SuppHeatingCoilPresent;
    5278           62 :     HVAC::FanPlace const fanPlace = vrfTU.fanPlace;
    5279           62 :     bool const FanPresent = fanPlace != HVAC::FanPlace::Invalid;
    5280           62 :     bool const OAMixerUsed = vrfTU.OAMixerUsed;
    5281           62 :     int const VRFTUInletNodeNum = vrfTU.VRFTUInletNodeNum;
    5282           62 :     int const VRFTUOutletNodeNum = vrfTU.VRFTUOutletNodeNum;
    5283           62 :     int const coolCoilAirInNode = vrfTU.coolCoilAirInNode;
    5284           62 :     int const coolCoilAirOutNode = vrfTU.coolCoilAirOutNode;
    5285           62 :     int const heatCoilAirInNode = vrfTU.heatCoilAirInNode;
    5286           62 :     int const heatCoilAirOutNode = vrfTU.heatCoilAirOutNode;
    5287           62 :     int const fanInletNode = vrfTU.fanInletNode;
    5288           62 :     int const fanOutletNode = vrfTU.fanOutletNode;
    5289           62 :     int const SuppHeatCoilAirInletNode = vrfTU.SuppHeatCoilAirInletNode;
    5290           62 :     int const SuppHeatCoilAirOutletNode = vrfTU.SuppHeatCoilAirOutletNode;
    5291           62 :     int const VRFTUOAMixerRetNodeNum = vrfTU.VRFTUOAMixerRetNodeNum;
    5292           62 :     int const VRFTUOAMixerMixedNodeNum = vrfTU.VRFTUOAMixerMixedNodeNum;
    5293              : 
    5294              :     // check that TU object internal nodes (TU inlet to TU outlet) are correctly connected
    5295              :     // the following is checked regardless of fan placement
    5296           62 :     if (CoolingCoilPresent && HeatingCoilPresent) {
    5297           62 :         if (coolCoilAirOutNode != heatCoilAirInNode) {
    5298            0 :             ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5299            0 :             ShowContinueError(state, "The cooling coil air outlet node name must match the heating coil air inlet node name.");
    5300            0 :             if (coolCoilAirOutNode > 0 && heatCoilAirInNode > 0) {
    5301            0 :                 ShowContinueError(state, format("... Cooling coil air outlet node = {}", nodeID(coolCoilAirOutNode)));
    5302            0 :                 ShowContinueError(state, format("... Heating coil air inlet node  = {}", nodeID(heatCoilAirInNode)));
    5303              :             }
    5304            0 :             ErrorsFound = true;
    5305              :         }
    5306              :     }
    5307              : 
    5308              :     // check the TU inlet node name with the first component
    5309           62 :     if (fanPlace == HVAC::FanPlace::DrawThru || !FanPresent) {
    5310           57 :         if (OAMixerUsed) {
    5311           46 :             if (VRFTUInletNodeNum != VRFTUOAMixerRetNodeNum) {
    5312            0 :                 ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5313            0 :                 ShowContinueError(state,
    5314              :                                   "... For draw thru or no fan when an OA mixer is specified the terminal unit "
    5315              :                                   "inlet node name must match the OA mixer return air stream node name.");
    5316            0 :                 if (VRFTUInletNodeNum > 0 && VRFTUOAMixerRetNodeNum > 0) {
    5317            0 :                     ShowContinueError(state, format("... Terminal unit inlet node name = {}.", nodeID(VRFTUInletNodeNum)));
    5318            0 :                     ShowContinueError(state, format("... OA mixer return air stream node name = {}.", nodeID(VRFTUOAMixerRetNodeNum)));
    5319              :                 }
    5320            0 :                 ErrorsFound = true;
    5321              :             }
    5322              :             // check mixer outlet with next component
    5323           46 :             if (CoolingCoilPresent) {
    5324           46 :                 if (VRFTUOAMixerMixedNodeNum != coolCoilAirInNode) {
    5325            0 :                     ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5326            0 :                     ShowContinueError(state,
    5327              :                                       "... For draw thru or no fan when an OA mixer is specified and a cooling coil is present "
    5328              :                                       "the OA mixer mixed air node name must match the cooling coil inlet node name.");
    5329            0 :                     if (VRFTUOAMixerMixedNodeNum > 0 && coolCoilAirInNode > 0) {
    5330            0 :                         ShowContinueError(state, format("... OA mixer mixed air node name = {}.", nodeID(VRFTUOAMixerMixedNodeNum)));
    5331            0 :                         ShowContinueError(state, format("... Cooling coil inlet node name = {}.", nodeID(coolCoilAirInNode)));
    5332              :                     }
    5333            0 :                     ErrorsFound = true;
    5334              :                 }
    5335            0 :             } else if (HeatingCoilPresent) {
    5336            0 :                 if (VRFTUOAMixerMixedNodeNum != heatCoilAirInNode) {
    5337            0 :                     ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5338            0 :                     ShowContinueError(state,
    5339              :                                       "... For draw thru or no fan when an OA mixer is specified and a cooling coil is not present "
    5340              :                                       "the OA mixer mixed air node name must match the heating coil inlet node name.");
    5341            0 :                     if (VRFTUOAMixerMixedNodeNum > 0 && heatCoilAirInNode > 0) {
    5342            0 :                         ShowContinueError(state, format("... OA mixer mixed air node name = {}.", nodeID(VRFTUOAMixerMixedNodeNum)));
    5343            0 :                         ShowContinueError(state, format("... Heating coil inlet node name = {}.", nodeID(heatCoilAirInNode)));
    5344              :                     }
    5345            0 :                     ErrorsFound = true;
    5346              :                 }
    5347              :             }
    5348              :         } else { // OAMixer not used
    5349           11 :             if (CoolingCoilPresent) {
    5350           11 :                 if (VRFTUInletNodeNum != coolCoilAirInNode) {
    5351            0 :                     ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5352            0 :                     ShowContinueError(
    5353              :                         state,
    5354              :                         "... For draw thru or no fan when no OA mixer is specified and a cooling coil is present the terminal unit inlet "
    5355              :                         "node name must match the cooling coil inlet node name.");
    5356            0 :                     if (VRFTUInletNodeNum > 0 && coolCoilAirInNode > 0) {
    5357            0 :                         ShowContinueError(state, format("... Terminal unit inlet node name = {}.", nodeID(VRFTUInletNodeNum)));
    5358            0 :                         ShowContinueError(state, format("... Cooling coil inlet node name = {}.", nodeID(coolCoilAirInNode)));
    5359              :                     }
    5360            0 :                     ErrorsFound = true;
    5361              :                 }
    5362            0 :             } else if (HeatingCoilPresent) {
    5363            0 :                 if (VRFTUInletNodeNum != heatCoilAirInNode) {
    5364            0 :                     ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5365            0 :                     ShowContinueError(state,
    5366              :                                       "... For draw thru or no fan when no cooling coil or OA mixer is specified the terminal unit inlet "
    5367              :                                       "node name must match the heating coil inlet node name.");
    5368            0 :                     if (VRFTUInletNodeNum > 0 && heatCoilAirInNode > 0) {
    5369            0 :                         ShowContinueError(state, format("... Terminal unit inlet node name = {}.", nodeID(VRFTUInletNodeNum)));
    5370            0 :                         ShowContinueError(state, format("... Heating coil inlet node name = {}.", nodeID(heatCoilAirInNode)));
    5371              :                     }
    5372            0 :                     ErrorsFound = true;
    5373              :                 }
    5374              :             }
    5375              :         }
    5376              :     }
    5377           62 :     if (fanPlace == HVAC::FanPlace::BlowThru && !OAMixerUsed) {
    5378            0 :         if (VRFTUInletNodeNum != fanInletNode) {
    5379            0 :             ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5380            0 :             ShowContinueError(state,
    5381              :                               "... For blow thru fan when no OA mixer is specified the terminal unit inlet "
    5382              :                               "node name must match the fan inlet node name.");
    5383            0 :             if (VRFTUInletNodeNum > 0 && fanInletNode > 0) {
    5384            0 :                 ShowContinueError(state, format("... Terminal unit inlet node name = {}.", nodeID(VRFTUInletNodeNum)));
    5385            0 :                 ShowContinueError(state, format("... Fan inlet node name = {}.", nodeID(fanInletNode)));
    5386              :             }
    5387            0 :             ErrorsFound = true;
    5388              :         }
    5389           62 :     } else if (OAMixerUsed) { // when OA mixer is used TU inlet = OAMixer return node regardless of fan placement
    5390           51 :         if (VRFTUInletNodeNum != VRFTUOAMixerRetNodeNum) {
    5391            0 :             ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5392            0 :             ShowContinueError(state,
    5393              :                               "... When an OA mixer is specified the terminal unit inlet "
    5394              :                               "node name must match the OA mixer return node name.");
    5395            0 :             if (VRFTUInletNodeNum > 0 && VRFTUOAMixerRetNodeNum > 0) {
    5396            0 :                 ShowContinueError(state, format("... Terminal unit inlet node name = {}.", nodeID(VRFTUInletNodeNum)));
    5397            0 :                 ShowContinueError(state, format("... Fan inlet node name = {}.", nodeID(VRFTUOAMixerRetNodeNum)));
    5398              :             }
    5399            0 :             ErrorsFound = true;
    5400              :         }
    5401              :     }
    5402              :     // check the next component
    5403           62 :     if (CoolingCoilPresent) {
    5404           62 :         if (fanPlace == HVAC::FanPlace::BlowThru) {
    5405            5 :             if (fanOutletNode != coolCoilAirInNode) {
    5406            0 :                 ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5407            0 :                 ShowContinueError(state,
    5408              :                                   "... For blow thru fan when a cooling coil is present "
    5409              :                                   "fan outlet node name must match the cooling coil inlet node name.");
    5410            0 :                 if (fanOutletNode > 0 && coolCoilAirInNode > 0) {
    5411            0 :                     ShowContinueError(state, format("... The fan outlet node name = {}.", nodeID(fanOutletNode)));
    5412            0 :                     ShowContinueError(state, format("... Cooling coil inlet node name = {}.", nodeID(coolCoilAirInNode)));
    5413              :                 }
    5414            0 :                 ErrorsFound = true;
    5415              :             }
    5416              :         }
    5417           62 :         if (!HeatingCoilPresent && fanPlace == HVAC::FanPlace::DrawThru) {
    5418            0 :             if (coolCoilAirOutNode != fanInletNode) {
    5419            0 :                 ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5420            0 :                 ShowContinueError(state,
    5421              :                                   "... For draw thru fan when a heating coil is not present "
    5422              :                                   "the cooling coil outlet node name must match the fan inlet node name.");
    5423            0 :                 if (coolCoilAirOutNode > 0 && fanInletNode > 0) {
    5424            0 :                     ShowContinueError(state, format("... Cooling coil outlet node name = {}.", nodeID(coolCoilAirOutNode)));
    5425            0 :                     ShowContinueError(state, format("... The fan inlet node name = {}.", nodeID(fanInletNode)));
    5426              :                 }
    5427            0 :                 ErrorsFound = true;
    5428              :             }
    5429              :         }
    5430              :     }
    5431           62 :     if (HeatingCoilPresent) {
    5432           62 :         if (fanPlace == HVAC::FanPlace::DrawThru) {
    5433           56 :             if (heatCoilAirOutNode != fanInletNode) {
    5434            0 :                 ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5435            0 :                 ShowContinueError(state,
    5436              :                                   "... For draw thru fan when a heating coil is present "
    5437              :                                   "the heating coil outlet node name must match the fan inlet node name.");
    5438            0 :                 if (heatCoilAirOutNode > 0 && fanInletNode > 0) {
    5439            0 :                     ShowContinueError(state, format("... Heating coil outlet node name = {}.", nodeID(heatCoilAirOutNode)));
    5440            0 :                     ShowContinueError(state, format("... The fan inlet node name = {}.", nodeID(fanInletNode)));
    5441              :                 }
    5442            0 :                 ErrorsFound = true;
    5443              :             }
    5444              :         }
    5445              :     }
    5446           62 :     if (SuppHeatingCoilPresent) {
    5447           11 :         if (SuppHeatCoilAirOutletNode != VRFTUOutletNodeNum) {
    5448            0 :             ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5449            0 :             ShowContinueError(state, "... The supplemental heating coil outlet node name must match the terminal unit outlet node name.");
    5450            0 :             if (SuppHeatCoilAirOutletNode > 0 && VRFTUOutletNodeNum > 0) {
    5451            0 :                 ShowContinueError(state, format("... Supplemental heating coil outlet node name = {}.", nodeID(SuppHeatCoilAirOutletNode)));
    5452            0 :                 ShowContinueError(state, format("... Terminal unit outlet node name = {}.", nodeID(VRFTUOutletNodeNum)));
    5453              :             }
    5454            0 :             ErrorsFound = true;
    5455              :         }
    5456           11 :         if (fanPlace == HVAC::FanPlace::DrawThru) {
    5457           11 :             if (fanOutletNode != SuppHeatCoilAirInletNode) {
    5458            0 :                 ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5459            0 :                 ShowContinueError(state,
    5460              :                                   "... For draw thru fan when a supplemental heating coil is present "
    5461              :                                   "the fan outlet node name must match the supplemental heating coil inlet node name.");
    5462            0 :                 if (fanOutletNode > 0 && SuppHeatCoilAirInletNode > 0) {
    5463            0 :                     ShowContinueError(state, format("... Fan outlet node name = {}.", nodeID(fanOutletNode)));
    5464            0 :                     ShowContinueError(state, format("... Supplemental heating coil inlet node name = {}.", nodeID(SuppHeatCoilAirInletNode)));
    5465              :                 }
    5466            0 :                 ErrorsFound = true;
    5467              :             }
    5468              :         } else {
    5469            0 :             if (heatCoilAirOutNode != SuppHeatCoilAirInletNode) {
    5470            0 :                 ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5471            0 :                 ShowContinueError(state,
    5472              :                                   "... For blow thru or no fan when a supplemental heating coil is present the heating "
    5473              :                                   "coil outlet node name must match the supplemental heating coil inlet node name.");
    5474            0 :                 if (heatCoilAirOutNode > 0 && SuppHeatCoilAirInletNode > 0) {
    5475            0 :                     ShowContinueError(state, format("... Heating coil outlet node name = {}.", nodeID(heatCoilAirOutNode)));
    5476            0 :                     ShowContinueError(state, format("... Supplemental heating coil inlet node name = {}.", nodeID(SuppHeatCoilAirInletNode)));
    5477              :                 }
    5478            0 :                 ErrorsFound = true;
    5479              :             }
    5480              :         }
    5481           51 :     } else if (CoolingCoilPresent && !HeatingCoilPresent && (fanPlace == HVAC::FanPlace::BlowThru || !FanPresent)) {
    5482            0 :         if (coolCoilAirOutNode != VRFTUOutletNodeNum) {
    5483            0 :             ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5484            0 :             ShowContinueError(state,
    5485              :                               "... For blow through or no fan and no heating or supplemental heating coil the cooling coil outlet node name must "
    5486              :                               "match the terminal unit outlet node name.");
    5487            0 :             if (coolCoilAirOutNode > 0 && VRFTUOutletNodeNum > 0) {
    5488            0 :                 ShowContinueError(state, format("... Cooling coil outlet node name = {}.", nodeID(coolCoilAirOutNode)));
    5489            0 :                 ShowContinueError(state, format("... Terminal unit outlet node name = {}.", nodeID(VRFTUOutletNodeNum)));
    5490              :             }
    5491            0 :             ErrorsFound = true;
    5492              :         }
    5493            0 :         if (fanPlace == HVAC::FanPlace::DrawThru) {
    5494            0 :             if (fanOutletNode != VRFTUOutletNodeNum) {
    5495            0 :                 ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5496            0 :                 ShowContinueError(state,
    5497              :                                   "... For draw through fan and no supplemental heating coil the fan outlet node name must "
    5498              :                                   "match the terminal unit outlet node name.");
    5499            0 :                 if (fanOutletNode > 0 && VRFTUOutletNodeNum > 0) {
    5500            0 :                     ShowContinueError(state, format("... Fan outlet node name = {}.", nodeID(fanOutletNode)));
    5501            0 :                     ShowContinueError(state, format("... Terminal unit outlet node name = {}.", nodeID(VRFTUOutletNodeNum)));
    5502              :                 }
    5503            0 :                 ErrorsFound = true;
    5504              :             }
    5505              :         }
    5506           51 :     } else if (fanPlace == HVAC::FanPlace::DrawThru) {
    5507           45 :         if (fanOutletNode != VRFTUOutletNodeNum) {
    5508            0 :             ShowSevereError(state, fmt::format("{}=\"{}\",", cTerminalUnitType, cTUName));
    5509            0 :             ShowContinueError(state,
    5510              :                               "... For draw through fan and no supplemental heating coil the fan outlet node name must "
    5511              :                               "match the terminal unit outlet node name.");
    5512            0 :             if (fanOutletNode > 0 && VRFTUOutletNodeNum > 0) {
    5513            0 :                 ShowContinueError(state, format("... Fan outlet node name = {}.", nodeID(fanOutletNode)));
    5514            0 :                 ShowContinueError(state, format("... Terminal unit outlet node name = {}.", nodeID(VRFTUOutletNodeNum)));
    5515              :             }
    5516            0 :             ErrorsFound = true;
    5517              :         }
    5518              :     }
    5519           62 : }
    5520              : 
    5521       244151 : void InitVRF(EnergyPlusData &state, int const VRFTUNum, int const ZoneNum, bool const FirstHVACIteration, Real64 &OnOffAirFlowRatio, Real64 &QZnReq)
    5522              : {
    5523              : 
    5524              :     // SUBROUTINE INFORMATION:
    5525              :     //       AUTHOR         Richard Raustad, FSEC
    5526              :     //       DATE WRITTEN   August 2010
    5527              :     //       MODIFIED       July 2012, Chandan Sharma - FSEC: Added zone sys avail managers
    5528              :     //       RE-ENGINEERED  na
    5529              : 
    5530              :     // PURPOSE OF THIS SUBROUTINE:
    5531              :     // This subroutine is for initializations of the VRF Components.
    5532              : 
    5533              :     // METHODOLOGY EMPLOYED:
    5534              :     // Uses the status flags to trigger initializations.
    5535              : 
    5536              :     using DataSizing::AutoSize;
    5537              :     using DataZoneEquipment::CheckZoneEquipmentList;
    5538              : 
    5539              :     using PlantUtilities::InitComponentNodes;
    5540              :     using SingleDuct::SimATMixer;
    5541              : 
    5542              :     static constexpr std::string_view RoutineName("InitVRF");
    5543              : 
    5544              :     int InNode;                  // TU inlet node
    5545              :     int OutNode;                 // TU outlet node
    5546              :     int OutsideAirNode;          // TU mixer outside air inlet node
    5547              :     int NumTULoop;               // loop counter, number of TU's in list
    5548              :     int ELLoop;                  // loop counter, number of zone equipment lists
    5549              :     int ListLoop;                // loop counter, number of equipment is each list
    5550              :     int VRFCond;                 // index to VRF condenser
    5551              :     int TUIndex;                 // index to TU
    5552              :     int TUListNum;               // index to VRF AC system terminal unit list
    5553              :     int TUListIndex;             // pointer to TU list for this VRF system
    5554              :     int IndexToTUInTUList;       // index to TU in TerminalUnilList
    5555              :     Real64 RhoAir;               // air density at InNode
    5556              :     Real64 CurrentEndTime;       // end time of current time step
    5557       244151 :     Real64 TimeStepSysLast(0.0); // system time step on last time step
    5558              :     Real64 TempOutput;           // Sensible output of TU
    5559              :     Real64 LoadToCoolingSP;      // thermostat load to cooling setpoint (W)
    5560              :     Real64 LoadToHeatingSP;      // thermostat load to heating setpoint (W)
    5561              :     bool EnableSystem;           // use to turn on secondary operating mode if OA temp limits exceeded
    5562              :     bool ErrorsFound;            // flag returned from mining call
    5563              :     Real64 rho;                  // density of water (kg/m3)
    5564              :     Real64 OutsideDryBulbTemp;   // Outdoor air temperature at external node height
    5565              :     bool errFlag;                // local error flag
    5566              :     Real64 SuppHeatCoilLoad;     // additional heating required by supplemental heater (W)
    5567              :     Real64 SuppHeatCoilCapacity; // supplemental heating coil size (W)
    5568              : 
    5569              :     // ALLOCATE and Initialize subroutine variables
    5570       244151 :     if (state.dataHVACVarRefFlow->MyOneTimeFlag) {
    5571              : 
    5572           13 :         state.dataHVACVarRefFlow->MyEnvrnFlag.allocate(state.dataHVACVarRefFlow->NumVRFTU);
    5573           13 :         state.dataHVACVarRefFlow->MySizeFlag.allocate(state.dataHVACVarRefFlow->NumVRFTU);
    5574           13 :         state.dataHVACVarRefFlow->MyVRFFlag.allocate(state.dataHVACVarRefFlow->NumVRFTU);
    5575           13 :         state.dataHVACVarRefFlow->MyZoneEqFlag.allocate(state.dataHVACVarRefFlow->NumVRFTU);
    5576           13 :         state.dataHVACVarRefFlow->MyBeginTimeStepFlag.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5577           13 :         state.dataHVACVarRefFlow->MaxDeltaT.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5578           13 :         state.dataHVACVarRefFlow->MinDeltaT.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5579           13 :         state.dataHVACVarRefFlow->LastModeCooling.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5580           13 :         state.dataHVACVarRefFlow->LastModeHeating.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5581           13 :         state.dataHVACVarRefFlow->HeatingLoad.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5582           13 :         state.dataHVACVarRefFlow->CoolingLoad.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5583           13 :         state.dataHVACVarRefFlow->NumCoolingLoads.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5584           13 :         state.dataHVACVarRefFlow->SumCoolingLoads.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5585           13 :         state.dataHVACVarRefFlow->NumHeatingLoads.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5586           13 :         state.dataHVACVarRefFlow->SumHeatingLoads.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5587           13 :         state.dataHVACVarRefFlow->MyVRFCondFlag.allocate(state.dataHVACVarRefFlow->NumVRFCond);
    5588           13 :         state.dataHVACVarRefFlow->MyEnvrnFlag = true;
    5589           13 :         state.dataHVACVarRefFlow->MySizeFlag = true;
    5590           13 :         state.dataHVACVarRefFlow->MyVRFFlag = true;
    5591           13 :         state.dataHVACVarRefFlow->MyZoneEqFlag = true;
    5592           13 :         state.dataHVACVarRefFlow->MyBeginTimeStepFlag = true;
    5593           13 :         state.dataHVACVarRefFlow->MaxDeltaT = 0.0;
    5594           13 :         state.dataHVACVarRefFlow->MinDeltaT = 0.0;
    5595           13 :         state.dataHVACVarRefFlow->LastModeCooling = false;
    5596           13 :         state.dataHVACVarRefFlow->LastModeHeating = true;
    5597           13 :         state.dataHVACVarRefFlow->NumCoolingLoads = 0;
    5598           13 :         state.dataHVACVarRefFlow->SumCoolingLoads = 0.0;
    5599           13 :         state.dataHVACVarRefFlow->NumHeatingLoads = 0;
    5600           13 :         state.dataHVACVarRefFlow->SumHeatingLoads = 0.0;
    5601              : 
    5602           13 :         state.dataHVACVarRefFlow->MyOneTimeFlag = false;
    5603           13 :         state.dataHVACVarRefFlow->MyVRFCondFlag = true;
    5604              : 
    5605              :     } // IF (MyOneTimeFlag) THEN
    5606              : 
    5607              :     // identify VRF condenser connected to this TU
    5608       244151 :     VRFCond = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum;
    5609       244151 :     TUListIndex = state.dataHVACVarRefFlow->VRF(VRFCond).ZoneTUListPtr;
    5610       244151 :     InNode = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum;
    5611       244151 :     OutNode = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOutletNodeNum;
    5612       244151 :     OutsideAirNode = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerOANodeNum;
    5613       244151 :     IndexToTUInTUList = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).IndexToTUInTUList;
    5614              : 
    5615       244151 :     SuppHeatCoilCapacity = 0.0;
    5616       244151 :     SuppHeatCoilLoad = 0.0;
    5617       244151 :     LoadToCoolingSP = 0.0;
    5618       244151 :     LoadToHeatingSP = 0.0;
    5619       244151 :     ErrorsFound = false;
    5620       244151 :     bool SetPointErrorFlag = false;
    5621              : 
    5622              :     // set condenser inlet temp, used as surrogate for OAT (used to check limits of operation)
    5623       244151 :     if (state.dataHVACVarRefFlow->VRF(VRFCond).CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    5624        15076 :         OutsideDryBulbTemp = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRF(VRFCond).CondenserNodeNum).Temp;
    5625              :     } else {
    5626       229075 :         if (OutsideAirNode == 0) {
    5627        33843 :             OutsideDryBulbTemp = state.dataEnvrn->OutDryBulbTemp;
    5628              :         } else {
    5629       195232 :             OutsideDryBulbTemp = state.dataLoopNodes->Node(OutsideAirNode).Temp;
    5630              :         }
    5631              :     }
    5632              : 
    5633       244151 :     if (allocated(state.dataAvail->ZoneComp)) {
    5634       244107 :         auto &availMgr = state.dataAvail->ZoneComp(DataZoneEquipment::ZoneEquipType::VariableRefrigerantFlowTerminal).ZoneCompAvailMgrs(VRFTUNum);
    5635       244107 :         if (state.dataHVACVarRefFlow->MyZoneEqFlag(VRFTUNum)) { // initialize the name of each availability manager list and zone number
    5636           62 :             availMgr.AvailManagerListName = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).AvailManagerListName;
    5637           62 :             availMgr.ZoneNum = ZoneNum;
    5638           62 :             state.dataHVACVarRefFlow->MyZoneEqFlag(VRFTUNum) = false;
    5639              :         }
    5640       244107 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).availStatus = availMgr.availStatus;
    5641              :     }
    5642              : 
    5643       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MySuppCoilPlantScanFlag && allocated(state.dataPlnt->PlantLoop)) {
    5644           62 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType_Num == HVAC::Coil_HeatingWater) {
    5645              :             // hot water supplemental heating coil
    5646            2 :             errFlag = false;
    5647            4 :             PlantUtilities::ScanPlantLoopsForObject(state,
    5648            2 :                                                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
    5649              :                                                     PlantEquipmentType::CoilWaterSimpleHeating,
    5650            2 :                                                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilPlantLoc,
    5651              :                                                     errFlag,
    5652              :                                                     _,
    5653              :                                                     _,
    5654              :                                                     _,
    5655              :                                                     _,
    5656              :                                                     _);
    5657              : 
    5658            2 :             WaterCoils::SetCoilDesFlow(state,
    5659            2 :                                        HVAC::cAllCoilTypes(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType_Num),
    5660            2 :                                        state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
    5661            2 :                                        state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow,
    5662              :                                        errFlag);
    5663              : 
    5664            2 :             if (errFlag) {
    5665            0 :                 ShowFatalError(state, format("{}: Program terminated for previous conditions.", RoutineName));
    5666              :             }
    5667            2 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow = WaterCoils::GetCoilMaxWaterFlowRate(
    5668            2 :                 state, "Coil:Heating:Water", state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName, ErrorsFound);
    5669              : 
    5670            2 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow > 0.0) {
    5671            0 :                 rho = state.dataPlnt->PlantLoop(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilPlantLoc.loopNum)
    5672            0 :                           .glycol->getDensity(state, Constant::HWInitConvTemp, RoutineName);
    5673            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow =
    5674            0 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow * rho;
    5675              :             }
    5676              : 
    5677              :             // fill fluid outlet node for hot water coil SuppHeatCoilFluidOutletNode
    5678            2 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidOutletNode =
    5679            2 :                 DataPlant::CompData::getPlantComponent(state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilPlantLoc).NodeNumOut;
    5680            2 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MySuppCoilPlantScanFlag = false;
    5681              : 
    5682           60 :         } else if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType_Num == HVAC::Coil_HeatingSteam) {
    5683              :             // steam supplemental heating coil
    5684            2 :             errFlag = false;
    5685            4 :             PlantUtilities::ScanPlantLoopsForObject(state,
    5686            2 :                                                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
    5687              :                                                     PlantEquipmentType::CoilSteamAirHeating,
    5688            2 :                                                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilPlantLoc,
    5689              :                                                     errFlag,
    5690              :                                                     _,
    5691              :                                                     _,
    5692              :                                                     _,
    5693              :                                                     _,
    5694              :                                                     _);
    5695            2 :             if (errFlag) {
    5696            0 :                 ShowFatalError(state, format("{}: Program terminated for previous conditions.", RoutineName));
    5697              :             }
    5698            2 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow =
    5699            2 :                 SteamCoils::GetCoilMaxSteamFlowRate(state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilIndex, ErrorsFound);
    5700            2 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow > 0.0) {
    5701            0 :                 Real64 TempSteamIn = 100.0;
    5702            0 :                 Real64 SteamDensity = Fluid::GetSteam(state)->getSatDensity(state, TempSteamIn, 1.0, RoutineName);
    5703            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow =
    5704            0 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow * SteamDensity;
    5705              :             }
    5706              : 
    5707              :             // fill fluid outlet node for steam coil SuppHeatCoilFluidOutletNode
    5708            2 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidOutletNode =
    5709            2 :                 DataPlant::CompData::getPlantComponent(state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilPlantLoc).NodeNumOut;
    5710            2 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MySuppCoilPlantScanFlag = false;
    5711              : 
    5712              :         } else { // VRF terminal unit not connected to plant
    5713           58 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MySuppCoilPlantScanFlag = false;
    5714              :         }
    5715       244089 :     } else if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MySuppCoilPlantScanFlag && !state.dataGlobal->AnyPlantInModel) {
    5716            0 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MySuppCoilPlantScanFlag = false;
    5717              :     }
    5718              : 
    5719              :     // one-time check to see if VRF TU's are on ZoneHVAC:EquipmentList or AirloopHVAC or issue warning
    5720       244151 :     if (state.dataHVACVarRefFlow->ZoneEquipmentListNotChecked) {
    5721          164 :         if (state.dataAirLoop->AirLoopInputsFilled) {
    5722           13 :             state.dataHVACVarRefFlow->ZoneEquipmentListNotChecked = false;
    5723              :         }
    5724          164 :         bool AirLoopFound = false;
    5725          164 :         bool errorsFound = false;
    5726          164 :         bool AirNodeFound = false;
    5727          164 :         int ctrlZoneNum = 0;
    5728          164 :         std::string const cCurrentModuleObject = "ZoneHVAC:TerminalUnit:VariableRefrigerantFlow";
    5729          339 :         for (TUListNum = 1; TUListNum <= state.dataHVACVarRefFlow->NumVRFTULists; ++TUListNum) {
    5730          998 :             for (NumTULoop = 1; NumTULoop <= state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList; ++NumTULoop) {
    5731          823 :                 AirLoopFound = false; // reset for next TU
    5732          823 :                 ctrlZoneNum = 0;      // reset for next TU
    5733          823 :                 TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTULoop);
    5734          823 :                 std::string const thisObjectName = state.dataHVACVarRefFlow->VRFTU(TUIndex).Name;
    5735          823 :                 if (state.dataHVACVarRefFlow->VRFTU(TUIndex).isInZone) {
    5736          733 :                     goto EquipList_exit; // already found previously
    5737              :                 }
    5738          445 :                 for (ELLoop = 1; ELLoop <= state.dataGlobal->NumOfZones; ++ELLoop) { // NumOfZoneEquipLists
    5739          415 :                     if (state.dataZoneEquip->ZoneEquipList(ELLoop).Name == "") {
    5740           89 :                         continue; // dimensioned by NumOfZones.  Only valid ones have names.
    5741              :                     }
    5742          797 :                     for (ListLoop = 1; ListLoop <= state.dataZoneEquip->ZoneEquipList(ELLoop).NumOfEquipTypes; ++ListLoop) {
    5743          531 :                         if (!Util::SameString(state.dataZoneEquip->ZoneEquipList(ELLoop).EquipTypeName(ListLoop),
    5744          531 :                                               tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(TUIndex).type])) {
    5745          235 :                             continue;
    5746              :                         }
    5747          296 :                         if (!Util::SameString(state.dataZoneEquip->ZoneEquipList(ELLoop).EquipName(ListLoop),
    5748          296 :                                               state.dataHVACVarRefFlow->VRFTU(TUIndex).Name)) {
    5749          236 :                             continue;
    5750              :                         }
    5751           60 :                         state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum = ELLoop;
    5752           60 :                         state.dataHVACVarRefFlow->VRFTU(TUIndex).isInZone = true;
    5753           60 :                         if (state.dataHVACVarRefFlow->VRF(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFSysNum).MasterZonePtr == ELLoop) {
    5754            9 :                             state.dataHVACVarRefFlow->VRF(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFSysNum).MasterZoneTUIndex = TUIndex;
    5755              :                         }
    5756           60 :                         if (state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneAirNode == 0) {
    5757            0 :                             bool ZoneNodeNotFound = true;
    5758            0 :                             for (int CtrlZone = 1; CtrlZone <= state.dataGlobal->NumOfZones; ++CtrlZone) {
    5759            0 :                                 if (!state.dataZoneEquip->ZoneEquipConfig(CtrlZone).IsControlled) {
    5760            0 :                                     continue;
    5761              :                                 }
    5762            0 :                                 for (int NodeNum = 1; NodeNum <= state.dataZoneEquip->ZoneEquipConfig(CtrlZone).NumExhaustNodes; ++NodeNum) {
    5763            0 :                                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUInletNodeNum ==
    5764            0 :                                         state.dataZoneEquip->ZoneEquipConfig(CtrlZone).ExhaustNode(NodeNum)) {
    5765            0 :                                         state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneAirNode =
    5766            0 :                                             state.dataZoneEquip->ZoneEquipConfig(CtrlZone).ZoneNode;
    5767            0 :                                         ZoneNodeNotFound = false;
    5768            0 :                                         break;
    5769              :                                     }
    5770              :                                 }
    5771            0 :                                 for (int NodeNum = 1; NodeNum <= state.dataZoneEquip->ZoneEquipConfig(CtrlZone).NumInletNodes; ++NodeNum) {
    5772            0 :                                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOutletNodeNum ==
    5773            0 :                                         state.dataZoneEquip->ZoneEquipConfig(CtrlZone).InletNode(NodeNum)) {
    5774            0 :                                         state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneAirNode =
    5775            0 :                                             state.dataZoneEquip->ZoneEquipConfig(CtrlZone).ZoneNode;
    5776            0 :                                         ZoneNodeNotFound = false;
    5777            0 :                                         break;
    5778              :                                     }
    5779              :                                 }
    5780            0 :                                 if (!ZoneNodeNotFound) {
    5781            0 :                                     break;
    5782              :                                 }
    5783              :                             }
    5784            0 :                             if (ZoneNodeNotFound) {
    5785            0 :                                 ShowSevereError(state,
    5786            0 :                                                 format("ZoneHVAC:TerminalUnit:VariableRefrigerantFlow \"{}\" Zone terminal unit air inlet node name "
    5787              :                                                        "must be the same as a zone inlet or exhaust node name.",
    5788            0 :                                                        state.dataHVACVarRefFlow->VRFTU(TUIndex).Name));
    5789            0 :                                 ShowContinueError(state,
    5790              :                                                   "... Zone inlet and exhaust node name is specified in ZoneHVAC:EquipmentConnections object.");
    5791            0 :                                 ShowContinueError(state,
    5792            0 :                                                   format("... Zone terminal unit inlet node name  = {}",
    5793            0 :                                                          state.dataLoopNodes->NodeID(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUInletNodeNum)));
    5794            0 :                                 ShowContinueError(state,
    5795            0 :                                                   format("... Zone terminal unit outlet node name = {}",
    5796            0 :                                                          state.dataLoopNodes->NodeID(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOutletNodeNum)));
    5797              :                             }
    5798              :                         }
    5799           60 :                         goto EquipList_exit;
    5800              :                     }
    5801              :                 }
    5802              :                 // check if the TU is connected to an air loop
    5803           30 :                 if (!state.dataHVACVarRefFlow->VRFTU(TUIndex).isInAirLoop) {
    5804           31 :                     for (int AirLoopNum = 1; AirLoopNum <= state.dataHVACGlobal->NumPrimaryAirSys; ++AirLoopNum) {
    5805           23 :                         for (int BranchNum = 1; BranchNum <= state.dataAirSystemsData->PrimaryAirSystems(AirLoopNum).NumBranches; ++BranchNum) {
    5806           35 :                             for (int CompNum = 1;
    5807           35 :                                  CompNum <= state.dataAirSystemsData->PrimaryAirSystems(AirLoopNum).Branch(BranchNum).TotalComponents;
    5808              :                                  ++CompNum) {
    5809           24 :                                 if (Util::SameString(state.dataAirSystemsData->PrimaryAirSystems(AirLoopNum).Branch(BranchNum).Comp(CompNum).Name,
    5810           25 :                                                      thisObjectName) &&
    5811            1 :                                     Util::SameString(state.dataAirSystemsData->PrimaryAirSystems(AirLoopNum).Branch(BranchNum).Comp(CompNum).TypeOf,
    5812              :                                                      cCurrentModuleObject)) {
    5813            1 :                                     state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum = AirLoopNum;
    5814            1 :                                     AirLoopFound = true;
    5815            1 :                                     state.dataHVACVarRefFlow->VRFTU(TUIndex).isInAirLoop = true;
    5816            2 :                                     BranchNodeConnections::TestCompSet(
    5817              :                                         state,
    5818              :                                         cCurrentModuleObject,
    5819              :                                         thisObjectName,
    5820            1 :                                         state.dataLoopNodes->NodeID(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUInletNodeNum),
    5821            1 :                                         state.dataLoopNodes->NodeID(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOutletNodeNum),
    5822              :                                         "Air Nodes");
    5823            1 :                                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum > 0) {
    5824            1 :                                         state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneAirNode =
    5825            1 :                                             state.dataZoneEquip->ZoneEquipConfig(state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum).ZoneNode;
    5826            1 :                                         int ControlledZoneNum = state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum;
    5827            5 :                                         for (int TstatZoneNum = 1; TstatZoneNum <= state.dataZoneCtrls->NumTempControlledZones; ++TstatZoneNum) {
    5828            5 :                                             if (state.dataZoneCtrls->TempControlledZone(TstatZoneNum).ActualZoneNum !=
    5829            5 :                                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum) {
    5830            4 :                                                 continue;
    5831              :                                             }
    5832            1 :                                             state.dataHVACVarRefFlow->VRF(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFSysNum).MasterZoneTUIndex =
    5833              :                                                 TUIndex;
    5834            1 :                                             AirNodeFound = true;
    5835            1 :                                             ctrlZoneNum = ControlledZoneNum;
    5836            1 :                                             goto EquipList_exit;
    5837              :                                         }
    5838            0 :                                         for (int TstatZoneNum = 1; TstatZoneNum <= state.dataZoneCtrls->NumComfortControlledZones; ++TstatZoneNum) {
    5839            0 :                                             if (state.dataZoneCtrls->ComfortControlledZone(TstatZoneNum).ActualZoneNum !=
    5840            0 :                                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum) {
    5841            0 :                                                 continue;
    5842              :                                             }
    5843            0 :                                             state.dataHVACVarRefFlow->VRF(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFSysNum).MasterZoneTUIndex =
    5844              :                                                 TUIndex;
    5845            0 :                                             AirNodeFound = true;
    5846            0 :                                             ctrlZoneNum = ControlledZoneNum;
    5847            0 :                                             goto EquipList_exit;
    5848              :                                         }
    5849            0 :                                         if (!AirNodeFound && state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum > 0) {
    5850            0 :                                             ShowSevereError(state, format("Input errors for {}:{}", cCurrentModuleObject, thisObjectName));
    5851            0 :                                             ShowContinueError(state, "Did not find Air node (Zone with Thermostat or Thermal Comfort Thermostat).");
    5852              :                                             // ShowContinueError(state, format("specified Controlling Zone or Thermostat Location name = {}{}", //,
    5853              :                                             // loc_controlZoneName));
    5854            0 :                                             errorsFound = true;
    5855              :                                         }
    5856            0 :                                     } else if (AirLoopFound) { // control zone name not entered in TU object input
    5857            0 :                                         state.dataHVACVarRefFlow->VRFTU(TUIndex).isSetPointControlled = true;
    5858              :                                     }
    5859              :                                 }
    5860           23 :                                 if (AirLoopFound) {
    5861            0 :                                     break;
    5862              :                                 }
    5863              :                             }
    5864           11 :                             if (AirLoopFound) {
    5865            0 :                                 break;
    5866              :                             }
    5867              :                         }
    5868           11 :                         if (AirLoopFound) {
    5869            0 :                             break;
    5870              :                         }
    5871              :                     }
    5872              :                 }
    5873              : 
    5874              :                 // check if the TU is connected to an outside air system
    5875           29 :                 if (!AirLoopFound && !state.dataHVACVarRefFlow->VRFTU(TUIndex).isInOASys) {
    5876           29 :                     for (int OASysNum = 1; OASysNum <= state.dataAirLoop->NumOASystems; ++OASysNum) {
    5877           31 :                         for (int OACompNum = 1; OACompNum <= state.dataAirLoop->OutsideAirSys(OASysNum).NumComponents; ++OACompNum) {
    5878           21 :                             if (!Util::SameString(state.dataAirLoop->OutsideAirSys(OASysNum).ComponentName(OACompNum),
    5879           43 :                                                   state.dataHVACVarRefFlow->VRFTU(TUIndex).Name) ||
    5880            1 :                                 !Util::SameString(state.dataAirLoop->OutsideAirSys(OASysNum).ComponentType(OACompNum), cCurrentModuleObject)) {
    5881           20 :                                 continue;
    5882              :                             }
    5883            1 :                             state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum = 0; // need air loop number here?
    5884            1 :                             state.dataHVACVarRefFlow->VRFTU(TUIndex).isInOASys = true;
    5885            1 :                             AirLoopFound = true;
    5886            1 :                             state.dataHVACVarRefFlow->VRFTU(TUIndex).isSetPointControlled = true;
    5887              :                             // user may have inadvertently entered a zone name in the OA system TU object
    5888            1 :                             state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum = 0;
    5889            1 :                             state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneAirNode = 0;
    5890            2 :                             BranchNodeConnections::TestCompSet(
    5891              :                                 state,
    5892              :                                 cCurrentModuleObject,
    5893              :                                 thisObjectName,
    5894            1 :                                 state.dataLoopNodes->NodeID(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUInletNodeNum),
    5895            1 :                                 state.dataLoopNodes->NodeID(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOutletNodeNum),
    5896              :                                 "Air Nodes");
    5897            1 :                             goto EquipList_exit;
    5898              :                         }
    5899              :                     }
    5900              :                 }
    5901           10 :             EquipList_exit:;
    5902          823 :                 if (ctrlZoneNum > 0) {
    5903            1 :                     int inletNodeADUNum = 0;
    5904            1 :                     DataZoneEquipment::ZoneEquipType sysType_Num = DataZoneEquipment::ZoneEquipType::Invalid;
    5905            1 :                     std::string sysName = "";
    5906            1 :                     for (int inletNode = 1; inletNode <= state.dataZoneEquip->ZoneEquipConfig(ctrlZoneNum).NumInletNodes; inletNode++) {
    5907            1 :                         if (state.dataZoneEquip->ZoneEquipConfig(ctrlZoneNum).InletNodeAirLoopNum(inletNode) !=
    5908            1 :                             state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum) {
    5909            0 :                             continue;
    5910              :                         }
    5911            1 :                         inletNodeADUNum = state.dataZoneEquip->ZoneEquipConfig(ctrlZoneNum).InletNodeADUNum(inletNode);
    5912            1 :                         if (inletNodeADUNum > 0 && inletNodeADUNum <= (int)state.dataDefineEquipment->AirDistUnit.size()) {
    5913            1 :                             sysType_Num = DataZoneEquipment::ZoneEquipType::AirDistributionUnit;
    5914            1 :                             sysName = state.dataDefineEquipment->AirDistUnit(inletNodeADUNum).Name;
    5915            1 :                             break;
    5916              :                         }
    5917              :                     }
    5918            1 :                     if (inletNodeADUNum > 0) {
    5919            1 :                         if (state.dataZoneEquip->ZoneEquipConfig(ctrlZoneNum).EquipListIndex > 0) {
    5920            1 :                             for (int EquipNum = 1;
    5921            1 :                                  EquipNum <=
    5922            1 :                                  state.dataZoneEquip->ZoneEquipList(state.dataZoneEquip->ZoneEquipConfig(ctrlZoneNum).EquipListIndex).NumOfEquipTypes;
    5923              :                                  ++EquipNum) {
    5924            1 :                                 if ((state.dataZoneEquip->ZoneEquipList(state.dataZoneEquip->ZoneEquipConfig(ctrlZoneNum).EquipListIndex)
    5925            2 :                                          .EquipType(EquipNum) != sysType_Num) ||
    5926            1 :                                     state.dataZoneEquip->ZoneEquipList(state.dataZoneEquip->ZoneEquipConfig(ctrlZoneNum).EquipListIndex)
    5927            1 :                                             .EquipName(EquipNum) != sysName) {
    5928            0 :                                     continue;
    5929              :                                 }
    5930            1 :                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).zoneSequenceCoolingNum =
    5931            1 :                                     state.dataZoneEquip->ZoneEquipList(state.dataZoneEquip->ZoneEquipConfig(ctrlZoneNum).EquipListIndex)
    5932            1 :                                         .CoolingPriority(EquipNum);
    5933            1 :                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).zoneSequenceHeatingNum =
    5934            1 :                                     state.dataZoneEquip->ZoneEquipList(state.dataZoneEquip->ZoneEquipConfig(ctrlZoneNum).EquipListIndex)
    5935            1 :                                         .HeatingPriority(EquipNum);
    5936            1 :                                 break;
    5937              :                             }
    5938              :                         }
    5939              :                     } else {
    5940            0 :                         ShowSevereError(state, format("Input errors for {}:{}", cCurrentModuleObject, thisObjectName));
    5941            0 :                         ShowContinueError(state, "Did not find ZoneHVAC:EquipmentList connected to this VRF terminal unit.");
    5942            0 :                         errorsFound = true;
    5943              :                     }
    5944            1 :                 }
    5945              : 
    5946              :                 // Find the number of zones (zone Inlet nodes) attached to an air loop from the air loop number
    5947          823 :                 if (AirLoopFound || state.dataHVACVarRefFlow->VRFTU(TUIndex).isInAirLoop) {
    5948           12 :                     int NumAirLoopZones = 0;
    5949           12 :                     bool initLoadBasedControlFlowFracFlagReady = false;
    5950           12 :                     Real64 initLoadBasedControlCntrlZoneTerminalUnitMassFlowRateMax = 0.0;
    5951           12 :                     if (allocated(state.dataAirLoop->AirToZoneNodeInfo) && state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum > 0) {
    5952           11 :                         NumAirLoopZones = state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum).NumZonesCooled +
    5953           11 :                                           state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum).NumZonesHeated;
    5954              :                     }
    5955           12 :                     if (allocated(state.dataAirLoop->AirToZoneNodeInfo)) {
    5956           12 :                         initLoadBasedControlFlowFracFlagReady = true;
    5957           67 :                         for (int ZoneInSysIndex = 1; ZoneInSysIndex <= NumAirLoopZones; ++ZoneInSysIndex) {
    5958              :                             // zone inlet nodes for cooling
    5959           55 :                             if (state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum).NumZonesCooled > 0) {
    5960           55 :                                 if (state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum)
    5961           55 :                                         .TermUnitCoolInletNodes(ZoneInSysIndex) == -999) {
    5962              :                                     // the data structure for the zones inlet nodes has not been filled
    5963            0 :                                     initLoadBasedControlFlowFracFlagReady = false;
    5964              :                                 } else {
    5965           55 :                                     int ZoneInletNodeNum = state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum)
    5966           55 :                                                                .TermUnitCoolInletNodes(ZoneInSysIndex);
    5967           55 :                                     if (state.dataLoopNodes->Node(ZoneInletNodeNum).MassFlowRateMax == -999.0) {
    5968              :                                         // the node mass flow rate has not been set
    5969           10 :                                         initLoadBasedControlFlowFracFlagReady = false;
    5970              :                                     }
    5971              :                                 }
    5972              :                             }
    5973              :                             // zone inlet nodes for heating
    5974           55 :                             if (state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum).NumZonesHeated > 0) {
    5975            0 :                                 if (state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum)
    5976            0 :                                         .TermUnitHeatInletNodes(ZoneInSysIndex) == -999) {
    5977              :                                     // the data structure for the zones inlet nodes has not been filled
    5978            0 :                                     initLoadBasedControlFlowFracFlagReady = false;
    5979              :                                 } else {
    5980            0 :                                     int ZoneInletNodeNum = state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum)
    5981            0 :                                                                .TermUnitHeatInletNodes(ZoneInSysIndex);
    5982            0 :                                     if (state.dataLoopNodes->Node(ZoneInletNodeNum).MassFlowRateMax == -999.0) {
    5983              :                                         // the node mass flow rate has not been set
    5984            0 :                                         initLoadBasedControlFlowFracFlagReady = false;
    5985              :                                     }
    5986              :                                 }
    5987              :                             }
    5988              :                         }
    5989              :                     }
    5990           12 :                     if (allocated(state.dataAirLoop->AirToZoneNodeInfo) && initLoadBasedControlFlowFracFlagReady) {
    5991            8 :                         Real64 SumOfMassFlowRateMax = 0.0; // initialize the sum of the maximum flows
    5992           43 :                         for (int ZoneInSysIndex = 1; ZoneInSysIndex <= NumAirLoopZones; ++ZoneInSysIndex) {
    5993           35 :                             int ZoneInletNodeNum = state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum)
    5994           35 :                                                        .TermUnitCoolInletNodes(ZoneInSysIndex);
    5995           35 :                             SumOfMassFlowRateMax += state.dataLoopNodes->Node(ZoneInletNodeNum).MassFlowRateMax;
    5996           35 :                             if (state.dataAirLoop->AirToZoneNodeInfo(state.dataHVACVarRefFlow->VRFTU(TUIndex).airLoopNum)
    5997           35 :                                     .CoolCtrlZoneNums(ZoneInSysIndex) == state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum) {
    5998            7 :                                 initLoadBasedControlCntrlZoneTerminalUnitMassFlowRateMax =
    5999            7 :                                     state.dataLoopNodes->Node(ZoneInletNodeNum).MassFlowRateMax;
    6000              :                             }
    6001              :                         }
    6002            8 :                         if (SumOfMassFlowRateMax != 0.0 && state.dataAirLoop->AirLoopInputsFilled) {
    6003            1 :                             if (initLoadBasedControlCntrlZoneTerminalUnitMassFlowRateMax >= HVAC::SmallAirVolFlow) {
    6004            1 :                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).controlZoneMassFlowFrac =
    6005            1 :                                     initLoadBasedControlCntrlZoneTerminalUnitMassFlowRateMax / SumOfMassFlowRateMax;
    6006            2 :                                 BaseSizer::reportSizerOutput(state,
    6007            1 :                                                              tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(TUIndex).type],
    6008            1 :                                                              state.dataHVACVarRefFlow->VRFTU(TUIndex).Name,
    6009              :                                                              "Fraction of Supply Air Flow That Goes Through the Controlling Zone",
    6010            1 :                                                              state.dataHVACVarRefFlow->VRFTU(TUIndex).controlZoneMassFlowFrac);
    6011            1 :                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).isSetPointControlled = false; // redundant
    6012              :                             } else {
    6013            0 :                                 if (state.dataHVACVarRefFlow->VRFTU(TUIndex).isInAirLoop && state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum == 0 &&
    6014            0 :                                     state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneAirNode == 0) {
    6015              :                                     // TU must be set point controlled and use constant fan mode (or coil out T won't change with PLR/air flow)
    6016            0 :                                     state.dataHVACVarRefFlow->VRFTU(TUIndex).isSetPointControlled = true;
    6017            0 :                                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).fanOpModeSched != nullptr) {
    6018            0 :                                         if (state.dataHVACVarRefFlow->VRFTU(TUIndex).fanOpModeSched->getCurrentVal() == 0.0) {
    6019            0 :                                             ShowSevereError(state,
    6020            0 :                                                             format("{} = {}",
    6021            0 :                                                                    tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(TUIndex).type],
    6022            0 :                                                                    state.dataHVACVarRefFlow->VRFTU(TUIndex).Name));
    6023            0 :                                             ShowContinueError(state,
    6024              :                                                               "When using set point control, fan operating mode must be continuous (fan "
    6025              :                                                               "operating mode schedule values > 0).");
    6026            0 :                                             ShowContinueError(state,
    6027            0 :                                                               format("Error found in Supply Air Fan Operating Mode Schedule Name = {}",
    6028            0 :                                                                      state.dataHVACVarRefFlow->VRFTU(TUIndex).fanOpModeSched->Name));
    6029            0 :                                             ShowContinueError(state, "...schedule values must be (>0., <=1.)");
    6030            0 :                                             ErrorsFound = true;
    6031              :                                         }
    6032              :                                     }
    6033              :                                 } else {
    6034            0 :                                     ShowSevereError(state,
    6035            0 :                                                     format("{} = {}",
    6036            0 :                                                            tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(TUIndex).type],
    6037            0 :                                                            state.dataHVACVarRefFlow->VRFTU(TUIndex).Name));
    6038            0 :                                     ShowContinueError(state, " The Fraction of Supply Air Flow That Goes Through the Controlling Zone is set to 1.");
    6039            0 :                                     state.dataHVACVarRefFlow->VRFTU(TUIndex).controlZoneMassFlowFrac = 1.0;
    6040            0 :                                     BaseSizer::reportSizerOutput(state,
    6041            0 :                                                                  tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(TUIndex).type],
    6042            0 :                                                                  state.dataHVACVarRefFlow->VRFTU(TUIndex).Name,
    6043              :                                                                  "Fraction of Supply Air Flow That Goes Through the Controlling Zone",
    6044            0 :                                                                  state.dataHVACVarRefFlow->VRFTU(TUIndex).controlZoneMassFlowFrac);
    6045              :                                 }
    6046              :                             }
    6047            7 :                         } else if (state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum == 0) {
    6048              :                             // TU must be set point controlled and use constant fan mode (or coil outlet T won't change with PLR/air flow rate)
    6049              :                             // TU inlet air flow rate is also determined by OA system, not TU
    6050            1 :                             state.dataHVACVarRefFlow->VRFTU(TUIndex).isSetPointControlled = true;
    6051              :                         }
    6052              :                     }
    6053              :                 }
    6054              : 
    6055          823 :                 if (state.dataHVACVarRefFlow->VRFTU(TUIndex).isInZone && state.dataAirLoop->AirLoopInputsFilled) {
    6056           60 :                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).fanPlace == HVAC::FanPlace::Invalid) {
    6057            0 :                         ShowSevereError(state,
    6058            0 :                                         format("ZoneHVAC:TerminalUnit:VariableRefrigerantFlow = {}", state.dataHVACVarRefFlow->VRFTU(TUIndex).Name));
    6059            0 :                         ShowContinueError(state, "Illegal Supply Air Fan Placement.");
    6060            0 :                         ErrorsFound = true;
    6061              :                     }
    6062           60 :                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).FanIndex == 0) {
    6063            0 :                         ShowSevereError(state,
    6064            0 :                                         format("ZoneHVAC:TerminalUnit:VariableRefrigerantFlow = {}", state.dataHVACVarRefFlow->VRFTU(TUIndex).Name));
    6065            0 :                         ShowContinueError(state, "VRF Terminal Unit fan is required when used as zone equipment.");
    6066            0 :                         ErrorsFound = true;
    6067              :                     }
    6068              :                 }
    6069              : 
    6070          823 :                 if (state.dataHVACVarRefFlow->VRFTU(TUIndex).isSetPointControlled && state.dataAirLoop->AirLoopInputsFilled) {
    6071            1 :                     bool missingSetPoint = false;
    6072            1 :                     Real64 TUOutNodeSP = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOutletNodeNum).TempSetPoint;
    6073            1 :                     Real64 coolCoilOutNodeSP = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).coolCoilAirOutNode).TempSetPoint;
    6074            1 :                     Real64 heatCoilOutNodeSP = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).heatCoilAirOutNode).TempSetPoint;
    6075              :                     // SP can be at outlet of TU or at outlet of coils
    6076              :                     // if supp heat coil is present, a SP must be at the outlet of the TU
    6077            1 :                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).SuppHeatingCoilPresent) {
    6078            0 :                         if (TUOutNodeSP == DataLoopNode::SensedNodeFlagValue) {
    6079            0 :                             missingSetPoint = true;
    6080              :                         }
    6081              :                     } else {
    6082            1 :                         if (state.dataHVACVarRefFlow->VRFTU(TUIndex).fanPlace == HVAC::FanPlace::DrawThru) {
    6083              :                             // then SP must be at TU outlet
    6084            0 :                             if (TUOutNodeSP == DataLoopNode::SensedNodeFlagValue) {
    6085            0 :                                 missingSetPoint = true;
    6086              :                             }
    6087              :                             // or at coil outlet nodes
    6088            0 :                             if (missingSetPoint) {
    6089            0 :                                 if (coolCoilOutNodeSP != DataLoopNode::SensedNodeFlagValue &&
    6090              :                                     heatCoilOutNodeSP != DataLoopNode::SensedNodeFlagValue) {
    6091            0 :                                     missingSetPoint = false;
    6092              :                                 }
    6093              :                             }
    6094              :                         } else {
    6095              :                             // else fan is blow thru or missing
    6096            1 :                             if (TUOutNodeSP == DataLoopNode::SensedNodeFlagValue) {
    6097            0 :                                 missingSetPoint = true;
    6098              :                             }
    6099              :                         }
    6100              :                     }
    6101            1 :                     if (missingSetPoint) {
    6102            0 :                         if (!state.dataGlobal->AnyEnergyManagementSystemInModel) {
    6103            0 :                             ShowSevereError(state,
    6104            0 :                                             format("ZoneHVAC:TerminalUnit:VariableRefrigerantFlow: Missing temperature setpoint for {}",
    6105            0 :                                                    state.dataHVACVarRefFlow->VRFTU(TUIndex).Name));
    6106            0 :                             ShowContinueError(state, "...use a Setpoint Manager to establish a setpoint at the TU or coil(s) outlet node.");
    6107            0 :                             ErrorsFound = true;
    6108            0 :                         } else if (state.dataGlobal->AnyEnergyManagementSystemInModel) {
    6109            0 :                             bool SPNotFound = false;
    6110            0 :                             EMSManager::CheckIfNodeSetPointManagedByEMS(
    6111            0 :                                 state, state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOutletNodeNum, HVAC::CtrlVarType::Temp, SetPointErrorFlag);
    6112            0 :                             SPNotFound = SPNotFound || SetPointErrorFlag;
    6113            0 :                             EMSManager::CheckIfNodeSetPointManagedByEMS(
    6114            0 :                                 state, state.dataHVACVarRefFlow->VRFTU(TUIndex).coolCoilAirOutNode, HVAC::CtrlVarType::Temp, SetPointErrorFlag);
    6115            0 :                             SPNotFound = SPNotFound || SetPointErrorFlag;
    6116            0 :                             EMSManager::CheckIfNodeSetPointManagedByEMS(
    6117            0 :                                 state, state.dataHVACVarRefFlow->VRFTU(TUIndex).heatCoilAirOutNode, HVAC::CtrlVarType::Temp, SetPointErrorFlag);
    6118            0 :                             SPNotFound = SPNotFound || SetPointErrorFlag;
    6119              : 
    6120              :                             // We disable the check at end (if API), because one of the nodes is enough, so there's an almost certainty
    6121              :                             // that it will throw as you're unlikely going to actuate all three nodes
    6122              :                             // It's not ideal, but it's better to let slide a bad condition rather than throw false positives...
    6123            0 :                             state.dataLoopNodes->NodeSetpointCheck(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOutletNodeNum)
    6124            0 :                                 .needsSetpointChecking = false;
    6125            0 :                             state.dataLoopNodes->NodeSetpointCheck(state.dataHVACVarRefFlow->VRFTU(TUIndex).coolCoilAirOutNode)
    6126            0 :                                 .needsSetpointChecking = false;
    6127            0 :                             state.dataLoopNodes->NodeSetpointCheck(state.dataHVACVarRefFlow->VRFTU(TUIndex).heatCoilAirOutNode)
    6128            0 :                                 .needsSetpointChecking = false;
    6129              : 
    6130            0 :                             if (SPNotFound && state.dataAirLoop->AirLoopInputsFilled) {
    6131            0 :                                 ShowSevereError(
    6132              :                                     state,
    6133            0 :                                     format("ZoneHVAC:TerminalUnit:VariableRefrigerantFlow: Missing temperature setpoint for unitary system = {}",
    6134            0 :                                            state.dataHVACVarRefFlow->VRFTU(TUIndex).Name));
    6135            0 :                                 ShowContinueError(state, "...use a Setpoint Manager to establish a setpoint at the TU or coil(s) outlet node.");
    6136            0 :                                 ShowContinueError(state, "...or use an EMS actuator to establish a temperature setpoint at the coil control node.");
    6137            0 :                                 ErrorsFound = true;
    6138              :                             }
    6139              :                         }
    6140              :                     }
    6141              :                 }
    6142              : 
    6143         1624 :                 if (state.dataHVACVarRefFlow->VRFTU(TUIndex).isInAirLoop || state.dataHVACVarRefFlow->VRFTU(TUIndex).isInOASys ||
    6144          801 :                     state.dataHVACVarRefFlow->VRFTU(TUIndex).isInZone) {
    6145          815 :                     continue;
    6146              :                 }
    6147            8 :                 if (!state.dataAirLoop->AirLoopInputsFilled) {
    6148            8 :                     continue;
    6149              :                 }
    6150            0 :                 ShowSevereError(state,
    6151            0 :                                 format("InitVRF: VRF Terminal Unit = [{},{}] is not on any ZoneHVAC:EquipmentList, AirloopHVAC or "
    6152              :                                        "AirLoopHVAC:OutdoorAirSystem:EquipmentList.  It will not be simulated.",
    6153            0 :                                        tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(TUIndex).type],
    6154            0 :                                        state.dataHVACVarRefFlow->VRFTU(TUIndex).Name));
    6155            0 :                 ShowContinueError(state, "...The VRF AC System associated with this terminal unit may also not be simulated.");
    6156          823 :             }
    6157              :         }
    6158              : 
    6159              :         // TU inlet node must be the same as a zone exhaust node and the OA Mixer return node
    6160              :         // check that TU inlet node is a zone exhaust node.
    6161          326 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInZone &&
    6162          162 :             (!state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerExists ||
    6163           32 :              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerType == HVAC::MixerType::SupplySide)) {
    6164          142 :             bool ZoneNodeNotFound = true;
    6165          551 :             for (int CtrlZone = 1; CtrlZone <= state.dataGlobal->NumOfZones; ++CtrlZone) {
    6166          551 :                 if (!state.dataZoneEquip->ZoneEquipConfig(CtrlZone).IsControlled) {
    6167          139 :                     continue;
    6168              :                 }
    6169          682 :                 for (int NodeNum = 1; NodeNum <= state.dataZoneEquip->ZoneEquipConfig(CtrlZone).NumExhaustNodes; ++NodeNum) {
    6170          412 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum ==
    6171          412 :                         state.dataZoneEquip->ZoneEquipConfig(CtrlZone).ExhaustNode(NodeNum)) {
    6172          142 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneAirNode = state.dataZoneEquip->ZoneEquipConfig(CtrlZone).ZoneNode;
    6173          142 :                         ZoneNodeNotFound = false;
    6174          142 :                         break;
    6175              :                     }
    6176              :                 }
    6177          412 :                 if (!ZoneNodeNotFound) {
    6178          142 :                     break;
    6179              :                 }
    6180              :             }
    6181          142 :             if (ZoneNodeNotFound && !state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInAirLoop) {
    6182            0 :                 ShowSevereError(state,
    6183            0 :                                 format("{} \"{}\" Zone terminal unit air inlet node name must be the same as a zone exhaust node name.",
    6184              :                                        cCurrentModuleObject,
    6185            0 :                                        state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6186            0 :                 ShowContinueError(state, "... Zone exhaust node name is specified in ZoneHVAC:EquipmentConnections object.");
    6187            0 :                 ShowContinueError(state,
    6188            0 :                                   format("... Zone terminal unit inlet node name = {}",
    6189            0 :                                          state.dataLoopNodes->NodeID(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum)));
    6190            0 :                 ErrorsFound = true;
    6191              :             }
    6192              :         }
    6193              :         // check OA Mixer return node
    6194          294 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInZone && !state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerExists &&
    6195          130 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    6196          130 :             Array1D_int OANodeNums = MixedAir::GetOAMixerNodeNumbers(state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerName, errFlag);
    6197          130 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum != OANodeNums(3)) {
    6198            0 :                 ShowSevereError(
    6199              :                     state,
    6200            0 :                     format("{} \"{}\" Zone terminal unit air inlet node name must be the same as the OutdoorAir:Mixer return air node name.",
    6201              :                            cCurrentModuleObject,
    6202            0 :                            state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6203            0 :                 ShowContinueError(state,
    6204            0 :                                   format("... Zone terminal unit air inlet node name = {}",
    6205            0 :                                          state.dataLoopNodes->NodeID(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum)));
    6206            0 :                 ShowContinueError(state, format("... OutdoorAir:Mixer return air node name = {}", state.dataLoopNodes->NodeID(OANodeNums(3))));
    6207            0 :                 ErrorsFound = true;
    6208              :             }
    6209          130 :         }
    6210              :         // check that TU outlet node is a zone inlet node.
    6211          326 :         if ((state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInZone &&
    6212          162 :              (!state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerExists ||
    6213           32 :               state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerType == HVAC::MixerType::InletSide))) {
    6214          150 :             bool ZoneNodeNotFound = true;
    6215          543 :             for (int CtrlZone = 1; CtrlZone <= state.dataGlobal->NumOfZones; ++CtrlZone) {
    6216          543 :                 if (!state.dataZoneEquip->ZoneEquipConfig(CtrlZone).IsControlled) {
    6217          147 :                     continue;
    6218              :                 }
    6219          750 :                 for (int NodeNum = 1; NodeNum <= state.dataZoneEquip->ZoneEquipConfig(CtrlZone).NumInletNodes; ++NodeNum) {
    6220          504 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOutletNodeNum ==
    6221          504 :                         state.dataZoneEquip->ZoneEquipConfig(CtrlZone).InletNode(NodeNum)) {
    6222          150 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneAirNode = state.dataZoneEquip->ZoneEquipConfig(CtrlZone).ZoneNode;
    6223          150 :                         ZoneNodeNotFound = false;
    6224          150 :                         break;
    6225              :                     }
    6226              :                 }
    6227          396 :                 if (!ZoneNodeNotFound) {
    6228          150 :                     break;
    6229              :                 }
    6230              :             }
    6231          150 :             if (ZoneNodeNotFound) {
    6232            0 :                 ShowSevereError(state,
    6233            0 :                                 format("{} \"{}\" Zone terminal unit air outlet node name must be the same as a zone inlet node name.",
    6234              :                                        cCurrentModuleObject,
    6235            0 :                                        state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6236            0 :                 ShowContinueError(state, "... Zone inlet node name is specified in ZoneHVAC:EquipmentConnections object.");
    6237            0 :                 ShowContinueError(state,
    6238            0 :                                   format("... Zone terminal unit outlet node name = {}",
    6239            0 :                                          state.dataLoopNodes->NodeID(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOutletNodeNum)));
    6240            0 :                 ErrorsFound = true;
    6241              :             }
    6242              :         }
    6243              : 
    6244          164 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInZone && state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerExists) {
    6245              :             //   check that OA flow in cooling must be set to zero when connected to DOAS
    6246           32 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow != 0) {
    6247            0 :                 ShowWarningError(state, format("{} = {}", cCurrentModuleObject, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6248            0 :                 ShowContinueError(state, format(".. Cooling Outdoor Air Flow Rate must be zero when {}", cCurrentModuleObject));
    6249            0 :                 ShowContinueError(state, "..object is connected to central dedicated outdoor air system via AirTerminal:SingleDuct:Mixer");
    6250            0 :                 ShowContinueError(state, ".. Cooling Outdoor Air Flow Rate is set to 0 and simulation continues.");
    6251            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow = 0;
    6252              :             }
    6253              :             //   check that OA flow in heating must be set to zero when connected to DOAS
    6254           32 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow != 0) {
    6255            0 :                 ShowWarningError(state, format("{} = {}", cCurrentModuleObject, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6256            0 :                 ShowContinueError(state, format(".. Heating Outdoor Air Flow Rate must be zero when {}", cCurrentModuleObject));
    6257            0 :                 ShowContinueError(state, "..object is connected to central dedicated outdoor air system via AirTerminal:SingleDuct:Mixer");
    6258            0 :                 ShowContinueError(state, ".. Heating Outdoor Air Flow Rate is set to 0 and simulation continues.");
    6259            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow = 0;
    6260              :             }
    6261              :             //   check that OA flow in no cooling and no heating must be set to zero when connected to DOAS
    6262           32 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow != 0) {
    6263            0 :                 ShowWarningError(state, format("{} = {}", cCurrentModuleObject, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6264            0 :                 ShowContinueError(state, format(".. No Load Outdoor Air Flow Rate must be zero when {}", cCurrentModuleObject));
    6265            0 :                 ShowContinueError(state, "..object is connected to central dedicated outdoor air system via AirTerminal:SingleDuct:Mixer");
    6266            0 :                 ShowContinueError(state, ".. No Load Outdoor Air Flow Rate is set to 0 and simulation continues.");
    6267            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow = 0;
    6268              :             }
    6269              :         }
    6270          164 :     } // IF(ZoneEquipmentListNotChecked)THEN
    6271              : 
    6272              :     // Size TU
    6273       244151 :     if (state.dataHVACVarRefFlow->MySizeFlag(VRFTUNum)) {
    6274          122 :         if (!state.dataGlobal->ZoneSizingCalc && !state.dataGlobal->SysSizingCalc) {
    6275           62 :             SizeVRF(state, VRFTUNum);
    6276           62 :             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).TerminalUnitNotSizedYet(IndexToTUInTUList) = false;
    6277           62 :             state.dataHVACVarRefFlow->MySizeFlag(VRFTUNum) = false;
    6278              :         } // IF ( .NOT. ZoneSizingCalc) THEN
    6279              :     } // IF (MySizeFlag(VRFTUNum)) THEN
    6280              : 
    6281              :     // Do the Begin Environment initializations
    6282       244151 :     if (state.dataGlobal->BeginEnvrnFlag && state.dataHVACVarRefFlow->MyEnvrnFlag(VRFTUNum)) {
    6283              : 
    6284              :         // Change the Volume Flow Rates to Mass Flow Rates
    6285              : 
    6286          371 :         RhoAir = state.dataEnvrn->StdRhoAir;
    6287              :         // set the mass flow rates from the input volume flow rates
    6288          371 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow = RhoAir * state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow;
    6289          371 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow = RhoAir * state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow;
    6290          371 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow = RhoAir * state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow;
    6291          371 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow = RhoAir * state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow;
    6292          371 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow = RhoAir * state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow;
    6293          371 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow = RhoAir * state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow;
    6294          371 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow =
    6295          371 :             RhoAir * state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow;
    6296              :         // set the node max and min mass flow rates
    6297              :         // outside air mixer is optional, check that node num > 0
    6298          371 :         if (OutsideAirNode > 0) {
    6299          305 :             state.dataLoopNodes->Node(OutsideAirNode).MassFlowRateMax =
    6300          305 :                 max(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow);
    6301          305 :             state.dataLoopNodes->Node(OutsideAirNode).MassFlowRateMin = 0.0;
    6302          305 :             state.dataLoopNodes->Node(OutsideAirNode).MassFlowRateMinAvail = 0.0;
    6303              :         }
    6304          371 :         state.dataLoopNodes->Node(OutNode).MassFlowRateMax =
    6305          371 :             max(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow);
    6306          371 :         state.dataLoopNodes->Node(OutNode).MassFlowRateMin = 0.0;
    6307          371 :         state.dataLoopNodes->Node(OutNode).MassFlowRateMinAvail = 0.0;
    6308          371 :         state.dataLoopNodes->Node(InNode).MassFlowRateMax =
    6309          371 :             max(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow);
    6310          371 :         state.dataLoopNodes->Node(InNode).MassFlowRateMin = 0.0;
    6311          371 :         state.dataLoopNodes->Node(InNode).MassFlowRateMinAvail = 0.0;
    6312          371 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRelNodeNum > 0) {
    6313          305 :             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRelNodeNum).MassFlowRateMinAvail = 0.0;
    6314              :         }
    6315              : 
    6316          371 :         state.dataHVACVarRefFlow->MyEnvrnFlag(VRFTUNum) = false;
    6317              : 
    6318          371 :         if (state.dataHVACVarRefFlow->VRF(VRFCond).CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    6319           24 :             rho = state.dataPlnt->PlantLoop(state.dataHVACVarRefFlow->VRF(VRFCond).SourcePlantLoc.loopNum)
    6320           24 :                       .glycol->getDensity(state, Constant::CWInitConvTemp, RoutineName);
    6321           24 :             state.dataHVACVarRefFlow->VRF(VRFCond).WaterCondenserDesignMassFlow = state.dataHVACVarRefFlow->VRF(VRFCond).WaterCondVolFlowRate * rho;
    6322              : 
    6323           72 :             InitComponentNodes(state,
    6324              :                                0.0,
    6325           24 :                                state.dataHVACVarRefFlow->VRF(VRFCond).WaterCondenserDesignMassFlow,
    6326           24 :                                state.dataHVACVarRefFlow->VRF(VRFCond).CondenserNodeNum,
    6327           24 :                                state.dataHVACVarRefFlow->VRF(VRFCond).CondenserOutletNodeNum);
    6328              :         }
    6329              :         //    IF(MyVRFCondFlag(VRFCond))THEN
    6330          371 :         state.dataHVACVarRefFlow->VRF(VRFCond).HRTimer = 0.0;
    6331          371 :         state.dataHVACVarRefFlow->VRF(VRFCond).ModeChange = false;
    6332          371 :         state.dataHVACVarRefFlow->VRF(VRFCond).HRModeChange = false;
    6333          371 :         state.dataHVACVarRefFlow->MyVRFCondFlag(VRFCond) = false;
    6334              :         //    END IF
    6335              : 
    6336          371 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidInletNode > 0) {
    6337           24 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType_Num == HVAC::Coil_HeatingWater) {
    6338           12 :                 if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow == DataSizing::AutoSize) {
    6339            4 :                     WaterCoils::SimulateWaterCoilComponents(state,
    6340            2 :                                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
    6341              :                                                             FirstHVACIteration,
    6342            2 :                                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilIndex);
    6343              :                     // design hot water volume flow rate
    6344            2 :                     Real64 CoilMaxVolFlowRate = WaterCoils::GetCoilMaxWaterFlowRate(
    6345            2 :                         state, "Coil:Heating:Water", state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName, ErrorsFound);
    6346            2 :                     if (CoilMaxVolFlowRate != DataSizing::AutoSize) {
    6347            2 :                         rho = state.dataPlnt->PlantLoop(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilPlantLoc.loopNum)
    6348            2 :                                   .glycol->getDensity(state, Constant::HWInitConvTemp, RoutineName);
    6349            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow = CoilMaxVolFlowRate * rho;
    6350              :                     }
    6351              :                 }
    6352              :             }
    6353              : 
    6354           24 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType_Num == HVAC::Coil_HeatingSteam) {
    6355           12 :                 if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow == DataSizing::AutoSize) {
    6356            6 :                     SteamCoils::SimulateSteamCoilComponents(state,
    6357            2 :                                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
    6358              :                                                             FirstHVACIteration,
    6359            2 :                                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilIndex,
    6360            4 :                                                             1.0);
    6361              :                     // design steam volume flow rate
    6362              :                     Real64 CoilMaxVolFlowRate =
    6363            2 :                         SteamCoils::GetCoilMaxSteamFlowRate(state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilIndex, ErrorsFound);
    6364            2 :                     if (CoilMaxVolFlowRate != DataSizing::AutoSize) {
    6365            2 :                         Real64 TempSteamIn = 100.0;
    6366            2 :                         Real64 SteamDensity = Fluid::GetSteam(state)->getSatDensity(state, TempSteamIn, 1.0, RoutineName);
    6367            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow = CoilMaxVolFlowRate * SteamDensity;
    6368              :                     }
    6369              :                 }
    6370              :             }
    6371              :             // init water/steam coils min and max flow rates
    6372           72 :             InitComponentNodes(state,
    6373              :                                0.0,
    6374           24 :                                state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow,
    6375           24 :                                state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidInletNode,
    6376           24 :                                state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidOutletNode);
    6377              :         }
    6378              : 
    6379              :         // the first time an air loop VRF TU is simulated set isSimulated = true so that the TU initialization
    6380              :         // will occur with the first TU simulated this time step. Zone VRF TUs are called during sizing which, if air
    6381              :         // loop TUs are included, alters when all TUs appear to have been simulated. Also, BeginEnvrnFlag is true multiple
    6382              :         // times during the simulation, reset each time to avoid a different order during sizing and simulation
    6383          371 :         if (state.dataHVACVarRefFlow->TerminalUnitList(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TUListIndex).reset_isSimulatedFlags) {
    6384              :             // if no TUs are in the air loop or outdoor air system they will all be simulated during ManageZoneEquipment
    6385              :             // and there is no need to adjust the order of simulation (i.e., when isSimulated are all true for a given system)
    6386          365 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInAirLoop || state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInOASys) {
    6387            6 :                 state.dataHVACVarRefFlow->TerminalUnitList(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TUListIndex).IsSimulated = true;
    6388            6 :                 state.dataHVACVarRefFlow->TerminalUnitList(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TUListIndex).reset_isSimulatedFlags = false;
    6389              :             }
    6390              :         }
    6391              : 
    6392              :     } // IF (BeginEnvrnFlag .and. MyEnvrnFlag(VRFTUNum)) THEN
    6393              : 
    6394              :     // reset environment flag for next environment
    6395       244151 :     if (!state.dataGlobal->BeginEnvrnFlag) {
    6396       241895 :         state.dataHVACVarRefFlow->MyEnvrnFlag(VRFTUNum) = true;
    6397       241895 :         state.dataHVACVarRefFlow->MyVRFCondFlag(VRFCond) = true;
    6398       241895 :         state.dataHVACVarRefFlow->TerminalUnitList(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TUListIndex).reset_isSimulatedFlags = true;
    6399              :     }
    6400              : 
    6401              :     // If all VRF Terminal Units on this VRF AC System have been simulated, reset the IsSimulated flag
    6402              :     // The condenser will be simulated after all terminal units have been simulated (see Sub SimulateVRF)
    6403       244151 :     if (all(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).IsSimulated)) {
    6404              :         //   this should be the first time through on the next iteration. All TU's and condenser have been simulated.
    6405              :         //   reset simulation flag for each terminal unit
    6406        55672 :         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).IsSimulated = false;
    6407              :         //     after all TU's have been simulated, reset operating mode flag if necessary
    6408        55672 :         if (state.dataHVACVarRefFlow->LastModeHeating(VRFCond) && state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) {
    6409           85 :             state.dataHVACVarRefFlow->LastModeCooling(VRFCond) = true;
    6410           85 :             state.dataHVACVarRefFlow->LastModeHeating(VRFCond) = false;
    6411              :             //        SwitchedMode(VRFCond)    = .TRUE.
    6412              :         }
    6413        55672 :         if (state.dataHVACVarRefFlow->LastModeCooling(VRFCond) && state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) {
    6414           71 :             state.dataHVACVarRefFlow->LastModeHeating(VRFCond) = true;
    6415           71 :             state.dataHVACVarRefFlow->LastModeCooling(VRFCond) = false;
    6416              :             //        SwitchedMode(VRFCond)    = .TRUE.
    6417              :         }
    6418              :     } // IF(ALL(TerminalUnitList(VRFTU(VRFTUNum)%TUListIndex)%IsSimulated))THEN
    6419              : 
    6420              :     // get operating capacity of water and steam coil
    6421       244151 :     if (FirstHVACIteration) {
    6422       122282 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidInletNode > 0) {
    6423         6846 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType_Num == HVAC::Coil_HeatingWater) {
    6424              :                 //     set hot water full flow rate for sizing
    6425         3423 :                 Real64 mdot = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow;
    6426         6846 :                 PlantUtilities::SetComponentFlowRate(state,
    6427              :                                                      mdot,
    6428         3423 :                                                      state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidInletNode,
    6429         3423 :                                                      state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidOutletNode,
    6430         3423 :                                                      state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilPlantLoc);
    6431              : 
    6432              :                 //     simulate water coil to find operating capacity
    6433         6846 :                 WaterCoils::SimulateWaterCoilComponents(state,
    6434         3423 :                                                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
    6435              :                                                         FirstHVACIteration,
    6436         3423 :                                                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilIndex,
    6437              :                                                         SuppHeatCoilCapacity);
    6438         3423 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSuppHeatingCapacity = SuppHeatCoilCapacity;
    6439              :             } // from iF VRFTU(VRFTUNum).SuppHeatCoilType_Num == HVAC::Coil_HeatingWater
    6440         6846 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType_Num == HVAC::Coil_HeatingSteam) {
    6441              :                 //     set hot water full flow rate for sizing
    6442         3423 :                 Real64 mdot = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow;
    6443         6846 :                 PlantUtilities::SetComponentFlowRate(state,
    6444              :                                                      mdot,
    6445         3423 :                                                      state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidInletNode,
    6446         3423 :                                                      state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidOutletNode,
    6447         3423 :                                                      state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilPlantLoc);
    6448              : 
    6449              :                 //     simulate steam coil to find operating capacity
    6450        10269 :                 SteamCoils::SimulateSteamCoilComponents(state,
    6451         3423 :                                                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
    6452              :                                                         FirstHVACIteration,
    6453         3423 :                                                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilIndex,
    6454         6846 :                                                         1.0,
    6455              :                                                         ErrorsFound); // QCoilReq, simulate any load > 0 to get max capacity of steam coil
    6456         3423 :                 SuppHeatCoilCapacity =
    6457         6846 :                     SteamCoils::GetCoilCapacity(state, "Coil:Heating:Steam", state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName, ErrorsFound);
    6458              : 
    6459         3423 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSuppHeatingCapacity = SuppHeatCoilCapacity;
    6460              :             } // from if VRFTU( VRFTUNum ).SuppHeatCoilType_Num == HVAC::Coil_HeatingSteam
    6461              :         }
    6462              :     }
    6463              :     // initialize water/steam coil inlet flow rate to zero
    6464       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidInletNode > 0) {
    6465        13664 :         Real64 mdot = 0.0;
    6466        27328 :         PlantUtilities::SetComponentFlowRate(state,
    6467              :                                              mdot,
    6468        13664 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidInletNode,
    6469        13664 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidOutletNode,
    6470        13664 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilPlantLoc);
    6471              :     }
    6472              : 
    6473              :     // one-time checks of flow rate vs fan flow rate
    6474       244151 :     if (state.dataHVACVarRefFlow->MyVRFFlag(VRFTUNum)) {
    6475          182 :         if (!state.dataGlobal->ZoneSizingCalc && !state.dataGlobal->SysSizingCalc) {
    6476          122 :             auto &vrfTU = state.dataHVACVarRefFlow->VRFTU(VRFTUNum);
    6477          122 :             if (vrfTU.fanPlace != HVAC::FanPlace::Invalid) { // was > 0 (is 0 invalid?)
    6478          121 :                 if (vrfTU.ActualFanVolFlowRate != AutoSize) {
    6479              : 
    6480           61 :                     if (vrfTU.fanType == HVAC::FanType::SystemModel) {
    6481           33 :                         auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(vrfTU.FanIndex));
    6482           50 :                         if (fanSystem->speedControl == Fans::SpeedControl::Discrete &&
    6483           17 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex < 0) {
    6484           16 :                             if (fanSystem->numSpeeds > 1) {
    6485            1 :                                 if (vrfTU.DXCoolCoilType_Num == HVAC::CoilVRF_Cooling) {
    6486            1 :                                     if (vrfTU.MaxCoolAirVolFlow != DataSizing::AutoSize) {
    6487            3 :                                         for (int i = 1; i <= vrfTU.NumOfSpeedCooling; ++i) {
    6488            2 :                                             vrfTU.CoolMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
    6489              :                                         }
    6490              :                                     }
    6491              :                                 }
    6492            1 :                                 if (vrfTU.DXHeatCoilType_Num == HVAC::CoilVRF_Heating) {
    6493            1 :                                     if (vrfTU.MaxHeatAirVolFlow != DataSizing::AutoSize) {
    6494            3 :                                         for (int i = 1; i <= vrfTU.NumOfSpeedCooling; ++i) {
    6495            2 :                                             vrfTU.HeatMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
    6496              :                                         }
    6497              :                                     }
    6498              :                                 }
    6499              :                             }
    6500              :                         }
    6501              :                     }
    6502              : 
    6503           61 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow >
    6504           61 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate) {
    6505            0 :                         ShowWarningError(state,
    6506            0 :                                          format("InitVRF: VRF Terminal Unit = [{}, \"{}\"]",
    6507            0 :                                                 tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    6508            0 :                                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6509            0 :                         ShowContinueError(state, "... has Supply Air Flow Rate During Cooling Operation > Max Fan Volume Flow Rate, should be <=");
    6510            0 :                         ShowContinueError(state,
    6511            0 :                                           format("... Supply Air Flow Rate During Cooling Operation = {:.4R} m3/s",
    6512            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow));
    6513            0 :                         ShowContinueError(state,
    6514            0 :                                           format("... Max Fan Volume Flow Rate                      = {:.4R} m3/s",
    6515            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate));
    6516            0 :                         ShowContinueError(
    6517              :                             state, "...the supply air flow rate during cooling operation will be reduced to match and the simulation continues.");
    6518            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate;
    6519              :                     }
    6520              : 
    6521           61 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow >
    6522           61 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate) {
    6523            0 :                         ShowWarningError(state,
    6524            0 :                                          format("InitVRF: VRF Terminal Unit = [{}, \"{}\"]",
    6525            0 :                                                 tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    6526            0 :                                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6527            0 :                         ShowContinueError(state, "... has Supply Air Flow Rate When No Cooling is Needed > Max Fan Volume Flow Rate, should be <=");
    6528            0 :                         ShowContinueError(state,
    6529            0 :                                           format("... Supply Air Flow Rate When No Cooling is Needed = {:.4R} m3/s",
    6530            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow));
    6531            0 :                         ShowContinueError(state,
    6532            0 :                                           format("... Max Fan Volume Flow Rate                       = {:.4R} m3/s",
    6533            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate));
    6534            0 :                         ShowContinueError(
    6535              :                             state, "...the supply air flow rate when no cooling is needed will be reduced to match and the simulation continues.");
    6536            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow =
    6537            0 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate;
    6538              :                     }
    6539              : 
    6540           61 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow > state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow) {
    6541            0 :                         ShowWarningError(state,
    6542            0 :                                          format("InitVRF: VRF Terminal Unit = [{}, \"{}\"]",
    6543            0 :                                                 tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    6544            0 :                                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6545            0 :                         ShowContinueError(
    6546              :                             state,
    6547              :                             "...The Outdoor Air Flow Rate During Cooling Operation exceeds the Supply Air Flow Rate During Cooling Operation.");
    6548            0 :                         ShowContinueError(state,
    6549            0 :                                           format("...Outdoor Air Flow Rate During Cooling Operation = {:.4R} m3/s",
    6550            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow));
    6551            0 :                         ShowContinueError(state,
    6552            0 :                                           format("... Supply Air Flow Rate During Cooling Operation = {:.4R} m3/s",
    6553            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow));
    6554            0 :                         ShowContinueError(state, "...the outdoor air flow rate will be reduced to match and the simulation continues.");
    6555            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow;
    6556              :                     }
    6557              : 
    6558           61 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow >
    6559           61 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate) {
    6560            0 :                         ShowWarningError(state,
    6561            0 :                                          format("InitVRF: VRF Terminal Unit = [{}, \"{}\"]",
    6562            0 :                                                 tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    6563            0 :                                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6564            0 :                         ShowContinueError(state, "... has Supply Air Flow Rate During Heating Operation > Max Fan Volume Flow Rate, should be <=");
    6565            0 :                         ShowContinueError(state,
    6566            0 :                                           format("... Supply Air Flow Rate During Heating Operation = {:.4R} m3/s",
    6567            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow));
    6568            0 :                         ShowContinueError(state,
    6569            0 :                                           format("... Max Fan Volume Flow Rate                      = {:.4R} m3/s",
    6570            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate));
    6571            0 :                         ShowContinueError(
    6572              :                             state, "...the supply air flow rate during cooling operation will be reduced to match and the simulation continues.");
    6573            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate;
    6574              :                     }
    6575              : 
    6576           61 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow >
    6577           61 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate) {
    6578            0 :                         ShowWarningError(state,
    6579            0 :                                          format("InitVRF: VRF Terminal Unit = [{}, \"{}\"]",
    6580            0 :                                                 tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    6581            0 :                                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6582            0 :                         ShowContinueError(state, "... has Supply Air Flow Rate When No Heating is Needed > Max Fan Volume Flow Rate, should be <=");
    6583            0 :                         ShowContinueError(state,
    6584            0 :                                           format("... Supply Air Flow Rate When No Heating is Needed = {:.4R} m3/s",
    6585            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow));
    6586            0 :                         ShowContinueError(state,
    6587            0 :                                           format("... Max Fan Volume Flow Rate                       = {:.4R} m3/s",
    6588            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate));
    6589            0 :                         ShowContinueError(
    6590              :                             state, "...the supply air flow rate when no cooling is needed will be reduced to match and the simulation continues.");
    6591            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow =
    6592            0 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate;
    6593              :                     }
    6594              : 
    6595           61 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow > state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow) {
    6596            0 :                         ShowWarningError(state,
    6597            0 :                                          format("InitVRF: VRF Terminal Unit = [{}, \"{}\"]",
    6598            0 :                                                 tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    6599            0 :                                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6600            0 :                         ShowContinueError(
    6601              :                             state,
    6602              :                             "...The Outdoor Air Flow Rate During Heating Operation exceeds the Supply Air Flow Rate During Heating Operation.");
    6603            0 :                         ShowContinueError(state,
    6604            0 :                                           format("...Outdoor Air Flow Rate During Heating Operation = {:.4R} m3/s",
    6605            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow));
    6606            0 :                         ShowContinueError(state,
    6607            0 :                                           format("... Supply Air Flow Rate During Heating Operation = {:.4R} m3/s",
    6608            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow));
    6609            0 :                         ShowContinueError(state, "...the outdoor air flow rate will be reduced to match and the simulation continues.");
    6610            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow;
    6611              :                     }
    6612              : 
    6613           61 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow >
    6614           61 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate) {
    6615            0 :                         ShowWarningError(state,
    6616            0 :                                          format("InitVRF: VRF Terminal Unit = [{}, \"{}\"]",
    6617            0 :                                                 tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    6618            0 :                                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    6619            0 :                         ShowContinueError(
    6620              :                             state, "... has a Outdoor Air Flow Rate When No Cooling or Heating is Needed > Max Fan Volume Flow Rate, should be <=");
    6621            0 :                         ShowContinueError(state,
    6622            0 :                                           format("... Outdoor Air Flow Rate When No Cooling or Heating is Needed = {:.4R} m3/s",
    6623            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow));
    6624            0 :                         ShowContinueError(state,
    6625            0 :                                           format("... Max Fan Volume Flow Rate                                   = {:.4R} m3/s",
    6626            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate));
    6627            0 :                         ShowContinueError(state,
    6628              :                                           "...the outdoor air flow rate when no cooling or heating is needed will be reduced to match and the "
    6629              :                                           "simulation continues.");
    6630            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow =
    6631            0 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate;
    6632              :                     }
    6633              : 
    6634           61 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate > 0.0) {
    6635          122 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingSpeedRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow /
    6636           61 :                                                                                       state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate;
    6637          122 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingSpeedRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow /
    6638           61 :                                                                                       state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate;
    6639           61 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoHeatingSpeedRatio =
    6640           61 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow /
    6641           61 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate;
    6642           61 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio =
    6643           61 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow /
    6644           61 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate;
    6645              :                     }
    6646              : 
    6647           61 :                     state.dataHVACVarRefFlow->MyVRFFlag(VRFTUNum) = false;
    6648              :                 } else {
    6649           60 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ActualFanVolFlowRate =
    6650           60 :                         state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex)->maxAirFlowRate;
    6651              :                 }
    6652              :             } else {
    6653            1 :                 state.dataHVACVarRefFlow->MyVRFFlag(VRFTUNum) = false;
    6654              :             }
    6655              :         }
    6656              :     } // IF(MyVRFFlag(VRFTUNum))THEN
    6657              : 
    6658              :     // calculate end time of current time step to determine if max capacity reset is required
    6659       244151 :     CurrentEndTime = double((state.dataGlobal->DayOfSim - 1) * 24) + state.dataGlobal->CurrentTime - state.dataGlobal->TimeStepZone +
    6660       244151 :                      state.dataHVACGlobal->SysTimeElapsed;
    6661              : 
    6662              :     // Initialize the maximum allowed terminal unit capacity. Total terminal unit capacity must not
    6663              :     // exceed the available condenser capacity. This variable is used to limit the terminal units
    6664              :     // providing more capacity than allowed. Example: TU loads are 1-ton, 2-ton, 3-ton, and 4-ton connected
    6665              :     // to a condenser having only 9-tons available. This variable will be set to 3-tons and the 4-ton
    6666              :     // terminal unit will be limited to 3-tons (see SimVRFCondenser where this variable is calculated).
    6667       343428 :     if (CurrentEndTime > state.dataHVACVarRefFlow->CurrentEndTimeLast || TimeStepSysLast > state.dataHVACGlobal->TimeStepSys ||
    6668        99277 :         (FirstHVACIteration && state.dataHVACVarRefFlow->MyBeginTimeStepFlag(VRFCond))) {
    6669        27789 :         state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond) = Constant::MaxCap;
    6670        27789 :         state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond) = Constant::MaxCap;
    6671        27789 :         state.dataHVACVarRefFlow->MyBeginTimeStepFlag(VRFCond) = false;
    6672              :     }
    6673              : 
    6674       244151 :     if (!FirstHVACIteration) {
    6675       121869 :         state.dataHVACVarRefFlow->MyBeginTimeStepFlag(VRFCond) = true;
    6676              :     }
    6677              : 
    6678              :     // Do the following initializations (every time step).
    6679              : 
    6680       244151 :     TimeStepSysLast = state.dataHVACGlobal->TimeStepSys;
    6681       244151 :     state.dataHVACVarRefFlow->CurrentEndTimeLast = CurrentEndTime;
    6682              : 
    6683       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOpModeSched != nullptr) {
    6684       240963 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOpModeSched->getCurrentVal() == 0.0) {
    6685        69438 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOp = HVAC::FanOp::Cycling;
    6686              :         } else {
    6687       171525 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOp = HVAC::FanOp::Continuous;
    6688              :         }
    6689              :     }
    6690              : 
    6691              :     // if condenser is off, all terminal unit coils are off
    6692       244151 :     if (state.dataHVACVarRefFlow->VRF(VRFCond).availSched->getCurrentVal() == 0.0) {
    6693        20400 :         state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
    6694        20400 :         state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
    6695              :     } else {
    6696              : 
    6697              :         //*** Operating Mode Initialization done at beginning of each iteration ***!
    6698              :         //*** assumes all TU's and Condenser were simulated last iteration ***!
    6699              :         //*** this code is done ONCE each iteration when all TU's IsSimulated flag is FALSE ***!
    6700              :         // Determine operating mode prior to simulating any terminal units connected to a VRF condenser
    6701              :         // this should happen at the beginning of a time step where all TU's are polled to see what
    6702              :         // mode the heat pump condenser will operate in
    6703       223751 :         if (!any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).IsSimulated)) {
    6704        51606 :             InitializeOperatingMode(state, FirstHVACIteration, VRFCond, TUListIndex, OnOffAirFlowRatio);
    6705              :         }
    6706              :         //*** End of Operating Mode Initialization done at beginning of each iteration ***!
    6707              : 
    6708              :         // disable VRF system when outside limits of operation based on OAT
    6709       223751 :         EnableSystem = false; // flag used to switch operating modes when OAT is outside operating limits
    6710       223751 :         if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) {
    6711       121271 :             if ((OutsideDryBulbTemp < state.dataHVACVarRefFlow->VRF(VRFCond).MinOATCooling ||
    6712       121271 :                  OutsideDryBulbTemp > state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATCooling) &&
    6713            0 :                 any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).CoolingCoilPresent)) {
    6714            0 :                 state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
    6715              :                 // test if heating load exists, account for thermostat control type
    6716            0 :                 switch (state.dataHVACVarRefFlow->VRF(VRFCond).ThermostatPriority) {
    6717            0 :                 case ThermostatCtrlType::LoadPriority:
    6718              :                 case ThermostatCtrlType::ZonePriority: {
    6719            0 :                     if (state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) > 0.0) {
    6720            0 :                         EnableSystem = true;
    6721              :                     }
    6722            0 :                 } break;
    6723            0 :                 case ThermostatCtrlType::ThermostatOffsetPriority: {
    6724            0 :                     if (state.dataHVACVarRefFlow->MinDeltaT(VRFCond) < 0.0) {
    6725            0 :                         EnableSystem = true;
    6726              :                     }
    6727            0 :                 } break;
    6728            0 :                 case ThermostatCtrlType::ScheduledPriority:
    6729              :                 case ThermostatCtrlType::MasterThermostatPriority: {
    6730              :                     // can't switch modes if scheduled (i.e., would be switching to unscheduled mode)
    6731              :                     // or master TSTAT used (i.e., master zone only has a specific load - can't switch)
    6732            0 :                 } break;
    6733            0 :                 default:
    6734            0 :                     break;
    6735              :                 }
    6736            0 :                 if (EnableSystem) {
    6737            0 :                     if ((OutsideDryBulbTemp >= state.dataHVACVarRefFlow->VRF(VRFCond).MinOATHeating &&
    6738            0 :                          OutsideDryBulbTemp <= state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATHeating) &&
    6739            0 :                         any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HeatingCoilPresent)) {
    6740            0 :                         state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
    6741              :                     } else {
    6742            0 :                         if (any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).CoolingCoilAvailable)) {
    6743            0 :                             if (state.dataHVACVarRefFlow->VRF(VRFCond).CoolingMaxTempLimitIndex == 0) {
    6744            0 :                                 ShowWarningMessage(state,
    6745            0 :                                                    format("{} \"{}\".",
    6746            0 :                                                           cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    6747            0 :                                                           state.dataHVACVarRefFlow->VRF(VRFCond).Name));
    6748            0 :                                 ShowContinueError(state,
    6749              :                                                   "...InitVRF: VRF Heat Pump Min/Max Operating Temperature in Cooling Mode Limits have been "
    6750              :                                                   "exceeded and VRF system is disabled.");
    6751            0 :                                 if (state.dataHVACVarRefFlow->VRF(VRFCond).CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    6752            0 :                                     ShowContinueError(state,
    6753            0 :                                                       format("... Outdoor Unit Inlet Water Temperature           = {:.3T}", OutsideDryBulbTemp));
    6754              :                                 } else {
    6755            0 :                                     ShowContinueError(state,
    6756            0 :                                                       format("... Outdoor Unit Inlet Air Temperature                 = {:.3T}", OutsideDryBulbTemp));
    6757              :                                 }
    6758            0 :                                 ShowContinueError(state,
    6759            0 :                                                   format("... Cooling Minimum Outdoor Unit Inlet Temperature = {:.3T}",
    6760            0 :                                                          state.dataHVACVarRefFlow->VRF(VRFCond).MinOATCooling));
    6761            0 :                                 ShowContinueError(state,
    6762            0 :                                                   format("... Cooling Maximum Outdoor Unit Inlet Temperature = {:.3T}",
    6763            0 :                                                          state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATCooling));
    6764            0 :                                 ShowContinueErrorTimeStamp(state, "... Check VRF Heat Pump Min/Max Outdoor Temperature in Cooling Mode limits.");
    6765              :                             }
    6766            0 :                             ShowRecurringWarningErrorAtEnd(state,
    6767            0 :                                                            std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)) + " \"" +
    6768            0 :                                                                state.dataHVACVarRefFlow->VRF(VRFCond).Name +
    6769              :                                                                "\" -- Exceeded VRF Heat Pump min/max cooling temperature limit error continues...",
    6770            0 :                                                            state.dataHVACVarRefFlow->VRF(VRFCond).CoolingMaxTempLimitIndex,
    6771              :                                                            OutsideDryBulbTemp,
    6772              :                                                            OutsideDryBulbTemp);
    6773              :                         }
    6774              :                     }
    6775              :                 } else {
    6776            0 :                     if (any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).CoolingCoilAvailable)) {
    6777            0 :                         if (state.dataHVACVarRefFlow->VRF(VRFCond).CoolingMaxTempLimitIndex == 0) {
    6778            0 :                             ShowWarningMessage(state,
    6779            0 :                                                format("{} \"{}\".",
    6780            0 :                                                       cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    6781            0 :                                                       state.dataHVACVarRefFlow->VRF(VRFCond).Name));
    6782            0 :                             ShowContinueError(state,
    6783              :                                               "...InitVRF: VRF Heat Pump Min/Max Operating Temperature in Cooling Mode Limits have been exceeded "
    6784              :                                               "and VRF system is disabled.");
    6785            0 :                             if (state.dataHVACVarRefFlow->VRF(VRFCond).CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    6786            0 :                                 ShowContinueError(state, format("... Outdoor Unit Inlet Water Temperature           = {:.3T}", OutsideDryBulbTemp));
    6787              :                             } else {
    6788            0 :                                 ShowContinueError(state,
    6789            0 :                                                   format("... Outdoor Unit Inlet Air Temperature                 = {:.3T}", OutsideDryBulbTemp));
    6790              :                             }
    6791            0 :                             ShowContinueError(state,
    6792            0 :                                               format("... Cooling Minimum Outdoor Unit Inlet Temperature = {:.3T}",
    6793            0 :                                                      state.dataHVACVarRefFlow->VRF(VRFCond).MinOATCooling));
    6794            0 :                             ShowContinueError(state,
    6795            0 :                                               format("... Cooling Maximum Outdoor Unit Inlet Temperature = {:.3T}",
    6796            0 :                                                      state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATCooling));
    6797            0 :                             ShowContinueErrorTimeStamp(state, "... Check VRF Heat Pump Min/Max Outdoor Temperature in Cooling Mode limits.");
    6798              :                         }
    6799            0 :                         ShowRecurringWarningErrorAtEnd(state,
    6800            0 :                                                        std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)) + " \"" +
    6801            0 :                                                            state.dataHVACVarRefFlow->VRF(VRFCond).Name +
    6802              :                                                            "\" -- Exceeded VRF Heat Pump min/max cooling temperature limit error continues...",
    6803            0 :                                                        state.dataHVACVarRefFlow->VRF(VRFCond).CoolingMaxTempLimitIndex,
    6804              :                                                        OutsideDryBulbTemp,
    6805              :                                                        OutsideDryBulbTemp);
    6806              :                     }
    6807              :                 }
    6808              :             }
    6809       102480 :         } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) {
    6810        94261 :             if ((OutsideDryBulbTemp < state.dataHVACVarRefFlow->VRF(VRFCond).MinOATHeating ||
    6811        94261 :                  OutsideDryBulbTemp > state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATHeating) &&
    6812            0 :                 any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HeatingCoilPresent)) {
    6813            0 :                 state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
    6814              :                 // test if cooling load exists, account for thermostat control type
    6815            0 :                 switch (state.dataHVACVarRefFlow->VRF(VRFCond).ThermostatPriority) {
    6816            0 :                 case ThermostatCtrlType::LoadPriority:
    6817              :                 case ThermostatCtrlType::ZonePriority: {
    6818            0 :                     if (state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond) < 0.0) {
    6819            0 :                         EnableSystem = true;
    6820              :                     }
    6821            0 :                 } break;
    6822            0 :                 case ThermostatCtrlType::ThermostatOffsetPriority: {
    6823            0 :                     if (state.dataHVACVarRefFlow->MaxDeltaT(VRFCond) > 0.0) {
    6824            0 :                         EnableSystem = true;
    6825              :                     }
    6826            0 :                 } break;
    6827            0 :                 case ThermostatCtrlType::ScheduledPriority:
    6828              :                 case ThermostatCtrlType::MasterThermostatPriority: {
    6829            0 :                 } break;
    6830            0 :                 default:
    6831            0 :                     break;
    6832              :                 }
    6833            0 :                 if (EnableSystem) {
    6834            0 :                     if ((OutsideDryBulbTemp >= state.dataHVACVarRefFlow->VRF(VRFCond).MinOATCooling &&
    6835            0 :                          OutsideDryBulbTemp <= state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATCooling) &&
    6836            0 :                         any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).CoolingCoilPresent)) {
    6837            0 :                         state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
    6838              :                     } else {
    6839            0 :                         if (any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HeatingCoilAvailable)) {
    6840            0 :                             if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatingMaxTempLimitIndex == 0) {
    6841            0 :                                 ShowWarningMessage(state,
    6842            0 :                                                    format("{} \"{}\".",
    6843            0 :                                                           cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    6844            0 :                                                           state.dataHVACVarRefFlow->VRF(VRFCond).Name));
    6845            0 :                                 ShowContinueError(state,
    6846              :                                                   "...InitVRF: VRF Heat Pump Min/Max Operating Temperature in Heating Mode Limits have been "
    6847              :                                                   "exceeded and VRF system is disabled.");
    6848            0 :                                 if (state.dataHVACVarRefFlow->VRF(VRFCond).CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    6849            0 :                                     ShowContinueError(state,
    6850            0 :                                                       format("... Outdoor Unit Inlet Water Temperature           = {:.3T}", OutsideDryBulbTemp));
    6851              :                                 } else {
    6852            0 :                                     ShowContinueError(state,
    6853            0 :                                                       format("... Outdoor Unit Inlet Air Temperature             = {:.3T}", OutsideDryBulbTemp));
    6854              :                                 }
    6855            0 :                                 ShowContinueError(state,
    6856            0 :                                                   format("... Heating Minimum Outdoor Unit Inlet Temperature = {:.3T}",
    6857            0 :                                                          state.dataHVACVarRefFlow->VRF(VRFCond).MinOATHeating));
    6858            0 :                                 ShowContinueError(state,
    6859            0 :                                                   format("... Heating Maximum Outdoor Unit Inlet Temperature = {:.3T}",
    6860            0 :                                                          state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATHeating));
    6861            0 :                                 ShowContinueErrorTimeStamp(state, "... Check VRF Heat Pump Min/Max Outdoor Temperature in Heating Mode limits.");
    6862              :                             }
    6863            0 :                             ShowRecurringWarningErrorAtEnd(state,
    6864            0 :                                                            std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)) + " \"" +
    6865            0 :                                                                state.dataHVACVarRefFlow->VRF(VRFCond).Name +
    6866              :                                                                "\" -- Exceeded VRF Heat Pump min/max heating temperature limit error continues...",
    6867            0 :                                                            state.dataHVACVarRefFlow->VRF(VRFCond).HeatingMaxTempLimitIndex,
    6868              :                                                            OutsideDryBulbTemp,
    6869              :                                                            OutsideDryBulbTemp);
    6870              :                         }
    6871              :                     }
    6872              :                 } else {
    6873            0 :                     if (any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HeatingCoilAvailable)) {
    6874            0 :                         if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatingMaxTempLimitIndex == 0) {
    6875            0 :                             ShowWarningMessage(state,
    6876            0 :                                                format("{} \"{}\".",
    6877            0 :                                                       cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    6878            0 :                                                       state.dataHVACVarRefFlow->VRF(VRFCond).Name));
    6879            0 :                             ShowContinueError(state,
    6880              :                                               "...InitVRF: VRF Heat Pump Min/Max Operating Temperature in Heating Mode Limits have been exceeded "
    6881              :                                               "and VRF system is disabled.");
    6882            0 :                             if (state.dataHVACVarRefFlow->VRF(VRFCond).CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    6883            0 :                                 ShowContinueError(state, format("... Outdoor Unit Inlet Water Temperature           = {:.3T}", OutsideDryBulbTemp));
    6884              :                             } else {
    6885            0 :                                 ShowContinueError(state, format("... Outdoor Unit Inlet Air Temperature             = {:.3T}", OutsideDryBulbTemp));
    6886              :                             }
    6887            0 :                             ShowContinueError(state,
    6888            0 :                                               format("... Heating Minimum Outdoor Unit Inlet Temperature = {:.3T}",
    6889            0 :                                                      state.dataHVACVarRefFlow->VRF(VRFCond).MinOATHeating));
    6890            0 :                             ShowContinueError(state,
    6891            0 :                                               format("... Heating Maximum Outdoor Unit Inlet Temperature = {:.3T}",
    6892            0 :                                                      state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATHeating));
    6893            0 :                             ShowContinueErrorTimeStamp(state, "... Check VRF Heat Pump Min/Max Outdoor Temperature in Heating Mode limits.");
    6894              :                         }
    6895            0 :                         ShowRecurringWarningErrorAtEnd(state,
    6896            0 :                                                        std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)) + " \"" +
    6897            0 :                                                            state.dataHVACVarRefFlow->VRF(VRFCond).Name +
    6898              :                                                            "\" -- Exceeded VRF Heat Pump min/max heating temperature limit error continues...",
    6899            0 :                                                        state.dataHVACVarRefFlow->VRF(VRFCond).HeatingMaxTempLimitIndex,
    6900              :                                                        OutsideDryBulbTemp,
    6901              :                                                        OutsideDryBulbTemp);
    6902              :                     }
    6903              :                 }
    6904              :             }
    6905              :         }
    6906              : 
    6907              :     } // IF (GetCurrentScheduleValue(state, VRF(VRFCond)%SchedPtr) .EQ. 0.0) THEN
    6908              : 
    6909              :     // initialize terminal unit flow rate
    6910       394041 :     if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) ||
    6911       149890 :         (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed &&
    6912        22042 :          state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList))) {
    6913        94290 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    6914        79570 :             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum).MassFlowRate =
    6915        79570 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    6916        79570 :             state.dataLoopNodes->Node(OutsideAirNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    6917              :         } else {
    6918        14720 :             if (!state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInOASys) {
    6919        13355 :                 state.dataLoopNodes->Node(InNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    6920              :             }
    6921              :         }
    6922       178463 :     } else if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) ||
    6923        28602 :                (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed &&
    6924          527 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList))) {
    6925       121438 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    6926       103018 :             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum).MassFlowRate =
    6927       103018 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    6928       103018 :             state.dataLoopNodes->Node(OutsideAirNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    6929              :         } else {
    6930        18420 :             if (!state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInOASys) {
    6931        16608 :                 state.dataLoopNodes->Node(InNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    6932              :             }
    6933              :         }
    6934              :     } else {
    6935        28423 :         if (state.dataHVACVarRefFlow->LastModeCooling(VRFCond)) {
    6936        13131 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    6937        12575 :                 state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum).MassFlowRate =
    6938        12575 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    6939        12575 :                 state.dataLoopNodes->Node(OutsideAirNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    6940              :             } else {
    6941          556 :                 if (!state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInOASys) {
    6942          545 :                     state.dataLoopNodes->Node(InNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    6943              :                 }
    6944              :             }
    6945        15292 :         } else if (state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) {
    6946        15292 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    6947        15145 :                 state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum).MassFlowRate =
    6948        15145 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    6949        15145 :                 state.dataLoopNodes->Node(OutsideAirNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    6950              :             } else {
    6951          147 :                 if (!state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInOASys) {
    6952          147 :                     state.dataLoopNodes->Node(InNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    6953              :                 }
    6954              :             }
    6955              :         }
    6956              :     }
    6957              : 
    6958       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerExists) {
    6959              :         // There is an air terminal mixer
    6960        30655 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerType == HVAC::MixerType::InletSide) { // if there is an inlet side air terminal mixer
    6961              :             // set the primary air inlet mass flow rate
    6962        18393 :             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerPriNode).MassFlowRate =
    6963        18393 :                 min(state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerPriNode).MassFlowRateMaxAvail,
    6964        18393 :                     state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum).MassFlowRate);
    6965              :             // now calculate the the mixer outlet air conditions (and the secondary air inlet flow rate). The mixer outlet flow rate has already
    6966              :             // been set above (it is the "inlet" node flow rate)
    6967        36786 :             SimATMixer(state,
    6968        18393 :                        state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerName,
    6969              :                        FirstHVACIteration,
    6970        18393 :                        state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerIndex);
    6971              :         }
    6972              :     } else {
    6973       213496 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    6974       210308 :             MixedAir::SimOAMixer(
    6975       210308 :                 state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerName, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerIndex);
    6976              :         }
    6977              :     }
    6978       244151 :     OnOffAirFlowRatio = 1.0;
    6979              : 
    6980              :     // these flags are used in Subroutine CalcVRF to turn on the correct coil (heating or cooling)
    6981              :     // valid operating modes
    6982              :     // Heat Pump (heat recovery flags are set to FALSE):
    6983              :     // CoolingLoad(VRFCond) - TU can only operate in this mode if heat recovery is not used and there is a cooling load
    6984              :     // HeatingLoad(VRFCond) - TU can only operate in this mode if heat recovery is not used and there is a heating load
    6985              :     // Heat Recovery (heat pump flags are set same as for Heat Pump operation):
    6986              :     // TerminalUnitList(TUListIndex)%HRCoolRequest(IndexToTUInTUList) - TU will operate in this mode if heat recovery is used
    6987              :     // TerminalUnitList(TUListIndex)%HRHeatRequest(IndexToTUInTUList) - TU will operate in this mode if heat recovery is used
    6988              : 
    6989       244151 :     getVRFTUZoneLoad(state, VRFTUNum, QZnReq, LoadToHeatingSP, LoadToCoolingSP, false);
    6990              : 
    6991       244151 :     if (std::abs(QZnReq) < HVAC::SmallLoad) {
    6992        30933 :         QZnReq = 0.0;
    6993              :     }
    6994              :     // set initial terminal unit operating mode for heat recovery
    6995              :     // operating mode for non-heat recovery set above using CoolingLoad(VRFCond) or HeatingLoad(VRFCond) variables
    6996              :     // first turn off terminal unit
    6997       244151 :     state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    6998       244151 :     state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    6999              :     // then set according to LoadToXXXXingSP variables
    7000       244151 :     if (LoadToCoolingSP < -1.0 * HVAC::SmallLoad) {
    7001       103403 :         if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) ||
    7002          208 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) { // don't allow heat recovery if control logic dictates unit is off
    7003       103018 :             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = true;
    7004              :         }
    7005              :     }
    7006       244151 :     if (LoadToHeatingSP > HVAC::SmallLoad) {
    7007       206200 :         if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) ||
    7008       102883 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) { // don't allow heat recovery if control logic dictates unit is off
    7009        90832 :             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = true;
    7010              :         }
    7011              :     }
    7012       244151 :     if (LoadToCoolingSP > 0.0 && LoadToHeatingSP < 0.0) {
    7013        36284 :         QZnReq = 0.0;
    7014              :     }
    7015              : 
    7016              :     // next check for overshoot when constant fan mode is used
    7017              :     // check operating load to see if OA will overshoot setpoint temperature when constant fan mode is used
    7018       421416 :     if ((state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOp == HVAC::FanOp::Continuous || state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerExists) &&
    7019       177265 :         !state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isSetPointControlled) {
    7020       174077 :         SetCompFlowRate(state, VRFTUNum, VRFCond, true);
    7021              : 
    7022       174077 :         if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    7023              :             // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    7024        51715 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
    7025              :                 state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7026              :         } else {
    7027              :             // Algorithm Type: VRF model based on system curve
    7028       122362 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(
    7029              :                 state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7030              :         }
    7031              : 
    7032              :         // If the Terminal Unit has a net cooling capacity (TempOutput < 0) and
    7033              :         // the zone temp is above the Tstat heating setpoint (QToHeatSetPt < 0)
    7034              :         // see if the terminal unit operation will exceed the setpoint
    7035              :         // 4 tests here to cover all possibilities:
    7036              :         // IF(TempOutput < 0.0d0 .AND. LoadToHeatingSP .LT. 0.0d0)THEN
    7037              :         // ELSE IF(TempOutput .GT. 0.0d0 .AND. LoadToCoolingSP .GT. 0.0d0)THEN
    7038              :         // ELSE IF(TempOutput .GT. 0.0d0 .AND. LoadToCoolingSP .LT. 0.0d0)THEN
    7039              :         // ELSE IF(TempOutput < 0.0d0 .AND. LoadToHeatingSP .GT. 0.0d0)THEN
    7040              :         // END IF
    7041              :         // could compress these to 2 complex IF's but logic inside each would get more complex
    7042       174077 :         if (TempOutput < 0.0 && LoadToHeatingSP < 0.0) {
    7043              :             // If the net cooling capacity overshoots the heating setpoint count as heating load
    7044         9138 :             if (TempOutput < LoadToHeatingSP) {
    7045              :                 // Don't count as heating load unless mode is allowed. Also check for floating zone.
    7046         3740 :                 if (state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::SingleCool &&
    7047         1870 :                     state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::Uncontrolled) {
    7048         1870 :                     if (!state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) {
    7049              :                         // system last operated in cooling mode, change air flows and repeat coil off capacity test
    7050           10 :                         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    7051            9 :                             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum).MassFlowRate =
    7052            9 :                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7053            9 :                             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerOANodeNum).MassFlowRate =
    7054            9 :                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7055            9 :                             MixedAir::SimOAMixer(
    7056            9 :                                 state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerName, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerIndex);
    7057              :                         } else {
    7058            1 :                             state.dataLoopNodes->Node(InNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7059              :                         }
    7060              : 
    7061           10 :                         if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    7062              :                             // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    7063            2 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
    7064              :                                 state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7065              :                         } else {
    7066              :                             // Algorithm Type: VRF model based on system curve
    7067            8 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(
    7068              :                                 state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7069              :                         }
    7070              : 
    7071              :                         // if zone temp will overshoot, pass the LoadToHeatingSP as the load to meet
    7072           10 :                         if (TempOutput < LoadToHeatingSP) {
    7073           10 :                             QZnReq = LoadToHeatingSP;
    7074           10 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = true;
    7075           10 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7076              :                         }
    7077              :                     } else {
    7078              :                         // last mode was heating, zone temp will overshoot heating setpoint, reset QznReq to LoadtoHeatingSP
    7079         1860 :                         QZnReq = LoadToHeatingSP;
    7080         1860 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = true;
    7081         1860 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7082              :                     }
    7083              :                 }
    7084         7268 :             } else if (TempOutput > LoadToCoolingSP && LoadToCoolingSP < 0.0) {
    7085              :                 //       If the net cooling capacity does not meet the zone cooling load enable cooling
    7086          818 :                 QZnReq = LoadToCoolingSP;
    7087          818 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7088          818 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = true;
    7089         6450 :             } else if (TempOutput < LoadToCoolingSP && LoadToCoolingSP < 0.0) {
    7090              :                 //       If the net cooling capacity meets the zone cooling load but does not overshoot heating setpoint
    7091          132 :                 QZnReq = 0.0;
    7092          132 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7093          132 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7094              :             }
    7095              :             //     If the terminal unit has a net heating capacity and the zone temp is below the Tstat cooling setpoint
    7096              :             //     see if the terminal unit operation will exceed the setpoint
    7097       164939 :         } else if (TempOutput > 0.0 && LoadToCoolingSP > 0.0) {
    7098              :             //       If the net heating capacity overshoots the cooling setpoint count as cooling load
    7099        23587 :             if (TempOutput > LoadToCoolingSP) {
    7100              :                 //         Don't count as cooling load unless mode is allowed. Also check for floating zone.
    7101        16658 :                 if (state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::SingleHeat &&
    7102         8329 :                     state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::Uncontrolled) {
    7103         8329 :                     if (!state.dataHVACVarRefFlow->LastModeCooling(VRFCond)) {
    7104           28 :                         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    7105           24 :                             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum).MassFlowRate =
    7106           24 :                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7107           24 :                             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerOANodeNum).MassFlowRate =
    7108           24 :                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7109           24 :                             MixedAir::SimOAMixer(
    7110           24 :                                 state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerName, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerIndex);
    7111              :                         } else {
    7112            4 :                             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum).MassFlowRate =
    7113            4 :                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7114              :                         }
    7115              : 
    7116           28 :                         if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    7117              :                             // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    7118            6 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
    7119              :                                 state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7120              :                         } else {
    7121              :                             // Algorithm Type: VRF model based on system curve
    7122           22 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(
    7123              :                                 state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7124              :                         }
    7125              : 
    7126              :                         // if zone temp will overshoot, pass the LoadToCoolingSP as the load to meet
    7127           28 :                         if (TempOutput > LoadToCoolingSP) {
    7128           28 :                             QZnReq = LoadToCoolingSP;
    7129           28 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = true;
    7130           28 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7131              :                         }
    7132              :                     } else {
    7133         8301 :                         QZnReq = LoadToCoolingSP;
    7134         8301 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = true;
    7135         8301 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7136              :                     }
    7137              :                 }
    7138        15258 :             } else if (TempOutput < LoadToHeatingSP) {
    7139              :                 //         Don't count as heating load unless mode is allowed. Also check for floating zone.
    7140        20938 :                 if (state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::SingleCool &&
    7141        10469 :                     state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::Uncontrolled) {
    7142        10469 :                     if (!state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) {
    7143            1 :                         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    7144            0 :                             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum).MassFlowRate =
    7145            0 :                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7146            0 :                             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerOANodeNum).MassFlowRate =
    7147            0 :                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7148            0 :                             MixedAir::SimOAMixer(
    7149            0 :                                 state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerName, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerIndex);
    7150              :                         } else {
    7151            1 :                             state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum).MassFlowRate =
    7152            1 :                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7153              :                         }
    7154              : 
    7155            1 :                         if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    7156              :                             // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    7157            0 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
    7158              :                                 state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7159              :                         } else {
    7160              :                             // Algorithm Type: VRF model based on system curve
    7161            1 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(
    7162              :                                 state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7163              :                         }
    7164              : 
    7165              :                         // if zone temp will overshoot, pass the LoadToHeatingSP as the load to meet
    7166            1 :                         if (TempOutput < LoadToHeatingSP) {
    7167            1 :                             QZnReq = LoadToHeatingSP;
    7168            1 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = true;
    7169            1 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7170              :                         }
    7171              :                     } else {
    7172        10468 :                         QZnReq = LoadToHeatingSP;
    7173        10468 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = true;
    7174        10468 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7175              :                     }
    7176              :                 }
    7177         4789 :             } else if (TempOutput > LoadToHeatingSP && TempOutput < LoadToCoolingSP) {
    7178              :                 //         If the net capacity does not overshoot either setpoint
    7179         4789 :                 QZnReq = 0.0;
    7180         4789 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7181         4789 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7182              :             } else {
    7183              :                 //         If the net heating capacity meets the zone heating load but does not overshoot cooling setpoint
    7184            0 :                 QZnReq = 0.0;
    7185            0 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7186            0 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7187              :             }
    7188              :             //     If the terminal unit has a net heating capacity and the zone temp is above the Tstat cooling setpoint
    7189              :             //     see if the terminal unit operation will exceed the setpoint
    7190       141352 :         } else if (TempOutput > 0.0 && LoadToCoolingSP < 0.0) {
    7191              :             //       If the net heating capacity overshoots the cooling setpoint count as cooling load
    7192              :             //       Don't count as cooling load unless mode is allowed. Also check for floating zone.
    7193       212517 :             if (state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::SingleHeat &&
    7194        70839 :                 state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::Uncontrolled) {
    7195        70839 :                 if (!state.dataHVACVarRefFlow->LastModeCooling(VRFCond)) {
    7196           20 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    7197           11 :                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum).MassFlowRate =
    7198           11 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7199           11 :                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerOANodeNum).MassFlowRate =
    7200           11 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7201           11 :                         MixedAir::SimOAMixer(
    7202           11 :                             state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerName, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerIndex);
    7203              :                     } else {
    7204            9 :                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum).MassFlowRate =
    7205            9 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7206              :                     }
    7207              : 
    7208           20 :                     if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    7209              :                         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    7210            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
    7211              :                             state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7212              :                     } else {
    7213              :                         // Algorithm Type: VRF model based on system curve
    7214           20 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(
    7215              :                             state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7216              :                     }
    7217              : 
    7218              :                     // if zone temp will overshoot, pass the LoadToCoolingSP as the load to meet
    7219           20 :                     if (TempOutput > LoadToCoolingSP) {
    7220           20 :                         QZnReq = LoadToCoolingSP;
    7221           20 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = true;
    7222           20 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7223              :                     }
    7224              :                     // last mode was cooling, zone temp will overshoot cooling setpoint, reset QznReq to LoadtoCoolingSP
    7225              :                 } else {
    7226        70819 :                     QZnReq = LoadToCoolingSP;
    7227        70819 :                     state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = true;
    7228        70819 :                     state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7229              :                 }
    7230              :             }
    7231              :             // If the Terminal Unit has a net cooling capacity (TempOutput < 0) and
    7232              :             // the zone temp is below the Tstat heating setpoint (QToHeatSetPt > 0)
    7233              :             // see if the terminal unit operation will exceed the setpoint
    7234        70513 :         } else if (TempOutput < 0.0 && LoadToHeatingSP > 0.0) {
    7235              :             // Don't count as heating load unless mode is allowed. Also check for floating zone.
    7236       115620 :             if (state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::SingleCool &&
    7237        57810 :                 state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::Uncontrolled) {
    7238        57810 :                 if (!state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) {
    7239              :                     // system last operated in cooling mode, change air flows and repeat coil off capacity test
    7240            0 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
    7241            0 :                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum).MassFlowRate =
    7242            0 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7243            0 :                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerOANodeNum).MassFlowRate =
    7244            0 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7245            0 :                         MixedAir::SimOAMixer(
    7246            0 :                             state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerName, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerIndex);
    7247              :                     } else {
    7248            0 :                         state.dataLoopNodes->Node(InNode).MassFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7249              :                     }
    7250              : 
    7251            0 :                     if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    7252              :                         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    7253            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
    7254              :                             state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7255              :                     } else {
    7256              :                         // Algorithm Type: VRF model based on system curve
    7257            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(
    7258              :                             state, VRFTUNum, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    7259              :                     }
    7260              : 
    7261              :                     // if zone temp will overshoot, pass the LoadToHeatingSP as the load to meet
    7262            0 :                     if (TempOutput < LoadToHeatingSP) {
    7263            0 :                         QZnReq = LoadToHeatingSP;
    7264            0 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = true;
    7265            0 :                         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7266              :                     }
    7267              :                 } else {
    7268              :                     // last mode was heating, zone temp will overshoot heating setpoint, reset QznReq to LoadtoHeatingSP
    7269        57810 :                     QZnReq = LoadToHeatingSP;
    7270        57810 :                     state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = true;
    7271        57810 :                     state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7272              :                 }
    7273              :             }
    7274              :         }
    7275              :         // test that the system is active if constant fan logic enables system when thermostat control logic did not
    7276       174077 :         if (!state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && !state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) {
    7277         7868 :             if (state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) &&
    7278         7994 :                 OutsideDryBulbTemp >= state.dataHVACVarRefFlow->VRF(VRFCond).MinOATCooling &&
    7279          126 :                 OutsideDryBulbTemp <= state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATCooling) {
    7280          126 :                 state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
    7281         7742 :             } else if (state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) &&
    7282         7750 :                        OutsideDryBulbTemp >= state.dataHVACVarRefFlow->VRF(VRFCond).MinOATHeating &&
    7283            8 :                        OutsideDryBulbTemp <= state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATHeating) {
    7284            8 :                 state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
    7285              :             }
    7286              :         }
    7287              :     } // IF(VRFTU(VRFTUNum)%fanOp == HVAC::FanOp::Continuous)THEN
    7288              : 
    7289       244151 :     if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed) {
    7290        73950 :         if (OutsideDryBulbTemp < state.dataHVACVarRefFlow->VRF(VRFCond).MinOATHeatRecovery ||
    7291        36975 :             OutsideDryBulbTemp > state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATHeatRecovery) {
    7292        37622 :             if ((any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest) && state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) ||
    7293        18811 :                 (any(state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest) && state.dataHVACVarRefFlow->CoolingLoad(VRFCond))) {
    7294            7 :                 if (state.dataHVACVarRefFlow->VRF(VRFCond).HRMaxTempLimitIndex == 0) {
    7295            2 :                     ShowWarningMessage(state,
    7296            2 :                                        format("{} \"{}\".",
    7297            1 :                                               cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    7298            1 :                                               state.dataHVACVarRefFlow->VRF(VRFCond).Name));
    7299            2 :                     ShowContinueError(state,
    7300              :                                       "...InitVRF: VRF Heat Pump Min/Max Outdoor Temperature in Heat Recovery Mode Limits have been exceeded and "
    7301              :                                       "VRF heat recovery is disabled.");
    7302            1 :                     ShowContinueError(state, format("... Outdoor Dry-Bulb Temperature                       = {:.3T}", OutsideDryBulbTemp));
    7303            2 :                     ShowContinueError(state,
    7304            2 :                                       format("... Heat Recovery Minimum Outdoor Dry-Bulb Temperature = {:.3T}",
    7305            1 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).MinOATHeatRecovery));
    7306            2 :                     ShowContinueError(state,
    7307            2 :                                       format("... Heat Recovery Maximum Outdoor Dry-Bulb Temperature = {:.3T}",
    7308            1 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATHeatRecovery));
    7309            2 :                     ShowContinueErrorTimeStamp(state, "... Check VRF Heat Pump Min/Max Outdoor Temperature in Heat Recovery Mode limits.");
    7310            3 :                     ShowContinueError(state, "...the system will operate in heat pump mode when applicable.");
    7311              :                 }
    7312           56 :                 ShowRecurringWarningErrorAtEnd(state,
    7313           14 :                                                std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)) + " \"" +
    7314           28 :                                                    state.dataHVACVarRefFlow->VRF(VRFCond).Name +
    7315              :                                                    "\" -- Exceeded VRF Heat Recovery min/max outdoor temperature limit error continues...",
    7316            7 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).HRMaxTempLimitIndex,
    7317              :                                                OutsideDryBulbTemp,
    7318              :                                                OutsideDryBulbTemp);
    7319              :             }
    7320              :             // Allow heat pump mode to operate if within limits
    7321        37622 :             if (OutsideDryBulbTemp < state.dataHVACVarRefFlow->VRF(VRFCond).MinOATCooling ||
    7322        18811 :                 OutsideDryBulbTemp > state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATCooling) {
    7323              :                 // Disable cooling mode only, heating model will still be allowed
    7324            0 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7325              :             }
    7326        37622 :             if (OutsideDryBulbTemp < state.dataHVACVarRefFlow->VRF(VRFCond).MinOATHeating ||
    7327        18811 :                 OutsideDryBulbTemp > state.dataHVACVarRefFlow->VRF(VRFCond).MaxOATHeating) {
    7328              :                 // Disable heating mode only, cooling model will still be allowed
    7329        18811 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7330              :             }
    7331              :         }
    7332              :     } else {
    7333       207176 :         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest = false;
    7334       207176 :         state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest = false;
    7335              :     }
    7336              : 
    7337              :     // Override operating mode when using EMS
    7338              :     // this logic seems suspect, uses a "just run it on" mentality. Nee to test using EMS.
    7339       244151 :     if (state.dataHVACVarRefFlow->VRF(VRFCond).EMSOverrideHPOperatingMode) {
    7340            0 :         if (state.dataHVACVarRefFlow->VRF(VRFCond).EMSValueForHPOperatingMode == 0.0) { // Off
    7341            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
    7342            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
    7343            0 :             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7344            0 :             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7345            0 :         } else if (state.dataHVACVarRefFlow->VRF(VRFCond).EMSValueForHPOperatingMode == 1.0) { // Cooling
    7346            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
    7347            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
    7348            0 :             QZnReq = LoadToCoolingSP;
    7349            0 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed) {
    7350            0 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = false;
    7351            0 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = true;
    7352              :             }
    7353            0 :         } else if (state.dataHVACVarRefFlow->VRF(VRFCond).EMSValueForHPOperatingMode == 2.0) { // Heating
    7354            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
    7355            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
    7356            0 :             QZnReq = LoadToHeatingSP;
    7357            0 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed) {
    7358            0 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList) = true;
    7359            0 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList) = false;
    7360              :             }
    7361              :         } else {
    7362            0 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).HPOperatingModeErrorIndex == 0) {
    7363            0 :                 ShowWarningMessage(state,
    7364            0 :                                    format("{} \"{}\".",
    7365            0 :                                           cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    7366            0 :                                           state.dataHVACVarRefFlow->VRF(VRFCond).Name));
    7367            0 :                 ShowContinueError(
    7368              :                     state,
    7369            0 :                     format("...InitVRF: Illegal HP operating mode = {:.0T}", state.dataHVACVarRefFlow->VRF(VRFCond).EMSValueForHPOperatingMode));
    7370            0 :                 ShowContinueError(state, "...InitVRF: VRF HP operating mode will not be controlled by EMS.");
    7371              :             }
    7372            0 :             ShowRecurringWarningErrorAtEnd(state,
    7373            0 :                                            std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)) + " \"" +
    7374            0 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).Name + "\" -- Illegal HP operating mode error continues...",
    7375            0 :                                            state.dataHVACVarRefFlow->VRF(VRFCond).HPOperatingModeErrorIndex,
    7376            0 :                                            state.dataHVACVarRefFlow->VRF(VRFCond).EMSValueForHPOperatingMode,
    7377            0 :                                            state.dataHVACVarRefFlow->VRF(VRFCond).EMSValueForHPOperatingMode);
    7378              :         }
    7379              :     }
    7380              : 
    7381              :     // set the TU flow rate. Check for heat recovery operation first, these will be FALSE if HR is not used.
    7382       244151 :     if (state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList)) {
    7383        19973 :         state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7384        19973 :         state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7385        19973 :         state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7386        19973 :         state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7387        19973 :         state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingSpeedRatio;
    7388        19973 :         state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7389       224178 :     } else if (state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList)) {
    7390        14055 :         state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7391        14055 :         state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    7392        14055 :         state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7393        14055 :         state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7394        14055 :         state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingSpeedRatio;
    7395        14055 :         state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoHeatingSpeedRatio;
    7396       210123 :     } else if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && QZnReq != 0.0) {
    7397        91418 :         state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7398        91418 :         state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7399        91418 :         state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7400        91418 :         state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7401        91418 :         state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingSpeedRatio;
    7402        91418 :         state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7403       118705 :     } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) && QZnReq != 0.0) {
    7404        78145 :         state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7405        78145 :         state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    7406        78145 :         state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7407        78145 :         state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7408        78145 :         state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingSpeedRatio;
    7409        78145 :         state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoHeatingSpeedRatio;
    7410              :     } else {
    7411        40560 :         if (state.dataHVACVarRefFlow->LastModeCooling(VRFCond)) {
    7412        23173 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7413        23173 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7414        23173 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7415        23173 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7416        23173 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7417              :         }
    7418        40560 :         if (state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) {
    7419        17387 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    7420        17387 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    7421        17387 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7422        17387 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoHeatingSpeedRatio;
    7423        17387 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoHeatingSpeedRatio;
    7424              :         }
    7425        40560 :         state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7426              :     }
    7427              : 
    7428       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOp == HVAC::FanOp::Cycling) {
    7429        69438 :         state.dataHVACVarRefFlow->CompOffMassFlow = 0.0;
    7430        69438 :         state.dataHVACVarRefFlow->OACompOffMassFlow = 0.0;
    7431        69438 :         state.dataHVACVarRefFlow->CompOffFlowRatio = 0.0;
    7432              :     }
    7433              : 
    7434       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating > 0 || state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling > 0) {
    7435         6030 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SpeedNum = 0;
    7436         6030 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SpeedRatio = 0.0;
    7437         6030 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CycRatio = 0.0;
    7438              :     }
    7439              : 
    7440       244151 :     SetAverageAirFlow(state, VRFTUNum, 0.0, OnOffAirFlowRatio);
    7441              : 
    7442       244151 :     if (ErrorsFound) {
    7443            0 :         ShowFatalError(state,
    7444            0 :                        format("{}: Errors found in getting ZoneHVAC:TerminalUnit:VariableRefrigerantFlow system input. Preceding condition(s) "
    7445              :                               "causes termination.",
    7446              :                               RoutineName));
    7447              :     }
    7448       244151 : }
    7449              : 
    7450       345512 : void SetCompFlowRate(EnergyPlusData &state, int const VRFTUNum, int const VRFCond, bool const UseCurrentMode)
    7451              : {
    7452              : 
    7453              :     // SUBROUTINE INFORMATION:
    7454              :     //       AUTHOR         Richard Raustad, FSEC
    7455              :     //       DATE WRITTEN   June 2011
    7456              :     //       MODIFIED       na
    7457              :     //       RE-ENGINEERED  na
    7458              : 
    7459              :     // PURPOSE OF THIS SUBROUTINE:
    7460              :     // This subroutine is for calling VRF terminal units during Init to initialize flow rate
    7461              :     // while looping through all terminal units connected to a specific condenser.
    7462              :     // This allows polling of capacities for all terminal units.
    7463              :     // Since the heat pump can only heat or cool, a single operating mode is chosen for each condenser.
    7464              : 
    7465              :     // METHODOLOGY EMPLOYED:
    7466              :     // Initializes flow rates for a specific terminal unit.
    7467              : 
    7468              :     int IndexToTUInTUList; // - index to TU in specific list for this VRF system
    7469              :     int TUListIndex;       // index to TU list for this VRF system
    7470              : 
    7471       345512 :     IndexToTUInTUList = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).IndexToTUInTUList;
    7472       345512 :     TUListIndex = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TUListIndex;
    7473              : 
    7474              :     // uses current operating mode to set flow rate (after mode is set)
    7475       345512 :     if (state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList)) {
    7476        95084 :         state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7477        95084 :         state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7478        95084 :         state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7479        95084 :         state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7480        95084 :         state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingSpeedRatio;
    7481        95084 :         state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7482       250428 :     } else if (state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList)) {
    7483        89101 :         state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7484        89101 :         state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    7485        89101 :         state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7486        89101 :         state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7487        89101 :         state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingSpeedRatio;
    7488        89101 :         state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoHeatingSpeedRatio;
    7489       161327 :     } else if (UseCurrentMode) { // uses current operating mode to set flow rate (after mode is set)
    7490        21741 :         if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) {
    7491        11579 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7492        11579 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7493        11579 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7494        11579 :             state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7495        11579 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingSpeedRatio;
    7496        11579 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7497        10162 :         } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) {
    7498         2294 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7499         2294 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    7500         2294 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7501         2294 :             state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7502         2294 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingSpeedRatio;
    7503         2294 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoHeatingSpeedRatio;
    7504         7868 :         } else if (state.dataHVACVarRefFlow->LastModeCooling(VRFCond)) { // if NOT cooling or heating then use last mode
    7505         6284 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7506         6284 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7507         6284 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7508         6284 :             state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7509         6284 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingSpeedRatio;
    7510         6284 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7511         1584 :         } else if (state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) { // if NOT cooling or heating then use last mode
    7512         1584 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7513         1584 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    7514         1584 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7515         1584 :             state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7516         1584 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingSpeedRatio;
    7517         1584 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoHeatingSpeedRatio;
    7518              :         } else { // should not happen so just set to cooling flow rate
    7519            0 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7520            0 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7521            0 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7522            0 :             state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7523            0 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingSpeedRatio;
    7524            0 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7525              :         }
    7526              :     } else { // uses previous operating mode to set flow rate (used for looping through each TU in Init before mode is set)
    7527       139586 :         if (state.dataHVACVarRefFlow->LastModeCooling(VRFCond)) {
    7528        75057 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7529        75057 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7530        75057 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7531        75057 :             state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7532        75057 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingSpeedRatio;
    7533        75057 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7534        64529 :         } else if (state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) {
    7535        64529 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirMassFlow;
    7536        64529 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirMassFlow;
    7537        64529 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirMassFlow;
    7538        64529 :             state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7539        64529 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingSpeedRatio;
    7540        64529 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoHeatingSpeedRatio;
    7541              :         } else { // should not happen so just set to cooling flow rate
    7542            0 :             state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirMassFlow;
    7543            0 :             state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirMassFlow;
    7544            0 :             state.dataHVACVarRefFlow->OACompOnMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirMassFlow;
    7545            0 :             state.dataHVACVarRefFlow->OACompOffMassFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirMassFlow;
    7546            0 :             state.dataHVACVarRefFlow->CompOnFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingSpeedRatio;
    7547            0 :             state.dataHVACVarRefFlow->CompOffFlowRatio = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolingSpeedRatio;
    7548              :         }
    7549              :     }
    7550              : 
    7551       345512 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOp == HVAC::FanOp::Cycling) {
    7552         2552 :         state.dataHVACVarRefFlow->CompOffMassFlow = 0.0;
    7553         2552 :         state.dataHVACVarRefFlow->OACompOffMassFlow = 0.0;
    7554         2552 :         state.dataHVACVarRefFlow->CompOffFlowRatio = 0.0;
    7555              :     }
    7556       345512 : }
    7557              : 
    7558           62 : void SizeVRF(EnergyPlusData &state, int const VRFTUNum)
    7559              : {
    7560              : 
    7561              :     // SUBROUTINE INFORMATION:
    7562              :     //       AUTHOR         Richard Raustad, FSEC
    7563              :     //       DATE WRITTEN   August 2010
    7564              :     //       MODIFIED       August 2013 Daeho Kang, add component sizing table entries
    7565              :     //                      B Nigusse, FSEC, added scalable sizing
    7566              :     //       RE-ENGINEERED  na
    7567              : 
    7568              :     // PURPOSE OF THIS SUBROUTINE:
    7569              :     // This subroutine is for sizing VRF Components for which inputs have not been
    7570              :     // specified in the input.
    7571              : 
    7572              :     // METHODOLOGY EMPLOYED:
    7573              :     // Obtains flow rates from the zone or system sizing arrays.
    7574              : 
    7575              :     using namespace DataSizing;
    7576              :     using Curve::CurveValue;
    7577              :     using HVAC::CoolingAirflowSizing;
    7578              :     using HVAC::CoolingCapacitySizing;
    7579              :     using HVAC::HeatingAirflowSizing;
    7580              :     using HVAC::HeatingCapacitySizing;
    7581              : 
    7582              :     using PlantUtilities::RegisterPlantCompDesignFlow;
    7583              : 
    7584              :     static constexpr std::string_view RoutineName("SizeVRF: "); // include trailing blank space
    7585              : 
    7586           62 :     auto &CheckVRFCombinationRatio = state.dataHVACVarRefFlow->CheckVRFCombinationRatio;
    7587              :     Real64 TUCoolingCapacity;           // total terminal unit cooling capacity
    7588              :     Real64 TUHeatingCapacity;           // total terminal unit heating capacity
    7589              :     int VRFCond;                        // index to VRF condenser
    7590              :     Real64 OnOffAirFlowRat;             // temporary variable used when sizing coils
    7591              :     Real64 DXCoilCap;                   // capacity of DX cooling coil (W)
    7592              :     bool IsAutoSize;                    // Indicator to autosize
    7593              :     Real64 MaxCoolAirVolFlowDes;        // Autosized supply air during cooling for reporting
    7594              :     Real64 MaxCoolAirVolFlowUser;       // Hardsized supply air during cooling for reporting
    7595              :     Real64 MaxHeatAirVolFlowDes;        // Autosized supply air during heating for reporting
    7596              :     Real64 MaxHeatAirVolFlowUser;       // Hardsized supply air during heating for reporting
    7597              :     Real64 MaxNoCoolAirVolFlowDes;      // Autosized supply air flow when no cooling is needed for reporting
    7598              :     Real64 MaxNoCoolAirVolFlowUser;     // Hardsized supply air flow when no cooling is needed for reporting
    7599              :     Real64 MaxNoHeatAirVolFlowDes;      // Autosized supply air flow when no heating is needed for reporting
    7600              :     Real64 MaxNoHeatAirVolFlowUser;     // Hardsized supply air flow when no heating is needed for reporting
    7601              :     Real64 CoolOutAirVolFlowDes;        // Autosized outdoor air flow during cooling for reporting
    7602              :     Real64 CoolOutAirVolFlowUser;       // Hardsized outdoor air flow during cooling for reporting
    7603              :     Real64 HeatOutAirVolFlowDes;        // Autosized outdoor air flow during heating for reporting
    7604              :     Real64 HeatOutAirVolFlowUser;       // Hardsized outdoor air flow during heating for reporting
    7605              :     Real64 NoCoolHeatOutAirVolFlowDes;  // Autosized outdoor air when unconditioned for reporting
    7606              :     Real64 NoCoolHeatOutAirVolFlowUser; // Hardsized outdoor air when unconditioned for reporting
    7607              :     Real64 CoolingCapacityDes;          // Autosized cooling capacity for reporting
    7608              :     Real64 CoolingCapacityUser;         // Hardsized cooling capacity for reporting
    7609              :     Real64 HeatingCapacityDes;          // Autosized heating capacity for reporting
    7610              :     Real64 HeatingCapacityUser;         // Hardsized heating capacity for reporting
    7611              :     Real64 DefrostCapacityDes;          // Autosized defrost heater capacity for reporting
    7612              :     Real64 DefrostCapacityUser;         // Hardsized defrost heater capacity for reporting
    7613              :     Real64 EvapCondAirVolFlowRateDes;   // Autosized evaporative condenser flow for reporting
    7614              :     Real64 EvapCondAirVolFlowRateUser;  // Hardsized evaporative condenser flow for reporting
    7615              :     Real64 EvapCondPumpPowerDes;        // Autosized evaporative condenser pump power for reporting
    7616              :     Real64 EvapCondPumpPowerUser;       // Hardsized evaporative condenser pump power for reporting
    7617              : 
    7618           62 :     std::string CompName;     // component name
    7619           62 :     std::string CompType;     // component type
    7620           62 :     std::string SizingString; // input field sizing description (e.g., Nominal Capacity)
    7621              :     Real64 TempSize;          // autosized value of coil input field
    7622           62 :     int FieldNum = 2;         // IDD numeric field number where input field description is found
    7623           62 :     bool PrintFlag = true;    // TRUE when sizing information is reported in the eio file
    7624              : 
    7625           62 :     auto &ZoneEqSizing = state.dataSize->ZoneEqSizing;
    7626              : 
    7627           62 :     DataSizing::ZoneEqSizingData *select_EqSizing(nullptr);
    7628              : 
    7629              :     // sweep specific data into one pointer to avoid if statements throughout this subroutine
    7630           62 :     if (state.dataSize->CurOASysNum > 0) {
    7631            1 :         select_EqSizing = &state.dataSize->OASysEqSizing(state.dataSize->CurOASysNum);
    7632           61 :     } else if (state.dataSize->CurSysNum > 0) {
    7633            1 :         select_EqSizing = &state.dataSize->UnitarySysEqSizing(state.dataSize->CurSysNum);
    7634           60 :     } else if (state.dataSize->CurZoneEqNum > 0) {
    7635           60 :         select_EqSizing = &ZoneEqSizing(state.dataSize->CurZoneEqNum);
    7636           60 :         state.dataSize->ZoneEqUnitarySys = true;
    7637              :     } else {
    7638            0 :         assert(false);
    7639              :     }
    7640              :     // Object Data, points to specific array
    7641           62 :     DataSizing::ZoneEqSizingData &EqSizing(*select_EqSizing);
    7642              : 
    7643              :     // can't hurt to initialize these going in, probably redundant
    7644           62 :     EqSizing.AirFlow = false;
    7645           62 :     EqSizing.CoolingAirFlow = false;
    7646           62 :     EqSizing.HeatingAirFlow = false;
    7647           62 :     EqSizing.AirVolFlow = 0.0;
    7648           62 :     EqSizing.CoolingAirVolFlow = 0.0;
    7649           62 :     EqSizing.HeatingAirVolFlow = 0.0;
    7650           62 :     EqSizing.Capacity = false;
    7651           62 :     EqSizing.CoolingCapacity = false;
    7652           62 :     EqSizing.HeatingCapacity = false;
    7653           62 :     EqSizing.DesCoolingLoad = 0.0;
    7654           62 :     EqSizing.DesHeatingLoad = 0.0;
    7655           62 :     EqSizing.OAVolFlow = 0.0;
    7656              : 
    7657           62 :     VRFCond = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum;
    7658           62 :     MaxCoolAirVolFlowDes = 0.0;
    7659           62 :     MaxCoolAirVolFlowUser = 0.0;
    7660           62 :     MaxHeatAirVolFlowDes = 0.0;
    7661           62 :     MaxHeatAirVolFlowUser = 0.0;
    7662           62 :     MaxNoCoolAirVolFlowDes = 0.0;
    7663           62 :     MaxNoCoolAirVolFlowUser = 0.0;
    7664           62 :     MaxNoHeatAirVolFlowDes = 0.0;
    7665           62 :     MaxNoHeatAirVolFlowUser = 0.0;
    7666           62 :     CoolOutAirVolFlowDes = 0.0;
    7667           62 :     CoolOutAirVolFlowUser = 0.0;
    7668           62 :     HeatOutAirVolFlowDes = 0.0;
    7669           62 :     HeatOutAirVolFlowUser = 0.0;
    7670           62 :     NoCoolHeatOutAirVolFlowDes = 0.0;
    7671           62 :     NoCoolHeatOutAirVolFlowUser = 0.0;
    7672           62 :     CoolingCapacityDes = 0.0;
    7673           62 :     CoolingCapacityUser = 0.0;
    7674           62 :     HeatingCapacityDes = 0.0;
    7675           62 :     HeatingCapacityUser = 0.0;
    7676           62 :     DefrostCapacityDes = 0.0;
    7677           62 :     DefrostCapacityUser = 0.0;
    7678           62 :     EvapCondAirVolFlowRateDes = 0.0;
    7679           62 :     EvapCondAirVolFlowRateUser = 0.0;
    7680           62 :     EvapCondPumpPowerDes = 0.0;
    7681           62 :     EvapCondPumpPowerUser = 0.0;
    7682              : 
    7683           62 :     state.dataSize->DataScalableSizingON = false;
    7684           62 :     state.dataSize->DataScalableCapSizingON = false;
    7685           62 :     state.dataSize->DataFracOfAutosizedCoolingAirflow = 1.0;
    7686           62 :     state.dataSize->DataFracOfAutosizedHeatingAirflow = 1.0;
    7687           62 :     state.dataSize->DataFracOfAutosizedCoolingCapacity = 1.0;
    7688           62 :     state.dataSize->DataFracOfAutosizedHeatingCapacity = 1.0;
    7689           62 :     state.dataSize->SuppHeatCap = 0.0;
    7690              : 
    7691           62 :     if (state.dataHVACVarRefFlow->MyOneTimeSizeFlag) {
    7692              :         // initialize the environment and sizing flags
    7693           13 :         CheckVRFCombinationRatio.dimension(state.dataHVACVarRefFlow->NumVRFCond, true);
    7694           13 :         state.dataHVACVarRefFlow->MyOneTimeSizeFlag = false;
    7695              :     }
    7696              : 
    7697           62 :     CompType = tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type];
    7698           62 :     CompName = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name;
    7699           62 :     state.dataSize->DataZoneNumber = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum;
    7700              : 
    7701           62 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex > 0) {
    7702           61 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInZone) {
    7703           60 :             state.dataSize->DataFanType = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanType;
    7704           60 :             state.dataSize->DataFanIndex = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex;
    7705           60 :             state.dataSize->DataFanPlacement = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanPlace;
    7706            1 :         } else if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInAirLoop) {
    7707            1 :             state.dataAirSystemsData->PrimaryAirSystems(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).airLoopNum).supFanType =
    7708            1 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanType;
    7709            1 :             state.dataAirSystemsData->PrimaryAirSystems(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).airLoopNum).supFanNum =
    7710            1 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex;
    7711            1 :             state.dataAirSystemsData->PrimaryAirSystems(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).airLoopNum).supFanPlace =
    7712            1 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanPlace;
    7713              :         }
    7714              :     }
    7715              : 
    7716           62 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HVACSizingIndex > 0) {
    7717              :         // initialize OA flow for sizing other inputs (e.g., capacity)
    7718            1 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow == AutoSize) {
    7719            1 :             EqSizing.OAVolFlow = state.dataSize->FinalZoneSizing(state.dataSize->CurZoneEqNum).MinOA;
    7720              :         } else {
    7721            0 :             EqSizing.OAVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow;
    7722              :         }
    7723            1 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow != AutoSize) {
    7724            0 :             EqSizing.OAVolFlow = max(EqSizing.OAVolFlow, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow);
    7725              :         }
    7726            1 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerExists &&
    7727            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInZone) { // set up ATMixer conditions for scalable capacity sizing
    7728            0 :             EqSizing.OAVolFlow = 0.0;                             // Equipment OA flow should always be 0 when ATMixer is used
    7729            0 :             SingleDuct::setATMixerSizingProperties(state,
    7730            0 :                                                    state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerIndex,
    7731            0 :                                                    state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum,
    7732            0 :                                                    state.dataSize->CurZoneEqNum);
    7733              :         }
    7734              : 
    7735            1 :         int zoneHVACIndex = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HVACSizingIndex;
    7736              : 
    7737              :         // Integer representation of sizing method name (e.g., CoolingAirflowSizing, HeatingAirflowSizing, CoolingCapacitySizing,
    7738              :         // HeatingCapacitySizing, etc.)
    7739            1 :         int SizingMethod = CoolingAirflowSizing;
    7740            1 :         PrintFlag = true;
    7741            1 :         bool errorsFound = false;
    7742              :         // supply air flow rate sizing method (SupplyAirFlowRate, FlowPerFloorArea, FractionOfAutosizedCoolingAirflow,
    7743              :         // FractionOfAutosizedHeatingAirflow ...)
    7744            1 :         int SAFMethod = state.dataSize->ZoneHVACSizing(zoneHVACIndex).CoolingSAFMethod;
    7745            1 :         EqSizing.SizingMethod(SizingMethod) = SAFMethod;
    7746            1 :         if (SAFMethod == SupplyAirFlowRate || SAFMethod == FlowPerFloorArea || SAFMethod == FractionOfAutosizedCoolingAirflow) {
    7747            1 :             if (SAFMethod == SupplyAirFlowRate) {
    7748            1 :                 if (state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow > 0.0) {
    7749            0 :                     EqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
    7750            0 :                     EqSizing.SystemAirFlow = true;
    7751              :                 }
    7752            1 :                 TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
    7753            0 :             } else if (SAFMethod == FlowPerFloorArea) {
    7754            0 :                 EqSizing.SystemAirFlow = true;
    7755            0 :                 EqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow *
    7756            0 :                                       state.dataHeatBal->Zone(state.dataSize->DataZoneNumber).FloorArea;
    7757            0 :                 TempSize = ZoneEqSizing(state.dataSize->CurZoneEqNum).AirVolFlow;
    7758            0 :                 state.dataSize->DataScalableSizingON = true;
    7759            0 :             } else if (SAFMethod == FractionOfAutosizedCoolingAirflow) {
    7760            0 :                 state.dataSize->DataFracOfAutosizedCoolingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
    7761            0 :                 TempSize = AutoSize;
    7762            0 :                 state.dataSize->DataScalableSizingON = true;
    7763              :             } else {
    7764            0 :                 TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
    7765              :             }
    7766              : 
    7767            1 :             CoolingAirFlowSizer sizingCoolingAirFlow;
    7768            1 :             std::string stringOverride = "Cooling Supply Air Flow Rate [m3/s]";
    7769            1 :             if (state.dataGlobal->isEpJSON) {
    7770            0 :                 stringOverride = "cooling_supply_air_flow_rate [m3/s]";
    7771              :             }
    7772            1 :             sizingCoolingAirFlow.overrideSizingString(stringOverride);
    7773              :             // sizingCoolingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
    7774            1 :             sizingCoolingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    7775            1 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow = sizingCoolingAirFlow.size(state, TempSize, errorsFound);
    7776              : 
    7777            1 :         } else if (SAFMethod == FlowPerCoolingCapacity) {
    7778            0 :             SizingMethod = CoolingCapacitySizing; // either this isn't needed or needs to be assigned to EqSizing
    7779            0 :             TempSize = AutoSize;
    7780            0 :             PrintFlag = false;
    7781            0 :             state.dataSize->DataScalableSizingON = true;
    7782            0 :             state.dataSize->DataFlowUsedForSizing = state.dataSize->FinalZoneSizing(state.dataSize->CurZoneEqNum).DesCoolVolFlow;
    7783            0 :             if (state.dataSize->ZoneHVACSizing(zoneHVACIndex).CoolingCapMethod == FractionOfAutosizedCoolingCapacity) {
    7784            0 :                 state.dataSize->DataFracOfAutosizedCoolingCapacity = state.dataSize->ZoneHVACSizing(zoneHVACIndex).ScaledCoolingCapacity;
    7785              :             }
    7786            0 :             CoolingCapacitySizer sizerCoolingCapacity;
    7787            0 :             sizerCoolingCapacity.overrideSizingString(SizingString);
    7788            0 :             sizerCoolingCapacity.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    7789            0 :             state.dataSize->DataAutosizedCoolingCapacity = sizerCoolingCapacity.size(state, TempSize, errorsFound);
    7790            0 :             state.dataSize->DataFlowPerCoolingCapacity = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
    7791            0 :             PrintFlag = true;
    7792            0 :             TempSize = AutoSize;
    7793            0 :             CoolingAirFlowSizer sizingCoolingAirFlow;
    7794            0 :             std::string stringOverride = "Cooling Supply Air Flow Rate [m3/s]";
    7795            0 :             if (state.dataGlobal->isEpJSON) {
    7796            0 :                 stringOverride = "cooling_supply_air_flow_rate [m3/s]";
    7797              :             }
    7798            0 :             sizingCoolingAirFlow.overrideSizingString(stringOverride);
    7799              :             // sizingCoolingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
    7800            0 :             sizingCoolingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    7801            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow = sizingCoolingAirFlow.size(state, TempSize, errorsFound);
    7802            0 :         }
    7803              :         // Multispeed Fan cooling flow sizing
    7804            1 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling > 0) {
    7805            0 :             Real64 AirFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow;
    7806            0 :             for (int i = 1; i <= state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling; ++i) {
    7807            0 :                 if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex > -1) {
    7808            0 :                     if (state.dataUnitarySystems->designSpecMSHP[state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex]
    7809            0 :                             .coolingVolFlowRatio[i] == DataSizing::AutoSize) {
    7810            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] =
    7811            0 :                             double(i) / double(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling) * AirFlowRate;
    7812              :                     } else {
    7813            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] =
    7814            0 :                             state.dataUnitarySystems->designSpecMSHP[state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex]
    7815            0 :                                 .coolingVolFlowRatio[i] *
    7816              :                             AirFlowRate;
    7817              :                     }
    7818            0 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] =
    7819            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] * state.dataEnvrn->StdRhoAir;
    7820              :                 } else {
    7821            0 :                     auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex));
    7822            0 :                     assert(fanSystem != nullptr);
    7823            0 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] == 0.0 && !fanSystem->massFlowAtSpeed.empty()) {
    7824            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
    7825            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] =
    7826            0 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] / state.dataEnvrn->StdRhoAir;
    7827              :                     }
    7828              :                 }
    7829              :             }
    7830              :         }
    7831              : 
    7832            1 :         SizingMethod = HeatingAirflowSizing;
    7833            1 :         FieldNum = 3; // N3, \field Supply Air Flow Rate During Heating Operation
    7834            1 :         PrintFlag = true;
    7835            1 :         SizingString = state.dataHVACVarRefFlow->VRFTUNumericFields(VRFTUNum).FieldNames(FieldNum) + " [m3/s]";
    7836            1 :         SAFMethod = state.dataSize->ZoneHVACSizing(zoneHVACIndex).HeatingSAFMethod;
    7837            1 :         EqSizing.SizingMethod(SizingMethod) = SAFMethod;
    7838            1 :         if (SAFMethod == SupplyAirFlowRate || SAFMethod == FlowPerFloorArea || SAFMethod == FractionOfAutosizedHeatingAirflow) {
    7839            1 :             if (SAFMethod == SupplyAirFlowRate) {
    7840            1 :                 if (state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxHeatAirVolFlow > 0.0) {
    7841            0 :                     EqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxHeatAirVolFlow;
    7842            0 :                     EqSizing.SystemAirFlow = true;
    7843              :                 }
    7844            1 :                 TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxHeatAirVolFlow;
    7845            0 :             } else if (SAFMethod == FlowPerFloorArea) {
    7846            0 :                 EqSizing.SystemAirFlow = true;
    7847            0 :                 EqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxHeatAirVolFlow *
    7848            0 :                                       state.dataHeatBal->Zone(state.dataSize->DataZoneNumber).FloorArea;
    7849            0 :                 TempSize = ZoneEqSizing(state.dataSize->CurZoneEqNum).AirVolFlow;
    7850            0 :                 state.dataSize->DataScalableSizingON = true;
    7851            0 :             } else if (SAFMethod == FractionOfAutosizedHeatingAirflow) {
    7852            0 :                 state.dataSize->DataFracOfAutosizedHeatingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxHeatAirVolFlow;
    7853            0 :                 TempSize = AutoSize;
    7854            0 :                 state.dataSize->DataScalableSizingON = true;
    7855              :             } else {
    7856            0 :                 TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxHeatAirVolFlow;
    7857              :             }
    7858            1 :             errorsFound = false;
    7859            1 :             HeatingAirFlowSizer sizingHeatingAirFlow;
    7860            1 :             sizingHeatingAirFlow.overrideSizingString(SizingString);
    7861              :             // sizingHeatingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
    7862            1 :             sizingHeatingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    7863            1 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow = sizingHeatingAirFlow.size(state, TempSize, errorsFound);
    7864            1 :         } else if (SAFMethod == FlowPerHeatingCapacity) {
    7865            0 :             SizingMethod = HeatingCapacitySizing; // either this isn't needed or needs to be assigned to EqSizing
    7866            0 :             TempSize = AutoSize;
    7867            0 :             PrintFlag = false;
    7868            0 :             state.dataSize->DataScalableSizingON = true;
    7869            0 :             state.dataSize->DataFlowUsedForSizing = state.dataSize->FinalZoneSizing(state.dataSize->CurZoneEqNum).DesHeatVolFlow;
    7870            0 :             if (state.dataSize->ZoneHVACSizing(zoneHVACIndex).HeatingCapMethod == FractionOfAutosizedHeatingCapacity) {
    7871            0 :                 state.dataSize->DataFracOfAutosizedHeatingCapacity = state.dataSize->ZoneHVACSizing(zoneHVACIndex).ScaledHeatingCapacity;
    7872              :             }
    7873            0 :             errorsFound = false;
    7874            0 :             HeatingCapacitySizer sizerHeatingCapacity;
    7875            0 :             sizerHeatingCapacity.overrideSizingString(SizingString);
    7876            0 :             sizerHeatingCapacity.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    7877            0 :             state.dataSize->DataAutosizedHeatingCapacity = sizerHeatingCapacity.size(state, TempSize, errorsFound);
    7878            0 :             state.dataSize->DataFlowPerHeatingCapacity = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxHeatAirVolFlow;
    7879            0 :             SizingMethod = HeatingAirflowSizing; // either this isn't needed or needs to be assigned to EqSizing
    7880            0 :             PrintFlag = true;
    7881            0 :             TempSize = AutoSize;
    7882            0 :             errorsFound = false;
    7883            0 :             HeatingAirFlowSizer sizingHeatingAirFlow;
    7884            0 :             sizingHeatingAirFlow.overrideSizingString(SizingString);
    7885              :             // sizingHeatingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
    7886            0 :             sizingHeatingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    7887            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow = sizingHeatingAirFlow.size(state, TempSize, errorsFound);
    7888            0 :         }
    7889              :         // Multispeed Fan heating flow sizing
    7890            1 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating > 0) {
    7891            0 :             Real64 AirFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow;
    7892            0 :             for (int i = 1; i <= state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating; ++i) {
    7893            0 :                 if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex > -1) {
    7894            0 :                     if (state.dataUnitarySystems->designSpecMSHP[state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex]
    7895            0 :                             .heatingVolFlowRatio[i] == DataSizing::AutoSize) {
    7896            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] =
    7897            0 :                             double(i) / double(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating) * AirFlowRate;
    7898              :                     } else {
    7899            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] =
    7900            0 :                             state.dataUnitarySystems->designSpecMSHP[state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex]
    7901            0 :                                 .heatingVolFlowRatio[i] *
    7902              :                             AirFlowRate;
    7903              :                     }
    7904            0 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] =
    7905            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] * state.dataEnvrn->StdRhoAir;
    7906              :                 } else {
    7907            0 :                     auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex));
    7908            0 :                     assert(fanSystem != nullptr);
    7909            0 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] == 0.0 && !fanSystem->massFlowAtSpeed.empty()) {
    7910            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
    7911            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] =
    7912            0 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] / state.dataEnvrn->StdRhoAir;
    7913              :                     }
    7914              :                 }
    7915              :             }
    7916              :         }
    7917              : 
    7918            1 :         PrintFlag = true;
    7919            1 :         SAFMethod = state.dataSize->ZoneHVACSizing(zoneHVACIndex).NoCoolHeatSAFMethod;
    7920            1 :         EqSizing.SizingMethod(SizingMethod) = SAFMethod;
    7921            1 :         if ((SAFMethod == SupplyAirFlowRate) || (SAFMethod == FlowPerFloorArea) || (SAFMethod == FractionOfAutosizedHeatingAirflow) ||
    7922              :             (SAFMethod == FractionOfAutosizedCoolingAirflow)) {
    7923            1 :             if (SAFMethod == SupplyAirFlowRate) {
    7924            1 :                 if (state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow > 0.0) {
    7925            0 :                     EqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7926            0 :                     EqSizing.SystemAirFlow = true;
    7927              :                 }
    7928            1 :                 TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7929            0 :             } else if (SAFMethod == FlowPerFloorArea) {
    7930            0 :                 EqSizing.SystemAirFlow = true;
    7931            0 :                 EqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow *
    7932            0 :                                       state.dataHeatBal->Zone(state.dataSize->DataZoneNumber).FloorArea;
    7933            0 :                 TempSize = ZoneEqSizing(state.dataSize->CurZoneEqNum).AirVolFlow;
    7934            0 :                 state.dataSize->DataScalableSizingON = true;
    7935            0 :             } else if (SAFMethod == FractionOfAutosizedCoolingAirflow) {
    7936            0 :                 state.dataSize->DataFracOfAutosizedCoolingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7937            0 :                 state.dataSize->DataFracOfAutosizedHeatingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7938            0 :                 TempSize = AutoSize;
    7939            0 :                 state.dataSize->DataScalableSizingON = true;
    7940            0 :             } else if (SAFMethod == FractionOfAutosizedHeatingAirflow) {
    7941            0 :                 state.dataSize->DataFracOfAutosizedCoolingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7942            0 :                 state.dataSize->DataFracOfAutosizedHeatingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7943            0 :                 TempSize = AutoSize;
    7944            0 :                 state.dataSize->DataScalableSizingON = true;
    7945              :             } else {
    7946            0 :                 TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7947              :             }
    7948            1 :             CoolingAirFlowSizer sizingCoolingAirFlow;
    7949            1 :             std::string stringOverride = "No Cooling Supply Air Flow Rate [m3/s]";
    7950            1 :             if (state.dataGlobal->isEpJSON) {
    7951            0 :                 stringOverride = "no_cooling_supply_air_flow_rate [m3/s]";
    7952              :             }
    7953            1 :             sizingCoolingAirFlow.overrideSizingString(stringOverride);
    7954              :             // sizingCoolingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
    7955            1 :             sizingCoolingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    7956            1 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling > 0) {
    7957            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[1];
    7958            0 :                 sizingCoolingAirFlow.reportSizerOutput(state,
    7959              :                                                        sizingCoolingAirFlow.compType,
    7960              :                                                        sizingCoolingAirFlow.compName,
    7961            0 :                                                        "Design Size " + stringOverride,
    7962            0 :                                                        state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow);
    7963              :             } else {
    7964            1 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow = sizingCoolingAirFlow.size(state, TempSize, errorsFound);
    7965              :             }
    7966            1 :         }
    7967              : 
    7968            1 :         SizingMethod = HeatingAirflowSizing;
    7969            1 :         FieldNum = 4; // N4, \field Supply Air Flow Rate When No Heating is Needed
    7970            1 :         PrintFlag = true;
    7971            1 :         SizingString = state.dataHVACVarRefFlow->VRFTUNumericFields(VRFTUNum).FieldNames(FieldNum) + " [m3/s]";
    7972            1 :         SAFMethod = state.dataSize->ZoneHVACSizing(zoneHVACIndex).NoCoolHeatSAFMethod;
    7973            1 :         EqSizing.SizingMethod(SizingMethod) = SAFMethod;
    7974            1 :         if ((SAFMethod == SupplyAirFlowRate) || (SAFMethod == FlowPerFloorArea) || (SAFMethod == FractionOfAutosizedHeatingAirflow) ||
    7975              :             (SAFMethod == FractionOfAutosizedCoolingAirflow)) {
    7976            1 :             if (SAFMethod == SupplyAirFlowRate) {
    7977            1 :                 if (state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow > 0.0) {
    7978            0 :                     EqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7979            0 :                     EqSizing.SystemAirFlow = true;
    7980              :                 }
    7981            1 :                 TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7982            0 :             } else if (SAFMethod == FlowPerFloorArea) {
    7983            0 :                 EqSizing.SystemAirFlow = true;
    7984            0 :                 EqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow *
    7985            0 :                                       state.dataHeatBal->Zone(state.dataSize->DataZoneNumber).FloorArea;
    7986            0 :                 TempSize = ZoneEqSizing(state.dataSize->CurZoneEqNum).AirVolFlow;
    7987            0 :                 state.dataSize->DataScalableSizingON = true;
    7988            0 :             } else if (SAFMethod == FractionOfAutosizedHeatingAirflow) {
    7989            0 :                 state.dataSize->DataFracOfAutosizedCoolingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7990            0 :                 state.dataSize->DataFracOfAutosizedHeatingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7991            0 :                 TempSize = AutoSize;
    7992            0 :                 state.dataSize->DataScalableSizingON = true;
    7993            0 :             } else if (SAFMethod == FractionOfAutosizedCoolingAirflow) {
    7994            0 :                 state.dataSize->DataFracOfAutosizedCoolingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7995            0 :                 state.dataSize->DataFracOfAutosizedHeatingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    7996            0 :                 TempSize = AutoSize;
    7997            0 :                 state.dataSize->DataScalableSizingON = true;
    7998              :             } else {
    7999            0 :                 TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxNoCoolHeatAirVolFlow;
    8000              :             }
    8001            1 :             errorsFound = false;
    8002            1 :             HeatingAirFlowSizer sizingNoHeatingAirFlow;
    8003            1 :             sizingNoHeatingAirFlow.overrideSizingString(SizingString);
    8004              :             // sizingNoHeatingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
    8005            1 :             sizingNoHeatingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    8006            1 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating > 0) {
    8007            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[1];
    8008            0 :                 sizingNoHeatingAirFlow.reportSizerOutput(state,
    8009              :                                                          sizingNoHeatingAirFlow.compType,
    8010              :                                                          sizingNoHeatingAirFlow.compName,
    8011            0 :                                                          "Design Size " + SizingString,
    8012            0 :                                                          state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow);
    8013              :             } else {
    8014            1 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow = sizingNoHeatingAirFlow.size(state, TempSize, errorsFound);
    8015              :             }
    8016            1 :         }
    8017              : 
    8018              :         // initialize capacity sizing variables: cooling
    8019            3 :         initCapSizingVars(state,
    8020              :                           CoolingCapacitySizing,
    8021            1 :                           state.dataSize->ZoneHVACSizing(zoneHVACIndex).CoolingCapMethod,
    8022              :                           EqSizing.SizingMethod(SizingMethod),
    8023            1 :                           state.dataSize->ZoneHVACSizing(zoneHVACIndex).ScaledCoolingCapacity,
    8024            1 :                           EqSizing.CoolingCapacity,
    8025            1 :                           EqSizing.DesCoolingLoad,
    8026            1 :                           state.dataSize->DataScalableCapSizingON,
    8027            1 :                           state.dataSize->DataFracOfAutosizedCoolingCapacity);
    8028              : 
    8029              :         // initialize capacity sizing variables: heating
    8030            3 :         initCapSizingVars(state,
    8031              :                           HeatingCapacitySizing,
    8032            1 :                           state.dataSize->ZoneHVACSizing(zoneHVACIndex).HeatingCapMethod,
    8033              :                           EqSizing.SizingMethod(SizingMethod),
    8034            1 :                           state.dataSize->ZoneHVACSizing(zoneHVACIndex).ScaledHeatingCapacity,
    8035            1 :                           EqSizing.HeatingCapacity,
    8036            1 :                           EqSizing.DesHeatingLoad,
    8037            1 :                           state.dataSize->DataScalableCapSizingON,
    8038            1 :                           state.dataSize->DataFracOfAutosizedHeatingCapacity);
    8039              : 
    8040              :     } else {
    8041              :         // no scalable sizing method has been specified. Sizing proceeds using the method
    8042              :         // specified in the zoneHVAC object
    8043              : 
    8044           61 :         PrintFlag = true;
    8045              : 
    8046           61 :         TempSize = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow;
    8047           61 :         bool errorsFound = false;
    8048           61 :         CoolingAirFlowSizer sizingCoolingAirFlow;
    8049           61 :         std::string stringOverride = "Cooling Supply Air Flow Rate [m3/s]";
    8050           61 :         if (state.dataGlobal->isEpJSON) {
    8051            0 :             stringOverride = "cooling_supply_air_flow_rate [m3/s]";
    8052              :         }
    8053           61 :         sizingCoolingAirFlow.overrideSizingString(stringOverride);
    8054              :         // sizingCoolingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
    8055           61 :         sizingCoolingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    8056           61 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow = sizingCoolingAirFlow.size(state, TempSize, errorsFound);
    8057              :         // Multispeed Fan cooling flow sizing
    8058           61 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling > 0) {
    8059            2 :             Real64 AirFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow;
    8060            6 :             for (int i = 1; i <= state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling; ++i) {
    8061            4 :                 if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex > -1) {
    8062            2 :                     if (state.dataUnitarySystems->designSpecMSHP[state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex]
    8063            2 :                             .coolingVolFlowRatio[i] == DataSizing::AutoSize) {
    8064            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] =
    8065            2 :                             double(i) / double(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling) * AirFlowRate;
    8066              :                     } else {
    8067            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] =
    8068            0 :                             state.dataUnitarySystems->designSpecMSHP[state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex]
    8069            0 :                                 .coolingVolFlowRatio[i] *
    8070              :                             AirFlowRate;
    8071              :                     }
    8072            2 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] =
    8073            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] * state.dataEnvrn->StdRhoAir;
    8074              :                 } else {
    8075            2 :                     auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex));
    8076            2 :                     assert(fanSystem != nullptr);
    8077            2 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] == 0.0 && !fanSystem->massFlowAtSpeed.empty()) {
    8078            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
    8079            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[i] =
    8080            2 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolMassFlowRate[i] / state.dataEnvrn->StdRhoAir;
    8081              :                     }
    8082              :                 }
    8083              :             }
    8084              :         }
    8085              : 
    8086           61 :         FieldNum = 3; // N3, \field Supply Air Flow Rate During Heating Operation
    8087           61 :         SizingString = state.dataHVACVarRefFlow->VRFTUNumericFields(VRFTUNum).FieldNames(FieldNum) + " [m3/s]";
    8088           61 :         TempSize = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow;
    8089           61 :         errorsFound = false;
    8090           61 :         HeatingAirFlowSizer sizingHeatingAirFlow;
    8091           61 :         sizingHeatingAirFlow.overrideSizingString(SizingString);
    8092              :         // sizingHeatingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
    8093           61 :         sizingHeatingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    8094           61 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow = sizingHeatingAirFlow.size(state, TempSize, errorsFound);
    8095              :         // Multispeed Fan heating flow sizing
    8096           61 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating > 0) {
    8097            2 :             Real64 AirFlowRate = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow;
    8098            6 :             for (int i = 1; i <= state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating; ++i) {
    8099            4 :                 if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex > -1) {
    8100            2 :                     if (state.dataUnitarySystems->designSpecMSHP[state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex]
    8101            2 :                             .heatingVolFlowRatio[i] == DataSizing::AutoSize) {
    8102            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] =
    8103            2 :                             double(i) / double(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating) * AirFlowRate;
    8104              :                     } else {
    8105            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] =
    8106            0 :                             state.dataUnitarySystems->designSpecMSHP[state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex]
    8107            0 :                                 .heatingVolFlowRatio[i] *
    8108              :                             AirFlowRate;
    8109              :                     }
    8110            2 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] =
    8111            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] * state.dataEnvrn->StdRhoAir;
    8112              :                 } else {
    8113            2 :                     auto *fanSystem = dynamic_cast<Fans::FanSystem *>(state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex));
    8114            2 :                     assert(fanSystem != nullptr);
    8115            2 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] == 0.0 && !fanSystem->massFlowAtSpeed.empty()) {
    8116            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] = fanSystem->massFlowAtSpeed[i - 1];
    8117            2 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[i] =
    8118            2 :                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatMassFlowRate[i] / state.dataEnvrn->StdRhoAir;
    8119              :                     }
    8120              :                 }
    8121              :             }
    8122              :         }
    8123              : 
    8124           61 :         errorsFound = false;
    8125           61 :         SystemAirFlowSizer sizerSystemAirFlow;
    8126           61 :         std::string sizingString = "No Cooling Supply Air Flow Rate [m3/s]";
    8127           61 :         sizerSystemAirFlow.overrideSizingString(sizingString);
    8128           61 :         sizerSystemAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    8129           61 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling > 0) {
    8130            2 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[1];
    8131            6 :             sizerSystemAirFlow.reportSizerOutput(state,
    8132              :                                                  sizerSystemAirFlow.compType,
    8133              :                                                  sizerSystemAirFlow.compName,
    8134            2 :                                                  "Design Size " + sizingString,
    8135            2 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow);
    8136              :         } else {
    8137           59 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow =
    8138           59 :                 sizerSystemAirFlow.size(state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoCoolAirVolFlow, errorsFound);
    8139              :         }
    8140              : 
    8141           61 :         SystemAirFlowSizer sizerSystemAirFlow2;
    8142           61 :         sizingString = "No Heating Supply Air Flow Rate [m3/s]";
    8143           61 :         sizerSystemAirFlow2.overrideSizingString(sizingString);
    8144           61 :         sizerSystemAirFlow2.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    8145           61 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating > 0) {
    8146            2 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[1];
    8147            6 :             sizerSystemAirFlow.reportSizerOutput(state,
    8148              :                                                  sizerSystemAirFlow.compType,
    8149              :                                                  sizerSystemAirFlow.compName,
    8150            2 :                                                  "Design Size " + sizingString,
    8151            2 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow);
    8152              :         } else {
    8153           59 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow =
    8154           59 :                 sizerSystemAirFlow2.size(state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxNoHeatAirVolFlow, errorsFound);
    8155              :         }
    8156           61 :     }
    8157           62 :     IsAutoSize = false;
    8158           62 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow == AutoSize) {
    8159           37 :         IsAutoSize = true;
    8160              :     }
    8161           62 :     if (state.dataSize->CurZoneEqNum > 0) {
    8162           60 :         if (!IsAutoSize && !state.dataSize->ZoneSizingRunDone) { // Simulation continue
    8163            0 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow > 0.0) {
    8164            0 :                 BaseSizer::reportSizerOutput(state,
    8165            0 :                                              tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8166            0 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8167              :                                              "User-Specified Outdoor Air Flow Rate During Cooling Operation [m3/s]",
    8168            0 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow);
    8169              :             }
    8170              :         } else {
    8171           60 :             CheckZoneSizing(state, tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type], state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name);
    8172           60 :             CoolOutAirVolFlowDes =
    8173           60 :                 min(state.dataSize->FinalZoneSizing(state.dataSize->CurZoneEqNum).MinOA, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow);
    8174           60 :             if (CoolOutAirVolFlowDes < HVAC::SmallAirVolFlow) {
    8175            0 :                 CoolOutAirVolFlowDes = 0.0;
    8176              :             }
    8177              : 
    8178           60 :             if (IsAutoSize) {
    8179           35 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow = CoolOutAirVolFlowDes;
    8180           70 :                 BaseSizer::reportSizerOutput(state,
    8181           35 :                                              tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8182           35 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8183              :                                              "Design Size Outdoor Air Flow Rate During Cooling Operation [m3/s]",
    8184              :                                              CoolOutAirVolFlowDes);
    8185              :             } else {
    8186           25 :                 if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow > 0.0 && CoolOutAirVolFlowDes > 0.0) {
    8187            0 :                     CoolOutAirVolFlowUser = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow;
    8188            0 :                     BaseSizer::reportSizerOutput(state,
    8189            0 :                                                  tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8190            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8191              :                                                  "Design Size Outdoor Air Flow Rate During Cooling Operation [m3/s]",
    8192              :                                                  CoolOutAirVolFlowDes,
    8193              :                                                  "User-Specified Outdoor Air Flow Rate During Cooling Operation [m3/s]",
    8194              :                                                  CoolOutAirVolFlowUser);
    8195            0 :                     if (state.dataGlobal->DisplayExtraWarnings) {
    8196            0 :                         if ((std::abs(CoolOutAirVolFlowDes - CoolOutAirVolFlowUser) / CoolOutAirVolFlowUser) >
    8197            0 :                             state.dataSize->AutoVsHardSizingThreshold) {
    8198            0 :                             ShowMessage(state,
    8199            0 :                                         format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8200            0 :                                                tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8201            0 :                                                state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    8202            0 :                             ShowContinueError(
    8203              :                                 state,
    8204            0 :                                 format("User-Specified Outdoor Air Flow Rate During Cooling Operation of {:.5R} [m3/s]", CoolOutAirVolFlowUser));
    8205            0 :                             ShowContinueError(state,
    8206            0 :                                               format("differs from Design Size Outdoor Air Flow Rate During Cooling Operation of {:.5R} [m3/s]",
    8207              :                                                      CoolOutAirVolFlowDes));
    8208            0 :                             ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8209            0 :                             ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8210              :                         }
    8211              :                     }
    8212              :                 }
    8213              :             }
    8214              :         }
    8215              :     } else {
    8216            2 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow == DataSizing::AutoSize) {
    8217            2 :             if (state.dataAirSystemsData->PrimaryAirSystems(state.dataSize->CurSysNum).OASysExists) {
    8218            2 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow = 0.0;
    8219              :             } else {
    8220            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow =
    8221            0 :                     min(state.dataSize->FinalSysSizing(state.dataSize->CurSysNum).DesOutAirVolFlow,
    8222            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow);
    8223              :             }
    8224            4 :             BaseSizer::reportSizerOutput(state,
    8225            2 :                                          tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8226            2 :                                          state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8227              :                                          "Design Size Outdoor Air Flow Rate During Cooling Operation [m3/s]",
    8228            2 :                                          state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow);
    8229              :         }
    8230              :     }
    8231              : 
    8232           62 :     IsAutoSize = false;
    8233           62 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow == AutoSize) {
    8234           37 :         IsAutoSize = true;
    8235              :     }
    8236           62 :     if (state.dataSize->CurZoneEqNum > 0) {
    8237           60 :         if (!IsAutoSize && !state.dataSize->ZoneSizingRunDone) { // Simulation continue
    8238            0 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow > 0.0) {
    8239            0 :                 BaseSizer::reportSizerOutput(state,
    8240            0 :                                              tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8241            0 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8242              :                                              "Outdoor Air Flow Rate During Heating Operation [m3/s]",
    8243            0 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow);
    8244              :             }
    8245              :         } else {
    8246           60 :             CheckZoneSizing(state, tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type], state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name);
    8247           60 :             HeatOutAirVolFlowDes =
    8248           60 :                 min(state.dataSize->FinalZoneSizing(state.dataSize->CurZoneEqNum).MinOA, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow);
    8249           60 :             if (HeatOutAirVolFlowDes < HVAC::SmallAirVolFlow) {
    8250            0 :                 HeatOutAirVolFlowDes = 0.0;
    8251              :             }
    8252              : 
    8253           60 :             if (IsAutoSize) {
    8254           35 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow = HeatOutAirVolFlowDes;
    8255           70 :                 BaseSizer::reportSizerOutput(state,
    8256           35 :                                              tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8257           35 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8258              :                                              "Design Size Outdoor Air Flow Rate During Heating Operation [m3/s]",
    8259              :                                              HeatOutAirVolFlowDes);
    8260              :             } else {
    8261           25 :                 if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow > 0.0 && HeatOutAirVolFlowDes > 0.0) {
    8262            0 :                     HeatOutAirVolFlowUser = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow;
    8263            0 :                     BaseSizer::reportSizerOutput(state,
    8264            0 :                                                  tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8265            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8266              :                                                  "Design Size Outdoor Air Flow Rate During Heating Operation [m3/s]",
    8267              :                                                  HeatOutAirVolFlowDes,
    8268              :                                                  "User-Specified Outdoor Air Flow Rate During Heating Operation [m3/s]",
    8269              :                                                  HeatOutAirVolFlowUser);
    8270            0 :                     if (state.dataGlobal->DisplayExtraWarnings) {
    8271            0 :                         if ((std::abs(HeatOutAirVolFlowDes - HeatOutAirVolFlowUser) / HeatOutAirVolFlowUser) >
    8272            0 :                             state.dataSize->AutoVsHardSizingThreshold) {
    8273            0 :                             ShowMessage(state,
    8274            0 :                                         format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8275            0 :                                                tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8276            0 :                                                state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    8277            0 :                             ShowContinueError(
    8278              :                                 state,
    8279            0 :                                 format("User-Specified Outdoor Air Flow Rate During Heating Operation of {:.5R} [m3/s]", HeatOutAirVolFlowUser));
    8280            0 :                             ShowContinueError(state,
    8281            0 :                                               format("differs from Design Size Outdoor Air Flow Rate During Heating Operation of {:.5R} [m3/s]",
    8282              :                                                      HeatOutAirVolFlowDes));
    8283            0 :                             ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8284            0 :                             ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8285              :                         }
    8286              :                     }
    8287              :                 }
    8288              :             }
    8289              :         }
    8290              :     } else {
    8291            2 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow == DataSizing::AutoSize) {
    8292            2 :             if (state.dataAirSystemsData->PrimaryAirSystems(state.dataSize->CurSysNum).OASysExists) {
    8293            2 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow = 0.0;
    8294              :             } else {
    8295            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow =
    8296            0 :                     min(state.dataSize->FinalSysSizing(state.dataSize->CurSysNum).DesOutAirVolFlow,
    8297            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow);
    8298              :             }
    8299            4 :             BaseSizer::reportSizerOutput(state,
    8300            2 :                                          tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8301            2 :                                          state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8302              :                                          "Design Size Outdoor Air Flow Rate During Heating Operation [m3/s]",
    8303            2 :                                          state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow);
    8304              :         }
    8305              :     }
    8306           62 :     EqSizing.OAVolFlow =
    8307           62 :         max(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow);
    8308              : 
    8309           72 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerExists &&
    8310           10 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInZone) { // set up ATMixer conditions for use in component sizing
    8311           10 :         EqSizing.OAVolFlow = 0.0;                             // Equipment OA flow should always be 0 when ATMixer is used
    8312           30 :         SingleDuct::setATMixerSizingProperties(state,
    8313           10 :                                                state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerIndex,
    8314           10 :                                                state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum,
    8315           10 :                                                state.dataSize->CurZoneEqNum);
    8316              :     }
    8317              : 
    8318           62 :     IsAutoSize = false;
    8319           62 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow == AutoSize) {
    8320           36 :         IsAutoSize = true;
    8321              :     }
    8322           62 :     if (state.dataSize->CurZoneEqNum > 0) {
    8323           60 :         if (!IsAutoSize && !state.dataSize->ZoneSizingRunDone) { // Simulation continue
    8324            0 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow > 0.0) {
    8325            0 :                 BaseSizer::reportSizerOutput(state,
    8326            0 :                                              tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8327            0 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8328              :                                              "User-Specified Outdoor Air Flow Rate When No Cooling or Heating is Needed [m3/s]",
    8329            0 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow);
    8330              :             }
    8331              :         } else {
    8332           60 :             CheckZoneSizing(state, tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type], state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name);
    8333           60 :             NoCoolHeatOutAirVolFlowDes = min(state.dataSize->FinalZoneSizing(state.dataSize->CurZoneEqNum).MinOA,
    8334           60 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow,
    8335           60 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow);
    8336           60 :             if (NoCoolHeatOutAirVolFlowDes < HVAC::SmallAirVolFlow) {
    8337           25 :                 NoCoolHeatOutAirVolFlowDes = 0.0;
    8338              :             }
    8339              : 
    8340           60 :             if (IsAutoSize) {
    8341           34 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow = NoCoolHeatOutAirVolFlowDes;
    8342           68 :                 BaseSizer::reportSizerOutput(state,
    8343           34 :                                              tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8344           34 :                                              state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8345              :                                              "Design Size Outdoor Air Flow Rate When No Cooling or Heating is Needed [m3/s]",
    8346              :                                              NoCoolHeatOutAirVolFlowDes);
    8347              :             } else {
    8348           26 :                 if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow > 0.0 && NoCoolHeatOutAirVolFlowDes > 0.0) {
    8349            0 :                     NoCoolHeatOutAirVolFlowUser = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow;
    8350            0 :                     BaseSizer::reportSizerOutput(state,
    8351            0 :                                                  tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8352            0 :                                                  state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8353              :                                                  "Design Size Outdoor Air Flow Rate When No Cooling or Heating is Needed [m3/s]",
    8354              :                                                  NoCoolHeatOutAirVolFlowDes,
    8355              :                                                  "User-Specified Outdoor Air Flow Rate When No Cooling or Heating is Needed [m3/s]",
    8356              :                                                  NoCoolHeatOutAirVolFlowUser);
    8357            0 :                     if (state.dataGlobal->DisplayExtraWarnings) {
    8358            0 :                         if ((std::abs(NoCoolHeatOutAirVolFlowDes - NoCoolHeatOutAirVolFlowUser) / NoCoolHeatOutAirVolFlowUser) >
    8359            0 :                             state.dataSize->AutoVsHardSizingThreshold) {
    8360            0 :                             ShowMessage(state,
    8361            0 :                                         format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8362            0 :                                                tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8363            0 :                                                state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name));
    8364            0 :                             ShowContinueError(state,
    8365            0 :                                               format("User-Specified Outdoor Air Flow Rate When No Cooling or Heating is Needed of {:.5R} [m3/s]",
    8366              :                                                      NoCoolHeatOutAirVolFlowUser));
    8367            0 :                             ShowContinueError(
    8368              :                                 state,
    8369            0 :                                 format("differs from Design Size Outdoor Air Flow Rate When No Cooling or Heating is Needed of {:.5R} [m3/s]",
    8370              :                                        NoCoolHeatOutAirVolFlowDes));
    8371            0 :                             ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8372            0 :                             ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8373              :                         }
    8374              :                     }
    8375              :                 }
    8376              :             }
    8377              :         }
    8378              :     } else {
    8379            2 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow == DataSizing::AutoSize) {
    8380            2 :             if (state.dataAirSystemsData->PrimaryAirSystems(state.dataSize->CurSysNum).OASysExists) {
    8381            2 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow = 0.0;
    8382              :             } else {
    8383            0 :                 if (!(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedCooling > 0 &&
    8384            0 :                       state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NumOfSpeedHeating > 0)) {
    8385            0 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow =
    8386            0 :                         min(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow);
    8387              :                 } else {
    8388            0 :                     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSpecMSHPIndex > -1) {
    8389            0 :                         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow =
    8390            0 :                             min(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatVolumeFlowRate[1],
    8391            0 :                                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolVolumeFlowRate[1]);
    8392              :                     }
    8393              :                 }
    8394              :             }
    8395            4 :             BaseSizer::reportSizerOutput(state,
    8396            2 :                                          tuTypeNames[(int)state.dataHVACVarRefFlow->VRFTU(VRFTUNum).type],
    8397            2 :                                          state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name,
    8398              :                                          "Design Size Outdoor Air Flow Rate When No Cooling or Heating Heating is Needed [m3/s]",
    8399            2 :                                          state.dataHVACVarRefFlow->VRFTU(VRFTUNum).NoCoolHeatOutAirVolFlow);
    8400              :         }
    8401              :     }
    8402              : 
    8403           62 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatingCoilPresent) {
    8404           11 :         bool ErrorsFound = false;
    8405           11 :         TempSize = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxSATFromSuppHeatCoil;
    8406           11 :         MaxHeaterOutletTempSizer sizerMaxHeaterOutTemp;
    8407           11 :         std::string stringOverride = "Maximum Supply Air Temperature from Supplemental Heater [C]";
    8408           11 :         if (state.dataGlobal->isEpJSON) {
    8409            0 :             stringOverride = "maximum_supply_air_temperature_from_supplemental_heater [C]";
    8410              :         }
    8411           11 :         sizerMaxHeaterOutTemp.overrideSizingString(stringOverride);
    8412           11 :         sizerMaxHeaterOutTemp.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    8413           11 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxSATFromSuppHeatCoil = sizerMaxHeaterOutTemp.size(state, TempSize, ErrorsFound);
    8414           11 :     }
    8415              : 
    8416           62 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType_Num == HVAC::Coil_HeatingWater) {
    8417            2 :         bool ErrorsFound = false;
    8418            2 :         WaterCoils::SetCoilDesFlow(state,
    8419            2 :                                    state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType,
    8420            2 :                                    state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
    8421            2 :                                    state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow,
    8422              :                                    ErrorsFound);
    8423              :     }
    8424              : 
    8425           62 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatingCoilPresent) {
    8426           11 :         CompType = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType;
    8427           11 :         CompName = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName;
    8428           11 :         PrintFlag = false; // why isn't this being reported?
    8429           11 :         TempSize = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSuppHeatingCapacity;
    8430           11 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilType_Num == HVAC::Coil_HeatingWater) {
    8431              :             // sizing result should always be reported
    8432            2 :             if (TempSize == DataSizing::AutoSize) {
    8433            0 :                 WaterHeatingCapacitySizer sizerWaterHeatingCapacity;
    8434            0 :                 bool ErrorsFound = false;
    8435            0 :                 std::string stringOverride = "Supplemental Heating Coil Nominal Capacity [W]";
    8436            0 :                 if (state.dataGlobal->isEpJSON) {
    8437            0 :                     stringOverride = "supplemental_heating_coil_nominal_capacity [W]";
    8438              :                 }
    8439            0 :                 sizerWaterHeatingCapacity.overrideSizingString(stringOverride);
    8440            0 :                 sizerWaterHeatingCapacity.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    8441            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSuppHeatingCapacity = sizerWaterHeatingCapacity.size(state, TempSize, ErrorsFound);
    8442            0 :             }
    8443              :         } else {
    8444            9 :             SizingString = "Supplemental Heating Coil Nominal Capacity [W]";
    8445            9 :             if (TempSize == DataSizing::AutoSize) {
    8446            7 :                 bool errorsFound = false;
    8447            7 :                 HeatingCapacitySizer sizerHeatingCapacity;
    8448            7 :                 sizerHeatingCapacity.overrideSizingString(SizingString);
    8449            7 :                 sizerHeatingCapacity.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
    8450            7 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).DesignSuppHeatingCapacity = sizerHeatingCapacity.size(state, TempSize, errorsFound);
    8451            7 :             }
    8452              :         }
    8453              :     }
    8454              : 
    8455           62 :     EqSizing.CoolingAirFlow = true;
    8456           62 :     EqSizing.CoolingAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxCoolAirVolFlow;
    8457           62 :     EqSizing.HeatingAirFlow = true;
    8458           62 :     EqSizing.HeatingAirVolFlow = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).MaxHeatAirVolFlow;
    8459              : 
    8460           62 :     if (CheckVRFCombinationRatio(VRFCond)) {
    8461           62 :         OnOffAirFlowRat = 1.0;
    8462              :         // set up the outside air data for sizing the DX coils
    8463           62 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInZone) {
    8464           60 :             state.dataSize->ZoneEqDXCoil = true;
    8465              :         }
    8466           62 :         if (state.dataSize->CurZoneEqNum > 0) {
    8467           85 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow > 0.0 ||
    8468           25 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow > 0.0) {
    8469           35 :                 EqSizing.OAVolFlow =
    8470           35 :                     max(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolOutAirVolFlow, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatOutAirVolFlow);
    8471              :             } else {
    8472           25 :                 EqSizing.OAVolFlow = 0.0;
    8473              :             }
    8474              :         } else {
    8475            2 :             EqSizing.OAVolFlow = 0.0;
    8476              :         }
    8477              : 
    8478           62 :         Real64 SuppHeatCoilLoad = 0.0;
    8479              :         // simulate the TU to size the coils
    8480           62 :         if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    8481              :             // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    8482           16 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
    8483              :                 state, VRFTUNum, true, 0.0, TUCoolingCapacity, OnOffAirFlowRat, SuppHeatCoilLoad);
    8484              :         } else {
    8485              :             // Algorithm Type: VRF model based on system curve
    8486           46 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(state, VRFTUNum, true, 0.0, TUCoolingCapacity, OnOffAirFlowRat, SuppHeatCoilLoad);
    8487              :         }
    8488              : 
    8489              :         //    ZoneEqDXCoil = .FALSE.
    8490           62 :         TUCoolingCapacity = 0.0;
    8491           62 :         TUHeatingCapacity = 0.0;
    8492           62 :         bool FoundAll = true;
    8493              :         bool errFlag; // temporary variable used for error checking
    8494           62 :         int TUListNum = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TUListIndex;
    8495          204 :         for (int NumTU = 1; NumTU <= state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList; ++NumTU) {
    8496          190 :             int TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
    8497          190 :             if (state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolCoilIndex > 0) {
    8498          570 :                 DXCoilCap = DXCoils::GetCoilCapacityByIndexType(state,
    8499          190 :                                                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolCoilIndex,
    8500          190 :                                                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).DXCoolCoilType_Num,
    8501              :                                                                 errFlag);
    8502          190 :                 TUCoolingCapacity += DXCoilCap;
    8503          190 :                 if (DXCoilCap == AutoSize) {
    8504           48 :                     FoundAll = false;
    8505           48 :                     break;
    8506              :                 }
    8507              :             }
    8508          142 :             if (state.dataHVACVarRefFlow->VRFTU(TUIndex).HeatCoilIndex > 0) {
    8509          426 :                 DXCoilCap = DXCoils::GetCoilCapacityByIndexType(state,
    8510          142 :                                                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).HeatCoilIndex,
    8511          142 :                                                                 state.dataHVACVarRefFlow->VRFTU(TUIndex).DXHeatCoilType_Num,
    8512              :                                                                 errFlag);
    8513          142 :                 TUHeatingCapacity += DXCoilCap;
    8514          142 :                 if (DXCoilCap == AutoSize) {
    8515            0 :                     FoundAll = false;
    8516            0 :                     break;
    8517              :                 }
    8518              :             }
    8519              :         }
    8520              : 
    8521           62 :         if (FoundAll && (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::SysCurve)) {
    8522              :             // Size VRF rated cooling/heating capacity (VRF-SysCurve Model)
    8523              : 
    8524              :             // Size VRF( VRFCond ).CoolingCapacity
    8525           10 :             IsAutoSize = false;
    8526           10 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity == AutoSize) {
    8527           10 :                 IsAutoSize = true;
    8528              :             }
    8529           10 :             CoolingCapacityDes = TUCoolingCapacity;
    8530           10 :             if (IsAutoSize) {
    8531           10 :                 state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity = CoolingCapacityDes;
    8532           30 :                 BaseSizer::reportSizerOutput(state,
    8533           30 :                                              std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8534           10 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8535              :                                              "Design Size Rated Total Cooling Capacity (gross) [W]",
    8536              :                                              CoolingCapacityDes);
    8537              :             } else {
    8538            0 :                 if (state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity > 0.0 && CoolingCapacityDes > 0.0) {
    8539            0 :                     CoolingCapacityUser = state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity;
    8540            0 :                     BaseSizer::reportSizerOutput(state,
    8541            0 :                                                  std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8542            0 :                                                  state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8543              :                                                  "Design Size Rated Total Cooling Capacity (gross) [W]",
    8544              :                                                  CoolingCapacityDes,
    8545              :                                                  "User-Specified Rated Total Cooling Capacity (gross) [W]",
    8546              :                                                  CoolingCapacityUser);
    8547            0 :                     if (state.dataGlobal->DisplayExtraWarnings) {
    8548            0 :                         if ((std::abs(CoolingCapacityDes - CoolingCapacityUser) / CoolingCapacityUser) > state.dataSize->AutoVsHardSizingThreshold) {
    8549            0 :                             ShowMessage(state,
    8550            0 :                                         format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8551            0 :                                                cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    8552            0 :                                                state.dataHVACVarRefFlow->VRFTU(VRFCond).Name));
    8553            0 :                             ShowContinueError(state,
    8554            0 :                                               format("User-Specified Rated Total Cooling Capacity (gross) of {:.2R} [W]", CoolingCapacityUser));
    8555            0 :                             ShowContinueError(
    8556            0 :                                 state, format("differs from Design Size Rated Total Cooling Capacity (gross) of {:.2R} [W]", CoolingCapacityDes));
    8557            0 :                             ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8558            0 :                             ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8559              :                         }
    8560              :                     }
    8561              :                 }
    8562              :             }
    8563              : 
    8564           10 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity > 0.0) {
    8565           10 :                 state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCombinationRatio =
    8566           10 :                     TUCoolingCapacity / state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity;
    8567              :             }
    8568              : 
    8569              :             // Size VRF( VRFCond ).HeatingCapacity
    8570           10 :             IsAutoSize = false;
    8571           10 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacity == AutoSize) {
    8572           10 :                 IsAutoSize = true;
    8573              :             }
    8574           10 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).LockHeatingCapacity) {
    8575            2 :                 HeatingCapacityDes =
    8576            2 :                     state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity * state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacitySizeRatio;
    8577              :             } else {
    8578            8 :                 HeatingCapacityDes = TUHeatingCapacity;
    8579              :             }
    8580           10 :             if (IsAutoSize) {
    8581           10 :                 state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacity = HeatingCapacityDes;
    8582           30 :                 BaseSizer::reportSizerOutput(state,
    8583           30 :                                              std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8584           10 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8585              :                                              "Design Size Rated Total Heating Capacity [W]",
    8586              :                                              HeatingCapacityDes);
    8587              :             } else {
    8588            0 :                 if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacity > 0.0 && HeatingCapacityDes > 0.0) {
    8589            0 :                     HeatingCapacityUser = state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacity;
    8590            0 :                     BaseSizer::reportSizerOutput(state,
    8591            0 :                                                  std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8592            0 :                                                  state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8593              :                                                  "Design Size Rated Total Heating Capacity [W]",
    8594              :                                                  HeatingCapacityDes,
    8595              :                                                  "User-Specified Rated Total Heating Capacity [W]",
    8596              :                                                  HeatingCapacityUser);
    8597            0 :                     if (state.dataGlobal->DisplayExtraWarnings) {
    8598            0 :                         if ((std::abs(HeatingCapacityDes - HeatingCapacityUser) / HeatingCapacityUser) > state.dataSize->AutoVsHardSizingThreshold) {
    8599            0 :                             ShowMessage(state,
    8600            0 :                                         format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8601            0 :                                                cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    8602            0 :                                                state.dataHVACVarRefFlow->VRFTU(VRFCond).Name));
    8603            0 :                             ShowContinueError(state, format("User-Specified Rated Total Heating Capacity of {:.2R} [W]", HeatingCapacityUser));
    8604            0 :                             ShowContinueError(state,
    8605            0 :                                               format("differs from Design Size Rated Total Heating Capacity of {:.2R} [W]", HeatingCapacityDes));
    8606            0 :                             ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8607            0 :                             ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8608              :                         }
    8609              :                     }
    8610              :                 }
    8611              :             }
    8612              : 
    8613           10 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacity > 0.0) {
    8614           10 :                 state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCombinationRatio =
    8615           10 :                     TUHeatingCapacity / state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacity;
    8616              :             }
    8617              : 
    8618              :             // calculate the piping correction factors only once
    8619           10 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).PCFLengthCoolPtr > 0) {
    8620              :                 {
    8621           10 :                     if (state.dataCurveManager->curves(state.dataHVACVarRefFlow->VRF(VRFCond).PCFLengthCoolPtr)->numDims == 2) {
    8622           10 :                         state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionCooling =
    8623           10 :                             min(1.0,
    8624              :                                 max(0.5,
    8625           40 :                                     CurveValue(state,
    8626           10 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).PCFLengthCoolPtr,
    8627           10 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).EquivPipeLngthCool,
    8628           10 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCombinationRatio) +
    8629           10 :                                         state.dataHVACVarRefFlow->VRF(VRFCond).VertPipeLngth * state.dataHVACVarRefFlow->VRF(VRFCond).PCFHeightCool));
    8630              :                     } else {
    8631            0 :                         state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionCooling =
    8632            0 :                             min(1.0,
    8633              :                                 max(0.5,
    8634            0 :                                     CurveValue(state,
    8635            0 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).PCFLengthCoolPtr,
    8636            0 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).EquivPipeLngthCool) +
    8637            0 :                                         state.dataHVACVarRefFlow->VRF(VRFCond).VertPipeLngth * state.dataHVACVarRefFlow->VRF(VRFCond).PCFHeightCool));
    8638              :                     }
    8639              :                 }
    8640              :             } else {
    8641            0 :                 state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionCooling = min(
    8642              :                     1.0,
    8643            0 :                     max(0.5, (1.0 + state.dataHVACVarRefFlow->VRF(VRFCond).VertPipeLngth * state.dataHVACVarRefFlow->VRF(VRFCond).PCFHeightCool)));
    8644              :             }
    8645              : 
    8646           10 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).PCFLengthHeatPtr > 0) {
    8647              :                 {
    8648            0 :                     if (state.dataCurveManager->curves(state.dataHVACVarRefFlow->VRF(VRFCond).PCFLengthHeatPtr)->numDims == 2) {
    8649            0 :                         state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionHeating =
    8650            0 :                             min(1.0,
    8651              :                                 max(0.5,
    8652            0 :                                     CurveValue(state,
    8653            0 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).PCFLengthHeatPtr,
    8654            0 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).EquivPipeLngthHeat,
    8655            0 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCombinationRatio) +
    8656            0 :                                         state.dataHVACVarRefFlow->VRF(VRFCond).VertPipeLngth * state.dataHVACVarRefFlow->VRF(VRFCond).PCFHeightHeat));
    8657              :                     } else {
    8658            0 :                         state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionHeating =
    8659            0 :                             min(1.0,
    8660              :                                 max(0.5,
    8661            0 :                                     CurveValue(state,
    8662            0 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).PCFLengthHeatPtr,
    8663            0 :                                                state.dataHVACVarRefFlow->VRF(VRFCond).EquivPipeLngthHeat) +
    8664            0 :                                         state.dataHVACVarRefFlow->VRF(VRFCond).VertPipeLngth * state.dataHVACVarRefFlow->VRF(VRFCond).PCFHeightHeat));
    8665              :                     }
    8666              :                 }
    8667              :             } else {
    8668           10 :                 state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionHeating = min(
    8669              :                     1.0,
    8670           10 :                     max(0.5, (1.0 + state.dataHVACVarRefFlow->VRF(VRFCond).VertPipeLngth * state.dataHVACVarRefFlow->VRF(VRFCond).PCFHeightHeat)));
    8671              :             }
    8672              : 
    8673           10 :             state.dataHVACVarRefFlow->VRF(VRFCond).RatedCoolingPower =
    8674           10 :                 state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity / state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCOP;
    8675           10 :             state.dataHVACVarRefFlow->VRF(VRFCond).RatedHeatingPower =
    8676           10 :                 state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacity / state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCOP;
    8677              : 
    8678           10 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).CoolCombRatioPTR > 0) {
    8679           10 :                 state.dataHVACVarRefFlow->CoolCombinationRatio(VRFCond) = CurveValue(
    8680           10 :                     state, state.dataHVACVarRefFlow->VRF(VRFCond).CoolCombRatioPTR, state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCombinationRatio);
    8681              :             } else {
    8682            0 :                 state.dataHVACVarRefFlow->CoolCombinationRatio(VRFCond) = 1.0;
    8683              :             }
    8684              : 
    8685           10 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatCombRatioPTR > 0) {
    8686           10 :                 state.dataHVACVarRefFlow->HeatCombinationRatio(VRFCond) = CurveValue(
    8687           10 :                     state, state.dataHVACVarRefFlow->VRF(VRFCond).HeatCombRatioPTR, state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCombinationRatio);
    8688              :             } else {
    8689            0 :                 state.dataHVACVarRefFlow->HeatCombinationRatio(VRFCond) = 1.0;
    8690              :             }
    8691              :         }
    8692              : 
    8693           62 :         if (FoundAll && (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl)) {
    8694              :             // Size VRF rated evaporative capacity (VRF-FluidTCtrl Model)
    8695              :             // Set piping correction factors to 1.0 here for reporting to eio output - recalculated every time step in
    8696              :             // VRFCondenserEquipment::CalcVRFCondenser_FluidTCtrl
    8697            4 :             state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionCooling = 1.0;
    8698            4 :             state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionHeating = 1.0;
    8699              : 
    8700              :             // Size VRF( VRFCond ).RatedEvapCapacity
    8701            4 :             IsAutoSize = false;
    8702            4 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).RatedEvapCapacity == AutoSize) {
    8703            2 :                 IsAutoSize = true;
    8704              :             }
    8705              : 
    8706            4 :             CoolingCapacityDes = TUCoolingCapacity;
    8707            4 :             HeatingCapacityDes = TUHeatingCapacity;
    8708              : 
    8709            4 :             if (IsAutoSize) {
    8710              :                 // RatedEvapCapacity
    8711            2 :                 state.dataHVACVarRefFlow->VRF(VRFCond).RatedEvapCapacity =
    8712            2 :                     max(CoolingCapacityDes, HeatingCapacityDes / (1 + state.dataHVACVarRefFlow->VRF(VRFCond).RatedCompPowerPerCapcity));
    8713              : 
    8714              :                 // Other parameters dependent on RatedEvapCapacity
    8715            2 :                 state.dataHVACVarRefFlow->VRF(VRFCond).RatedCompPower =
    8716            2 :                     state.dataHVACVarRefFlow->VRF(VRFCond).RatedCompPowerPerCapcity * state.dataHVACVarRefFlow->VRF(VRFCond).RatedEvapCapacity;
    8717            2 :                 state.dataHVACVarRefFlow->VRF(VRFCond).RatedOUFanPower =
    8718            2 :                     state.dataHVACVarRefFlow->VRF(VRFCond).RatedOUFanPowerPerCapcity * state.dataHVACVarRefFlow->VRF(VRFCond).RatedEvapCapacity;
    8719            2 :                 state.dataHVACVarRefFlow->VRF(VRFCond).OUAirFlowRate =
    8720            2 :                     state.dataHVACVarRefFlow->VRF(VRFCond).OUAirFlowRatePerCapcity * state.dataHVACVarRefFlow->VRF(VRFCond).RatedEvapCapacity;
    8721              : 
    8722            2 :                 state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity = state.dataHVACVarRefFlow->VRF(VRFCond).RatedEvapCapacity;
    8723            2 :                 state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacity =
    8724            2 :                     state.dataHVACVarRefFlow->VRF(VRFCond).RatedEvapCapacity * (1 + state.dataHVACVarRefFlow->VRF(VRFCond).RatedCompPowerPerCapcity);
    8725              : 
    8726            6 :                 BaseSizer::reportSizerOutput(state,
    8727            6 :                                              std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8728            2 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8729              :                                              "Design Size Rated Total Heating Capacity [W]",
    8730            2 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCapacity);
    8731            6 :                 BaseSizer::reportSizerOutput(state,
    8732            6 :                                              std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8733            2 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8734              :                                              "Design Size Rated Total Cooling Capacity (gross) [W]",
    8735            2 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity);
    8736              :             } else {
    8737            2 :                 CoolingCapacityUser = state.dataHVACVarRefFlow->VRF(VRFCond).RatedEvapCapacity;
    8738            2 :                 HeatingCapacityUser = state.dataHVACVarRefFlow->VRF(VRFCond).RatedHeatCapacity;
    8739              : 
    8740            6 :                 BaseSizer::reportSizerOutput(state,
    8741            6 :                                              std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8742            2 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8743              :                                              "Design Size Rated Total Cooling Capacity (gross) [W]",
    8744              :                                              CoolingCapacityDes,
    8745              :                                              "User-Specified Rated Total Cooling Capacity (gross) [W]",
    8746              :                                              CoolingCapacityUser);
    8747            6 :                 BaseSizer::reportSizerOutput(state,
    8748            6 :                                              std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8749            2 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8750              :                                              "Design Size Rated Total Heating Capacity [W]",
    8751              :                                              HeatingCapacityDes,
    8752              :                                              "User-Specified Rated Total Heating Capacity [W]",
    8753              :                                              HeatingCapacityUser);
    8754              : 
    8755            2 :                 if (state.dataGlobal->DisplayExtraWarnings) {
    8756            1 :                     if ((std::abs(CoolingCapacityDes - CoolingCapacityUser) / CoolingCapacityUser) > state.dataSize->AutoVsHardSizingThreshold) {
    8757            2 :                         ShowMessage(state,
    8758            2 :                                     format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8759            1 :                                            cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    8760            1 :                                            state.dataHVACVarRefFlow->VRFTU(VRFCond).Name));
    8761            1 :                         ShowContinueError(state, format("User-Specified Rated Total Cooling Capacity (gross) of {:.2R} [W]", CoolingCapacityUser));
    8762            2 :                         ShowContinueError(state,
    8763            2 :                                           format("differs from Design Size Rated Total Cooling Capacity (gross) of {:.2R} [W]", CoolingCapacityDes));
    8764            2 :                         ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8765            3 :                         ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8766              :                     }
    8767              : 
    8768            1 :                     if ((std::abs(HeatingCapacityDes - HeatingCapacityUser) / HeatingCapacityUser) > state.dataSize->AutoVsHardSizingThreshold) {
    8769            2 :                         ShowMessage(state,
    8770            2 :                                     format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8771            1 :                                            cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    8772            1 :                                            state.dataHVACVarRefFlow->VRFTU(VRFCond).Name));
    8773            1 :                         ShowContinueError(state, format("User-Specified Rated Total Heating Capacity of {:.2R} [W]", HeatingCapacityUser));
    8774            1 :                         ShowContinueError(state, format("differs from Design Size Rated Total Heating Capacity of {:.2R} [W]", HeatingCapacityDes));
    8775            2 :                         ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8776            3 :                         ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8777              :                     }
    8778              :                 }
    8779              :             }
    8780              :         }
    8781              : 
    8782           62 :         if (FoundAll) {
    8783              :             // autosize resistive defrost heater capacity
    8784           14 :             IsAutoSize = false;
    8785           14 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).DefrostCapacity == AutoSize) {
    8786            8 :                 IsAutoSize = true;
    8787              :             }
    8788           14 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).DefrostStrategy == StandardRatings::DefrostStrat::Resistive) {
    8789           10 :                 DefrostCapacityDes = state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity;
    8790              :             } else {
    8791            4 :                 DefrostCapacityDes = 0.0;
    8792              :             }
    8793           14 :             if (IsAutoSize) {
    8794            8 :                 state.dataHVACVarRefFlow->VRF(VRFCond).DefrostCapacity = DefrostCapacityDes;
    8795           24 :                 BaseSizer::reportSizerOutput(state,
    8796           24 :                                              std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8797            8 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8798              :                                              "Design Size Resistive Defrost Heater Capacity [W]",
    8799              :                                              DefrostCapacityDes);
    8800              :             } else {
    8801            6 :                 if (state.dataHVACVarRefFlow->VRF(VRFCond).DefrostCapacity > 0.0 && DefrostCapacityDes > 0.0) {
    8802            2 :                     DefrostCapacityUser = state.dataHVACVarRefFlow->VRF(VRFCond).DefrostCapacity;
    8803            6 :                     BaseSizer::reportSizerOutput(state,
    8804            6 :                                                  std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8805            2 :                                                  state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8806              :                                                  "Design Size Resistive Defrost Heater Capacity [W]",
    8807              :                                                  DefrostCapacityDes,
    8808              :                                                  "User-Specified Resistive Defrost Heater Capacity",
    8809              :                                                  DefrostCapacityUser);
    8810            2 :                     if (state.dataGlobal->DisplayExtraWarnings) {
    8811            0 :                         if ((std::abs(DefrostCapacityDes - DefrostCapacityUser) / DefrostCapacityUser) > state.dataSize->AutoVsHardSizingThreshold) {
    8812            0 :                             ShowMessage(state,
    8813            0 :                                         format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8814            0 :                                                cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    8815            0 :                                                state.dataHVACVarRefFlow->VRFTU(VRFCond).Name));
    8816            0 :                             ShowContinueError(state, format("User-Specified Resistive Defrost Heater Capacity of {:.2R} [W]", DefrostCapacityUser));
    8817            0 :                             ShowContinueError(state,
    8818            0 :                                               format("differs from Design Size Resistive Defrost Heater Capacity of {:.2R} [W]", DefrostCapacityDes));
    8819            0 :                             ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8820            0 :                             ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8821              :                         }
    8822              :                     }
    8823              :                 }
    8824              :             }
    8825              : 
    8826           14 :             IsAutoSize = false;
    8827           14 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondAirVolFlowRate == AutoSize) {
    8828            2 :                 IsAutoSize = true;
    8829              :             }
    8830              :             // Auto-size condenser air flow to Total Capacity * 0.000114 m3/s/w (850 cfm/ton)
    8831           14 :             EvapCondAirVolFlowRateDes = state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity * 0.000114;
    8832           14 :             if (IsAutoSize) {
    8833            2 :                 state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondAirVolFlowRate = EvapCondAirVolFlowRateDes;
    8834            6 :                 BaseSizer::reportSizerOutput(state,
    8835            6 :                                              std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8836            2 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8837              :                                              "Design Size Evaporative Condenser Air Flow Rate [m3/s]",
    8838              :                                              EvapCondAirVolFlowRateDes);
    8839              :             } else {
    8840           12 :                 if (state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondAirVolFlowRate > 0.0 && EvapCondAirVolFlowRateDes > 0.0) {
    8841            0 :                     EvapCondAirVolFlowRateUser = state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondAirVolFlowRate;
    8842            0 :                     BaseSizer::reportSizerOutput(state,
    8843            0 :                                                  std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8844            0 :                                                  state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8845              :                                                  "Design Size Evaporative Condenser Air Flow Rate [m3/s]",
    8846              :                                                  EvapCondAirVolFlowRateDes,
    8847              :                                                  "User-Specified Evaporative Condenser Air Flow Rate [m3/s]",
    8848              :                                                  EvapCondAirVolFlowRateUser);
    8849            0 :                     if (state.dataGlobal->DisplayExtraWarnings) {
    8850            0 :                         if ((std::abs(EvapCondAirVolFlowRateDes - EvapCondAirVolFlowRateUser) / EvapCondAirVolFlowRateUser) >
    8851            0 :                             state.dataSize->AutoVsHardSizingThreshold) {
    8852            0 :                             ShowMessage(state,
    8853            0 :                                         format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8854            0 :                                                cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    8855            0 :                                                state.dataHVACVarRefFlow->VRFTU(VRFCond).Name));
    8856            0 :                             ShowContinueError(
    8857            0 :                                 state, format("User-Specified Evaporative Condenser Air Flow Rate of {:.5R} [m3/s]", EvapCondAirVolFlowRateUser));
    8858            0 :                             ShowContinueError(
    8859              :                                 state,
    8860            0 :                                 format("differs from Design Size Evaporative Condenser Air Flow Rate of {:.5R} [m3/s]", EvapCondAirVolFlowRateDes));
    8861            0 :                             ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8862            0 :                             ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8863              :                         }
    8864              :                     }
    8865              :                 }
    8866              :             }
    8867              : 
    8868           14 :             IsAutoSize = false;
    8869           14 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondPumpPower == AutoSize) {
    8870            0 :                 IsAutoSize = true;
    8871              :             }
    8872              :             // Auto-size evap condenser pump power to Total Capacity * 0.004266 w/w (15 w/ton)
    8873           14 :             EvapCondPumpPowerDes = state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCapacity * 0.004266;
    8874           14 :             if (IsAutoSize) {
    8875            0 :                 state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondPumpPower = EvapCondPumpPowerDes;
    8876            0 :                 BaseSizer::reportSizerOutput(state,
    8877            0 :                                              std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8878            0 :                                              state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8879              :                                              "Design Size Evaporative Condenser Pump Rated Power Consumption [W]",
    8880              :                                              EvapCondPumpPowerDes);
    8881              : 
    8882              :             } else {
    8883           14 :                 if (state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondPumpPower > 0.0 && EvapCondPumpPowerDes > 0.0) {
    8884            0 :                     EvapCondPumpPowerUser = state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondPumpPower;
    8885            0 :                     BaseSizer::reportSizerOutput(state,
    8886            0 :                                                  std::string(cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum)),
    8887            0 :                                                  state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8888              :                                                  "Design Size Evaporative Condenser Pump Rated Power Consumption [W]",
    8889              :                                                  EvapCondPumpPowerDes,
    8890              :                                                  "User-Specified Evaporative Condenser Pump Rated Power Consumption [W]",
    8891              :                                                  EvapCondPumpPowerUser);
    8892            0 :                     if (state.dataGlobal->DisplayExtraWarnings) {
    8893            0 :                         if ((std::abs(EvapCondPumpPowerDes - EvapCondPumpPowerUser) / EvapCondPumpPowerUser) >
    8894            0 :                             state.dataSize->AutoVsHardSizingThreshold) {
    8895            0 :                             ShowMessage(state,
    8896            0 :                                         format("SizeVRF: Potential issue with equipment sizing for {} {}",
    8897            0 :                                                cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    8898            0 :                                                state.dataHVACVarRefFlow->VRFTU(VRFCond).Name));
    8899            0 :                             ShowContinueError(
    8900              :                                 state,
    8901            0 :                                 format("User-Specified Evaporative Condenser Pump Rated Power Consumption of {:.2R} [W]", EvapCondPumpPowerUser));
    8902            0 :                             ShowContinueError(state,
    8903            0 :                                               format("differs from Design Size Evaporative Condenser Pump Rated Power Consumption of {:.2R} [W]",
    8904              :                                                      EvapCondPumpPowerDes));
    8905            0 :                             ShowContinueError(state, "This may, or may not, indicate mismatched component sizes.");
    8906            0 :                             ShowContinueError(state, "Verify that the value entered is intended and is consistent with other components.");
    8907              :                         }
    8908              :                     }
    8909              :                 }
    8910              :             }
    8911              : 
    8912              :             // Report to eio other information not related to autosizing
    8913           14 :             if (state.dataHVACVarRefFlow->MyOneTimeEIOFlag) {
    8914              :                 static constexpr std::string_view Format_990(
    8915              :                     "! <VRF System Information>, VRF System Type, VRF System Name, VRF System Cooling Combination Ratio, VRF "
    8916              :                     "System Heating Combination Ratio, VRF System Cooling Piping Correction Factor, VRF System Heating Piping "
    8917              :                     "Correction Factor\n");
    8918           13 :                 print(state.files.eio, Format_990);
    8919           13 :                 state.dataHVACVarRefFlow->MyOneTimeEIOFlag = false;
    8920              :             }
    8921              :             static constexpr std::string_view Format_991(" VRF System Information, {}, {}, {:.5R}, {:.5R}, {:.5R}, {:.5R}\n");
    8922           14 :             print(state.files.eio,
    8923              :                   Format_991,
    8924           14 :                   cVRFTypes(state.dataHVACVarRefFlow->VRF(VRFCond).VRFSystemTypeNum),
    8925           14 :                   state.dataHVACVarRefFlow->VRF(VRFCond).Name,
    8926           14 :                   state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCombinationRatio,
    8927           14 :                   state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCombinationRatio,
    8928           14 :                   state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionCooling,
    8929           14 :                   state.dataHVACVarRefFlow->VRF(VRFCond).PipingCorrectionHeating);
    8930              : 
    8931           14 :             CheckVRFCombinationRatio(VRFCond) = false;
    8932              :         }
    8933              :     }
    8934              : 
    8935           62 :     state.dataSize->DataScalableCapSizingON = false;
    8936           62 : }
    8937              : 
    8938            2 : void initCapSizingVars(EnergyPlusData &state,
    8939              :                        int sizingMethod,
    8940              :                        int capSizingMethod,
    8941              :                        int &eqSizingMethod,
    8942              :                        Real64 scaledCapacity,
    8943              :                        bool &modeCapacity,
    8944              :                        Real64 &designLoad,
    8945              :                        bool &scalableCapSizingOn,
    8946              :                        Real64 &fracOfAutosizedCapacity)
    8947              : {
    8948              :     using namespace DataSizing;
    8949              :     using HVAC::CoolingCapacitySizing;
    8950              :     using HVAC::HeatingCapacitySizing;
    8951              : 
    8952            2 :     eqSizingMethod = capSizingMethod;
    8953            2 :     if (capSizingMethod == CoolingDesignCapacity || capSizingMethod == HeatingDesignCapacity || capSizingMethod == CapacityPerFloorArea ||
    8954            0 :         capSizingMethod == FractionOfAutosizedCoolingCapacity || capSizingMethod == FractionOfAutosizedHeatingCapacity) {
    8955            2 :         if ((capSizingMethod == CoolingDesignCapacity && sizingMethod == CoolingCapacitySizing) ||
    8956            0 :             (capSizingMethod == HeatingDesignCapacity && sizingMethod == HeatingCapacitySizing)) {
    8957            1 :             if (scaledCapacity > 0.0) {
    8958            0 :                 modeCapacity = true;
    8959            0 :                 designLoad = scaledCapacity;
    8960              :             }
    8961            1 :         } else if (capSizingMethod == CapacityPerFloorArea) {
    8962            1 :             modeCapacity = true;
    8963            1 :             designLoad = scaledCapacity * state.dataHeatBal->Zone(state.dataSize->DataZoneNumber).FloorArea;
    8964            1 :             scalableCapSizingOn = true;
    8965            0 :         } else if ((capSizingMethod == FractionOfAutosizedCoolingCapacity && sizingMethod == CoolingCapacitySizing) ||
    8966            0 :                    (capSizingMethod == FractionOfAutosizedHeatingCapacity && sizingMethod == HeatingCapacitySizing)) {
    8967            0 :             fracOfAutosizedCapacity = scaledCapacity;
    8968            0 :             scalableCapSizingOn = true;
    8969              :         }
    8970              :     }
    8971            2 : }
    8972              : 
    8973            5 : void VRFCondenserEquipment::SizeVRFCondenser(EnergyPlusData &state)
    8974              : {
    8975              : 
    8976              :     // SUBROUTINE INFORMATION:
    8977              :     //       AUTHOR         Richard Raustad, FSEC
    8978              :     //       DATE WRITTEN   August 2012
    8979              :     //       MODIFIED       na
    8980              :     //       RE-ENGINEERED  na
    8981              : 
    8982              :     // PURPOSE OF THIS SUBROUTINE:
    8983              :     // This subroutine is for sizing VRF Condenser.
    8984              : 
    8985              :     // METHODOLOGY EMPLOYED:
    8986              :     // Set water-cooled plant flow rates.
    8987              : 
    8988              :     static constexpr std::string_view RoutineName("SizeVRFCondenser");
    8989              : 
    8990              :     Real64 rho;                // local fluid density [kg/m3]
    8991              :     Real64 Cp;                 // local fluid specific heat [J/kg-k]
    8992              :     Real64 tmpCondVolFlowRate; // local condenser design volume flow rate [m3/s]
    8993              : 
    8994              :     // save the design water flow rate for use by the water loop sizing algorithms
    8995            5 :     if (this->CondenserType == DataHeatBalance::RefrigCondenserType::Water) {
    8996              : 
    8997            5 :         bool ErrorsFound = false;
    8998            5 :         if (this->WaterCondVolFlowRate == DataSizing::AutoSize) {
    8999            1 :             int PltSizCondNum = 0;
    9000            1 :             if (this->SourcePlantLoc.loopNum > 0) {
    9001            1 :                 PltSizCondNum = state.dataPlnt->PlantLoop(this->SourcePlantLoc.loopNum).PlantSizNum;
    9002              :             }
    9003            1 :             if (PltSizCondNum > 0) {
    9004            1 :                 rho = state.dataPlnt->PlantLoop(this->SourcePlantLoc.loopNum)
    9005            1 :                           .glycol->getDensity(state, state.dataSize->PlantSizData(PltSizCondNum).ExitTemp, RoutineName);
    9006              : 
    9007            1 :                 Cp = state.dataPlnt->PlantLoop(this->SourcePlantLoc.loopNum)
    9008            1 :                          .glycol->getSpecificHeat(state, state.dataSize->PlantSizData(PltSizCondNum).ExitTemp, RoutineName);
    9009            1 :                 tmpCondVolFlowRate =
    9010            1 :                     max(this->CoolingCapacity, this->HeatingCapacity) / (state.dataSize->PlantSizData(PltSizCondNum).DeltaT * Cp * rho);
    9011            1 :                 if (this->HeatingCapacity != DataSizing::AutoSize && this->CoolingCapacity != DataSizing::AutoSize) {
    9012            1 :                     this->WaterCondVolFlowRate = tmpCondVolFlowRate;
    9013            1 :                     BaseSizer::reportSizerOutput(state,
    9014              :                                                  "AirConditioner:VariableRefrigerantFlow",
    9015              :                                                  this->Name,
    9016              :                                                  "Design Condenser Water Flow Rate [m3/s]",
    9017              :                                                  this->WaterCondVolFlowRate);
    9018              :                 }
    9019              : 
    9020            1 :                 rho = state.dataPlnt->PlantLoop(this->SourcePlantLoc.loopNum).glycol->getDensity(state, Constant::CWInitConvTemp, RoutineName);
    9021            1 :                 this->WaterCondenserDesignMassFlow = this->WaterCondVolFlowRate * rho;
    9022            1 :                 PlantUtilities::InitComponentNodes(
    9023              :                     state, 0.0, this->WaterCondenserDesignMassFlow, this->CondenserNodeNum, this->CondenserOutletNodeNum);
    9024              : 
    9025              :             } else {
    9026            0 :                 ShowSevereError(state, "Autosizing of condenser water flow rate requires a condenser loop Sizing:Plant object");
    9027            0 :                 ShowContinueError(state, format("... occurs in AirConditioner:VariableRefrigerantFlow object={}", this->Name));
    9028            0 :                 ShowContinueError(state, "... plant loop name must be referenced in Sizing:Plant object");
    9029            0 :                 ErrorsFound = true;
    9030              :             }
    9031              :         }
    9032              : 
    9033            5 :         if (ErrorsFound) {
    9034            0 :             ShowFatalError(state, "Preceding sizing errors cause program termination");
    9035              :         }
    9036              : 
    9037            5 :         PlantUtilities::RegisterPlantCompDesignFlow(state, this->CondenserNodeNum, this->WaterCondVolFlowRate);
    9038              :     }
    9039            5 : }
    9040              : 
    9041       244151 : void SimVRF(EnergyPlusData &state,
    9042              :             int const VRFTUNum,
    9043              :             bool const FirstHVACIteration,
    9044              :             Real64 &OnOffAirFlowRatio,
    9045              :             Real64 &SysOutputProvided,
    9046              :             Real64 &LatOutputProvided,
    9047              :             Real64 const QZnReq)
    9048              : {
    9049              : 
    9050              :     // SUBROUTINE INFORMATION:
    9051              :     //       AUTHOR         Richard Raustad, FSEC
    9052              :     //       DATE WRITTEN   August 2010
    9053              :     //       MODIFIED       na
    9054              :     //       RE-ENGINEERED  na
    9055              : 
    9056              :     // PURPOSE OF THIS SUBROUTINE:
    9057              :     // This subroutine simulates the VRF TU's.
    9058              : 
    9059              :     // METHODOLOGY EMPLOYED:
    9060              :     // Simulate terminal unit to meet zone load.
    9061              : 
    9062       244151 :     Real64 PartLoadRatio(1.0);
    9063       244151 :     Real64 SuppHeatCoilLoad(0.0); // supplemental heating coil load (W)
    9064              : 
    9065       244151 :     if (state.dataHVACVarRefFlow->VRF(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    9066              :         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    9067        56371 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ControlVRF_FluidTCtrl(
    9068              :             state, VRFTUNum, QZnReq, FirstHVACIteration, PartLoadRatio, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9069        56371 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
    9070              :             state, VRFTUNum, FirstHVACIteration, PartLoadRatio, SysOutputProvided, OnOffAirFlowRatio, SuppHeatCoilLoad, LatOutputProvided);
    9071        56371 :         if (PartLoadRatio ==
    9072              :             0.0) { // set coil inlet conditions when coil does not operate. Inlet conditions are set in ControlVRF_FluidTCtrl when PLR=1
    9073         3515 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingCoilPresent) {
    9074         3515 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).coilInNodeT =
    9075         3515 :                     state.dataLoopNodes->Node(state.dataDXCoils->DXCoil(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolCoilIndex).AirInNode).Temp;
    9076         3515 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).coilInNodeW =
    9077         3515 :                     state.dataLoopNodes->Node(state.dataDXCoils->DXCoil(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolCoilIndex).AirInNode).HumRat;
    9078              :             } else {
    9079            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).coilInNodeT =
    9080            0 :                     state.dataLoopNodes->Node(state.dataDXCoils->DXCoil(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatCoilIndex).AirInNode).Temp;
    9081            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).coilInNodeW =
    9082            0 :                     state.dataLoopNodes->Node(state.dataDXCoils->DXCoil(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatCoilIndex).AirInNode).HumRat;
    9083              :             }
    9084              :         }
    9085              :         // CalcVRF( VRFTUNum, FirstHVACIteration, PartLoadRatio, SysOutputProvided, OnOffAirFlowRatio, LatOutputProvided );
    9086              :     } else {
    9087              :         // Algorithm Type: VRF model based on system curve
    9088       187780 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ControlVRF(
    9089              :             state, VRFTUNum, QZnReq, FirstHVACIteration, PartLoadRatio, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9090       187780 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(
    9091              :             state, VRFTUNum, FirstHVACIteration, PartLoadRatio, SysOutputProvided, OnOffAirFlowRatio, SuppHeatCoilLoad, LatOutputProvided);
    9092              :     }
    9093              : 
    9094       244151 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TerminalUnitSensibleRate = SysOutputProvided;
    9095       244151 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TerminalUnitLatentRate = LatOutputProvided;
    9096       244151 : }
    9097              : 
    9098       187780 : void VRFTerminalUnitEquipment::ControlVRF(EnergyPlusData &state,
    9099              :                                           int const VRFTUNum,            // Index to VRF terminal unit
    9100              :                                           Real64 const QZnReq,           // Index to zone number
    9101              :                                           bool const FirstHVACIteration, // flag for 1st HVAC iteration in the time step
    9102              :                                           Real64 &PartLoadRatio,         // unit part load ratio
    9103              :                                           Real64 &OnOffAirFlowRatio,     // ratio of compressor ON airflow to AVERAGE airflow over timestep
    9104              :                                           Real64 &SuppHeatCoilLoad       // supplemental heating coil load (W)
    9105              : )
    9106              : {
    9107              : 
    9108              :     // SUBROUTINE INFORMATION:
    9109              :     //       AUTHOR         Richard Raustad
    9110              :     //       DATE WRITTEN   July 2005
    9111              : 
    9112              :     // PURPOSE OF THIS SUBROUTINE:
    9113              :     // Determine the part load fraction of the heat pump for this time step.
    9114              : 
    9115              :     // METHODOLOGY EMPLOYED:
    9116              :     // Use RegulaFalsi technique to iterate on part-load ratio until convergence is achieved.
    9117              : 
    9118       187780 :     PartLoadRatio = 0.0;
    9119       187780 :     state.dataHVACVarRefFlow->LoopDXCoolCoilRTF = 0.0;
    9120       187780 :     state.dataHVACVarRefFlow->LoopDXHeatCoilRTF = 0.0;
    9121       187780 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatPartLoadRatio = 0.0;
    9122              : 
    9123              :     // The RETURNS here will jump back to SimVRF where the CalcVRF routine will simulate with latest PLR
    9124              : 
    9125              :     // do nothing else if TU is scheduled off
    9126       187780 :     if (this->availSched->getCurrentVal() == 0.0) {
    9127            0 :         return;
    9128              :     }
    9129              : 
    9130              :     // do nothing if TU has no load (TU will be modeled using PLR=0)
    9131       187780 :     if (QZnReq == 0.0) {
    9132        24121 :         return;
    9133              :     }
    9134              : 
    9135              :     // Set EMS value for PLR and return
    9136       163659 :     if (this->EMSOverridePartLoadFrac) {
    9137            0 :         PartLoadRatio = this->EMSValueForPartLoadFrac;
    9138            0 :         return;
    9139              :     }
    9140              : 
    9141              :     // Get result when DX coil is operating at the minimum PLR (1E-20) if not otherwise specified
    9142       163659 :     PartLoadRatio = this->MinOperatingPLR;
    9143              : 
    9144       163659 :     this->ControlVRFToLoad(state, VRFTUNum, QZnReq, FirstHVACIteration, PartLoadRatio, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9145              : }
    9146              : 
    9147       163659 : void VRFTerminalUnitEquipment::ControlVRFToLoad(EnergyPlusData &state,
    9148              :                                                 int const VRFTUNum,
    9149              :                                                 Real64 const QZnReq,
    9150              :                                                 bool const FirstHVACIteration,
    9151              :                                                 Real64 &PartLoadRatio,
    9152              :                                                 Real64 &OnOffAirFlowRatio,
    9153              :                                                 Real64 &SuppHeatCoilLoad)
    9154              : {
    9155              : 
    9156       163659 :     int constexpr MaxIte(500);        // maximum number of iterations
    9157       163659 :     Real64 constexpr MinPLF(0.0);     // minimum part load factor allowed
    9158       163659 :     Real64 constexpr ErrorTol(0.001); // tolerance for RegulaFalsi iterations
    9159              : 
    9160       163659 :     int VRFCond = this->VRFSysNum;
    9161       163659 :     Real64 FullOutput = 0.0;   // unit full output when compressor is operating [W]
    9162       163659 :     Real64 TempOutput = 0.0;   // unit output when iteration limit exceeded [W]
    9163       163659 :     Real64 TempMinPLR = 0.0;   // min PLR used in Regula Falsi call
    9164       163659 :     Real64 TempMaxPLR = 0.0;   // max PLR used in Regula Falsi call
    9165       163659 :     Real64 NoCompOutput = 0.0; // output when no active compressor [W]
    9166       163659 :     bool VRFCoolingMode = state.dataHVACVarRefFlow->CoolingLoad(VRFCond);
    9167       163659 :     bool VRFHeatingMode = state.dataHVACVarRefFlow->HeatingLoad(VRFCond);
    9168       163659 :     int IndexToTUInTUList = this->IndexToTUInTUList;
    9169       163659 :     auto &thisVRFCond = state.dataHVACVarRefFlow->VRF(VRFCond);
    9170       163659 :     int TUListIndex = thisVRFCond.ZoneTUListPtr;
    9171       163659 :     bool HRCoolingMode = state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList);
    9172       163659 :     bool HRHeatingMode = state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList);
    9173       163659 :     auto &thisVRFTU = state.dataHVACVarRefFlow->VRFTU(VRFTUNum);
    9174              : 
    9175       163659 :     if (thisVRFCond.VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    9176              :         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    9177            0 :         this->CalcVRF_FluidTCtrl(state, VRFTUNum, FirstHVACIteration, PartLoadRatio, NoCompOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9178              :     } else {
    9179              :         // Algorithm Type: VRF model based on system curve
    9180       163659 :         this->CalcVRF(state, VRFTUNum, FirstHVACIteration, PartLoadRatio, NoCompOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9181              :     }
    9182              : 
    9183       163659 :     bool DXCoolingCoilOprCtrl = true;
    9184              : 
    9185       163659 :     if (VRFCoolingMode && HRHeatingMode) {
    9186              :         // IF the system is in cooling mode, but the terminal unit requests heating (heat recovery)
    9187            0 :         if (NoCompOutput >= QZnReq) {
    9188            0 :             PartLoadRatio = 0.0;
    9189        29498 :             return;
    9190              :         }
    9191       163659 :     } else if (VRFHeatingMode && HRCoolingMode) {
    9192              :         // IF the system is in heating mode, but the terminal unit requests cooling (heat recovery)
    9193            5 :         if (NoCompOutput <= QZnReq) {
    9194            0 :             PartLoadRatio = 0.0;
    9195            0 :             return;
    9196              :         }
    9197       163654 :     } else if (VRFCoolingMode || HRCoolingMode) {
    9198              :         // IF the system is in cooling mode and/or the terminal unit requests cooling
    9199        81856 :         if (NoCompOutput <= QZnReq) {
    9200            0 :             DXCoolingCoilOprCtrl = false;
    9201            0 :             if (!this->SuppHeatingCoilPresent || HRCoolingMode) {
    9202            0 :                 PartLoadRatio = 0.0;
    9203            0 :                 return;
    9204              :             }
    9205              :         }
    9206        81798 :     } else if (VRFHeatingMode || HRHeatingMode) {
    9207              :         // IF the system is in heating mode and/or the terminal unit requests heating
    9208        69276 :         if (NoCompOutput >= QZnReq) {
    9209           15 :             PartLoadRatio = 0.0;
    9210           15 :             return;
    9211              :         }
    9212              :     }
    9213              : 
    9214              :     // Otherwise the coil needs to turn on. Get full load result
    9215       163644 :     PartLoadRatio = 1.0;
    9216       163644 :     if (!DXCoolingCoilOprCtrl) {
    9217            0 :         PartLoadRatio = 0.0;
    9218              :     }
    9219       163644 :     if (thisVRFCond.VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    9220              :         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    9221            0 :         this->CalcVRF_FluidTCtrl(state, VRFTUNum, FirstHVACIteration, PartLoadRatio, FullOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9222              :     } else {
    9223              :         // Algorithm Type: VRF model based on system curve
    9224       163644 :         if (this->NumOfSpeedHeating > 0 && VRFHeatingMode) {
    9225         2676 :             this->SpeedNum = this->NumOfSpeedHeating;
    9226         2676 :             this->SpeedRatio = 1.0;
    9227         2676 :             this->CycRatio = 1.0;
    9228              :         }
    9229       163644 :         if (this->NumOfSpeedCooling > 0 && VRFCoolingMode) {
    9230         3127 :             this->SpeedNum = this->NumOfSpeedCooling;
    9231         3127 :             this->SpeedRatio = 1.0;
    9232         3127 :             this->CycRatio = 1.0;
    9233              :         }
    9234       163644 :         this->CalcVRF(state, VRFTUNum, FirstHVACIteration, PartLoadRatio, FullOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9235              :     }
    9236              : 
    9237              :     // set supplemental heating coil calculation if the condition requires
    9238       163644 :     if (this->SuppHeatingCoilPresent) {
    9239        14453 :         if (this->isSetPointControlled) {
    9240            0 :             auto const &thisSuppHeatCoilAirInletNode = state.dataLoopNodes->Node(this->SuppHeatCoilAirInletNode);
    9241            0 :             if (this->suppTempSetPoint > thisSuppHeatCoilAirInletNode.Temp) {
    9242            0 :                 Real64 mDot = thisSuppHeatCoilAirInletNode.MassFlowRate;
    9243            0 :                 Real64 Tin = thisSuppHeatCoilAirInletNode.Temp;
    9244            0 :                 Real64 Win = thisSuppHeatCoilAirInletNode.HumRat;
    9245            0 :                 Real64 CpAirIn = Psychrometrics::PsyCpAirFnW(Win);
    9246            0 :                 SuppHeatCoilLoad = mDot * CpAirIn * (this->suppTempSetPoint - Tin);
    9247            0 :                 this->SuppHeatingCoilLoad = SuppHeatCoilLoad;
    9248              :             } else {
    9249            0 :                 SuppHeatCoilLoad = 0.0;
    9250              :             }
    9251              :         } else {
    9252              :             // not sure why FirstHVAC has anything to do with this but that was already here
    9253              :             // another branch should test removing FirstHVACIteration to get same answer each iteration
    9254        14453 :             if (!FirstHVACIteration &&
    9255         7219 :                 ((QZnReq > HVAC::SmallLoad && QZnReq > FullOutput) || (((QZnReq - NoCompOutput) > HVAC::SmallLoad) && QZnReq <= 0.0))) {
    9256         2416 :                 Real64 ZoneLoad = 0.0;
    9257         2416 :                 Real64 LoadToHeatingSP = 0.0;
    9258         2416 :                 Real64 LoadToCoolingSP = 0.0;
    9259         2416 :                 getVRFTUZoneLoad(state, VRFTUNum, ZoneLoad, LoadToHeatingSP, LoadToCoolingSP, false);
    9260         2416 :                 if ((QZnReq - NoCompOutput) > HVAC::SmallLoad && QZnReq <= 0.0) {
    9261           61 :                     if (LoadToHeatingSP < 0.0 && QZnReq == 0.0) {
    9262            0 :                         SuppHeatCoilLoad = max(0.0, LoadToHeatingSP - FullOutput);
    9263              :                     } else {
    9264           61 :                         SuppHeatCoilLoad = max(0.0, QZnReq - FullOutput);
    9265              :                     }
    9266         2355 :                 } else if (FullOutput < (LoadToHeatingSP - HVAC::SmallLoad) && LoadToHeatingSP > 0.0) {
    9267         2074 :                     if (QZnReq > 0.0 && (NoCompOutput - QZnReq) >= HVAC::SmallLoad) {
    9268            0 :                         SuppHeatCoilLoad = 0.0;
    9269              :                     } else {
    9270         2074 :                         SuppHeatCoilLoad = max(0.0, LoadToHeatingSP - FullOutput);
    9271              :                     }
    9272              :                 } else {
    9273          281 :                     SuppHeatCoilLoad = 0.0;
    9274              :                 }
    9275         2416 :             } else {
    9276        12037 :                 SuppHeatCoilLoad = 0.0;
    9277              :             }
    9278              :         }
    9279        14453 :         if (this->DesignSuppHeatingCapacity > 0.0) {
    9280        14453 :             this->SuppHeatPartLoadRatio = min(1.0, SuppHeatCoilLoad / this->DesignSuppHeatingCapacity);
    9281              :         }
    9282              :     } else { // does it matter what these are if there is no supp heater?
    9283       149191 :         SuppHeatCoilLoad = 0.0;
    9284       149191 :         this->SuppHeatPartLoadRatio = 0.0;
    9285              :     }
    9286              : 
    9287       163644 :     if ((VRFCoolingMode && !thisVRFCond.HeatRecoveryUsed) || (thisVRFCond.HeatRecoveryUsed && HRCoolingMode)) {
    9288              :         // Since we are cooling, we expect FullOutput < NoCompOutput
    9289              :         // If the QZnReq <= FullOutput the unit needs to run full out
    9290        81861 :         if (QZnReq <= FullOutput) {
    9291              :             // if no coil present in terminal unit, no need to reset PLR?
    9292         4895 :             if (thisVRFTU.CoolingCoilPresent && DXCoolingCoilOprCtrl) {
    9293         4895 :                 PartLoadRatio = 1.0;
    9294              :                 // the zone set point could be exceeded if set point control is used so protect against that
    9295         4895 :                 if (this->isSetPointControlled) {
    9296            0 :                     if (state.dataLoopNodes->Node(this->coolCoilAirOutNode).Temp > this->coilTempSetPoint) {
    9297            0 :                         return;
    9298              :                     }
    9299              :                 } else {
    9300         4895 :                     return;
    9301              :                 }
    9302              :             } else {
    9303            0 :                 PartLoadRatio = 0.0;
    9304            0 :                 return;
    9305              :             }
    9306              :         }
    9307        81783 :     } else if ((VRFHeatingMode && !thisVRFCond.HeatRecoveryUsed) || (thisVRFCond.HeatRecoveryUsed && HRHeatingMode)) {
    9308              :         // Since we are heating, we expect FullOutput > NoCompOutput
    9309              :         // If the QZnReq >= FullOutput the unit needs to run full out
    9310        69261 :         if (QZnReq >= FullOutput) {
    9311              :             // if no coil present in terminal unit, no need reset PLR?
    9312        12066 :             if (this->HeatingCoilPresent) {
    9313        12066 :                 PartLoadRatio = 1.0;
    9314              :                 // the zone set point could be exceeded if set point control is used so protect against that
    9315        12066 :                 if (this->isSetPointControlled) {
    9316            1 :                     if (state.dataLoopNodes->Node(this->heatCoilAirOutNode).Temp < this->coilTempSetPoint) {
    9317            1 :                         return;
    9318              :                     }
    9319              :                 } else {
    9320        12065 :                     return;
    9321              :                 }
    9322              :             } else {
    9323            0 :                 PartLoadRatio = 0.0;
    9324            0 :                 return;
    9325              :             }
    9326              :         }
    9327              :     } else {
    9328              :         // VRF terminal unit is off
    9329              :         // shouldn't actually get here
    9330        12522 :         PartLoadRatio = 0.0;
    9331        12522 :         return;
    9332              :     }
    9333              : 
    9334              :     // The coil will not operate at PLR=0 or PLR=1, calculate the operating part-load ratio
    9335              : 
    9336       134161 :     if ((VRFHeatingMode || HRHeatingMode) || ((VRFCoolingMode && DXCoolingCoilOprCtrl) || HRCoolingMode)) {
    9337              : 
    9338       134161 :         int NumOfSpeed = 1;
    9339       134161 :         if (this->NumOfSpeedHeating > 1 && ((VRFHeatingMode || HRHeatingMode))) {
    9340         2676 :             NumOfSpeed = this->NumOfSpeedHeating;
    9341              :         }
    9342       134161 :         if (this->NumOfSpeedCooling > 1 && ((VRFCoolingMode || HRCoolingMode))) {
    9343         3127 :             NumOfSpeed = this->NumOfSpeedCooling;
    9344              :         }
    9345              : 
    9346       134161 :         for (int SpeedNum = 1; SpeedNum <= NumOfSpeed; ++SpeedNum) {
    9347              : 
    9348       134161 :             if (NumOfSpeed > 1) {
    9349         5803 :                 this->SpeedNum = SpeedNum;
    9350         5803 :                 this->CalcVRF(state, VRFTUNum, FirstHVACIteration, 1.0, FullOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9351         5803 :                 if ((VRFHeatingMode || HRHeatingMode) && QZnReq >= FullOutput) {
    9352            0 :                     continue;
    9353              :                 }
    9354         5803 :                 if ((VRFCoolingMode || HRCoolingMode) && QZnReq <= FullOutput) {
    9355            0 :                     continue;
    9356              :                 }
    9357              :             }
    9358              : 
    9359       134161 :             if (SpeedNum == 1) {
    9360       134161 :                 this->SpeedRatio = 0.0;
    9361              :             }
    9362       134161 :             int SolFla = 0; // Flag of RegulaFalsi solver
    9363      1072153 :             auto f = [&state, VRFTUNum, FirstHVACIteration, QZnReq, OnOffAirFlowRatio](Real64 const PartLoadRatio) {
    9364       937992 :                 Real64 QZnReqTemp = QZnReq; // denominator representing zone load (W)
    9365              :                 Real64 ActualOutput;        // delivered capacity of VRF terminal unit
    9366       937992 :                 Real64 SuppHeatCoilLoad = 0.0;
    9367       937992 :                 bool setPointControlled = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isSetPointControlled;
    9368       937992 :                 Real64 nonConstOnOffAirFlowRatio = OnOffAirFlowRatio;
    9369              : 
    9370       937992 :                 if (state.dataHVACVarRefFlow->VRF(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum).VRFAlgorithmType ==
    9371              :                     AlgorithmType::FluidTCtrl) {
    9372              :                     // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    9373            0 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
    9374              :                         state, VRFTUNum, FirstHVACIteration, PartLoadRatio, ActualOutput, nonConstOnOffAirFlowRatio, SuppHeatCoilLoad);
    9375              :                 } else {
    9376              :                     // Algorithm Type: VRF model based on system curve
    9377       937992 :                     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(
    9378              :                         state, VRFTUNum, FirstHVACIteration, PartLoadRatio, ActualOutput, nonConstOnOffAirFlowRatio, SuppHeatCoilLoad);
    9379              :                 }
    9380              : 
    9381       937992 :                 if (setPointControlled) {
    9382        11986 :                     Real64 outletNodeT = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOutletNodeNum).Temp;
    9383        11986 :                     return (outletNodeT - state.dataHVACVarRefFlow->VRFTU(VRFTUNum).coilTempSetPoint);
    9384              :                 } else {
    9385       926006 :                     if (std::abs(QZnReq) < 100.0) {
    9386       108930 :                         QZnReqTemp = sign(100.0, QZnReq);
    9387              :                     }
    9388       926006 :                     return (ActualOutput - QZnReq) / QZnReqTemp;
    9389              :                 }
    9390       134161 :             };
    9391       134161 :             General::SolveRoot(state, ErrorTol, MaxIte, SolFla, PartLoadRatio, f, 0.0, 1.0);
    9392       134161 :             if (SpeedNum == 1) {
    9393       134161 :                 if (this->NumOfSpeedCooling > 1 || this->NumOfSpeedHeating > 1) {
    9394         5803 :                     this->CycRatio = PartLoadRatio;
    9395              :                 }
    9396       134161 :                 this->SpeedRatio = 0.0;
    9397       134161 :                 if (SolFla > 0 && PartLoadRatio <= 1.0) {
    9398       134161 :                     break;
    9399              :                 }
    9400              :             } else {
    9401            0 :                 this->CycRatio = 1.0;
    9402            0 :                 this->SpeedRatio = PartLoadRatio;
    9403            0 :                 if (SolFla > 0 && PartLoadRatio <= 1.0) {
    9404            0 :                     break;
    9405              :                 }
    9406              :             }
    9407              : 
    9408            0 :             if (SolFla == -1) {
    9409              :                 //     Very low loads may not converge quickly. Tighten PLR boundary and try again.
    9410            0 :                 TempMaxPLR = -0.1;
    9411            0 :                 bool ContinueIter = true;
    9412            0 :                 while (ContinueIter && TempMaxPLR < 1.0) {
    9413            0 :                     TempMaxPLR += 0.1;
    9414              : 
    9415            0 :                     if (thisVRFCond.VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    9416              :                         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    9417            0 :                         this->CalcVRF_FluidTCtrl(state, VRFTUNum, FirstHVACIteration, TempMaxPLR, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9418              :                     } else {
    9419              :                         // Algorithm Type: VRF model based on system curve
    9420            0 :                         this->CalcVRF(state, VRFTUNum, FirstHVACIteration, TempMaxPLR, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9421              :                     }
    9422              : 
    9423            0 :                     if (VRFHeatingMode && TempOutput > QZnReq) {
    9424            0 :                         ContinueIter = false;
    9425              :                     }
    9426            0 :                     if (VRFCoolingMode && TempOutput < QZnReq) {
    9427            0 :                         ContinueIter = false;
    9428              :                     }
    9429              :                 }
    9430            0 :                 TempMinPLR = TempMaxPLR;
    9431            0 :                 ContinueIter = true;
    9432            0 :                 while (ContinueIter && TempMinPLR > 0.0) {
    9433            0 :                     TempMaxPLR = TempMinPLR;
    9434            0 :                     TempMinPLR -= 0.01;
    9435              : 
    9436            0 :                     if (thisVRFCond.VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    9437              :                         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    9438            0 :                         this->CalcVRF_FluidTCtrl(state, VRFTUNum, FirstHVACIteration, TempMinPLR, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9439              :                     } else {
    9440              :                         // Algorithm Type: VRF model based on system curve
    9441            0 :                         this->CalcVRF(state, VRFTUNum, FirstHVACIteration, TempMinPLR, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9442              :                     }
    9443              : 
    9444            0 :                     if (VRFHeatingMode && TempOutput < QZnReq) {
    9445            0 :                         ContinueIter = false;
    9446              :                     }
    9447            0 :                     if (VRFCoolingMode && TempOutput > QZnReq) {
    9448            0 :                         ContinueIter = false;
    9449              :                     }
    9450              :                 }
    9451            0 :                 General::SolveRoot(state, ErrorTol, MaxIte, SolFla, PartLoadRatio, f, TempMinPLR, TempMaxPLR);
    9452            0 :                 if (SolFla == -1) {
    9453            0 :                     if (!FirstHVACIteration && !state.dataGlobal->WarmupFlag) {
    9454            0 :                         if (this->IterLimitExceeded == 0) {
    9455            0 :                             ShowWarningMessage(state, format("{} \"{}\"", tuTypeNames[(int)this->type], this->Name));
    9456            0 :                             ShowContinueError(
    9457              :                                 state,
    9458            0 :                                 format(" Iteration limit exceeded calculating terminal unit part-load ratio, maximum iterations = {}", MaxIte));
    9459            0 :                             ShowContinueErrorTimeStamp(state, format(" Part-load ratio returned = {:.3R}", PartLoadRatio));
    9460              : 
    9461            0 :                             if (thisVRFCond.VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
    9462              :                                 // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
    9463            0 :                                 this->CalcVRF_FluidTCtrl(
    9464              :                                     state, VRFTUNum, FirstHVACIteration, PartLoadRatio, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9465              :                             } else {
    9466              :                                 // Algorithm Type: VRF model based on system curve
    9467            0 :                                 this->CalcVRF(state, VRFTUNum, FirstHVACIteration, PartLoadRatio, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
    9468              :                             }
    9469              : 
    9470            0 :                             ShowContinueError(state, format(" Load requested = {:.5T}, Load delivered = {:.5T}", QZnReq, TempOutput));
    9471            0 :                             ShowRecurringWarningErrorAtEnd(state,
    9472            0 :                                                            format("{} \"{}\" -- Terminal unit Iteration limit exceeded error continues...",
    9473            0 :                                                                   tuTypeNames[(int)this->type],
    9474            0 :                                                                   this->Name),
    9475            0 :                                                            this->IterLimitExceeded);
    9476              :                         } else {
    9477            0 :                             ShowRecurringWarningErrorAtEnd(state,
    9478            0 :                                                            format("{} \"{}\" -- Terminal unit Iteration limit exceeded error continues...",
    9479            0 :                                                                   tuTypeNames[(int)this->type],
    9480            0 :                                                                   this->Name),
    9481            0 :                                                            this->IterLimitExceeded);
    9482              :                         }
    9483              :                     }
    9484            0 :                 } else if (SolFla == -2) {
    9485            0 :                     if (!FirstHVACIteration && !state.dataGlobal->WarmupFlag) {
    9486            0 :                         if (thisVRFTU.FirstIterfailed == 0) {
    9487            0 :                             ShowWarningMessage(state, format("{} \"{}\"", tuTypeNames[(int)this->type], this->Name));
    9488            0 :                             ShowContinueError(state, "Terminal unit part-load ratio calculation failed: PLR limits of 0 to 1 exceeded");
    9489            0 :                             ShowContinueError(state, "Please fill out a bug report and forward to the EnergyPlus support group.");
    9490            0 :                             ShowContinueErrorTimeStamp(state, "");
    9491            0 :                             ShowRecurringWarningErrorAtEnd(
    9492              :                                 state,
    9493            0 :                                 format("{} \"{}\" -- Terminal unit part-load ratio limits of 0 to 1 exceeded error continues...",
    9494            0 :                                        tuTypeNames[(int)this->type],
    9495            0 :                                        this->Name),
    9496            0 :                                 this->FirstIterfailed);
    9497              :                         } else {
    9498            0 :                             ShowRecurringWarningErrorAtEnd(
    9499              :                                 state,
    9500            0 :                                 format("{} \"{}\" -- Terminal unit part-load ratio limits of 0 to 1 exceeded error continues...",
    9501            0 :                                        tuTypeNames[(int)this->type],
    9502            0 :                                        this->Name),
    9503            0 :                                 thisVRFTU.FirstIterfailed);
    9504              :                         }
    9505              :                     }
    9506            0 :                     PartLoadRatio = max(MinPLF, std::abs(QZnReq - NoCompOutput) / std::abs(FullOutput - NoCompOutput));
    9507              :                 }
    9508            0 :             } else if (SolFla == -2) {
    9509            0 :                 if (!FirstHVACIteration && !state.dataGlobal->WarmupFlag) {
    9510            0 :                     if (thisVRFTU.FirstIterfailed == 0) {
    9511            0 :                         ShowWarningMessage(state, format("{} \"{}\"", tuTypeNames[(int)this->type], this->Name));
    9512              : 
    9513            0 :                         ShowContinueError(state, "Terminal unit part-load ratio calculation failed: PLR limits of 0 to 1 exceeded");
    9514            0 :                         ShowContinueError(state, "Please fill out a bug report and forward to the EnergyPlus support group.");
    9515            0 :                         ShowContinueErrorTimeStamp(state, "");
    9516            0 :                         ShowRecurringWarningErrorAtEnd(
    9517              :                             state,
    9518            0 :                             format("{} \"{}\" -- Terminal unit part-load ratio limits of 0 to 1 exceeded error continues...",
    9519            0 :                                    tuTypeNames[(int)this->type],
    9520            0 :                                    " \"" + this->Name),
    9521            0 :                             this->FirstIterfailed);
    9522              :                     } else {
    9523            0 :                         ShowRecurringWarningErrorAtEnd(
    9524              :                             state,
    9525            0 :                             format("{} \"{}\" -- Terminal unit part-load ratio limits of 0 to 1 exceeded error continues...",
    9526            0 :                                    tuTypeNames[(int)this->type],
    9527            0 :                                    this->Name),
    9528            0 :                             this->FirstIterfailed);
    9529              :                     }
    9530              :                 }
    9531            0 :                 if (FullOutput - NoCompOutput == 0.0) {
    9532            0 :                     PartLoadRatio = 0.0;
    9533              :                 } else {
    9534            0 :                     PartLoadRatio = min(1.0, max(MinPLF, std::abs(QZnReq - NoCompOutput) / std::abs(FullOutput - NoCompOutput)));
    9535              :                 }
    9536              :             }
    9537              :         }
    9538              :     }
    9539              : }
    9540              : 
    9541      1701118 : void VRFTerminalUnitEquipment::CalcVRF(EnergyPlusData &state,
    9542              :                                        int const VRFTUNum,                           // Unit index in VRF terminal unit array
    9543              :                                        bool const FirstHVACIteration,                // flag for 1st HVAC iteration in the time step
    9544              :                                        Real64 const PartLoadRatio,                   // compressor part load fraction
    9545              :                                        Real64 &LoadMet,                              // load met by unit (W)
    9546              :                                        Real64 &OnOffAirFlowRatio,                    // ratio of ON air flow to average air flow
    9547              :                                        Real64 &SuppHeatCoilLoad,                     // supplemental heating coil load (W)
    9548              :                                        ObjexxFCL::Optional<Real64> LatOutputProvided // delivered latent capacity (kgWater/s)
    9549              : )
    9550              : {
    9551              : 
    9552              :     // SUBROUTINE INFORMATION:
    9553              :     //       AUTHOR         Richard Raustad
    9554              :     //       DATE WRITTEN   July 2005
    9555              :     //       MODIFIED       July 2012, Chandan Sharma - FSEC: Added zone sys avail managers
    9556              :     //       RE-ENGINEERED  na
    9557              : 
    9558              :     // PURPOSE OF THIS SUBROUTINE:
    9559              :     // Simulate the components making up the VRF terminal unit.
    9560              : 
    9561              :     // METHODOLOGY EMPLOYED:
    9562              :     // Simulates the unit components sequentially in the air flow direction.
    9563              : 
    9564              :     using DXCoils::SimDXCoil;
    9565              :     using SingleDuct::SimATMixer;
    9566              :     using SteamCoils::SimulateSteamCoilComponents;
    9567              :     using WaterCoils::SimulateWaterCoilComponents;
    9568              : 
    9569              :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
    9570              :     int VRFTUOutletNodeNum; // TU air outlet node
    9571              :     int VRFTUInletNodeNum;  // TU air inlet node
    9572              :     Real64 AirMassFlow;     // total supply air mass flow [m3/s]
    9573              :     HVAC::FanOp fanOp;      // fan operating mode, HVAC::FanOp::Cycling or HVAC::FanOp::Continuous
    9574              :     int VRFCond;            // index to VRF condenser
    9575      1701118 :     Real64 SpecHumOut(0.0); // specific humidity ratio at outlet node
    9576      1701118 :     Real64 SpecHumIn(0.0);  // specific humidity ratio at inlet node
    9577              :     int TUListIndex;        // index to TU list for this VRF system
    9578              :     int IndexToTUInTUList;  // index to TU in specific list for the VRF system
    9579              :     int ZoneNode;           // Zone node of VRFTU is serving
    9580              : 
    9581      1701118 :     VRFCond = this->VRFSysNum;
    9582      1701118 :     TUListIndex = state.dataHVACVarRefFlow->VRF(VRFCond).ZoneTUListPtr;
    9583      1701118 :     IndexToTUInTUList = this->IndexToTUInTUList;
    9584      1701118 :     VRFTUOutletNodeNum = this->VRFTUOutletNodeNum;
    9585      1701118 :     VRFTUInletNodeNum = this->VRFTUInletNodeNum;
    9586      1701118 :     fanOp = this->fanOp;
    9587      1701118 :     ZoneNode = this->ZoneAirNode;
    9588              : 
    9589              :     // Set inlet air mass flow rate based on PLR and compressor on/off air flow rates
    9590      1701118 :     SetAverageAirFlow(state, VRFTUNum, PartLoadRatio, OnOffAirFlowRatio);
    9591              : 
    9592      1701118 :     AirMassFlow = state.dataLoopNodes->Node(VRFTUInletNodeNum).MassFlowRate;
    9593      1701118 :     if (this->ATMixerExists) {
    9594              :         // There is an air terminal mixer
    9595       360197 :         state.dataHVACVarRefFlow->ATMixOutNode = this->ATMixerOutNode;
    9596       360197 :         if (this->ATMixerType == HVAC::MixerType::InletSide) { // if there is an inlet side air terminal mixer
    9597              :             // set the primary air inlet mass flow rate
    9598       224226 :             state.dataLoopNodes->Node(this->ATMixerPriNode).MassFlowRate =
    9599       224226 :                 min(state.dataLoopNodes->Node(this->ATMixerPriNode).MassFlowRateMaxAvail, state.dataLoopNodes->Node(VRFTUInletNodeNum).MassFlowRate);
    9600              :             // now calculate the the mixer outlet air conditions (and the secondary air inlet flow rate). The mixer outlet flow rate has already
    9601              :             // been set above (it is the "inlet" node flow rate)
    9602       224226 :             SimATMixer(state, this->ATMixerName, FirstHVACIteration, this->ATMixerIndex);
    9603              :         }
    9604              :     } else {
    9605              :         // ATMixOutNode = 0;
    9606      1340921 :         if (this->OAMixerUsed) {
    9607      1321416 :             MixedAir::SimOAMixer(state, this->OAMixerName, this->OAMixerIndex);
    9608              :         }
    9609              :     }
    9610              :     // if blow through, simulate fan then coils
    9611      1701118 :     if (this->fanPlace == HVAC::FanPlace::BlowThru) {
    9612       190907 :         if (this->fanType == HVAC::FanType::SystemModel) {
    9613            0 :             if (OnOffAirFlowRatio > 0.0) {
    9614            0 :                 state.dataFans->fans(this->FanIndex)->simulate(state, FirstHVACIteration, _, _);
    9615              :             } else {
    9616            0 :                 state.dataFans->fans(this->FanIndex)->simulate(state, FirstHVACIteration, _, _, PartLoadRatio);
    9617              :             }
    9618              :         } else {
    9619       190907 :             state.dataFans->fans(this->FanIndex)->simulate(state, FirstHVACIteration, state.dataHVACVarRefFlow->FanSpeedRatio);
    9620              :         }
    9621              :     }
    9622              : 
    9623      1701118 :     if (this->CoolingCoilPresent) {
    9624              :         // above condition for heat pump mode, below condition for heat recovery mode
    9625      2431016 :         if ((!state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed && state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) ||
    9626       729898 :             (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed &&
    9627       173677 :              state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList))) {
    9628      2164982 :             SimDXCoil(state,
    9629              :                       "",
    9630              :                       HVAC::CompressorOp::On,
    9631              :                       FirstHVACIteration,
    9632      1082491 :                       this->CoolCoilIndex,
    9633              :                       fanOp,
    9634              :                       PartLoadRatio,
    9635              :                       OnOffAirFlowRatio,
    9636              :                       _,
    9637      1082491 :                       state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond),
    9638      1082491 :                       state.dataHVACVarRefFlow->VRF(this->VRFSysNum).VRFCondCyclingRatio);
    9639              :         } else { // cooling coil is off
    9640       618627 :             SimDXCoil(state, "", HVAC::CompressorOp::Off, FirstHVACIteration, this->CoolCoilIndex, fanOp, 0.0, OnOffAirFlowRatio);
    9641              :         }
    9642      1701118 :         state.dataHVACVarRefFlow->LoopDXCoolCoilRTF = state.dataAirLoop->LoopDXCoilRTF;
    9643              :     } else {
    9644            0 :         state.dataHVACVarRefFlow->LoopDXCoolCoilRTF = 0.0;
    9645              :     }
    9646              : 
    9647      1701118 :     if (this->HeatingCoilPresent) {
    9648              :         // above condition for heat pump mode, below condition for heat recovery mode
    9649      3005137 :         if ((!state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed && state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) ||
    9650      1304019 :             (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed &&
    9651       173677 :              state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList))) {
    9652      1353630 :             SimDXCoil(state,
    9653              :                       "",
    9654              :                       HVAC::CompressorOp::Off,
    9655              :                       FirstHVACIteration,
    9656       451210 :                       this->HeatCoilIndex,
    9657              :                       fanOp,
    9658              :                       PartLoadRatio,
    9659              :                       OnOffAirFlowRatio,
    9660              :                       _,
    9661       451210 :                       state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond));
    9662              :         } else {
    9663      1249908 :             SimDXCoil(state, "", HVAC::CompressorOp::Off, FirstHVACIteration, this->HeatCoilIndex, fanOp, 0.0, OnOffAirFlowRatio, _);
    9664              :         }
    9665      1701118 :         state.dataHVACVarRefFlow->LoopDXHeatCoilRTF = state.dataAirLoop->LoopDXCoilRTF;
    9666              :     } else {
    9667            0 :         state.dataHVACVarRefFlow->LoopDXHeatCoilRTF = 0.0;
    9668              :     }
    9669              : 
    9670              :     // if draw through, simulate coils then fan
    9671      1701118 :     if (this->fanPlace == HVAC::FanPlace::DrawThru) {
    9672      1490706 :         if (this->fanType == HVAC::FanType::SystemModel) {
    9673       815360 :             if (OnOffAirFlowRatio > 0.0) {
    9674       762062 :                 state.dataFans->fans(this->FanIndex)->simulate(state, FirstHVACIteration, _, _);
    9675              :             } else {
    9676        53298 :                 state.dataFans->fans(this->FanIndex)->simulate(state, FirstHVACIteration, _, _, PartLoadRatio);
    9677              :             }
    9678              : 
    9679              :         } else {
    9680       675346 :             state.dataFans->fans(this->FanIndex)->simulate(state, FirstHVACIteration, state.dataHVACVarRefFlow->FanSpeedRatio);
    9681              :         }
    9682              :     }
    9683              : 
    9684              :     // track fan power per terminal unit for calculating COP
    9685      1701118 :     this->FanPower = (this->FanIndex == 0) ? 0.0 : state.dataFans->fans(this->FanIndex)->totalPower;
    9686              : 
    9687              :     // run supplemental heating coil
    9688      1701118 :     if (this->SuppHeatingCoilPresent) {
    9689       156472 :         Real64 SuppPLR = this->SuppHeatPartLoadRatio;
    9690       156472 :         this->CalcVRFSuppHeatingCoil(state, VRFTUNum, FirstHVACIteration, SuppPLR, SuppHeatCoilLoad);
    9691       156472 :         if ((state.dataLoopNodes->Node(this->SuppHeatCoilAirOutletNode).Temp > this->MaxSATFromSuppHeatCoil) && SuppPLR > 0.0) {
    9692              :             // adjust the heating load to maximum allowed
    9693            0 :             Real64 MaxHeatCoilLoad = this->HeatingCoilCapacityLimit(state, this->SuppHeatCoilAirInletNode, this->MaxSATFromSuppHeatCoil);
    9694            0 :             this->CalcVRFSuppHeatingCoil(state, VRFTUNum, FirstHVACIteration, SuppPLR, MaxHeatCoilLoad);
    9695            0 :             SuppHeatCoilLoad = MaxHeatCoilLoad;
    9696              :         }
    9697              :     }
    9698              : 
    9699      1701118 :     Real64 LatentLoadMet = 0.0; // latent load delivered [kgWater/s]
    9700      1701118 :     Real64 TempOut = 0.0;
    9701      1701118 :     Real64 TempIn = 0.0;
    9702      1701118 :     if (this->ATMixerExists) {
    9703       360197 :         if (this->ATMixerType == HVAC::MixerType::SupplySide) {
    9704              :             // Air terminal supply side mixer, calculate supply side mixer output
    9705       135971 :             SimATMixer(state, this->ATMixerName, FirstHVACIteration, this->ATMixerIndex);
    9706       135971 :             TempOut = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->ATMixOutNode).Temp;
    9707       135971 :             SpecHumOut = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->ATMixOutNode).HumRat;
    9708       135971 :             AirMassFlow = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->ATMixOutNode).MassFlowRate;
    9709              :         } else {
    9710              :             // Air terminal inlet side mixer
    9711       224226 :             TempOut = state.dataLoopNodes->Node(VRFTUOutletNodeNum).Temp;
    9712       224226 :             SpecHumOut = state.dataLoopNodes->Node(VRFTUOutletNodeNum).HumRat;
    9713              :         }
    9714       360197 :         TempIn = state.dataLoopNodes->Node(ZoneNode).Temp;
    9715       360197 :         SpecHumIn = state.dataLoopNodes->Node(ZoneNode).HumRat;
    9716              :     } else {
    9717      1340921 :         TempOut = state.dataLoopNodes->Node(VRFTUOutletNodeNum).Temp;
    9718      1340921 :         SpecHumOut = state.dataLoopNodes->Node(VRFTUOutletNodeNum).HumRat;
    9719      1340921 :         if (ZoneNode > 0) {
    9720      1321416 :             TempIn = state.dataLoopNodes->Node(ZoneNode).Temp;
    9721      1321416 :             SpecHumIn = state.dataLoopNodes->Node(ZoneNode).HumRat;
    9722              :         } else {
    9723        19505 :             TempIn = state.dataLoopNodes->Node(VRFTUInletNodeNum).Temp;
    9724        19505 :             SpecHumIn = state.dataLoopNodes->Node(VRFTUInletNodeNum).HumRat;
    9725              :         }
    9726              :     }
    9727              :     // calculate sensible load met using delta enthalpy
    9728      1701118 :     Real64 TotalOutput = AirMassFlow * (Psychrometrics::PsyHFnTdbW(TempOut, SpecHumOut) -
    9729      1701118 :                                         Psychrometrics::PsyHFnTdbW(TempIn, SpecHumIn));         // total addition/removal rate, {W};
    9730      1701118 :     LoadMet = AirMassFlow * PsyDeltaHSenFnTdb2W2Tdb1W1(TempOut, SpecHumOut, TempIn, SpecHumIn); // sensible {W}
    9731      1701118 :     LatentLoadMet = TotalOutput - LoadMet;
    9732      1701118 :     if (present(LatOutputProvided)) {
    9733              :         //   CR9155 Remove specific humidity calculations
    9734       187780 :         LatOutputProvided = LatentLoadMet;
    9735              :     }
    9736      1701118 : }
    9737              : 
    9738       244151 : void ReportVRFTerminalUnit(EnergyPlusData &state, int const VRFTUNum) // index to VRF terminal unit
    9739              : {
    9740              : 
    9741              :     // SUBROUTINE INFORMATION:
    9742              :     //       AUTHOR         Richard Raustad, FSEC
    9743              :     //       DATE WRITTEN   August 2010
    9744              :     //       MODIFIED       na
    9745              :     //       RE-ENGINEERED  na
    9746              : 
    9747              :     // PURPOSE OF THIS SUBROUTINE:
    9748              :     // This subroutine updates the report variables for the VRF Terminal Units.
    9749              : 
    9750              :     using namespace DataSizing;
    9751              : 
    9752              :     Real64 TotalConditioning;    // - sum of sensible and latent rates
    9753              :     Real64 SensibleConditioning; // - sensible rate
    9754              :     Real64 LatentConditioning;   // - latent rate
    9755              :     Real64 ReportingConstant;    // - used to convert watts to joules
    9756              :     int VRFCond;                 // - index to VRF condenser
    9757              :     int TUListIndex;             // - index to terminal unit list
    9758              :     int IndexToTUInTUList;       // - index to the TU in the list
    9759              :     bool HRHeatRequestFlag;      // - indicates TU could be in heat mode
    9760              :     bool HRCoolRequestFlag;      // - indicates TU could be in cool mode
    9761              : 
    9762       244151 :     VRFCond = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum;
    9763       244151 :     TUListIndex = state.dataHVACVarRefFlow->VRF(VRFCond).ZoneTUListPtr;
    9764       244151 :     IndexToTUInTUList = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).IndexToTUInTUList;
    9765       244151 :     HRHeatRequestFlag = state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList);
    9766       244151 :     HRCoolRequestFlag = state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList);
    9767       244151 :     ReportingConstant = state.dataHVACGlobal->TimeStepSysSec;
    9768              : 
    9769              :     // account for terminal unit parasitic On/Off power use
    9770              :     // account for heat recovery first since these flags will be FALSE otherwise, each TU may have different operating mode
    9771              : 
    9772       244151 :     if (HRCoolRequestFlag) {
    9773        19973 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingCoilPresent) {
    9774        19973 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower =
    9775        19973 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElec * state.dataHVACVarRefFlow->LoopDXCoolCoilRTF +
    9776        19973 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec * (1.0 - state.dataHVACVarRefFlow->LoopDXCoolCoilRTF);
    9777        19973 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecCoolConsumption =
    9778        19973 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower * ReportingConstant;
    9779        19973 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower = 0.0;
    9780        19973 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecHeatConsumption = 0.0;
    9781              :         } else {
    9782              :             // cooling parasitic power report variable is not even available when there is no cooling coil, report for heating
    9783            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec;
    9784            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecHeatConsumption =
    9785            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower * ReportingConstant;
    9786              :         }
    9787       224178 :     } else if (HRHeatRequestFlag) {
    9788        14055 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingCoilPresent) {
    9789        14055 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower = 0.0;
    9790        14055 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecCoolConsumption = 0.0;
    9791        14055 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower =
    9792        14055 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElec * state.dataHVACVarRefFlow->LoopDXHeatCoilRTF +
    9793        14055 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec * (1.0 - state.dataHVACVarRefFlow->LoopDXHeatCoilRTF);
    9794        14055 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecHeatConsumption =
    9795        14055 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower * ReportingConstant;
    9796              :         } else {
    9797              :             // heating parasitic power report variable is not even available when there is no heating coil, report for cooling
    9798            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec;
    9799            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecCoolConsumption =
    9800            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower * ReportingConstant;
    9801              :         }
    9802       318817 :     } else if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) ||
    9803       108694 :                (!state.dataHVACVarRefFlow->HeatingLoad(VRFCond) &&
    9804        28485 :                 state.dataHVACVarRefFlow->LastModeCooling(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum))) {
    9805       114618 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingCoilPresent) {
    9806       114618 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower =
    9807       114618 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElec * state.dataHVACVarRefFlow->LoopDXCoolCoilRTF +
    9808       114618 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec * (1.0 - state.dataHVACVarRefFlow->LoopDXCoolCoilRTF);
    9809       114618 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecCoolConsumption =
    9810       114618 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower * ReportingConstant;
    9811       114618 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower = 0.0;
    9812       114618 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecHeatConsumption = 0.0;
    9813              :         } else {
    9814              :             // cooling parasitic power report variable is not even available when there is no cooling coil, report for heating
    9815            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec;
    9816            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecHeatConsumption =
    9817            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower * ReportingConstant;
    9818              :         }
    9819       110801 :     } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) ||
    9820        15296 :                (!state.dataHVACVarRefFlow->CoolingLoad(VRFCond) &&
    9821        15296 :                 state.dataHVACVarRefFlow->LastModeHeating(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum))) {
    9822        95505 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingCoilPresent) {
    9823        95505 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower = 0.0;
    9824        95505 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecCoolConsumption = 0.0;
    9825        95505 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower =
    9826        95505 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElec * state.dataHVACVarRefFlow->LoopDXHeatCoilRTF +
    9827        95505 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec * (1.0 - state.dataHVACVarRefFlow->LoopDXHeatCoilRTF);
    9828        95505 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecHeatConsumption =
    9829        95505 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower * ReportingConstant;
    9830              :         } else {
    9831              :             // heating parasitic power report variable is not even available when there is no heating coil, report for cooling
    9832            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec;
    9833            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecCoolConsumption =
    9834            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower * ReportingConstant;
    9835              :         }
    9836              :     } else {
    9837              :         // happens when there is no cooling or heating load
    9838            0 :         if (!state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CoolingCoilPresent) {
    9839              :             // report all for heating
    9840            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec;
    9841            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecHeatConsumption =
    9842            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower * ReportingConstant;
    9843            0 :         } else if (!state.dataHVACVarRefFlow->VRFTU(VRFTUNum).HeatingCoilPresent) {
    9844              :             // report all for cooling
    9845            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec;
    9846            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecCoolConsumption =
    9847            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower * ReportingConstant;
    9848              :         } else {
    9849              :             // split parasitic between both reporting variables
    9850            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec / 2.0;
    9851            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecCoolConsumption =
    9852            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticCoolElecPower * ReportingConstant;
    9853            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticOffElec / 2.0;
    9854            0 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticElecHeatConsumption =
    9855            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ParasiticHeatElecPower * ReportingConstant;
    9856              :         }
    9857              :     }
    9858              : 
    9859       244151 :     SensibleConditioning = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TerminalUnitSensibleRate;
    9860       244151 :     LatentConditioning = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TerminalUnitLatentRate;
    9861       244151 :     Real64 TempOut = 0.0;
    9862       244151 :     Real64 TempIn = 0.0;
    9863       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerExists) {
    9864        30655 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerType == HVAC::MixerType::SupplySide) {
    9865              :             // Air terminal supply side mixer
    9866        12262 :             TempOut = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ATMixerOutNode).Temp;
    9867        12262 :             TempIn = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneAirNode).Temp;
    9868              :         } else {
    9869              :             // Air terminal inlet side mixer
    9870        18393 :             TempOut = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOutletNodeNum).Temp;
    9871        18393 :             TempIn = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneAirNode).Temp;
    9872              :         }
    9873              :     } else {
    9874       213496 :         TempOut = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOutletNodeNum).Temp;
    9875       213496 :         TempIn = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum).Temp;
    9876              :     }
    9877       244151 :     TotalConditioning = SensibleConditioning + LatentConditioning;
    9878              : 
    9879       244151 :     if (TotalConditioning <= 0.0) {
    9880       140425 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalCoolingRate = std::abs(TotalConditioning);
    9881       140425 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalHeatingRate = 0.0;
    9882              :     } else {
    9883       103726 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalCoolingRate = 0.0;
    9884       103726 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalHeatingRate = TotalConditioning;
    9885              :     }
    9886       244151 :     if (SensibleConditioning <= 0.0) {
    9887       146495 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SensibleCoolingRate = std::abs(SensibleConditioning);
    9888       146495 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SensibleHeatingRate = 0.0;
    9889              :     } else {
    9890        97656 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SensibleCoolingRate = 0.0;
    9891        97656 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SensibleHeatingRate = SensibleConditioning;
    9892              :     }
    9893       244151 :     if (LatentConditioning <= 0.0) {
    9894       172336 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).LatentCoolingRate = std::abs(LatentConditioning);
    9895       172336 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).LatentHeatingRate = 0.0;
    9896              :     } else {
    9897        71815 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).LatentCoolingRate = 0.0;
    9898        71815 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).LatentHeatingRate = LatentConditioning;
    9899              :     }
    9900       244151 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalCoolingEnergy = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalCoolingRate * ReportingConstant;
    9901       244151 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SensibleCoolingEnergy =
    9902       244151 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SensibleCoolingRate * ReportingConstant;
    9903       244151 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).LatentCoolingEnergy = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).LatentCoolingRate * ReportingConstant;
    9904       244151 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalHeatingEnergy = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).TotalHeatingRate * ReportingConstant;
    9905       244151 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SensibleHeatingEnergy =
    9906       244151 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SensibleHeatingRate * ReportingConstant;
    9907       244151 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).LatentHeatingEnergy = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).LatentHeatingRate * ReportingConstant;
    9908              : 
    9909       244151 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).firstPass) {
    9910          122 :         if (!state.dataHVACVarRefFlow->MySizeFlag(VRFTUNum)) {
    9911           62 :             DataSizing::resetHVACSizingGlobals(state, state.dataSize->CurZoneEqNum, 0, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).firstPass);
    9912              :         }
    9913              :     }
    9914              : 
    9915              :     // reset to 1 in case blow through fan configuration (fan resets to 1, but for blow thru fans coil sets back down < 1)
    9916       244151 :     state.dataHVACGlobal->OnOffFanPartLoadFraction = 1.0;
    9917       244151 : }
    9918              : 
    9919        55680 : void ReportVRFCondenser(EnergyPlusData &state, int const VRFCond) // index to VRF condensing unit
    9920              : {
    9921              : 
    9922              :     // SUBROUTINE INFORMATION:
    9923              :     //       AUTHOR         Richard Raustad, FSEC
    9924              :     //       DATE WRITTEN   August 2010
    9925              :     //       MODIFIED       na
    9926              :     //       RE-ENGINEERED  na
    9927              : 
    9928              :     // PURPOSE OF THIS SUBROUTINE:
    9929              :     // This subroutine updates the report variables for the VRF Condenser.
    9930              : 
    9931              :     Real64 ReportingConstant; // - conversion constant for energy
    9932              : 
    9933        55680 :     ReportingConstant = state.dataHVACGlobal->TimeStepSysSec;
    9934              : 
    9935              :     //   calculate VRF condenser power/energy use
    9936        55680 :     state.dataHVACVarRefFlow->VRF(VRFCond).CoolElecConsumption = state.dataHVACVarRefFlow->VRF(VRFCond).ElecCoolingPower * ReportingConstant;
    9937        55680 :     state.dataHVACVarRefFlow->VRF(VRFCond).HeatElecConsumption = state.dataHVACVarRefFlow->VRF(VRFCond).ElecHeatingPower * ReportingConstant;
    9938              : 
    9939        55680 :     state.dataHVACVarRefFlow->VRF(VRFCond).DefrostConsumption = state.dataHVACVarRefFlow->VRF(VRFCond).DefrostPower * ReportingConstant;
    9940        55680 :     state.dataHVACVarRefFlow->VRF(VRFCond).BasinHeaterConsumption = state.dataHVACVarRefFlow->VRF(VRFCond).BasinHeaterPower * ReportingConstant;
    9941              : 
    9942        55680 :     state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondPumpElecConsumption =
    9943        55680 :         state.dataHVACVarRefFlow->VRF(VRFCond).EvapCondPumpElecPower * ReportingConstant;
    9944        55680 :     state.dataHVACVarRefFlow->VRF(VRFCond).CrankCaseHeaterElecConsumption =
    9945        55680 :         state.dataHVACVarRefFlow->VRF(VRFCond).CrankCaseHeaterPower * ReportingConstant;
    9946              : 
    9947        55680 :     state.dataHVACVarRefFlow->VRF(VRFCond).QCondEnergy = state.dataHVACVarRefFlow->VRF(VRFCond).QCondenser * ReportingConstant;
    9948        55680 :     state.dataHVACVarRefFlow->VRF(VRFCond).VRFHeatEnergyRec = state.dataHVACVarRefFlow->VRF(VRFCond).VRFHeatRec * ReportingConstant;
    9949        55680 : }
    9950              : 
    9951         3769 : void UpdateVRFCondenser(EnergyPlusData &state, int const VRFCond) // index to VRF condensing unit
    9952              : {
    9953              : 
    9954              :     // SUBROUTINE INFORMATION:
    9955              :     //       AUTHOR         Richard Raustad, FSEC
    9956              :     //       DATE WRITTEN   May 2012
    9957              :     //       MODIFIED       na
    9958              :     //       RE-ENGINEERED  na
    9959              : 
    9960              :     // PURPOSE OF THIS SUBROUTINE:
    9961              :     // This subroutine updates the node data for the VRF Condenser.
    9962              : 
    9963              :     int CondenserOutletNode; // - outlet node for VRF water-cooled condenser
    9964              : 
    9965         3769 :     CondenserOutletNode = state.dataHVACVarRefFlow->VRF(VRFCond).CondenserOutletNodeNum;
    9966              : 
    9967         3769 :     state.dataLoopNodes->Node(CondenserOutletNode).Temp = state.dataHVACVarRefFlow->VRF(VRFCond).CondenserSideOutletTemp;
    9968              : 
    9969         3769 :     state.dataLoopNodes->Node(CondenserOutletNode).MassFlowRate = state.dataHVACVarRefFlow->CondenserWaterMassFlowRate;
    9970         3769 :     state.dataLoopNodes->Node(CondenserOutletNode).MassFlowRateMaxAvail = state.dataLoopNodes->Node(CondenserOutletNode).MassFlowRateMaxAvail;
    9971         3769 :     state.dataLoopNodes->Node(CondenserOutletNode).MassFlowRateMinAvail = state.dataLoopNodes->Node(CondenserOutletNode).MassFlowRateMinAvail;
    9972         3769 : }
    9973              : 
    9974            2 : void isVRFCoilPresent(EnergyPlusData &state, std::string_view VRFTUName, bool &CoolCoilPresent, bool &HeatCoilPresent)
    9975              : {
    9976              : 
    9977            2 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) {
    9978            0 :         GetVRFInput(state);
    9979            0 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
    9980              :     }
    9981              : 
    9982              :     int WhichVRFTU =
    9983            2 :         Util::FindItemInList(VRFTUName, state.dataHVACVarRefFlow->VRFTU, &VRFTerminalUnitEquipment::Name, state.dataHVACVarRefFlow->NumVRFTU);
    9984            2 :     if (WhichVRFTU != 0) {
    9985            2 :         CoolCoilPresent = state.dataHVACVarRefFlow->VRFTU(WhichVRFTU).CoolingCoilPresent;
    9986            2 :         HeatCoilPresent = state.dataHVACVarRefFlow->VRFTU(WhichVRFTU).HeatingCoilPresent;
    9987              :     } else {
    9988            0 :         ShowSevereError(state, format("isVRFCoilPresent: Could not find VRF TU = \"{}\"", VRFTUName));
    9989              :     }
    9990            2 : }
    9991              : 
    9992              : //        End of Reporting subroutines for the Module
    9993              : // *****************************************************************************
    9994              : 
    9995              : // Utility subroutines for the Module
    9996              : 
    9997      3559335 : void SetAverageAirFlow(EnergyPlusData &state,
    9998              :                        int const VRFTUNum,         // Unit index
    9999              :                        Real64 const PartLoadRatio, // unit part load ratio
   10000              :                        Real64 &OnOffAirFlowRatio   // ratio of compressor ON airflow to average airflow over timestep
   10001              : )
   10002              : {
   10003              : 
   10004              :     // SUBROUTINE INFORMATION:
   10005              :     //       AUTHOR         Richard Raustad
   10006              :     //       DATE WRITTEN   August 2010
   10007              :     //       MODIFIED       July 2012, Chandan Sharma - FSEC: Added zone sys avail managers
   10008              :     //       RE-ENGINEERED  na
   10009              : 
   10010              :     // PURPOSE OF THIS SUBROUTINE:
   10011              :     // Set the average air mass flow rates using the part load fraction of the heat pump for this time step
   10012              :     // Set OnOffAirFlowRatio to be used by DX coils
   10013      3559335 :     auto &s_vrf = state.dataHVACVarRefFlow;
   10014      3559335 :     auto &vrfTu = s_vrf->VRFTU(VRFTUNum);
   10015              : 
   10016              :     int InletNode;                   // inlet node number
   10017              :     int OutsideAirNode;              // outside air node number
   10018              :     int AirRelNode;                  // relief air node number
   10019      3559335 :     Real64 AverageUnitMassFlow(0.0); // average supply air mass flow rate over time step
   10020      3559335 :     Real64 AverageOAMassFlow(0.0);   // average outdoor air mass flow rate over time step
   10021              : 
   10022      3559335 :     InletNode = vrfTu.VRFTUInletNodeNum;
   10023      3559335 :     OutsideAirNode = vrfTu.VRFTUOAMixerOANodeNum;
   10024      3559335 :     AirRelNode = vrfTu.VRFTUOAMixerRelNodeNum;
   10025              : 
   10026      3559335 :     if (vrfTu.fanOp == HVAC::FanOp::Cycling && vrfTu.SpeedNum == 0) {
   10027       557864 :         Real64 partLoadRat = PartLoadRatio;
   10028       557864 :         if (partLoadRat == 0.0 && vrfTu.SuppHeatPartLoadRatio > 0.0) {
   10029         1014 :             partLoadRat = vrfTu.SuppHeatPartLoadRatio;
   10030              :         }
   10031       557864 :         AverageUnitMassFlow = (partLoadRat * s_vrf->CompOnMassFlow) + ((1 - partLoadRat) * s_vrf->CompOffMassFlow);
   10032       557864 :         AverageOAMassFlow = (partLoadRat * s_vrf->OACompOnMassFlow) + ((1 - partLoadRat) * s_vrf->OACompOffMassFlow);
   10033      3559335 :     } else if (vrfTu.SpeedNum == 0) {
   10034      2935492 :         if (PartLoadRatio == 0.0) {
   10035              :             // set the average OA air flow to off compressor values if the compressor PartLoadRatio is zero
   10036       718311 :             AverageUnitMassFlow = s_vrf->CompOffMassFlow;
   10037       718311 :             AverageOAMassFlow = s_vrf->OACompOffMassFlow;
   10038              :         } else {
   10039      2217181 :             AverageUnitMassFlow = s_vrf->CompOnMassFlow;
   10040      2217181 :             AverageOAMassFlow = s_vrf->OACompOnMassFlow;
   10041              :         }
   10042        65979 :     } else if (vrfTu.SpeedNum == 1) {
   10043        60176 :         if (s_vrf->CoolingLoad(vrfTu.VRFSysNum)) {
   10044        39637 :             AverageUnitMassFlow = vrfTu.CoolMassFlowRate[vrfTu.SpeedNum] * PartLoadRatio + (1.0 - PartLoadRatio) * s_vrf->CompOffMassFlow;
   10045        20539 :         } else if (s_vrf->HeatingLoad(vrfTu.VRFSysNum)) {
   10046        17285 :             AverageUnitMassFlow = vrfTu.HeatMassFlowRate[vrfTu.SpeedNum] * PartLoadRatio + (1.0 - PartLoadRatio) * s_vrf->CompOffMassFlow;
   10047              :         }
   10048         5803 :     } else if (s_vrf->CoolingLoad(vrfTu.VRFSysNum)) {
   10049         3127 :         AverageUnitMassFlow =
   10050         3127 :             vrfTu.CoolMassFlowRate[vrfTu.SpeedNum] * PartLoadRatio + (1.0 - PartLoadRatio) * vrfTu.CoolMassFlowRate[vrfTu.SpeedNum - 1];
   10051         2676 :     } else if (s_vrf->HeatingLoad(vrfTu.VRFSysNum)) {
   10052         2676 :         AverageUnitMassFlow =
   10053         2676 :             vrfTu.HeatMassFlowRate[vrfTu.SpeedNum] * PartLoadRatio + (1.0 - PartLoadRatio) * vrfTu.HeatMassFlowRate[vrfTu.SpeedNum - 1];
   10054              :     }
   10055              : 
   10056      3559335 :     if (vrfTu.SpeedNum == 0) {
   10057      3493356 :         if (s_vrf->CompOffFlowRatio > 0.0) {
   10058      2850098 :             s_vrf->FanSpeedRatio = (PartLoadRatio * s_vrf->CompOnFlowRatio) + ((1 - PartLoadRatio) * s_vrf->CompOffFlowRatio);
   10059              :         } else {
   10060       643258 :             s_vrf->FanSpeedRatio = s_vrf->CompOnFlowRatio;
   10061              :         }
   10062              :     }
   10063              : 
   10064              :     // if the terminal unit and fan are scheduled on then set flow rate
   10065      7030162 :     if (vrfTu.availSched->getCurrentVal() > 0.0 && (vrfTu.fanAvailSched->getCurrentVal() > 0.0 || state.dataHVACGlobal->TurnFansOn) &&
   10066      3470827 :         !state.dataHVACGlobal->TurnFansOff) {
   10067              : 
   10068              :         // so for sure OA system TUs should use inlet node flow rate, don't overwrite inlet node flow rate
   10069              :         // could there be a reason for air loops to use inlet node flow? Possibly when VAV TUs used?
   10070      3439046 :         if (!vrfTu.isInOASys) {
   10071      3427224 :             state.dataLoopNodes->Node(InletNode).MassFlowRate = AverageUnitMassFlow;
   10072              :         }
   10073      3439046 :         if (!vrfTu.isInOASys) {
   10074      3427224 :             state.dataLoopNodes->Node(InletNode).MassFlowRateMaxAvail = AverageUnitMassFlow;
   10075              :         }
   10076      3439046 :         if (OutsideAirNode > 0) {
   10077      3036372 :             state.dataLoopNodes->Node(OutsideAirNode).MassFlowRate = AverageOAMassFlow;
   10078      3036372 :             state.dataLoopNodes->Node(OutsideAirNode).MassFlowRateMaxAvail = AverageOAMassFlow;
   10079      3036372 :             state.dataLoopNodes->Node(AirRelNode).MassFlowRate = AverageOAMassFlow;
   10080      3036372 :             state.dataLoopNodes->Node(AirRelNode).MassFlowRateMaxAvail = AverageOAMassFlow;
   10081              :         }
   10082      3439046 :         if (AverageUnitMassFlow > 0.0) {
   10083      3316708 :             OnOffAirFlowRatio = s_vrf->CompOnMassFlow / AverageUnitMassFlow;
   10084              :         } else {
   10085       122338 :             OnOffAirFlowRatio = 0.0;
   10086              :         }
   10087              : 
   10088              :     } else { // terminal unit and/or fan is off
   10089       120289 :         if (!vrfTu.isInOASys) {
   10090       107820 :             state.dataLoopNodes->Node(InletNode).MassFlowRate = 0.0;
   10091       107820 :             OnOffAirFlowRatio = 0.0;
   10092              :         }
   10093       120289 :         if (OutsideAirNode > 0) {
   10094       107820 :             state.dataLoopNodes->Node(OutsideAirNode).MassFlowRate = 0.0;
   10095       107820 :             state.dataLoopNodes->Node(AirRelNode).MassFlowRate = 0.0;
   10096              :         }
   10097              :     }
   10098      3559335 : }
   10099              : 
   10100        51606 : void InitializeOperatingMode(EnergyPlusData &state,
   10101              :                              bool const FirstHVACIteration, // flag for first time through HVAC systems
   10102              :                              int const VRFCond,             // Condenser Unit index
   10103              :                              int const TUListNum,           // Condenser Unit terminal unit list
   10104              :                              Real64 &OnOffAirFlowRatio      // ratio of on to off flow rate
   10105              : )
   10106              : {
   10107              : 
   10108              :     // SUBROUTINE INFORMATION:
   10109              :     //       AUTHOR         Richard Raustad
   10110              :     //       DATE WRITTEN   July 2012 (Moved from InitVRF)
   10111              :     //       MODIFIED       na
   10112              :     //       RE-ENGINEERED  na
   10113              : 
   10114              :     // PURPOSE OF THIS SUBROUTINE:
   10115              :     // Scans each zone coil and determines the load based on control
   10116              :     // Moved from Init to clean up and localize code segments
   10117              : 
   10118              :     Real64 ZoneDeltaT;       // zone temperature difference from setpoint
   10119              :     Real64 SPTempHi;         // thermostat setpoint high
   10120              :     Real64 SPTempLo;         // thermostat setpoint low
   10121              :     int NumTU;               // loop counter, number of TU's in list
   10122              :     Real64 ZoneLoad;         // current zone load (W)
   10123              :     Real64 LoadToCoolingSP;  // thermostat load to cooling setpoint (W)
   10124              :     Real64 LoadToHeatingSP;  // thermostat load to heating setpoint (W)
   10125              :     Real64 TempOutput;       // terminal unit output [W]
   10126              :     Real64 SuppHeatCoilLoad; // supplemental heating coil load
   10127              : 
   10128        51606 :     state.dataHVACVarRefFlow->MaxDeltaT = 0.0;
   10129        51606 :     state.dataHVACVarRefFlow->MinDeltaT = 0.0;
   10130        51606 :     state.dataHVACVarRefFlow->NumCoolingLoads = 0;
   10131        51606 :     state.dataHVACVarRefFlow->SumCoolingLoads = 0.0;
   10132        51606 :     state.dataHVACVarRefFlow->NumHeatingLoads = 0;
   10133        51606 :     state.dataHVACVarRefFlow->SumHeatingLoads = 0.0;
   10134        51606 :     SuppHeatCoilLoad = 0.0;
   10135              : 
   10136        51606 :     state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond) = 0;
   10137        51606 :     state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond) = 0;
   10138        51606 :     state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond) = 0.0;
   10139        51606 :     state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) = 0.0;
   10140        51606 :     state.dataHVACVarRefFlow->MaxDeltaT(VRFCond) = 0.0;
   10141        51606 :     state.dataHVACVarRefFlow->MinDeltaT(VRFCond) = 0.0;
   10142        51606 :     ZoneDeltaT = 0.0;
   10143        51606 :     state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10144        51606 :     state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10145        51606 :     state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).CoolingCoilAvailable = false;
   10146        51606 :     state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).HeatingCoilAvailable = false;
   10147              :     // loop through all TU's to find operating mode. Be careful not to mix loop counters with current TU/Cond index
   10148       275269 :     for (NumTU = 1; NumTU <= state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList; ++NumTU) {
   10149              :         // make sure TU's have been sized before looping through each one of them to determine operating mode
   10150       223683 :         if (any(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TerminalUnitNotSizedYet)) {
   10151           20 :             break;
   10152              :         }
   10153       223663 :         int TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   10154              : 
   10155              :         //       check to see if coil is present
   10156       223663 :         if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).CoolingCoilPresent(NumTU)) {
   10157              :             //         now check to see if coil is scheduled off
   10158       223663 :             if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).coolingCoilAvailScheds(NumTU)->getCurrentVal() > 0.0) {
   10159       223663 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).CoolingCoilAvailable(NumTU) = true;
   10160              :             }
   10161              :         }
   10162              : 
   10163              :         //       check to see if coil is present
   10164       223663 :         if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).HeatingCoilPresent(NumTU)) {
   10165              :             //         now check to see if coil is scheduled off
   10166       223663 :             if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).heatingCoilAvailScheds(NumTU)->getCurrentVal() > 0.0) {
   10167       223663 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).HeatingCoilAvailable(NumTU) = true;
   10168              :             }
   10169              :         }
   10170              : 
   10171       223663 :         if (state.dataHVACVarRefFlow->VRFTU(TUIndex).isSetPointControlled) {
   10172              :             // set point temperature may only reside at the TU outlet node
   10173         3192 :             Real64 coolCoilTempSetPoint = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOutletNodeNum).TempSetPoint;
   10174         3192 :             state.dataHVACVarRefFlow->VRFTU(TUIndex).suppTempSetPoint = coolCoilTempSetPoint;
   10175         3192 :             Real64 heatCoilTempSetPoint = coolCoilTempSetPoint;
   10176              :             // adjust coil control for fan heat when set point is at outlet node
   10177         3192 :             Real64 coolfanDeltaT = 0.0;
   10178         3192 :             Real64 heatfanDeltaT = 0.0;
   10179         3192 :             if (state.dataHVACVarRefFlow->VRFTU(TUIndex).fanPlace == HVAC::FanPlace::DrawThru) {
   10180            0 :                 if (state.dataHVACVarRefFlow->VRFTU(TUIndex).fanOutletNode > 0) {
   10181            0 :                     coolfanDeltaT = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).fanOutletNode).Temp -
   10182            0 :                                     state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).fanInletNode).Temp;
   10183              :                 }
   10184              :             }
   10185         3192 :             heatfanDeltaT = coolfanDeltaT;
   10186              :             // or the set point could be placed at either or both coils, update both if necessary
   10187         3192 :             if (state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolingCoilPresent) {
   10188         3192 :                 if (state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).coolCoilAirOutNode).TempSetPoint !=
   10189              :                     DataLoopNode::SensedNodeFlagValue) {
   10190         3192 :                     coolCoilTempSetPoint = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).coolCoilAirOutNode).TempSetPoint;
   10191              :                     //// should we adjust for fan heat or not? What if it's a mixed air SP that already adjusts for fan heat?
   10192              :                     // coolfanDeltaT = 0.0;
   10193              :                 }
   10194              :             }
   10195         3192 :             if (state.dataHVACVarRefFlow->VRFTU(TUIndex).HeatingCoilPresent) {
   10196         3192 :                 if (state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).heatCoilAirOutNode).TempSetPoint !=
   10197              :                     DataLoopNode::SensedNodeFlagValue) {
   10198         3192 :                     heatCoilTempSetPoint = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).heatCoilAirOutNode).TempSetPoint;
   10199              :                     //// should we adjust for fan heat or not? What if it's a mixed air SP that already adjusts for fan heat?
   10200              :                     // heatfanDeltaT = 0.0;
   10201              :                 }
   10202              :             }
   10203              :             // set a flow rate and simulate ATMixer/OASystem if needed
   10204         3192 :             if (FirstHVACIteration) {
   10205         1598 :                 SetAverageAirFlow(state, TUIndex, 1.0, OnOffAirFlowRatio);
   10206         1598 :                 if (state.dataHVACVarRefFlow->VRFTU(TUIndex).ATMixerExists) {
   10207              :                     // There is an air terminal mixer
   10208            0 :                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).ATMixerType ==
   10209              :                         HVAC::MixerType::InletSide) { // if there is an inlet side air terminal mixer
   10210              :                                                       // set the primary air inlet mass flow rate
   10211            0 :                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).ATMixerPriNode).MassFlowRate =
   10212            0 :                             min(state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).ATMixerPriNode).MassFlowRateMaxAvail,
   10213            0 :                                 state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUInletNodeNum).MassFlowRate);
   10214              :                         // now calculate the the mixer outlet air conditions (and the secondary air inlet flow rate). The mixer outlet flow rate
   10215              :                         // has already been set above (it is the "inlet" node flow rate)
   10216            0 :                         SingleDuct::SimATMixer(state,
   10217            0 :                                                state.dataHVACVarRefFlow->VRFTU(TUIndex).ATMixerName,
   10218              :                                                FirstHVACIteration,
   10219            0 :                                                state.dataHVACVarRefFlow->VRFTU(TUIndex).ATMixerIndex);
   10220              :                     }
   10221              :                 } else {
   10222              :                     // simulate OA Mixer
   10223         1598 :                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).OAMixerUsed) {
   10224            0 :                         MixedAir::SimOAMixer(
   10225            0 :                             state, state.dataHVACVarRefFlow->VRFTU(TUIndex).OAMixerName, state.dataHVACVarRefFlow->VRFTU(TUIndex).OAMixerIndex);
   10226              :                     }
   10227              :                 }
   10228              :             }
   10229              :             // identify a coil inlet temperature
   10230         3192 :             if (state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolingCoilPresent) {
   10231         3192 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).coilInNodeT =
   10232         3192 :                     state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).coolCoilAirInNode).Temp;
   10233         3192 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).coilInNodeW =
   10234         3192 :                     state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).coolCoilAirInNode).HumRat;
   10235              :             } else {
   10236            0 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).coilInNodeT =
   10237            0 :                     state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).heatCoilAirInNode).Temp;
   10238            0 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).coilInNodeW =
   10239            0 :                     state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).heatCoilAirInNode).HumRat;
   10240              :             }
   10241         3192 :             Real64 coilInletTemp = state.dataHVACVarRefFlow->VRFTU(TUIndex).coilInNodeT;
   10242         3192 :             Real64 coilInletHumRat = state.dataHVACVarRefFlow->VRFTU(TUIndex).coilInNodeW;
   10243         3192 :             Real64 coilInletMassFlow = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUInletNodeNum).MassFlowRate;
   10244         3192 :             state.dataHVACVarRefFlow->VRFTU(TUIndex).coolSPActive = false;
   10245         3192 :             state.dataHVACVarRefFlow->VRFTU(TUIndex).heatSPActive = false;
   10246              : 
   10247         3192 :             if ((heatCoilTempSetPoint - coilInletTemp - heatfanDeltaT) > HVAC::SmallTempDiff) { // heating
   10248         1366 :                 Real64 CpAirIn = Psychrometrics::PsyCpAirFnW(coilInletHumRat);
   10249         1366 :                 ZoneLoad = coilInletMassFlow * CpAirIn * (heatCoilTempSetPoint - coilInletTemp - heatfanDeltaT);
   10250         1366 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).heatSPActive = true;
   10251         1366 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).heatLoadToSP = ZoneLoad;
   10252         1366 :                 ++state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond);
   10253         1366 :                 state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) += ZoneLoad;
   10254         1366 :                 state.dataHVACVarRefFlow->MinDeltaT(VRFCond) = min(state.dataHVACVarRefFlow->MinDeltaT(VRFCond), -1.0);
   10255         1366 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).coilTempSetPoint = heatCoilTempSetPoint - heatfanDeltaT;
   10256         1826 :             } else if ((coilInletTemp - coolCoilTempSetPoint - coolfanDeltaT) > HVAC::SmallTempDiff) { // cooling
   10257         1812 :                 Real64 CpAirIn = Psychrometrics::PsyCpAirFnW(coilInletHumRat);
   10258         1812 :                 ZoneLoad = coilInletMassFlow * CpAirIn * (coolCoilTempSetPoint - coilInletTemp - coolfanDeltaT);
   10259         1812 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).coolSPActive = true;
   10260         1812 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).coolLoadToSP = ZoneLoad;
   10261         1812 :                 ++state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond);
   10262         1812 :                 state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond) += ZoneLoad;
   10263         1812 :                 state.dataHVACVarRefFlow->MaxDeltaT(VRFCond) = max(state.dataHVACVarRefFlow->MaxDeltaT(VRFCond), 1.0);
   10264         1812 :                 state.dataHVACVarRefFlow->VRFTU(TUIndex).coilTempSetPoint = coolCoilTempSetPoint - coolfanDeltaT;
   10265              :             }
   10266              :         } else { // else is not set point controlled
   10267              :             //     Constant fan systems are tested for ventilation load to determine if load to be met changes.
   10268              :             //     more logic may be needed here, what is the OA flow rate, was last mode heating or cooling, what control is used, etc...
   10269              : 
   10270       220471 :             int ThisZoneNum = state.dataHVACVarRefFlow->VRFTU(TUIndex).ZoneNum;
   10271       220471 :             getVRFTUZoneLoad(state, TUIndex, ZoneLoad, LoadToHeatingSP, LoadToCoolingSP, true);
   10272              : 
   10273       220471 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).ThermostatPriority == ThermostatCtrlType::ThermostatOffsetPriority) {
   10274              :                 //         for TSTATPriority, just check difference between zone temp and thermostat setpoint
   10275            0 :                 if (ThisZoneNum > 0) {
   10276            0 :                     auto const &thisZoneHB = state.dataZoneTempPredictorCorrector->zoneHeatBalance(ThisZoneNum);
   10277            0 :                     auto const &zoneTstatSetpt = state.dataHeatBalFanSys->zoneTstatSetpts(ThisZoneNum);
   10278            0 :                     SPTempHi = zoneTstatSetpt.setptHi;
   10279            0 :                     SPTempLo = zoneTstatSetpt.setptLo;
   10280              : 
   10281            0 :                     switch (state.dataHeatBalFanSys->TempControlType(ThisZoneNum)) {
   10282            0 :                     case HVAC::SetptType::Uncontrolled:
   10283              :                         // MaxDeltaT denotes cooling, MinDeltaT denotes heating
   10284            0 :                         break;
   10285            0 :                     case HVAC::SetptType::SingleHeat:
   10286              :                         // if heating load, ZoneDeltaT will be negative
   10287            0 :                         ZoneDeltaT = min(0.0, thisZoneHB.ZT - SPTempLo);
   10288            0 :                         state.dataHVACVarRefFlow->MinDeltaT(VRFCond) = min(state.dataHVACVarRefFlow->MinDeltaT(VRFCond), ZoneDeltaT);
   10289            0 :                         break;
   10290            0 :                     case HVAC::SetptType::SingleCool:
   10291              :                         // if cooling load, ZoneDeltaT will be positive
   10292            0 :                         ZoneDeltaT = max(0.0, thisZoneHB.ZT - SPTempHi);
   10293            0 :                         state.dataHVACVarRefFlow->MaxDeltaT(VRFCond) = max(state.dataHVACVarRefFlow->MaxDeltaT(VRFCond), ZoneDeltaT);
   10294            0 :                         break;
   10295            0 :                     case HVAC::SetptType::SingleHeatCool:
   10296            0 :                         ZoneDeltaT = thisZoneHB.ZT - SPTempHi; //- SPTempHi and SPTempLo are same value
   10297            0 :                         if (ZoneDeltaT > 0.0) {
   10298            0 :                             state.dataHVACVarRefFlow->MaxDeltaT(VRFCond) = max(state.dataHVACVarRefFlow->MaxDeltaT(VRFCond), ZoneDeltaT);
   10299              :                         } else {
   10300            0 :                             state.dataHVACVarRefFlow->MinDeltaT(VRFCond) = min(state.dataHVACVarRefFlow->MinDeltaT(VRFCond), ZoneDeltaT);
   10301              :                         }
   10302            0 :                         break;
   10303            0 :                     case HVAC::SetptType::DualHeatCool:
   10304            0 :                         if (thisZoneHB.ZT - SPTempHi > 0.0) {
   10305            0 :                             ZoneDeltaT = max(0.0, thisZoneHB.ZT - SPTempHi);
   10306            0 :                             state.dataHVACVarRefFlow->MaxDeltaT(VRFCond) = max(state.dataHVACVarRefFlow->MaxDeltaT(VRFCond), ZoneDeltaT);
   10307            0 :                         } else if (SPTempLo - thisZoneHB.ZT > 0.0) {
   10308            0 :                             ZoneDeltaT = min(0.0, thisZoneHB.ZT - SPTempLo);
   10309            0 :                             state.dataHVACVarRefFlow->MinDeltaT(VRFCond) = min(state.dataHVACVarRefFlow->MinDeltaT(VRFCond), ZoneDeltaT);
   10310              :                         }
   10311            0 :                         break;
   10312            0 :                     default:
   10313            0 :                         break;
   10314              :                     }
   10315              :                 }
   10316       224239 :             } else if (state.dataHVACVarRefFlow->VRF(VRFCond).ThermostatPriority == ThermostatCtrlType::LoadPriority ||
   10317         3768 :                        state.dataHVACVarRefFlow->VRF(VRFCond).ThermostatPriority == ThermostatCtrlType::ZonePriority) {
   10318       216703 :                 if (state.dataHVACVarRefFlow->VRFTU(TUIndex).fanOp == HVAC::FanOp::Continuous) {
   10319       167680 :                     SetCompFlowRate(state, TUIndex, VRFCond);
   10320              : 
   10321       167680 :                     if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
   10322              :                         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
   10323        51685 :                         state.dataHVACVarRefFlow->VRFTU(TUIndex).CalcVRF_FluidTCtrl(
   10324              :                             state, TUIndex, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   10325              :                     } else {
   10326              :                         // Algorithm Type: VRF model based on system curve
   10327       115995 :                         state.dataHVACVarRefFlow->VRFTU(TUIndex).CalcVRF(
   10328              :                             state, TUIndex, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   10329              :                     }
   10330              : 
   10331              :                     //           If the Terminal Unit has a net cooling capacity (NoCompOutput < 0) and
   10332              :                     //           the zone temp is above the Tstat heating setpoint (QToHeatSetPt < 0)
   10333       167680 :                     if (TempOutput < 0.0 && LoadToHeatingSP < 0.0) {
   10334              :                         //             If the net cooling capacity overshoots the heating setpoint count as heating load
   10335         8421 :                         if (TempOutput < LoadToHeatingSP) {
   10336              :                             //               Don't count as heating load unless mode is allowed. Also check for floating zone.
   10337         3678 :                             if (state.dataHeatBalFanSys->TempControlType(ThisZoneNum) != HVAC::SetptType::SingleCool &&
   10338         1839 :                                 state.dataHeatBalFanSys->TempControlType(ThisZoneNum) != HVAC::SetptType::Uncontrolled) {
   10339         1839 :                                 if (!state.dataHVACVarRefFlow->LastModeHeating(VRFCond)) {
   10340              :                                     // if last mode was cooling, make sure heating flow rate is used
   10341            8 :                                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).OAMixerUsed) {
   10342            7 :                                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOAMixerRetNodeNum).MassFlowRate =
   10343            7 :                                             state.dataHVACVarRefFlow->VRFTU(TUIndex).MaxHeatAirMassFlow;
   10344            7 :                                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOAMixerOANodeNum).MassFlowRate =
   10345            7 :                                             state.dataHVACVarRefFlow->VRFTU(TUIndex).HeatOutAirMassFlow;
   10346            7 :                                         MixedAir::SimOAMixer(state,
   10347            7 :                                                              state.dataHVACVarRefFlow->VRFTU(TUIndex).OAMixerName,
   10348            7 :                                                              state.dataHVACVarRefFlow->VRFTU(TUIndex).OAMixerIndex);
   10349              :                                     } else {
   10350            1 :                                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUInletNodeNum).MassFlowRate =
   10351            1 :                                             state.dataHVACVarRefFlow->VRFTU(TUIndex).MaxHeatAirMassFlow;
   10352              :                                     }
   10353              : 
   10354              :                                     // recalculate using correct flow rate
   10355            8 :                                     if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
   10356              :                                         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
   10357            2 :                                         state.dataHVACVarRefFlow->VRFTU(TUIndex).CalcVRF_FluidTCtrl(
   10358              :                                             state, TUIndex, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   10359              :                                     } else {
   10360              :                                         // Algorithm Type: VRF model based on system curve
   10361            6 :                                         state.dataHVACVarRefFlow->VRFTU(TUIndex).CalcVRF(
   10362              :                                             state, TUIndex, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   10363              :                                     }
   10364              : 
   10365            8 :                                     if (TempOutput < LoadToHeatingSP) {
   10366            8 :                                         ++state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond);
   10367              :                                         // sum heating load on condenser, not total zone heating load
   10368            8 :                                         state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) += (LoadToHeatingSP - TempOutput);
   10369              :                                     }
   10370              :                                 } else {
   10371         1831 :                                     ++state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond);
   10372              :                                     // sum heating load on condenser, not total zone heating load
   10373         1831 :                                     state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) += (LoadToHeatingSP - TempOutput);
   10374              :                                 }
   10375              :                             }
   10376         6582 :                         } else if (TempOutput < ZoneLoad) {
   10377              :                             //             If the net cooling capacity meets the zone cooling load but does not overshoot heating setpoint, turn
   10378              :                             //             off coil do nothing, the zone will float
   10379          785 :                         } else if (ZoneLoad < 0.0) {
   10380              :                             //               still a cooling load
   10381          785 :                             ++state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond);
   10382              :                             // sum cooling load on condenser, not total zone cooling load
   10383          785 :                             state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond) += (LoadToCoolingSP - TempOutput);
   10384              :                         }
   10385              : 
   10386              :                         //           If the terminal unit has a net heating capacity and the zone temp is below the Tstat cooling setpoint
   10387       159259 :                     } else if (TempOutput > 0.0 && LoadToCoolingSP > 0.0) {
   10388              :                         //             If the net heating capacity overshoots the cooling setpoint count as cooling load
   10389        19630 :                         if (TempOutput > LoadToCoolingSP) {
   10390              :                             //               Don't count as cooling load unless mode is allowed. Also check for floating zone.
   10391        10884 :                             if (state.dataHeatBalFanSys->TempControlType(ThisZoneNum) != HVAC::SetptType::SingleHeat &&
   10392         5442 :                                 state.dataHeatBalFanSys->TempControlType(ThisZoneNum) != HVAC::SetptType::Uncontrolled) {
   10393         5442 :                                 if (!state.dataHVACVarRefFlow->LastModeCooling(VRFCond)) {
   10394           31 :                                     if (state.dataHVACVarRefFlow->VRFTU(TUIndex).OAMixerUsed) {
   10395           27 :                                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOAMixerRetNodeNum).MassFlowRate =
   10396           27 :                                             state.dataHVACVarRefFlow->VRFTU(TUIndex).MaxCoolAirMassFlow;
   10397           27 :                                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUOAMixerOANodeNum).MassFlowRate =
   10398           27 :                                             state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolOutAirMassFlow;
   10399           27 :                                         MixedAir::SimOAMixer(state,
   10400           27 :                                                              state.dataHVACVarRefFlow->VRFTU(TUIndex).OAMixerName,
   10401           27 :                                                              state.dataHVACVarRefFlow->VRFTU(TUIndex).OAMixerIndex);
   10402              :                                     } else {
   10403            4 :                                         state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(TUIndex).VRFTUInletNodeNum).MassFlowRate =
   10404            4 :                                             state.dataHVACVarRefFlow->VRFTU(TUIndex).MaxCoolAirMassFlow;
   10405              :                                     }
   10406              : 
   10407           31 :                                     if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
   10408              :                                         // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
   10409            6 :                                         state.dataHVACVarRefFlow->VRFTU(TUIndex).CalcVRF_FluidTCtrl(
   10410              :                                             state, TUIndex, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   10411              :                                     } else {
   10412              :                                         // Algorithm Type: VRF model based on system curve
   10413           25 :                                         state.dataHVACVarRefFlow->VRFTU(TUIndex).CalcVRF(
   10414              :                                             state, TUIndex, FirstHVACIteration, 0.0, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   10415              :                                     }
   10416              : 
   10417           31 :                                     if (TempOutput > LoadToCoolingSP) {
   10418           31 :                                         ++state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond);
   10419           31 :                                         state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond) += (LoadToCoolingSP - TempOutput);
   10420              :                                     }
   10421              :                                 } else {
   10422         5411 :                                     ++state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond);
   10423         5411 :                                     state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond) += (LoadToCoolingSP - TempOutput);
   10424              :                                 }
   10425              :                             }
   10426        14188 :                         } else if (TempOutput > ZoneLoad) {
   10427              :                             // do nothing, zone will float
   10428        10462 :                         } else if (ZoneLoad > 0.0) {
   10429        10462 :                             ++state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond);
   10430        10462 :                             state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) += ZoneLoad;
   10431              :                         }
   10432              :                         //           ELSE there is no overshoot and the zone has a valid cooling load
   10433       139629 :                     } else if (ZoneLoad < 0.0) {
   10434        75510 :                         ++state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond);
   10435        75510 :                         state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond) += ZoneLoad;
   10436              :                         // ELSE there is no overshoot and the zone has a valid heating load
   10437        64119 :                     } else if (ZoneLoad > 0.0) {
   10438        62017 :                         ++state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond);
   10439        62017 :                         state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) += ZoneLoad;
   10440              :                     }
   10441              :                 } else { // is cycling fan
   10442        49023 :                     if (ZoneLoad > 0.0) {
   10443        16621 :                         ++state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond);
   10444        16621 :                         state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) += ZoneLoad;
   10445        32402 :                     } else if (ZoneLoad < 0.0) {
   10446        29218 :                         ++state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond);
   10447        29218 :                         state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond) += ZoneLoad;
   10448              :                     }
   10449              :                 }
   10450              :             }
   10451              :         }
   10452              :     }
   10453              : 
   10454              :     // Determine operating mode based on VRF type and thermostat control selection
   10455        51606 :     switch (state.dataHVACVarRefFlow->VRF(VRFCond).ThermostatPriority) {
   10456            0 :     case ThermostatCtrlType::ThermostatOffsetPriority: {
   10457            0 :         if (state.dataHVACVarRefFlow->MaxDeltaT(VRFCond) > std::abs(state.dataHVACVarRefFlow->MinDeltaT(VRFCond)) &&
   10458            0 :             state.dataHVACVarRefFlow->MaxDeltaT(VRFCond) > 0.0) {
   10459            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10460            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
   10461            0 :         } else if (state.dataHVACVarRefFlow->MaxDeltaT(VRFCond) < std::abs(state.dataHVACVarRefFlow->MinDeltaT(VRFCond)) &&
   10462            0 :                    state.dataHVACVarRefFlow->MinDeltaT(VRFCond) < 0.0) {
   10463            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
   10464            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10465              :         } else {
   10466            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10467            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10468              :         }
   10469            0 :     } break;
   10470        47837 :     case ThermostatCtrlType::LoadPriority: {
   10471        68070 :         if (state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) > std::abs(state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond)) &&
   10472        20233 :             state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) > 0.0) {
   10473        20233 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
   10474        20233 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10475        55208 :         } else if (state.dataHVACVarRefFlow->SumHeatingLoads(VRFCond) <= std::abs(state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond)) &&
   10476        27604 :                    state.dataHVACVarRefFlow->SumCoolingLoads(VRFCond) < 0.0) {
   10477        25909 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10478        25909 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
   10479              :         } else {
   10480         1695 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10481         1695 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10482              :         }
   10483        47837 :     } break;
   10484            0 :     case ThermostatCtrlType::ZonePriority: {
   10485            0 :         if (state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond) > state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond) &&
   10486            0 :             state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond) > 0) {
   10487            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
   10488            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10489            0 :         } else if (state.dataHVACVarRefFlow->NumHeatingLoads(VRFCond) <= state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond) &&
   10490            0 :                    state.dataHVACVarRefFlow->NumCoolingLoads(VRFCond) > 0) {
   10491            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10492            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
   10493              :         } else {
   10494            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10495            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10496              :         }
   10497            0 :     } break;
   10498            0 :     case ThermostatCtrlType::ScheduledPriority: {
   10499            0 :         if (state.dataHVACVarRefFlow->VRF(VRFCond).prioritySched->getCurrentVal() == 0) {
   10500            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
   10501            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10502            0 :         } else if (state.dataHVACVarRefFlow->VRF(VRFCond).prioritySched->getCurrentVal() == 1) {
   10503            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10504            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
   10505              :         } else {
   10506            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10507            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10508              :         }
   10509            0 :     } break;
   10510         3769 :     case ThermostatCtrlType::MasterThermostatPriority: {
   10511         3769 :         ZoneLoad = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRF(VRFCond).MasterZonePtr).RemainingOutputRequired /
   10512         3769 :                    state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->VRF(VRFCond).MasterZoneTUIndex).controlZoneMassFlowFrac;
   10513         3769 :         if (state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->VRF(VRFCond).MasterZoneTUIndex).fanOp == HVAC::FanOp::Continuous) {
   10514         3755 :             SetCompFlowRate(state, state.dataHVACVarRefFlow->VRF(VRFCond).MasterZoneTUIndex, VRFCond);
   10515              : 
   10516         3755 :             if (state.dataHVACVarRefFlow->VRF(VRFCond).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
   10517              :                 // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
   10518            0 :                 state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->VRF(VRFCond).MasterZoneTUIndex)
   10519            0 :                     .CalcVRF_FluidTCtrl(state,
   10520            0 :                                         state.dataHVACVarRefFlow->VRF(VRFCond).MasterZoneTUIndex,
   10521              :                                         FirstHVACIteration,
   10522              :                                         0.0,
   10523              :                                         TempOutput,
   10524              :                                         OnOffAirFlowRatio,
   10525              :                                         SuppHeatCoilLoad);
   10526              :             } else {
   10527              :                 // Algorithm Type: VRF model based on system curve
   10528         3755 :                 state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->VRF(VRFCond).MasterZoneTUIndex)
   10529         7510 :                     .CalcVRF(state,
   10530         3755 :                              state.dataHVACVarRefFlow->VRF(VRFCond).MasterZoneTUIndex,
   10531              :                              FirstHVACIteration,
   10532              :                              0.0,
   10533              :                              TempOutput,
   10534              :                              OnOffAirFlowRatio,
   10535              :                              SuppHeatCoilLoad);
   10536              :             }
   10537              : 
   10538         3755 :             LoadToCoolingSP =
   10539         3755 :                 state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRF(VRFCond).MasterZonePtr).OutputRequiredToCoolingSP /
   10540         3755 :                 state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->VRF(VRFCond).MasterZoneTUIndex).controlZoneMassFlowFrac;
   10541         3755 :             LoadToHeatingSP =
   10542         3755 :                 state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRF(VRFCond).MasterZonePtr).OutputRequiredToHeatingSP /
   10543         3755 :                 state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->VRF(VRFCond).MasterZoneTUIndex).controlZoneMassFlowFrac;
   10544         3755 :             if (TempOutput < LoadToHeatingSP) {
   10545         1456 :                 state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10546         1456 :                 state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
   10547         2299 :             } else if (TempOutput > LoadToCoolingSP) {
   10548         1674 :                 state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
   10549         1674 :                 state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10550              :             } else {
   10551          625 :                 state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10552          625 :                 state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10553              :             }
   10554           14 :         } else if (ZoneLoad > 0.0) {
   10555            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = true;
   10556            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10557           14 :         } else if (ZoneLoad < 0.0) {
   10558            0 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10559            0 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = true;
   10560              :         } else {
   10561           14 :             state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10562           14 :             state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   10563              :         }
   10564         3769 :     } break;
   10565            0 :     case ThermostatCtrlType::FirstOnPriority: {
   10566              :         // na
   10567            0 :     } break;
   10568            0 :     default:
   10569            0 :         break;
   10570              :     }
   10571              : 
   10572              :     // limit to one possible mode
   10573        51606 :     if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) {
   10574            0 :         state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   10575              :     }
   10576        51606 : }
   10577              : 
   10578         3455 : void LimitTUCapacity(EnergyPlusData &state,
   10579              :                      int const VRFCond,               // Condenser Unit index
   10580              :                      int const NumTUInList,           // Number of terminal units in list
   10581              :                      Real64 const StartingCapacity,   // temporary variable holding condenser capacity [W]
   10582              :                      const Array1D<Real64> &CapArray, // Array of coil capacities in either cooling or heating mode [W]
   10583              :                      Real64 &MaxLimit,                // Maximum terminal unit capacity for coils in same operating mode [W]
   10584              :                      Real64 const AltCapacity,        // temporary variable holding heat recovery capacity [W]
   10585              :                      const Array1D<Real64> &AltArray, // Array of coil capacities of heat recovery [W]
   10586              :                      Real64 &AltLimit                 // Maximum terminal unit capacity of heat recovery coils [W]
   10587              : )
   10588              : {
   10589              : 
   10590              :     // SUBROUTINE INFORMATION:
   10591              :     //       AUTHOR         Richard Raustad
   10592              :     //       DATE WRITTEN   July 2012 (Moved from InitVRF)
   10593              :     //       MODIFIED       na
   10594              :     //       RE-ENGINEERED  na
   10595              : 
   10596              :     // PURPOSE OF THIS SUBROUTINE:
   10597              :     // Calculate the maximum allowed terminal unit capacity. Total terminal unit capacity must not
   10598              :     // exceed the available condenser capacity. This variable, MaxCapacity (passed out to MaxCoolingCapacity
   10599              :     // or MaxHeatingCapacity), is used to limit the terminal units providing more capacity than allowed.
   10600              :     // Example: TU loads are 1-ton, 2-ton, 3-ton, and 4-ton connected to a condenser having only 9-tons available.
   10601              :     // This variable is will be set to 3-tons and the 4-ton terminal unit will be limited to 3-tons
   10602              :     // (see InitVRF where this variable is reset and CalcVRF where the call to the DX coils passes this argument).
   10603              : 
   10604              :     // METHODOLOGY EMPLOYED:
   10605              :     // The coils are simulated and summed. This value is compared to the available capacity. If the summed
   10606              :     // TU capacity is greater than the available capacity, limit the TU's with the highest capacity so that
   10607              :     // the TU capacity equals the available capacity. The report variable Variable Refrigerant Flow Heat Pump
   10608              :     // Maximum Terminal Unit Cool/Heating Capacity holds the value for maximum TU capacity. This value may not
   10609              :     // match the maximum individual coil capacity exactly since the available capacity uses a load weighted
   10610              :     // average WB temperature to calculate available capacity. When the TU's are limited, this weighting changes.
   10611              :     // The extra iterations required for these values to converge is considered excessive.
   10612              :     // If the global flag SimZoneEquipment could be set for 1 additional iteration, these variables would
   10613              :     // converge more closely (setting this global flag is not yet implemented).
   10614              : 
   10615              :     Real64 RemainingCapacity; // decrement capacity counter to find limiting TU capacity [W]
   10616              : 
   10617              :     // limit TU coil capacity to be equal to the condenser capacity (piping losses already accounted for)
   10618         3455 :     LimitCoilCapacity(NumTUInList, StartingCapacity, CapArray, MaxLimit);
   10619              : 
   10620              :     // ** add in logic to limit coils operating opposite to mode when heat recovery is used
   10621              :     // ** this is a hard one since we are here because the system is overloaded. That means
   10622              :     // ** that we do not know at this point the actual operating capacity or compressor power.
   10623         3455 :     if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed) {
   10624            1 :         if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) {
   10625            0 :             RemainingCapacity = StartingCapacity * (1 + 1 / state.dataHVACVarRefFlow->VRF(VRFCond).CoolingCOP);
   10626            0 :             if (AltCapacity > RemainingCapacity) {
   10627            0 :                 LimitCoilCapacity(NumTUInList, RemainingCapacity, AltArray, AltLimit);
   10628              :             }
   10629              :         }
   10630            1 :         if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) {
   10631            1 :             RemainingCapacity = StartingCapacity / (1 + 1 / state.dataHVACVarRefFlow->VRF(VRFCond).HeatingCOP);
   10632            1 :             if (AltCapacity > RemainingCapacity) {
   10633            0 :                 LimitCoilCapacity(NumTUInList, RemainingCapacity, AltArray, AltLimit);
   10634              :             }
   10635              :         }
   10636              :     }
   10637         3455 : }
   10638              : 
   10639         3455 : void LimitCoilCapacity(int const NumTUInList,           // Number of terminal units in list
   10640              :                        Real64 const TotalCapacity,      // temporary variable holding condenser capacity [W]
   10641              :                        const Array1D<Real64> &CapArray, // Array of coil capacities in either cooling or heating mode [W]
   10642              :                        Real64 &MaxLimit                 // Maximum terminal unit capacity for coils in same operating mode [W]
   10643              : )
   10644              : {
   10645              : 
   10646              :     // SUBROUTINE INFORMATION:
   10647              :     //       AUTHOR         Richard Raustad
   10648              :     //       DATE WRITTEN   July 2012 (Moved from InitVRF)
   10649              :     //       MODIFIED       na
   10650              :     //       RE-ENGINEERED  na
   10651              : 
   10652              :     // PURPOSE OF THIS SUBROUTINE:
   10653              :     // Calculate the maximum allowed terminal unit capacity. Total terminal unit capacity must not
   10654              :     // exceed the available condenser capacity. This variable, MaxCapacity (passed out to MaxCoolingCapacity
   10655              :     // or MaxHeatingCapacity), is used to limit the terminal units providing more capacity than allowed.
   10656              :     // Example: TU loads are 1-ton, 2-ton, 3-ton, and 4-ton connected to a condenser having only 9-tons available.
   10657              :     // This variable is will be set to 3-tons and the 4-ton terminal unit will be limited to 3-tons
   10658              :     // (see InitVRF where this variable is reset and CalcVRF where the call to the DX coils passes this argument).
   10659              : 
   10660              :     // METHODOLOGY EMPLOYED:
   10661              :     // The coils are simulated and summed. This value is compared to the available capacity. If the summed
   10662              :     // TU capacity is greater than the available capacity, limit the TU's with the highest capacity so that
   10663              :     // the TU capacity equals the available capacity. The report variable Variable Refrigerant Flow Heat Pump
   10664              :     // Maximum Terminal Unit Cool/Heating Capacity holds the value for maximum TU capacity. This value may not
   10665              :     // match the maximum individual coil capacity exactly since the available capacity uses a load weighted
   10666              :     // average WB temperature to calculate available capacity. When the TU's are limited, this weighting changes.
   10667              :     // The extra iterations required for these values to converge is considered excessive.
   10668              :     // If the global flag SimZoneEquipment could be set for 1 additional iteration, these variables would
   10669              :     // converge more closely (setting this global flag is not yet implemented).
   10670              : 
   10671              :     int NumTU;                                   // loop counter
   10672              :     int TempTUIndex;                             // temp variable used to find max terminal unit limit
   10673              :     int MinOutputIndex;                          // index to TU with lowest load
   10674              :     Real64 MinOutput;                            // used when finding TU "max" capacity limit
   10675              :     Real64 RemainingCapacity;                    // decrement capacity counter to find limiting TU capacity [W]
   10676         3455 :     Array1D<Real64> Temp(NumTUInList, CapArray); // temporary array for processing terminal units
   10677         3455 :     Array1D<Real64> Temp2(NumTUInList, Temp);    // temporary array for processing terminal units
   10678              : 
   10679         3455 :     RemainingCapacity = TotalCapacity;
   10680              : 
   10681              :     // sort TU capacity from lowest to highest
   10682        12626 :     for (TempTUIndex = 1; TempTUIndex <= NumTUInList; ++TempTUIndex) {
   10683         9171 :         MinOutput = Constant::MaxCap;
   10684        46924 :         for (NumTU = 1; NumTU <= NumTUInList; ++NumTU) {
   10685        37753 :             if (Temp2(NumTU) < MinOutput) {
   10686        13554 :                 MinOutput = Temp2(NumTU);
   10687        13554 :                 Temp(TempTUIndex) = MinOutput;
   10688        13554 :                 MinOutputIndex = NumTU;
   10689              :             }
   10690              :         }
   10691         9171 :         Temp2(MinOutputIndex) = Constant::MaxCap;
   10692              :     }
   10693              : 
   10694              :     // find limit of "terminal unit" capacity so that sum of all TU's does not exceed condenser capacity
   10695              :     // if the terminal unit capacity multiplied by number of remaining TU's does not exceed remaining available, subtract and cycle
   10696         7226 :     for (TempTUIndex = 1; TempTUIndex <= NumTUInList; ++TempTUIndex) {
   10697         7219 :         if ((Temp(TempTUIndex) * (NumTUInList - TempTUIndex + 1)) < RemainingCapacity) {
   10698         3771 :             RemainingCapacity -= Temp(TempTUIndex);
   10699         3771 :             continue;
   10700              :         } else {
   10701              :             // if it does exceed, limit is found
   10702         3448 :             MaxLimit = RemainingCapacity / (NumTUInList - TempTUIndex + 1);
   10703         3448 :             break;
   10704              :         }
   10705              :     }
   10706         3455 : }
   10707              : 
   10708        14810 : int GetVRFTUOutAirNode(EnergyPlusData &state, int const VRFTUNum)
   10709              : {
   10710              : 
   10711              :     // FUNCTION INFORMATION:
   10712              :     //       AUTHOR         R. Raustad (copy of B Griffith routine)
   10713              :     //       DATE WRITTEN   Jan  2015
   10714              :     //       MODIFIED       na
   10715              :     //       RE-ENGINEERED  na
   10716              : 
   10717              :     // PURPOSE OF THIS FUNCTION:
   10718              :     // lookup function for VRF terminal unit OA inlet node
   10719              : 
   10720        14810 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) {
   10721            0 :         GetVRFInput(state);
   10722            0 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
   10723              :     }
   10724              : 
   10725        14810 :     if (VRFTUNum > 0 && VRFTUNum <= state.dataHVACVarRefFlow->NumVRFTU) {
   10726        14810 :         return state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerOANodeNum;
   10727              :     } else {
   10728            0 :         return 0;
   10729              :     }
   10730              : }
   10731              : 
   10732        14810 : int GetVRFTUZoneInletAirNode(EnergyPlusData &state, int const VRFTUNum)
   10733              : {
   10734              : 
   10735              :     // FUNCTION INFORMATION:
   10736              :     //       AUTHOR         R. Raustad (copy of B Griffith routine)
   10737              :     //       DATE WRITTEN   Jan  2015
   10738              :     //       MODIFIED       na
   10739              :     //       RE-ENGINEERED  na
   10740              : 
   10741              :     // PURPOSE OF THIS FUNCTION:
   10742              :     // lookup function for VRF terminal unit zone inlet node
   10743              : 
   10744        14810 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) {
   10745            0 :         GetVRFInput(state);
   10746            0 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
   10747              :     }
   10748              : 
   10749        14810 :     if (VRFTUNum > 0 && VRFTUNum <= state.dataHVACVarRefFlow->NumVRFTU) {
   10750        14810 :         return state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOutletNodeNum;
   10751              :     } else {
   10752            0 :         return 0;
   10753              :     }
   10754              : }
   10755              : 
   10756            0 : int GetVRFTUOutAirNodeFromName(EnergyPlusData &state, std::string const &VRFTUName, bool &errorsFound)
   10757              : {
   10758              :     int NodeNum; // return value of node number
   10759              : 
   10760            0 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) {
   10761            0 :         GetVRFInput(state);
   10762            0 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
   10763              :     }
   10764              : 
   10765              :     int WhichVRFTU =
   10766            0 :         Util::FindItemInList(VRFTUName, state.dataHVACVarRefFlow->VRFTU, &VRFTerminalUnitEquipment::Name, state.dataHVACVarRefFlow->NumVRFTU);
   10767            0 :     if (WhichVRFTU != 0) {
   10768            0 :         NodeNum = state.dataHVACVarRefFlow->VRFTU(WhichVRFTU).VRFTUOutletNodeNum;
   10769              :     } else {
   10770            0 :         ShowSevereError(state, format("GetVRFTUOutAirNodeFromName: Could not find VRF TU = \"{}\"", VRFTUName));
   10771            0 :         errorsFound = true;
   10772            0 :         NodeNum = 0;
   10773              :     }
   10774              : 
   10775            0 :     return NodeNum;
   10776              : }
   10777              : 
   10778            0 : int GetVRFTUInAirNodeFromName(EnergyPlusData &state, std::string const &VRFTUName, bool &errorsFound)
   10779              : {
   10780              :     int NodeNum; // return value of node number
   10781              : 
   10782            0 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) {
   10783            0 :         GetVRFInput(state);
   10784            0 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
   10785              :     }
   10786              : 
   10787              :     int WhichVRFTU =
   10788            0 :         Util::FindItemInList(VRFTUName, state.dataHVACVarRefFlow->VRFTU, &VRFTerminalUnitEquipment::Name, state.dataHVACVarRefFlow->NumVRFTU);
   10789            0 :     if (WhichVRFTU != 0) {
   10790            0 :         NodeNum = state.dataHVACVarRefFlow->VRFTU(WhichVRFTU).VRFTUInletNodeNum;
   10791              :     } else {
   10792            0 :         ShowSevereError(state, format("GetVRFTUInAirNodeFromName: Could not find VRF TU = \"{}\"", VRFTUName));
   10793            0 :         errorsFound = true;
   10794            0 :         NodeNum = 0;
   10795              :     }
   10796              : 
   10797            0 :     return NodeNum;
   10798              : }
   10799              : 
   10800        14810 : int GetVRFTUMixedAirNode(EnergyPlusData &state, int const VRFTUNum)
   10801              : {
   10802              : 
   10803              :     // FUNCTION INFORMATION:
   10804              :     //       AUTHOR         R. Raustad (copy of B Griffith routine)
   10805              :     //       DATE WRITTEN   Jan  2015
   10806              :     //       MODIFIED       na
   10807              :     //       RE-ENGINEERED  na
   10808              : 
   10809              :     // PURPOSE OF THIS FUNCTION:
   10810              :     // lookup function for VRF terminal unit mixed air node
   10811              : 
   10812        14810 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) {
   10813            0 :         GetVRFInput(state);
   10814            0 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
   10815              :     }
   10816              : 
   10817        14810 :     if (VRFTUNum > 0 && VRFTUNum <= state.dataHVACVarRefFlow->NumVRFTU) {
   10818        14810 :         return state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerOANodeNum;
   10819              :     } else {
   10820            0 :         return 0;
   10821              :     }
   10822              : }
   10823              : 
   10824        14810 : int GetVRFTUReturnAirNode(EnergyPlusData &state, int const VRFTUNum)
   10825              : {
   10826              : 
   10827              :     // FUNCTION INFORMATION:
   10828              :     //       AUTHOR         R. Raustad (copy of B Griffith routine)
   10829              :     //       DATE WRITTEN   Jan  2015
   10830              :     //       MODIFIED       na
   10831              :     //       RE-ENGINEERED  na
   10832              : 
   10833              :     // PURPOSE OF THIS FUNCTION:
   10834              :     // lookup function for VRF terminal unit return air node
   10835              : 
   10836        14810 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) {
   10837            0 :         GetVRFInput(state);
   10838            0 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
   10839              :     }
   10840              : 
   10841        14810 :     if (VRFTUNum > 0 && VRFTUNum <= state.dataHVACVarRefFlow->NumVRFTU) {
   10842        14810 :         return state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOAMixerRetNodeNum;
   10843              :     } else {
   10844            0 :         return 0;
   10845              :     }
   10846              : }
   10847              : 
   10848            0 : int getEqIndex(EnergyPlusData &state, std::string_view VRFTUName)
   10849              : {
   10850            0 :     if (state.dataHVACVarRefFlow->GetVRFInputFlag) {
   10851            0 :         GetVRFInput(state);
   10852            0 :         state.dataHVACVarRefFlow->GetVRFInputFlag = false;
   10853              :     }
   10854              : 
   10855            0 :     for (int VRFTUNum = 1; VRFTUNum <= state.dataHVACVarRefFlow->NumVRFTU; VRFTUNum++) {
   10856            0 :         if (Util::SameString(VRFTUName, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).Name)) {
   10857            0 :             return VRFTUNum;
   10858              :         }
   10859              :     }
   10860            0 :     return 0;
   10861              : }
   10862              : 
   10863       496885 : void getVRFTUZoneLoad(
   10864              :     EnergyPlusData &state, int const VRFTUNum, Real64 &zoneLoad, Real64 &LoadToHeatingSP, Real64 &LoadToCoolingSP, bool const InitFlag)
   10865              : {
   10866              : 
   10867       496885 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).zoneSequenceCoolingNum > 0 &&
   10868       496885 :         state.dataHVACVarRefFlow->VRFTU(VRFTUNum).zoneSequenceHeatingNum > 0 && state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isInAirLoop) {
   10869              :         // air loop equipment uses sequenced variables
   10870         6380 :         LoadToCoolingSP = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum)
   10871         6380 :                               .SequencedOutputRequiredToCoolingSP(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).zoneSequenceCoolingNum) /
   10872         6380 :                           state.dataHVACVarRefFlow->VRFTU(VRFTUNum).controlZoneMassFlowFrac;
   10873         6380 :         LoadToHeatingSP = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum)
   10874         6380 :                               .SequencedOutputRequiredToHeatingSP(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).zoneSequenceHeatingNum) /
   10875         6380 :                           state.dataHVACVarRefFlow->VRFTU(VRFTUNum).controlZoneMassFlowFrac;
   10876         9004 :         if (LoadToHeatingSP > 0.0 && LoadToCoolingSP > 0.0 &&
   10877         2624 :             state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::SingleCool) {
   10878         2624 :             zoneLoad = LoadToHeatingSP;
   10879         3756 :         } else if (LoadToHeatingSP > 0.0 && LoadToCoolingSP > 0.0 &&
   10880            0 :                    state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) == HVAC::SetptType::SingleCool) {
   10881            0 :             zoneLoad = 0.0;
   10882         6516 :         } else if (LoadToHeatingSP < 0.0 && LoadToCoolingSP < 0.0 &&
   10883         2760 :                    state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) != HVAC::SetptType::SingleHeat) {
   10884         2760 :             zoneLoad = LoadToCoolingSP;
   10885          996 :         } else if (LoadToHeatingSP < 0.0 && LoadToCoolingSP < 0.0 &&
   10886            0 :                    state.dataHeatBalFanSys->TempControlType(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum) == HVAC::SetptType::SingleHeat) {
   10887            0 :             zoneLoad = 0.0;
   10888          996 :         } else if (LoadToHeatingSP <= 0.0 && LoadToCoolingSP >= 0.0) {
   10889          996 :             zoneLoad = 0.0;
   10890              :         }
   10891       490505 :     } else if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum > 0) {
   10892              :         // zone equipment uses Remaining* variables
   10893       487317 :         if (InitFlag) {
   10894              :             // this will need more investigation. Using Remaining* variable during the initial load calculation seems wrong.
   10895              :             // This may also have implications when VRF TUs are in the air loop or if SP control is used
   10896              :             // another question is whether initialization of the operating mode should look at TotalOutputRequired or RemainingOutputRequired
   10897       217279 :             zoneLoad = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum).RemainingOutputRequired /
   10898       217279 :                        state.dataHVACVarRefFlow->VRFTU(VRFTUNum).controlZoneMassFlowFrac;
   10899       217279 :             LoadToCoolingSP =
   10900       217279 :                 state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum).OutputRequiredToCoolingSP /
   10901       217279 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).controlZoneMassFlowFrac;
   10902       217279 :             LoadToHeatingSP =
   10903       217279 :                 state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum).OutputRequiredToHeatingSP /
   10904       217279 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).controlZoneMassFlowFrac;
   10905              :         } else {
   10906       270038 :             zoneLoad = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum).RemainingOutputRequired /
   10907       270038 :                        state.dataHVACVarRefFlow->VRFTU(VRFTUNum).controlZoneMassFlowFrac;
   10908       270038 :             LoadToCoolingSP =
   10909       270038 :                 state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum).RemainingOutputReqToCoolSP /
   10910       270038 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).controlZoneMassFlowFrac;
   10911       270038 :             LoadToHeatingSP =
   10912       270038 :                 state.dataZoneEnergyDemand->ZoneSysEnergyDemand(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).ZoneNum).RemainingOutputReqToHeatSP /
   10913       270038 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).controlZoneMassFlowFrac;
   10914              :         }
   10915         3188 :     } else if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isSetPointControlled) {
   10916         3188 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).coolSPActive) {
   10917         1810 :             LoadToCoolingSP = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).coolLoadToSP;
   10918         1810 :             zoneLoad = LoadToCoolingSP;
   10919         1810 :             LoadToHeatingSP = 0.0;
   10920              :         }
   10921         3188 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).heatSPActive) {
   10922         1365 :             LoadToHeatingSP = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).heatLoadToSP;
   10923         1365 :             zoneLoad = LoadToHeatingSP;
   10924         1365 :             LoadToCoolingSP = 0.0;
   10925              :         }
   10926              :     }
   10927       496885 : }
   10928              : 
   10929           16 : bool getVRFTUNodeNumber(EnergyPlusData &state, int const nodeNumber)
   10930              : {
   10931           16 :     for (int vrfTUIndex = 1; vrfTUIndex <= state.dataHVACVarRefFlow->NumVRFTU; ++vrfTUIndex) {
   10932            0 :         auto const &vrfTU = state.dataHVACVarRefFlow->VRFTU(vrfTUIndex);
   10933              : 
   10934            0 :         bool noVrfTUOutdoorAir = false;
   10935            0 :         if (vrfTU.CoolOutAirVolFlow == 0 && vrfTU.HeatOutAirVolFlow == 0 && vrfTU.NoCoolHeatOutAirVolFlow == 0) {
   10936            0 :             noVrfTUOutdoorAir = true;
   10937              :         }
   10938              : 
   10939            0 :         if (noVrfTUOutdoorAir &&
   10940            0 :             (nodeNumber == vrfTU.VRFTUInletNodeNum || nodeNumber == vrfTU.VRFTUOutletNodeNum || nodeNumber == vrfTU.fanInletNode ||
   10941            0 :              nodeNumber == vrfTU.fanOutletNode || nodeNumber == vrfTU.heatCoilAirOutNode || nodeNumber == vrfTU.coolCoilAirOutNode ||
   10942            0 :              nodeNumber == vrfTU.VRFTUOAMixerOANodeNum || nodeNumber == vrfTU.VRFTUOAMixerRelNodeNum || nodeNumber == vrfTU.VRFTUOAMixerRetNodeNum ||
   10943            0 :              nodeNumber == vrfTU.VRFTUOAMixerMixedNodeNum || nodeNumber == vrfTU.SuppHeatCoilAirInletNode ||
   10944            0 :              nodeNumber == vrfTU.SuppHeatCoilAirOutletNode)) {
   10945            0 :             return true;
   10946              :         }
   10947              :     }
   10948           16 :     return false;
   10949              : }
   10950              : 
   10951        14999 : void VRFCondenserEquipment::CalcVRFIUTeTc_FluidTCtrl(EnergyPlusData &state)
   10952              : {
   10953              :     // SUBROUTINE INFORMATION:
   10954              :     //       AUTHOR         RP Zhang (LBNL), XF Pang (LBNL), Y Yura (Daikin Inc)
   10955              :     //       DATE WRITTEN   June 2015
   10956              :     //       MODIFIED       na
   10957              :     //       RE-ENGINEERED  na
   10958              : 
   10959              :     // PURPOSE OF THIS SUBROUTINE:
   10960              :     //       This subroutine is part of the new VRF model based on physics, applicable for Fluid Temperature Control.
   10961              :     //       This subroutine determines the VRF evaporating temperature at cooling mode and the condensing temperature
   10962              :     //       at heating mode. This is the indoor unit side analysis.
   10963              : 
   10964              :     // METHODOLOGY EMPLOYED:
   10965              :     //       There are two options to calculate the IU Te/Tc: (1) HighSensible method analyzes the conditions of each IU
   10966              :     //       and then decide and Te/Tc that can satisfy all the zones (2) TeTcConstant method uses fixed values provided
   10967              :     //       by the user.
   10968              : 
   10969              :     // Followings for FluidTCtrl Only
   10970        14999 :     Array1D<Real64> EvapTemp;
   10971        14999 :     Array1D<Real64> CondTemp;
   10972              :     Real64 IUMinEvapTemp;
   10973              :     Real64 IUMaxCondTemp;
   10974              : 
   10975        14999 :     int TUListNum = this->ZoneTUListPtr;
   10976        14999 :     EvapTemp.allocate(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList);
   10977        14999 :     CondTemp.allocate(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList);
   10978        14999 :     IUMinEvapTemp = 100.0;
   10979        14999 :     IUMaxCondTemp = 0.0;
   10980              : 
   10981        14999 :     if (this->AlgorithmIUCtrl == 1) {
   10982              :         // 1. HighSensible: analyze the conditions of each IU
   10983              : 
   10984        30690 :         for (int i = 1; i <= state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList; i++) {
   10985        22471 :             int VRFTUNum = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(i);
   10986              :             // analyze the conditions of each IU
   10987        22471 :             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRFIUVariableTeTc(state, EvapTemp(i), CondTemp(i));
   10988              : 
   10989              :             // select the Te/Tc that can satisfy all the zones
   10990        22471 :             IUMinEvapTemp = min(IUMinEvapTemp, EvapTemp(i), this->IUEvapTempHigh);
   10991        22471 :             IUMaxCondTemp = max(IUMaxCondTemp, CondTemp(i), this->IUCondTempLow);
   10992              :         }
   10993              : 
   10994         8219 :         this->IUEvaporatingTemp = max(IUMinEvapTemp, this->IUEvapTempLow);
   10995         8219 :         this->IUCondensingTemp = min(IUMaxCondTemp, this->IUCondTempHigh);
   10996              : 
   10997              :     } else {
   10998              :         // 2. TeTcConstant: use fixed values provided by the user
   10999         6780 :         this->IUEvaporatingTemp = this->EvapTempFixed;
   11000         6780 :         this->IUCondensingTemp = this->CondTempFixed;
   11001              :     }
   11002        14999 : }
   11003              : 
   11004        22471 : void VRFTerminalUnitEquipment::CalcVRFIUVariableTeTc(EnergyPlusData &state,
   11005              :                                                      Real64 &EvapTemp, // evaporating temperature
   11006              :                                                      Real64 &CondTemp  // condensing temperature
   11007              : )
   11008              : {
   11009              :     // SUBROUTINE INFORMATION:
   11010              :     //       AUTHOR         Xiufeng Pang, LBNL
   11011              :     //       DATE WRITTEN   Feb 2014
   11012              :     //       MODIFIED       Jul 2015, RP Zhang, LBNL, Modify the bounds of the Te/Tc
   11013              :     //       MODIFIED       Nov 2015, RP Zhang, LBNL, take into account OA in Te/Tc determination
   11014              :     //       RE-ENGINEERED  na
   11015              : 
   11016              :     // PURPOSE OF THIS SUBROUTINE:
   11017              :     //       Calculate the VRF IU Te (cooling mode) and Tc (heating mode), given zonal loads.
   11018              : 
   11019              :     // METHODOLOGY EMPLOYED:
   11020              :     //       A new physics based VRF model applicable for Fluid Temperature Control.
   11021              : 
   11022              :     using namespace DataZoneEnergyDemands;
   11023              :     using Psychrometrics::PsyHFnTdbW;
   11024              :     using SingleDuct::SimATMixer;
   11025              : 
   11026              :     int CoolCoilNum;             // index to the VRF Cooling DX coil to be simulated
   11027              :     int HeatCoilNum;             // index to the VRF Heating DX coil to be simulated
   11028              :     int IndexToTUInTUList;       // index to TU in specific list for the VRF system
   11029              :     int TUListIndex;             // index to TU list for this VRF system
   11030              :     int VRFNum;                  // index to VRF that the VRF Terminal Unit serves
   11031              :     int VRFInletNode;            // VRF inlet node number
   11032              :     Real64 BFC;                  // Bypass factor at the cooling mode (-)
   11033              :     Real64 BFH;                  // Bypass factor at the heating mode (-)
   11034              :     Real64 C1Tevap;              // Coefficient for indoor unit coil evaporating temperature curve (-)
   11035              :     Real64 C2Tevap;              // Coefficient for indoor unit coil evaporating temperature curve (-)
   11036              :     Real64 C3Tevap;              // Coefficient for indoor unit coil evaporating temperature curve (-)
   11037              :     Real64 C1Tcond;              // Coefficient for indoor unit coil condensing temperature curve (-)
   11038              :     Real64 C2Tcond;              // Coefficient for indoor unit coil condensing temperature curve (-)
   11039              :     Real64 C3Tcond;              // Coefficient for indoor unit coil condensing temperature curve (-)
   11040              :     Real64 CondTempMin;          // Min condensing temperature (C)
   11041              :     Real64 CondTempMax;          // Max condensing temperature, correspond to the maximum heating capacity (C)
   11042              :     Real64 DeltaT;               // Difference between evaporating/condensing temperature and coil surface temperature (C)
   11043              :     Real64 EvapTempMax;          // Max evaporating temperature (C)
   11044              :     Real64 EvapTempMin;          // Min evaporating temperature, correspond to the maximum cooling capacity (C)
   11045              :     Real64 Garate;               // Nominal air mass flow rate
   11046              :     Real64 H_coil_in;            // Air enthalpy at the coil inlet (kJ/kg)
   11047              :     Real64 QZnReqSenCoolingLoad; // Zone required sensible cooling load (W)
   11048              :     Real64 QZnReqSenHeatingLoad; // Zone required sensible heating load (W)
   11049              :     Real64 RHsat;                // Relative humidity of the air at saturated condition(-)
   11050              :     Real64 SH;                   // Super heating degrees (C)
   11051              :     Real64 SC;                   // Subcooling degrees (C)
   11052              :     Real64 T_coil_in;            // Temperature of the air at the coil inlet, after absorbing the heat released by fan (C)
   11053              :     Real64 T_TU_in;              // Air temperature at the indoor unit inlet (C)
   11054              :     Real64 Tout;                 // Air temperature at the indoor unit outlet (C)
   11055              :     Real64 Th2;                  // Air temperature at the coil surface (C)
   11056              :     Real64 W_coil_in;            // coil inlet air humidity ratio [kg/kg]
   11057              :     Real64 W_TU_in;              // Air humidity ratio at the indoor unit inlet[kg/kg]
   11058              : 
   11059              :     // Get the equipment/zone index corresponding to the VRFTU
   11060        22471 :     CoolCoilNum = this->CoolCoilIndex;
   11061        22471 :     HeatCoilNum = this->HeatCoilIndex;
   11062        22471 :     VRFNum = this->VRFSysNum;
   11063        22471 :     TUListIndex = state.dataHVACVarRefFlow->VRF(VRFNum).ZoneTUListPtr;
   11064        22471 :     IndexToTUInTUList = this->IndexToTUInTUList;
   11065              : 
   11066              :     // Bounds of Te/Tc for VRF IU Control Algorithm: VariableTemp
   11067        22471 :     EvapTempMin = state.dataHVACVarRefFlow->VRF(VRFNum).IUEvapTempLow;
   11068        22471 :     EvapTempMax = state.dataHVACVarRefFlow->VRF(VRFNum).IUEvapTempHigh;
   11069        22471 :     CondTempMin = state.dataHVACVarRefFlow->VRF(VRFNum).IUCondTempLow;
   11070        22471 :     CondTempMax = state.dataHVACVarRefFlow->VRF(VRFNum).IUCondTempHigh;
   11071              : 
   11072              :     // Coefficients describing coil performance
   11073        22471 :     SH = state.dataDXCoils->DXCoil(CoolCoilNum).SH;
   11074        22471 :     SC = state.dataDXCoils->DXCoil(HeatCoilNum).SC;
   11075        22471 :     C1Tevap = state.dataDXCoils->DXCoil(CoolCoilNum).C1Te;
   11076        22471 :     C2Tevap = state.dataDXCoils->DXCoil(CoolCoilNum).C2Te;
   11077        22471 :     C3Tevap = state.dataDXCoils->DXCoil(CoolCoilNum).C3Te;
   11078        22471 :     C1Tcond = state.dataDXCoils->DXCoil(HeatCoilNum).C1Tc;
   11079        22471 :     C2Tcond = state.dataDXCoils->DXCoil(HeatCoilNum).C2Tc;
   11080        22471 :     C3Tcond = state.dataDXCoils->DXCoil(HeatCoilNum).C3Tc;
   11081              : 
   11082        22471 :     VRFInletNode = this->VRFTUInletNodeNum;
   11083        22471 :     T_TU_in = state.dataLoopNodes->Node(VRFInletNode).Temp;
   11084        22471 :     W_TU_in = state.dataLoopNodes->Node(VRFInletNode).HumRat;
   11085        22471 :     T_coil_in = this->coilInNodeT;
   11086        22471 :     W_coil_in = this->coilInNodeW;
   11087              : 
   11088        22471 :     Garate = state.dataHVACVarRefFlow->CompOnMassFlow;
   11089        22471 :     H_coil_in = PsyHFnTdbW(T_coil_in, W_coil_in);
   11090        22471 :     RHsat = 0.98;
   11091        22471 :     BFC = 0.0592;
   11092        22471 :     BFH = 0.136;
   11093        22471 :     Real64 ZoneLoad = 0.0;
   11094        22471 :     Real64 LoadToHeatingSP = 0.0;
   11095        22471 :     Real64 LoadToCoolingSP = 0.0;
   11096              : 
   11097              :     // 1. COOLING Mode
   11098        42391 :     if ((Garate > 0.0) && ((!state.dataHVACVarRefFlow->VRF(VRFNum).HeatRecoveryUsed && state.dataHVACVarRefFlow->CoolingLoad(VRFNum)) ||
   11099        19920 :                            (state.dataHVACVarRefFlow->VRF(VRFNum).HeatRecoveryUsed &&
   11100        17810 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList)))) {
   11101              :         // 1.1) Cooling coil is running
   11102        13387 :         getVRFTUZoneLoad(state, IndexToTUInTUList, ZoneLoad, LoadToHeatingSP, LoadToCoolingSP, false);
   11103        13387 :         QZnReqSenCoolingLoad = max(0.0, -1.0 * LoadToCoolingSP);
   11104        13387 :         Tout = T_TU_in - QZnReqSenCoolingLoad * 1.2 / Garate / 1005;
   11105        13387 :         Th2 = T_coil_in - (T_coil_in - Tout) / (1 - BFC);
   11106        13387 :         DeltaT = C3Tevap * SH * SH + C2Tevap * SH + C1Tevap;
   11107        13387 :         EvapTemp = max(min((Th2 - DeltaT), EvapTempMax), EvapTempMin);
   11108              : 
   11109              :     } else {
   11110              :         // 1.2) Cooling coil is not running
   11111         9084 :         EvapTemp = T_coil_in;
   11112              :     }
   11113              : 
   11114              :     // 2. HEATING Mode
   11115        42865 :     if ((Garate > 0.0) && ((!state.dataHVACVarRefFlow->VRF(VRFNum).HeatRecoveryUsed && state.dataHVACVarRefFlow->HeatingLoad(VRFNum)) ||
   11116        20394 :                            (state.dataHVACVarRefFlow->VRF(VRFNum).HeatRecoveryUsed &&
   11117        17810 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList)))) {
   11118              :         // 2.1) Heating coil is running
   11119         8751 :         getVRFTUZoneLoad(state, IndexToTUInTUList, ZoneLoad, LoadToHeatingSP, LoadToCoolingSP, false);
   11120         8751 :         QZnReqSenHeatingLoad = max(0.0, LoadToHeatingSP);
   11121         8751 :         Tout = T_TU_in + QZnReqSenHeatingLoad / Garate / 1005;
   11122         8751 :         Th2 = T_coil_in + (Tout - T_coil_in) / (1 - BFH);
   11123         8751 :         DeltaT = C3Tcond * SC * SC + C2Tcond * SC + C1Tcond;
   11124         8751 :         CondTemp = max(min((Th2 + DeltaT), CondTempMax), CondTempMin);
   11125              :     } else {
   11126              :         // 2.2) Heating coil is not running
   11127        13720 :         CondTemp = T_coil_in;
   11128              :     }
   11129        22471 : }
   11130              : 
   11131        14999 : void VRFCondenserEquipment::CalcVRFCondenser_FluidTCtrl(EnergyPlusData &state, const bool FirstHVACIteration)
   11132              : {
   11133              : 
   11134              :     // SUBROUTINE INFORMATION:
   11135              :     //       AUTHOR         RP Zhang (LBNL), XF Pang (LBNL), Y Yura (Daikin Inc)
   11136              :     //       DATE WRITTEN   June 2015
   11137              :     //       MODIFIED       Feb 2016, RP Zhang, add the control logics for VRF-HR operations
   11138              :     //       RE-ENGINEERED  na
   11139              : 
   11140              :     // PURPOSE OF THIS SUBROUTINE:
   11141              :     //       This subroutine is part of the new VRF model based on physics, applicable for Fluid Temperature Control.
   11142              :     //       This is adapted from subroutine CalcVRFCondenser, which is part of the VRF model based on system curves.
   11143              :     //       This subroutine models the interactions of VRF indoor units with the outdoor unit.
   11144              :     //       The indoor terminal units are simulated first, and then the outdoor unit is simulated.
   11145              : 
   11146              :     // METHODOLOGY EMPLOYED:
   11147              :     //       A new physics based VRF model applicable for Fluid Temperature Control.
   11148              : 
   11149              :     using Curve::CurveValue;
   11150              :     using General::SolveRoot;
   11151              : 
   11152              :     using PlantUtilities::SetComponentFlowRate;
   11153              :     using Psychrometrics::RhoH2O;
   11154              : 
   11155              :     static constexpr std::string_view RoutineName("CalcVRFCondenser_FluidTCtrl");
   11156              : 
   11157              :     int VRFCond;            // index to VRF condenser
   11158              :     int TUListNum;          // index to TU List
   11159              :     int NumTUInList;        // number of terminal units is list
   11160              :     int NumTU;              // index for loop on terminal units
   11161              :     int TUIndex;            // Index to terminal unit
   11162              :     int CoolCoilIndex;      // index to cooling coil in terminal unit
   11163              :     int HeatCoilIndex;      // index to heating coil in terminal unit
   11164              :     int NumTUInCoolingMode; // number of terminal units actually cooling
   11165              :     int NumTUInHeatingMode; // number of terminal units actually heating
   11166              : 
   11167              :     Real64 TUParasiticPower;          // total terminal unit parasitic power (W)
   11168              :     Real64 TUFanPower;                // total terminal unit fan power (W)
   11169              :     Real64 InletAirWetBulbC;          // coil inlet air wet-bulb temperature (C)
   11170              :     Real64 InletAirDryBulbC;          // coil inlet air dry-bulb temperature (C)
   11171              :     Real64 CondInletTemp;             // condenser inlet air temperature (C)
   11172              :     Real64 OutdoorDryBulb;            // outdoor dry-bulb temperature (C)
   11173              :     Real64 OutdoorHumRat;             // outdoor humidity ratio (kg/kg)
   11174              :     Real64 OutdoorPressure;           // outdoor pressure (Pa)
   11175              :     Real64 OutdoorWetBulb;            // outdoor wet-bulb temperature (C)
   11176              :     Real64 SumCoolInletWB;            // sum of active TU's DX cooling coil inlet air wet-bulb temperature
   11177              :     Real64 SumHeatInletDB;            // sum of active TU's DX heating coil inlet air dry-bulb temperature
   11178              :     Real64 SumHeatInletWB;            // sum of active TU's DX heating coil inlet air wet-bulb temperature
   11179              :     Real64 TotalTUCoolingCapacity;    // sum of TU's cooling capacity (W)
   11180              :     Real64 TotalTUHeatingCapacity;    // sum of TU's heating capacity (W)
   11181              :     Real64 TotalCondCoolingCapacity;  // total available condenser cooling capacity (W)
   11182              :     Real64 TotalCondHeatingCapacity;  // total available condenser heating capacity (W)
   11183              :     Real64 CoolingPLR;                // condenser cooling PLR
   11184              :     Real64 HeatingPLR;                // condenser heating PLR
   11185              :     Real64 CyclingRatio;              // cycling ratio of condenser's compressors
   11186              :     int Stage;                        // used for crankcase heater power calculation
   11187              :     Real64 UpperStageCompressorRatio; // used for crankcase heater power calculation
   11188              :     Real64 RhoAir;                    // Density of air [kg/m3]
   11189              :     Real64 PartLoadFraction;          // Part load fraction from PLFFPLR curve
   11190              :     Real64 VRFRTF;                    // VRF runtime fraction when cycling below MINPLR
   11191              :     Real64 OutdoorCoilT;              // Outdoor coil temperature (C)
   11192              :     Real64 OutdoorCoildw;             // Outdoor coil delta w assuming coil temp of OutdoorCoilT (kg/kg)
   11193              :     Real64 FractionalDefrostTime;     // Fraction of time step system is in defrost
   11194              :     Real64 HeatingCapacityMultiplier; // Multiplier for heating capacity when system is in defrost
   11195              :     Real64 InputPowerMultiplier;      // Multiplier for power when system is in defrost
   11196              :     Real64 LoadDueToDefrost;          // Additional load due to defrost
   11197              :     Real64 DefrostEIRTempModFac;      // EIR modifier for defrost (function of entering drybulb, outside wetbulb)
   11198              :     Real64 HRInitialCapFrac;          // Fractional cooling degradation at the start of heat recovery from cooling mode
   11199              :     Real64 HRCapTC;                   // Time constant used to recover from initial degradation in cooling heat recovery
   11200              :     Real64 HRInitialEIRFrac;          // Fractional cooling degradation at the start of heat recovery from cooling mode
   11201              :     Real64 HREIRTC;                   // Time constant used to recover from initial degradation in cooling heat recovery
   11202              :     Real64 CurrentEndTime;            // end time of current time step
   11203              :     Real64 SUMultiplier;              // multiplier for simulating mode changes
   11204              :     Real64 CondPower;                 // condenser power [W]
   11205              :     Real64 CondCapacity;              // condenser heat rejection [W]
   11206              :     Real64 TotPower;                  // total condenser power use [W]
   11207              :     bool HRHeatRequestFlag;           // flag indicating VRF TU could operate in heating mode
   11208              :     bool HRCoolRequestFlag;           // flag indicating VRF TU could operate in cooling mode
   11209              : 
   11210              :     // Followings for VRF FluidTCtrl Only
   11211              :     int Counter;                     // index for iterations [-]
   11212              :     int NumIteHIUIn;                 // index for HIU calculation iterations [-]
   11213              :     int NumOfCompSpdInput;           // Number of compressor speed input by the user [-]
   11214              :     Real64 CompSpdActual;            // Actual compressor running speed [rps]
   11215              :     Real64 C_cap_operation;          // Compressor capacity modification algorithm_modified Cap [-]
   11216              :     Real64 CompEvaporatingCAPSpdMin; // evaporating capacity at the lowest compressor speed [W]
   11217              :     Real64 CompEvaporatingCAPSpdMax; // evaporating capacity at the highest compressor speed [W]
   11218              :     Real64 CompEvaporatingPWRSpdMin; // compressor power at the lowest compressor speed [W]
   11219              :     Real64 CompEvaporatingPWRSpdMax; // compressor power at the highest compressor speed [W]
   11220              :     Real64 CapMaxTe;                 // maximum Te during operation, for capacity calculations [C]
   11221              :     Real64 CapMinTe;                 // minimum Te during operation, for capacity calculations [C]
   11222              :     Real64 CapMinPe;                 // minimum Pe during operation, for capacity calculations [Pa]
   11223              :     Real64 CapMaxTc;                 // maximum Tc during operation, for capacity calculations [C]
   11224              :     Real64 CapMaxPc;                 // maximum Pc during operation, for capacity calculations [Pa]
   11225              :     Real64 CapMinTc;                 // minimum Tc during operation, for capacity calculations [C]
   11226              :     Real64 CapMinPc;                 // minimum Pc during operation, for capacity calculations [Pa]
   11227              :     Real64 h_IU_evap_in;             // enthalpy of IU evaporator at inlet [kJ/kg]
   11228              :     Real64 h_IU_evap_in_new;         // enthalpy of IU evaporator at inlet (new) [kJ/kg]
   11229              :     Real64 h_IU_evap_in_low;         // enthalpy of IU evaporator at inlet (low) [kJ/kg]
   11230              :     Real64 h_IU_evap_in_up;          // enthalpy of IU evaporator at inlet (up) [kJ/kg]
   11231              :     Real64 h_IU_evap_out;            // enthalpy of IU evaporator at outlet [kJ/kg]
   11232              :     Real64 h_IU_evap_out_i;          // enthalpy of IU evaporator at outlet (individual) [kJ/kg]
   11233              :     Real64 h_IU_cond_in;             // enthalpy of IU condenser at inlet [kJ/kg]
   11234              :     Real64 h_IU_cond_in_low;         // enthalpy of IU condenser at inlet (low) [kJ/kg]
   11235              :     Real64 h_IU_cond_in_up;          // enthalpy of IU condenser at inlet (up) [kJ/kg]
   11236              :     Real64 h_IU_cond_out;            // enthalpy of IU condenser at outlet [kJ/kg]
   11237              :     Real64 h_IU_cond_out_i;          // enthalpy of IU condenser at outlet (individual) [kJ/kg]
   11238              :     Real64 h_IU_cond_out_ave;        // average enthalpy of the refrigerant leaving IU condensers [kJ/kg]
   11239              :     Real64 h_IU_PLc_out;             // enthalpy of refrigerant at the outlet of IU evaporator side main pipe, after piping loss (c) [kJ/kg]
   11240              :     Real64 h_comp_in;                // enthalpy of refrigerant at compressor inlet, after piping loss (c) [kJ/kg]
   11241              :     Real64 h_comp_in_new;            // enthalpy of refrigerant at compressor inlet (new) [kJ/kg]
   11242              :     Real64 h_comp_out;               // enthalpy of refrigerant at compressor outlet [kJ/kg]
   11243              :     Real64 h_comp_out_new;           // enthalpy of refrigerant at compressor outlet (new) [kJ/kg]
   11244              :     Real64 m_air;                    // OU coil air mass flow rate [kg/s]
   11245              :     Real64 m_ref_IU_cond;            // mass flow rate of Refrigerant through IU condensers [kg/s]
   11246              :     Real64 m_ref_IU_cond_i;          // mass flow rate of Refrigerant through an individual IU condenser [kg/s]
   11247              :     Real64 m_ref_IU_evap;            // mass flow rate of Refrigerant through IU evaporators [kg/s]
   11248              :     Real64 m_ref_IU_evap_i;          // mass flow rate of Refrigerant through an individual IU evaporator [kg/s]
   11249              :     Real64 m_ref_OU_evap;            // mass flow rate of Refrigerant through OU evaporator [kg/s]
   11250              :     Real64 m_ref_OU_cond;            // mass flow rate of Refrigerant through OU condenser [kg/s]
   11251              :     Real64 Ncomp;                    // compressor power [W]
   11252              :     Real64 Ncomp_new;                // compressor power for temporary use in iterations [W]
   11253              :     Real64 P_comp_in;                // pressure of refrigerant at IU condenser outlet [Pa]
   11254              :     Real64 Pcond;                    // VRF condensing pressure [Pa]
   11255              :     Real64 Pevap;                    // VRF evaporating pressure [Pa]
   11256              :     Real64 Pdischarge;               // VRF compressor discharge pressure [Pa]
   11257              :     Real64 Psuction;                 // VRF compressor suction pressure [Pa]
   11258              :     Real64 Pipe_DeltP_c;             // Piping Loss Algorithm Parameter: Pipe pressure drop (c) [Pa]
   11259              :     Real64 Pipe_DeltP_h;             // Piping Loss Algorithm Parameter: Pipe pressure drop (h) [Pa]
   11260              :     Real64 Pipe_Q_c;                 // Piping Loss Algorithm Parameter: Heat loss (c) [W]
   11261              :     Real64 Pipe_Q_h;                 // Piping Loss Algorithm Parameter: Heat loss (h) [W]
   11262              :     Real64 Q_c_TU_PL;                // Cooling load to be met at cooling mode, including the piping loss(W)
   11263              :     Real64 Q_h_TU_PL;                // Heating load to be met at heating mode, including the piping loss (W)
   11264              :     Real64 Q_h_OU;                   // outdoor unit condenser heat release (cooling mode) [W]
   11265              :     Real64 Q_c_OU;                   // outdoor unit evaporator heat extract (heating mode) [W]
   11266              :     Real64 RefMaxPc;                 // maximum refrigerant condensing pressure [Pa]
   11267              :     Real64 RefMinTe;                 // Minimum refrigerant evaporating temperature [Pa]
   11268              :     Real64 RefMinPe;                 // Minimum refrigerant evaporating pressure [Pa]
   11269              :     Real64 RefPLow;                  // Low Pressure Value for Ps (>0.0) [Pa]
   11270              :     Real64 RefPHigh;                 // High Pressure Value for Ps (max in tables) [Pa]
   11271              :     Real64 RefTLow;                  // Low Temperature Value for Ps (max in tables) [C]
   11272              :     Real64 RefTHigh;                 // High Temperature Value for Ps (max in tables) [C]
   11273              :     Real64 RefTSat;                  // Saturated temperature of the refrigerant. Used to check whether the refrigerant is in the superheat area [C]
   11274              :     Real64 SC_IU_merged;             // Piping Loss Algorithm Parameter: average subcooling degrees after the indoor units [C]
   11275              :     Real64 SH_IU_merged;             // Piping Loss Algorithm Parameter: average super heating degrees after the indoor units [C]
   11276              :     Real64 SC_OU;                    // subcooling degrees at OU condenser [C]
   11277              :     Real64 SH_OU;                    // super heating degrees at OU evaporator [C]
   11278              :     Real64 SH_Comp;                  // Temperature difference between compressor inlet node and Tsuction [C]
   11279              :     Real64 T_comp_in;                // temperature of refrigerant at compressor inlet, after piping loss (c) [C]
   11280              :     Real64 TU_HeatingLoad;           // Heating load from terminal units, excluding heating loss [W]
   11281              :     Real64 TU_CoolingLoad;           // Cooling load from terminal units, excluding heating loss [W]
   11282              :     Real64 Tdischarge;               // VRF Compressor discharge refrigerant temperature [C]
   11283              :     Real64 Tsuction;                 // VRF compressor suction refrigerant temperature [C]
   11284              :     Real64 Tolerance;                // Tolerance for condensing temperature calculation [C]
   11285              :     Real64 Tfs;                      // Temperature of the air at the coil surface [C]
   11286        14999 :     Array1D<Real64> CompEvaporatingPWRSpd; // Array for the compressor power at certain speed [W]
   11287        14999 :     Array1D<Real64> CompEvaporatingCAPSpd; // Array for the evaporating capacity at certain speed [W]
   11288              : 
   11289              :     // variable initializations
   11290        14999 :     TUListNum = this->ZoneTUListPtr;
   11291        14999 :     NumTUInList = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList;
   11292        14999 :     VRFCond = state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(1)).VRFSysNum;
   11293        14999 :     TU_CoolingLoad = 0.0;
   11294        14999 :     TU_HeatingLoad = 0.0;
   11295        14999 :     TUParasiticPower = 0.0;
   11296        14999 :     TUFanPower = 0.0;
   11297        14999 :     CoolingPLR = 0.0;
   11298        14999 :     HeatingPLR = 0.0;
   11299        14999 :     CyclingRatio = 1.0;
   11300        14999 :     SumCoolInletWB = 0.0;
   11301        14999 :     SumHeatInletDB = 0.0;
   11302        14999 :     SumHeatInletWB = 0.0;
   11303        14999 :     TotalCondCoolingCapacity = 0.0;
   11304        14999 :     TotalCondHeatingCapacity = 0.0;
   11305        14999 :     TotalTUCoolingCapacity = 0.0;
   11306        14999 :     TotalTUHeatingCapacity = 0.0;
   11307        14999 :     NumTUInCoolingMode = 0;
   11308        14999 :     NumTUInHeatingMode = 0;
   11309        14999 :     Tolerance = 0.05;
   11310        14999 :     Counter = 1;
   11311        14999 :     NumIteHIUIn = 1;
   11312        14999 :     this->ElecCoolingPower = 0.0;
   11313        14999 :     this->ElecHeatingPower = 0.0;
   11314        14999 :     this->CrankCaseHeaterPower = 0.0;
   11315        14999 :     this->EvapCondPumpElecPower = 0.0; // for EvaporativelyCooled condenser
   11316        14999 :     this->EvapWaterConsumpRate = 0.0;
   11317        14999 :     this->DefrostPower = 0.0;
   11318        14999 :     this->OperatingCoolingCOP = 0.0;
   11319        14999 :     this->OperatingHeatingCOP = 0.0;
   11320        14999 :     this->OperatingCOP = 0.0;
   11321        14999 :     this->SCHE = 0.0;
   11322        14999 :     this->BasinHeaterPower = 0.0;
   11323        14999 :     this->CondensingTemp = 60.0; // OutDryBulbTemp;
   11324        14999 :     this->VRFHeatRec = 0.0;
   11325              : 
   11326              :     // Refrigerant data
   11327        14999 :     RefMinTe = -15;
   11328        14999 :     RefMaxPc = 4000000.0;
   11329        14999 :     RefMinPe = this->refrig->getSatPressure(state, RefMinTe, RoutineName);
   11330        14999 :     RefTLow = this->refrig->PsLowTempValue;   // High Temperature Value for Ps (max in tables)
   11331        14999 :     RefTHigh = this->refrig->PsHighTempValue; // High Temperature Value for Ps (max in tables)
   11332        14999 :     RefPLow = this->refrig->PsLowPresValue;   // Low Pressure Value for Ps (>0.0)
   11333        14999 :     RefPHigh = this->refrig->PsHighPresValue; // High Pressure Value for Ps (max in tables)
   11334              : 
   11335              :     // sum loads on TU coils
   11336        71370 :     for (NumTU = 1; NumTU <= NumTUInList; ++NumTU) {
   11337        56371 :         TU_CoolingLoad += state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU);
   11338        56371 :         TU_HeatingLoad += state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU);
   11339        56371 :         TUParasiticPower +=
   11340        56371 :             state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU)).ParasiticCoolElecPower +
   11341        56371 :             state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU)).ParasiticHeatElecPower;
   11342        56371 :         TUFanPower += state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU)).FanPower;
   11343              :     }
   11344        14999 :     this->TUCoolingLoad = TU_CoolingLoad; // this is cooling coil load, not terminal unit load
   11345        14999 :     this->TUHeatingLoad = TU_HeatingLoad; // this is heating coil load, not terminal unit load
   11346              : 
   11347              :     // loop through TU's and calculate average inlet conditions for active coils
   11348        71370 :     for (NumTU = 1; NumTU <= NumTUInList; ++NumTU) {
   11349        56371 :         TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   11350        56371 :         CoolCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolCoilIndex;
   11351        56371 :         HeatCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).HeatCoilIndex;
   11352              : 
   11353        56371 :         if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) > 0.0) {
   11354        29832 :             SumCoolInletWB += state.dataDXCoils->DXCoilCoolInletAirWBTemp(CoolCoilIndex) *
   11355        29832 :                               state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) / TU_CoolingLoad;
   11356        29832 :             ++NumTUInCoolingMode;
   11357              :         }
   11358        56371 :         if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) > 0.0) {
   11359        23011 :             SumHeatInletDB += state.dataDXCoils->DXCoilHeatInletAirDBTemp(HeatCoilIndex) *
   11360        23011 :                               state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) / TU_HeatingLoad;
   11361        23011 :             SumHeatInletWB += state.dataDXCoils->DXCoilHeatInletAirWBTemp(HeatCoilIndex) *
   11362        23011 :                               state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) / TU_HeatingLoad;
   11363        23011 :             ++NumTUInHeatingMode;
   11364              :         }
   11365              :     }
   11366              : 
   11367              :     // set condenser entering air conditions (Outdoor air conditions)
   11368        14999 :     if (this->CondenserNodeNum != 0) {
   11369            0 :         OutdoorDryBulb = state.dataLoopNodes->Node(this->CondenserNodeNum).Temp;
   11370            0 :         if (this->CondenserType != DataHeatBalance::RefrigCondenserType::Water) {
   11371            0 :             OutdoorHumRat = state.dataLoopNodes->Node(this->CondenserNodeNum).HumRat;
   11372            0 :             OutdoorPressure = state.dataLoopNodes->Node(this->CondenserNodeNum).Press;
   11373            0 :             OutdoorWetBulb = state.dataLoopNodes->Node(this->CondenserNodeNum).OutAirWetBulb;
   11374              :         } else {
   11375            0 :             OutdoorHumRat = state.dataEnvrn->OutHumRat;
   11376            0 :             OutdoorPressure = state.dataEnvrn->OutBaroPress;
   11377            0 :             OutdoorWetBulb = state.dataEnvrn->OutWetBulbTemp;
   11378              :         }
   11379              :     } else {
   11380        14999 :         OutdoorDryBulb = state.dataEnvrn->OutDryBulbTemp;
   11381        14999 :         OutdoorHumRat = state.dataEnvrn->OutHumRat;
   11382        14999 :         OutdoorPressure = state.dataEnvrn->OutBaroPress;
   11383        14999 :         OutdoorWetBulb = state.dataEnvrn->OutWetBulbTemp;
   11384              :     }
   11385        14999 :     RhoAir = PsyRhoAirFnPbTdbW(state, OutdoorPressure, OutdoorDryBulb, OutdoorHumRat);
   11386              : 
   11387        14999 :     CondInletTemp = OutdoorDryBulb; // this->CondenserType == AirCooled
   11388        14999 :     this->CondenserInletTemp = CondInletTemp;
   11389              : 
   11390              :     //*************
   11391              :     // VRF-HP MODES:
   11392              :     //     1. Cooling
   11393              :     //     2. Heating
   11394              :     //     3. No running
   11395              :     // VRF-HR MODES:
   11396              :     //     1. Cooling Only
   11397              :     //     2. Cooling Dominant w/o HR Loss
   11398              :     //     3. Cooling Dominant w/ HR Loss
   11399              :     //     4. Heating Dominant w/ HR Loss
   11400              :     //     5. Heating Dominant w/o HR Loss
   11401              :     //     6. Heating Only
   11402              :     //     7. No running
   11403              : 
   11404              :     // Flag for VRF-HR Operations
   11405        14999 :     if (TU_HeatingLoad > 0) {
   11406         6280 :         HRHeatRequestFlag = true;
   11407              :     } else {
   11408         8719 :         state.dataHVACVarRefFlow->HeatingLoad(VRFCond) = false;
   11409         8719 :         HRHeatRequestFlag = false;
   11410              :     }
   11411        14999 :     if (TU_CoolingLoad > 0) {
   11412         8127 :         HRCoolRequestFlag = true;
   11413              :     } else {
   11414         6872 :         state.dataHVACVarRefFlow->CoolingLoad(VRFCond) = false;
   11415         6872 :         HRCoolRequestFlag = false;
   11416              :     }
   11417              : 
   11418              :     // Initialization for Ncomp iterations
   11419        14999 :     NumOfCompSpdInput = this->CompressorSpeed.size();
   11420        14999 :     CompEvaporatingPWRSpd.dimension(NumOfCompSpdInput);
   11421        14999 :     CompEvaporatingCAPSpd.dimension(NumOfCompSpdInput);
   11422        14999 :     this->OperatingMode = 0; // report variable for heating or cooling mode
   11423              : 
   11424              :     // 1. VRF-HP Cooling Mode .OR. VRF-HR Mode_1
   11425        24045 :     if ((!this->HeatRecoveryUsed && state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) ||
   11426         9046 :         (this->HeatRecoveryUsed && !HRHeatRequestFlag && HRCoolRequestFlag)) {
   11427              : 
   11428         8127 :         this->OperatingMode = ModeCoolingOnly;
   11429         8127 :         this->VRFOperationSimPath = 10;
   11430              : 
   11431              :         // Initialization of VRF-FluidTCtrl Model
   11432         8127 :         Q_c_TU_PL = TU_CoolingLoad;
   11433              : 
   11434              :         // Evaporator (IU side) operational parameters
   11435         8127 :         Pevap = this->refrig->getSatPressure(state, this->IUEvaporatingTemp, RoutineName);
   11436         8127 :         Psuction = Pevap;
   11437         8127 :         this->EvaporatingTemp =
   11438         8127 :             this->IUEvaporatingTemp; // GetSatTemperatureRefrig(state,  this->RefrigerantName, max( min( Pevap, RefPHigh ), RefPLow
   11439              :                                      // ), RefrigerantIndex, RoutineName );
   11440              : 
   11441              :         // Condenser (OU side) operation ranges
   11442         8127 :         CapMaxPc = min(Psuction + this->CompMaxDeltaP, RefMaxPc);
   11443         8127 :         CapMaxTc = this->refrig->getSatTemperature(state, max(min(CapMaxPc, RefPHigh), RefPLow), RoutineName);
   11444         8127 :         CapMinTc = OutdoorDryBulb + this->SC;
   11445         8127 :         CapMinPc = this->refrig->getSatPressure(state, CapMinTc, RoutineName);
   11446              : 
   11447              :         // Evaporator (IU side) operation ranges
   11448         8127 :         CapMinPe = max(CapMinPc - this->CompMaxDeltaP, RefMinPe);
   11449         8127 :         CapMinTe = this->refrig->getSatTemperature(state, max(min(CapMinPe, RefPHigh), RefPLow), RoutineName);
   11450              : 
   11451              :         // Evaporative capacity ranges
   11452         8127 :         CompEvaporatingCAPSpdMin = this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(1), CapMinTc, CapMinTe);
   11453         8127 :         CompEvaporatingPWRSpdMin = this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(1), CapMinTc, CapMinTe);
   11454        16254 :         CompEvaporatingCAPSpdMax = this->CoffEvapCap * this->RatedEvapCapacity *
   11455         8127 :                                    CurveValue(state, this->OUCoolingCAPFT(NumOfCompSpdInput), this->CondensingTemp, this->IUEvaporatingTemp);
   11456         8127 :         CompEvaporatingPWRSpdMax =
   11457         8127 :             this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(NumOfCompSpdInput), this->CondensingTemp, this->IUEvaporatingTemp);
   11458              : 
   11459              :         // Initialization for h_IU_evap_in iterations (Label12)
   11460         8127 :         h_IU_evap_in_low = this->refrig->getSatEnthalpy(state, OutdoorDryBulb - this->SC, 0.0, RoutineName);  // Tc = Tamb
   11461         8127 :         h_IU_evap_in_up = this->refrig->getSatEnthalpy(state, CapMaxTc - this->SC, 0.0, RoutineName);         // Tc = CapMaxTc
   11462         8127 :         h_IU_evap_in = this->refrig->getSatEnthalpy(state, OutdoorDryBulb + 10 - this->SC, 0.0, RoutineName); // Tc = Tamb+10
   11463              : 
   11464         8127 :         NumIteHIUIn = 1;
   11465              :         bool converged_12;
   11466              :         do {
   11467         9243 :             m_ref_IU_evap = 0;
   11468         9243 :             h_IU_evap_out = 0;
   11469         9243 :             h_IU_evap_out_i = 0;
   11470         9243 :             m_ref_IU_evap_i = 0;
   11471         9243 :             SH_IU_merged = 0;
   11472              : 
   11473              :             // Calculate total IU refrigerant flow rate and SH_IU_merged
   11474         9243 :             if (Q_c_TU_PL > CompEvaporatingCAPSpdMax) {
   11475              :                 // Required load is beyond the max system capacity
   11476              : 
   11477            0 :                 RefTSat = this->refrig->getSatTemperature(state, max(min(Pevap, RefPHigh), RefPLow), RoutineName);
   11478            0 :                 h_IU_evap_out = this->refrig->getSupHeatEnthalpy(
   11479            0 :                     state, max(RefTSat, this->IUEvaporatingTemp + 3), max(min(Pevap, RefPHigh), RefPLow), RoutineName);
   11480            0 :                 SH_IU_merged = 3;
   11481            0 :                 m_ref_IU_evap = TU_CoolingLoad / (h_IU_evap_out - h_IU_evap_in);
   11482              : 
   11483              :             } else {
   11484              : 
   11485        45278 :                 for (NumTU = 1; NumTU <= NumTUInList; NumTU++) { // Calc total refrigerant flow rate
   11486        36035 :                     if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) > 0) {
   11487        35219 :                         TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   11488        35219 :                         CoolCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolCoilIndex;
   11489              : 
   11490        35219 :                         RefTSat = this->refrig->getSatTemperature(state, max(min(Pevap, RefPHigh), RefPLow), RoutineName);
   11491        70438 :                         h_IU_evap_out_i = this->refrig->getSupHeatEnthalpy(
   11492              :                             state,
   11493        35219 :                             max(RefTSat, this->IUEvaporatingTemp + state.dataDXCoils->DXCoil(CoolCoilIndex).ActualSH),
   11494              :                             max(min(Pevap, RefPHigh), RefPLow),
   11495              :                             RoutineName);
   11496              : 
   11497        35219 :                         if (h_IU_evap_out_i > h_IU_evap_in) {
   11498        35219 :                             m_ref_IU_evap_i = (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) <= 0.0)
   11499        35219 :                                                   ? 0.0
   11500        35219 :                                                   : (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) /
   11501        35219 :                                                      (h_IU_evap_out_i - h_IU_evap_in)); // Ref Flow Rate in the IU( kg/s )
   11502        35219 :                             m_ref_IU_evap = m_ref_IU_evap + m_ref_IU_evap_i;
   11503        35219 :                             h_IU_evap_out = h_IU_evap_out + m_ref_IU_evap_i * h_IU_evap_out_i;
   11504        35219 :                             SH_IU_merged = SH_IU_merged + m_ref_IU_evap_i * state.dataDXCoils->DXCoil(CoolCoilIndex).ActualSH;
   11505              :                         }
   11506              :                     }
   11507              :                 }
   11508         9243 :                 if (m_ref_IU_evap > 0) {
   11509         9243 :                     h_IU_evap_out = h_IU_evap_out / m_ref_IU_evap;
   11510         9243 :                     SH_IU_merged = SH_IU_merged / m_ref_IU_evap;
   11511              :                 } else {
   11512            0 :                     RefTSat = this->refrig->getSatTemperature(state, max(min(Pevap, RefPHigh), RefPLow), RoutineName);
   11513            0 :                     h_IU_evap_out = this->refrig->getSupHeatEnthalpy(
   11514            0 :                         state, max(RefTSat, this->IUEvaporatingTemp + 3), max(min(Pevap, RefPHigh), RefPLow), RoutineName);
   11515            0 :                     SH_IU_merged = 3;
   11516            0 :                     m_ref_IU_evap = TU_CoolingLoad / (h_IU_evap_out - h_IU_evap_in);
   11517              :                 }
   11518              :             }
   11519              : 
   11520              :             // *Calculate piping loss
   11521         9243 :             this->VRFOU_PipeLossC(state,
   11522              :                                   m_ref_IU_evap,
   11523              :                                   max(min(Pevap, RefPHigh), RefPLow),
   11524              :                                   h_IU_evap_out,
   11525              :                                   SH_IU_merged,
   11526              :                                   OutdoorDryBulb,
   11527              :                                   Pipe_Q_c,
   11528              :                                   Pipe_DeltP_c,
   11529              :                                   h_comp_in);
   11530         9243 :             Tsuction = this->refrig->getSatTemperature(state, max(min(Pevap - Pipe_DeltP_c, RefPHigh), RefPLow), RoutineName);
   11531         9243 :             Psuction = Pevap - Pipe_DeltP_c; // This Psuction is used for rps > min; will be updated for rps = min
   11532              : 
   11533              :             // Perform iteration to calculate T_comp_in
   11534         9243 :             T_comp_in = this->refrig->getSupHeatTemp(
   11535              :                 state, max(min(Pevap - Pipe_DeltP_c, RefPHigh), RefPLow), h_comp_in, Tsuction + 3, Tsuction + 30, RoutineName);
   11536         9243 :             SH_Comp = T_comp_in - Tsuction; // This is used for rps > min; will be updated for rps = min
   11537              : 
   11538         9243 :             Q_c_TU_PL = TU_CoolingLoad + Pipe_Q_c;
   11539         9243 :             Q_h_OU = Q_c_TU_PL + CompEvaporatingPWRSpdMin;
   11540              : 
   11541              :             // *Calculate capacity modification factor
   11542         9243 :             C_cap_operation = this->VRFOU_CapModFactor(
   11543              :                 state, h_comp_in, h_IU_evap_in, max(min(Psuction, RefPHigh), RefPLow), Tsuction + SH_Comp, Tsuction + 8, CapMinTc - 5);
   11544              : 
   11545              :             // Iteration_Ncomp: Perform iterations to calculate Ncomp (Label10)
   11546         9243 :             Counter = 1;
   11547         9243 :             Ncomp = TU_CoolingLoad / this->CoolingCOP;
   11548         9243 :             Ncomp_new = Ncomp;
   11549              :             bool converged_10;
   11550              :             do {
   11551        18463 :                 Q_h_OU = Q_c_TU_PL + Ncomp_new; // Ncomp_new may be updated during Iteration_Ncomp Label10
   11552              : 
   11553              :                 // *VRF OU TeTc calculations
   11554        18463 :                 m_air = this->OUAirFlowRate * RhoAir;
   11555        18463 :                 SC_OU = this->SC;
   11556        18463 :                 this->VRFOU_TeTc(
   11557        18463 :                     state, HXOpMode::CondMode, Q_h_OU, SC_OU, m_air, OutdoorDryBulb, OutdoorHumRat, OutdoorPressure, Tfs, this->CondensingTemp);
   11558        18463 :                 this->CondensingTemp = min(CapMaxTc, this->CondensingTemp);
   11559        18463 :                 this->SC = SC_OU;
   11560              : 
   11561              :                 // *VEF OU Compressor Simulation at cooling mode: Specify the compressor speed and power consumption
   11562        18463 :                 this->VRFOU_CalcCompC(state,
   11563              :                                       TU_CoolingLoad,
   11564              :                                       Tsuction,
   11565              :                                       this->CondensingTemp,
   11566              :                                       Psuction,
   11567              :                                       T_comp_in,
   11568              :                                       h_comp_in,
   11569              :                                       h_IU_evap_in,
   11570              :                                       Pipe_Q_c,
   11571              :                                       CapMaxTc,
   11572              :                                       Q_h_OU,
   11573              :                                       CompSpdActual,
   11574              :                                       Ncomp,
   11575              :                                       CyclingRatio);
   11576              : 
   11577        18463 :                 converged_10 = (std::abs(Ncomp - Ncomp_new) <= (Tolerance * Ncomp_new)) || (Counter >= 30);
   11578        18463 :                 if (!converged_10) {
   11579         9220 :                     Ncomp_new = Ncomp;
   11580              :                 }
   11581        18463 :             } while (!converged_10);
   11582              : 
   11583              :             // Update h_IU_evap_in in iterations Label12
   11584         9243 :             h_IU_evap_in_new = this->refrig->getSatEnthalpy(state, this->CondensingTemp - this->SC, 0.0, RoutineName);
   11585        10359 :             converged_12 = !((std::abs(h_IU_evap_in - h_IU_evap_in_new) > Tolerance * h_IU_evap_in) && (h_IU_evap_in < h_IU_evap_in_up) &&
   11586         1116 :                              (h_IU_evap_in > h_IU_evap_in_low));
   11587         9243 :             h_IU_evap_in = h_IU_evap_in_new;
   11588         9243 :             NumIteHIUIn = NumIteHIUIn + 1;
   11589         9243 :         } while (!converged_12);
   11590         8127 :         if ((std::abs(h_IU_evap_in - h_IU_evap_in_new) > Tolerance * h_IU_evap_in)) {
   11591            0 :             h_IU_evap_in = 0.5 * (h_IU_evap_in_low + h_IU_evap_in_up);
   11592         8127 :         } else if (h_IU_evap_in > h_IU_evap_in_up) {
   11593            0 :             h_IU_evap_in = h_IU_evap_in_up;
   11594         8127 :         } else if (h_IU_evap_in < h_IU_evap_in_low) {
   11595            0 :             h_IU_evap_in = h_IU_evap_in_low;
   11596              :         } else {
   11597         8127 :             h_IU_evap_in = (h_IU_evap_in + h_IU_evap_in_new) / 2;
   11598              :         }
   11599              : 
   11600              :         // Key outputs of this subroutine
   11601         8127 :         Ncomp *= CyclingRatio;
   11602         8127 :         Q_h_OU *= CyclingRatio;
   11603         8127 :         this->CompActSpeed = max(CompSpdActual, 0.0);
   11604         8127 :         this->Ncomp = max(Ncomp, 0.0) / this->EffCompInverter;   // 0.95 is the efficiency of the compressor inverter, can come from IDF //@minor
   11605         8127 :         this->OUFanPower = this->RatedOUFanPower * CyclingRatio; //@ * pow_3( CondFlowRatio )
   11606         8127 :         this->VRFCondCyclingRatio = CyclingRatio;                // report variable for cycling rate
   11607              : 
   11608         8127 :         Tdischarge = this->CondensingTemp; // outdoor unit condensing temperature
   11609         8127 :         this->CoolingCapacity =
   11610        16254 :             this->CoffEvapCap * this->RatedEvapCapacity *
   11611        16254 :             CurveValue(
   11612         8127 :                 state, this->OUCoolingCAPFT(NumOfCompSpdInput), Tdischarge, Tsuction); // Include the piping loss, at the highest compressor speed
   11613         8127 :         this->PipingCorrectionCooling = TU_CoolingLoad / (TU_CoolingLoad + Pipe_Q_c);
   11614         8127 :         state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond) = this->CoolingCapacity; // for report, maximum evaporating capacity of the system
   11615              : 
   11616         8127 :         this->HeatingCapacity = 0.0;         // Include the piping loss
   11617         8127 :         this->PipingCorrectionHeating = 1.0; // 1 means no piping loss
   11618         8127 :         state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond) = Constant::MaxCap;
   11619              : 
   11620         8127 :         this->OUCondHeatRate = Q_h_OU;
   11621         8127 :         this->OUEvapHeatRate = 0;
   11622         8127 :         this->IUCondHeatRate = 0;
   11623         8127 :         this->IUEvapHeatRate = TU_CoolingLoad;
   11624              : 
   11625              :         // 2. VRF-HP Heating Mode .OR. VRF-HR Mode_6
   11626         8821 :     } else if ((!this->HeatRecoveryUsed && state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) ||
   11627         1949 :                (this->HeatRecoveryUsed && !HRCoolRequestFlag && HRHeatRequestFlag)) {
   11628              : 
   11629         6280 :         this->OperatingMode = ModeHeatingOnly;
   11630         6280 :         this->VRFOperationSimPath = 60;
   11631              : 
   11632              :         // Initialization of VRF-FluidTCtrl Model
   11633         6280 :         Q_h_TU_PL = TU_HeatingLoad;
   11634         6280 :         Ncomp = TU_HeatingLoad / this->HeatingCOP;
   11635         6280 :         this->CondensingTemp = this->IUCondensingTemp;
   11636              : 
   11637              :         // Evaporative capacity ranges_Max
   11638         6280 :         CapMaxTe = OutdoorDryBulb - this->SH;
   11639        12560 :         CompEvaporatingCAPSpdMax = this->CoffEvapCap * this->RatedEvapCapacity *
   11640         6280 :                                    CurveValue(state, this->OUCoolingCAPFT(NumOfCompSpdInput), this->IUCondensingTemp, CapMaxTe);
   11641         6280 :         CompEvaporatingPWRSpdMax =
   11642         6280 :             this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(NumOfCompSpdInput), this->IUCondensingTemp, CapMaxTe);
   11643              : 
   11644              :         // Initialization of h_comp_out iterations (Label23)
   11645         6280 :         Pcond = this->refrig->getSatPressure(state, 40.0, RoutineName);
   11646         6280 :         RefTSat = this->refrig->getSatTemperature(state, Pcond, RoutineName);
   11647         6280 :         h_IU_cond_in_up = this->refrig->getSupHeatEnthalpy(state, max(RefTSat, min(this->IUCondensingTemp + 50, RefTHigh)), Pcond, RoutineName);
   11648         6280 :         h_IU_cond_in_low = this->refrig->getSatEnthalpy(state, this->IUCondensingTemp, 1.0, RoutineName); // Quality=1
   11649         6280 :         h_IU_cond_in = h_IU_cond_in_low;
   11650              : 
   11651              :         bool converged_23;
   11652              :         do {
   11653        19045 :             m_ref_IU_cond = 0;
   11654        19045 :             h_IU_cond_out_ave = 0;
   11655        19045 :             SC_IU_merged = 0;
   11656              : 
   11657              :             // Calculate total refrigerant flow rate
   11658        19045 :             if (Q_h_TU_PL > CompEvaporatingCAPSpdMax + CompEvaporatingPWRSpdMax) {
   11659              :                 // Required load is beyond the max system capacity
   11660              : 
   11661              :                 h_IU_cond_out =
   11662        30390 :                     this->refrig->getSatEnthalpy(state,
   11663        10130 :                                                  this->refrig->getSatTemperature(state, max(min(Pcond, RefPHigh), RefPLow), RoutineName) - 5.0,
   11664              :                                                  0.0,
   11665              :                                                  RoutineName); // Quality=0
   11666        10130 :                 h_IU_cond_out_ave = h_IU_cond_out;
   11667        10130 :                 SC_IU_merged = 5;
   11668        10130 :                 m_ref_IU_cond = TU_HeatingLoad / (h_IU_cond_in - h_IU_cond_out);
   11669              : 
   11670              :             } else {
   11671        53482 :                 for (NumTU = 1; NumTU <= NumTUInList; NumTU++) {
   11672        44567 :                     if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) > 0) {
   11673        44152 :                         TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   11674        44152 :                         HeatCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).HeatCoilIndex;
   11675              :                         h_IU_cond_out_i =
   11676       132456 :                             this->refrig->getSatEnthalpy(state,
   11677        44152 :                                                          this->refrig->getSatTemperature(state, max(min(Pcond, RefPHigh), RefPLow), RoutineName) -
   11678        44152 :                                                              state.dataDXCoils->DXCoil(HeatCoilIndex).ActualSC,
   11679              :                                                          0.0,
   11680              :                                                          RoutineName); // Quality=0
   11681        44152 :                         m_ref_IU_cond_i =
   11682        44152 :                             (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) <= 0.0)
   11683        44152 :                                 ? 0.0
   11684        44152 :                                 : (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) / (h_IU_cond_in - h_IU_cond_out_i));
   11685        44152 :                         m_ref_IU_cond = m_ref_IU_cond + m_ref_IU_cond_i;
   11686        44152 :                         h_IU_cond_out_ave = h_IU_cond_out_ave + m_ref_IU_cond_i * h_IU_cond_out_i;
   11687        44152 :                         SC_IU_merged = SC_IU_merged + m_ref_IU_cond_i * state.dataDXCoils->DXCoil(HeatCoilIndex).ActualSC;
   11688              :                     }
   11689              :                 }
   11690         8915 :                 if (m_ref_IU_cond > 0) {
   11691         8915 :                     h_IU_cond_out_ave = h_IU_cond_out_ave / m_ref_IU_cond; // h_merge
   11692         8915 :                     SC_IU_merged = SC_IU_merged / m_ref_IU_cond;
   11693              :                 } else {
   11694              :                     h_IU_cond_out_ave =
   11695            0 :                         this->refrig->getSatEnthalpy(state,
   11696            0 :                                                      this->refrig->getSatTemperature(state, max(min(Pcond, RefPHigh), RefPLow), RoutineName) - 5.0,
   11697              :                                                      0.0,
   11698              :                                                      RoutineName); // Quality=0
   11699            0 :                     SC_IU_merged = 5;
   11700            0 :                     m_ref_IU_cond = TU_HeatingLoad / (h_IU_cond_in - h_IU_cond_out_ave);
   11701              :                 }
   11702              :             }
   11703              : 
   11704              :             // *Calculate piping loss
   11705        19045 :             this->VRFOU_PipeLossH(
   11706              :                 state, m_ref_IU_cond, max(min(Pcond, RefPHigh), RefPLow), h_IU_cond_in, OutdoorDryBulb, Pipe_Q_h, Pipe_DeltP_h, h_comp_out);
   11707              : 
   11708        19045 :             Pdischarge = max(Pcond + Pipe_DeltP_h, Pcond); // affected by piping loss
   11709        19045 :             Tdischarge = this->refrig->getSatTemperature(state, max(min(Pdischarge, RefPHigh), RefPLow), RoutineName);
   11710              : 
   11711              :             // Evaporative capacity ranges_Min
   11712              :             // suction pressure lower bound need to be no less than both terms in the following
   11713        19045 :             CapMinPe = max(Pdischarge - this->CompMaxDeltaP, RefMinPe);
   11714        19045 :             CapMinTe = this->refrig->getSatTemperature(state, max(min(CapMinPe, RefPHigh), RefPLow), RoutineName);
   11715        19045 :             CompEvaporatingCAPSpdMin = this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(1), Tdischarge, CapMinTe);
   11716        19045 :             CompEvaporatingPWRSpdMin = this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(1), Tdischarge, CapMinTe);
   11717              : 
   11718        19045 :             Q_h_TU_PL = TU_HeatingLoad + Pipe_Q_h;
   11719        19045 :             Q_c_OU = max(0.0, Q_h_TU_PL - CompEvaporatingPWRSpdMin);
   11720              : 
   11721              :             // *Calculate capacity modification factor
   11722        19045 :             RefTSat = this->refrig->getSatTemperature(state, max(min(CapMinPe, RefPHigh), RefPLow), RoutineName);
   11723        19045 :             h_comp_in =
   11724        19045 :                 this->refrig->getSupHeatEnthalpy(state, max(RefTSat, CapMinTe + this->SH), max(min(CapMinPe, RefPHigh), RefPLow), RoutineName);
   11725        19045 :             C_cap_operation = this->VRFOU_CapModFactor(state,
   11726              :                                                        h_comp_in,
   11727              :                                                        h_IU_cond_out_ave,
   11728              :                                                        max(min(CapMinPe, RefPHigh), RefPLow),
   11729        19045 :                                                        CapMinTe + this->SH,
   11730              :                                                        CapMinTe + 8,
   11731        19045 :                                                        this->IUCondensingTemp - 5);
   11732              : 
   11733              :             Real64 CompEvaporatingCAPSpdMaxCurrentTsuc =
   11734        38090 :                 this->CoffEvapCap * this->RatedEvapCapacity *
   11735        19045 :                 CurveValue(state, this->OUCoolingCAPFT(NumOfCompSpdInput), Tdischarge, this->EvaporatingTemp);
   11736              :             Real64 CompEvaporatingPWRSpdMaxCurrentTsuc =
   11737        19045 :                 this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(NumOfCompSpdInput), Tdischarge, this->EvaporatingTemp);
   11738        19045 :             if (CompEvaporatingCAPSpdMin > CompEvaporatingCAPSpdMaxCurrentTsuc) {
   11739            0 :                 if (this->CondenserCapErrIdx == 0) {
   11740            0 :                     ShowSevereMessage(state, format("{} \"{}\":", cVRFTypes(VRF_HeatPump), this->Name));
   11741            0 :                     ShowContinueErrorTimeStamp(state,
   11742            0 :                                                format(" Evaporative Capacity at max speed is smaller than evaporative capacity at min speed, "
   11743              :                                                       "{:.3T} < {:.3T}",
   11744              :                                                       CompEvaporatingCAPSpdMaxCurrentTsuc,
   11745              :                                                       CompEvaporatingCAPSpdMin));
   11746              :                 }
   11747            0 :                 ShowRecurringSevereErrorAtEnd(
   11748              :                     state,
   11749            0 :                     format("\"{}\" - Evaporative Capacity at max speed is smaller than evaporative capacity at min speed ", this->Name),
   11750            0 :                     this->CondenserCapErrIdx,
   11751            0 :                     CompEvaporatingCAPSpdMaxCurrentTsuc - CompEvaporatingCAPSpdMin,
   11752            0 :                     CompEvaporatingCAPSpdMaxCurrentTsuc - CompEvaporatingCAPSpdMin);
   11753              :             }
   11754        19045 :             if ((Q_c_OU * C_cap_operation) > CompEvaporatingCAPSpdMaxCurrentTsuc) {
   11755              :                 // this branch resolves the issue of supplemental heating coil turning on when compressor speed is not at the highest
   11756         2067 :                 Q_c_OU = CompEvaporatingCAPSpdMaxCurrentTsuc;
   11757         2067 :                 CompSpdActual = this->CompressorSpeed(NumOfCompSpdInput);
   11758         2067 :                 Ncomp = CompEvaporatingPWRSpdMaxCurrentTsuc;
   11759         2067 :                 m_air = this->OUAirFlowRate * RhoAir;
   11760         2067 :                 SH_OU = this->SH;
   11761         2067 :                 this->VRFOU_TeTc(
   11762         2067 :                     state, HXOpMode::EvapMode, Q_c_OU, SH_OU, m_air, OutdoorDryBulb, OutdoorHumRat, OutdoorPressure, Tfs, this->EvaporatingTemp);
   11763         6280 :                 break;
   11764              :             } else {
   11765              :                 // CompEvaporatingCAPSpdMin < (Q_c_OU * C_cap_operation) <= CompEvaporatingCAPSpdMaxCurrentTsuc + CompEvaporatingPWRSpdMaxCurrentTsuc
   11766              :                 // Required heating load is greater than or equal to the min heating capacity
   11767              : 
   11768              :                 // Iteration_Ncomp: Perform iterations to calculate Ncomp (Label20)
   11769        16978 :                 Counter = 1;
   11770              :                 bool converged_20;
   11771              :                 do {
   11772        26940 :                     Ncomp_new = Ncomp;
   11773        26940 :                     Q_c_OU = max(0.0, Q_h_TU_PL - Ncomp);
   11774              : 
   11775              :                     // *VRF OU Te calculations
   11776        26940 :                     m_air = this->OUAirFlowRate * RhoAir;
   11777        26940 :                     SH_OU = this->SH;
   11778        26940 :                     this->VRFOU_TeTc(
   11779        26940 :                         state, HXOpMode::EvapMode, Q_c_OU, SH_OU, m_air, OutdoorDryBulb, OutdoorHumRat, OutdoorPressure, Tfs, this->EvaporatingTemp);
   11780        26940 :                     this->SH = SH_OU;
   11781              : 
   11782              :                     // *VRF OU Compressor Simulation at heating mode: Specify the compressor speed and power consumption
   11783        26940 :                     this->VRFOU_CalcCompH(state,
   11784              :                                           TU_HeatingLoad,
   11785              :                                           this->EvaporatingTemp,
   11786              :                                           Tdischarge,
   11787              :                                           h_IU_cond_out_ave,
   11788              :                                           this->IUCondensingTemp,
   11789              :                                           CapMinTe,
   11790              :                                           Tfs,
   11791              :                                           Pipe_Q_h,
   11792              :                                           Q_c_OU,
   11793              :                                           CompSpdActual,
   11794              :                                           Ncomp_new,
   11795              :                                           CyclingRatio);
   11796              : 
   11797        26940 :                     converged_20 = (std::abs(Ncomp_new - Ncomp) <= (Tolerance * Ncomp)) || (Counter >= 30);
   11798        26940 :                     Counter = Counter + 1;
   11799        26940 :                     if (!converged_20) {
   11800         9962 :                         Ncomp = Ncomp_new;
   11801              :                     }
   11802        26940 :                 } while (!converged_20);
   11803              : 
   11804              :                 // Update h_comp_out in iteration Label23
   11805        16978 :                 P_comp_in = this->refrig->getSatPressure(state, this->EvaporatingTemp, RoutineName);
   11806        16978 :                 RefTSat = this->refrig->getSatTemperature(state, max(min(P_comp_in, RefPHigh), RefPLow), RoutineName);
   11807        33956 :                 h_comp_in_new = this->refrig->getSupHeatEnthalpy(
   11808        16978 :                     state, max(RefTSat, this->SH + this->EvaporatingTemp), max(min(P_comp_in, RefPHigh), RefPLow), RoutineName);
   11809        16978 :                 h_comp_out_new = Ncomp_new / m_ref_IU_cond + h_comp_in_new;
   11810              : 
   11811        16978 :                 converged_23 = !((std::abs(h_comp_out - h_comp_out_new) > Tolerance * h_comp_out) && (h_IU_cond_in < h_IU_cond_in_up));
   11812        16978 :                 if (!converged_23) {
   11813        12765 :                     h_IU_cond_in = h_IU_cond_in + 0.1 * (h_IU_cond_in_up - h_IU_cond_in_low);
   11814              :                 } else {
   11815         4213 :                     if (h_IU_cond_in > h_IU_cond_in_up) {
   11816            0 :                         h_IU_cond_in = 0.5 * (h_IU_cond_in_up + h_IU_cond_in_low);
   11817              :                     }
   11818         4213 :                     Ncomp = Ncomp_new;
   11819         4213 :                     break;
   11820              :                 }
   11821              :             }
   11822        12765 :         } while (!converged_23);
   11823              : 
   11824              :         // Key outputs of this subroutine
   11825         6280 :         Q_c_OU *= CyclingRatio;
   11826         6280 :         this->CompActSpeed = max(CompSpdActual, 0.0);
   11827         6280 :         this->Ncomp = max(Ncomp, 0.0) / this->EffCompInverter;
   11828         6280 :         this->OUFanPower = this->RatedOUFanPower * CyclingRatio;
   11829         6280 :         this->VRFCondCyclingRatio = CyclingRatio;
   11830              : 
   11831         6280 :         Tsuction = this->EvaporatingTemp; // Outdoor unit evaporating temperature
   11832         6280 :         this->HeatingCapacity =
   11833         6280 :             this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(NumOfCompSpdInput), Tdischarge, Tsuction) +
   11834        18840 :             this->RatedCompPower * CurveValue(state,
   11835         6280 :                                               this->OUCoolingPWRFT(NumOfCompSpdInput),
   11836              :                                               Tdischarge,
   11837              :                                               Tsuction); // Include the piping loss, at the highest compressor speed
   11838         6280 :         this->PipingCorrectionHeating = TU_HeatingLoad / (TU_HeatingLoad + Pipe_Q_h);
   11839         6280 :         state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond) =
   11840         6280 :             this->HeatingCapacity; // for report, maximum condensing capacity the system can provide
   11841              : 
   11842         6280 :         this->CoolingCapacity = 0.0; // Include the piping loss
   11843         6280 :         this->PipingCorrectionCooling = 1.0;
   11844         6280 :         state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond) = Constant::MaxCap; // for report
   11845              : 
   11846         6280 :         this->OUCondHeatRate = 0;
   11847         6280 :         this->OUEvapHeatRate = Q_c_OU;
   11848         6280 :         this->IUCondHeatRate = TU_HeatingLoad;
   11849         6280 :         this->IUEvapHeatRate = 0;
   11850              : 
   11851              :         // 3. VRF-HR Mode_2-5, Simultaneous Heating and Cooling
   11852          592 :     } else if (this->HeatRecoveryUsed && HRCoolRequestFlag && HRHeatRequestFlag) {
   11853              : 
   11854            0 :         this->OperatingMode = ModeCoolingAndHeating;
   11855              : 
   11856              :         // Initialization of VRF-FluidTCtrl Model
   11857            0 :         Q_c_TU_PL = TU_CoolingLoad;
   11858            0 :         Q_h_TU_PL = TU_HeatingLoad;
   11859              : 
   11860              :         // Evaporator (IU side) operational parameters
   11861            0 :         Pevap = this->refrig->getSatPressure(state, this->IUEvaporatingTemp, RoutineName);
   11862            0 :         Psuction = Pevap;
   11863            0 :         this->EvaporatingTemp = this->IUEvaporatingTemp;
   11864              : 
   11865              :         // Condenser (OU side) operation ranges
   11866            0 :         CapMaxPc = min(Psuction + this->CompMaxDeltaP, RefMaxPc);
   11867            0 :         CapMaxTc = this->refrig->getSatTemperature(state, max(min(CapMaxPc, RefPHigh), RefPLow), RoutineName);
   11868            0 :         CapMinTc = OutdoorDryBulb + this->SC;
   11869            0 :         CapMinPc = this->refrig->getSatPressure(state, CapMinTc, RoutineName);
   11870              : 
   11871              :         // Evaporator (IU side) operation ranges
   11872            0 :         CapMinPe = max(CapMinPc - this->CompMaxDeltaP, RefMinPe);
   11873            0 :         CapMinTe = this->refrig->getSatTemperature(state, max(min(CapMinPe, RefPHigh), RefPLow), RoutineName);
   11874              : 
   11875              :         //===**h_comp_out Iteration Starts
   11876              : 
   11877              :         // Initialization of h_comp_out iterations (Label230)
   11878              :         {
   11879            0 :             Pcond = this->refrig->getSatPressure(state, this->IUCondensingTemp, RoutineName);
   11880            0 :             Real64 Pcond_temp = this->refrig->getSatPressure(state, 40.0, RoutineName);
   11881            0 :             RefTSat = this->refrig->getSatTemperature(state, Pcond_temp, RoutineName);
   11882              :             h_IU_cond_in_up =
   11883            0 :                 this->refrig->getSupHeatEnthalpy(state, max(RefTSat, min(this->IUCondensingTemp + 50, RefTHigh)), Pcond_temp, RoutineName);
   11884            0 :             h_IU_cond_in_low = this->refrig->getSatEnthalpy(state, this->IUCondensingTemp, 1.0, RoutineName); // Quality=1
   11885            0 :             h_IU_cond_in = h_IU_cond_in_low;
   11886              :         }
   11887              : 
   11888              :         bool converged_230;
   11889              :         do {
   11890              :             // *PL-h: Calculate total refrigerant flow rate
   11891            0 :             m_ref_IU_cond = 0;
   11892            0 :             h_IU_cond_out_ave = 0;
   11893            0 :             SC_IU_merged = 0;
   11894            0 :             for (NumTU = 1; NumTU <= NumTUInList; NumTU++) {
   11895            0 :                 if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) > 0) {
   11896            0 :                     TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   11897            0 :                     HeatCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).HeatCoilIndex;
   11898              :                     h_IU_cond_out_i =
   11899            0 :                         this->refrig->getSatEnthalpy(state,
   11900            0 :                                                      this->refrig->getSatTemperature(state, max(min(Pcond, RefPHigh), RefPLow), RoutineName) -
   11901            0 :                                                          state.dataDXCoils->DXCoil(HeatCoilIndex).ActualSC,
   11902              :                                                      0.0,
   11903              :                                                      RoutineName); // Quality=0
   11904            0 :                     m_ref_IU_cond_i =
   11905            0 :                         (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) <= 0.0)
   11906            0 :                             ? 0.0
   11907            0 :                             : (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad(NumTU) / (h_IU_cond_in - h_IU_cond_out_i));
   11908            0 :                     m_ref_IU_cond = m_ref_IU_cond + m_ref_IU_cond_i;
   11909            0 :                     h_IU_cond_out_ave = h_IU_cond_out_ave + m_ref_IU_cond_i * h_IU_cond_out_i;
   11910            0 :                     SC_IU_merged = SC_IU_merged + m_ref_IU_cond_i * state.dataDXCoils->DXCoil(HeatCoilIndex).ActualSC;
   11911              :                 }
   11912              :             }
   11913            0 :             if (m_ref_IU_cond > 0) {
   11914            0 :                 h_IU_cond_out_ave = h_IU_cond_out_ave / m_ref_IU_cond;
   11915            0 :                 SC_IU_merged = SC_IU_merged / m_ref_IU_cond;
   11916              :             } else {
   11917              :                 h_IU_cond_out_ave =
   11918            0 :                     this->refrig->getSatEnthalpy(state,
   11919            0 :                                                  this->refrig->getSatTemperature(state, max(min(Pcond, RefPHigh), RefPLow), RoutineName) - 5.0,
   11920              :                                                  0.0,
   11921              :                                                  RoutineName); // Quality=0
   11922            0 :                 SC_IU_merged = 5;
   11923            0 :                 m_ref_IU_cond = TU_HeatingLoad / (h_IU_cond_in - h_IU_cond_out_ave);
   11924              :             }
   11925              : 
   11926              :             // *PL-h: Calculate piping loss
   11927            0 :             this->VRFOU_PipeLossH(
   11928              :                 state, m_ref_IU_cond, max(min(Pcond, RefPHigh), RefPLow), h_IU_cond_in, OutdoorDryBulb, Pipe_Q_h, Pipe_DeltP_h, h_comp_out);
   11929            0 :             Pdischarge = max(Pcond + Pipe_DeltP_h, Pcond); // affected by piping loss
   11930            0 :             Tdischarge = this->refrig->getSatTemperature(state, max(min(Pdischarge, RefPHigh), RefPLow), RoutineName);
   11931            0 :             Q_h_TU_PL = TU_HeatingLoad + Pipe_Q_h;
   11932              : 
   11933              :             // *PL-c: Calculate total IU refrigerant flow rate and SH_IU_merged
   11934            0 :             h_IU_evap_in = h_IU_cond_out_ave;
   11935            0 :             m_ref_IU_evap = 0;
   11936            0 :             h_IU_evap_out = 0;
   11937            0 :             SH_IU_merged = 0;
   11938            0 :             for (NumTU = 1; NumTU <= NumTUInList; NumTU++) { // Calc total refrigerant flow rate
   11939            0 :                 if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) > 0) {
   11940            0 :                     TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   11941            0 :                     CoolCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolCoilIndex;
   11942              : 
   11943            0 :                     RefTSat = this->refrig->getSatTemperature(state, max(min(Pevap, RefPHigh), RefPLow), RoutineName);
   11944              :                     h_IU_evap_out_i =
   11945            0 :                         this->refrig->getSupHeatEnthalpy(state,
   11946            0 :                                                          max(RefTSat, this->IUEvaporatingTemp + state.dataDXCoils->DXCoil(CoolCoilIndex).ActualSH),
   11947              :                                                          max(min(Pevap, RefPHigh), RefPLow),
   11948              :                                                          RoutineName);
   11949              : 
   11950            0 :                     if (h_IU_evap_out_i > h_IU_evap_in) {
   11951            0 :                         m_ref_IU_evap_i = (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) <= 0.0)
   11952            0 :                                               ? 0.0
   11953            0 :                                               : (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) /
   11954            0 :                                                  (h_IU_evap_out_i - h_IU_evap_in)); // Ref Flow Rate in the IU( kg/s )
   11955            0 :                         m_ref_IU_evap = m_ref_IU_evap + m_ref_IU_evap_i;
   11956            0 :                         h_IU_evap_out = h_IU_evap_out + m_ref_IU_evap_i * h_IU_evap_out_i;
   11957            0 :                         SH_IU_merged = SH_IU_merged + m_ref_IU_evap_i * state.dataDXCoils->DXCoil(CoolCoilIndex).ActualSH;
   11958              :                     }
   11959              :                 }
   11960              :             }
   11961            0 :             if (m_ref_IU_evap > 0) {
   11962            0 :                 h_IU_evap_out = h_IU_evap_out / m_ref_IU_evap;
   11963            0 :                 SH_IU_merged = SH_IU_merged / m_ref_IU_evap;
   11964              :             } else {
   11965            0 :                 RefTSat = this->refrig->getSatTemperature(state, max(min(Pevap, RefPHigh), RefPLow), RoutineName);
   11966            0 :                 h_IU_evap_out = this->refrig->getSupHeatEnthalpy(
   11967            0 :                     state, max(RefTSat, this->IUEvaporatingTemp + 3), max(min(Pevap, RefPHigh), RefPLow), RoutineName);
   11968            0 :                 SH_IU_merged = 3;
   11969            0 :                 m_ref_IU_evap = TU_CoolingLoad / (h_IU_evap_out - h_IU_evap_in);
   11970              :             }
   11971              : 
   11972              :             // *PL-c: Calculate piping loss
   11973            0 :             this->VRFOU_PipeLossC(state,
   11974              :                                   m_ref_IU_evap,
   11975              :                                   max(min(Pevap, RefPHigh), RefPLow),
   11976              :                                   h_IU_evap_out,
   11977              :                                   SH_IU_merged,
   11978              :                                   OutdoorDryBulb,
   11979              :                                   Pipe_Q_c,
   11980              :                                   Pipe_DeltP_c,
   11981              :                                   h_IU_PLc_out);
   11982            0 :             Psuction = min(Pevap - Pipe_DeltP_c, Pevap); // This Psuction is used for rps > min; will be updated for rps = min
   11983            0 :             Tsuction = this->refrig->getSatTemperature(state, max(min(Psuction, RefPHigh), RefPLow), RoutineName);
   11984            0 :             h_comp_in = h_IU_PLc_out;
   11985            0 :             Q_c_TU_PL = TU_CoolingLoad + Pipe_Q_c;
   11986              : 
   11987              :             //**OU operations: Determine VRF-HR OU system operational mode
   11988              :             //  Determine the operational mode of the VRF-HR system, given the terminal unit side load conditions.
   11989              :             //  A number of OU side operational parameters are also calculated here, including:
   11990              :             //  (1) OU evaporator load Q_c_OU, (2) OU condenser load Q_h_OU,
   11991              :             //  (3) m_ref_OU_evap, (4) m_ref_OU_cond
   11992              :             //  Note that Te and Te' may be updated here, and thus IU evaporator side piping loss recalculations.
   11993              :             //  Then a number of operational parameters need to be updated, including:
   11994              :             //  (1) IU evaporating temperature Te (2) OU evaporating temperature Te' etc (3) m_ref_IU_evap
   11995              :             //  (4) Pipe_Q_c (5) h_IU_PLc_out (6) h_comp_in
   11996              :             //*VRF OU Compressor Simulation at HR mode: Specify the compressor speed and power consumption
   11997              :             {
   11998            0 :                 Real64 Pipe_Q_c_new = Pipe_Q_c;
   11999            0 :                 Real64 Tsuction_new = Tsuction;
   12000            0 :                 Real64 Te_new = this->IUEvaporatingTemp;
   12001              :                 Real64 N_fan_OU;
   12002              : 
   12003            0 :                 this->VRFHR_OU_HR_Mode(state,
   12004              :                                        h_IU_evap_in,
   12005              :                                        h_comp_out,
   12006              :                                        Q_c_TU_PL,
   12007              :                                        Q_h_TU_PL,
   12008              :                                        Tdischarge,
   12009              :                                        Tsuction_new,
   12010              :                                        Te_new,
   12011              :                                        h_comp_in,
   12012              :                                        h_IU_PLc_out,
   12013              :                                        Pipe_Q_c_new,
   12014              :                                        Q_c_OU,
   12015              :                                        Q_h_OU,
   12016              :                                        m_ref_IU_evap,
   12017              :                                        m_ref_OU_evap,
   12018              :                                        m_ref_OU_cond,
   12019              :                                        N_fan_OU,
   12020              :                                        CompSpdActual,
   12021              :                                        Ncomp);
   12022              : 
   12023              :                 // parameter update
   12024            0 :                 Tsuction = Tsuction_new;
   12025            0 :                 Pipe_Q_c = Pipe_Q_c_new;
   12026            0 :                 this->OUFanPower = N_fan_OU;
   12027            0 :                 this->IUEvaporatingTemp = Te_new;
   12028              :             }
   12029              : 
   12030              :             //* Update h_comp_out in iteration (Label230)
   12031            0 :             h_comp_out_new = Ncomp / (m_ref_IU_evap + m_ref_OU_evap) + h_comp_in;
   12032              : 
   12033            0 :             converged_230 = !((std::abs(h_comp_out - h_comp_out_new) > Tolerance * h_comp_out) && (h_IU_cond_in < h_IU_cond_in_up));
   12034            0 :             h_IU_cond_in = h_IU_cond_in + 0.1 * (h_IU_cond_in_up - h_IU_cond_in_low);
   12035            0 :         } while (!converged_230);
   12036            0 :         if (h_IU_cond_in > h_IU_cond_in_up) {
   12037            0 :             h_IU_cond_in = 0.5 * (h_IU_cond_in_up + h_IU_cond_in_low);
   12038              :         }
   12039              : 
   12040              :         //===**h_comp_out Iteration Ends (Label230)
   12041              : 
   12042              :         // Key outputs of this subroutine
   12043            0 :         this->CompActSpeed = max(CompSpdActual, 0.0);
   12044            0 :         this->Ncomp = max(Ncomp, 0.0) / this->EffCompInverter;
   12045            0 :         this->VRFCondCyclingRatio = 1.0;
   12046              : 
   12047            0 :         this->HeatingCapacity =
   12048            0 :             this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(NumOfCompSpdInput), Tdischarge, Tsuction) +
   12049            0 :             this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(NumOfCompSpdInput), Tdischarge, Tsuction); // Include the piping loss
   12050            0 :         state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond) =
   12051            0 :             this->HeatingCapacity; // for report, maximum heating capacity of the system, at the highest compressor speed
   12052            0 :         this->PipingCorrectionHeating = TU_HeatingLoad / Q_h_TU_PL;
   12053              : 
   12054            0 :         this->CoolingCapacity =
   12055            0 :             this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(NumOfCompSpdInput), Tdischarge, Tsuction);
   12056            0 :         state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond) =
   12057            0 :             this->CoolingCapacity; // for report, maximum evaporating capacity of the system, at the highest compressor speed
   12058            0 :         this->PipingCorrectionCooling = TU_CoolingLoad / Q_c_TU_PL;
   12059              : 
   12060            0 :         this->CondensingTemp = Tdischarge; // OU condensing temperature
   12061            0 :         this->EvaporatingTemp = Tsuction;  // OU evaporating temperature
   12062              : 
   12063            0 :         this->OUCondHeatRate = Q_h_OU;
   12064            0 :         this->OUEvapHeatRate = Q_c_OU;
   12065            0 :         this->IUCondHeatRate = TU_HeatingLoad;
   12066            0 :         this->IUEvapHeatRate = TU_CoolingLoad;
   12067              : 
   12068              :         // 4. Stop running
   12069            0 :     } else {
   12070              : 
   12071          592 :         this->OperatingMode = 0;
   12072          592 :         this->VRFOperationSimPath = 0;
   12073              : 
   12074          592 :         this->Ncomp = 0.0;
   12075          592 :         this->CompActSpeed = 0.0;
   12076          592 :         this->OUFanPower = 0.0;
   12077          592 :         this->VRFCondCyclingRatio = 0.0;
   12078              : 
   12079          592 :         this->HeatingCapacity = 0.0;                                              // Include the piping loss
   12080          592 :         this->PipingCorrectionHeating = 1.0;                                      // 1 means no piping loss
   12081          592 :         state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond) = Constant::MaxCap; // yujie: default value is MaxCap = 1e+20, not 0
   12082              : 
   12083          592 :         this->CoolingCapacity = 0.0; // Include the piping loss
   12084          592 :         this->PipingCorrectionCooling = 1.0;
   12085          592 :         state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond) = Constant::MaxCap; // for report
   12086              : 
   12087          592 :         this->CondensingTemp = state.dataEnvrn->OutDryBulbTemp;
   12088          592 :         this->EvaporatingTemp = state.dataEnvrn->OutDryBulbTemp;
   12089              : 
   12090          592 :         this->OUCondHeatRate = 0.0;
   12091          592 :         this->OUEvapHeatRate = 0.0;
   12092          592 :         this->IUCondHeatRate = 0.0;
   12093          592 :         this->IUEvapHeatRate = 0.0;
   12094              :     }
   12095              : 
   12096              :     // calculate capacities and energy use
   12097        23126 :     if (((!this->HeatRecoveryUsed && state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) || (this->HeatRecoveryUsed && HRCoolRequestFlag)) &&
   12098         8127 :         state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).CoolingCoilPresent(NumTUInList)) {
   12099         8127 :         InletAirWetBulbC = SumCoolInletWB;
   12100              : 
   12101              :         // From the VRF_FluidTCtrl model
   12102         8127 :         TotalCondCoolingCapacity = this->CoolingCapacity;
   12103         8127 :         TotalTUCoolingCapacity = TotalCondCoolingCapacity * this->PipingCorrectionCooling;
   12104              : 
   12105         8127 :         if (TotalCondCoolingCapacity > 0.0) {
   12106         8127 :             CoolingPLR = min(1.0, (this->TUCoolingLoad / this->PipingCorrectionCooling) / TotalCondCoolingCapacity);
   12107              :         } else {
   12108            0 :             CoolingPLR = 0.0;
   12109              :         }
   12110              :     }
   12111        21279 :     if (((!this->HeatRecoveryUsed && state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) || (this->HeatRecoveryUsed && HRHeatRequestFlag)) &&
   12112         6280 :         state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).HeatingCoilPresent(NumTUInList)) {
   12113         6280 :         InletAirDryBulbC = SumHeatInletDB;
   12114         6280 :         InletAirWetBulbC = SumHeatInletWB;
   12115              : 
   12116              :         // Initializing defrost adjustment factors
   12117         6280 :         LoadDueToDefrost = 0.0;
   12118         6280 :         HeatingCapacityMultiplier = 1.0;
   12119         6280 :         FractionalDefrostTime = 0.0;
   12120         6280 :         InputPowerMultiplier = 1.0;
   12121              : 
   12122              :         // Check outdoor temperature to determine of defrost is active
   12123         6280 :         if (OutdoorDryBulb <= this->MaxOATDefrost && this->CondenserType != DataHeatBalance::RefrigCondenserType::Water) {
   12124              : 
   12125              :             // Calculating adjustment factors for defrost
   12126              :             // Calculate delta w through outdoor coil by assuming a coil temp of 0.82*DBT-9.7(F) per DOE2.1E
   12127         3514 :             OutdoorCoilT = 0.82 * OutdoorDryBulb - 8.589;
   12128         3514 :             OutdoorCoildw = max(1.0e-6, (OutdoorHumRat - PsyWFnTdpPb(state, OutdoorCoilT, OutdoorPressure)));
   12129              : 
   12130              :             // Calculate defrost adjustment factors depending on defrost control type
   12131         3514 :             if (this->DefrostControl == StandardRatings::HPdefrostControl::Timed) {
   12132         3514 :                 FractionalDefrostTime = this->DefrostFraction;
   12133         3514 :                 if (FractionalDefrostTime > 0.0) {
   12134         3514 :                     HeatingCapacityMultiplier = 0.909 - 107.33 * OutdoorCoildw;
   12135         3514 :                     InputPowerMultiplier = 0.90 - 36.45 * OutdoorCoildw;
   12136              :                 }
   12137              :             } else { // else defrost control is on-demand
   12138            0 :                 FractionalDefrostTime = 1.0 / (1.0 + 0.01446 / OutdoorCoildw);
   12139            0 :                 HeatingCapacityMultiplier = 0.875 * (1.0 - FractionalDefrostTime);
   12140            0 :                 InputPowerMultiplier = 0.954 * (1.0 - FractionalDefrostTime);
   12141              :             }
   12142              : 
   12143         3514 :             if (FractionalDefrostTime > 0.0) {
   12144              :                 // Calculate defrost adjustment factors depending on defrost control strategy
   12145         3514 :                 if (this->DefrostStrategy == StandardRatings::DefrostStrat::ReverseCycle &&
   12146         3514 :                     this->DefrostControl == StandardRatings::HPdefrostControl::OnDemand) {
   12147            0 :                     LoadDueToDefrost = (0.01 * FractionalDefrostTime) * (7.222 - OutdoorDryBulb) * (this->HeatingCapacity / 1.01667);
   12148            0 :                     DefrostEIRTempModFac = CurveValue(state, this->DefrostEIRPtr, max(15.555, InletAirWetBulbC), max(15.555, OutdoorDryBulb));
   12149              : 
   12150              :                     //         Warn user if curve output goes negative
   12151            0 :                     if (DefrostEIRTempModFac < 0.0) {
   12152            0 :                         if (!state.dataGlobal->WarmupFlag) {
   12153            0 :                             if (this->DefrostHeatErrorIndex == 0) {
   12154            0 :                                 ShowSevereMessage(state, format("{} \"{}\":", cVRFTypes(VRF_HeatPump), this->Name));
   12155            0 :                                 ShowContinueError(
   12156              :                                     state,
   12157            0 :                                     format(" Defrost Energy Input Ratio Modifier curve (function of temperature) output is negative ({:.3T}).",
   12158              :                                            DefrostEIRTempModFac));
   12159            0 :                                 ShowContinueError(state,
   12160            0 :                                                   format(" Negative value occurs using an outdoor air dry-bulb temperature of {:.1T} C and an "
   12161              :                                                          "average indoor air wet-bulb temperature of {:.1T} C.",
   12162              :                                                          OutdoorDryBulb,
   12163              :                                                          InletAirWetBulbC));
   12164            0 :                                 ShowContinueErrorTimeStamp(state, " Resetting curve output to zero and continuing simulation.");
   12165              :                             }
   12166            0 :                             ShowRecurringWarningErrorAtEnd(state,
   12167            0 :                                                            format("{} \"{}\": Defrost Energy Input Ratio Modifier curve (function of temperature) "
   12168              :                                                                   "output is negative warning continues...",
   12169            0 :                                                                   PlantEquipTypeNames[static_cast<int>(PlantEquipmentType::HeatPumpVRF)],
   12170            0 :                                                                   this->Name),
   12171            0 :                                                            this->DefrostHeatErrorIndex,
   12172              :                                                            DefrostEIRTempModFac,
   12173              :                                                            DefrostEIRTempModFac);
   12174            0 :                             DefrostEIRTempModFac = 0.0;
   12175              :                         }
   12176              :                     }
   12177              : 
   12178            0 :                     this->DefrostPower = DefrostEIRTempModFac * (this->HeatingCapacity / 1.01667) * FractionalDefrostTime;
   12179              : 
   12180              :                 } else { // Defrost strategy is resistive
   12181         3514 :                     this->DefrostPower = this->DefrostCapacity * FractionalDefrostTime;
   12182              :                 }
   12183              :             } else { // Defrost is not active because FractionalDefrostTime = 0.0
   12184            0 :                 this->DefrostPower = 0.0;
   12185              :             }
   12186              :         }
   12187              : 
   12188              :         // From the VRF_FluidTCtrl model
   12189         6280 :         TotalCondHeatingCapacity = this->HeatingCapacity;
   12190         6280 :         TotalTUHeatingCapacity = TotalCondHeatingCapacity * this->PipingCorrectionHeating;
   12191              : 
   12192         6280 :         if (TotalCondHeatingCapacity > 0.0) {
   12193         6280 :             HeatingPLR = min(1.0, (this->TUHeatingLoad / this->PipingCorrectionHeating) / TotalCondHeatingCapacity);
   12194         6280 :             HeatingPLR += (LoadDueToDefrost * HeatingPLR) / TotalCondHeatingCapacity;
   12195              :         } else {
   12196            0 :             HeatingPLR = 0.0;
   12197              :         }
   12198              :     }
   12199              : 
   12200        14999 :     this->VRFCondPLR = max(CoolingPLR, HeatingPLR);
   12201              : 
   12202              :     // For VRF-HR Operations
   12203        14999 :     HRInitialCapFrac = 1.0;
   12204        14999 :     HRInitialEIRFrac = 1.0;
   12205        14999 :     HRCapTC = 0.0;
   12206        14999 :     HREIRTC = 0.0;
   12207        14999 :     if (!state.dataGlobal->DoingSizing && !state.dataGlobal->WarmupFlag) {
   12208         2074 :         if (HRHeatRequestFlag && HRCoolRequestFlag) { // Simultaneous Heating and Cooling operations for HR system
   12209              :             // determine operating mode change: (1) ModeChange (2) HRCoolingActive (3) HRHeatingActive
   12210            0 :             if (!this->HRCoolingActive && !this->HRHeatingActive) {
   12211            0 :                 this->ModeChange = true;
   12212              :             }
   12213            0 :             if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) {
   12214            0 :                 if (this->HRHeatingActive && !this->HRCoolingActive) {
   12215            0 :                     this->HRModeChange = true;
   12216              :                 }
   12217            0 :                 this->HRCoolingActive = true;
   12218            0 :                 this->HRHeatingActive = false;
   12219              : 
   12220            0 :                 HRInitialCapFrac = this->HRInitialCoolCapFrac; // Fractional cooling degradation at the start of heat recovery from cooling mode
   12221            0 :                 HRCapTC = this->HRCoolCapTC;                   // Time constant used to recover from initial degradation in cooling heat recovery
   12222              : 
   12223            0 :                 HRInitialEIRFrac = this->HRInitialCoolEIRFrac; // Fractional cooling degradation at the start of heat recovery from cooling mode
   12224            0 :                 HREIRTC = this->HRCoolEIRTC;                   // Time constant used to recover from initial degradation in cooling heat recovery
   12225              : 
   12226            0 :             } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) {
   12227            0 :                 if (!this->HRHeatingActive && this->HRCoolingActive) {
   12228            0 :                     this->HRModeChange = true;
   12229              :                 }
   12230            0 :                 this->HRCoolingActive = false;
   12231            0 :                 this->HRHeatingActive = true;
   12232              : 
   12233            0 :                 HRInitialCapFrac = this->HRInitialHeatCapFrac; // Fractional heating degradation at the start of heat recovery from cooling mode
   12234            0 :                 HRCapTC = this->HRHeatCapTC;                   // Time constant used to recover from initial degradation in heating heat recovery
   12235              : 
   12236            0 :                 HRInitialEIRFrac = this->HRInitialHeatEIRFrac; // Fractional heating degradation at the start of heat recovery from heating mode
   12237            0 :                 HREIRTC = this->HRHeatEIRTC;                   // Time constant used to recover from initial degradation in heating heat recovery
   12238              : 
   12239              :             } else {
   12240              :                 // zone thermostats satisfied, condenser is off. Set values anyway
   12241              :                 // HRCAPFTConst = 1.0;
   12242            0 :                 HRInitialCapFrac = 1.0;
   12243            0 :                 HRCapTC = 1.0;
   12244              :                 // HREIRFTConst = 1.0;
   12245            0 :                 HRInitialEIRFrac = 1.0;
   12246            0 :                 HREIRTC = 1.0;
   12247            0 :                 if (this->HRHeatingActive || this->HRCoolingActive) {
   12248            0 :                     this->HRModeChange = true;
   12249              :                 }
   12250            0 :                 this->HRCoolingActive = false;
   12251            0 :                 this->HRHeatingActive = false;
   12252              :             }
   12253              : 
   12254              :         } else { // IF(HRHeatRequestFlag .AND. HRCoolRequestFlag)THEN -- Heat recovery turned off
   12255         2074 :             HRInitialCapFrac = 1.0;
   12256         2074 :             HRCapTC = 0.0;
   12257         2074 :             HRInitialEIRFrac = 1.0;
   12258         2074 :             HREIRTC = 0.0;
   12259         2074 :             this->HRModeChange = false;
   12260         2074 :             this->HRCoolingActive = false;
   12261         2074 :             this->HRHeatingActive = false;
   12262              :         }
   12263              : 
   12264              :         // Calculate the capacity modification factor (SUMultiplier) for the HR mode transition period
   12265              :         {
   12266         2074 :             CurrentEndTime = double((state.dataGlobal->DayOfSim - 1) * 24) + state.dataGlobal->CurrentTime - state.dataGlobal->TimeStepZone +
   12267         2074 :                              state.dataHVACGlobal->SysTimeElapsed;
   12268              : 
   12269         2074 :             if (this->ModeChange || this->HRModeChange) {
   12270            0 :                 if (this->HRCoolingActive && this->HRTimer == 0.0) {
   12271            0 :                     this->HRTimer = state.dataHVACVarRefFlow->CurrentEndTimeLast;
   12272            0 :                 } else if (this->HRHeatingActive && this->HRTimer == 0.0) {
   12273            0 :                     this->HRTimer = state.dataHVACVarRefFlow->CurrentEndTimeLast;
   12274            0 :                 } else if (!this->HRCoolingActive && !this->HRHeatingActive) {
   12275            0 :                     this->HRTimer = 0.0;
   12276              :                 }
   12277              :             }
   12278              : 
   12279         2074 :             this->HRTime = max(0.0, CurrentEndTime - this->HRTimer);
   12280         2074 :             if (this->HRTime < (HRCapTC * 5.0)) {
   12281            0 :                 if (HRCapTC > 0.0) {
   12282            0 :                     SUMultiplier = min(1.0, 1.0 - std::exp(-this->HRTime / HRCapTC));
   12283              :                 } else {
   12284            0 :                     SUMultiplier = 1.0;
   12285              :                 }
   12286              :             } else {
   12287         2074 :                 SUMultiplier = 1.0;
   12288         2074 :                 this->ModeChange = false;
   12289         2074 :                 this->HRModeChange = false;
   12290              :             }
   12291         2074 :             this->SUMultiplier = SUMultiplier;
   12292              : 
   12293         2074 :             state.dataHVACVarRefFlow->CurrentEndTimeLast = CurrentEndTime;
   12294              :         }
   12295              : 
   12296              :         // Modify HR capacity for the transition period
   12297              :         {
   12298         2074 :             if (this->HeatRecoveryUsed && this->HRCoolingActive) {
   12299            0 :                 TotalCondCoolingCapacity =
   12300            0 :                     HRInitialCapFrac * TotalCondCoolingCapacity + (1.0 - HRInitialCapFrac) * TotalCondCoolingCapacity * SUMultiplier;
   12301            0 :                 TotalTUCoolingCapacity = TotalCondCoolingCapacity * this->PipingCorrectionCooling;
   12302            0 :                 if (TotalCondCoolingCapacity > 0.0) {
   12303            0 :                     CoolingPLR = min(1.0, (this->TUCoolingLoad / this->PipingCorrectionCooling) / TotalCondCoolingCapacity);
   12304              :                 } else {
   12305            0 :                     CoolingPLR = 0.0;
   12306              :                 }
   12307            0 :                 this->VRFHeatRec = this->TUHeatingLoad;
   12308         2074 :             } else if (this->HeatRecoveryUsed && this->HRHeatingActive) {
   12309            0 :                 TotalCondHeatingCapacity =
   12310            0 :                     HRInitialCapFrac * TotalCondHeatingCapacity + (1.0 - HRInitialCapFrac) * TotalCondHeatingCapacity * SUMultiplier;
   12311            0 :                 TotalTUHeatingCapacity = TotalCondHeatingCapacity * this->PipingCorrectionHeating;
   12312            0 :                 if (TotalCondHeatingCapacity > 0.0) {
   12313            0 :                     HeatingPLR = min(1.0, (this->TUHeatingLoad / this->PipingCorrectionHeating) / TotalCondHeatingCapacity);
   12314              :                 } else {
   12315            0 :                     HeatingPLR = 0.0;
   12316              :                 }
   12317            0 :                 this->VRFHeatRec = this->TUCoolingLoad;
   12318              :             }
   12319              : 
   12320         2074 :             this->VRFCondPLR = max(CoolingPLR, HeatingPLR);
   12321              :         }
   12322              :     }
   12323              : 
   12324        14999 :     this->TotalCoolingCapacity = TotalCondCoolingCapacity * CoolingPLR;
   12325        14999 :     this->TotalHeatingCapacity = TotalCondHeatingCapacity * HeatingPLR;
   12326              : 
   12327        14999 :     if (this->MinPLR > 0.0) {
   12328            0 :         bool const plrTooLow = this->VRFCondPLR < this->MinPLR;
   12329            0 :         bool const plrGreaterThanZero = this->VRFCondPLR > 0.0;
   12330            0 :         if (plrTooLow && plrGreaterThanZero) {
   12331            0 :             this->VRFCondPLR = this->MinPLR;
   12332              :         }
   12333              :     }
   12334              : 
   12335        14999 :     VRFRTF = 0.0;
   12336              :     // VRF Cooling and Heating Electric Power (output variables)
   12337        14999 :     if (this->OperatingMode == ModeCoolingOnly) {
   12338         8127 :         PartLoadFraction = 1.0;
   12339         8127 :         VRFRTF = min(1.0, (CyclingRatio / PartLoadFraction));
   12340              : 
   12341         8127 :         this->ElecCoolingPower = state.dataHVACVarRefFlow->VRF(VRFCond).Ncomp + this->OUFanPower;
   12342         8127 :         this->ElecHeatingPower = 0;
   12343              : 
   12344         6872 :     } else if (this->OperatingMode == ModeHeatingOnly) {
   12345         6280 :         PartLoadFraction = 1.0;
   12346         6280 :         VRFRTF = min(1.0, (CyclingRatio / PartLoadFraction));
   12347              : 
   12348         6280 :         this->ElecCoolingPower = 0;
   12349         6280 :         this->ElecHeatingPower = this->Ncomp + this->OUFanPower;
   12350              : 
   12351          592 :     } else if (this->OperatingMode == ModeCoolingAndHeating) {
   12352            0 :         PartLoadFraction = 1.0;
   12353            0 :         VRFRTF = min(1.0, (CyclingRatio / PartLoadFraction));
   12354              : 
   12355            0 :         this->ElecCoolingPower = (this->Ncomp + this->OUFanPower) * this->IUEvapHeatRate / (this->IUCondHeatRate + this->IUEvapHeatRate);
   12356            0 :         this->ElecHeatingPower = (this->Ncomp + this->OUFanPower) * this->IUCondHeatRate / (this->IUCondHeatRate + this->IUEvapHeatRate);
   12357              : 
   12358              :     } else {
   12359          592 :         this->ElecCoolingPower = 0;
   12360          592 :         this->ElecHeatingPower = 0;
   12361              :     }
   12362        14999 :     this->VRFCondRTF = VRFRTF;
   12363        14999 :     this->DefrostPower *= VRFRTF;
   12364              : 
   12365              :     // Calculate CrankCaseHeaterPower: VRF Heat Pump Crankcase Heater Electric Power [W]
   12366        14999 :     if (this->MaxOATCCHeater > OutdoorDryBulb) {
   12367              :         // calculate crankcase heater power
   12368         3516 :         this->CrankCaseHeaterPower = this->CCHeaterPower * (1.0 - VRFRTF);
   12369         3516 :         if (this->NumCompressors > 1) {
   12370            0 :             UpperStageCompressorRatio = (1.0 - this->CompressorSizeRatio) / (this->NumCompressors - 1);
   12371            0 :             for (Stage = 1; Stage <= this->NumCompressors - 2; ++Stage) {
   12372            0 :                 if (this->VRFCondPLR < (this->CompressorSizeRatio + Stage * UpperStageCompressorRatio)) {
   12373            0 :                     this->CrankCaseHeaterPower += this->CCHeaterPower;
   12374              :                 }
   12375              :             }
   12376              :         }
   12377              :     } else {
   12378        11483 :         this->CrankCaseHeaterPower = 0.0;
   12379              :     }
   12380              : 
   12381              :     // Calculate QCondenser: VRF Heat Pump Condenser Heat Transfer Rate [W]
   12382        14999 :     CondCapacity = max(this->TotalCoolingCapacity, this->TotalHeatingCapacity) * VRFRTF;
   12383        14999 :     CondPower = max(this->ElecCoolingPower, this->ElecHeatingPower);
   12384        14999 :     if (this->ElecHeatingPower > 0.0) {
   12385         6280 :         this->QCondenser = CondCapacity + CondPower - this->TUHeatingLoad / this->PipingCorrectionHeating;
   12386         8719 :     } else if (this->ElecCoolingPower > 0.0) {
   12387         8127 :         this->QCondenser = -CondCapacity + CondPower + this->TUCoolingLoad / this->PipingCorrectionCooling;
   12388              :     } else {
   12389          592 :         this->QCondenser = 0.0;
   12390              :     }
   12391              :     // if ( this->CondenserType == HVAC::EvapCooled )
   12392              : 
   12393              :     // Calculate OperatingHeatingCOP & OperatingCoolingCOP: VRF Heat Pump Operating COP []
   12394        14999 :     if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && CoolingPLR > 0.0) {
   12395         8127 :         if (this->ElecCoolingPower != 0.0) {
   12396              :             // this calc should use delivered capacity, not condenser capacity, use VRF(VRFCond).TUCoolingLoad
   12397         8127 :             this->OperatingCoolingCOP = (this->TotalCoolingCapacity) /
   12398         8127 :                                         (this->ElecCoolingPower + this->CrankCaseHeaterPower + this->EvapCondPumpElecPower + this->DefrostPower);
   12399              :         } else {
   12400            0 :             this->OperatingCoolingCOP = 0.0;
   12401              :         }
   12402              :     }
   12403        14999 :     if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) && HeatingPLR > 0.0) {
   12404              :         // this calc should use delivered capacity, not condenser capacity, use VRF(VRFCond).TUHeatingLoad
   12405         6280 :         if (this->ElecHeatingPower != 0.0) {
   12406         6280 :             this->OperatingHeatingCOP = (this->TotalHeatingCapacity) /
   12407         6280 :                                         (this->ElecHeatingPower + this->CrankCaseHeaterPower + this->EvapCondPumpElecPower + this->DefrostPower);
   12408              :         } else {
   12409            0 :             this->OperatingHeatingCOP = 0.0;
   12410              :         }
   12411              :     }
   12412              : 
   12413        14999 :     TotPower = TUParasiticPower + TUFanPower + this->ElecHeatingPower + this->ElecCoolingPower + this->CrankCaseHeaterPower +
   12414        14999 :                this->EvapCondPumpElecPower + this->DefrostPower;
   12415        14999 :     if (TotPower > 0.0) {
   12416        14999 :         this->OperatingCOP = (this->TUCoolingLoad + this->TUHeatingLoad) / TotPower;
   12417        14999 :         this->SCHE = this->OperatingCOP * 3.412141633; // see StandardRatings::ConvFromSIToIP
   12418              :     }
   12419              : 
   12420              :     // limit the TU capacity when the condenser is maxed out on capacity
   12421              :     // I think this next line will make the max cap report variable match the coil objects, will probably change the answer though
   12422              :     //  IF(CoolingLoad(VRFCond) .AND. NumTUInCoolingMode .GT. 0 .AND. MaxCoolingCapacity(VRFCond) == MaxCap)THEN
   12423        14999 :     if (state.dataHVACVarRefFlow->CoolingLoad(VRFCond) && NumTUInCoolingMode > 0) {
   12424              : 
   12425              :         //   IF TU capacity is greater than condenser capacity find maximum allowed TU capacity (i.e., conserve energy)
   12426         8127 :         if (TU_CoolingLoad > TotalTUCoolingCapacity) {
   12427            0 :             LimitTUCapacity(state,
   12428              :                             VRFCond,
   12429              :                             NumTUInList,
   12430              :                             TotalTUCoolingCapacity,
   12431            0 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad,
   12432            0 :                             state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond),
   12433              :                             TotalTUHeatingCapacity,
   12434            0 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad,
   12435            0 :                             state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond));
   12436              :         }
   12437         6872 :     } else if (state.dataHVACVarRefFlow->HeatingLoad(VRFCond) && NumTUInHeatingMode > 0) {
   12438              :         //   IF TU capacity is greater than condenser capacity
   12439         6280 :         if (TU_HeatingLoad > TotalTUHeatingCapacity) {
   12440         2026 :             LimitTUCapacity(state,
   12441              :                             VRFCond,
   12442              :                             NumTUInList,
   12443              :                             TotalTUHeatingCapacity,
   12444         2026 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalHeatLoad,
   12445         2026 :                             state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond),
   12446              :                             TotalTUCoolingCapacity,
   12447         2026 :                             state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad,
   12448         2026 :                             state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond));
   12449              :         }
   12450              :     } else {
   12451              :     }
   12452              : 
   12453              :     // Calculate the IU Te/Tc for the next time step
   12454        14999 :     this->CalcVRFIUTeTc_FluidTCtrl(state);
   12455              :     // update coil and IU evaporating temperature, also keep coil RTF updated with the condenser side cycling ratio, for the FluidTCtrl model
   12456        71370 :     for (int VRFTUNum = 1; VRFTUNum <= state.dataHVACVarRefFlow->NumVRFTU; ++VRFTUNum) {
   12457        56371 :         auto const &thisTU = state.dataHVACVarRefFlow->VRFTU(VRFTUNum);
   12458        56371 :         auto &coolingCoil = state.dataDXCoils->DXCoil(thisTU.CoolCoilIndex);
   12459        56371 :         if (this->adjustedTe && (!FirstHVACIteration)) {
   12460        13436 :             coolingCoil.EvaporatingTemp = this->EvaporatingTemp;
   12461        13436 :             this->IUEvaporatingTemp = this->EvaporatingTemp;
   12462              :         }
   12463              : 
   12464              :         int PLF;
   12465        56371 :         if (coolingCoil.PLFFPLR(1) > 0 && this->VRFCondCyclingRatio < 1.0) {
   12466            0 :             PLF = Curve::CurveValue(state, coolingCoil.PLFFPLR(1), this->VRFCondCyclingRatio); // Calculate part-load factor
   12467              :         } else {
   12468        56371 :             PLF = 1.0;
   12469              :         }
   12470        56371 :         if (coolingCoil.TotalCoolingEnergyRate > 0.0) {
   12471        29832 :             coolingCoil.CoolingCoilRuntimeFraction = this->VRFCondCyclingRatio / PLF;
   12472              :         }
   12473              :     }
   12474        14999 : }
   12475              : 
   12476        56371 : void VRFTerminalUnitEquipment::ControlVRF_FluidTCtrl(EnergyPlusData &state,
   12477              :                                                      int const VRFTUNum,            // Index to VRF terminal unit
   12478              :                                                      Real64 const QZnReq,           // Index to zone number
   12479              :                                                      bool const FirstHVACIteration, // flag for 1st HVAC iteration in the time step
   12480              :                                                      Real64 &PartLoadRatio,         // unit part load ratio
   12481              :                                                      Real64 &OnOffAirFlowRatio,     // ratio of compressor ON airflow to AVERAGE airflow over timestep
   12482              :                                                      Real64 &SuppHeatCoilLoad       // supplemental heating coil load (W)
   12483              : )
   12484              : {
   12485              : 
   12486              :     // SUBROUTINE INFORMATION:
   12487              :     //       AUTHOR         Rongpeng Zhang
   12488              :     //       DATE WRITTEN   Nov 2015
   12489              :     //       MODIFIED       na
   12490              :     //       RE-ENGINEERED  na
   12491              : 
   12492              :     // PURPOSE OF THIS SUBROUTINE:
   12493              :     // Determine the coil load and part load ratio, given the zone load
   12494              :     // Determine the air mass flow rate corresponding to the coil load of the heat pump for this time step
   12495              : 
   12496              :     // METHODOLOGY EMPLOYED:
   12497              :     // Use RegulaFalsi technique to iterate on part-load ratio until convergence is achieved.
   12498              : 
   12499              :     using General::SolveRoot;
   12500              : 
   12501        56371 :     int constexpr MaxIte(500);        // maximum number of iterations
   12502        56371 :     Real64 constexpr MinPLF(0.0);     // minimum part load factor allowed
   12503        56371 :     Real64 constexpr ErrorTol(0.001); // tolerance for RegulaFalsi iterations
   12504              : 
   12505              :     Real64 FullOutput;     // unit full output when compressor is operating [W]
   12506              :     Real64 TempOutput;     // unit output when iteration limit exceeded [W]
   12507              :     Real64 NoCompOutput;   // output when no active compressor [W]
   12508              :     Real64 TempMinPLR;     // min PLR used in Regula Falsi call
   12509              :     Real64 TempMaxPLR;     // max PLR used in Regula Falsi call
   12510              :     int VRFCond;           // index to VRF condenser
   12511              :     int IndexToTUInTUList; // index to TU in specific list for the VRF system
   12512              :     int TUListIndex;       // index to TU list for this VRF system
   12513              :     bool VRFCoolingMode;
   12514              :     bool VRFHeatingMode;
   12515              :     bool HRCoolingMode;
   12516              :     bool HRHeatingMode;
   12517              : 
   12518        56371 :     PartLoadRatio = 0.0;
   12519        56371 :     state.dataHVACVarRefFlow->LoopDXCoolCoilRTF = 0.0;
   12520        56371 :     state.dataHVACVarRefFlow->LoopDXHeatCoilRTF = 0.0;
   12521        56371 :     state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatPartLoadRatio = 0.0;
   12522        56371 :     VRFCond = this->VRFSysNum;
   12523        56371 :     IndexToTUInTUList = this->IndexToTUInTUList;
   12524        56371 :     auto &thisVRFCond = state.dataHVACVarRefFlow->VRF(VRFCond);
   12525        56371 :     TUListIndex = thisVRFCond.ZoneTUListPtr;
   12526        56371 :     VRFCoolingMode = state.dataHVACVarRefFlow->CoolingLoad(VRFCond);
   12527        56371 :     VRFHeatingMode = state.dataHVACVarRefFlow->HeatingLoad(VRFCond);
   12528        56371 :     HRCoolingMode = state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList);
   12529        56371 :     HRHeatingMode = state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList);
   12530        56371 :     auto &thisVRFTU = state.dataHVACVarRefFlow->VRFTU(VRFTUNum);
   12531              : 
   12532              :     // The RETURNS here will jump back to SimVRF where the CalcVRF routine will simulate with latest PLR
   12533              : 
   12534              :     // do nothing else if TU is scheduled off
   12535        56371 :     if (this->availSched->getCurrentVal() == 0.0) {
   12536         7568 :         return;
   12537              :     }
   12538              : 
   12539              :     // Block the following statement: QZnReq==0 doesn't mean QCoilReq==0 due to possible OA mixer operation. zrp_201511
   12540              :     // do nothing if TU has no load (TU will be modeled using PLR=0)
   12541              :     // if ( QZnReq == 0.0 ) return;
   12542              : 
   12543              :     // Set EMS value for PLR and return
   12544        56371 :     if (this->EMSOverridePartLoadFrac) {
   12545            0 :         PartLoadRatio = this->EMSValueForPartLoadFrac;
   12546            0 :         return;
   12547              :     }
   12548              : 
   12549              :     // Get result when DX coil is off
   12550        56371 :     PartLoadRatio = 0.0;
   12551        56371 :     bool DXCoolingCoilOprCtrl = true;
   12552              : 
   12553              :     // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
   12554        56371 :     this->CalcVRF_FluidTCtrl(state, VRFTUNum, FirstHVACIteration, 0.0, NoCompOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   12555              : 
   12556        56371 :     if (VRFCoolingMode && HRHeatingMode) {
   12557              :         // IF the system is in cooling mode, but the terminal unit requests heating (heat recovery)
   12558            0 :         if (NoCompOutput >= QZnReq) {
   12559            0 :             return;
   12560              :         }
   12561        56371 :     } else if (VRFHeatingMode && HRCoolingMode) {
   12562              :         // IF the system is in heating mode, but the terminal unit requests cooling (heat recovery)
   12563            0 :         if (NoCompOutput <= QZnReq) {
   12564            0 :             return;
   12565              :         }
   12566        56371 :     } else if (VRFCoolingMode || HRCoolingMode) {
   12567              :         // IF the system is in cooling mode and/or the terminal unit requests cooling
   12568        30491 :         if (NoCompOutput <= QZnReq && ((QZnReq <= 0.0) || (QZnReq >= HVAC::SmallLoad && !HRCoolingMode))) {
   12569          601 :             DXCoolingCoilOprCtrl = false;
   12570          601 :             if (!this->SuppHeatingCoilPresent) {
   12571            0 :                 return;
   12572              :             }
   12573              :         }
   12574        25880 :     } else if (VRFHeatingMode || HRHeatingMode) {
   12575              :         // IF the system is in heating mode and/or the terminal unit requests heating
   12576        23116 :         if (NoCompOutput >= QZnReq) {
   12577            0 :             return;
   12578              :         }
   12579              :     }
   12580              : 
   12581              :     // Otherwise the coil needs to turn on. Get full load result
   12582        56371 :     PartLoadRatio = 1.0;
   12583        56371 :     if (!DXCoolingCoilOprCtrl) {
   12584          601 :         PartLoadRatio = 0.0;
   12585              :     }
   12586        56371 :     this->CalcVRF_FluidTCtrl(state, VRFTUNum, FirstHVACIteration, PartLoadRatio, FullOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   12587        56371 :     if (this->CoolingCoilPresent) {
   12588        56371 :         auto const &thisAirInNode = state.dataLoopNodes->Node(state.dataDXCoils->DXCoil(this->CoolCoilIndex).AirInNode);
   12589        56371 :         this->coilInNodeT = thisAirInNode.Temp;
   12590        56371 :         this->coilInNodeW = thisAirInNode.HumRat;
   12591              :     } else {
   12592            0 :         auto const &thisAirInNode = state.dataLoopNodes->Node(state.dataDXCoils->DXCoil(this->HeatCoilIndex).AirInNode);
   12593            0 :         this->coilInNodeT = thisAirInNode.Temp;
   12594            0 :         this->coilInNodeW = thisAirInNode.HumRat;
   12595              :     }
   12596              : 
   12597              :     // set supplemental heating coil calculation if the condition requires
   12598        56371 :     if (this->SuppHeatingCoilPresent) {
   12599        22231 :         auto const &thisSuppHeatCoilAirInletNode = state.dataLoopNodes->Node(this->SuppHeatCoilAirInletNode);
   12600        22231 :         if (((QZnReq > HVAC::SmallLoad && QZnReq > FullOutput) || (((QZnReq - NoCompOutput) > HVAC::SmallLoad) && QZnReq <= 0.0)) ||
   12601        14522 :             (this->isSetPointControlled && this->suppTempSetPoint > thisSuppHeatCoilAirInletNode.Temp)) {
   12602         7709 :             Real64 ZoneLoad = 0.0;
   12603         7709 :             Real64 LoadToHeatingSP = 0.0;
   12604         7709 :             Real64 LoadToCoolingSP = 0.0;
   12605         7709 :             if (this->isSetPointControlled) {
   12606            0 :                 Real64 mDot = thisSuppHeatCoilAirInletNode.MassFlowRate;
   12607            0 :                 Real64 Tin = thisSuppHeatCoilAirInletNode.Temp;
   12608            0 :                 Real64 Win = thisSuppHeatCoilAirInletNode.HumRat;
   12609            0 :                 Real64 CpAirIn = Psychrometrics::PsyCpAirFnW(Win);
   12610            0 :                 SuppHeatCoilLoad = mDot * CpAirIn * (this->suppTempSetPoint - Tin);
   12611            0 :                 this->SuppHeatingCoilLoad = SuppHeatCoilLoad;
   12612            0 :                 if (this->DesignSuppHeatingCapacity > 0.0) {
   12613            0 :                     this->SuppHeatPartLoadRatio = min(1.0, SuppHeatCoilLoad / this->DesignSuppHeatingCapacity);
   12614              :                 }
   12615              :             } else {
   12616         7709 :                 getVRFTUZoneLoad(state, VRFTUNum, ZoneLoad, LoadToHeatingSP, LoadToCoolingSP, false);
   12617         7709 :                 if (((FullOutput < (LoadToHeatingSP - HVAC::SmallLoad) || ((QZnReq - NoCompOutput) > HVAC::SmallLoad && QZnReq <= 0.0))) &&
   12618         7705 :                     !FirstHVACIteration) {
   12619         3848 :                     if ((QZnReq - NoCompOutput) > HVAC::SmallLoad && QZnReq <= 0.0) {
   12620         1531 :                         if (LoadToHeatingSP < 0.0 && QZnReq == 0.0) {
   12621         1465 :                             SuppHeatCoilLoad = max(0.0, LoadToHeatingSP - FullOutput);
   12622              :                         } else {
   12623           66 :                             SuppHeatCoilLoad = max(0.0, QZnReq - FullOutput);
   12624              :                         }
   12625              :                     } else {
   12626         2317 :                         if (QZnReq > 0.0 && (NoCompOutput - QZnReq) >= HVAC::SmallLoad) {
   12627           14 :                             SuppHeatCoilLoad = 0.0;
   12628              :                         } else {
   12629         2303 :                             SuppHeatCoilLoad = max(0.0, LoadToHeatingSP - FullOutput);
   12630              :                         }
   12631              :                     }
   12632         3848 :                     this->SuppHeatingCoilLoad = SuppHeatCoilLoad;
   12633         3848 :                     if (this->DesignSuppHeatingCapacity > 0.0) {
   12634         3848 :                         this->SuppHeatPartLoadRatio = min(1.0, SuppHeatCoilLoad / this->DesignSuppHeatingCapacity);
   12635              :                     }
   12636              :                 } else {
   12637         3861 :                     SuppHeatCoilLoad = 0.0;
   12638         3861 :                     this->SuppHeatPartLoadRatio = 0.0;
   12639              :                 }
   12640              :             }
   12641         7709 :         } else {
   12642        14522 :             SuppHeatCoilLoad = 0.0;
   12643        14522 :             this->SuppHeatPartLoadRatio = 0.0;
   12644              :         }
   12645              :     } else {
   12646        34140 :         SuppHeatCoilLoad = 0.0;
   12647        34140 :         this->SuppHeatPartLoadRatio = 0.0;
   12648              :     }
   12649              : 
   12650        56371 :     if ((VRFCoolingMode && !thisVRFCond.HeatRecoveryUsed) || (thisVRFCond.HeatRecoveryUsed && HRCoolingMode)) {
   12651              :         // Since we are cooling, we expect FullOutput < NoCompOutput
   12652              :         // If the QZnReq <= FullOutput the unit needs to run full out
   12653        30453 :         if (QZnReq <= FullOutput) {
   12654              :             // if no coil present in terminal unit, no need to reset PLR?
   12655           62 :             if (thisVRFTU.CoolingCoilPresent) {
   12656           62 :                 PartLoadRatio = 1.0;
   12657              :                 // the zone set point could be exceeded if set point control is used so protect against that
   12658           62 :                 if (this->isSetPointControlled) {
   12659            0 :                     if (state.dataLoopNodes->Node(this->coolCoilAirOutNode).Temp > this->coilTempSetPoint) {
   12660            0 :                         return;
   12661              :                     }
   12662              :                 } else {
   12663           62 :                     if (QZnReq >= 0.0 && FullOutput >= 0.0) {
   12664            7 :                         PartLoadRatio = 0.0;
   12665              :                     }
   12666           62 :                     return;
   12667              :                 }
   12668              :             } else {
   12669            0 :                 PartLoadRatio = 0.0;
   12670            0 :                 return;
   12671              :             }
   12672              :         } else {
   12673        30391 :             if (QZnReq == 0.0 && (FullOutput < 0.0 && NoCompOutput < FullOutput)) {
   12674            0 :                 PartLoadRatio = 0.0;
   12675            0 :                 return;
   12676              :             }
   12677              :         }
   12678        25918 :     } else if ((VRFHeatingMode && !thisVRFCond.HeatRecoveryUsed) || (thisVRFCond.HeatRecoveryUsed && HRHeatingMode)) {
   12679              :         // Since we are heating, we expect FullOutput > NoCompOutput
   12680              :         // If the QZnReq >= FullOutput the unit needs to run full out
   12681        23011 :         if (QZnReq >= FullOutput) {
   12682              :             // if no coil present in terminal unit, no need reset PLR?
   12683         4599 :             if (this->HeatingCoilPresent) {
   12684         4599 :                 PartLoadRatio = 1.0;
   12685              :                 // the zone set point could be exceeded if set point control is used so protect against that
   12686         4599 :                 if (this->isSetPointControlled) {
   12687            0 :                     if (state.dataLoopNodes->Node(this->heatCoilAirOutNode).Temp < this->coilTempSetPoint) {
   12688            0 :                         return;
   12689              :                     }
   12690              :                 } else {
   12691         4599 :                     return;
   12692              :                 }
   12693              :             } else {
   12694            0 :                 PartLoadRatio = 0.0;
   12695            0 :                 return;
   12696              :             }
   12697              :         }
   12698              :     } else {
   12699              :         // VRF terminal unit is off
   12700              :         // shouldn't actually get here
   12701         2907 :         PartLoadRatio = 0.0;
   12702         2907 :         return;
   12703              :     }
   12704              : 
   12705              :     // The coil will not operate at PLR=0 or PLR=1, calculate the operating part-load ratio
   12706              : 
   12707        48803 :     if ((VRFHeatingMode || HRHeatingMode) || ((VRFCoolingMode && DXCoolingCoilOprCtrl) || HRCoolingMode)) {
   12708              :         int SolFla; // Flag of RegulaFalsi solver
   12709       299803 :         auto f = [&state, VRFTUNum, FirstHVACIteration, QZnReq, OnOffAirFlowRatio](Real64 const PartLoadRatio) {
   12710       251601 :             Real64 QZnReqTemp = QZnReq;    // denominator representing zone load (W)
   12711              :             Real64 ActualOutput;           // delivered capacity of VRF terminal unit
   12712       251601 :             Real64 SuppHeatCoilLoad = 0.0; // supplemental heating coil load (W)
   12713       251601 :             bool setPointControlled = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).isSetPointControlled;
   12714       251601 :             Real64 nonConstOnOffAirFlowRatio = OnOffAirFlowRatio;
   12715              : 
   12716       251601 :             if (state.dataHVACVarRefFlow->VRF(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum).VRFAlgorithmType == AlgorithmType::FluidTCtrl) {
   12717              :                 // Algorithm Type: VRF model based on physics, applicable for Fluid Temperature Control
   12718       251601 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF_FluidTCtrl(
   12719              :                     state, VRFTUNum, FirstHVACIteration, PartLoadRatio, ActualOutput, nonConstOnOffAirFlowRatio, SuppHeatCoilLoad);
   12720              :             } else {
   12721              :                 // Algorithm Type: VRF model based on system curve
   12722            0 :                 state.dataHVACVarRefFlow->VRFTU(VRFTUNum).CalcVRF(
   12723              :                     state, VRFTUNum, FirstHVACIteration, PartLoadRatio, ActualOutput, nonConstOnOffAirFlowRatio, SuppHeatCoilLoad);
   12724              :             }
   12725              : 
   12726       251601 :             if (setPointControlled) {
   12727            0 :                 Real64 outletNodeT = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUOutletNodeNum).Temp;
   12728            0 :                 return (outletNodeT - state.dataHVACVarRefFlow->VRFTU(VRFTUNum).coilTempSetPoint);
   12729              :             } else {
   12730       251601 :                 if (std::abs(QZnReq) < 100.0) {
   12731        15866 :                     QZnReqTemp = sign(100.0, QZnReq);
   12732              :                 }
   12733       251601 :                 return (ActualOutput - QZnReq) / QZnReqTemp;
   12734              :             }
   12735        48202 :         };
   12736        48202 :         SolveRoot(state, ErrorTol, MaxIte, SolFla, PartLoadRatio, f, 0.0, 1.0);
   12737        48202 :         if (SolFla == -1) {
   12738              :             //     Very low loads may not converge quickly. Tighten PLR boundary and try again.
   12739          253 :             TempMaxPLR = -0.1;
   12740          253 :             bool ContinueIter = true;
   12741         1506 :             while (ContinueIter && TempMaxPLR < 1.0) {
   12742         1253 :                 TempMaxPLR += 0.1;
   12743              : 
   12744         1253 :                 this->CalcVRF_FluidTCtrl(state, VRFTUNum, FirstHVACIteration, TempMaxPLR, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   12745              : 
   12746         1253 :                 if (VRFHeatingMode && TempOutput > QZnReq) {
   12747           74 :                     ContinueIter = false;
   12748              :                 }
   12749         1253 :                 if (VRFCoolingMode && TempOutput < QZnReq) {
   12750          179 :                     ContinueIter = false;
   12751              :                 }
   12752              :             }
   12753          253 :             TempMinPLR = TempMaxPLR;
   12754          253 :             ContinueIter = true;
   12755         2321 :             while (ContinueIter && TempMinPLR > 0.0) {
   12756         2068 :                 TempMaxPLR = TempMinPLR;
   12757         2068 :                 TempMinPLR -= 0.01;
   12758              : 
   12759         2068 :                 this->CalcVRF_FluidTCtrl(state, VRFTUNum, FirstHVACIteration, TempMaxPLR, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   12760              : 
   12761         2068 :                 if (VRFHeatingMode && TempOutput < QZnReq) {
   12762           74 :                     ContinueIter = false;
   12763              :                 }
   12764         2068 :                 if (VRFCoolingMode && TempOutput > QZnReq) {
   12765          179 :                     ContinueIter = false;
   12766              :                 }
   12767              :             }
   12768              : 
   12769          253 :             SolveRoot(state, ErrorTol, MaxIte, SolFla, PartLoadRatio, f, TempMinPLR, TempMaxPLR);
   12770          253 :             if (SolFla == -1) {
   12771            0 :                 if (!FirstHVACIteration && !state.dataGlobal->WarmupFlag) {
   12772            0 :                     if (this->IterLimitExceeded == 0) {
   12773            0 :                         ShowWarningMessage(state, format("{} \"{}\"", tuTypeNames[(int)this->type], this->Name));
   12774            0 :                         ShowContinueError(
   12775            0 :                             state, format(" Iteration limit exceeded calculating terminal unit part-load ratio, maximum iterations = {}", MaxIte));
   12776            0 :                         ShowContinueErrorTimeStamp(state, format(" Part-load ratio returned = {:.3R}", PartLoadRatio));
   12777              : 
   12778            0 :                         this->CalcVRF_FluidTCtrl(state, VRFTUNum, FirstHVACIteration, TempMinPLR, TempOutput, OnOffAirFlowRatio, SuppHeatCoilLoad);
   12779              : 
   12780            0 :                         ShowContinueError(state, format(" Load requested = {:.5T}, Load delivered = {:.5T}", QZnReq, TempOutput));
   12781            0 :                         ShowRecurringWarningErrorAtEnd(state,
   12782            0 :                                                        format("{} \"{}\" -- Terminal unit Iteration limit exceeded error continues...",
   12783            0 :                                                               tuTypeNames[(int)this->type],
   12784            0 :                                                               this->Name),
   12785            0 :                                                        this->IterLimitExceeded);
   12786              :                     } else {
   12787            0 :                         ShowRecurringWarningErrorAtEnd(state,
   12788            0 :                                                        format("{} \"{}\" -- Terminal unit Iteration limit exceeded error continues...",
   12789            0 :                                                               tuTypeNames[(int)this->type],
   12790            0 :                                                               this->Name),
   12791            0 :                                                        this->IterLimitExceeded);
   12792              :                     }
   12793              :                 }
   12794          253 :             } else if (SolFla == -2) {
   12795          253 :                 PartLoadRatio = max(MinPLF, std::abs(QZnReq - NoCompOutput) / std::abs(FullOutput - NoCompOutput));
   12796              :             }
   12797        47949 :         } else if (SolFla == -2) {
   12798            0 :             if (FullOutput - NoCompOutput == 0.0) {
   12799            0 :                 PartLoadRatio = 0.0;
   12800              :             } else {
   12801            0 :                 PartLoadRatio = min(1.0, max(MinPLF, std::abs(QZnReq - NoCompOutput) / std::abs(FullOutput - NoCompOutput)));
   12802              :             }
   12803              :         }
   12804              :     }
   12805              : }
   12806              : 
   12807       527467 : void VRFTerminalUnitEquipment::CalcVRF_FluidTCtrl(EnergyPlusData &state,
   12808              :                                                   int const VRFTUNum,                           // Index to VRF terminal unit
   12809              :                                                   bool const FirstHVACIteration,                // flag for 1st HVAC iteration in the time step
   12810              :                                                   Real64 const PartLoadRatio,                   // compressor part load fraction
   12811              :                                                   Real64 &LoadMet,                              // load met by unit (W)
   12812              :                                                   Real64 &OnOffAirFlowRatio,                    // ratio of ON air flow to average air flow
   12813              :                                                   Real64 &SuppHeatCoilLoad,                     // supplemental heating coil load (W)
   12814              :                                                   ObjexxFCL::Optional<Real64> LatOutputProvided // delivered latent capacity (W)
   12815              : )
   12816              : {
   12817              : 
   12818              :     // SUBROUTINE INFORMATION:
   12819              :     //       AUTHOR         RP Zhang (LBNL), XF Pang (LBNL), Y Yura (Daikin Inc)
   12820              :     //       DATE WRITTEN   June 2015
   12821              :     //       MODIFIED       na
   12822              :     //       RE-ENGINEERED  na
   12823              : 
   12824              :     // PURPOSE OF THIS SUBROUTINE:
   12825              :     //         This subroutine is part of the new VRF model based on physics, applicable for Fluid Temperature Control.
   12826              :     //         This is adapted from subroutine CalcVRF, which is part of the VRF model based on system curves.
   12827              :     //         This subroutine simulates the components making up the VRF indoor terminal unit.
   12828              : 
   12829              :     // METHODOLOGY EMPLOYED:
   12830              :     //        A new physics based VRF model applicable for Fluid Temperature Control.
   12831              :     using DXCoils::SimDXCoil;
   12832              :     using SingleDuct::SimATMixer;
   12833              :     using SteamCoils::SimulateSteamCoilComponents;
   12834              :     using WaterCoils::SimulateWaterCoilComponents;
   12835              : 
   12836              :     int VRFTUOutletNodeNum; // TU air outlet node
   12837              :     int VRFTUInletNodeNum;  // TU air inlet node
   12838              :     Real64 AirMassFlow;     // total supply air mass flow [m3/s]
   12839              :     HVAC::FanOp fanOp;      // fan operating mode, HVAC::FanOp::Cycling or HVAC::FanOp::Continuous
   12840              :     int VRFCond;            // index to VRF condenser
   12841              :     Real64 SpecHumOut;      // specific humidity ratio at outlet node
   12842              :     Real64 SpecHumIn;       // specific humidity ratio at inlet node
   12843              :     int TUListIndex;        // index to TU list for this VRF system
   12844              :     int IndexToTUInTUList;  // index to TU in specific list for the VRF system
   12845              :     Real64 EvapTemp;        // evaporating temperature
   12846              :     Real64 CondTemp;        // condensing temperature
   12847              :     int ZoneNode;           // Zone node of VRFTU is serving
   12848              : 
   12849       527467 :     VRFCond = this->VRFSysNum;
   12850       527467 :     TUListIndex = state.dataHVACVarRefFlow->VRF(VRFCond).ZoneTUListPtr;
   12851       527467 :     IndexToTUInTUList = this->IndexToTUInTUList;
   12852       527467 :     VRFTUOutletNodeNum = this->VRFTUOutletNodeNum;
   12853       527467 :     VRFTUInletNodeNum = this->VRFTUInletNodeNum;
   12854       527467 :     fanOp = this->fanOp;
   12855       527467 :     EvapTemp = state.dataHVACVarRefFlow->VRF(VRFCond).IUEvaporatingTemp;
   12856       527467 :     CondTemp = state.dataHVACVarRefFlow->VRF(VRFCond).IUCondensingTemp;
   12857       527467 :     ZoneNode = this->ZoneAirNode;
   12858              : 
   12859              :     // Set inlet air mass flow rate based on PLR and compressor on/off air flow rates
   12860       527467 :     if (PartLoadRatio == 0) {
   12861              :         // only provide required OA when coil is off
   12862       212374 :         state.dataHVACVarRefFlow->CompOnMassFlow = state.dataHVACVarRefFlow->OACompOnMassFlow;
   12863       212374 :         state.dataHVACVarRefFlow->CompOffMassFlow = state.dataHVACVarRefFlow->OACompOffMassFlow;
   12864              :     } else {
   12865              :         // identify the air flow rate corresponding to the coil load
   12866       315093 :         if (this->HeatingCoilPresent && state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond) < Constant::MaxCap) {
   12867              :             // Only fix heating only mode for now
   12868        62890 :             state.dataHVACVarRefFlow->CompOnMassFlow = CalVRFTUAirFlowRate_FluidTCtrl(
   12869        62890 :                 state, VRFTUNum, PartLoadRatio, FirstHVACIteration, state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond));
   12870              :         } else {
   12871       252203 :             state.dataHVACVarRefFlow->CompOnMassFlow = CalVRFTUAirFlowRate_FluidTCtrl(state, VRFTUNum, PartLoadRatio, FirstHVACIteration, _);
   12872              :         }
   12873              :     }
   12874       527467 :     SetAverageAirFlow(state, VRFTUNum, PartLoadRatio, OnOffAirFlowRatio);
   12875       527467 :     AirMassFlow = state.dataLoopNodes->Node(VRFTUInletNodeNum).MassFlowRate;
   12876              : 
   12877       527467 :     if (this->ATMixerExists) {
   12878              :         // There is an air terminal mixer
   12879            0 :         state.dataHVACVarRefFlow->ATMixOutNode2 = this->ATMixerOutNode;
   12880            0 :         if (this->ATMixerType == HVAC::MixerType::InletSide) { // if there is an inlet side air terminal mixer
   12881              :             // set the primary air inlet mass flow rate
   12882            0 :             state.dataLoopNodes->Node(this->ATMixerPriNode).MassFlowRate =
   12883            0 :                 min(state.dataLoopNodes->Node(this->ATMixerPriNode).MassFlowRateMaxAvail, state.dataLoopNodes->Node(VRFTUInletNodeNum).MassFlowRate);
   12884              :             // now calculate the the mixer outlet air conditions (and the secondary air inlet flow rate). The mixer outlet flow rate has already
   12885              :             // been set above (it is the "inlet" node flow rate)
   12886            0 :             SimATMixer(state, this->ATMixerName, FirstHVACIteration, this->ATMixerIndex);
   12887              :             // inlet side ATMixer can change the VRF TU inlet condition and therefore the operating air flow rate
   12888            0 :             if (this->fanOp == HVAC::FanOp::Cycling && PartLoadRatio > 0) {
   12889            0 :                 if (this->HeatingCoilPresent && state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond) < Constant::MaxCap) {
   12890              :                     // Only fix heating only mode for now
   12891            0 :                     state.dataHVACVarRefFlow->CompOnMassFlow = CalVRFTUAirFlowRate_FluidTCtrl(
   12892            0 :                         state, VRFTUNum, PartLoadRatio, FirstHVACIteration, state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond));
   12893              :                 } else {
   12894            0 :                     state.dataHVACVarRefFlow->CompOnMassFlow = CalVRFTUAirFlowRate_FluidTCtrl(state, VRFTUNum, PartLoadRatio, FirstHVACIteration, _);
   12895              :                 }
   12896            0 :                 if (std::abs(state.dataHVACVarRefFlow->CompOnMassFlow - AirMassFlow) > HVAC::SmallMassFlow) {
   12897            0 :                     SetAverageAirFlow(state, VRFTUNum, PartLoadRatio, OnOffAirFlowRatio);
   12898            0 :                     AirMassFlow = state.dataLoopNodes->Node(VRFTUInletNodeNum).MassFlowRate;
   12899              :                     // set the primary air inlet mass flow rate
   12900            0 :                     state.dataLoopNodes->Node(this->ATMixerPriNode).MassFlowRate =
   12901            0 :                         min(state.dataLoopNodes->Node(this->ATMixerPriNode).MassFlowRateMaxAvail,
   12902            0 :                             state.dataLoopNodes->Node(VRFTUInletNodeNum).MassFlowRate);
   12903            0 :                     SimATMixer(state, this->ATMixerName, FirstHVACIteration, this->ATMixerIndex);
   12904              :                 }
   12905              :             }
   12906              :         }
   12907              :     } else {
   12908       527467 :         state.dataHVACVarRefFlow->ATMixOutNode2 = 0;
   12909              :         // simulate OA Mixer
   12910       527467 :         if (this->OAMixerUsed) {
   12911       527467 :             MixedAir::SimOAMixer(state, this->OAMixerName, this->OAMixerIndex);
   12912              :         }
   12913              :     }
   12914              :     // if blow through, simulate fan then coils
   12915       527467 :     if (this->fanPlace == HVAC::FanPlace::BlowThru) {
   12916            0 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanType == HVAC::FanType::SystemModel) {
   12917            0 :             if (OnOffAirFlowRatio > 0.0) {
   12918            0 :                 state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex)->simulate(state, FirstHVACIteration, _, _);
   12919              :             } else {
   12920            0 :                 state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex)->simulate(state, FirstHVACIteration, _, _, PartLoadRatio);
   12921              :             }
   12922              :         } else {
   12923            0 :             state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex)
   12924            0 :                 ->simulate(state, FirstHVACIteration, state.dataHVACVarRefFlow->FanSpeedRatio);
   12925              :         }
   12926              :     }
   12927       527467 :     if (this->CoolingCoilPresent) {
   12928              :         // above condition for heat pump mode, below condition for heat recovery mode
   12929       881691 :         if ((!state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed && state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) ||
   12930       354224 :             (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed &&
   12931       180454 :              state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList))) {
   12932       572162 :             SimDXCoil(state,
   12933              :                       "",
   12934              :                       HVAC::CompressorOp::On,
   12935              :                       FirstHVACIteration,
   12936       286081 :                       this->CoolCoilIndex,
   12937              :                       fanOp,
   12938              :                       PartLoadRatio,
   12939              :                       _,
   12940              :                       _,
   12941       286081 :                       state.dataHVACVarRefFlow->MaxCoolingCapacity(VRFCond),
   12942       286081 :                       state.dataHVACVarRefFlow->VRF(this->VRFSysNum).VRFCondCyclingRatio);
   12943              :         } else { // cooling coil is off
   12944       241386 :             SimDXCoil(state, "", HVAC::CompressorOp::Off, FirstHVACIteration, this->CoolCoilIndex, fanOp, 0.0, _);
   12945              :         }
   12946       527467 :         state.dataHVACVarRefFlow->LoopDXCoolCoilRTF = state.dataAirLoop->LoopDXCoilRTF;
   12947              :     } else {
   12948            0 :         state.dataHVACVarRefFlow->LoopDXCoolCoilRTF = 0.0;
   12949              :     }
   12950              : 
   12951       527467 :     if (this->HeatingCoilPresent) {
   12952              :         // above condition for heat pump mode, below condition for heat recovery mode
   12953       925491 :         if ((!state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed && state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) ||
   12954       398024 :             (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed &&
   12955       180454 :              state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList))) {
   12956       580134 :             SimDXCoil(state,
   12957              :                       "",
   12958              :                       HVAC::CompressorOp::On,
   12959              :                       FirstHVACIteration,
   12960       193378 :                       this->HeatCoilIndex,
   12961              :                       fanOp,
   12962              :                       PartLoadRatio,
   12963              :                       _,
   12964              :                       _,
   12965       193378 :                       state.dataHVACVarRefFlow->MaxHeatingCapacity(VRFCond));
   12966              :         } else {
   12967       334089 :             SimDXCoil(state, "", HVAC::CompressorOp::Off, FirstHVACIteration, this->HeatCoilIndex, fanOp, 0.0, _);
   12968              :         }
   12969       527467 :         state.dataHVACVarRefFlow->LoopDXHeatCoilRTF = state.dataAirLoop->LoopDXCoilRTF;
   12970              :     } else {
   12971            0 :         state.dataHVACVarRefFlow->LoopDXHeatCoilRTF = 0.0;
   12972              :     }
   12973              : 
   12974       527467 :     Real64 OnOffFanPartLoadFraction = 1.0;
   12975       527467 :     if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOp == HVAC::FanOp::Cycling) {
   12976        28608 :         OnOffFanPartLoadFraction = state.dataHVACGlobal->OnOffFanPartLoadFraction;
   12977              :     }
   12978              :     // if draw through, simulate coils then fan
   12979       527467 :     if (this->fanPlace == HVAC::FanPlace::DrawThru) {
   12980       527467 :         auto *fan = state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex);
   12981       527467 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanType == HVAC::FanType::SystemModel) {
   12982       527467 :             if (OnOffAirFlowRatio > 0.0) {
   12983       520110 :                 fan->simulate(state, FirstHVACIteration, _, _, _, fan->inletAirMassFlowRate, OnOffFanPartLoadFraction, 0, 0, _);
   12984              :             } else {
   12985         7357 :                 fan->simulate(state, FirstHVACIteration, _, _, PartLoadRatio);
   12986              :             }
   12987              :         } else {
   12988            0 :             fan->simulate(state, FirstHVACIteration, state.dataHVACVarRefFlow->FanSpeedRatio);
   12989              :         }
   12990              :     }
   12991              : 
   12992              :     // track fan power per terminal unit for calculating COP
   12993       527467 :     this->FanPower = state.dataFans->fans(this->FanIndex)->totalPower;
   12994              : 
   12995              :     // run supplemental heating coil
   12996       527467 :     if (this->SuppHeatingCoilPresent) {
   12997       187252 :         Real64 SuppPLR = this->SuppHeatPartLoadRatio;
   12998       187252 :         this->CalcVRFSuppHeatingCoil(state, VRFTUNum, FirstHVACIteration, SuppPLR, SuppHeatCoilLoad);
   12999       187252 :         if ((state.dataLoopNodes->Node(this->SuppHeatCoilAirOutletNode).Temp > this->MaxSATFromSuppHeatCoil) && SuppPLR > 0.0) {
   13000              :             // adjust the heating load to maximum allowed
   13001            0 :             Real64 MaxHeatCoilLoad = this->HeatingCoilCapacityLimit(state, this->SuppHeatCoilAirInletNode, this->MaxSATFromSuppHeatCoil);
   13002            0 :             this->CalcVRFSuppHeatingCoil(state, VRFTUNum, FirstHVACIteration, SuppPLR, MaxHeatCoilLoad);
   13003            0 :             SuppHeatCoilLoad = MaxHeatCoilLoad;
   13004              :         }
   13005              :     }
   13006              : 
   13007       527467 :     Real64 LatentLoadMet = 0.0;
   13008       527467 :     Real64 TempOut = 0.0;
   13009       527467 :     Real64 TempIn = 0.0;
   13010       527467 :     if (this->ATMixerExists) {
   13011            0 :         if (this->ATMixerType == HVAC::MixerType::SupplySide) {
   13012              :             // Air terminal supply side mixer, calculate supply side mixer output
   13013            0 :             SimATMixer(state, this->ATMixerName, FirstHVACIteration, this->ATMixerIndex);
   13014            0 :             TempOut = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->ATMixOutNode2).Temp;
   13015            0 :             SpecHumOut = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->ATMixOutNode2).HumRat;
   13016            0 :             AirMassFlow = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->ATMixOutNode2).MassFlowRate;
   13017              :         } else {
   13018              :             // Air terminal inlet side mixer
   13019            0 :             TempOut = state.dataLoopNodes->Node(VRFTUOutletNodeNum).Temp;
   13020            0 :             SpecHumOut = state.dataLoopNodes->Node(VRFTUOutletNodeNum).HumRat;
   13021              :         }
   13022            0 :         TempIn = state.dataLoopNodes->Node(ZoneNode).Temp;
   13023            0 :         SpecHumIn = state.dataLoopNodes->Node(ZoneNode).HumRat;
   13024              :     } else {
   13025       527467 :         TempOut = state.dataLoopNodes->Node(VRFTUOutletNodeNum).Temp;
   13026       527467 :         SpecHumOut = state.dataLoopNodes->Node(VRFTUOutletNodeNum).HumRat;
   13027       527467 :         if (ZoneNode > 0) {
   13028       527467 :             TempIn = state.dataLoopNodes->Node(ZoneNode).Temp;
   13029       527467 :             SpecHumIn = state.dataLoopNodes->Node(ZoneNode).HumRat;
   13030              :         } else {
   13031            0 :             TempIn = state.dataLoopNodes->Node(VRFTUInletNodeNum).Temp;
   13032            0 :             SpecHumIn = state.dataLoopNodes->Node(VRFTUInletNodeNum).HumRat;
   13033              :         }
   13034              :     }
   13035              :     // calculate sensible load met using delta enthalpy
   13036       527467 :     Real64 TotalOutput = AirMassFlow * (Psychrometrics::PsyHFnTdbW(TempOut, SpecHumOut) -
   13037       527467 :                                         Psychrometrics::PsyHFnTdbW(TempIn, SpecHumIn));         // total addition/removal rate, {W};
   13038       527467 :     LoadMet = AirMassFlow * PsyDeltaHSenFnTdb2W2Tdb1W1(TempOut, SpecHumOut, TempIn, SpecHumIn); // sensible {W}
   13039       527467 :     LatentLoadMet = TotalOutput - LoadMet;
   13040       527467 :     if (present(LatOutputProvided)) {
   13041        56371 :         LatOutputProvided = LatentLoadMet;
   13042              :     }
   13043       527467 : }
   13044              : 
   13045       315093 : Real64 VRFTerminalUnitEquipment::CalVRFTUAirFlowRate_FluidTCtrl(EnergyPlusData &state,
   13046              :                                                                 int const VRFTUNum,                          // Index to VRF terminal unit
   13047              :                                                                 Real64 PartLoadRatio,                        // part load ratio of the coil
   13048              :                                                                 [[maybe_unused]] bool FirstHVACIteration,    // FirstHVACIteration flag
   13049              :                                                                 ObjexxFCL::Optional<Real64 const> MaxHeatCap // maximum allowed heating capacity
   13050              : )
   13051              : {
   13052              :     // SUBROUTINE INFORMATION:
   13053              :     //       AUTHOR         Rongpeng Zhang, LBNL
   13054              :     //       DATE WRITTEN   Nov 2015
   13055              :     //       MODIFIED       na
   13056              :     //       RE-ENGINEERED  na
   13057              : 
   13058              :     // PURPOSE OF THIS FUNCTION:
   13059              :     //  This function determines the TU airflow rate corresponding to the coil load.
   13060              :     //  This is used to address the coupling between OA mixer simulation and VRF-FluidTCtrl coil simulation.
   13061              : 
   13062              :     // METHODOLOGY EMPLOYED:
   13063              :     //  VRF-FluidTCtrl TU airflow rate is determined by the control logic of VRF-FluidTCtrl coil to match the
   13064              :     //  coil load. This is affected by the coil inlet conditions. However, the airflow rate will affect the
   13065              :     //  OA mixer simulation, which leads to different coil inlet conditions. So, there is a coupling issue here.
   13066              : 
   13067              :     using General::SolveRoot;
   13068              : 
   13069              :     Real64 AirMassFlowRate; // air mass flow rate of the coil (kg/s)
   13070              : 
   13071       315093 :     int constexpr Mode(1);           // Performance mode for MultiMode DX coil. Always 1 for other coil types
   13072       315093 :     int constexpr MaxIte(500);       // maximum number of iterations
   13073              :     int DXCoilNum;                   // index to DX Coil
   13074              :     int IndexToTUInTUList;           // index to TU in specific list for the VRF system
   13075              :     int SolFla;                      // Flag of RegulaFalsi solver
   13076              :     int TUListIndex;                 // index to TU list for this VRF system
   13077              :     int VRFCond;                     // index to VRF condenser
   13078       315093 :     Real64 constexpr ErrorTol(0.01); // tolerance for RegulaFalsi iterations
   13079              :     Real64 FanSpdRatio;              // ratio of required and rated air flow rate
   13080              :     Real64 FanSpdRatioMin;           // min fan speed ratio
   13081              :     Real64 FanSpdRatioMax;           // min fan speed ratio
   13082              :     Real64 QCoilReq;                 // required coil load (W)
   13083              :     Real64 QCoilAct;                 // actual coil load (W)
   13084              :     Real64 TeTc;                     // evaporating temperature or condensing temperature for VRF indoor unit(C)
   13085              : 
   13086       315093 :     VRFCond = this->VRFSysNum;
   13087       315093 :     TUListIndex = state.dataHVACVarRefFlow->VRF(VRFCond).ZoneTUListPtr;
   13088       315093 :     IndexToTUInTUList = this->IndexToTUInTUList;
   13089              : 
   13090       513869 :     if ((!state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed && state.dataHVACVarRefFlow->CoolingLoad(VRFCond)) ||
   13091       198776 :         (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed &&
   13092       109119 :          state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRCoolRequest(IndexToTUInTUList))) {
   13093              :         // VRF terminal unit is on cooling mode
   13094       186607 :         DXCoilNum = this->CoolCoilIndex;
   13095       186607 :         QCoilReq = -PartLoadRatio * state.dataDXCoils->DXCoil(DXCoilNum).RatedTotCap(Mode);
   13096       186607 :         TeTc = state.dataHVACVarRefFlow->VRF(VRFCond).IUEvaporatingTemp;
   13097              : 
   13098              :         // For HR operations, Te is lower than the outdoor air temperature because of outdoor evaporator operations
   13099              :         // The difference is usually 2-3C according to the engineering experience. 2 is used here for a slightly bigger fan flow rate.
   13100       186607 :         if (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed) {
   13101        70290 :             TeTc = min(TeTc, state.dataEnvrn->OutDryBulbTemp - 2);
   13102              :         }
   13103              : 
   13104       169929 :     } else if ((!state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed && state.dataHVACVarRefFlow->HeatingLoad(VRFCond)) ||
   13105        41443 :                (state.dataHVACVarRefFlow->VRF(VRFCond).HeatRecoveryUsed &&
   13106        38829 :                 state.dataHVACVarRefFlow->TerminalUnitList(TUListIndex).HRHeatRequest(IndexToTUInTUList))) {
   13107              :         // VRF terminal unit is on heating mode
   13108       125579 :         DXCoilNum = this->HeatCoilIndex;
   13109       125579 :         Real64 RatedCapacity = state.dataDXCoils->DXCoil(DXCoilNum).RatedTotCap(Mode);
   13110       125579 :         if (present(MaxHeatCap)) {
   13111        62836 :             RatedCapacity = min(MaxHeatCap, RatedCapacity);
   13112              :         }
   13113       125579 :         QCoilReq = PartLoadRatio * RatedCapacity;
   13114       125579 :         TeTc = state.dataHVACVarRefFlow->VRF(VRFCond).IUCondensingTemp;
   13115              : 
   13116              :     } else {
   13117              :         // VRF terminal unit is off
   13118         2907 :         QCoilAct = 0.0;
   13119         2907 :         AirMassFlowRate = max(state.dataHVACVarRefFlow->OACompOnMassFlow, 0.0);
   13120         2907 :         return AirMassFlowRate;
   13121              :     }
   13122              : 
   13123              :     // minimum airflow rate
   13124       312186 :     if (state.dataDXCoils->DXCoil(DXCoilNum).RatedAirMassFlowRate(Mode) > 0.0) {
   13125       312186 :         FanSpdRatioMin = min(state.dataHVACVarRefFlow->OACompOnMassFlow / state.dataDXCoils->DXCoil(DXCoilNum).RatedAirMassFlowRate(Mode), 1.0);
   13126              :     } else {
   13127              :         // VRF terminal unit is off
   13128            0 :         QCoilAct = 0.0;
   13129            0 :         AirMassFlowRate = max(state.dataHVACVarRefFlow->OACompOnMassFlow, 0.0);
   13130            0 :         return AirMassFlowRate;
   13131              :     }
   13132              : 
   13133       312186 :     FanSpdRatioMax = 1.0;
   13134              : 
   13135      1085001 :     auto f = [&state, VRFTUNum, DXCoilNum, QCoilReq, TeTc, PartLoadRatio](Real64 const FanSpdRatio) {
   13136              :         using DXCoils::ControlVRFIUCoil;
   13137              :         using Psychrometrics::PsyHFnTdbW;
   13138              :         using SingleDuct::SimATMixer;
   13139              : 
   13140      1085001 :         int constexpr Mode(1);  // Performance mode for MultiMode DX coil. Always 1 for other coil types
   13141              :         int VRFCond;            // index to VRF condenser
   13142              :         int VRFInletNode;       // VRF inlet node number
   13143              :         Real64 FanSpdRatioBase; // baseline FanSpdRatio for VRFTUAirFlowResidual
   13144              :         Real64 FanSpdRatioAct;  // calculated FanSpdRatio for VRFTUAirFlowResidual
   13145              :         Real64 QCoilAct;        // actual coil load [W]
   13146              :         Real64 temp;            // for temporary use
   13147              :         Real64 Tin;             // coil inlet air temperature [C]
   13148              :         Real64 Win;             // coil inlet air humidity ratio [kg/kg]
   13149              :         Real64 Hin;             // coil inlet air enthalpy
   13150              :         Real64 Wout;            // coil outlet air humidity ratio
   13151              :         Real64 Tout;            // coil outlet air temperature
   13152              :         Real64 Hout;            // coil outlet air enthalpy
   13153              :         Real64 SHact;           // coil actual SH
   13154              :         Real64 SCact;           // coil actual SC
   13155              : 
   13156      1085001 :         VRFCond = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFSysNum;
   13157      1085001 :         VRFInletNode = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).VRFTUInletNodeNum;
   13158              : 
   13159      1085001 :         if (std::abs(FanSpdRatio) < 0.01) {
   13160            0 :             FanSpdRatioBase = sign(0.01, FanSpdRatio);
   13161              :         } else {
   13162      1085001 :             FanSpdRatioBase = FanSpdRatio;
   13163              :         }
   13164              : 
   13165              :         // Set inlet air mass flow rate based on PLR and compressor on/off air flow rates
   13166      1085001 :         state.dataHVACVarRefFlow->CompOnMassFlow = FanSpdRatio * state.dataDXCoils->DXCoil(DXCoilNum).RatedAirMassFlowRate(Mode);
   13167      1085001 :         SetAverageAirFlow(state, VRFTUNum, PartLoadRatio, temp);
   13168      1085001 :         Tin = state.dataLoopNodes->Node(VRFInletNode).Temp;
   13169      1085001 :         Win = state.dataLoopNodes->Node(VRFInletNode).HumRat;
   13170              : 
   13171              :         // Simulation the OAMixer if there is any
   13172      1085001 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerUsed) {
   13173      1085001 :             MixedAir::SimOAMixer(
   13174      1085001 :                 state, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerName, state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerIndex);
   13175      1085001 :             int OAMixNode = state.dataMixedAir->OAMixer(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).OAMixerIndex).MixNode;
   13176      1085001 :             Tin = state.dataLoopNodes->Node(OAMixNode).Temp;
   13177      1085001 :             Win = state.dataLoopNodes->Node(OAMixNode).HumRat;
   13178              :         }
   13179              :         // Simulate the blow-through fan if there is any
   13180      1085001 :         if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanPlace == HVAC::FanPlace::BlowThru) {
   13181            0 :             auto *fan = state.dataFans->fans(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).FanIndex);
   13182            0 :             if (state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanType == HVAC::FanType::SystemModel) {
   13183            0 :                 if (temp > 0) {
   13184            0 :                     fan->simulate(state, false, _, _);
   13185              :                 } else {
   13186            0 :                     fan->simulate(state, false, _, _, PartLoadRatio);
   13187              :                 }
   13188              :             } else {
   13189            0 :                 fan->simulate(state, false, state.dataHVACVarRefFlow->FanSpeedRatio);
   13190              :             }
   13191            0 :             Tin = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOutletNode).Temp;
   13192            0 :             Win = state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOutletNode).HumRat;
   13193              :         }
   13194              : 
   13195              :         // Call the coil control logic to determine the air flow rate to match the given coil load
   13196      1085001 :         ControlVRFIUCoil(
   13197      1085001 :             state, DXCoilNum, QCoilReq, Tin, Win, TeTc, state.dataHVACVarRefFlow->OACompOnMassFlow, FanSpdRatioAct, Wout, Tout, Hout, SHact, SCact);
   13198              : 
   13199      1085001 :         Hin = PsyHFnTdbW(Tin, Win);
   13200      1085001 :         QCoilAct = FanSpdRatioAct * state.dataDXCoils->DXCoil(DXCoilNum).RatedAirMassFlowRate(Mode) *
   13201      1085001 :                    (Hout - Hin); // positive for heating, negative for cooling
   13202              : 
   13203      1085001 :         return (FanSpdRatioAct - FanSpdRatio);
   13204       312186 :     };
   13205              : 
   13206       312186 :     SolveRoot(state, ErrorTol, MaxIte, SolFla, FanSpdRatio, f, FanSpdRatioMin, FanSpdRatioMax);
   13207       312186 :     if (SolFla < 0) {
   13208            0 :         FanSpdRatio = FanSpdRatioMax; // over capacity
   13209              :     }
   13210              : 
   13211       312186 :     AirMassFlowRate = FanSpdRatio * state.dataDXCoils->DXCoil(DXCoilNum).RatedAirMassFlowRate(Mode);
   13212              : 
   13213       312186 :     return AirMassFlowRate;
   13214              : }
   13215              : 
   13216      1814512 : Real64 CompResidual_FluidTCtrl(EnergyPlusData &state,
   13217              :                                Real64 T_dis,
   13218              :                                Real64 CondHeat,
   13219              :                                int CAPFT,
   13220              :                                Real64 const T_suc // Compressor suction temperature Te' [C]
   13221              : )
   13222              : {
   13223              :     // FUNCTION INFORMATION:
   13224              :     //       AUTHOR         Xiufeng Pang (XP)
   13225              :     //       DATE WRITTEN   Mar 2013
   13226              :     //       MODIFIED       Jul 2015, RP Zhang, LBNL
   13227              :     //       RE-ENGINEERED
   13228              :     //
   13229              :     // PURPOSE OF THIS FUNCTION:
   13230              :     //       Calculates residual function ((VRV terminal unit cooling output - Zone sensible cooling load)
   13231              :     //
   13232              :     using Curve::CurveValue;
   13233              : 
   13234              :     Real64 CAPSpd; // Evaporative capacity of the compressor at a given spd[W]
   13235              :     Real64 CompResidual;
   13236              : 
   13237      1814512 :     CAPSpd = CurveValue(state, CAPFT, T_dis, T_suc);
   13238      1814512 :     CompResidual = (CondHeat - CAPSpd) / CAPSpd;
   13239              : 
   13240      1814512 :     return CompResidual;
   13241              : }
   13242              : 
   13243       311718 : void VRFCondenserEquipment::VRFOU_TeTc(EnergyPlusData &state,
   13244              :                                        HXOpMode const OperationMode, // Mode 0 for running as condenser, 1 for evaporator
   13245              :                                        Real64 const Q_coil,          // // OU coil heat release at cooling mode or heat extract at heating mode [W]
   13246              :                                        Real64 const SHSC,            // SC for OU condenser or SH for OU evaporator [C]
   13247              :                                        Real64 const m_air,           // OU coil air mass flow rate [kg/s]
   13248              :                                        Real64 const T_coil_in,       // Temperature of air at OU coil inlet [C]
   13249              :                                        Real64 const W_coil_in,       // Humidity ratio of air at OU coil inlet [kg/kg]
   13250              :                                        Real64 const OutdoorPressure, // Outdoor air pressure [Pa]
   13251              :                                        Real64 &T_coil_surf,          // Air temperature at coil surface [C]
   13252              :                                        Real64 &TeTc                  // VRF Tc at cooling mode, or Te at heating mode [C]
   13253              : )
   13254              : {
   13255              : 
   13256              :     // SUBROUTINE INFORMATION:
   13257              :     //       AUTHOR         Rongpeng Zhang, LBNL
   13258              :     //       DATE WRITTEN   Jan 2016
   13259              :     //       MODIFIED       na
   13260              :     //
   13261              :     //       RE-ENGINEERED  na
   13262              :     //
   13263              :     // PURPOSE OF THIS SUBROUTINE:
   13264              :     //        Calculate the VRF OU refrigerant side temperature, i.e., condensing temperature
   13265              :     //        at cooling mode, or evaporating temperature at heating mode, given the coil heat
   13266              :     //        release/extract amount and air side parameters.
   13267              :     //
   13268              :     // METHODOLOGY EMPLOYED:
   13269              :     //        This is part of the physics based VRF model applicable for Fluid Temperature Control.
   13270              :     //
   13271              : 
   13272              :     Real64 BF;              // VRF OU bypass  [-]
   13273              :     Real64 deltaT;          // Difference between Te/Tc and air temperature at coil surface [C]
   13274              :     Real64 h_coil_in;       // Enthalpy of air at OU coil inlet [C]
   13275              :     Real64 h_coil_out;      // Enthalpy of air at OU coil outlet [C]
   13276              :     Real64 T_coil_out;      // Air temperature at coil outlet [C]
   13277              :     Real64 T_coil_surf_sat; // Saturated air temperature at coil surface [C]
   13278              :     Real64 W_coil_surf_sat; // Humidity ratio of saturated air at coil surface [kg/kg]
   13279              : 
   13280       311718 :     if (OperationMode == HXOpMode::CondMode) {
   13281              :         // IU Cooling: OperationMode 0
   13282              : 
   13283       282711 :         if (m_air <= 0) {
   13284            0 :             TeTc = this->CondensingTemp;
   13285            0 :             ShowSevereMessage(state, format(" Unreasonable outdoor unit airflow rate ({:.3T} ) for \"{}\":", m_air, this->Name));
   13286            0 :             ShowContinueError(state, " This cannot be used to calculate outdoor unit refrigerant temperature.");
   13287            0 :             ShowContinueError(state, format(" Default condensing temperature is used: {:.3T}", TeTc));
   13288              :         }
   13289              : 
   13290       282711 :         BF = this->RateBFOUCond; // 0.219;
   13291       282711 :         T_coil_out = T_coil_in + Q_coil / 1005.0 / m_air;
   13292       282711 :         T_coil_surf = T_coil_in + (T_coil_out - T_coil_in) / (1 - BF);
   13293              : 
   13294       282711 :         deltaT = this->C3Tc * pow_2(SHSC) + this->C2Tc * SHSC + this->C1Tc;
   13295              : 
   13296       282711 :         TeTc = T_coil_surf + deltaT;
   13297              : 
   13298        29007 :     } else if (OperationMode == HXOpMode::EvapMode) {
   13299              :         // IU Heating: OperationMode 1
   13300              : 
   13301        29007 :         if (m_air <= 0) {
   13302            0 :             TeTc = this->EvaporatingTemp;
   13303            0 :             ShowSevereMessage(state, format(" Unreasonable outdoor unit airflow rate ({:.3T} ) for \"{}\":", m_air, this->Name));
   13304            0 :             ShowContinueError(state, " This cannot be used to calculate outdoor unit refrigerant temperature.");
   13305            0 :             ShowContinueError(state, format(" Default condensing temperature is used: {:.3T}", TeTc));
   13306              :         }
   13307              : 
   13308        29007 :         BF = this->RateBFOUEvap; // 0.45581;
   13309        29007 :         h_coil_in = PsyHFnTdbW(T_coil_in, W_coil_in);
   13310        29007 :         h_coil_out = h_coil_in - Q_coil / m_air / (1 - BF);
   13311        29007 :         h_coil_out = max(0.01, h_coil_out);
   13312              : 
   13313        29007 :         T_coil_surf_sat = PsyTsatFnHPb(state, h_coil_out, OutdoorPressure, "VRFOU_TeTc");
   13314        29007 :         W_coil_surf_sat = PsyWFnTdbH(state, T_coil_surf_sat, h_coil_out, "VRFOU_TeTc");
   13315              : 
   13316        29007 :         if (W_coil_surf_sat < W_coil_in) {
   13317              :             // There is dehumidification
   13318        16771 :             T_coil_surf = T_coil_surf_sat;
   13319              :         } else {
   13320              :             // No dehumidification
   13321        12236 :             T_coil_surf = PsyTdbFnHW(h_coil_out, W_coil_in);
   13322              :         }
   13323              : 
   13324        29007 :         deltaT = this->C3Te * pow_2(SHSC) + this->C2Te * SHSC + this->C1Te;
   13325              : 
   13326        29007 :         TeTc = T_coil_surf - deltaT;
   13327              :     }
   13328       311718 : }
   13329              : 
   13330            0 : Real64 VRFCondenserEquipment::VRFOU_Cap(EnergyPlusData &state,
   13331              :                                         HXOpMode const OperationMode, // Mode 0 for running as condenser, 1 for evaporator
   13332              :                                         Real64 const TeTc,            // VRF Tc at cooling mode, or Te at heating mode [C]
   13333              :                                         Real64 const SHSC,            // SC for OU condenser or SH for OU evaporator [C]
   13334              :                                         Real64 const m_air,           // OU coil air mass flow rate [kg/s]
   13335              :                                         Real64 const T_coil_in,       // Temperature of air at OU coil inlet [C]
   13336              :                                         Real64 const W_coil_in        // Humidity ratio of air at OU coil inlet [kg/kg]
   13337              : )
   13338              : {
   13339              : 
   13340              :     // SUBROUTINE INFORMATION:
   13341              :     //       AUTHOR         Rongpeng Zhang, LBNL
   13342              :     //       DATE WRITTEN   Jan 2016
   13343              :     //       MODIFIED       na
   13344              :     //
   13345              :     //       RE-ENGINEERED  na
   13346              :     //
   13347              :     // PURPOSE OF THIS SUBROUTINE:
   13348              :     //        Calculate the VRF OU load, given refrigerant side temperature, i.e., condensing temperature
   13349              :     //        and SC for condenser, or evaporating temperature and SH for evaporator.
   13350              :     //
   13351              :     // METHODOLOGY EMPLOYED:
   13352              :     //        This is part of the physics based VRF model applicable for Fluid Temperature Control.
   13353              : 
   13354              :     Real64 BF;              // VRF OU bypass [-]
   13355              :     Real64 deltaT;          // Difference between Te/Tc and air temperature at coil surface [C]
   13356              :     Real64 h_coil_in;       // Enthalpy of air at OU coil inlet [C]
   13357              :     Real64 h_coil_out;      // Enthalpy of air at OU coil outlet [C]
   13358              :     Real64 Q_coil;          // OU coil heat release at cooling mode or heat extract at heating mode [W]
   13359              :     Real64 T_coil_out;      // Air temperature at coil outlet [C]
   13360              :     Real64 T_coil_surf;     // Air temperature at coil surface [C]
   13361              :     Real64 W_coil_surf_sat; // Humidity ratio of saturated air at coil surface [kg/kg]
   13362              : 
   13363            0 :     Q_coil = 0.0;
   13364              : 
   13365            0 :     if (OperationMode == HXOpMode::CondMode) {
   13366              :         // IU Cooling: OperationMode 0
   13367            0 :         if (m_air <= 0) {
   13368            0 :             ShowSevereMessage(state, format(" Unreasonable outdoor unit airflow rate ({:.3T} ) for \"{}\":", m_air, this->Name));
   13369            0 :             ShowContinueError(state, " This cannot be used to calculate outdoor unit capacity.");
   13370              :         }
   13371              : 
   13372            0 :         BF = this->RateBFOUCond; // 0.219;
   13373            0 :         deltaT = this->C3Tc * pow_2(SHSC) + this->C2Tc * SHSC + this->C1Tc;
   13374            0 :         T_coil_surf = TeTc - deltaT;
   13375            0 :         T_coil_out = T_coil_in + (T_coil_surf - T_coil_in) * (1 - BF);
   13376            0 :         Q_coil = (T_coil_out - T_coil_in) * 1005.0 * m_air;
   13377              : 
   13378            0 :     } else if (OperationMode == HXOpMode::EvapMode) {
   13379              :         // IU Heating: OperationMode 1
   13380            0 :         if (m_air <= 0) {
   13381            0 :             ShowSevereMessage(state, format(" Unreasonable outdoor unit airflow rate ({:.3T} ) for \"{}\":", m_air, this->Name));
   13382            0 :             ShowContinueError(state, " This cannot be used to calculate outdoor unit capacity.");
   13383              :         }
   13384              : 
   13385            0 :         BF = this->RateBFOUEvap; // 0.45581;
   13386            0 :         deltaT = this->C3Te * pow_2(SHSC) + this->C2Te * SHSC + this->C1Te;
   13387            0 :         T_coil_surf = TeTc + deltaT;
   13388              : 
   13389              :         // saturated humidity ratio corresponding to T_coil_surf
   13390            0 :         W_coil_surf_sat = PsyWFnTdpPb(state, T_coil_surf, state.dataEnvrn->OutBaroPress);
   13391              : 
   13392            0 :         if (W_coil_surf_sat < W_coil_in) {
   13393              :             // There is dehumidification, W_coil_out = W_coil_surf_sat
   13394            0 :             h_coil_out = PsyHFnTdbW(T_coil_surf, W_coil_surf_sat);
   13395              :         } else {
   13396              :             // No dehumidification, W_coil_out = W_coil_in
   13397            0 :             h_coil_out = PsyHFnTdbW(T_coil_surf, W_coil_in);
   13398              :         }
   13399            0 :         h_coil_out = max(0.01, h_coil_out);
   13400            0 :         h_coil_in = PsyHFnTdbW(T_coil_in, W_coil_in);
   13401            0 :         Q_coil = (h_coil_in - h_coil_out) * m_air * (1 - BF); // bypass airflow should not be included here
   13402              : 
   13403              :     } else {
   13404              :         // Should not come here
   13405            0 :         ShowSevereMessage(state, format(" Unreasonable outdoor unit operational mode for \"{}\":", this->Name));
   13406            0 :         ShowContinueError(state, " The operational mode is not correctly set in the function VRFOU_Cap.");
   13407              :     }
   13408              : 
   13409            0 :     return Q_coil;
   13410              : }
   13411              : 
   13412            0 : Real64 VRFCondenserEquipment::VRFOU_FlowRate(EnergyPlusData &state,
   13413              :                                              HXOpMode const OperationMode, // Mode 0 for running as condenser, 1 for evaporator
   13414              :                                              Real64 const TeTc,            // VRF Tc at cooling mode, or Te at heating mode [C]
   13415              :                                              Real64 const SHSC,            // SC for OU condenser or SH for OU evaporator [C]
   13416              :                                              Real64 const Q_coil,          // absolute value of OU coil heat release or heat extract [W]
   13417              :                                              Real64 const T_coil_in,       // Temperature of air at OU coil inlet [C]
   13418              :                                              Real64 const W_coil_in        // Humidity ratio of air at OU coil inlet [kg/kg]
   13419              : ) const
   13420              : {
   13421              : 
   13422              :     // SUBROUTINE INFORMATION:
   13423              :     //       AUTHOR         Rongpeng Zhang, LBNL
   13424              :     //       DATE WRITTEN   Mar 2016
   13425              :     //       MODIFIED       na
   13426              :     //
   13427              :     //       RE-ENGINEERED  na
   13428              :     //
   13429              :     // PURPOSE OF THIS SUBROUTINE:
   13430              :     //        Calculate the outdoor unit fan flow rate, given VRF OU load and refrigerant side temperature, i.e.,
   13431              :     //        condensing temperature and SC for condenser, or evaporating temperature and SH for evaporator.
   13432              :     //
   13433              :     // METHODOLOGY EMPLOYED:
   13434              :     //        This is part of the physics based VRF model applicable for Fluid Temperature Control.
   13435              : 
   13436              :     Real64 BF;              // VRF OU bypass [-]
   13437              :     Real64 deltaT;          // Difference between Te/Tc and air temperature at coil surface [C]
   13438              :     Real64 h_coil_in;       // Enthalpy of air at OU coil inlet [C]
   13439              :     Real64 h_coil_out;      // Enthalpy of air at OU coil outlet [C]
   13440              :     Real64 m_air;           // OU coil air mass flow rate [kg/s]
   13441              :     Real64 T_coil_out;      // Air temperature at coil outlet [C]
   13442              :     Real64 T_coil_surf;     // Air temperature at coil surface [C]
   13443              :     Real64 W_coil_surf_sat; // Humidity ratio of saturated air at coil surface [kg/kg]
   13444              : 
   13445            0 :     m_air = 0.0;
   13446              : 
   13447            0 :     if (OperationMode == HXOpMode::CondMode) {
   13448              :         // IU Cooling: OperationMode 0
   13449              : 
   13450            0 :         BF = this->RateBFOUCond; // 0.219;
   13451            0 :         deltaT = this->C3Tc * pow_2(SHSC) + this->C2Tc * SHSC + this->C1Tc;
   13452            0 :         T_coil_surf = TeTc - deltaT;
   13453            0 :         T_coil_out = T_coil_in + (T_coil_surf - T_coil_in) * (1 - BF);
   13454            0 :         m_air = Q_coil / (T_coil_out - T_coil_in) / 1005.0;
   13455              : 
   13456            0 :     } else if (OperationMode == HXOpMode::EvapMode) {
   13457              :         // IU Heating: OperationMode 1
   13458              : 
   13459            0 :         BF = this->RateBFOUEvap; // 0.45581;
   13460            0 :         deltaT = this->C3Te * pow_2(SHSC) + this->C2Te * SHSC + this->C1Te;
   13461            0 :         T_coil_surf = TeTc + deltaT;
   13462              : 
   13463              :         // saturated humidity ratio corresponding to T_coil_surf
   13464            0 :         W_coil_surf_sat = PsyWFnTdpPb(state, T_coil_surf, state.dataEnvrn->OutBaroPress);
   13465              : 
   13466            0 :         if (W_coil_surf_sat < W_coil_in) {
   13467              :             // There is dehumidification, W_coil_out = W_coil_surf_sat
   13468            0 :             h_coil_out = PsyHFnTdbW(T_coil_surf, W_coil_surf_sat);
   13469              :         } else {
   13470              :             // No dehumidification, W_coil_out = W_coil_in
   13471            0 :             h_coil_out = PsyHFnTdbW(T_coil_surf, W_coil_in);
   13472              :         }
   13473            0 :         h_coil_out = max(0.01, h_coil_out);
   13474            0 :         h_coil_in = PsyHFnTdbW(T_coil_in, W_coil_in);
   13475            0 :         m_air = Q_coil / (h_coil_in - h_coil_out) / (1 - BF);
   13476              : 
   13477              :     } else {
   13478              :         // Should not come here
   13479            0 :         ShowSevereMessage(state, format(" Unreasonable outdoor unit operational mode for \"{}\":", this->Name));
   13480            0 :         ShowContinueError(state, " The operational mode is not correctly set in the function VRFOU_Cap.");
   13481              :     }
   13482              : 
   13483            0 :     return m_air;
   13484              : }
   13485              : 
   13486            0 : Real64 VRFCondenserEquipment::VRFOU_SCSH(EnergyPlusData &state,
   13487              :                                          HXOpMode const OperationMode, // Mode 0 for running as condenser, 1 for evaporator
   13488              :                                          Real64 const Q_coil,          // // OU coil heat release at cooling mode or heat extract at heating mode [W]
   13489              :                                          Real64 const TeTc,            // VRF Tc at cooling mode, or Te at heating mode [C]
   13490              :                                          Real64 const m_air,           // OU coil air mass flow rate [kg/s]
   13491              :                                          Real64 const T_coil_in,       // Temperature of air at OU coil inlet [C]
   13492              :                                          Real64 const W_coil_in,       // Humidity ratio of air at OU coil inlet [kg/kg]
   13493              :                                          Real64 const OutdoorPressure  // Outdoor air pressure [Pa]
   13494              : ) const
   13495              : {
   13496              : 
   13497              :     // SUBROUTINE INFORMATION:
   13498              :     //       AUTHOR         Rongpeng Zhang, LBNL
   13499              :     //       DATE WRITTEN   Jan 2016
   13500              :     //       MODIFIED       na
   13501              :     //
   13502              :     //       RE-ENGINEERED  na
   13503              :     //
   13504              :     // PURPOSE OF THIS SUBROUTINE:
   13505              :     //        Calculate the SC for OU condenser, or SH for OU evaporator, given
   13506              :     //        VRF OU load and refrigerant side temperature, i.e., condensing temperature
   13507              :     //        for condenser, or evaporating temperature for evaporator.
   13508              :     //
   13509              :     // METHODOLOGY EMPLOYED:
   13510              :     //        This is part of the physics based VRF model applicable for Fluid Temperature Control.
   13511              : 
   13512              :     Real64 BF;              // VRF OU bypass [-]
   13513              :     Real64 deltaT;          // Difference between Te/Tc and air temperature at coil surface [C]
   13514              :     Real64 h_coil_in;       // Enthalpy of air at OU coil inlet [C]
   13515              :     Real64 h_coil_out;      // Enthalpy of air at OU coil outlet [C]
   13516              :     Real64 SHSC;            // SC for OU condenser, or SH for OU evaporator
   13517              :     Real64 T_coil_out;      // Air temperature at coil outlet [C]
   13518              :     Real64 T_coil_surf;     // Air temperature at coil surface [C]
   13519              :     Real64 T_coil_surf_sat; // Saturated air temperature at coil surface [C]
   13520              :     Real64 W_coil_surf_sat; // Humidity ratio of saturated air at coil surface [kg/kg]
   13521              : 
   13522            0 :     SHSC = 0.0;
   13523              : 
   13524            0 :     if (OperationMode == HXOpMode::CondMode) {
   13525              :         // Cooling: OperationMode 0
   13526            0 :         if (m_air <= 0) {
   13527            0 :             ShowSevereMessage(state, format(" Unreasonable outdoor unit airflow rate ({:.3T} ) for \"{}\":", m_air, this->Name));
   13528            0 :             ShowContinueError(state, " This cannot be used to calculate outdoor unit subcooling.");
   13529              :         }
   13530              : 
   13531            0 :         BF = this->RateBFOUCond; // 0.219;
   13532            0 :         T_coil_out = T_coil_in + Q_coil / 1005.0 / m_air;
   13533            0 :         T_coil_surf = T_coil_in + (T_coil_out - T_coil_in) / (1 - BF);
   13534            0 :         deltaT = TeTc - T_coil_surf;
   13535              : 
   13536              :         // SC_OU
   13537            0 :         if (this->C3Tc == 0) {
   13538            0 :             SHSC = -(this->C1Tc - deltaT) / this->C2Tc;
   13539              :         } else {
   13540            0 :             SHSC = (-this->C2Tc + std::pow((pow_2(this->C2Tc) - 4 * (this->C1Tc - deltaT) * this->C3Tc), 0.5)) / (2 * this->C3Tc);
   13541              :         }
   13542              : 
   13543            0 :     } else if (OperationMode == HXOpMode::EvapMode) {
   13544              :         // Heating: OperationMode 1
   13545            0 :         if (m_air <= 0) {
   13546            0 :             ShowSevereMessage(state, format(" Unreasonable outdoor unit airflow rate ({:.3T} ) for \"{}\":", m_air, this->Name));
   13547            0 :             ShowContinueError(state, " This cannot be used to calculate outdoor unit super heating.");
   13548              :         }
   13549              : 
   13550            0 :         BF = this->RateBFOUEvap; // 0.45581;
   13551            0 :         h_coil_in = PsyHFnTdbW(T_coil_in, W_coil_in);
   13552            0 :         h_coil_out = h_coil_in - Q_coil / m_air / (1 - BF);
   13553            0 :         h_coil_out = max(0.01, h_coil_out);
   13554              : 
   13555            0 :         T_coil_surf_sat = PsyTsatFnHPb(state, h_coil_out, OutdoorPressure, "VRFOU_TeTc");
   13556            0 :         W_coil_surf_sat = PsyWFnTdbH(state, T_coil_surf_sat, h_coil_out, "VRFOU_TeTc");
   13557              : 
   13558            0 :         if (W_coil_surf_sat < W_coil_in) {
   13559              :             // There is dehumidification
   13560            0 :             T_coil_surf = T_coil_surf_sat;
   13561              :         } else {
   13562              :             // No dehumidification
   13563            0 :             T_coil_surf = PsyTdbFnHW(h_coil_out, W_coil_in);
   13564              :         }
   13565              : 
   13566            0 :         deltaT = T_coil_surf - TeTc;
   13567              : 
   13568              :         // SH_OU
   13569            0 :         if (this->C3Te == 0) {
   13570            0 :             SHSC = -(this->C1Te - deltaT) / this->C2Te;
   13571              :         } else {
   13572            0 :             SHSC = (-this->C2Te + std::pow((pow_2(this->C2Te) - 4 * (this->C1Te - deltaT) * this->C3Te), 0.5)) / (2 * this->C3Te);
   13573              :         }
   13574              : 
   13575              :     } else {
   13576              :         // Should not come here
   13577            0 :         ShowSevereMessage(state, format(" Unreasonable outdoor unit operational mode for \"{}\":", this->Name));
   13578            0 :         ShowContinueError(state, " The operational mode is not correctly set in the function VRFOU_Cap.");
   13579              :     }
   13580              : 
   13581            0 :     return SHSC;
   13582              : }
   13583              : 
   13584       842955 : Real64 VRFCondenserEquipment::VRFOU_CapModFactor(
   13585              :     EnergyPlusData &state,
   13586              :     Real64 const h_comp_in_real, // Enthalpy of refrigerant at the compressor inlet at real conditions [kJ/kg]
   13587              :     Real64 const h_evap_in_real, // Enthalpy of refrigerant at the evaporator inlet at real conditions [kJ/kg]
   13588              :     Real64 const P_evap_real,    // Evaporative pressure at real conditions [Pa]
   13589              :     Real64 const T_comp_in_real, // Temperature of the refrigerant at the compressor inlet at real conditions [C]
   13590              :     Real64 const T_comp_in_rate, // Temperature of the refrigerant at the compressor inlet at rated conditions [C]
   13591              :     Real64 const T_cond_out_rate // Temperature of the refrigerant at the condenser outlet at rated conditions [C]
   13592              : )
   13593              : {
   13594              : 
   13595              :     // SUBROUTINE INFORMATION:
   13596              :     //       AUTHOR         Rongpeng Zhang
   13597              :     //       DATE WRITTEN   Nov 2015
   13598              :     //       MODIFIED       na
   13599              :     //       RE-ENGINEERED  na
   13600              : 
   13601              :     // PURPOSE OF THIS SUBROUTINE:
   13602              :     // Calculate capacity modification factor for the compressors at Outdoor Unit.
   13603              :     // This factor is used to modify the system evaporative capacity, by describing
   13604              :     // the difference between rated conditions and real conditions.
   13605              : 
   13606              :     // METHODOLOGY EMPLOYED:
   13607              :     // This is part of the VRF-FluidTCtrl Model.
   13608              : 
   13609              :     Real64 C_cap_density;   // Compressor capacity modification algorithm_modified flow rate [-]
   13610              :     Real64 C_cap_enthalpy;  // Compressor capacity modification algorithm_modified enthalpy difference [-]
   13611              :     Real64 C_cap_operation; // Compressor capacity modification algorithm_modified Cap [-]
   13612              :     Real64 RefTSat;         // Saturated temperature of the refrigerant. Used to check whether the refrigerant is in the superheat area [C].
   13613              :     Real64 h_evap_out_rate; // enthalpy of refrigerant at the evaporator outlet at rated conditions [kJ/kg]
   13614              :     Real64 h_evap_in_rate;  // enthalpy of refrigerant at the evaporator inlet at rated conditions [kJ/kg]
   13615              :     Real64 density_rate;    // density of refrigerant at rated conditions [kg/m3]
   13616              :     Real64 density_real;    // density of refrigerant at rated conditions [kg/m3]
   13617              : 
   13618              :     static constexpr std::string_view RoutineName("VRFOU_CapModFactor");
   13619              : 
   13620              :     // Saturated temperature at real evaporating pressure
   13621       842955 :     RefTSat = this->refrig->getSatTemperature(state, P_evap_real, RoutineName);
   13622              : 
   13623              :     // Enthalpy at rated conditions
   13624       842955 :     h_evap_out_rate = this->refrig->getSupHeatEnthalpy(state, max(RefTSat, T_comp_in_rate), P_evap_real, RoutineName);
   13625       842955 :     h_evap_in_rate = this->refrig->getSatEnthalpy(state, T_cond_out_rate, 0.0, RoutineName);
   13626              : 
   13627              :     // Density calculations
   13628       842955 :     density_rate = this->refrig->getSupHeatDensity(state, T_comp_in_rate, P_evap_real, RoutineName);
   13629       842955 :     density_real = this->refrig->getSupHeatDensity(state, T_comp_in_real, P_evap_real, RoutineName);
   13630              : 
   13631              :     // Modification factor calculations
   13632       842955 :     if (density_real > 0) {
   13633       842955 :         C_cap_density = density_rate / density_real;
   13634              :     } else {
   13635            0 :         C_cap_density = 1.0;
   13636              :     }
   13637              : 
   13638       842955 :     if ((h_comp_in_real - h_evap_in_real) > 0) {
   13639       842955 :         C_cap_enthalpy = std::abs(h_evap_out_rate - h_evap_in_rate) / std::abs(h_comp_in_real - h_evap_in_real);
   13640              :     } else {
   13641            0 :         C_cap_enthalpy = 1.0;
   13642              :     }
   13643              : 
   13644       842955 :     C_cap_operation = C_cap_density * C_cap_enthalpy;
   13645              : 
   13646       842955 :     return C_cap_operation;
   13647              : }
   13648              : 
   13649            0 : void VRFCondenserEquipment::VRFOU_TeModification(
   13650              :     EnergyPlusData &state,
   13651              :     Real64 const Te_up,          // Upper bound of Te during iteration, i.e., Te before reduction [C]
   13652              :     Real64 const Te_low,         // Lower bound of Te during iteration, i.e., the given suction temperature Te' [C]
   13653              :     Real64 const Pipe_h_IU_in,   // Piping Loss Algorithm Parameter: enthalpy of IU at inlet [kJ/kg]
   13654              :     Real64 const OutdoorDryBulb, // outdoor dry-bulb temperature [C]
   13655              :     Real64 &Te_update,           // Updated Te that can generate the required Tsuction [C]
   13656              :     Real64 &Pe_update,           // Piping Loss Algorithm Parameter: evaporating pressure assumed for iterations [Pa]
   13657              :     Real64 &Pipe_m_ref,          // Piping Loss Algorithm Parameter: Refrigerant mass flow rate [kg/s]
   13658              :     Real64 &Pipe_h_IU_out,       // Piping Loss Algorithm Parameter: enthalpy of IU at outlet [kJ/kg]
   13659              :     Real64 &Pipe_SH_merged       // Piping Loss Algorithm Parameter: Average SH after the indoor units [C]
   13660              : )
   13661              : {
   13662              : 
   13663              :     // SUBROUTINE INFORMATION:
   13664              :     //       AUTHOR         Rongpeng Zhang
   13665              :     //       DATE WRITTEN   Jan 2016
   13666              :     //       MODIFIED       na
   13667              :     //       RE-ENGINEERED  na
   13668              : 
   13669              :     // PURPOSE OF THIS SUBROUTINE:
   13670              :     // This is part of the low load modification algorithm for the VRF-FluidTCtrl model. It aims
   13671              :     // to find a new Te (Te_update) that can generate a new compressor suction temperature (Tsuction) equaling
   13672              :     // to the given compressor suction temperature (Te_low). This requires the re-calculate of piping loss.
   13673              : 
   13674              :     // METHODOLOGY EMPLOYED:
   13675              :     // This is part of the VRF-FluidTCtrl Model.
   13676              : 
   13677              :     int CoolCoilIndex;      // index to cooling coil in terminal unit
   13678              :     int NumTUInList;        // number of terminal units is list
   13679              :     int NumTeIte;           // counter for Te calculation iterations [-]
   13680              :     int TUListNum;          // index to TU List
   13681              :     int TUIndex;            // Index to terminal unit
   13682              :     Real64 MaxNumTeIte;     // Piping Loss Algorithm Parameter: max number of iterations for Te [-]
   13683              :     Real64 Pipe_h_comp_in;  // Piping Loss Algorithm Parameter: Enthalpy after piping loss (compressor inlet) [kJ/kg]
   13684              :     Real64 Pipe_DeltP;      // Piping Loss Algorithm Parameter: Pipe pressure drop [Pa]
   13685              :     Real64 Pipe_Q;          // Piping Loss Algorithm Parameter: Heat loss [W]
   13686              :     Real64 Pipe_m_ref_i;    // Piping Loss Algorithm Parameter: Refrigerant mass flow rate for a individual IU[kg/s]
   13687              :     Real64 Pipe_h_IU_out_i; // Piping Loss Algorithm Parameter: enthalpy of IU at outlet (individual) [kJ/kg]
   13688              :     Real64 RefTSat;         // Saturated temperature of the refrigerant [C]
   13689              :     Real64 RefPLow;         // Low Pressure Value for Ps (>0.0) [Pa]
   13690              :     Real64 RefPHigh;        // High Pressure Value for Ps (max in tables) [Pa]
   13691              :     Real64 SH_IU_update;    // Modified SH for VRF IU [C]
   13692              :     Real64 Te_ItePreci;     // Precision of iterations for Te [C]he superheat area [C]
   13693              :     Real64 Tfs;             // Temperature of the air at the coil surface [C]]
   13694              :     Real64 Tsuction;        // VRF compressor suction refrigerant temperature [Pa]
   13695              : 
   13696              :     static constexpr std::string_view RoutineName("VRFOU_TeModification");
   13697              : 
   13698              :     // variable initializations
   13699            0 :     TUListNum = this->ZoneTUListPtr;
   13700            0 :     RefPLow = this->refrig->PsLowPresValue;
   13701            0 :     RefPHigh = this->refrig->PsHighPresValue;
   13702            0 :     NumTUInList = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList;
   13703              : 
   13704              :     // Initialization of Te iterations (Label11)
   13705            0 :     NumTeIte = 1;
   13706            0 :     Te_ItePreci = 0.1;
   13707            0 :     MaxNumTeIte = (Te_up - Te_low) / Te_ItePreci + 1; // upper bound and lower bound of Te iterations
   13708            0 :     Te_update = Te_up - Te_ItePreci;
   13709              : 
   13710              :     bool converged_11;
   13711              :     // The following is triggered in VariableRefrigerantFlow_FluidTCtrl_HR_5Zone.idf
   13712              :     do {
   13713            0 :         Pipe_m_ref = 0; // Total Ref Flow Rate( kg/s )
   13714            0 :         Pipe_h_IU_out = 0;
   13715            0 :         Pipe_h_IU_out_i = 0;
   13716            0 :         Pipe_m_ref_i = 0;
   13717            0 :         Pipe_SH_merged = 0;
   13718            0 :         Pe_update = this->refrig->getSatPressure(state, Te_update, RoutineName);
   13719              : 
   13720              :         // Re-calculate total refrigerant flow rate, with updated SH
   13721            0 :         for (int NumTU = 1; NumTU <= NumTUInList; NumTU++) {
   13722            0 :             if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) > 0) {
   13723            0 :                 TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   13724            0 :                 CoolCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolCoilIndex;
   13725              : 
   13726              :                 // The IU coil surface temperature should be the same.
   13727            0 :                 Tfs = Te_up + (this->C3Te * pow_2(state.dataDXCoils->DXCoil(CoolCoilIndex).ActualSH) +
   13728            0 :                                this->C2Te * state.dataDXCoils->DXCoil(CoolCoilIndex).ActualSH + this->C1Te);
   13729              : 
   13730              :                 // SH_IU_update is the updated SH for a specific IU
   13731            0 :                 if (this->C3Te == 0) {
   13732            0 :                     SH_IU_update = -(this->C1Te - Tfs + Te_update) / this->C2Te;
   13733              :                 } else {
   13734            0 :                     SH_IU_update =
   13735            0 :                         (-this->C2Te + std::pow((pow_2(this->C2Te) - 4 * (this->C1Te - Tfs + Te_update) * this->C3Te), 0.5)) / (2 * this->C3Te);
   13736              :                 }
   13737              : 
   13738            0 :                 RefTSat = this->refrig->getSatTemperature(state, Pe_update, RoutineName);
   13739            0 :                 Pipe_h_IU_out_i = this->refrig->getSupHeatEnthalpy(state,
   13740            0 :                                                                    max(RefTSat, Te_update + SH_IU_update),
   13741              :                                                                    Pe_update,
   13742              :                                                                    RoutineName); // hB_i for the IU
   13743              : 
   13744            0 :                 if (Pipe_h_IU_out_i > Pipe_h_IU_in) {
   13745            0 :                     Pipe_m_ref_i =
   13746            0 :                         (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) <= 0.0)
   13747            0 :                             ? 0.0
   13748            0 :                             : (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) / (Pipe_h_IU_out_i - Pipe_h_IU_in));
   13749            0 :                     Pipe_m_ref = Pipe_m_ref + Pipe_m_ref_i;
   13750            0 :                     Pipe_SH_merged = Pipe_SH_merged + Pipe_m_ref_i * SH_IU_update;
   13751            0 :                     Pipe_h_IU_out = Pipe_h_IU_out + Pipe_m_ref_i * Pipe_h_IU_out_i;
   13752              :                 }
   13753              :             }
   13754              :         }
   13755            0 :         if (Pipe_m_ref > 0) {
   13756            0 :             Pipe_h_IU_out = Pipe_h_IU_out / Pipe_m_ref;
   13757            0 :             Pipe_SH_merged = Pipe_SH_merged / Pipe_m_ref;
   13758              :         } else {
   13759            0 :             Pipe_SH_merged = this->SH;
   13760            0 :             RefTSat = this->refrig->getSatTemperature(state, Pe_update, RoutineName);
   13761            0 :             Pipe_h_IU_out = this->refrig->getSupHeatEnthalpy(state, max(RefTSat, Te_update + Pipe_SH_merged), Pe_update, RoutineName);
   13762              :         }
   13763              : 
   13764              :         // Re-calculate piping loss
   13765            0 :         this->VRFOU_PipeLossC(state, Pipe_m_ref, Pe_update, Pipe_h_IU_out, Pipe_SH_merged, OutdoorDryBulb, Pipe_Q, Pipe_DeltP, Pipe_h_comp_in);
   13766              : 
   13767            0 :         Tsuction = this->refrig->getSatTemperature(state, max(min(Pe_update - Pipe_DeltP, RefPHigh), RefPLow), RoutineName);
   13768            0 :         converged_11 = !((std::abs(Tsuction - Te_low) > 0.5) && (Te_update < Te_up) && (Te_update > Te_low) && (NumTeIte < MaxNumTeIte));
   13769            0 :         Te_update = Te_update - 0.1;
   13770            0 :         NumTeIte = NumTeIte + 1;
   13771            0 :     } while (!converged_11);
   13772              : 
   13773            0 :     if (std::abs(Tsuction - Te_low) > 0.5) {
   13774            0 :         NumTeIte = 999;
   13775            0 :         Tsuction = Te_low;
   13776            0 :         Pipe_SH_merged = 3.0;
   13777            0 :         Te_update = Te_low + 1;
   13778              :     }
   13779            0 : }
   13780              : 
   13781            0 : void VRFCondenserEquipment::VRFOU_CompSpd(
   13782              :     EnergyPlusData &state,
   13783              :     Real64 const Q_req,        // Required capacity [W]
   13784              :     HXOpMode const Q_type,     // Required capacity type:  0 for condenser, 1 for evaporator
   13785              :     Real64 const T_suction,    // Compressor suction temperature Te' [C]
   13786              :     Real64 const T_discharge,  // Compressor discharge temperature Tc' [C]
   13787              :     Real64 const h_IU_evap_in, // Enthalpy of IU at inlet, for C_cap_operation calculation [kJ/kg]
   13788              :     Real64 const h_comp_in,    // Enthalpy after piping loss (compressor inlet), for C_cap_operation calculation [kJ/kg]
   13789              :     Real64 &CompSpdActual      // Actual compressor running speed [rps]
   13790              : )
   13791              : {
   13792              : 
   13793              :     // SUBROUTINE INFORMATION:
   13794              :     //       AUTHOR         Rongpeng Zhang, LBNL
   13795              :     //       DATE WRITTEN   Feb 2016
   13796              :     //       MODIFIED       na
   13797              :     //       RE-ENGINEERED  na
   13798              : 
   13799              :     // PURPOSE OF THIS SUBROUTINE:
   13800              :     //       This subroutine specifies the compressor speed at given operational conditions to meet the evaporator or condenser capacity provided.
   13801              : 
   13802              :     // METHODOLOGY EMPLOYED:
   13803              :     //        This is part of the VRF-FluidTCtrl Model.
   13804              : 
   13805              :     using Curve::CurveValue;
   13806              : 
   13807              :     // Locals
   13808              :     // SUBROUTINE ARGUMENT DEFINITIONS:
   13809              : 
   13810              :     // SUBROUTINE PARAMETER DEFINITIONS:
   13811              :     int CounterCompSpdTemp;                // Index for the compressor speed level[-]
   13812              :     int CompSpdLB;                         // index for Compressor speed low bound [-]
   13813              :     int CompSpdUB;                         // index for Compressor speed up bound [-]
   13814              :     int NumOfCompSpdInput;                 // Number of compressor speed input by the user [-]
   13815              :     Real64 C_cap_operation;                // Compressor capacity modification algorithm_modified Cap [-]
   13816              :     Real64 P_suction;                      // Compressor suction pressure Pe' [Pa]
   13817              :     Real64 Q_evap_req;                     // Required evaporative capacity [W]
   13818              :     Real64 Q_cond_req;                     // Required evaporative capacity [W]
   13819              :     Real64 RefPLow;                        // Low Pressure Value for Ps (>0.0) [Pa]
   13820              :     Real64 RefPHigh;                       // High Pressure Value for Ps (max in tables) [Pa]
   13821              :     Real64 SH_Comp;                        // Temperature between compressor inlet temperature and evaporative temperature Te' [C]
   13822              :     Real64 T_comp_in;                      // Refrigerant temperature at compressor inlet (after piping loss) [C]
   13823            0 :     Array1D<Real64> CompEvaporatingPWRSpd; // Array for the compressor power at certain speed [W]
   13824            0 :     Array1D<Real64> CompEvaporatingCAPSpd; // Array for the evaporating capacity at certain speed [W]
   13825              : 
   13826              :     static constexpr std::string_view RoutineName("VRFOU_CompSpd");
   13827              : 
   13828              :     // variable initializations: component index
   13829            0 :     RefPLow = this->refrig->PsLowPresValue;
   13830            0 :     RefPHigh = this->refrig->PsHighPresValue;
   13831              : 
   13832              :     // variable initializations: compressor
   13833            0 :     NumOfCompSpdInput = this->CompressorSpeed.size();
   13834            0 :     CompEvaporatingPWRSpd.dimension(NumOfCompSpdInput);
   13835            0 :     CompEvaporatingCAPSpd.dimension(NumOfCompSpdInput);
   13836              : 
   13837              :     // variable initializations: system operational parameters
   13838            0 :     P_suction = this->refrig->getSatPressure(state, T_suction, RoutineName);
   13839            0 :     T_comp_in = this->refrig->getSupHeatTemp(state, max(min(P_suction, RefPHigh), RefPLow), h_comp_in, T_suction + 3, T_suction + 30, RoutineName);
   13840            0 :     SH_Comp = T_comp_in - T_suction;
   13841              : 
   13842              :     // Calculate capacity modification factor
   13843            0 :     C_cap_operation = this->VRFOU_CapModFactor(
   13844              :         state, h_comp_in, h_IU_evap_in, max(min(P_suction, RefPHigh), RefPLow), T_suction + SH_Comp, T_suction + 8, T_discharge - 5);
   13845              : 
   13846            0 :     if (Q_type == HXOpMode::EvapMode) {
   13847              :         // Capacity to meet is for evaporator
   13848              : 
   13849            0 :         Q_evap_req = Q_req;
   13850              : 
   13851            0 :         for (CounterCompSpdTemp = 1; CounterCompSpdTemp <= NumOfCompSpdInput; CounterCompSpdTemp++) {
   13852              :             // Iteration to find the VRF speed that can meet the required load, Iteration DoName1
   13853              : 
   13854            0 :             CompEvaporatingPWRSpd(CounterCompSpdTemp) =
   13855            0 :                 this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(CounterCompSpdTemp), T_discharge, T_suction);
   13856            0 :             CompEvaporatingCAPSpd(CounterCompSpdTemp) =
   13857            0 :                 this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(CounterCompSpdTemp), T_discharge, T_suction);
   13858              : 
   13859            0 :             if (Q_evap_req * C_cap_operation <= CompEvaporatingCAPSpd(CounterCompSpdTemp)) {
   13860              :                 // Compressor speed stage CounterCompSpdTemp need not to be increased, finish Iteration DoName1
   13861              : 
   13862            0 :                 if (CounterCompSpdTemp > 1) {
   13863              : 
   13864            0 :                     CompSpdLB = CounterCompSpdTemp - 1;
   13865            0 :                     CompSpdUB = CounterCompSpdTemp;
   13866              : 
   13867            0 :                     CompSpdActual = this->CompressorSpeed(CompSpdLB) + (this->CompressorSpeed(CompSpdUB) - this->CompressorSpeed(CompSpdLB)) /
   13868            0 :                                                                            (CompEvaporatingCAPSpd(CompSpdUB) - CompEvaporatingCAPSpd(CompSpdLB)) *
   13869            0 :                                                                            (Q_evap_req * C_cap_operation - CompEvaporatingCAPSpd(CompSpdLB));
   13870              : 
   13871              :                 } else {
   13872            0 :                     CompSpdActual = this->CompressorSpeed(1) * (Q_evap_req * C_cap_operation) / CompEvaporatingCAPSpd(1);
   13873              :                 }
   13874              : 
   13875            0 :                 break; // EXIT DoName1
   13876              :             }
   13877              :         } // End: Iteration DoName1
   13878              : 
   13879            0 :         if (CounterCompSpdTemp > NumOfCompSpdInput) {
   13880            0 :             CompSpdActual = this->CompressorSpeed(NumOfCompSpdInput);
   13881              :         }
   13882              : 
   13883              :     } else {
   13884              :         // Capacity to meet is for condenser
   13885              : 
   13886              :         // derivation process
   13887              :         // let
   13888              :         // k be the speed level
   13889              :         // C be the short form for C_cap_operation
   13890              :         // PWR(.) be the short form of CompEvaporatingPWRSpd(.)
   13891              :         // CAP(.) be the short form of CompEvaporatingCAPSpd(.)
   13892              :         // spd(.) be the short form of this->CompressorSpeed(.)
   13893              :         // deltaPWR be PWR(k) - PWR(k - 1)
   13894              :         // deltaCAP be CAP(k) - CAP(k - 1)
   13895              :         //
   13896              :         // compressor heat = deltaPWR * r + PWR(k - 1)
   13897              :         // so
   13898              :         // Q_cond_req = Q_req = Q_evap_req + deltaPWR * r + PWR(k - 1) <---- eq 1
   13899              :         //
   13900              :         // we also know this from the CompSpdActual calculation equation that
   13901              :         // CompSpdActual = Spd(k - 1) + deltaSpd / deltaCAP * (Q_evap_req * C - CAP(k - 1))
   13902              :         // so we call the following r
   13903              :         // r = (Q_evap_req * C - CAP(k - 1)) / deltaCAP
   13904              :         // so
   13905              :         // CompSpdActual = Spd(k - 1) + deltaSpd * r
   13906              :         //
   13907              :         // arranging terms in eq 1
   13908              :         // Q_cond_req - deltaPWR * r - PWR(k - 1) = Q_evap_req
   13909              :         // (Q_cond_req - deltaPWR * r - PWR(k - 1)) * C - CAP(k - 1) = Q_evap_req * C - CAP(k - 1)
   13910              :         // ((Q_cond_req - deltaPWR * r - PWR(k - 1)) * C - CAP(k - 1)) / deltaCAP = (Q_evap_req * C - CAP(k - 1)) / deltaCAP
   13911              :         // ((Q_cond_req - deltaPWR * r - PWR(k - 1)) * C - CAP(k - 1)) / deltaCAP = r
   13912              :         // (Q_cond_req - deltaPWR * r - PWR(k - 1)) * C - CAP(k - 1) = deltaCAP * r
   13913              :         // (Q_cond_req - PWR(k - 1)) * C - CAP(k - 1) = deltaCAP * r + deltaPWR * r * C
   13914              :         // so
   13915              :         // r = ((Q_cond_req - PWR(k - 1)) * C - CAP(k - 1)) / (deltaCAP + deltaPWR * C)
   13916              :         //   = ((Q_cond_req - PWR(k - 1)) - CAP(k - 1)/C) / (deltaCAP/C + deltaPWR)
   13917              :         //
   13918              :         // in the special case where k = 1, then k - 1, PWR(k - 1) and CAP(k - 1) will all be 0
   13919              :         // r = ((Q_cond_req) * C) / (CAP(1) - PWR(1) * C)
   13920              :         //   = (Q_cond_req) / (CAP(1)/C - PWR(1))
   13921              : 
   13922            0 :         Q_cond_req = Q_req;
   13923              : 
   13924            0 :         CounterCompSpdTemp = 1;
   13925            0 :         CompEvaporatingPWRSpd(1) = this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(1), T_discharge, T_suction);
   13926            0 :         CompEvaporatingCAPSpd(1) = this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(1), T_discharge, T_suction);
   13927            0 :         Real64 r = (Q_cond_req * C_cap_operation) / (CompEvaporatingCAPSpd(1) + CompEvaporatingPWRSpd(1) * C_cap_operation);
   13928            0 :         if (r < 1.0) {
   13929            0 :             CompSpdActual = this->CompressorSpeed(1) * r;
   13930            0 :             Q_evap_req = Q_cond_req - CompEvaporatingPWRSpd(1) * r;
   13931              :         } else {
   13932            0 :             for (CounterCompSpdTemp = 2; CounterCompSpdTemp <= NumOfCompSpdInput; CounterCompSpdTemp++) {
   13933            0 :                 CompEvaporatingPWRSpd(CounterCompSpdTemp) =
   13934            0 :                     this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(CounterCompSpdTemp), T_discharge, T_suction);
   13935            0 :                 CompEvaporatingCAPSpd(CounterCompSpdTemp) =
   13936            0 :                     this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(CounterCompSpdTemp), T_discharge, T_suction);
   13937            0 :                 CompSpdLB = CounterCompSpdTemp - 1;
   13938            0 :                 CompSpdUB = CounterCompSpdTemp;
   13939            0 :                 Real64 deltaCAP = CompEvaporatingCAPSpd(CompSpdUB) - CompEvaporatingCAPSpd(CompSpdLB);
   13940            0 :                 Real64 deltaPWR = CompEvaporatingPWRSpd(CompSpdUB) - CompEvaporatingPWRSpd(CompSpdLB);
   13941            0 :                 Real64 r = ((Q_cond_req - CompEvaporatingPWRSpd(CompSpdLB)) * C_cap_operation - CompEvaporatingCAPSpd(CompSpdLB)) /
   13942            0 :                            (deltaCAP + deltaPWR * C_cap_operation);
   13943            0 :                 if (r < 1.0) {
   13944            0 :                     CompSpdActual = this->CompressorSpeed(CompSpdLB) + (this->CompressorSpeed(CompSpdUB) - this->CompressorSpeed(CompSpdLB)) * r;
   13945            0 :                     Q_evap_req = Q_cond_req - deltaPWR * r - CompEvaporatingPWRSpd(CompSpdLB);
   13946            0 :                     break;
   13947              :                 }
   13948              :             }
   13949              :         } // End: Iteration DoName1
   13950              : 
   13951            0 :         if (CounterCompSpdTemp > NumOfCompSpdInput) {
   13952            0 :             CompSpdActual = this->CompressorSpeed(NumOfCompSpdInput);
   13953              :         }
   13954              :     }
   13955            0 : }
   13956              : 
   13957            0 : void VRFCondenserEquipment::VRFOU_CompCap(
   13958              :     EnergyPlusData &state,
   13959              :     Real64 const CompSpdActual, // Given compressor speed
   13960              :     Real64 const T_suction,     // Compressor suction temperature Te' [C]
   13961              :     Real64 const T_discharge,   // Compressor discharge temperature Tc' [C]
   13962              :     Real64 const h_IU_evap_in,  // Enthalpy of IU at inlet, for C_cap_operation calculation [kJ/kg]
   13963              :     Real64 const h_comp_in,     // Enthalpy after piping loss (compressor inlet), for C_cap_operation calculation [kJ/kg]
   13964              :     Real64 &Q_c_tot,            // Compressor evaporative capacity [W]
   13965              :     Real64 &Ncomp               // Compressor power [W]
   13966              : )
   13967              : {
   13968              : 
   13969              :     // SUBROUTINE INFORMATION:
   13970              :     //       AUTHOR         Rongpeng Zhang, LBNL
   13971              :     //       DATE WRITTEN   Feb 2016
   13972              :     //       MODIFIED       na
   13973              :     //       RE-ENGINEERED  na
   13974              : 
   13975              :     // PURPOSE OF THIS SUBROUTINE:
   13976              :     //       This subroutine specifies the compressor performance (power and capacity) at given compressor speed and operational conditions.
   13977              : 
   13978              :     // METHODOLOGY EMPLOYED:
   13979              :     //       This is part of the VRF-FluidTCtrl Model.
   13980              : 
   13981              :     using Curve::CurveValue;
   13982              :     int CounterCompSpdTemp;                // Index for the compressor speed level[-]
   13983              :     int CompSpdLB;                         // index for Compressor speed low bound [-]
   13984              :     int CompSpdUB;                         // index for Compressor speed up bound [-]
   13985              :     int NumOfCompSpdInput;                 // Number of compressor speed input by the user [-]
   13986              :     Real64 C_cap_operation;                // Compressor capacity modification algorithm_modified Cap [-]
   13987              :     Real64 P_suction;                      // Compressor suction pressure Pe' [Pa]
   13988              :     Real64 Q_evap_sys;                     // evaporative capacity [W]
   13989              :     Real64 RefPLow;                        // Low Pressure Value for Ps (>0.0) [Pa]
   13990              :     Real64 RefPHigh;                       // High Pressure Value for Ps (max in tables) [Pa]
   13991              :     Real64 SH_Comp;                        // Temperature between compressor inlet temperature and evaporative temperature Te' [C]
   13992              :     Real64 T_comp_in;                      // Refrigerant temperature at compressor inlet (after piping loss) [C]
   13993            0 :     Array1D<Real64> CompEvaporatingPWRSpd; // Array for the compressor power at certain speed [W]
   13994            0 :     Array1D<Real64> CompEvaporatingCAPSpd; // Array for the evaporating capacity at certain speed [W]
   13995              : 
   13996              :     static constexpr std::string_view RoutineName("VRFOU_CompCap");
   13997              : 
   13998              :     // variable initializations: component index
   13999            0 :     RefPLow = this->refrig->PsLowPresValue;
   14000            0 :     RefPHigh = this->refrig->PsHighPresValue;
   14001              : 
   14002              :     // variable initializations: compressor
   14003            0 :     NumOfCompSpdInput = this->CompressorSpeed.size();
   14004            0 :     CompEvaporatingPWRSpd.dimension(NumOfCompSpdInput);
   14005            0 :     CompEvaporatingCAPSpd.dimension(NumOfCompSpdInput);
   14006              : 
   14007            0 :     for (CounterCompSpdTemp = 1; CounterCompSpdTemp <= NumOfCompSpdInput; CounterCompSpdTemp++) {
   14008              : 
   14009            0 :         CompEvaporatingPWRSpd(CounterCompSpdTemp) =
   14010            0 :             this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(CounterCompSpdTemp), T_discharge, T_suction);
   14011            0 :         CompEvaporatingCAPSpd(CounterCompSpdTemp) =
   14012            0 :             this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(CounterCompSpdTemp), T_discharge, T_suction);
   14013              : 
   14014            0 :         if (CompSpdActual <= this->CompressorSpeed(CounterCompSpdTemp)) {
   14015              :             // Compressor speed stage CounterCompSpdTemp need not to be increased, finish Iteration DoName1
   14016              : 
   14017            0 :             if (CounterCompSpdTemp > 1) {
   14018              : 
   14019            0 :                 CompSpdLB = CounterCompSpdTemp - 1;
   14020            0 :                 CompSpdUB = CounterCompSpdTemp;
   14021              : 
   14022            0 :                 Q_evap_sys = CompEvaporatingCAPSpd(CompSpdLB) + (CompEvaporatingCAPSpd(CompSpdUB) - CompEvaporatingCAPSpd(CompSpdLB)) *
   14023            0 :                                                                     (CompSpdActual - this->CompressorSpeed(CompSpdLB)) /
   14024            0 :                                                                     (this->CompressorSpeed(CompSpdUB) - this->CompressorSpeed(CompSpdLB));
   14025            0 :                 Ncomp = CompEvaporatingPWRSpd(CompSpdLB) + (CompEvaporatingPWRSpd(CompSpdUB) - CompEvaporatingPWRSpd(CompSpdLB)) *
   14026            0 :                                                                (CompSpdActual - this->CompressorSpeed(CompSpdLB)) /
   14027            0 :                                                                (this->CompressorSpeed(CompSpdUB) - this->CompressorSpeed(CompSpdLB));
   14028              : 
   14029              :             } else {
   14030            0 :                 Q_evap_sys = CompEvaporatingCAPSpd(1) * CompSpdActual / this->CompressorSpeed(1);
   14031            0 :                 Ncomp = CompEvaporatingPWRSpd(1) * CompSpdActual / this->CompressorSpeed(1);
   14032              :             }
   14033              : 
   14034            0 :             break;
   14035              :         }
   14036              :     }
   14037              : 
   14038            0 :     if (CounterCompSpdTemp > NumOfCompSpdInput) {
   14039            0 :         Q_evap_sys = CompEvaporatingCAPSpd(NumOfCompSpdInput);
   14040            0 :         Ncomp = CompEvaporatingPWRSpd(NumOfCompSpdInput);
   14041              :     }
   14042              : 
   14043              :     // variable initializations: system operational parameters
   14044            0 :     P_suction = this->refrig->getSatPressure(state, T_suction, RoutineName);
   14045            0 :     T_comp_in = this->refrig->getSupHeatTemp(state, max(min(P_suction, RefPHigh), RefPLow), h_comp_in, T_suction + 3, T_suction + 30, RoutineName);
   14046            0 :     SH_Comp = T_comp_in - T_suction;
   14047              : 
   14048              :     // Calculate capacity modification factor
   14049            0 :     C_cap_operation = this->VRFOU_CapModFactor(
   14050              :         state, h_comp_in, h_IU_evap_in, max(min(P_suction, RefPHigh), RefPLow), T_suction + SH_Comp, T_suction + 8, T_discharge - 5);
   14051            0 :     C_cap_operation = min(1.5, max(0.5, C_cap_operation));
   14052            0 :     Q_c_tot = Q_evap_sys / C_cap_operation;
   14053            0 : }
   14054              : 
   14055        18463 : void VRFCondenserEquipment::VRFOU_CalcCompC(EnergyPlusData &state,
   14056              :                                             Real64 TU_load,            // Indoor unit cooling load [W]
   14057              :                                             Real64 T_suction,          // Compressor suction temperature Te' [C]
   14058              :                                             Real64 T_discharge,        // Compressor discharge temperature Tc' [C]
   14059              :                                             Real64 P_suction,          // Compressor suction pressure Pe' [Pa]
   14060              :                                             Real64 Pipe_T_comp_in,     // Refrigerant temperature at compressor inlet (after piping loss) [C]
   14061              :                                             Real64 Pipe_h_comp_in,     // Enthalpy after piping loss (compressor inlet) [kJ/kg]
   14062              :                                             Real64 Pipe_h_IU_in,       // Enthalpy of IU at inlet [kJ/kg]
   14063              :                                             Real64 Pipe_Q,             // Piping Loss Algorithm Parameter: Heat loss [W]
   14064              :                                             Real64 MaxOutdoorUnitTc,   // The maximum temperature that Tc can be at heating mode [C]
   14065              :                                             Real64 &OUCondHeatRelease, // Condenser heat release (cooling mode) [W]
   14066              :                                             Real64 &CompSpdActual,     // Actual compressor running speed [rps]
   14067              :                                             Real64 &Ncomp,             // Compressor power [W]
   14068              :                                             Real64 &CyclingRatio       // Cycling Ratio [W]
   14069              : )
   14070              : {
   14071              : 
   14072              :     // SUBROUTINE INFORMATION:
   14073              :     //       AUTHOR         Xiufeng Pang
   14074              :     //       DATE WRITTEN   Feb 2014
   14075              :     //       MODIFIED       Rongpeng Zhang, Jan 2016
   14076              :     //       MODIFIED       Yujie Xu, Sep 2023
   14077              :     //       RE-ENGINEERED  na
   14078              : 
   14079              :     // PURPOSE OF THIS SUBROUTINE:
   14080              :     // This subroutine simulates the compressor performance at given operational conditions (cooling mode). More specifically, it specifies
   14081              :     // the compressor speed to provide sufficient evaporative capacity, and calculate the power of the compressor running at the specified
   14082              :     // speed. Note that it may be needed to manipulate the operational conditions to further adjust system capacity at low load conditions.
   14083              :     // The low load modification logics are different for cooling mode and heating mode.
   14084              : 
   14085              :     // METHODOLOGY EMPLOYED:
   14086              :     // This is part of the VRF-FluidTCtrl Model.
   14087              : 
   14088              :     using Curve::CurveValue;
   14089              : 
   14090              :     using General::SolveRoot;
   14091              : 
   14092              :     int CounterCompSpdTemp;                // Index for the compressor speed level[-]
   14093              :     int CompSpdLB;                         // index for Compressor speed low bound [-]
   14094              :     int CompSpdUB;                         // index for Compressor speed up bound [-]
   14095              :     int CoolCoilIndex;                     // index to cooling coil in terminal unit
   14096        18463 :     int MaxIter(500);                      // max iteration number allowed [-]
   14097              :     int NumOfCompSpdInput;                 // Number of compressor speed input by the user [-]
   14098              :     int NumIteCcap;                        // counter for Ccap calculation iterations [-]
   14099              :     int NumIteTe;                          // counter for Te calculation iterations [-]
   14100              :     int NumTUInList;                       // number of terminal units is list
   14101              :     int SolFla;                            // Slove flag for SolveRoot [-]
   14102              :     int TUListNum;                         // index to TU List
   14103              :     int TUIndex;                           // Index to terminal unit
   14104              :     Real64 Cap_Eva0;                       // Evaporating capacity calculated based on physics model, used in the iterations [W]
   14105              :     Real64 Cap_Eva1;                       // Evaporating capacity calculated by curves, used in the iterations [W]
   14106              :     Real64 CapDiff;                        // Evaporating capacity difference used in the iterations [W]
   14107              :     Real64 C_cap_operation;                // Compressor capacity modification algorithm_modified Cap [-]
   14108              :     Real64 C_cap_operation0;               // Compressor capacity modification algorithm_modified Cap, for temporary use [-]
   14109              :     Real64 SmallLoadTe;                    // Updated suction temperature at small load conditions (Te') [C]
   14110              :     Real64 Modifi_SH;                      // Temperature between compressor inlet temperature and evaporative temperature Te' [C]
   14111              :     Real64 MaxNumIteTe;                    // Piping Loss Algorithm Parameter: max number of iterations for Te [-]
   14112              :     Real64 MinOutdoorUnitTe;               // The minimum temperature that Te can be at cooling mode (only used for calculating Min capacity)
   14113              :     Real64 MinOutdoorUnitPe;               // The minimum pressure that Pe can be at cooling mode (only used for calculating Min capacity)
   14114              :     Real64 MinRefriPe;                     // Minimum refrigerant evaporating pressure [Pa]
   14115              :     Real64 Modifi_SHin;                    // Compressor power modification algorithm_modified SH for IDU [C]
   14116              :     Real64 P_discharge;                    // VRF compressor discharge pressure [Pa]
   14117              :     Real64 Pipe_m_ref;                     // Piping Loss Algorithm Parameter: Refrigerant mass flow rate [kg/s]
   14118              :     Real64 Pipe_DeltP;                     // Piping Loss Algorithm Parameter: Pipe pressure drop [Pa]
   14119              :     Real64 Pipe_Q0;                        // Compressor capacity modification algorithm_modified Pipe_Q, for temporary use [W]
   14120              :     Real64 Pipe_m_ref_i;                   // Piping Loss Algorithm Parameter: Refrigerant mass flow rate for a individual IU[kg/s]
   14121              :     Real64 Pipe_h_IU_out;                  // Piping Loss Algorithm Parameter: enthalpy of IU at outlet [kJ/kg]
   14122              :     Real64 Pipe_h_IU_out_i;                // Piping Loss Algorithm Parameter: enthalpy of IU at outlet (individual) [kJ/kg]
   14123              :     Real64 Pipe_Pe_assumed;                // Piping Loss Algorithm Parameter: evaporating pressure assumed for iterations[Pa]
   14124              :     Real64 Pipe_SH_merged;                 // Piping Loss Algorithm Parameter: average super heating degrees after the indoor units [C]
   14125              :     Real64 Pipe_Te_assumed;                // Piping Loss Algorithm Parameter: evaporating temperature assumed for iterations[C]
   14126              :     Real64 Q_evap_req;                     // Required evaporative capacity [W]
   14127              :     Real64 RefTSat;                        // Saturated temperature of the refrigerant [C]
   14128              :     Real64 RefPLow;                        // Low Pressure Value for Ps (>0.0) [Pa]
   14129              :     Real64 RefPHigh;                       // High Pressure Value for Ps (max in tables) [Pa]
   14130              :     Real64 T_discharge_new;                // Condensing temperature, for temporary use in iterations [C]
   14131              :     Real64 Tfs;                            // Temperature of the air at the coil surface [C]]
   14132        18463 :     Real64 constexpr Tolerance(0.05);      // Tolerance for condensing temperature calculation [C]
   14133        18463 :     Real64 constexpr TeTol(0.5);           // Tolerance for the difference between Te and SmallLoadTe
   14134        18463 :     Array1D<Real64> CompEvaporatingPWRSpd; // Array for the compressor power at certain speed [W]
   14135        18463 :     Array1D<Real64> CompEvaporatingCAPSpd; // Array for the evaporating capacity at certain speed [W]
   14136              : 
   14137              :     static constexpr std::string_view RoutineName("VRFOU_CalcCompC");
   14138              : 
   14139              :     // variable initializations
   14140        18463 :     NumOfCompSpdInput = this->CompressorSpeed.size();
   14141        18463 :     CompEvaporatingPWRSpd.dimension(NumOfCompSpdInput);
   14142        18463 :     CompEvaporatingCAPSpd.dimension(NumOfCompSpdInput);
   14143        18463 :     Q_evap_req = TU_load + Pipe_Q;
   14144              : 
   14145        18463 :     TUListNum = this->ZoneTUListPtr;
   14146        18463 :     RefPLow = this->refrig->PsLowPresValue;
   14147        18463 :     RefPHigh = this->refrig->PsHighPresValue;
   14148        18463 :     NumTUInList = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList;
   14149              : 
   14150        18463 :     Modifi_SH = Pipe_T_comp_in - T_suction;
   14151              : 
   14152              :     // set condenser entering air conditions (Outdoor air conditions)
   14153        18463 :     Real64 OutdoorDryBulb = state.dataEnvrn->OutDryBulbTemp;
   14154        18463 :     Real64 OutdoorHumRat = state.dataEnvrn->OutHumRat;
   14155        18463 :     Real64 OutdoorPressure = state.dataEnvrn->OutBaroPress;
   14156        18463 :     Real64 RhoAir = PsyRhoAirFnPbTdbW(state, OutdoorPressure, OutdoorDryBulb, OutdoorHumRat);
   14157              : 
   14158              :     // Calculate capacity modification factor
   14159        18463 :     C_cap_operation = this->VRFOU_CapModFactor(
   14160              :         state, Pipe_h_comp_in, Pipe_h_IU_in, max(min(P_suction, RefPHigh), RefPLow), T_suction + Modifi_SH, T_suction + 8, T_discharge - 5);
   14161              : 
   14162        18463 :     this->adjustedTe = false;
   14163        37361 :     for (CounterCompSpdTemp = 1; CounterCompSpdTemp <= NumOfCompSpdInput; CounterCompSpdTemp++) {
   14164              :         // Iteration to find the VRF speed that can meet the required load, Iteration DoName1
   14165              : 
   14166        74722 :         CompEvaporatingPWRSpd(CounterCompSpdTemp) =
   14167        37361 :             this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(CounterCompSpdTemp), T_discharge, T_suction);
   14168        74722 :         CompEvaporatingCAPSpd(CounterCompSpdTemp) =
   14169        37361 :             this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(CounterCompSpdTemp), T_discharge, T_suction);
   14170              : 
   14171        37361 :         if (Q_evap_req * C_cap_operation <= CompEvaporatingCAPSpd(CounterCompSpdTemp)) {
   14172              :             // Compressor speed stage CounterCompSpdTemp need not to be increased, finish Iteration DoName1
   14173              : 
   14174        18463 :             if (CounterCompSpdTemp > 1) { // Since: if( CounterCompSpdTemp <= 1 )
   14175              :                 // Compressor speed > min
   14176              : 
   14177         9386 :                 CompSpdLB = CounterCompSpdTemp - 1;
   14178         9386 :                 CompSpdUB = CounterCompSpdTemp;
   14179              : 
   14180         9386 :                 CompSpdActual = this->CompressorSpeed(CompSpdLB) + (this->CompressorSpeed(CompSpdUB) - this->CompressorSpeed(CompSpdLB)) /
   14181         9386 :                                                                        (CompEvaporatingCAPSpd(CompSpdUB) - CompEvaporatingCAPSpd(CompSpdLB)) *
   14182         9386 :                                                                        (Q_evap_req * C_cap_operation - CompEvaporatingCAPSpd(CompSpdLB));
   14183              : 
   14184         9386 :                 Ncomp = CompEvaporatingPWRSpd(CompSpdLB) + (CompEvaporatingPWRSpd(CompSpdUB) - CompEvaporatingPWRSpd(CompSpdLB)) /
   14185         9386 :                                                                (this->CompressorSpeed(CompSpdUB) - this->CompressorSpeed(CompSpdLB)) *
   14186         9386 :                                                                (CompSpdActual - this->CompressorSpeed(CompSpdLB));
   14187         9386 :                 break; // EXIT DoName1
   14188              : 
   14189              :             } else {
   14190              :                 // Compressor runs at the min speed
   14191              :                 // Low Load Modification Algorithm for cooling (IU side modification)
   14192              : 
   14193              :                 // Initialization of NumIteCcap iterations (Label13)
   14194         9077 :                 Pipe_Q0 = Pipe_Q;
   14195         9077 :                 C_cap_operation0 = C_cap_operation;
   14196         9077 :                 T_discharge_new = T_discharge;
   14197         9077 :                 NumIteCcap = 1;
   14198              : 
   14199              :                 // Update the C_cap_operation
   14200              :                 bool converged_13;
   14201              :                 do {
   14202       264248 :                     Q_evap_req = TU_load + Pipe_Q0; // Pipe_Q0 is updated during the iteration
   14203       264248 :                     Pipe_h_IU_in = this->refrig->getSatEnthalpy(state, T_discharge_new - this->SC, 0.0, RoutineName);
   14204       264248 :                     CompSpdActual = this->CompressorSpeed(1);
   14205       264248 :                     Real64 CondHeat = Q_evap_req * C_cap_operation0 / this->RatedEvapCapacity; // 150130 To be confirmed
   14206       264248 :                     int CAPFT = this->OUCoolingCAPFT(CounterCompSpdTemp);
   14207              : 
   14208       264248 :                     P_discharge = this->refrig->getSatPressure(state, T_discharge, RoutineName);
   14209       264248 :                     MinRefriPe = this->refrig->getSatPressure(state, -15, RoutineName);
   14210       264248 :                     MinOutdoorUnitPe = max(P_discharge - this->CompMaxDeltaP, MinRefriPe);
   14211       264248 :                     MinOutdoorUnitTe = this->refrig->getSatTemperature(state, max(min(MinOutdoorUnitPe, RefPHigh), RefPLow), RoutineName);
   14212              :                     // Te can't be smaller than user input lower bound
   14213       264248 :                     MinOutdoorUnitTe = max(this->IUEvapTempLow, MinOutdoorUnitTe);
   14214              : 
   14215       804156 :                     auto f = [&state, T_discharge_new, CondHeat, CAPFT](Real64 const T_suc) {
   14216       804156 :                         return CompResidual_FluidTCtrl(state, T_discharge_new, CondHeat, CAPFT, T_suc);
   14217       264248 :                     };
   14218              : 
   14219       264248 :                     General::SolveRoot(state, 1.0e-3, MaxIter, SolFla, SmallLoadTe, f, MinOutdoorUnitTe,
   14220              :                                        T_suction); // SmallLoadTe is the updated Te'
   14221       264248 :                     if (SolFla == -1) {
   14222              :                         // show error not converging
   14223            0 :                         ShowWarningMessage(state, format("{}: low load Te adjustment failed for {}", RoutineName, this->Name));
   14224            0 :                         ShowContinueErrorTimeStamp(state, "");
   14225            0 :                         ShowContinueError(state, format("  Iteration limit [{}] exceeded in calculating OU evaporating temperature", MaxIter));
   14226       264248 :                     } else if (SolFla == -2) {
   14227       264050 :                         this->LowLoadTeError++;
   14228       264050 :                         if (LowLoadTeError < 5) {
   14229           32 :                             ShowWarningMessage(state,
   14230           32 :                                                format("{}: no Te solution was found for {} f({})={} and f({})={} are the same sign",
   14231              :                                                       RoutineName,
   14232           16 :                                                       this->Name,
   14233              :                                                       MinOutdoorUnitTe,
   14234           16 :                                                       f(MinOutdoorUnitTe),
   14235              :                                                       T_suction,
   14236           16 :                                                       f(T_suction)));
   14237           48 :                             ShowContinueErrorTimeStamp(state, "");
   14238              :                         }
   14239      1848350 :                         ShowRecurringWarningErrorAtEnd(state,
   14240              :                                                        "Low load calculation Te solution not found as end points have the same sign",
   14241       264050 :                                                        this->LowLoadTeErrorIndex,
   14242              :                                                        SolFla,
   14243              :                                                        SolFla);
   14244       264050 :                         if (f(T_suction) < 0) {
   14245              :                             // demand < capacity at both endpoints of the Te range, assuming f(x) is roughly monotonic than this is the low load case
   14246              :                             // TeTol is added to prevent the final updated Te to go out of bounds
   14247       258453 :                             SmallLoadTe = MinOutdoorUnitTe + TeTol; // MinOutdoorUnitTe; //SmallLoadTe( Te'_new ) is constant during iterations
   14248              :                         } else {
   14249              :                             // demand > capacity at both endpoints of the Te range, take the end point x where f(x) is closer to zero
   14250         5597 :                             if (f(MinOutdoorUnitTe) > f(T_suction)) { // f(T_suction > 0, not equal as SolFla will not be -2
   14251         5597 :                                 SmallLoadTe = T_suction;
   14252              :                             } else {
   14253            0 :                                 SmallLoadTe = MinOutdoorUnitTe;
   14254              :                             }
   14255              :                         }
   14256              :                     }
   14257              : 
   14258              :                     // Get an updated Te corresponding to the updated Te'
   14259              :                     // VRFOU_TeModification( VRFCond, this->EvaporatingTemp, SmallLoadTe, Pipe_h_IU_in, OutdoorDryBulb, Pipe_Te_assumed,
   14260              :                     // Pipe_Pe_assumed, Pipe_m_ref, Pipe_SH_merged );
   14261              :                     {
   14262              :                         // Initialization of Iteration_Te (Label11)
   14263              :                         // i.e., find a new Te (Pipe_Te_assumed) that can generate a new T_suction equaling to SmallLoadTe.
   14264              :                         // This requires the re-calculate of piping loss.
   14265       264248 :                         NumIteTe = 1;
   14266       264248 :                         MaxNumIteTe = (this->EvaporatingTemp - SmallLoadTe) / 0.1 + 1; // upper bound and lower bound of Te iterations
   14267       264248 :                         Pipe_Te_assumed = this->EvaporatingTemp - 0.1;
   14268       264248 :                         this->adjustedTe = true;
   14269              : 
   14270              :                         bool converged_11_2;
   14271              :                         do {
   14272      1901065 :                             Pipe_m_ref = 0; // Total Ref Flow Rate( kg/s )
   14273              : 
   14274              :                             // Re-calculate Piping loss due to the Te and SH updates
   14275      1901065 :                             Pipe_h_IU_out = 0;
   14276      1901065 :                             Pipe_h_IU_out_i = 0;
   14277      1901065 :                             Pipe_m_ref_i = 0;
   14278      1901065 :                             Pipe_SH_merged = 0;
   14279      1901065 :                             Pipe_Pe_assumed = this->refrig->getSatPressure(state, Pipe_Te_assumed, RoutineName);
   14280              : 
   14281              :                             // Re-calculate total refrigerant flow rate, with updated SH
   14282      9637162 :                             for (int NumTU = 1; NumTU <= NumTUInList; NumTU++) {
   14283      7736097 :                                 if (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) > 0) {
   14284      7627197 :                                     TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   14285      7627197 :                                     CoolCoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolCoilIndex;
   14286              : 
   14287      7627197 :                                     Tfs = this->EvaporatingTemp + (this->C3Te * pow_2(state.dataDXCoils->DXCoil(CoolCoilIndex).ActualSH) +
   14288      7627197 :                                                                    this->C2Te * state.dataDXCoils->DXCoil(CoolCoilIndex).ActualSH + this->C1Te);
   14289              : 
   14290              :                                     // Modifi_SH is the updated SH for a specific IU
   14291      7627197 :                                     if (this->C3Te == 0) {
   14292            0 :                                         Modifi_SHin = -(this->C1Te - Tfs + Pipe_Te_assumed) / this->C2Te; // 150130 Modifi_SH>Modifi_SHin
   14293              :                                     } else {
   14294      7627197 :                                         Modifi_SHin = (-this->C2Te +
   14295      7627197 :                                                        std::pow((pow_2(this->C2Te) - 4 * (this->C1Te - Tfs + Pipe_Te_assumed) * this->C3Te), 0.5)) /
   14296      7627197 :                                                       (2 * this->C3Te);
   14297              :                                     }
   14298              : 
   14299      7627197 :                                     RefTSat = this->refrig->getSatTemperature(state, max(min(Pipe_Pe_assumed, RefPHigh), RefPLow), RoutineName);
   14300      7627197 :                                     Pipe_h_IU_out_i = this->refrig->getSupHeatEnthalpy(state,
   14301              :                                                                                        max(RefTSat, Pipe_Te_assumed + Modifi_SHin),
   14302              :                                                                                        max(min(Pipe_Pe_assumed, RefPHigh), RefPLow),
   14303              :                                                                                        RoutineName);
   14304              : 
   14305      7627197 :                                     if (Pipe_h_IU_out_i > Pipe_h_IU_in) {
   14306      7627197 :                                         Real64 min_speed_capacity = this->CoffEvapCap * this->RatedEvapCapacity *
   14307      7627197 :                                                                     CurveValue(state, this->OUCoolingCAPFT(1), T_discharge, T_suction);
   14308      7627197 :                                         Pipe_m_ref_i = (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU) <= 0.0)
   14309      7627197 :                                                            ? 0.0
   14310              :                                                            // refrigerant flow rate do not get smaller when the compressor needs to cycle.
   14311      7627197 :                                                            : max(min_speed_capacity,
   14312      7627197 :                                                                  (state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).TotalCoolLoad(NumTU)) /
   14313      7627197 :                                                                      (Pipe_h_IU_out_i - Pipe_h_IU_in));
   14314      7627197 :                                         Pipe_m_ref = Pipe_m_ref + Pipe_m_ref_i;
   14315      7627197 :                                         Pipe_SH_merged = Pipe_SH_merged + Pipe_m_ref_i * Modifi_SHin;
   14316      7627197 :                                         Pipe_h_IU_out = Pipe_h_IU_out + Pipe_m_ref_i * Pipe_h_IU_out_i;
   14317              :                                     }
   14318              :                                 }
   14319              :                             }
   14320      1901065 :                             if (Pipe_m_ref > 0) {
   14321      1901065 :                                 Pipe_h_IU_out = Pipe_h_IU_out / Pipe_m_ref;
   14322      1901065 :                                 Pipe_SH_merged = Pipe_SH_merged / Pipe_m_ref;
   14323              :                             } else {
   14324            0 :                                 Pipe_SH_merged = this->SH;
   14325            0 :                                 RefTSat = this->refrig->getSatTemperature(state, max(min(Pipe_Pe_assumed, RefPHigh), RefPLow), RoutineName);
   14326            0 :                                 Pipe_h_IU_out = this->refrig->getSupHeatEnthalpy(
   14327              :                                     state, max(RefTSat, Pipe_Te_assumed + Pipe_SH_merged), max(min(Pipe_Pe_assumed, RefPHigh), RefPLow), RoutineName);
   14328              :                             }
   14329              : 
   14330              :                             // Re-calculate piping loss
   14331      1901065 :                             this->VRFOU_PipeLossC(state,
   14332              :                                                   Pipe_m_ref,
   14333              :                                                   max(min(Pipe_Pe_assumed, RefPHigh), RefPLow),
   14334              :                                                   Pipe_h_IU_out,
   14335              :                                                   Pipe_SH_merged,
   14336              :                                                   OutdoorDryBulb,
   14337              :                                                   Pipe_Q,
   14338              :                                                   Pipe_DeltP,
   14339              :                                                   Pipe_h_comp_in);
   14340              : 
   14341      1901065 :                             T_suction =
   14342      1901065 :                                 this->refrig->getSatTemperature(state, max(min(Pipe_Pe_assumed - Pipe_DeltP, RefPHigh), RefPLow), RoutineName);
   14343              : 
   14344      3802130 :                             converged_11_2 = !((std::abs(T_suction - SmallLoadTe) > TeTol) && (Pipe_Te_assumed < this->EvaporatingTemp) &&
   14345      1901065 :                                                (Pipe_Te_assumed > SmallLoadTe) && (NumIteTe < MaxNumIteTe));
   14346      1901065 :                             Pipe_Te_assumed = Pipe_Te_assumed - 0.1;
   14347      1901065 :                             NumIteTe = NumIteTe + 1;
   14348      1901065 :                         } while (!converged_11_2);
   14349              : 
   14350       264248 :                         if (std::abs(T_suction - SmallLoadTe) > TeTol) {
   14351       264248 :                             NumIteTe = 999;
   14352       264248 :                             T_suction = SmallLoadTe;
   14353       264248 :                             Pipe_SH_merged = 3.0;
   14354       264248 :                             Pipe_Te_assumed = SmallLoadTe + 1;
   14355              :                         }
   14356              :                         // Iteration_Te End
   14357              :                     }
   14358              : 
   14359              :                     // Perform iteration to calculate Pipe_T_comp_in( Te'+SH' )
   14360       264248 :                     Pipe_T_comp_in = this->refrig->getSupHeatTemp(
   14361              :                         state, max(min(Pipe_Pe_assumed - Pipe_DeltP, RefPHigh), RefPLow), Pipe_h_comp_in, T_suction + 3, T_suction + 30, RoutineName);
   14362              : 
   14363       264248 :                     Modifi_SH = Pipe_T_comp_in - T_suction;
   14364       264248 :                     P_suction = Pipe_Pe_assumed - Pipe_DeltP;
   14365       264248 :                     OUCondHeatRelease = TU_load + Pipe_Q + Ncomp; // Pipe_Q is changed when T_suction is changed -> Tc is also changed
   14366              : 
   14367              :                     // *VRF OU Tc calculations
   14368       264248 :                     this->VRFOU_TeTc(state,
   14369              :                                      HXOpMode::CondMode,
   14370              :                                      OUCondHeatRelease,
   14371              :                                      this->SC,
   14372       264248 :                                      this->OUAirFlowRate * RhoAir,
   14373              :                                      OutdoorDryBulb,
   14374              :                                      OutdoorHumRat,
   14375              :                                      OutdoorPressure,
   14376              :                                      Tfs,
   14377              :                                      T_discharge);
   14378       264248 :                     T_discharge = min(MaxOutdoorUnitTc, T_discharge);
   14379              : 
   14380              :                     // *Calculate capacity modification factor
   14381       264248 :                     C_cap_operation = this->VRFOU_CapModFactor(state,
   14382              :                                                                Pipe_h_comp_in,
   14383              :                                                                Pipe_h_IU_in,
   14384              :                                                                max(min(P_suction, RefPHigh), RefPLow),
   14385              :                                                                T_suction + Modifi_SH,
   14386              :                                                                T_suction + 8,
   14387              :                                                                T_discharge - 5);
   14388              : 
   14389       264248 :                     Cap_Eva0 = (TU_load + Pipe_Q) * C_cap_operation; // New Pipe_Q & C_cap_operation
   14390       528496 :                     Cap_Eva1 = this->CoffEvapCap * this->RatedEvapCapacity *
   14391       264248 :                                CurveValue(state, this->OUCoolingCAPFT(CounterCompSpdTemp), T_discharge, T_suction); // New Tc
   14392       264248 :                     CapDiff = std::abs(Cap_Eva1 - Cap_Eva0);
   14393       264248 :                     converged_13 = !((CapDiff > (Tolerance * Cap_Eva0)) && (NumIteCcap < 30));
   14394       264248 :                     NumIteCcap = NumIteCcap + 1;
   14395       264248 :                     Pipe_Q0 = Pipe_Q;
   14396       264248 :                     C_cap_operation0 = C_cap_operation;
   14397       264248 :                     T_discharge_new = T_discharge;
   14398       264248 :                 } while (!converged_13);
   14399              : 
   14400              :                 // when it gets here, either NumIteCcap = 30 or CapDiff > (Tolerance * Cap_Eva0)
   14401         9077 :                 if (CapDiff > (Tolerance * Cap_Eva0) && (Cap_Eva1 - Cap_Eva0) >= 0.0) {
   14402         8606 :                     NumIteCcap = 999;
   14403         8606 :                     CyclingRatio = Cap_Eva0 / Cap_Eva1;
   14404              :                 } else {
   14405          471 :                     CyclingRatio = 1.0;
   14406              :                 }
   14407              : 
   14408         9077 :                 Ncomp = this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(CounterCompSpdTemp), T_discharge, T_suction);
   14409         9077 :                 OUCondHeatRelease = Ncomp + Cap_Eva1;
   14410              : 
   14411         9077 :                 this->CondensingTemp = T_discharge; // OU Tc' is updated due to OUCondHeatRelease updates, which is caused by IU Te' updates
   14412              :                                                     // during low load conditions
   14413         9077 :                 this->EvaporatingTemp = T_suction;
   14414         9077 :                 this->IUEvaporatingTemp = T_suction;
   14415              : 
   14416         9077 :                 break; // EXIT DoName1
   14417              : 
   14418              :             } // End: if( CounterCompSpdTemp <= 1 ) Low load modification
   14419              : 
   14420              :         } // End: if( Q_evap_req <= CompEvaporatingCAPSpd( CounterCompSpdTemp ) )
   14421              : 
   14422              :     } // End: Iteration DoName1
   14423              : 
   14424        18463 :     if (CounterCompSpdTemp > NumOfCompSpdInput) {
   14425              :         // Required load is beyond the maximum system capacity
   14426            0 :         CompEvaporatingCAPSpd(NumOfCompSpdInput) =
   14427            0 :             this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(NumOfCompSpdInput), T_discharge, T_suction);
   14428            0 :         OUCondHeatRelease = Ncomp + CompEvaporatingCAPSpd(NumOfCompSpdInput);
   14429            0 :         CompSpdActual = this->CompressorSpeed(NumOfCompSpdInput);
   14430            0 :         Ncomp = CompEvaporatingPWRSpd(NumOfCompSpdInput);
   14431              :     }
   14432        18463 : }
   14433              : 
   14434        26940 : void VRFCondenserEquipment::VRFOU_CalcCompH(
   14435              :     EnergyPlusData &state,
   14436              :     Real64 TU_load,            // Indoor unit heating load [W]
   14437              :     Real64 T_suction,          // Compressor suction temperature Te' [C]
   14438              :     Real64 T_discharge,        // Compressor discharge temperature Tc' [C]
   14439              :     Real64 Pipe_h_out_ave,     // Average Enthalpy of the refrigerant leaving IUs [kJ/kg]
   14440              :     Real64 IUMaxCondTemp,      // VRV IU condensing temperature, max among all indoor units [C]
   14441              :     Real64 MinOutdoorUnitTe,   // The minimum temperature that OU Te can be at cooling mode (only used for calculating Min capacity)
   14442              :     Real64 Tfs,                // Temperature of the air at the OU evaporator coil surface [C]]
   14443              :     Real64 Pipe_Q,             // Piping Loss Algorithm Parameter: Heat loss [W]
   14444              :     Real64 &OUEvapHeatExtract, // Condenser heat release (cooling mode) [W]
   14445              :     Real64 &CompSpdActual,     // Actual compressor running speed [rps]
   14446              :     Real64 &Ncomp,             // Compressor power [W]
   14447              :     Real64 &CyclingRatio       // Compressor cycling ratio
   14448              : )
   14449              : {
   14450              : 
   14451              :     // SUBROUTINE INFORMATION:
   14452              :     //       AUTHOR         Xiufeng Pang
   14453              :     //       DATE WRITTEN   Feb 2014
   14454              :     //       MODIFIED       Rongpeng Zhang, Jan 2016
   14455              :     //       RE-ENGINEERED  na
   14456              : 
   14457              :     // PURPOSE OF THIS SUBROUTINE:
   14458              :     // This subroutine simulates the compressor performance at given proportional conditions (heating mode). More specifically, it specifies
   14459              :     // the compressor speed to provide sufficient evaporative capacity, and calculate the power of the compressor running at the specified
   14460              :     // speed. Note that it may be needed to manipulate the operational conditions to further adjust system capacity at low load conditions.
   14461              :     // The low load modification logics are different for cooling mode and heating mode.
   14462              : 
   14463              :     // METHODOLOGY EMPLOYED:
   14464              :     // This is part of the VRF-FluidTCtrl Model.
   14465              : 
   14466              :     using Curve::CurveValue;
   14467              :     using General::SolveRoot;
   14468              : 
   14469              :     int CounterCompSpdTemp;                // Index for the compressor speed level[-]
   14470              :     int CompSpdLB;                         // index for Compressor speed low bound [-]
   14471              :     int CompSpdUB;                         // index for Compressor speed up bound [-]
   14472        26940 :     int MaxIter(500);                      // max iteration number allowed [-]
   14473              :     int NumOfCompSpdInput;                 // Number of compressor speed input by the user [-]
   14474              :     int NumIteCcap;                        // counter for Ccap calculation iterations [-]
   14475              :     int NumTUInList;                       // number of terminal units is list
   14476              :     int SolFla;                            // Solve flag for SolveRoot [-]
   14477              :     int TUListNum;                         // index to TU List
   14478              :     Real64 Cap_Eva0;                       // Evaporating capacity calculated based on physics model, used in the iterations [W]
   14479              :     Real64 Cap_Eva1;                       // Evaporating capacity calculated by curves, used in the iterations [W]
   14480              :     Real64 CapDiff;                        // Evaporating capacity difference used in the iterations [W]
   14481              :     Real64 C_cap_operation;                // Compressor capacity modification algorithm_modified Cap [-]
   14482              :     Real64 SmallLoadTe;                    // Updated suction temperature at small load conditions (Te') [C]
   14483              :     Real64 Modifi_SH;                      // Temperature between compressor inlet temperature and evaporative temperature Te' [C]
   14484              :     Real64 MinOutdoorUnitPe;               // The minimum pressure that Pe can be at cooling mode (only used for calculating Min capacity)
   14485              :     Real64 Modifi_Pe;                      // Compressor power modification algorithm_modified Pe [Pa]
   14486              :     Real64 Pipe_h_comp_in;                 // Piping Loss Algorithm Parameter: Enthalpy after piping loss (compressor inlet) [kJ/kg]
   14487              :     Real64 Q_evap_req;                     // Required evaporative capacity [W]
   14488              :     Real64 RefTSat;                        // Saturated temperature of the refrigerant [C]
   14489              :     Real64 RefPLow;                        // Low Pressure Value for Ps (>0.0) [Pa]
   14490              :     Real64 RefPHigh;                       // High Pressure Value for Ps (max in tables) [Pa]
   14491        26940 :     Real64 constexpr Tolerance(0.05);      // Tolerance for condensing temperature calculation [C}
   14492        26940 :     Array1D<Real64> CompEvaporatingPWRSpd; // Array for the compressor power at certain speed [W]
   14493        26940 :     Array1D<Real64> CompEvaporatingCAPSpd; // Array for the evaporating capacity at certain speed [W]
   14494              : 
   14495              :     static constexpr std::string_view RoutineName("VRFOU_CalcCompH");
   14496              : 
   14497              :     // variable initializations
   14498        26940 :     NumOfCompSpdInput = this->CompressorSpeed.size();
   14499        26940 :     CompEvaporatingPWRSpd.dimension(NumOfCompSpdInput);
   14500        26940 :     CompEvaporatingCAPSpd.dimension(NumOfCompSpdInput);
   14501        26940 :     Q_evap_req = TU_load + Pipe_Q - Ncomp;
   14502              : 
   14503        26940 :     TUListNum = this->ZoneTUListPtr;
   14504        26940 :     RefPLow = this->refrig->PsLowPresValue;
   14505        26940 :     RefPHigh = this->refrig->PsHighPresValue;
   14506        26940 :     NumTUInList = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList;
   14507              : 
   14508              :     // Calculate capacity modification factor
   14509        26940 :     MinOutdoorUnitPe = this->refrig->getSatPressure(state, T_suction, RoutineName);
   14510        26940 :     RefTSat = this->refrig->getSatTemperature(state, max(min(MinOutdoorUnitPe, RefPHigh), RefPLow), RoutineName);
   14511              :     Pipe_h_comp_in =
   14512        26940 :         this->refrig->getSupHeatEnthalpy(state, max(RefTSat, T_suction + this->SH), max(min(MinOutdoorUnitPe, RefPHigh), RefPLow), RoutineName);
   14513        26940 :     C_cap_operation = this->VRFOU_CapModFactor(
   14514        26940 :         state, Pipe_h_comp_in, Pipe_h_out_ave, max(min(MinOutdoorUnitPe, RefPHigh), RefPLow), T_suction + this->SH, T_suction + 8, IUMaxCondTemp - 5);
   14515              : 
   14516              :     // Perform iterations to find the compressor speed that can meet the required heating load, Iteration DoName2
   14517        46917 :     for (CounterCompSpdTemp = 1; CounterCompSpdTemp <= NumOfCompSpdInput; CounterCompSpdTemp++) {
   14518              : 
   14519        93834 :         CompEvaporatingPWRSpd(CounterCompSpdTemp) =
   14520        46917 :             this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(CounterCompSpdTemp), T_discharge, T_suction);
   14521        93834 :         CompEvaporatingCAPSpd(CounterCompSpdTemp) =
   14522        46917 :             this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(CounterCompSpdTemp), T_discharge, T_suction);
   14523              : 
   14524        46917 :         if ((Q_evap_req * C_cap_operation) <= CompEvaporatingCAPSpd(CounterCompSpdTemp)) {
   14525              :             // Compressor Capacity is greater than the required, finish Iteration DoName2
   14526              : 
   14527        26940 :             if (CounterCompSpdTemp > 1) {
   14528              :                 // Compressor runs at higher speed than min speed
   14529         9994 :                 CompSpdLB = CounterCompSpdTemp - 1;
   14530         9994 :                 CompSpdUB = CounterCompSpdTemp;
   14531              : 
   14532         9994 :                 CompSpdActual = this->CompressorSpeed(CompSpdLB) + (this->CompressorSpeed(CompSpdUB) - this->CompressorSpeed(CompSpdLB)) /
   14533         9994 :                                                                        (CompEvaporatingCAPSpd(CompSpdUB) - CompEvaporatingCAPSpd(CompSpdLB)) *
   14534         9994 :                                                                        (Q_evap_req * C_cap_operation - CompEvaporatingCAPSpd(CompSpdLB));
   14535         9994 :                 Modifi_SH = this->SH;
   14536         9994 :                 Ncomp = CompEvaporatingPWRSpd(CompSpdLB) + (CompEvaporatingPWRSpd(CompSpdUB) - CompEvaporatingPWRSpd(CompSpdLB)) /
   14537         9994 :                                                                (this->CompressorSpeed(CompSpdUB) - this->CompressorSpeed(CompSpdLB)) *
   14538         9994 :                                                                (CompSpdActual - this->CompressorSpeed(CompSpdLB));
   14539              : 
   14540         9994 :                 break; // EXIT DoName2
   14541              : 
   14542              :             } else {
   14543              :                 // Compressor runs at the min speed
   14544              :                 // Low Load Modifications
   14545              : 
   14546        16946 :                 NumIteCcap = 1;
   14547              :                 bool converged_19;
   14548              :                 // triggered in VariableRefrigerantFlow_FluidTCtrl_HR_5Zone.idf
   14549              :                 do {
   14550       505016 :                     Q_evap_req = max(0.0, TU_load + Pipe_Q - Ncomp);
   14551              : 
   14552              :                     // Update Te'( SmallLoadTe ) to meet the required evaporator capacity
   14553       505016 :                     CompSpdActual = this->CompressorSpeed(1);
   14554       505016 :                     Real64 CondHeat = Q_evap_req * C_cap_operation / this->RatedEvapCapacity;
   14555       505016 :                     int CAPFT = this->OUCoolingCAPFT(CounterCompSpdTemp);
   14556              : 
   14557      1010356 :                     auto f = [&state, T_discharge, CondHeat, CAPFT](Real64 const T_suc) {
   14558      1010356 :                         return CompResidual_FluidTCtrl(state, T_discharge, CondHeat, CAPFT, T_suc);
   14559       505016 :                     };
   14560       505016 :                     General::SolveRoot(state, 1.0e-3, MaxIter, SolFla, SmallLoadTe, f, MinOutdoorUnitTe, T_suction);
   14561       505016 :                     if (SolFla < 0) {
   14562       504900 :                         SmallLoadTe = MinOutdoorUnitTe;
   14563              :                     }
   14564              : 
   14565       505016 :                     T_suction = SmallLoadTe;
   14566              : 
   14567              :                     // Update SH and Pe to calculate Modification Factor, which is used to update rps to for N_comp calculations
   14568       505016 :                     if (this->C3Te == 0) {
   14569            0 :                         Modifi_SH = -(this->C1Te - Tfs + T_suction) / this->C2Te;
   14570              :                     } else {
   14571       505016 :                         if ((pow_2(this->C2Te) - 4 * (this->C1Te - Tfs + T_suction) * this->C3Te) < 0.0) {
   14572            0 :                             Modifi_SH = this->C2Te / (-2 * (this->C1Te - Tfs + T_suction));
   14573              :                         } else {
   14574       505016 :                             Modifi_SH = (-this->C2Te + std::pow((pow_2(this->C2Te) - 4 * (this->C1Te - Tfs + T_suction) * this->C3Te), 0.5)) /
   14575       505016 :                                         (2 * this->C3Te);
   14576              :                         }
   14577              :                     }
   14578              : 
   14579       505016 :                     Modifi_Pe = this->refrig->getSatPressure(state, T_suction, RoutineName);
   14580              : 
   14581              :                     // Calculate capacity modification factor
   14582       505016 :                     RefTSat = this->refrig->getSatTemperature(state, max(min(Modifi_Pe, RefPHigh), RefPLow), RoutineName);
   14583       505016 :                     Pipe_h_comp_in = this->refrig->getSupHeatEnthalpy(
   14584              :                         state, max(RefTSat, T_suction + Modifi_SH), max(min(Modifi_Pe, RefPHigh), RefPLow), RoutineName);
   14585       505016 :                     C_cap_operation = this->VRFOU_CapModFactor(state,
   14586              :                                                                Pipe_h_comp_in,
   14587              :                                                                Pipe_h_out_ave,
   14588              :                                                                max(min(Modifi_Pe, RefPHigh), RefPLow),
   14589              :                                                                T_suction + Modifi_SH,
   14590              :                                                                T_suction + 8,
   14591              :                                                                IUMaxCondTemp - 5);
   14592              : 
   14593       505016 :                     Cap_Eva0 = Q_evap_req * C_cap_operation;
   14594      1010032 :                     Cap_Eva1 = this->CoffEvapCap * this->RatedEvapCapacity *
   14595       505016 :                                CurveValue(state, this->OUCoolingCAPFT(CounterCompSpdTemp), T_discharge, T_suction);
   14596       505016 :                     CapDiff = std::abs(Cap_Eva1 - Cap_Eva0);
   14597       505016 :                     converged_19 = (CapDiff <= (Tolerance * Cap_Eva0)) || (NumIteCcap >= 30);
   14598       505016 :                     NumIteCcap = NumIteCcap + 1;
   14599       505016 :                 } while (!converged_19);
   14600        16946 :                 if (CapDiff > (Tolerance * Cap_Eva0) && (Cap_Eva1 - Cap_Eva0) >= 0.0) {
   14601        16830 :                     NumIteCcap = 999;
   14602        16830 :                     CyclingRatio = Cap_Eva0 / Cap_Eva1;
   14603              :                 } else {
   14604          116 :                     CyclingRatio = 1.0;
   14605              :                 }
   14606              : 
   14607        16946 :                 Ncomp = this->RatedCompPower * CurveValue(state, this->OUCoolingPWRFT(CounterCompSpdTemp), T_discharge, T_suction) * CyclingRatio;
   14608              :                 // Cap_Eva1 is the updated compressor min speed capacity
   14609        16946 :                 OUEvapHeatExtract = Cap_Eva1;
   14610        16946 :                 this->EvaporatingTemp = T_suction;
   14611        16946 :                 this->CondensingTemp = T_discharge;
   14612        16946 :                 this->IUCondensingTemp = T_discharge;
   14613        16946 :                 break; // EXIT DoName2
   14614              : 
   14615              :             } // End: if( CounterCompSpdTemp <= 1 ) Low load modification
   14616              : 
   14617              :         } // End: if( Q_evap_req <= CompEvaporatingCAPSpd( CounterCompSpdTemp ) )
   14618              : 
   14619              :     } // End: Iteration DoName2
   14620              : 
   14621        26940 :     if (CounterCompSpdTemp > NumOfCompSpdInput) {
   14622              :         // Required heating load is beyond the maximum system capacity
   14623            0 :         CompEvaporatingCAPSpd(NumOfCompSpdInput) =
   14624            0 :             this->CoffEvapCap * this->RatedEvapCapacity * CurveValue(state, this->OUCoolingCAPFT(NumOfCompSpdInput), T_discharge, T_suction);
   14625            0 :         OUEvapHeatExtract = CompEvaporatingCAPSpd(NumOfCompSpdInput);
   14626            0 :         CompSpdActual = this->CompressorSpeed(NumOfCompSpdInput);
   14627            0 :         Ncomp = CompEvaporatingPWRSpd(NumOfCompSpdInput);
   14628              :     }
   14629        26940 : }
   14630              : 
   14631            0 : void VRFCondenserEquipment::VRFHR_OU_HR_Mode(EnergyPlusData &state,
   14632              :                                              Real64 const h_IU_evap_in, // enthalpy of IU evaporator at inlet [kJ/kg]
   14633              :                                              Real64 const h_comp_out,   // enthalpy of refrigerant at compressor outlet [kJ/kg]
   14634              :                                              Real64 const Q_c_TU_PL,    // IU evaporator load, including piping loss [W]
   14635              :                                              Real64 const Q_h_TU_PL,    // IU condenser load, including piping loss [W]
   14636              :                                              Real64 const Tdischarge,   // VRF Compressor discharge refrigerant temperature [C]
   14637              :                                              Real64 &Tsuction,          // VRF compressor suction refrigerant temperature [C]
   14638              :                                              Real64 &Te_update,         // updated evaporating temperature, only updated when Tsuction is updated [C]
   14639              :                                              Real64 &h_comp_in,         // enthalpy of refrigerant at compressor inlet [kJ/kg]
   14640              :                                              Real64 &h_IU_PLc_out,  // enthalpy of refrigerant at the outlet of IU evaporator side main pipe [kJ/kg]
   14641              :                                              Real64 &Pipe_Q_c,      // IU evaporator side piping loss [W]
   14642              :                                              Real64 &Q_c_OU,        // OU evaporator load [W]
   14643              :                                              Real64 &Q_h_OU,        // OU condenser load [W]
   14644              :                                              Real64 &m_ref_IU_evap, // mass flow rate of Refrigerant through IU evaporators [kg/s]
   14645              :                                              Real64 &m_ref_OU_evap, // mass flow rate of Refrigerant through OU evaporator [kg/s]
   14646              :                                              Real64 &m_ref_OU_cond, // mass flow rate of Refrigerant through OU condenser [kg/s]
   14647              :                                              Real64 &N_fan_OU,      // outdoor unit fan power [W]
   14648              :                                              Real64 &CompSpdActual, // Actual compressor running speed [rps]
   14649              :                                              Real64 &Ncomp          // compressor power [W]
   14650              : )
   14651              : {
   14652              : 
   14653              :     // SUBROUTINE INFORMATION:
   14654              :     //       AUTHOR         Rongpeng Zhang, LBNL
   14655              :     //       DATE WRITTEN   Jan 2016
   14656              :     //       MODIFIED       na
   14657              :     //
   14658              :     //       RE-ENGINEERED  na
   14659              :     //
   14660              :     // PURPOSE OF THIS SUBROUTINE:
   14661              :     //        Determine the operational mode of the VRF-HR system, given the terminal unit side load conditions.
   14662              :     //        Compressor and OU hex performance are analyzed for each mode.
   14663              :     //        A number of OU side operational parameters are also calculated here, including:
   14664              :     //        (1) OU evaporator load Q_c_OU (2) OU condenser load Q_h_OU (3) OU fan energy consumption
   14665              :     //        (4) OU compressor speed and energy consumption
   14666              :     //        Note that Te and Te' may be updated here, and thus IU evaporator side piping loss recalculations.
   14667              :     //        Then a number of operational parameters need to be updated, including:
   14668              :     //        (1) IU evaporating temperature Te (2) OU evaporating temperature Te' etc.
   14669              :     //
   14670              :     // METHODOLOGY EMPLOYED:
   14671              :     //        This is part of the physics based VRF model applicable for Fluid Temperature Control.
   14672              : 
   14673              :     using General::SolveRoot;
   14674              : 
   14675            0 :     Real64 constexpr ErrorTol(0.1); // tolerance for RegulaFalsi iterations
   14676            0 :     int constexpr MaxIte(100);      // maximum number of iterations
   14677            0 :     int HRMode(0);                  // HR operational mode [W]
   14678            0 :     int HRMode_sub(0);              // HR operational mode (sub) [W]
   14679              :     int SolFla;                     // Flag of RegulaFalsi solver
   14680              :     Real64 C_OU_HexRatio;           // capacity ratio between the OU condenser and OU evaporator [-]
   14681              :     Real64 m_air_rated;             // OU coil air mass flow rate [kg/s]
   14682              :     Real64 m_air_evap;              // OU evaporator air mass flow rate [kg/s]
   14683              :     Real64 m_air_cond;              // OU condenser air mass flow rate [kg/s]
   14684              :     Real64 m_air_evap_rated;        // Rated OU evaporator air mass flow rate [kg/s]
   14685            0 :     Real64 N_fan_OU_evap(0);        // OU evaporator air mass flow rate [kg/s]
   14686            0 :     Real64 N_fan_OU_cond(0);        // OU condenser air mass flow rate [kg/s]
   14687              :     Real64 RhoAir;                  // outdoor air density [kg/m3]
   14688              :     Real64 Q_c_tot;                 // Total evaporator capacity [W]
   14689              :     Real64 Q_h_tot;                 // Total condenser capacity [W]
   14690              :     Real64 Pipe_Q_c_new;            // IU evaporator side piping loss (new), updated because of Te update [W]
   14691              :     Real64 rps1_evap;               // compressor speed satisfying IU cooling load
   14692              :     Real64 rps2_cond;               // compressor speed satisfying IU heating load
   14693              :     Real64 RefPLow;                 // Low Pressure Value for Ps (>0.0) [Pa]
   14694              :     Real64 RefPHigh;                // High Pressure Value for Ps (max in tables) [Pa]
   14695              :     Real64 Tfs;                     // temperature of the air at coil surface [C]
   14696            0 :     Real64 Tolerance(0.05);         // Tolerance for condensing temperature calculation [C}
   14697              :     Real64 Tsuction_new;            // VRF compressor suction refrigerant temperature (new) [C]
   14698              : 
   14699              :     // SUBROUTINE LOCAL VARIABLE DECLARATIONS:
   14700              :     static constexpr std::string_view RoutineName("VRFHR_OU_Mode");
   14701              : 
   14702              :     // Initialization: operational parameters
   14703            0 :     RhoAir = PsyRhoAirFnPbTdbW(state, state.dataEnvrn->OutBaroPress, state.dataEnvrn->OutDryBulbTemp, state.dataEnvrn->OutHumRat);
   14704            0 :     m_air_rated = this->OUAirFlowRate * RhoAir;
   14705            0 :     C_OU_HexRatio = this->HROUHexRatio;
   14706              : 
   14707              :     // Initializations: component index
   14708            0 :     RefPLow = this->refrig->PsLowPresValue;
   14709            0 :     RefPHigh = this->refrig->PsHighPresValue;
   14710              : 
   14711              :     // **Q_OU: HR mode determination
   14712              :     //     HRMode-1. Cooling Only
   14713              :     //     HRMode-2. Cooling Dominant w/o HR Loss
   14714              :     //     HRMode-3. Cooling Dominant w/ HR Loss
   14715              :     //     HRMode-4. Heating Dominant w/ HR Loss
   14716              :     //     HRMode-5. Heating Dominant w/o HR Loss
   14717              :     //     HRMode-6. Heating Only
   14718              :     //     HRMode-7. OU Hex not running
   14719              :     {
   14720              : 
   14721              :         bool FlagMode5;   // true if compressor speed satisfying IU cooling load < that satisfying IU heating load
   14722              :         bool FlagToLower; // true if To-5 is lower than the Tsuction determined by IU part
   14723              :         Real64 temp_Tsuction;
   14724              : 
   14725              :         // Determine FlagToLower
   14726            0 :         if (state.dataEnvrn->OutDryBulbTemp - this->DiffOUTeTo < Tsuction) {
   14727            0 :             temp_Tsuction = state.dataEnvrn->OutDryBulbTemp - this->DiffOUTeTo;
   14728            0 :             FlagToLower = true;
   14729              :         } else {
   14730            0 :             temp_Tsuction = Tsuction;
   14731            0 :             FlagToLower = false;
   14732              :         }
   14733              : 
   14734              :         // Calculate compressor speed satisfying IU loads: rps1_evap & rps2_cond
   14735            0 :         this->VRFOU_CompSpd(state, Q_c_TU_PL, HXOpMode::EvapMode, temp_Tsuction, Tdischarge, h_IU_evap_in, h_IU_PLc_out, rps1_evap);
   14736            0 :         this->VRFOU_CompSpd(state, Q_h_TU_PL, HXOpMode::CondMode, temp_Tsuction, Tdischarge, h_IU_evap_in, h_IU_PLc_out, rps2_cond);
   14737              : 
   14738              :         // Determine FlagMode5
   14739            0 :         if (rps1_evap <= rps2_cond) {
   14740            0 :             FlagMode5 = true;
   14741              :         } else {
   14742            0 :             FlagMode5 = false;
   14743              :         }
   14744              : 
   14745              :         // Determine HR Mode
   14746            0 :         if (FlagMode5) {
   14747            0 :             HRMode = 5;
   14748            0 :             if (FlagToLower) {
   14749            0 :                 HRMode_sub = 1;
   14750              :             } else {
   14751            0 :                 HRMode_sub = 2;
   14752              :             }
   14753              :         } else {
   14754              : 
   14755            0 :             if (FlagToLower) {
   14756            0 :                 HRMode = 3; // Mode 3&4 share the same logics below
   14757              :             } else {
   14758            0 :                 HRMode = 2;
   14759              :             }
   14760              :         }
   14761              : 
   14762            0 :         this->VRFOperationSimPath = HRMode * 10 + HRMode_sub;
   14763              :     }
   14764              : 
   14765              :     // **Simulate outdoor unit and compressor performance, including
   14766              :     // (1) compressor spd/power (2) OU hex capacity (3) OU fan flow rate and power
   14767              :     // Tsuction/Te may also need updates
   14768            0 :     if (HRMode == 5 && HRMode_sub == 2) {
   14769              : 
   14770            0 :         CompSpdActual = rps2_cond; // constant in this mode
   14771              :         // Tsuction = Te'_iu < OutDryBulbTemp - 5; constant in this mode
   14772              : 
   14773              :         // compressor: Ncomp & Q_c_tot
   14774            0 :         this->VRFOU_CompCap(state, CompSpdActual, Tsuction, Tdischarge, h_IU_evap_in, h_comp_in, Q_c_tot, Ncomp);
   14775              : 
   14776              :         // OU hex capacity
   14777            0 :         Q_c_OU = Q_c_tot - Q_c_TU_PL;
   14778            0 :         Q_h_OU = 0;
   14779              : 
   14780              :         // OU fan flow rate and power
   14781              :         m_air_evap =
   14782            0 :             this->VRFOU_FlowRate(state, HXOpMode::EvapMode, Tsuction, this->SH, Q_c_OU, state.dataEnvrn->OutDryBulbTemp, state.dataEnvrn->OutHumRat);
   14783            0 :         m_air_evap_rated = m_air_rated;
   14784            0 :         N_fan_OU_evap = this->RatedOUFanPower * m_air_evap / m_air_evap_rated;
   14785            0 :         N_fan_OU_cond = 0;
   14786              : 
   14787            0 :     } else if (HRMode == 5 && HRMode_sub == 1) {
   14788              : 
   14789              :         // local parameters
   14790              :         int Counter_Iter_Ncomp;
   14791            0 :         bool Flag_Iter_Ncomp(true); // Flag to perform iterations
   14792              :         Real64 Ncomp_ini;
   14793              :         Real64 Ncomp_new;
   14794              :         Real64 Q_c_tot_temp;
   14795              :         Real64 Q_c_OU_temp;
   14796              : 
   14797              :         //===**Ncomp Iterations
   14798              : 
   14799              :         // initialization: Ncomp_ini, CompSpdActual
   14800            0 :         Counter_Iter_Ncomp = 1;
   14801            0 :         CompSpdActual = rps2_cond;
   14802            0 :         Tsuction_new = state.dataEnvrn->OutDryBulbTemp - this->DiffOUTeTo;
   14803            0 :         Pipe_Q_c_new = Pipe_Q_c;
   14804              : 
   14805            0 :         this->VRFOU_CompCap(state, CompSpdActual, Tsuction_new, Tdischarge, h_IU_evap_in, h_comp_in, Q_c_tot, Ncomp_ini);
   14806              : 
   14807            0 :         while (Flag_Iter_Ncomp) {
   14808              : 
   14809            0 :             Q_c_tot_temp = Q_h_TU_PL - Ncomp_ini; // Q_h_OU = 0
   14810            0 :             Q_c_OU_temp = Q_c_tot_temp - Q_c_TU_PL;
   14811              : 
   14812              :             // Tsuction_new updated based on OU evaporator air-side calculations (Tsuction_new < To)
   14813            0 :             m_air_evap_rated = m_air_rated;
   14814            0 :             this->VRFOU_TeTc(state,
   14815              :                              HXOpMode::EvapMode,
   14816              :                              Q_c_OU_temp,
   14817              :                              this->SH,
   14818              :                              m_air_evap_rated,
   14819            0 :                              state.dataEnvrn->OutDryBulbTemp,
   14820            0 :                              state.dataEnvrn->OutHumRat,
   14821            0 :                              state.dataEnvrn->OutBaroPress,
   14822              :                              Tfs,
   14823              :                              Tsuction_new);
   14824            0 :             Tsuction_new = min(Tsuction_new, Tsuction); // should be lower than Tsuction_IU
   14825              : 
   14826              :             // Calculate updated rps corresponding to updated Tsuction_new and Q_c_tot_temp
   14827            0 :             this->VRFOU_CompSpd(state, Q_c_tot_temp, HXOpMode::EvapMode, Tsuction_new, Tdischarge, h_IU_evap_in, h_comp_in, CompSpdActual);
   14828              : 
   14829              :             // Calculate Ncomp_new, using updated CompSpdActual and Tsuction_new
   14830            0 :             this->VRFOU_CompCap(state, CompSpdActual, Tsuction_new, Tdischarge, h_IU_evap_in, h_comp_in, Q_c_tot_temp, Ncomp_new);
   14831              : 
   14832            0 :             if ((std::abs(Ncomp_new - Ncomp_ini) > (Tolerance * Ncomp_ini)) && (Counter_Iter_Ncomp < 30)) {
   14833            0 :                 Ncomp_ini = 0.5 * Ncomp_ini + 0.5 * Ncomp_new;
   14834            0 :                 Counter_Iter_Ncomp = Counter_Iter_Ncomp + 1;
   14835            0 :                 continue;
   14836              :             }
   14837              : 
   14838            0 :             Flag_Iter_Ncomp = false;
   14839              :         }
   14840              : 
   14841              :         // Ncomp Iterations Update
   14842            0 :         Ncomp = Ncomp_new;
   14843            0 :         Q_c_tot = Q_c_tot_temp;
   14844              : 
   14845            0 :         if (Tsuction_new < Tsuction) {
   14846              :             // Need to update the Tsuction, and thus update Te_update & Pipe_Q_c_new.
   14847              :             // Iteration continues.
   14848              : 
   14849              :             // temporary parameters
   14850              :             Real64 Pe_update;
   14851              :             Real64 Pipe_SH_merged;
   14852              :             Real64 Pipe_DeltP;
   14853              :             Real64 Pipe_h_IU_out;
   14854              : 
   14855              :             // Get an updated Te (Te_update) corresponding to the updated Te' (Tsuction_new). PL_c is re-performed.
   14856            0 :             this->VRFOU_TeModification(state,
   14857              :                                        this->EvaporatingTemp,
   14858              :                                        Tsuction_new,
   14859              :                                        h_IU_evap_in,
   14860            0 :                                        state.dataEnvrn->OutDryBulbTemp,
   14861              :                                        Te_update,
   14862              :                                        Pe_update,
   14863              :                                        m_ref_IU_evap,
   14864              :                                        Pipe_h_IU_out,
   14865              :                                        Pipe_SH_merged);
   14866              : 
   14867              :             // Re-calculate piping loss, update Pipe_Q_c_new
   14868            0 :             this->VRFOU_PipeLossC(state,
   14869              :                                   m_ref_IU_evap,
   14870              :                                   Pe_update,
   14871              :                                   Pipe_h_IU_out,
   14872              :                                   Pipe_SH_merged,
   14873            0 :                                   state.dataEnvrn->OutDryBulbTemp,
   14874              :                                   Pipe_Q_c_new,
   14875              :                                   Pipe_DeltP,
   14876              :                                   h_IU_PLc_out);
   14877              : 
   14878            0 :             Tsuction = Tsuction_new;
   14879            0 :             Pipe_Q_c = Pipe_Q_c_new;
   14880              :         }
   14881              : 
   14882              :         // No need to update the Tsuction.
   14883              : 
   14884              :         //===**Ncomp Iteration Ends (Label200)
   14885              : 
   14886              :         // OU hex capacity
   14887            0 :         Q_c_OU = Q_c_tot - Q_c_TU_PL;
   14888            0 :         Q_h_OU = 0;
   14889              : 
   14890              :         // OU fan power
   14891            0 :         N_fan_OU_evap = this->RatedOUFanPower;
   14892            0 :         N_fan_OU_cond = 0;
   14893              : 
   14894            0 :     } else if (HRMode == 3) { // Mode3 & Mode4 share the same algorithm
   14895              : 
   14896              :         // local parameters
   14897              :         Real64 Ncomp_new;
   14898              :         Real64 Q_c_tot_temp;
   14899              :         Real64 Q_c_OU_temp;
   14900            0 :         Real64 Tsuction_LB = state.dataEnvrn->OutDryBulbTemp - this->DiffOUTeTo;
   14901            0 :         Real64 Tsuction_HB = Tsuction;
   14902              : 
   14903              :         // compressor speed is fixed in this mode
   14904            0 :         CompSpdActual = rps1_evap; // constant in this mode
   14905            0 :         m_air_evap_rated = m_air_rated * (1 - C_OU_HexRatio);
   14906            0 :         m_air_evap = m_air_evap_rated; // may be updated
   14907              : 
   14908              :         // perform iterations to calculate Te at the given compressor speed and operational conditions
   14909              :         {
   14910              : 
   14911            0 :             auto f = [&state, this, CompSpdActual, Tdischarge, h_IU_evap_in, h_comp_in, Q_c_TU_PL, m_air_evap_rated](Real64 const Te) {
   14912            0 :                 int VRFCond = state.dataHVACVarRefFlow->VRFTU(state.dataHVACVarRefFlow->TerminalUnitList(this->ZoneTUListPtr).ZoneTUPtr(1))
   14913            0 :                                   .VRFSysNum; // VRFCond;
   14914              : 
   14915              :                 Real64 Ncomp_temp;   // compressor power [W]
   14916              :                 Real64 Q_c_tot_temp; // total evaporator load, including piping loss [W]
   14917              :                 Real64 Q_c_OU_temp;  // OU evaporator load, including piping loss [W]
   14918              :                 Real64 Te_new;       // newly calculated OU evaporating temperature
   14919              :                 Real64 Tfs;          // OU evaporator coil surface temperature [C]
   14920              : 
   14921            0 :                 state.dataHVACVarRefFlow->VRF(VRFCond).VRFOU_CompCap(
   14922              :                     state, CompSpdActual, Te, Tdischarge, h_IU_evap_in, h_comp_in, Q_c_tot_temp, Ncomp_temp);
   14923            0 :                 Q_c_OU_temp = Q_c_tot_temp - Q_c_TU_PL;
   14924              : 
   14925              :                 // Tsuction_new calculated based on OU evaporator air-side calculations (Tsuction_new < To)
   14926            0 :                 state.dataHVACVarRefFlow->VRF(VRFCond).VRFOU_TeTc(state,
   14927              :                                                                   HXOpMode::EvapMode,
   14928              :                                                                   Q_c_OU_temp,
   14929            0 :                                                                   state.dataHVACVarRefFlow->VRF(VRFCond).SH,
   14930              :                                                                   m_air_evap_rated,
   14931            0 :                                                                   state.dataEnvrn->OutDryBulbTemp,
   14932            0 :                                                                   state.dataEnvrn->OutHumRat,
   14933            0 :                                                                   state.dataEnvrn->OutBaroPress,
   14934              :                                                                   Tfs,
   14935              :                                                                   Te_new);
   14936              : 
   14937            0 :                 return Te_new - Te;
   14938            0 :             };
   14939              : 
   14940            0 :             General::SolveRoot(state, ErrorTol, MaxIte, SolFla, Tsuction_new, f, Tsuction_LB, Tsuction_HB);
   14941            0 :             if (SolFla < 0) {
   14942            0 :                 Tsuction_new = Tsuction_LB;
   14943              :             }
   14944              : 
   14945              :             // Update Q_c_tot_temp using updated Tsuction_new
   14946            0 :             this->VRFOU_CompCap(state, CompSpdActual, Tsuction_new, Tdischarge, h_IU_evap_in, h_comp_in, Q_c_tot_temp, Ncomp_new);
   14947            0 :             Q_c_OU_temp = Q_c_tot_temp - Q_c_TU_PL;
   14948              : 
   14949              :             // Iterations_Te Update
   14950            0 :             Ncomp = Ncomp_new;
   14951            0 :             Tsuction = Tsuction_new;
   14952            0 :             Q_c_tot = Q_c_tot_temp;
   14953            0 :             Q_c_OU = Q_c_OU_temp;
   14954              :         }
   14955              : 
   14956            0 :         if (Tsuction >= Tsuction_HB) {
   14957              :             // modify m_air_evap to adjust OU evaporator capacity;
   14958              :             // update Ncomp, Q_c_OU, m_air_evap
   14959              : 
   14960            0 :             Tsuction = Tsuction_HB;
   14961              : 
   14962              :             // Q_c_tot
   14963            0 :             this->VRFOU_CompCap(state, CompSpdActual, Tsuction_new, Tdischarge, h_IU_evap_in, h_comp_in, Q_c_tot, Ncomp);
   14964            0 :             Q_c_OU = Q_c_tot - Q_c_TU_PL;
   14965              : 
   14966              :             // OU evaporator fan flow rate and power
   14967            0 :             m_air_evap = this->VRFOU_FlowRate(
   14968            0 :                 state, HXOpMode::EvapMode, Tsuction, this->SH, Q_c_OU_temp, state.dataEnvrn->OutDryBulbTemp, state.dataEnvrn->OutHumRat);
   14969              : 
   14970              :         } else {
   14971              :             // Need to update Te_update & Pipe_Q_c_new, corresponding to Tsuction update.
   14972              : 
   14973              :             // temporary parameters
   14974              :             Real64 Pe_update;
   14975              :             Real64 Pipe_SH_merged;
   14976              :             Real64 Pipe_DeltP;
   14977              :             Real64 Pipe_h_IU_out;
   14978              : 
   14979              :             // Get an updated Te (Te_update) corresponding to the updated Te' (Tsuction_new). PL_c is re-performed.
   14980            0 :             this->VRFOU_TeModification(state,
   14981              :                                        this->EvaporatingTemp,
   14982              :                                        Tsuction_new,
   14983              :                                        h_IU_evap_in,
   14984            0 :                                        state.dataEnvrn->OutDryBulbTemp,
   14985              :                                        Te_update,
   14986              :                                        Pe_update,
   14987              :                                        m_ref_IU_evap,
   14988              :                                        Pipe_h_IU_out,
   14989              :                                        Pipe_SH_merged);
   14990              : 
   14991              :             // Re-calculate piping loss, update Pipe_Q_c_new
   14992            0 :             this->VRFOU_PipeLossC(state,
   14993              :                                   m_ref_IU_evap,
   14994              :                                   Pe_update,
   14995              :                                   Pipe_h_IU_out,
   14996              :                                   Pipe_SH_merged,
   14997            0 :                                   state.dataEnvrn->OutDryBulbTemp,
   14998              :                                   Pipe_Q_c_new,
   14999              :                                   Pipe_DeltP,
   15000              :                                   h_IU_PLc_out);
   15001            0 :             Pipe_Q_c = Pipe_Q_c_new;
   15002              :         }
   15003              : 
   15004              :         // Q_h_ou
   15005            0 :         Q_h_tot = Q_c_tot + Ncomp;
   15006            0 :         Q_h_OU = Q_h_tot - Q_h_TU_PL;
   15007              : 
   15008              :         // OU condenser fan flow rate and power
   15009            0 :         m_air_cond = this->VRFOU_FlowRate(
   15010            0 :             state, HXOpMode::CondMode, Tdischarge, this->SC, Q_h_OU, state.dataEnvrn->OutDryBulbTemp, state.dataEnvrn->OutHumRat);
   15011              : 
   15012              :         // OU fan power
   15013            0 :         N_fan_OU_evap = this->RatedOUFanPower * m_air_evap / m_air_rated;
   15014            0 :         N_fan_OU_cond = this->RatedOUFanPower * m_air_cond / m_air_rated;
   15015              : 
   15016            0 :     } else if (HRMode == 2) {
   15017              : 
   15018            0 :         CompSpdActual = rps1_evap; // constant in this mode
   15019              :         // Tsuction = Te'_iu < OutDryBulbTemp - 5; constant in this mode
   15020              : 
   15021              :         // compressor: Ncomp & Q_c_tot
   15022            0 :         this->VRFOU_CompCap(state, CompSpdActual, Tsuction, Tdischarge, h_IU_evap_in, h_comp_in, Q_c_tot, Ncomp);
   15023              : 
   15024              :         // OU hex capacity
   15025            0 :         Q_h_tot = Q_c_tot + Ncomp;
   15026            0 :         Q_h_OU = Q_h_tot - Q_h_TU_PL;
   15027            0 :         Q_c_OU = 0;
   15028              : 
   15029              :         // OU fan flow rate and power
   15030            0 :         m_air_cond = this->VRFOU_FlowRate(
   15031            0 :             state, HXOpMode::CondMode, Tdischarge, this->SC, Q_h_OU, state.dataEnvrn->OutDryBulbTemp, state.dataEnvrn->OutHumRat);
   15032            0 :         N_fan_OU_cond = this->RatedOUFanPower * m_air_cond / m_air_rated;
   15033            0 :         N_fan_OU_evap = 0;
   15034              : 
   15035              :     } else {
   15036            0 :         Ncomp = 0;
   15037            0 :         CompSpdActual = 0;
   15038            0 :         Q_c_OU = 0;
   15039            0 :         Q_h_OU = 0;
   15040            0 :         N_fan_OU_evap = 0;
   15041            0 :         N_fan_OU_cond = 0;
   15042              :     }
   15043              : 
   15044              :     // OU fan power
   15045            0 :     N_fan_OU = N_fan_OU_evap + N_fan_OU_cond;
   15046              : 
   15047              :     // Calculate the m_ref_OU_evap & m_ref_OU_cond, with updated Tsuction
   15048              :     {
   15049              :         Real64 h_OU_evap_in;  // enthalpy of OU evaporator at inlet [kJ/kg]
   15050              :         Real64 h_OU_evap_out; // enthalpy of OU evaporator at outlet [kJ/kg]
   15051              :         Real64 h_OU_cond_in;  // enthalpy of OU condenser at inlet [kJ/kg]
   15052              :         Real64 h_OU_cond_out; // enthalpy of OU condenser at outlet [kJ/kg]
   15053              : 
   15054            0 :         Real64 Psuction = this->refrig->getSatPressure(state, Tsuction, RoutineName);
   15055              : 
   15056              :         // enthalpy of OU evaporator/condenser inlets and outlets
   15057            0 :         h_OU_evap_in = h_IU_evap_in;
   15058            0 :         h_OU_cond_in = h_comp_out;
   15059            0 :         h_OU_evap_out = this->refrig->getSupHeatEnthalpy(state, Tsuction + this->SH, max(min(Psuction, RefPHigh), RefPLow), RoutineName);
   15060            0 :         h_OU_cond_out = this->refrig->getSatEnthalpy(state, Tdischarge - this->SC, 0.0, RoutineName);
   15061              : 
   15062            0 :         if ((Q_c_OU == 0) || (h_OU_evap_out - h_OU_evap_in) <= 0) {
   15063            0 :             m_ref_OU_evap = 0;
   15064              :         } else {
   15065            0 :             m_ref_OU_evap = Q_c_OU / (h_OU_evap_out - h_OU_evap_in);
   15066              :         }
   15067              : 
   15068            0 :         if ((Q_h_OU == 0) || (h_OU_cond_in - h_OU_cond_out <= 0)) {
   15069            0 :             m_ref_OU_cond = 0;
   15070              :         } else {
   15071            0 :             m_ref_OU_cond = Q_h_OU / (h_OU_cond_in - h_OU_cond_out);
   15072              :         }
   15073              : 
   15074              :         // Calculate the parameters of refrigerant at compressor inlet, which is
   15075              :         // a combination of refrigerant from IU evaporators and OU evaporator
   15076            0 :         if ((m_ref_OU_evap + m_ref_IU_evap) > 0) {
   15077            0 :             h_comp_in = (m_ref_OU_evap * h_OU_evap_out + m_ref_IU_evap * h_IU_PLc_out) / (m_ref_OU_evap + m_ref_IU_evap);
   15078              :         }
   15079              :     }
   15080            0 : }
   15081              : 
   15082      1910308 : void VRFCondenserEquipment::VRFOU_PipeLossC(
   15083              :     EnergyPlusData &state,
   15084              :     Real64 const Pipe_m_ref,     // Refrigerant mass flow rate [kg/s]
   15085              :     Real64 const Pevap,          // VRF evaporating pressure [Pa]
   15086              :     Real64 const Pipe_h_IU_out,  // Enthalpy of IU at outlet [kJ/kg]
   15087              :     Real64 const Pipe_SH_merged, // Average super heating degrees after the indoor units [C]
   15088              :     Real64 const OutdoorDryBulb, // outdoor dry-bulb temperature (C)
   15089              :     Real64 &Pipe_Q,              // unit part load ratio
   15090              :     Real64 &Pipe_DeltP,          // ratio of compressor ON airflow to AVERAGE airflow over timestep
   15091              :     Real64 &Pipe_h_comp_in       // Piping Loss Algorithm Parameter: Enthalpy after piping loss (compressor inlet) [kJ/kg]
   15092              : )
   15093              : {
   15094              : 
   15095              :     // SUBROUTINE INFORMATION:
   15096              :     //       AUTHOR         Rongpeng Zhang
   15097              :     //       DATE WRITTEN   Nov 2015
   15098              :     //       MODIFIED       na
   15099              :     //       RE-ENGINEERED  na
   15100              : 
   15101              :     // PURPOSE OF THIS SUBROUTINE:
   15102              :     // Determine the piping loss of the refrigerant, including both the heat loss and pressure drop.
   15103              :     // This happens at VRF cooling mode, within the Main Pipe connecting Outdoor Unit to Indoor Units.
   15104              : 
   15105              :     // METHODOLOGY EMPLOYED:
   15106              :     // Use a physics based piping loss model.
   15107              : 
   15108              :     using General::SolveRoot;
   15109              : 
   15110              :     int TUListNum;      // index to TU List
   15111              :     int NumTUInList;    // number of terminal units is list
   15112              :     int NumIUActivated; // number of the used indoor units [-]
   15113              : 
   15114              :     Real64 Pipe_v_ref;            // Piping Loss Algorithm Parameter: Refrigerant velocity [m/s]
   15115              :     Real64 Pipe_T_room;           // Piping Loss Algorithm Parameter: Average Room Temperature [C]
   15116              :     Real64 Pipe_Num_Re;           // Piping Loss Algorithm Parameter: refrigerant Re Number [-]
   15117              :     Real64 Pipe_Num_Pr;           // Piping Loss Algorithm Parameter: refrigerant Pr Number [-]
   15118              :     Real64 Pipe_Num_Nu;           // Piping Loss Algorithm Parameter: refrigerant Nu Number [-]
   15119              :     Real64 Pipe_Num_St;           // Piping Loss Algorithm Parameter: refrigerant St Number [-]
   15120              :     Real64 Pipe_Coe_k1;           // Piping Loss Algorithm Parameter: coefficients [-]
   15121              :     Real64 Pipe_Coe_k2;           // Piping Loss Algorithm Parameter: coefficients [-]
   15122              :     Real64 Pipe_Coe_k3;           // Piping Loss Algorithm Parameter: coefficients [-]
   15123              :     Real64 Pipe_cp_ref;           // Piping Loss Algorithm_[kJ/kg/K]
   15124              :     Real64 Pipe_conductivity_ref; // Piping Loss Algorithm: refrigerant conductivity [W/m/K]
   15125              :     Real64 Pipe_viscosity_ref;    // Piping Loss Algorithm Parameter: refrigerant viscosity [MuPa*s]
   15126              :     Real64 Ref_Coe_v1;            // Piping Loss Algorithm Parameter: coefficient to calculate Pipe_viscosity_ref [-]
   15127              :     Real64 Ref_Coe_v2;            // Piping Loss Algorithm Parameter: coefficient to calculate Pipe_viscosity_ref [-]
   15128              :     Real64 Ref_Coe_v3;            // Piping Loss Algorithm Parameter: coefficient to calculate Pipe_viscosity_ref [-]
   15129              :     Real64 RefPipInsH;            // Heat transfer coefficient for calculating piping loss [W/m2K]
   15130              : 
   15131              :     static constexpr std::string_view RoutineName("VRFOU_PipeLossC");
   15132              : 
   15133      1910308 :     TUListNum = this->ZoneTUListPtr;
   15134      1910308 :     NumTUInList = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList;
   15135      1910308 :     Pipe_conductivity_ref = this->RefPipInsCon;
   15136              : 
   15137      1910308 :     RefPipInsH = 9.3;
   15138      1910308 :     Pipe_cp_ref = 1.6;
   15139              : 
   15140              :     // Refrigerant data
   15141      1910308 :     Real64 RefPLow = this->refrig->PsLowPresValue;   // Low Pressure Value for Ps (>0.0)
   15142      1910308 :     Real64 RefPHigh = this->refrig->PsHighPresValue; // High Pressure Value for Ps (max in tables)
   15143              : 
   15144              :     // Calculate Pipe_T_room
   15145      1910308 :     Pipe_T_room = 0;
   15146      1910308 :     NumIUActivated = 0;
   15147      9682440 :     for (int NumTU = 1; NumTU <= NumTUInList; ++NumTU) {
   15148      7772132 :         int TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   15149      7772132 :         int CoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).CoolCoilIndex;
   15150              : 
   15151      7772132 :         if (state.dataDXCoils->DXCoil(CoilIndex).TotalCoolingEnergyRate > 0.0) {
   15152      7662416 :             Pipe_T_room = Pipe_T_room + state.dataDXCoils->DXCoil(CoilIndex).InletAirTemp;
   15153      7662416 :             NumIUActivated = NumIUActivated + 1;
   15154              :         }
   15155              :     }
   15156      1910308 :     if (NumIUActivated > 0) {
   15157      1910308 :         Pipe_T_room = Pipe_T_room / NumIUActivated;
   15158              :     } else {
   15159            0 :         Pipe_T_room = 24;
   15160              :     }
   15161              : 
   15162      1910308 :     if (Pipe_m_ref > 0) {
   15163      1910308 :         if (this->RefPipDiaSuc <= 0) {
   15164            0 :             this->RefPipDiaSuc = 0.025;
   15165              :         }
   15166              : 
   15167      1910308 :         Ref_Coe_v1 = Pevap / 1000000 / 4.926;
   15168      1910308 :         Ref_Coe_v2 = Pipe_h_IU_out / 383.5510343;
   15169      1910308 :         Ref_Coe_v3 = (this->EvaporatingTemp + Pipe_SH_merged + 273.15) / 344.39;
   15170              : 
   15171      1910308 :         Pipe_viscosity_ref = 4.302 * Ref_Coe_v1 + 0.81622 * pow_2(Ref_Coe_v1) - 120.98 * Ref_Coe_v2 + 139.17 * pow_2(Ref_Coe_v2) +
   15172      1910308 :                              118.76 * Ref_Coe_v3 + 81.04 * pow_2(Ref_Coe_v3) + 5.7858 * Ref_Coe_v1 * Ref_Coe_v2 - 8.3817 * Ref_Coe_v1 * Ref_Coe_v3 -
   15173      1910308 :                              218.48 * Ref_Coe_v2 * Ref_Coe_v3 + 21.58;
   15174      1910308 :         if (Pipe_viscosity_ref <= 0) {
   15175            0 :             Pipe_viscosity_ref = 16.26; // default superheated vapor viscosity data (MuPa*s) at T=353.15 K, P=2MPa
   15176              :         }
   15177              : 
   15178      1910308 :         Pipe_v_ref = Pipe_m_ref / (Constant::Pi * pow_2(this->RefPipDiaSuc) * 0.25) /
   15179      1910308 :                      this->refrig->getSupHeatDensity(state, this->EvaporatingTemp + Pipe_SH_merged, max(min(Pevap, RefPHigh), RefPLow), RoutineName);
   15180      1910308 :         Pipe_Num_Re = Pipe_m_ref / (Constant::Pi * pow_2(this->RefPipDiaSuc) * 0.25) * this->RefPipDiaSuc / Pipe_viscosity_ref * 1000000;
   15181      1910308 :         Pipe_Num_Pr = Pipe_viscosity_ref * Pipe_cp_ref * 0.001 / Pipe_conductivity_ref;
   15182      1910308 :         Pipe_Num_Nu = 0.023 * std::pow(Pipe_Num_Re, 0.8) * std::pow(Pipe_Num_Pr, 0.3);
   15183      1910308 :         Pipe_Num_St = Pipe_Num_Nu / Pipe_Num_Re / Pipe_Num_Pr;
   15184              : 
   15185      3820616 :         Pipe_DeltP = max(
   15186              :             0.0,
   15187      3820616 :             8 * Pipe_Num_St * std::pow(Pipe_Num_Pr, 0.6667) * this->RefPipEquLen / this->RefPipDiaSuc *
   15188      1910308 :                     this->refrig->getSupHeatDensity(state, this->EvaporatingTemp + Pipe_SH_merged, max(min(Pevap, RefPHigh), RefPLow), RoutineName) *
   15189      1910308 :                     pow_2(Pipe_v_ref) / 2 -
   15190      3820616 :                 this->RefPipHei *
   15191      1910308 :                     this->refrig->getSupHeatDensity(state, this->EvaporatingTemp + Pipe_SH_merged, max(min(Pevap, RefPHigh), RefPLow), RoutineName) *
   15192              :                     9.80665);
   15193              : 
   15194      1910308 :         Pipe_Coe_k1 = Pipe_Num_Nu * Pipe_viscosity_ref;
   15195      1910308 :         Pipe_Coe_k3 = RefPipInsH * (this->RefPipDiaSuc + 2 * this->RefPipInsThi);
   15196      1910308 :         if (this->RefPipInsThi >= 0.0) {
   15197      1910308 :             Pipe_Coe_k2 = 2 * this->RefPipInsCon / std::log1p(2 * this->RefPipInsThi / this->RefPipDiaSuc);
   15198              :         } else {
   15199            0 :             Pipe_Coe_k2 = 9999.9;
   15200              :         }
   15201              : 
   15202      3820616 :         Pipe_Q = max(0.0,
   15203      1910308 :                      (Constant::Pi * this->RefPipLen) * (OutdoorDryBulb / 2 + Pipe_T_room / 2 - this->EvaporatingTemp - Pipe_SH_merged) /
   15204      1910308 :                          (1 / Pipe_Coe_k1 + 1 / Pipe_Coe_k2 + 1 / Pipe_Coe_k3));
   15205              : 
   15206      1910308 :         Pipe_h_comp_in = Pipe_h_IU_out + Pipe_Q / Pipe_m_ref;
   15207              :         // when Pipe_m_ref is close to 0, there will still be Pipe_Q, Pipe_Q / Pipe_m_ref will blow up
   15208              :         // At low flow rate (stationary flow)
   15209              :         // Pipe_h_comp_in = Pipe_h_IU_out + Cp * deltaT
   15210              :         // where deltaT is the refrigerant temperature change over time t,
   15211              :         // deltaT = Pipe_Q * t / (refrigerant_mass_in_pipe * Cp)
   15212              :         // so Pipe_h_comp_in = Pipe_h_IU_out + Cp * Pipe_Q / refrigerant_mass_in_pipe
   15213              :         // assume 0.001 is the cutoff Re for stationary flow
   15214      1910308 :         if (Pipe_Num_Re < 0.001) { // low flow rate calculation
   15215         2170 :             Pipe_h_comp_in =
   15216         2170 :                 Pipe_h_IU_out + Pipe_Q * state.dataHVACGlobal->TimeStepSysSec /
   15217         2170 :                                     ((Constant::Pi * std::pow(this->RefPipDiaSuc / 2, 2) * this->RefPipLen *
   15218         4340 :                                       this->refrig->getSupHeatDensity(
   15219         2170 :                                           state, this->EvaporatingTemp + Pipe_SH_merged, max(min(Pevap, RefPHigh), RefPLow), RoutineName)));
   15220              :         }
   15221              : 
   15222              :     } else {
   15223            0 :         Pipe_DeltP = 0;
   15224            0 :         Pipe_Q = 0;
   15225            0 :         Pipe_h_comp_in = Pipe_h_IU_out;
   15226              :     }
   15227      1910308 : }
   15228              : 
   15229        19045 : void VRFCondenserEquipment::VRFOU_PipeLossH(
   15230              :     EnergyPlusData &state,
   15231              :     Real64 const Pipe_m_ref,     // Refrigerant mass flow rate [kg/s]
   15232              :     Real64 const Pcond,          // VRF condensing pressure [Pa]
   15233              :     Real64 const Pipe_h_IU_in,   // Enthalpy of IU at outlet [kJ/kg]
   15234              :     Real64 const OutdoorDryBulb, // outdoor dry-bulb temperature (C)
   15235              :     Real64 &Pipe_Q,              // unit part load ratio
   15236              :     Real64 &Pipe_DeltP,          // ratio of compressor ON airflow to AVERAGE airflow over timestep
   15237              :     Real64 &Pipe_h_comp_out      // Piping Loss Algorithm Parameter: Enthalpy before piping loss (compressor outlet) [kJ/kg]
   15238              : ) const
   15239              : {
   15240              : 
   15241              :     // SUBROUTINE INFORMATION:
   15242              :     //       AUTHOR         Rongpeng Zhang
   15243              :     //       DATE WRITTEN   Nov 2015
   15244              :     //       MODIFIED       na
   15245              :     //       RE-ENGINEERED  na
   15246              : 
   15247              :     // PURPOSE OF THIS SUBROUTINE:
   15248              :     // Determine the piping loss of the refrigerant, including both the heat loss and pressure drop.
   15249              :     // This happens at VRF cooling mode, within the Main Pipe connecting Outdoor Unit to Indoor Units.
   15250              : 
   15251              :     // METHODOLOGY EMPLOYED:
   15252              :     // Use a physics based piping loss model.
   15253              : 
   15254              :     using General::SolveRoot;
   15255              : 
   15256              :     int TUListNum;      // index to TU List
   15257              :     int NumTUInList;    // number of terminal units is list
   15258              :     int NumIUActivated; // number of the used indoor units [-]
   15259              : 
   15260              :     Real64 Pipe_v_ref;            // Piping Loss Algorithm Parameter: Refrigerant velocity [m/s]
   15261              :     Real64 Pipe_T_room;           // Piping Loss Algorithm Parameter: Average Room Temperature [C]
   15262              :     Real64 Pipe_T_IU_in;          // Piping Loss Algorithm Parameter: Average Refrigerant Temperature [C]
   15263              :     Real64 Pipe_Num_Re;           // Piping Loss Algorithm Parameter: refrigerant Re Number [-]
   15264              :     Real64 Pipe_Num_Pr;           // Piping Loss Algorithm Parameter: refrigerant Pr Number [-]
   15265              :     Real64 Pipe_Num_Nu;           // Piping Loss Algorithm Parameter: refrigerant Nu Number [-]
   15266              :     Real64 Pipe_Num_St;           // Piping Loss Algorithm Parameter: refrigerant St Number [-]
   15267              :     Real64 Pipe_Coe_k1;           // Piping Loss Algorithm Parameter: coefficients [-]
   15268              :     Real64 Pipe_Coe_k2;           // Piping Loss Algorithm Parameter: coefficients [-]
   15269              :     Real64 Pipe_Coe_k3;           // Piping Loss Algorithm Parameter: coefficients [-]
   15270              :     Real64 Pipe_cp_ref;           // Piping Loss Algorithm_[kJ/kg/K]
   15271              :     Real64 Pipe_conductivity_ref; // Piping Loss Algorithm: refrigerant conductivity [W/m/K]
   15272              :     Real64 Pipe_viscosity_ref;    // Piping Loss Algorithm Parameter: refrigerant viscosity [MuPa*s]
   15273              :     Real64 Ref_Coe_v1;            // Piping Loss Algorithm Parameter: coefficient to calculate Pipe_viscosity_ref [-]
   15274              :     Real64 Ref_Coe_v2;            // Piping Loss Algorithm Parameter: coefficient to calculate Pipe_viscosity_ref [-]
   15275              :     Real64 Ref_Coe_v3;            // Piping Loss Algorithm Parameter: coefficient to calculate Pipe_viscosity_ref [-]
   15276              :     Real64 RefPipInsH;            // Heat transfer coefficient for calculating piping loss [W/m2K]
   15277              : 
   15278              :     static constexpr std::string_view RoutineName("VRFOU_PipeLossH");
   15279              : 
   15280        19045 :     TUListNum = this->ZoneTUListPtr;
   15281        19045 :     NumTUInList = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).NumTUInList;
   15282        19045 :     Pipe_conductivity_ref = this->RefPipInsCon;
   15283              : 
   15284        19045 :     RefPipInsH = 9.3;
   15285        19045 :     Pipe_cp_ref = 1.6;
   15286              : 
   15287              :     // Refrigerant data
   15288        19045 :     Real64 RefTHigh = this->refrig->PsHighTempValue; // High Temperature Value for Ps (max in tables)
   15289        19045 :     Real64 RefPLow = this->refrig->PsLowPresValue;   // Low Pressure Value for Ps (>0.0)
   15290        19045 :     Real64 RefPHigh = this->refrig->PsHighPresValue; // High Pressure Value for Ps (max in tables)
   15291        19045 :     Real64 RefTSat = this->refrig->getSatTemperature(state, max(min(Pcond, RefPHigh), RefPLow), RoutineName);
   15292              : 
   15293              :     // Perform iteration to calculate Pipe_T_IU_in, given P and h
   15294        19045 :     Pipe_T_IU_in = this->refrig->getSupHeatTemp(state,
   15295              :                                                 max(min(Pcond, RefPHigh), RefPLow),
   15296              :                                                 Pipe_h_IU_in,
   15297        19045 :                                                 max(this->IUCondensingTemp, RefTSat),
   15298        19045 :                                                 min(this->IUCondensingTemp + 50, RefTHigh),
   15299              :                                                 RoutineName);
   15300        19045 :     Pipe_T_IU_in = min(RefTHigh, Pipe_T_IU_in);
   15301              : 
   15302              :     // Calculate average room temperature
   15303        19045 :     Pipe_T_room = 0;
   15304        19045 :     NumIUActivated = 0;
   15305       105782 :     for (int NumTU = 1; NumTU <= NumTUInList; ++NumTU) {
   15306        86737 :         int TUIndex = state.dataHVACVarRefFlow->TerminalUnitList(TUListNum).ZoneTUPtr(NumTU);
   15307        86737 :         int CoilIndex = state.dataHVACVarRefFlow->VRFTU(TUIndex).HeatCoilIndex;
   15308              : 
   15309        86737 :         if (state.dataDXCoils->DXCoil(CoilIndex).TotalHeatingEnergyRate > 0.0) {
   15310        86322 :             Pipe_T_room = Pipe_T_room + state.dataDXCoils->DXCoil(CoilIndex).InletAirTemp;
   15311        86322 :             NumIUActivated = NumIUActivated + 1;
   15312              :         }
   15313              :     }
   15314        19045 :     if (NumIUActivated > 0) {
   15315        19045 :         Pipe_T_room = Pipe_T_room / NumIUActivated;
   15316              :     } else {
   15317            0 :         Pipe_T_room = 18;
   15318              :     }
   15319              : 
   15320              :     // Calculate piping loss
   15321        19045 :     if (Pipe_m_ref > 0) {
   15322        19045 :         Ref_Coe_v1 = Pcond / 1000000 / 4.926;
   15323        19045 :         Ref_Coe_v2 = Pipe_h_IU_in / 383.5510343;
   15324        19045 :         Ref_Coe_v3 = (Pipe_T_IU_in + 273.15) / 344.39;
   15325        19045 :         Pipe_viscosity_ref = 4.302 * Ref_Coe_v1 + 0.81622 * pow_2(Ref_Coe_v1) - 120.98 * Ref_Coe_v2 + 139.17 * pow_2(Ref_Coe_v2) +
   15326        19045 :                              118.76 * Ref_Coe_v3 + 81.04 * pow_2(Ref_Coe_v3) + 5.7858 * Ref_Coe_v1 * Ref_Coe_v2 - 8.3817 * Ref_Coe_v1 * Ref_Coe_v3 -
   15327        19045 :                              218.48 * Ref_Coe_v2 * Ref_Coe_v3 + 21.58;
   15328        19045 :         if (Pipe_viscosity_ref <= 0) {
   15329            0 :             Pipe_viscosity_ref = 16.26; // default superheated vapor viscosity data (MuPa*s) at T=353.15 K, P=2MPa
   15330              :         }
   15331              : 
   15332        19045 :         Pipe_v_ref = Pipe_m_ref / (Constant::Pi * pow_2(this->RefPipDiaDis) * 0.25) /
   15333        19045 :                      this->refrig->getSupHeatDensity(state, Pipe_T_IU_in, max(min(Pcond, RefPHigh), RefPLow), RoutineName);
   15334        19045 :         Pipe_Num_Re = Pipe_m_ref / (Constant::Pi * pow_2(this->RefPipDiaDis) * 0.25) * this->RefPipDiaDis / Pipe_viscosity_ref * 1000000;
   15335        19045 :         Pipe_Num_Pr = Pipe_viscosity_ref * Pipe_cp_ref * 0.001 / Pipe_conductivity_ref;
   15336        19045 :         Pipe_Num_Nu = 0.023 * std::pow(Pipe_Num_Re, 0.8) * std::pow(Pipe_Num_Pr, 0.4);
   15337        19045 :         Pipe_Num_St = Pipe_Num_Nu / Pipe_Num_Re / Pipe_Num_Pr;
   15338              : 
   15339        19045 :         Pipe_Coe_k1 = Pipe_Num_Nu * Pipe_viscosity_ref;
   15340        19045 :         Pipe_Coe_k2 = this->RefPipInsCon * (this->RefPipDiaDis + this->RefPipInsThi) / this->RefPipInsThi;
   15341        19045 :         Pipe_Coe_k3 = RefPipInsH * (this->RefPipDiaDis + 2 * this->RefPipInsThi);
   15342              : 
   15343        38090 :         Pipe_Q = max(0.0,
   15344        19045 :                      (Constant::Pi * this->RefPipLen) * (Pipe_T_IU_in - OutdoorDryBulb / 2 - Pipe_T_room / 2) /
   15345        19045 :                          (1 / Pipe_Coe_k1 + 1 / Pipe_Coe_k2 + 1 / Pipe_Coe_k3)); // [W]
   15346        38090 :         Pipe_DeltP = max(
   15347              :             0.0,
   15348        38090 :             8 * Pipe_Num_St * std::pow(Pipe_Num_Pr, 0.6667) * this->RefPipEquLen / this->RefPipDiaDis *
   15349        19045 :                     this->refrig->getSupHeatDensity(state, Pipe_T_IU_in, max(min(Pcond, RefPHigh), RefPLow), RoutineName) * pow_2(Pipe_v_ref) / 2 -
   15350        19045 :                 this->RefPipHei * this->refrig->getSupHeatDensity(state, Pipe_T_IU_in, max(min(Pcond, RefPHigh), RefPLow), RoutineName) * 9.80665);
   15351              : 
   15352        19045 :         Pipe_h_comp_out = Pipe_h_IU_in + Pipe_Q / Pipe_m_ref;
   15353              : 
   15354              :     } else {
   15355            0 :         Pipe_DeltP = 0;
   15356            0 :         Pipe_Q = 0;
   15357            0 :         Pipe_h_comp_out = Pipe_h_IU_in;
   15358              :     }
   15359        19045 : }
   15360            0 : void VRFCondenserEquipment::oneTimeInit([[maybe_unused]] EnergyPlusData &state)
   15361              : {
   15362            0 : }
   15363            1 : void VRFCondenserEquipment::oneTimeInit_new([[maybe_unused]] EnergyPlusData &state)
   15364              : {
   15365            1 : }
   15366              : 
   15367       343724 : void VRFTerminalUnitEquipment::CalcVRFSuppHeatingCoil(EnergyPlusData &state,
   15368              :                                                       int const VRFTUNum,            // index of vrf terminal unit
   15369              :                                                       bool const FirstHVACIteration, // True when first HVAC iteration
   15370              :                                                       Real64 const PartLoadRatio,    // coil operating part-load ratio
   15371              :                                                       Real64 &SuppCoilLoad           // supp heating coil load max (W)
   15372              : )
   15373              : {
   15374              : 
   15375              :     // PURPOSE OF THIS SUBROUTINE:
   15376              :     // Manages VRF terminal unit supplemental heaters simulation.
   15377              : 
   15378              :     // Locals
   15379              :     // subroutine parameter definitions:
   15380       343724 :     int constexpr MaxIte(500);   // Maximum number of iterations for solver
   15381       343724 :     Real64 constexpr Acc(1.e-3); // Accuracy of solver result
   15382              : 
   15383              :     // local variable declaration:
   15384              :     Real64 SuppHeatCoilLoad; // load passed to supplemental heating coil (W)
   15385              :     Real64 QActual;          // actual coil output (W)
   15386              :     Real64 PartLoadFrac;     // temporary PLR variable
   15387              : 
   15388       343724 :     QActual = 0.0;
   15389       343724 :     PartLoadFrac = 0.0;
   15390       343724 :     SuppHeatCoilLoad = 0.0;
   15391              : 
   15392              :     // simulate gas, electric, hot water, and steam heating coils
   15393       343724 :     if (state.dataEnvrn->OutDryBulbTemp <= this->MaxOATSuppHeatingCoil) {
   15394       131056 :         SuppHeatCoilLoad = SuppCoilLoad;
   15395              :     } else {
   15396       212668 :         SuppHeatCoilLoad = 0.0;
   15397              :     }
   15398              : 
   15399       343724 :     switch (this->SuppHeatCoilType_Num) {
   15400       235709 :     case HVAC::Coil_HeatingGasOrOtherFuel:
   15401              :     case HVAC::Coil_HeatingElectric: {
   15402       942836 :         HeatingCoils::SimulateHeatingCoilComponents(
   15403       707127 :             state, this->SuppHeatCoilName, FirstHVACIteration, SuppHeatCoilLoad, this->SuppHeatCoilIndex, QActual, true, this->fanOp, PartLoadRatio);
   15404       235709 :         SuppHeatCoilLoad = QActual;
   15405       235709 :     } break;
   15406        54718 :     case HVAC::Coil_HeatingWater: {
   15407        54718 :         if (SuppHeatCoilLoad > HVAC::SmallLoad) {
   15408              :             //     see if HW coil has enough capacity to meet the load
   15409         1364 :             Real64 mdot = this->SuppHeatCoilFluidMaxFlow;
   15410         1364 :             state.dataLoopNodes->Node(this->SuppHeatCoilFluidInletNode).MassFlowRate = mdot;
   15411              :             //     simulate hot water coil to find the full flow operating capacity
   15412         4092 :             WaterCoils::SimulateWaterCoilComponents(
   15413         2728 :                 state, this->SuppHeatCoilName, FirstHVACIteration, this->SuppHeatCoilIndex, QActual, this->fanOp, PartLoadRatio);
   15414         1364 :             if (QActual > SuppHeatCoilLoad) {
   15415              :                 int SolFla; // Flag of solver, num iterations if >0, else error index
   15416        10912 :                 auto f = [&state, VRFTUNum, FirstHVACIteration, SuppHeatCoilLoad](Real64 const PartLoadFrac) {
   15417        10912 :                     Real64 QActual = 0.0; // actual heating load delivered [W]
   15418        10912 :                     Real64 mdot = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow * PartLoadFrac;
   15419        10912 :                     state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidInletNode).MassFlowRate = mdot;
   15420        32736 :                     WaterCoils::SimulateWaterCoilComponents(state,
   15421        10912 :                                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
   15422              :                                                             FirstHVACIteration,
   15423        10912 :                                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilIndex,
   15424              :                                                             QActual,
   15425        10912 :                                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOp,
   15426              :                                                             PartLoadFrac);
   15427        10912 :                     if (std::abs(SuppHeatCoilLoad) == 0.0) {
   15428            0 :                         return (QActual - SuppHeatCoilLoad) / 100.0;
   15429              :                     } else {
   15430        10912 :                         return (QActual - SuppHeatCoilLoad) / SuppHeatCoilLoad;
   15431              :                     }
   15432         1364 :                 };
   15433         1364 :                 General::SolveRoot(state, Acc, MaxIte, SolFla, PartLoadFrac, f, 0.0, 1.0);
   15434         1364 :                 this->SuppHeatPartLoadRatio = PartLoadFrac;
   15435              :             } else {
   15436            0 :                 this->SuppHeatPartLoadRatio = 1.0;
   15437            0 :                 SuppHeatCoilLoad = QActual;
   15438              :             }
   15439              :         } else {
   15440        53354 :             this->SuppHeatPartLoadRatio = 0.0;
   15441        53354 :             Real64 mdot = 0.0;
   15442        53354 :             SuppHeatCoilLoad = 0.0;
   15443        53354 :             PlantUtilities::SetComponentFlowRate(
   15444        53354 :                 state, mdot, this->SuppHeatCoilFluidInletNode, this->SuppHeatCoilFluidOutletNode, this->SuppHeatCoilPlantLoc);
   15445              :         }
   15446              :         //     simulate water heating coil
   15447       109436 :         WaterCoils::SimulateWaterCoilComponents(
   15448       109436 :             state, this->SuppHeatCoilName, FirstHVACIteration, this->SuppHeatCoilIndex, SuppHeatCoilLoad, this->fanOp, this->SuppHeatPartLoadRatio);
   15449        54718 :     } break;
   15450        53297 :     case HVAC::Coil_HeatingSteam: {
   15451              :         //     simulate steam heating coil
   15452        53297 :         Real64 mdot = this->SuppHeatCoilFluidMaxFlow * PartLoadRatio;
   15453        53297 :         state.dataLoopNodes->Node(this->SuppHeatCoilFluidInletNode).MassFlowRate = mdot;
   15454       159891 :         SteamCoils::SimulateSteamCoilComponents(
   15455       106594 :             state, this->SuppHeatCoilName, FirstHVACIteration, this->SuppHeatCoilIndex, SuppHeatCoilLoad, QActual, this->fanOp, PartLoadRatio);
   15456        53297 :         SuppHeatCoilLoad = QActual;
   15457        53297 :     } break;
   15458            0 :     default:
   15459            0 :         break;
   15460              :     }
   15461              : 
   15462       343724 :     SuppCoilLoad = SuppHeatCoilLoad;
   15463       343724 : }
   15464              : 
   15465            0 : Real64 VRFTerminalUnitEquipment::HotWaterHeatingCoilResidual(EnergyPlusData &state,
   15466              :                                                              Real64 const PartLoadFrac,     // water heating coil part-load ratio
   15467              :                                                              std::vector<Real64> const &Par // par(1) = index to current VRF terminal unit
   15468              : )
   15469              : {
   15470              : 
   15471              :     // PURPOSE OF THIS FUNCTION:
   15472              :     // Calculates supplemental hot water heating coils load fraction residual [(QActual - Load)/Load]
   15473              :     // hot water Coil output depends on the part load ratio which is being varied to drive the load
   15474              :     // fraction residual to zero.
   15475              : 
   15476              :     // METHODOLOGY EMPLOYED:
   15477              :     // runs Coil:Heating:Water component object to get the actual heating load delivered [W] at a
   15478              :     // given part load ratio and calculates the residual as defined above
   15479              : 
   15480              :     // Return value
   15481              :     Real64 Residuum; // Residual to be minimized to zero
   15482              : 
   15483              :     // local variables declaration:
   15484            0 :     int VRFTUNum = int(Par[1]);       // index to current terminal unit simulated
   15485            0 :     bool FirstHVACIteration = Par[2]; // 0 flag if it first HVAC iteration, or else 1
   15486            0 :     Real64 SuppHeatCoilLoad = Par[3]; // supplemental heating coil load to be met [W]
   15487            0 :     Real64 QActual = 0.0;             // actual heating load delivered [W]
   15488              : 
   15489              :     // Real64 mdot = min(state.dataLoopNodes->Node(VRFTU(VRFTUNum).SuppHeatCoilFluidOutletNode).MassFlowRateMaxAvail,
   15490              :     //                  VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow * PartLoadFrac);
   15491              : 
   15492            0 :     Real64 mdot = state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidMaxFlow * PartLoadFrac;
   15493            0 :     state.dataLoopNodes->Node(state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilFluidInletNode).MassFlowRate = mdot;
   15494            0 :     WaterCoils::SimulateWaterCoilComponents(state,
   15495            0 :                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilName,
   15496              :                                             FirstHVACIteration,
   15497            0 :                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).SuppHeatCoilIndex,
   15498              :                                             QActual,
   15499            0 :                                             state.dataHVACVarRefFlow->VRFTU(VRFTUNum).fanOp,
   15500              :                                             PartLoadFrac);
   15501              : 
   15502            0 :     if (std::abs(SuppHeatCoilLoad) == 0.0) {
   15503            0 :         Residuum = (QActual - SuppHeatCoilLoad) / 100.0;
   15504              :     } else {
   15505            0 :         Residuum = (QActual - SuppHeatCoilLoad) / SuppHeatCoilLoad;
   15506              :     }
   15507              : 
   15508            0 :     return Residuum;
   15509              : }
   15510              : 
   15511            0 : Real64 VRFTerminalUnitEquipment::HeatingCoilCapacityLimit(
   15512              :     EnergyPlusData &state,
   15513              :     Real64 const HeatCoilAirInletNode, // supplemental heating coil air inlet node
   15514              :     Real64 const HeatCoilMaxSATAllowed // supplemental heating coil maximum supply air temperature allowed [C]
   15515              : )
   15516              : {
   15517              :     // PURPOSE OF THIS FUNCTION:
   15518              :     // Calculates supplemental heating coils maximum heating capacity allowed based on the maximum
   15519              :     // supply air temperature limit specified.
   15520              : 
   15521              :     // METHODOLOGY EMPLOYED:
   15522              :     // ( m_dot_air * Cp_air_avg * DeltaT_air_across_heating_coil) [W]
   15523              : 
   15524              :     // Return value
   15525              :     Real64 HeatCoilCapacityAllowed; // heating coil maximum capacity that can be delivered at current time [W]
   15526              : 
   15527            0 :     Real64 MDotAir = state.dataLoopNodes->Node(HeatCoilAirInletNode).MassFlowRate;
   15528            0 :     Real64 CpAirIn = Psychrometrics::PsyCpAirFnW(state.dataLoopNodes->Node(HeatCoilAirInletNode).HumRat);
   15529            0 :     Real64 HCDeltaT = max(0.0, HeatCoilMaxSATAllowed - state.dataLoopNodes->Node(HeatCoilAirInletNode).Temp);
   15530            0 :     HeatCoilCapacityAllowed = MDotAir * CpAirIn * HCDeltaT;
   15531              : 
   15532            0 :     return HeatCoilCapacityAllowed;
   15533              : }
   15534              : 
   15535              : } // namespace EnergyPlus::HVACVariableRefrigerantFlow
        

Generated by: LCOV version 2.0-1