LCOV - code coverage report
Current view: top level - EnergyPlus - UserDefinedComponents.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 985 1582 62.3 %
Date: 2023-01-17 19:17:23 Functions: 20 23 87.0 %

          Line data    Source code
       1             : // EnergyPlus, Copyright (c) 1996-2023, 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 <cmath>
      50             : 
      51             : // ObjexxFCL Headers
      52             : #include <ObjexxFCL/Fmath.hh>
      53             : 
      54             : // EnergyPlus Headers
      55             : #include <EnergyPlus/BranchNodeConnections.hh>
      56             : #include <EnergyPlus/Data/EnergyPlusData.hh>
      57             : #include <EnergyPlus/DataDefineEquip.hh>
      58             : #include <EnergyPlus/DataEnvironment.hh>
      59             : #include <EnergyPlus/DataHeatBalance.hh>
      60             : #include <EnergyPlus/DataIPShortCuts.hh>
      61             : #include <EnergyPlus/DataLoopNode.hh>
      62             : #include <EnergyPlus/DataRuntimeLanguage.hh>
      63             : #include <EnergyPlus/DataWater.hh>
      64             : #include <EnergyPlus/DataZoneEnergyDemands.hh>
      65             : #include <EnergyPlus/DataZoneEquipment.hh>
      66             : #include <EnergyPlus/EMSManager.hh>
      67             : #include <EnergyPlus/FluidProperties.hh>
      68             : #include <EnergyPlus/GlobalNames.hh>
      69             : #include <EnergyPlus/HeatBalanceInternalHeatGains.hh>
      70             : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
      71             : #include <EnergyPlus/NodeInputManager.hh>
      72             : #include <EnergyPlus/Plant/PlantLocation.hh>
      73             : #include <EnergyPlus/PlantUtilities.hh>
      74             : #include <EnergyPlus/PluginManager.hh>
      75             : #include <EnergyPlus/Psychrometrics.hh>
      76             : #include <EnergyPlus/UserDefinedComponents.hh>
      77             : #include <EnergyPlus/UtilityRoutines.hh>
      78             : #include <EnergyPlus/WaterManager.hh>
      79             : 
      80             : namespace EnergyPlus {
      81             : 
      82             : namespace UserDefinedComponents {
      83             : 
      84             :     // Module containing the routines dealing with the User Defined HVAC and Plant component models
      85             : 
      86             :     // MODULE INFORMATION:
      87             :     //       AUTHOR         B. Griffith
      88             :     //       DATE WRITTEN   January 2012
      89             :     //       MODIFIED       na
      90             :     //       RE-ENGINEERED  na
      91             : 
      92             :     // PURPOSE OF THIS MODULE:
      93             :     // Collect component models for custom program with Erl.
      94             : 
      95           2 :     PlantComponent *UserPlantComponentStruct::factory(EnergyPlusData &state, std::string const &objectName)
      96             :     {
      97             :         // Process the input data
      98           2 :         if (state.dataUserDefinedComponents->GetPlantCompInput) {
      99           2 :             GetUserDefinedPlantComponents(state);
     100           2 :             state.dataUserDefinedComponents->GetPlantCompInput = false;
     101             :         }
     102             :         // Now look for this particular object
     103           2 :         for (auto &thisComp : state.dataUserDefinedComponents->UserPlantComp) {
     104           2 :             if (thisComp.Name == objectName) {
     105           2 :                 return &thisComp;
     106             :             }
     107             :         }
     108             :         // If we didn't find it, fatal
     109             :         ShowFatalError(state, "LocalUserDefinedPlantComponentFactory: Error getting inputs for object named: " + objectName); // LCOV_EXCL_LINE
     110             :         // Shut up the compiler
     111             :         return nullptr; // LCOV_EXCL_LINE
     112             :     }
     113             : 
     114         390 :     void UserPlantComponentStruct::onInitLoopEquip(EnergyPlusData &state, const PlantLocation &calledFromLocation)
     115             :     {
     116             :         bool anyEMSRan;
     117         390 :         Real64 myLoad = 0.0;
     118         390 :         int thisLoop = 0;
     119             : 
     120         390 :         this->initialize(state, calledFromLocation.loopNum, myLoad);
     121             : 
     122         780 :         for (int loop = 1; loop <= this->NumPlantConnections; ++loop) {
     123         390 :             if (calledFromLocation.loopNum != this->Loop(loop).plantLoc.loopNum) continue;
     124         390 :             if (calledFromLocation.loopSideNum != this->Loop(loop).plantLoc.loopSideNum) continue;
     125         390 :             thisLoop = loop;
     126             :         }
     127             : 
     128         390 :         if (thisLoop > 0) {
     129         390 :             if (this->Loop(thisLoop).ErlInitProgramMngr > 0) {
     130         195 :                 EMSManager::ManageEMS(state, EMSManager::EMSCallFrom::UserDefinedComponentModel, anyEMSRan, this->Loop(thisLoop).ErlInitProgramMngr);
     131         195 :             } else if (this->Loop(thisLoop).initPluginLocation > -1) {
     132         195 :                 state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(state, this->Loop(thisLoop).initPluginLocation);
     133             :             }
     134             : 
     135        1560 :             PlantUtilities::InitComponentNodes(state,
     136         390 :                                                this->Loop(thisLoop).MassFlowRateMin,
     137         390 :                                                this->Loop(thisLoop).MassFlowRateMax,
     138         390 :                                                this->Loop(thisLoop).InletNodeNum,
     139         390 :                                                this->Loop(thisLoop).OutletNodeNum);
     140             : 
     141         390 :             PlantUtilities::RegisterPlantCompDesignFlow(state, this->Loop(thisLoop).InletNodeNum, this->Loop(thisLoop).DesignVolumeFlowRate);
     142             : 
     143             :         } else {
     144             :             // throw warning
     145           0 :             ShowFatalError(
     146             :                 state,
     147           0 :                 format("SimUserDefinedPlantComponent: did not find where called from. Loop number called from ={}, loop side called from ={}.",
     148             :                        calledFromLocation.loopNum,
     149           0 :                        calledFromLocation.loopSideNum));
     150             :         }
     151         390 :     }
     152             : 
     153          10 :     void UserPlantComponentStruct::getDesignCapacities(
     154             :         [[maybe_unused]] EnergyPlusData &state, const PlantLocation &calledFromLocation, Real64 &MaxLoad, Real64 &MinLoad, Real64 &OptLoad)
     155             :     {
     156          10 :         int thisLoop = 0;
     157          20 :         for (int loop = 1; loop <= this->NumPlantConnections; ++loop) {
     158          10 :             if (calledFromLocation.loopNum != this->Loop(loop).plantLoc.loopNum) continue;
     159          10 :             if (calledFromLocation.loopSideNum != this->Loop(loop).plantLoc.loopSideNum) continue;
     160          10 :             thisLoop = loop;
     161             :         }
     162             : 
     163          10 :         MinLoad = this->Loop(thisLoop).MinLoad;
     164          10 :         MaxLoad = this->Loop(thisLoop).MaxLoad;
     165          10 :         OptLoad = this->Loop(thisLoop).OptLoad;
     166          10 :     }
     167             : 
     168       95740 :     void UserPlantComponentStruct::UserPlantComponentStruct::simulate(EnergyPlusData &state,
     169             :                                                                       const EnergyPlus::PlantLocation &calledFromLocation,
     170             :                                                                       [[maybe_unused]] bool FirstHVACIteration,
     171             :                                                                       Real64 &CurLoad,
     172             :                                                                       [[maybe_unused]] bool RunFlag)
     173             :     {
     174             :         // SUBROUTINE INFORMATION:
     175             :         //       AUTHOR         B. Griffith
     176             :         //       DATE WRITTEN   Jan 2012
     177             :         //       MODIFIED       na
     178             :         //       RE-ENGINEERED  na
     179             : 
     180             :         // PURPOSE OF THIS SUBROUTINE:
     181             :         // User Defined plant generic component
     182             : 
     183       95740 :         if (state.dataGlobal->BeginEnvrnFlag) {
     184         380 :             this->onInitLoopEquip(state, calledFromLocation);
     185             :         }
     186             : 
     187             :         bool anyEMSRan;
     188       95740 :         int thisLoop = 0;
     189             : 
     190      191480 :         for (int loop = 1; loop <= this->NumPlantConnections; ++loop) {
     191       95740 :             if (calledFromLocation.loopNum != this->Loop(loop).plantLoc.loopNum) continue;
     192       95740 :             if (calledFromLocation.loopSideNum != this->Loop(loop).plantLoc.loopSideNum) continue;
     193       95740 :             thisLoop = loop;
     194             :         }
     195             : 
     196       95740 :         this->initialize(state, thisLoop, CurLoad);
     197             : 
     198       95740 :         if (thisLoop > 0) {
     199       95740 :             if (this->Loop(thisLoop).ErlSimProgramMngr > 0) {
     200       47870 :                 EMSManager::ManageEMS(state, EMSManager::EMSCallFrom::UserDefinedComponentModel, anyEMSRan, this->Loop(thisLoop).ErlSimProgramMngr);
     201       47870 :             } else if (this->Loop(thisLoop).simPluginLocation > -1) {
     202       47870 :                 state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(state, this->Loop(thisLoop).simPluginLocation);
     203             :             }
     204             :         }
     205             : 
     206       95740 :         if (this->ErlSimProgramMngr > 0) {
     207           0 :             EMSManager::ManageEMS(state, EMSManager::EMSCallFrom::UserDefinedComponentModel, anyEMSRan, this->ErlSimProgramMngr);
     208       95740 :         } else if (this->simPluginLocation > -1) {
     209           0 :             state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(state, this->simPluginLocation);
     210             :         }
     211             : 
     212       95740 :         this->report(state, thisLoop);
     213       95740 :     }
     214             : 
     215       80346 :     void SimCoilUserDefined(EnergyPlusData &state,
     216             :                             std::string_view EquipName, // user name for component
     217             :                             int &CompIndex,
     218             :                             int const AirLoopNum,
     219             :                             bool &HeatingActive,
     220             :                             bool &CoolingActive)
     221             :     {
     222             : 
     223             :         // SUBROUTINE INFORMATION:
     224             :         //       AUTHOR         B. Griffith
     225             :         //       DATE WRITTEN   Feb. 2012
     226             :         //       MODIFIED       na
     227             :         //       RE-ENGINEERED  na
     228             : 
     229             :         int CompNum;
     230             : 
     231       80346 :         if (state.dataUserDefinedComponents->GetPlantCompInput) {
     232           0 :             GetUserDefinedPlantComponents(state);
     233           0 :             state.dataUserDefinedComponents->GetPlantCompInput = false;
     234             :         }
     235             : 
     236             :         // Find the correct Equipment
     237       80346 :         if (CompIndex == 0) {
     238           6 :             CompNum = UtilityRoutines::FindItemInList(EquipName, state.dataUserDefinedComponents->UserCoil);
     239           6 :             if (CompNum == 0) {
     240           0 :                 ShowFatalError(state, "SimUserDefinedPlantComponent: User Defined Coil not found");
     241             :             }
     242           6 :             CompIndex = CompNum;
     243             :         } else {
     244       80340 :             CompNum = CompIndex;
     245       80340 :             if (CompNum < 1 || CompNum > state.dataUserDefinedComponents->NumUserCoils) {
     246           0 :                 ShowFatalError(state,
     247           0 :                                format("SimUserDefinedPlantComponent: Invalid CompIndex passed={}, Number of units ={}, Entered Unit name = {}",
     248             :                                       CompNum,
     249           0 :                                       state.dataUserDefinedComponents->NumUserCoils,
     250           0 :                                       EquipName));
     251             :             }
     252       80340 :             if (state.dataUserDefinedComponents->CheckUserCoilName(CompNum)) {
     253           6 :                 if (EquipName != state.dataUserDefinedComponents->UserCoil(CompNum).Name) {
     254           0 :                     ShowFatalError(
     255             :                         state,
     256           0 :                         format("SimUserDefinedPlantComponent: Invalid CompIndex passed={}, Unit name={}, stored unit name for that index={}",
     257             :                                CompNum,
     258             :                                EquipName,
     259           0 :                                state.dataUserDefinedComponents->UserCoil(CompNum).Name));
     260             :                 }
     261           6 :                 state.dataUserDefinedComponents->CheckUserCoilName(CompNum) = false;
     262             :             }
     263             :         }
     264             :         bool anyEMSRan;
     265       80346 :         if (state.dataGlobal->BeginEnvrnFlag) {
     266         234 :             if (state.dataUserDefinedComponents->UserCoil(CompNum).ErlInitProgramMngr > 0) {
     267         234 :                 EMSManager::ManageEMS(state,
     268             :                                       EMSManager::EMSCallFrom::UserDefinedComponentModel,
     269             :                                       anyEMSRan,
     270         234 :                                       state.dataUserDefinedComponents->UserCoil(CompNum).ErlInitProgramMngr);
     271           0 :             } else if (state.dataUserDefinedComponents->UserCoil(CompNum).initPluginLocation > -1) {
     272           0 :                 state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(
     273           0 :                     state, state.dataUserDefinedComponents->UserCoil(CompNum).initPluginLocation);
     274             :             }
     275             : 
     276         234 :             if (state.dataUserDefinedComponents->UserCoil(CompNum).PlantIsConnected) {
     277             : 
     278         936 :                 PlantUtilities::InitComponentNodes(state,
     279         234 :                                                    state.dataUserDefinedComponents->UserCoil(CompNum).Loop.MassFlowRateMin,
     280         234 :                                                    state.dataUserDefinedComponents->UserCoil(CompNum).Loop.MassFlowRateMax,
     281         234 :                                                    state.dataUserDefinedComponents->UserCoil(CompNum).Loop.InletNodeNum,
     282         234 :                                                    state.dataUserDefinedComponents->UserCoil(CompNum).Loop.OutletNodeNum);
     283             : 
     284         468 :                 PlantUtilities::RegisterPlantCompDesignFlow(state,
     285         234 :                                                             state.dataUserDefinedComponents->UserCoil(CompNum).Loop.InletNodeNum,
     286         234 :                                                             state.dataUserDefinedComponents->UserCoil(CompNum).Loop.DesignVolumeFlowRate);
     287             :             }
     288             :         }
     289             : 
     290       80346 :         state.dataUserDefinedComponents->UserCoil(CompNum).initialize(state);
     291             : 
     292       80346 :         if (state.dataUserDefinedComponents->UserCoil(CompNum).ErlSimProgramMngr > 0) {
     293       80346 :             EMSManager::ManageEMS(state,
     294             :                                   EMSManager::EMSCallFrom::UserDefinedComponentModel,
     295             :                                   anyEMSRan,
     296       80346 :                                   state.dataUserDefinedComponents->UserCoil(CompNum).ErlSimProgramMngr);
     297           0 :         } else if (state.dataUserDefinedComponents->UserCoil(CompNum).simPluginLocation > -1) {
     298           0 :             state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(state,
     299           0 :                                                                                state.dataUserDefinedComponents->UserCoil(CompNum).simPluginLocation);
     300             :         }
     301             : 
     302       80346 :         state.dataUserDefinedComponents->UserCoil(CompNum).report(state);
     303             : 
     304       80346 :         if (AirLoopNum != -1) { // IF the system is not an equipment of outdoor air unit
     305             :             // determine if heating or cooling on primary air stream
     306      160692 :             HeatingActive = state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).InletNodeNum).Temp <
     307       80346 :                             state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).OutletNodeNum).Temp;
     308             : 
     309             :             Real64 EnthInlet =
     310       80346 :                 Psychrometrics::PsyHFnTdbW(state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).InletNodeNum).Temp,
     311      160692 :                                            state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).InletNodeNum).HumRat);
     312             :             Real64 EnthOutlet =
     313       80346 :                 Psychrometrics::PsyHFnTdbW(state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).OutletNodeNum).Temp,
     314      160692 :                                            state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).OutletNodeNum).HumRat);
     315       80346 :             CoolingActive = EnthInlet > EnthOutlet;
     316             :         }
     317       80346 :     }
     318             : 
     319       24690 :     void SimZoneAirUserDefined(EnergyPlusData &state,
     320             :                                std::string_view CompName,      // name of the packaged terminal heat pump
     321             :                                int const ZoneNum,              // number of zone being served
     322             :                                Real64 &SensibleOutputProvided, // sensible capacity delivered to zone
     323             :                                Real64 &LatentOutputProvided,   // Latent add/removal  (kg/s), dehumid = negative
     324             :                                int &CompIndex                  // index to zone hvac unit
     325             :     )
     326             :     {
     327             : 
     328             :         // SUBROUTINE INFORMATION:
     329             :         //       AUTHOR         B. Griffith
     330             :         //       DATE WRITTEN   February, 2012
     331             :         //       MODIFIED       na
     332             :         //       RE-ENGINEERED  na
     333             : 
     334             :         int CompNum;
     335             : 
     336       24690 :         if (state.dataUserDefinedComponents->GetInput) {
     337           2 :             GetUserDefinedComponents(state);
     338           2 :             state.dataUserDefinedComponents->GetInput = false;
     339             :         }
     340             : 
     341             :         // Find the correct Equipment
     342       24690 :         if (CompIndex == 0) {
     343           6 :             CompNum = UtilityRoutines::FindItemInList(CompName, state.dataUserDefinedComponents->UserZoneAirHVAC);
     344           6 :             if (CompNum == 0) {
     345           0 :                 ShowFatalError(state, "SimUserDefinedPlantComponent: User Defined Coil not found");
     346             :             }
     347           6 :             CompIndex = CompNum;
     348             :         } else {
     349       24684 :             CompNum = CompIndex;
     350       24684 :             if (CompNum < 1 || CompNum > state.dataUserDefinedComponents->NumUserZoneAir) {
     351           0 :                 ShowFatalError(state,
     352           0 :                                format("SimUserDefinedPlantComponent: Invalid CompIndex passed={}, Number of units ={}, Entered Unit name = {}",
     353             :                                       CompNum,
     354           0 :                                       state.dataUserDefinedComponents->NumUserZoneAir,
     355           0 :                                       CompName));
     356             :             }
     357       24684 :             if (state.dataUserDefinedComponents->CheckUserZoneAirName(CompNum)) {
     358           6 :                 if (CompName != state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Name) {
     359           0 :                     ShowFatalError(
     360             :                         state,
     361           0 :                         format("SimUserDefinedPlantComponent: Invalid CompIndex passed={}, Unit name={}, stored unit name for that index={}",
     362             :                                CompNum,
     363             :                                CompName,
     364           0 :                                state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Name));
     365             :                 }
     366           6 :                 state.dataUserDefinedComponents->CheckUserZoneAirName(CompNum) = false;
     367             :             }
     368             :         }
     369             :         bool anyEMSRan;
     370       24690 :         if (state.dataGlobal->BeginEnvrnFlag) {
     371         180 :             state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).initialize(state, ZoneNum);
     372             : 
     373         180 :             if (state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ErlInitProgramMngr > 0) {
     374         150 :                 EMSManager::ManageEMS(state,
     375             :                                       EMSManager::EMSCallFrom::UserDefinedComponentModel,
     376             :                                       anyEMSRan,
     377         150 :                                       state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ErlInitProgramMngr);
     378          30 :             } else if (state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).initPluginLocation > -1) {
     379           0 :                 state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(
     380           0 :                     state, state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).initPluginLocation);
     381             :             }
     382         180 :             if (state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).NumPlantConnections > 0) {
     383           0 :                 for (int Loop = 1; Loop <= state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).NumPlantConnections; ++Loop) {
     384             : 
     385           0 :                     PlantUtilities::InitComponentNodes(state,
     386           0 :                                                        state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).MassFlowRateMin,
     387           0 :                                                        state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).MassFlowRateMax,
     388           0 :                                                        state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).InletNodeNum,
     389           0 :                                                        state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).OutletNodeNum);
     390             : 
     391           0 :                     PlantUtilities::RegisterPlantCompDesignFlow(
     392             :                         state,
     393           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).InletNodeNum,
     394           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).DesignVolumeFlowRate);
     395             :                 }
     396             :             }
     397             : 
     398             :         } // BeginEnvrnFlag
     399             : 
     400       24690 :         state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).initialize(state, ZoneNum);
     401             : 
     402       24690 :         if (state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ErlSimProgramMngr > 0) {
     403       20575 :             EMSManager::ManageEMS(state,
     404             :                                   EMSManager::EMSCallFrom::UserDefinedComponentModel,
     405             :                                   anyEMSRan,
     406       20575 :                                   state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ErlSimProgramMngr);
     407        4115 :         } else if (state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).simPluginLocation > -1) {
     408        4115 :             state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(
     409        4115 :                 state, state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).simPluginLocation);
     410             :         }
     411             : 
     412       24690 :         state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).report(state);
     413             : 
     414             :         // calculate delivered capacity
     415             :         Real64 AirMassFlow =
     416       24690 :             min(state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ZoneAir.InletNodeNum).MassFlowRate,
     417       49380 :                 state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ZoneAir.OutletNodeNum).MassFlowRate);
     418             :         // calculate sensible load met using delta enthalpy at a constant (minimum) humidity ratio)
     419       24690 :         Real64 MinHumRat = min(state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ZoneAir.InletNodeNum).HumRat,
     420       49380 :                                state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ZoneAir.OutletNodeNum).HumRat);
     421       24690 :         SensibleOutputProvided =
     422       24690 :             AirMassFlow *
     423       24690 :             (Psychrometrics::PsyHFnTdbW(
     424       49380 :                  state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ZoneAir.OutletNodeNum).Temp, MinHumRat) -
     425       24690 :              Psychrometrics::PsyHFnTdbW(
     426       24690 :                  state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ZoneAir.InletNodeNum).Temp, MinHumRat));
     427             : 
     428       24690 :         Real64 SpecHumOut = state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ZoneAir.OutletNodeNum).HumRat;
     429       24690 :         Real64 SpecHumIn = state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).ZoneAir.InletNodeNum).HumRat;
     430       24690 :         LatentOutputProvided = AirMassFlow * (SpecHumOut - SpecHumIn); // Latent rate, kg/s (dehumid = negative)
     431       24690 :     }
     432             : 
     433      119640 :     void SimAirTerminalUserDefined(EnergyPlusData &state,
     434             :                                    std::string_view CompName,
     435             :                                    [[maybe_unused]] bool const FirstHVACIteration,
     436             :                                    int const ZoneNum,
     437             :                                    [[maybe_unused]] int const ZoneNodeNum,
     438             :                                    int &CompIndex)
     439             :     {
     440             : 
     441             :         // SUBROUTINE INFORMATION:
     442             :         //       AUTHOR         B. Griffith
     443             :         //       DATE WRITTEN   March 2012
     444             :         //       MODIFIED       na
     445             :         //       RE-ENGINEERED  na
     446             : 
     447             :         // PURPOSE OF THIS SUBROUTINE:
     448             :         // simulation call for generic air terminal
     449             : 
     450             :         int CompNum;
     451             : 
     452      119640 :         if (state.dataUserDefinedComponents->GetInput) {
     453           2 :             GetUserDefinedComponents(state);
     454           2 :             state.dataUserDefinedComponents->GetInput = false;
     455             :         }
     456             : 
     457             :         // Find the correct Equipment
     458      119640 :         if (CompIndex == 0) {
     459          10 :             CompNum = UtilityRoutines::FindItemInList(CompName, state.dataUserDefinedComponents->UserAirTerminal);
     460          10 :             if (CompNum == 0) {
     461           0 :                 ShowFatalError(state, "SimUserDefinedPlantComponent: User Defined Coil not found");
     462             :             }
     463          10 :             CompIndex = CompNum;
     464             :         } else {
     465      119630 :             CompNum = CompIndex;
     466      119630 :             if (CompNum < 1 || CompNum > state.dataUserDefinedComponents->NumUserAirTerminals) {
     467           0 :                 ShowFatalError(state,
     468           0 :                                format("SimUserDefinedPlantComponent: Invalid CompIndex passed={}, Number of units ={}, Entered Unit name = {}",
     469             :                                       CompNum,
     470           0 :                                       state.dataUserDefinedComponents->NumUserAirTerminals,
     471           0 :                                       CompName));
     472             :             }
     473      119630 :             if (state.dataUserDefinedComponents->CheckUserAirTerminal(CompNum)) {
     474          10 :                 if (CompName != state.dataUserDefinedComponents->UserAirTerminal(CompNum).Name) {
     475           0 :                     ShowFatalError(
     476             :                         state,
     477           0 :                         format("SimUserDefinedPlantComponent: Invalid CompIndex passed={}, Unit name={}, stored unit name for that index={}",
     478             :                                CompNum,
     479             :                                CompName,
     480           0 :                                state.dataUserDefinedComponents->UserAirTerminal(CompNum).Name));
     481             :                 }
     482          10 :                 state.dataUserDefinedComponents->CheckUserAirTerminal(CompNum) = false;
     483             :             }
     484             :         }
     485             :         bool anyEMSRan;
     486      119640 :         if (state.dataGlobal->BeginEnvrnFlag) {
     487         430 :             state.dataUserDefinedComponents->UserAirTerminal(CompNum).initialize(state, ZoneNum);
     488             : 
     489         430 :             if (state.dataUserDefinedComponents->UserAirTerminal(CompNum).ErlInitProgramMngr > 0) {
     490         430 :                 EMSManager::ManageEMS(state,
     491             :                                       EMSManager::EMSCallFrom::UserDefinedComponentModel,
     492             :                                       anyEMSRan,
     493         430 :                                       state.dataUserDefinedComponents->UserAirTerminal(CompNum).ErlInitProgramMngr);
     494           0 :             } else if (state.dataUserDefinedComponents->UserAirTerminal(CompNum).initPluginLocation > -1) {
     495           0 :                 state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(
     496           0 :                     state, state.dataUserDefinedComponents->UserAirTerminal(CompNum).initPluginLocation);
     497             :             }
     498         430 :             if (state.dataUserDefinedComponents->UserAirTerminal(CompNum).NumPlantConnections > 0) {
     499         860 :                 for (int Loop = 1; Loop <= state.dataUserDefinedComponents->UserAirTerminal(CompNum).NumPlantConnections; ++Loop) {
     500             : 
     501        1720 :                     PlantUtilities::InitComponentNodes(state,
     502         430 :                                                        state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).MassFlowRateMin,
     503         430 :                                                        state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).MassFlowRateMax,
     504         430 :                                                        state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).InletNodeNum,
     505         430 :                                                        state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).OutletNodeNum);
     506             : 
     507         860 :                     PlantUtilities::RegisterPlantCompDesignFlow(
     508             :                         state,
     509         430 :                         state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).InletNodeNum,
     510         430 :                         state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).DesignVolumeFlowRate);
     511             :                 }
     512             :             }
     513             : 
     514             :         } // BeginEnvrnFlag
     515             : 
     516      119640 :         state.dataUserDefinedComponents->UserAirTerminal(CompNum).initialize(state, ZoneNum);
     517             : 
     518      119640 :         if (state.dataUserDefinedComponents->UserAirTerminal(CompNum).ErlSimProgramMngr > 0) {
     519      119640 :             EMSManager::ManageEMS(state,
     520             :                                   EMSManager::EMSCallFrom::UserDefinedComponentModel,
     521             :                                   anyEMSRan,
     522      119640 :                                   state.dataUserDefinedComponents->UserAirTerminal(CompNum).ErlSimProgramMngr);
     523           0 :         } else if (state.dataUserDefinedComponents->UserAirTerminal(CompNum).simPluginLocation > -1) {
     524           0 :             state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(
     525           0 :                 state, state.dataUserDefinedComponents->UserAirTerminal(CompNum).simPluginLocation);
     526             :         }
     527             : 
     528      119640 :         state.dataUserDefinedComponents->UserAirTerminal(CompNum).report(state);
     529      119640 :     }
     530             : 
     531           4 :     void GetUserDefinedPlantComponents(EnergyPlusData &state)
     532             :     {
     533           4 :         bool ErrorsFound(false);
     534             :         int NumAlphas; // Number of elements in the alpha array
     535             :         int NumNums;   // Number of elements in the numeric array
     536             :         int IOStat;    // IO Status when calling get input subroutine
     537             :         int TotalArgs; // argument for call to GetObjectDefMaxArgs
     538           8 :         Array1D_string cAlphaFieldNames;
     539           8 :         Array1D_bool lAlphaFieldBlanks;
     540           8 :         Array1D_string cAlphaArgs;
     541           8 :         Array1D<Real64> rNumericArgs;
     542           8 :         std::string cCurrentModuleObject;
     543             : 
     544           4 :         cCurrentModuleObject = "PlantComponent:UserDefined";
     545           4 :         state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(state, cCurrentModuleObject, TotalArgs, NumAlphas, NumNums);
     546             : 
     547           4 :         cAlphaFieldNames.allocate(NumAlphas);
     548           4 :         cAlphaArgs.allocate(NumAlphas);
     549           4 :         lAlphaFieldBlanks.dimension(NumAlphas, false);
     550           4 :         rNumericArgs.dimension(NumNums, 0.0);
     551             : 
     552             :         // need to make sure GetEMSInput has run...
     553             : 
     554           4 :         state.dataUserDefinedComponents->NumUserPlantComps =
     555           4 :             state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
     556           4 :         if (state.dataUserDefinedComponents->NumUserPlantComps > 0) {
     557           2 :             state.dataUserDefinedComponents->UserPlantComp.allocate(state.dataUserDefinedComponents->NumUserPlantComps);
     558           2 :             state.dataUserDefinedComponents->CheckUserPlantCompName.dimension(state.dataUserDefinedComponents->NumUserPlantComps, true);
     559           4 :             for (int CompLoop = 1; CompLoop <= state.dataUserDefinedComponents->NumUserPlantComps; ++CompLoop) {
     560           2 :                 state.dataInputProcessing->inputProcessor->getObjectItem(state,
     561             :                                                                          cCurrentModuleObject,
     562             :                                                                          CompLoop,
     563             :                                                                          cAlphaArgs,
     564             :                                                                          NumAlphas,
     565             :                                                                          rNumericArgs,
     566             :                                                                          NumNums,
     567             :                                                                          IOStat,
     568             :                                                                          _,
     569             :                                                                          lAlphaFieldBlanks,
     570             :                                                                          cAlphaFieldNames,
     571             :                                                                          _);
     572           2 :                 UtilityRoutines::IsNameEmpty(state, cAlphaArgs(1), cCurrentModuleObject, ErrorsFound);
     573             : 
     574           2 :                 state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name = cAlphaArgs(1);
     575             : 
     576             :                 // now get program manager for model simulations
     577           2 :                 if (!lAlphaFieldBlanks(2)) {
     578           0 :                     int StackMngrNum = UtilityRoutines::FindItemInList(cAlphaArgs(2), state.dataRuntimeLang->EMSProgramCallManager);
     579           0 :                     if (StackMngrNum > 0) { // found it
     580           0 :                         state.dataUserDefinedComponents->UserPlantComp(CompLoop).ErlSimProgramMngr = StackMngrNum;
     581             :                     } else {
     582             :                         // check Python Plugins
     583           0 :                         state.dataUserDefinedComponents->UserPlantComp(CompLoop).simPluginLocation =
     584           0 :                             state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(2));
     585           0 :                         if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).simPluginLocation == -1) {
     586           0 :                             ShowSevereError(state, "Invalid " + cAlphaFieldNames(2) + '=' + cAlphaArgs(2));
     587           0 :                             ShowContinueError(state, "Entered in " + cCurrentModuleObject + '=' + cAlphaArgs(1));
     588           0 :                             ShowContinueError(state, "Program Manager Name not found as an EMS Program Manager or a Python Plugin Instance object.");
     589           0 :                             ErrorsFound = true;
     590             :                         }
     591             :                     }
     592             :                 }
     593             : 
     594           2 :                 int NumPlantConnections = std::floor(rNumericArgs(1));
     595             : 
     596           2 :                 if ((NumPlantConnections >= 1) && (NumPlantConnections <= 4)) {
     597           2 :                     state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop.allocate(NumPlantConnections);
     598           2 :                     state.dataUserDefinedComponents->UserPlantComp(CompLoop).NumPlantConnections = NumPlantConnections;
     599           4 :                     for (int ConnectionLoop = 1; ConnectionLoop <= NumPlantConnections; ++ConnectionLoop) {
     600           4 :                         const auto LoopStr = fmt::to_string(ConnectionLoop);
     601           2 :                         int aArgCount = (ConnectionLoop - 1) * 6 + 3;
     602           2 :                         state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletNodeNum =
     603           4 :                             NodeInputManager::GetOnlySingleNode(state,
     604           2 :                                                                 cAlphaArgs(aArgCount),
     605             :                                                                 ErrorsFound,
     606             :                                                                 DataLoopNode::ConnectionObjectType::PlantComponentUserDefined,
     607           2 :                                                                 cAlphaArgs(1),
     608             :                                                                 DataLoopNode::NodeFluidType::Water,
     609             :                                                                 DataLoopNode::ConnectionType::Inlet,
     610             :                                                                 static_cast<NodeInputManager::CompFluidStream>(ConnectionLoop),
     611           2 :                                                                 DataLoopNode::ObjectIsNotParent);
     612           2 :                         state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).OutletNodeNum =
     613           4 :                             NodeInputManager::GetOnlySingleNode(state,
     614           2 :                                                                 cAlphaArgs(aArgCount + 1),
     615             :                                                                 ErrorsFound,
     616             :                                                                 DataLoopNode::ConnectionObjectType::PlantComponentUserDefined,
     617           2 :                                                                 cAlphaArgs(1),
     618             :                                                                 DataLoopNode::NodeFluidType::Water,
     619             :                                                                 DataLoopNode::ConnectionType::Outlet,
     620             :                                                                 static_cast<NodeInputManager::CompFluidStream>(ConnectionLoop),
     621           2 :                                                                 DataLoopNode::ObjectIsNotParent);
     622             : 
     623           2 :                         BranchNodeConnections::TestCompSet(
     624           4 :                             state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(aArgCount), cAlphaArgs(aArgCount + 1), "Plant Nodes " + LoopStr);
     625             : 
     626             :                         {
     627           2 :                             state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HowLoadServed =
     628             :                                 static_cast<DataPlant::HowMet>(
     629           4 :                                     getEnumerationValue(DataPlant::HowMetTypeNamesUC, UtilityRoutines::MakeUPPERCase(cAlphaArgs(aArgCount + 2))));
     630           2 :                             if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HowLoadServed ==
     631             :                                 DataPlant::HowMet::ByNominalCapLowOutLimit) {
     632             :                                 // actuator for low out limit
     633          10 :                                 SetupEMSActuator(state,
     634           4 :                                                  "Plant Connection " + LoopStr,
     635           2 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     636             :                                                  "Low Outlet Temperature Limit",
     637             :                                                  "[C]",
     638           2 :                                                  state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     639           4 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).LowOutTempLimit);
     640           0 :                             } else if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HowLoadServed ==
     641             :                                        DataPlant::HowMet::ByNominalCapHiOutLimit) {
     642             :                                 // actuator for hi out limit
     643           0 :                                 SetupEMSActuator(state,
     644           0 :                                                  "Plant Connection " + LoopStr,
     645           0 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     646             :                                                  "High Outlet Temperature Limit",
     647             :                                                  "[C]",
     648           0 :                                                  state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     649           0 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HiOutTempLimit);
     650             :                             }
     651             :                         }
     652             : 
     653             :                         {
     654           2 :                             state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).FlowPriority =
     655           6 :                                 static_cast<DataPlant::LoopFlowStatus>(getEnumerationValue(
     656           6 :                                     DataPlant::LoopFlowStatusTypeNamesUC, UtilityRoutines::MakeUPPERCase(cAlphaArgs(aArgCount + 3))));
     657             :                         }
     658             : 
     659             :                         // find program manager for initial setup, begin environment and sizing of this plant connection
     660           2 :                         if (!lAlphaFieldBlanks(aArgCount + 4)) {
     661             :                             int StackMngrNum =
     662           2 :                                 UtilityRoutines::FindItemInList(cAlphaArgs(aArgCount + 4), state.dataRuntimeLang->EMSProgramCallManager);
     663           2 :                             if (StackMngrNum > 0) { // found it
     664           1 :                                 state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).ErlInitProgramMngr = StackMngrNum;
     665             :                             } else {
     666           1 :                                 state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).initPluginLocation =
     667           1 :                                     state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(aArgCount + 4));
     668           1 :                                 if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).initPluginLocation == -1) {
     669           0 :                                     ShowSevereError(state, "Invalid " + cAlphaFieldNames(aArgCount + 4) + '=' + cAlphaArgs(aArgCount + 4));
     670           0 :                                     ShowContinueError(state, "Entered in " + cCurrentModuleObject + '=' + cAlphaArgs(1));
     671           0 :                                     ShowContinueError(state,
     672             :                                                       "Program Manager Name not found as an EMS Program Manager or a Python Plugin Instance object.");
     673           0 :                                     ErrorsFound = true;
     674             :                                 }
     675             :                             }
     676             :                         }
     677             : 
     678             :                         // find program to call for model simulations for just this plant connection
     679           2 :                         if (!lAlphaFieldBlanks(aArgCount + 5)) {
     680             :                             int StackMngrNum =
     681           2 :                                 UtilityRoutines::FindItemInList(cAlphaArgs(aArgCount + 5), state.dataRuntimeLang->EMSProgramCallManager);
     682           2 :                             if (StackMngrNum > 0) { // found it
     683           1 :                                 state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).ErlSimProgramMngr = StackMngrNum;
     684             :                             } else {
     685           1 :                                 state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).simPluginLocation =
     686           1 :                                     state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(aArgCount + 5));
     687           1 :                                 if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).simPluginLocation == -1) {
     688           0 :                                     ShowSevereError(state, "Invalid " + cAlphaFieldNames(aArgCount + 4) + '=' + cAlphaArgs(aArgCount + 4));
     689           0 :                                     ShowContinueError(state, "Entered in " + cCurrentModuleObject + '=' + cAlphaArgs(1));
     690           0 :                                     ShowContinueError(state, "Program Manager Name not found.");
     691           0 :                                     ErrorsFound = true;
     692             :                                 }
     693             :                             }
     694             :                         }
     695             :                         // Setup Internal Variables
     696             :                         // model input related internal variables
     697           8 :                         SetupEMSInternalVariable(state,
     698           4 :                                                  "Inlet Temperature for Plant Connection " + LoopStr,
     699           2 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     700             :                                                  "[C]",
     701           4 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletTemp);
     702           8 :                         SetupEMSInternalVariable(state,
     703           4 :                                                  "Inlet Mass Flow Rate for Plant Connection " + LoopStr,
     704           2 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     705             :                                                  "[kg/s]",
     706           4 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletMassFlowRate);
     707           2 :                         if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HowLoadServed !=
     708             :                             DataPlant::HowMet::NoneDemand) {
     709           8 :                             SetupEMSInternalVariable(state,
     710           4 :                                                      "Load Request for Plant Connection " + LoopStr,
     711           2 :                                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     712             :                                                      "[W]",
     713           4 :                                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MyLoad);
     714             :                         }
     715           8 :                         SetupEMSInternalVariable(state,
     716           4 :                                                  "Inlet Density for Plant Connection " + LoopStr,
     717           2 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     718             :                                                  "[kg/m3]",
     719           4 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletRho);
     720           8 :                         SetupEMSInternalVariable(state,
     721           4 :                                                  "Inlet Specific Heat for Plant Connection " + LoopStr,
     722           2 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     723             :                                                  "[J/kg-C]",
     724           4 :                                                  state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletCp);
     725             :                         // model results related actuators
     726          10 :                         SetupEMSActuator(state,
     727           4 :                                          "Plant Connection " + LoopStr,
     728           2 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     729             :                                          "Outlet Temperature",
     730             :                                          "[C]",
     731           2 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     732           4 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).OutletTemp);
     733          10 :                         SetupEMSActuator(state,
     734           4 :                                          "Plant Connection " + LoopStr,
     735           2 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     736             :                                          "Mass Flow Rate",
     737             :                                          "[kg/s]",
     738           2 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     739           4 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MassFlowRateRequest);
     740             :                         // model initialization and sizing related actuators
     741          10 :                         SetupEMSActuator(state,
     742           4 :                                          "Plant Connection " + LoopStr,
     743           2 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     744             :                                          "Minimum Mass Flow Rate",
     745             :                                          "[kg/s]",
     746           2 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     747           4 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MassFlowRateMin);
     748          10 :                         SetupEMSActuator(state,
     749           4 :                                          "Plant Connection " + LoopStr,
     750           2 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     751             :                                          "Maximum Mass Flow Rate",
     752             :                                          "[kg/s]",
     753           2 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     754           4 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MassFlowRateMax);
     755          10 :                         SetupEMSActuator(state,
     756           4 :                                          "Plant Connection " + LoopStr,
     757           2 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     758             :                                          "Design Volume Flow Rate",
     759             :                                          "[m3/s]",
     760           2 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     761           4 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).DesignVolumeFlowRate);
     762          10 :                         SetupEMSActuator(state,
     763           4 :                                          "Plant Connection " + LoopStr,
     764           2 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     765             :                                          "Minimum Loading Capacity",
     766             :                                          "[W]",
     767           2 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     768           4 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MinLoad);
     769          10 :                         SetupEMSActuator(state,
     770           4 :                                          "Plant Connection " + LoopStr,
     771           2 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     772             :                                          "Maximum Loading Capacity",
     773             :                                          "[W]",
     774           2 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     775           4 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MaxLoad);
     776          10 :                         SetupEMSActuator(state,
     777           4 :                                          "Plant Connection " + LoopStr,
     778           2 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     779             :                                          "Optimal Loading Capacity",
     780             :                                          "[W]",
     781           2 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     782           4 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).OptLoad);
     783             :                     }
     784             :                 }
     785             : 
     786           2 :                 if (!lAlphaFieldBlanks(27)) {
     787           2 :                     state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.InletNodeNum =
     788           6 :                         NodeInputManager::GetOnlySingleNode(state,
     789           2 :                                                             cAlphaArgs(27),
     790             :                                                             ErrorsFound,
     791             :                                                             DataLoopNode::ConnectionObjectType::PlantComponentUserDefined,
     792           2 :                                                             state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     793             :                                                             DataLoopNode::NodeFluidType::Air,
     794             :                                                             DataLoopNode::ConnectionType::OutsideAirReference,
     795             :                                                             NodeInputManager::CompFluidStream::Primary,
     796           2 :                                                             DataLoopNode::ObjectIsNotParent);
     797             :                     // model input related internal variables
     798           6 :                     SetupEMSInternalVariable(state,
     799             :                                              "Inlet Temperature for Air Connection",
     800           2 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     801             :                                              "[C]",
     802           6 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.InletTemp);
     803           6 :                     SetupEMSInternalVariable(state,
     804             :                                              "Inlet Mass Flow Rate for Air Connection",
     805           2 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     806             :                                              "[kg/s]",
     807           6 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.InletMassFlowRate);
     808           6 :                     SetupEMSInternalVariable(state,
     809             :                                              "Inlet Humidity Ratio for Air Connection",
     810           2 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     811             :                                              "[kgWater/kgDryAir]",
     812           6 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.InletHumRat);
     813           6 :                     SetupEMSInternalVariable(state,
     814             :                                              "Inlet Density for Air Connection",
     815           2 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     816             :                                              "[kg/m3]",
     817           6 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.InletRho);
     818           6 :                     SetupEMSInternalVariable(state,
     819             :                                              "Inlet Specific Heat for Air Connection",
     820           2 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     821             :                                              "[J/kg-C]",
     822           6 :                                              state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.InletCp);
     823             :                 }
     824             : 
     825           2 :                 if (!lAlphaFieldBlanks(28)) {
     826           2 :                     state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.OutletNodeNum =
     827           6 :                         NodeInputManager::GetOnlySingleNode(state,
     828           2 :                                                             cAlphaArgs(28),
     829             :                                                             ErrorsFound,
     830             :                                                             DataLoopNode::ConnectionObjectType::PlantComponentUserDefined,
     831           2 :                                                             state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     832             :                                                             DataLoopNode::NodeFluidType::Air,
     833             :                                                             DataLoopNode::ConnectionType::ReliefAir,
     834             :                                                             NodeInputManager::CompFluidStream::Primary,
     835           2 :                                                             DataLoopNode::ObjectIsNotParent);
     836             :                     // outlet air node results
     837           8 :                     SetupEMSActuator(state,
     838             :                                      "Air Connection",
     839           2 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     840             :                                      "Outlet Temperature",
     841             :                                      "[C]",
     842           2 :                                      state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     843           6 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.OutletTemp);
     844           8 :                     SetupEMSActuator(state,
     845             :                                      "Air Connection",
     846           2 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     847             :                                      "Outlet Humidity Ratio",
     848             :                                      "[kgWater/kgDryAir]",
     849           2 :                                      state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     850           6 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.OutletHumRat);
     851           8 :                     SetupEMSActuator(state,
     852             :                                      "Air Connection",
     853           2 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     854             :                                      "Mass Flow Rate",
     855             :                                      "[kg/s]",
     856           2 :                                      state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     857           6 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Air.OutletMassFlowRate);
     858             :                 }
     859             : 
     860           2 :                 if (!lAlphaFieldBlanks(29)) {
     861           0 :                     WaterManager::SetupTankDemandComponent(state,
     862           0 :                                                            cAlphaArgs(1),
     863             :                                                            cCurrentModuleObject,
     864           0 :                                                            cAlphaArgs(29),
     865             :                                                            ErrorsFound,
     866           0 :                                                            state.dataUserDefinedComponents->UserPlantComp(CompLoop).Water.SupplyTankID,
     867           0 :                                                            state.dataUserDefinedComponents->UserPlantComp(CompLoop).Water.SupplyTankDemandARRID);
     868             : 
     869           0 :                     state.dataUserDefinedComponents->UserPlantComp(CompLoop).Water.SuppliedByWaterSystem = true;
     870           0 :                     SetupEMSActuator(state,
     871             :                                      "Water System",
     872           0 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     873             :                                      "Supplied Volume Flow Rate",
     874             :                                      "[m3/s]",
     875           0 :                                      state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     876           0 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Water.SupplyVdotRequest);
     877             :                 }
     878             : 
     879           2 :                 if (!lAlphaFieldBlanks(30)) {
     880           0 :                     WaterManager::SetupTankSupplyComponent(state,
     881           0 :                                                            cAlphaArgs(1),
     882             :                                                            cCurrentModuleObject,
     883           0 :                                                            cAlphaArgs(30),
     884             :                                                            ErrorsFound,
     885           0 :                                                            state.dataUserDefinedComponents->UserPlantComp(CompLoop).Water.CollectionTankID,
     886           0 :                                                            state.dataUserDefinedComponents->UserPlantComp(CompLoop).Water.CollectionTankSupplyARRID);
     887           0 :                     state.dataUserDefinedComponents->UserPlantComp(CompLoop).Water.CollectsToWaterSystem = true;
     888           0 :                     SetupEMSActuator(state,
     889             :                                      "Water System",
     890           0 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     891             :                                      "Collected Volume Flow Rate",
     892             :                                      "[m3/s]",
     893           0 :                                      state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     894           0 :                                      state.dataUserDefinedComponents->UserPlantComp(CompLoop).Water.CollectedVdot);
     895             :                 }
     896             : 
     897           2 :                 if (!lAlphaFieldBlanks(31)) {
     898             : 
     899           0 :                     state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ZoneNum =
     900           0 :                         UtilityRoutines::FindItemInList(cAlphaArgs(31), state.dataHeatBal->Zone);
     901           0 :                     if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ZoneNum == 0) {
     902           0 :                         ShowSevereError(state, cCurrentModuleObject + " = " + cAlphaArgs(1) + ":  Ambient Zone Name not found = " + cAlphaArgs(31));
     903           0 :                         ErrorsFound = true;
     904             :                     } else {
     905           0 :                         state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.DeviceHasInternalGains = true;
     906           0 :                         SetupZoneInternalGain(state,
     907           0 :                                               state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ZoneNum,
     908           0 :                                               cAlphaArgs(1),
     909             :                                               DataHeatBalance::IntGainType::PlantComponentUserDefined,
     910           0 :                                               &state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ConvectionGainRate,
     911           0 :                                               &state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ReturnAirConvectionGainRate,
     912           0 :                                               &state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ThermalRadiationGainRate,
     913           0 :                                               &state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.LatentGainRate,
     914           0 :                                               &state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ReturnAirLatentGainRate,
     915           0 :                                               &state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.CarbonDioxideGainRate,
     916           0 :                                               &state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.GenericContamGainRate);
     917             : 
     918           0 :                         SetupEMSActuator(state,
     919             :                                          "Component Zone Internal Gain",
     920           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     921             :                                          "Sensible Heat Gain Rate",
     922             :                                          "[W]",
     923           0 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     924           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ConvectionGainRate);
     925           0 :                         SetupEMSActuator(state,
     926             :                                          "Component Zone Internal Gain",
     927           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     928             :                                          "Return Air Heat Sensible Gain Rate",
     929             :                                          "[W]",
     930           0 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     931           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ReturnAirConvectionGainRate);
     932           0 :                         SetupEMSActuator(state,
     933             :                                          "Component Zone Internal Gain",
     934           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     935             :                                          "Thermal Radiation Heat Gain Rate",
     936             :                                          "[W]",
     937           0 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     938           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ThermalRadiationGainRate);
     939           0 :                         SetupEMSActuator(state,
     940             :                                          "Component Zone Internal Gain",
     941           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     942             :                                          "Latent Heat Gain Rate",
     943             :                                          "[W]",
     944           0 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     945           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.LatentGainRate);
     946           0 :                         SetupEMSActuator(state,
     947             :                                          "Component Zone Internal Gain",
     948           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     949             :                                          "Return Air Latent Heat Gain Rate",
     950             :                                          "[W]",
     951           0 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     952           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.ReturnAirLatentGainRate);
     953           0 :                         SetupEMSActuator(state,
     954             :                                          "Component Zone Internal Gain",
     955           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     956             :                                          "Carbon Dioxide Gain Rate",
     957             :                                          "[W]",
     958           0 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     959           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.CarbonDioxideGainRate);
     960           0 :                         SetupEMSActuator(state,
     961             :                                          "Component Zone Internal Gain",
     962           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name,
     963             :                                          "Gaseous Contaminant Gain Rate",
     964             :                                          "[W]",
     965           0 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
     966           0 :                                          state.dataUserDefinedComponents->UserPlantComp(CompLoop).Zone.GenericContamGainRate);
     967             :                     }
     968             :                 }
     969             : 
     970             :                 // make sure user has entered at least some erl program managers to actually calculate something
     971           2 :                 int MgrCountTest = 0;
     972           2 :                 if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).ErlSimProgramMngr > 0) MgrCountTest = 1;
     973           4 :                 for (int ConnectionLoop = 1; ConnectionLoop <= NumPlantConnections; ++ConnectionLoop) {
     974           2 :                     if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).ErlInitProgramMngr > 0) ++MgrCountTest;
     975           2 :                     if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).ErlSimProgramMngr > 0) ++MgrCountTest;
     976           2 :                     if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).initPluginLocation >= 0) ++MgrCountTest;
     977           2 :                     if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).simPluginLocation >= 0) ++MgrCountTest;
     978             :                 }
     979           2 :                 if (MgrCountTest == 0) {
     980           0 :                     ShowSevereError(state, "Invalid " + cCurrentModuleObject + '=' + cAlphaArgs(1));
     981           0 :                     ShowContinueError(state, "At least one program calling manager is needed.");
     982           0 :                     ErrorsFound = true;
     983             :                 }
     984             :             }
     985             :         } // NumUserPlantComps > 0
     986             : 
     987           4 :         if (ErrorsFound) {
     988           0 :             ShowFatalError(state, "GetUserDefinedComponents: Errors found in processing " + cCurrentModuleObject + " input.");
     989             :         }
     990             : 
     991           4 :         cCurrentModuleObject = "Coil:UserDefined";
     992           4 :         state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(state, cCurrentModuleObject, TotalArgs, NumAlphas, NumNums);
     993             : 
     994           4 :         cAlphaFieldNames.allocate(NumAlphas);
     995           4 :         cAlphaArgs.allocate(NumAlphas);
     996           4 :         lAlphaFieldBlanks.dimension(NumAlphas, false);
     997           4 :         rNumericArgs.dimension(NumNums, 0.0);
     998             : 
     999           4 :         state.dataUserDefinedComponents->NumUserCoils = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
    1000             : 
    1001           4 :         if (state.dataUserDefinedComponents->NumUserCoils > 0) {
    1002           2 :             state.dataUserDefinedComponents->UserCoil.allocate(state.dataUserDefinedComponents->NumUserCoils);
    1003           2 :             state.dataUserDefinedComponents->CheckUserCoilName.dimension(state.dataUserDefinedComponents->NumUserCoils, true);
    1004           8 :             for (int CompLoop = 1; CompLoop <= state.dataUserDefinedComponents->NumUserCoils; ++CompLoop) {
    1005           6 :                 state.dataInputProcessing->inputProcessor->getObjectItem(state,
    1006             :                                                                          cCurrentModuleObject,
    1007             :                                                                          CompLoop,
    1008             :                                                                          cAlphaArgs,
    1009             :                                                                          NumAlphas,
    1010             :                                                                          rNumericArgs,
    1011             :                                                                          NumNums,
    1012             :                                                                          IOStat,
    1013             :                                                                          _,
    1014             :                                                                          lAlphaFieldBlanks,
    1015             :                                                                          cAlphaFieldNames,
    1016             :                                                                          _);
    1017           6 :                 UtilityRoutines::IsNameEmpty(state, cAlphaArgs(1), cCurrentModuleObject, ErrorsFound);
    1018             : 
    1019             :                 // ErrorsFound will be set to True if problem was found, left untouched otherwise
    1020           6 :                 GlobalNames::VerifyUniqueCoilName(state, cCurrentModuleObject, cAlphaArgs(1), ErrorsFound, cCurrentModuleObject + " Name");
    1021             : 
    1022           6 :                 state.dataUserDefinedComponents->UserCoil(CompLoop).Name = cAlphaArgs(1);
    1023             : 
    1024             :                 // now get program manager for model simulations
    1025           6 :                 if (!lAlphaFieldBlanks(2)) {
    1026           6 :                     int StackMngrNum = UtilityRoutines::FindItemInList(cAlphaArgs(2), state.dataRuntimeLang->EMSProgramCallManager);
    1027           6 :                     if (StackMngrNum > 0) { // found it
    1028           6 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).ErlSimProgramMngr = StackMngrNum;
    1029             :                     } else {
    1030           0 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).simPluginLocation =
    1031           0 :                             state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(2));
    1032           0 :                         if (state.dataUserDefinedComponents->UserCoil(CompLoop).simPluginLocation == -1) {
    1033           0 :                             ShowSevereError(state, "Invalid " + cAlphaFieldNames(2) + '=' + cAlphaArgs(2));
    1034           0 :                             ShowContinueError(state, "Entered in " + cCurrentModuleObject + '=' + cAlphaArgs(1));
    1035           0 :                             ShowContinueError(state, "Program Manager Name not found as an EMS Program Manager or a Python Plugin Instance object.");
    1036           0 :                             ErrorsFound = true;
    1037             :                         }
    1038             :                     }
    1039             :                 }
    1040             : 
    1041             :                 // now get program manager for model initializations
    1042           6 :                 if (!lAlphaFieldBlanks(3)) {
    1043           6 :                     int StackMngrNum = UtilityRoutines::FindItemInList(cAlphaArgs(3), state.dataRuntimeLang->EMSProgramCallManager);
    1044           6 :                     if (StackMngrNum > 0) { // found it
    1045           6 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).ErlInitProgramMngr = StackMngrNum;
    1046             :                     } else {
    1047           0 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).initPluginLocation =
    1048           0 :                             state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(3));
    1049           0 :                         if (state.dataUserDefinedComponents->UserCoil(CompLoop).initPluginLocation == -1) {
    1050           0 :                             ShowSevereError(state, "Invalid " + cAlphaFieldNames(3) + '=' + cAlphaArgs(3));
    1051           0 :                             ShowContinueError(state, "Entered in " + cCurrentModuleObject + '=' + cAlphaArgs(1));
    1052           0 :                             ShowContinueError(state, "Program Manager Name not found as an EMS Program Manager or a Python Plugin Instance object.");
    1053           0 :                             ErrorsFound = true;
    1054             :                         }
    1055             :                     }
    1056             :                 }
    1057             : 
    1058           6 :                 int NumAirConnections = std::floor(rNumericArgs(1));
    1059           6 :                 if ((NumAirConnections >= 1) && (NumAirConnections <= 2)) {
    1060           6 :                     state.dataUserDefinedComponents->UserCoil(CompLoop).Air.allocate(NumAirConnections);
    1061           6 :                     state.dataUserDefinedComponents->UserCoil(CompLoop).NumAirConnections = NumAirConnections;
    1062          12 :                     for (int ConnectionLoop = 1; ConnectionLoop <= NumAirConnections; ++ConnectionLoop) {
    1063           6 :                         int aArgCount = (ConnectionLoop - 1) * 2 + 4;
    1064           6 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletNodeNum =
    1065          18 :                             NodeInputManager::GetOnlySingleNode(state,
    1066           6 :                                                                 cAlphaArgs(aArgCount),
    1067             :                                                                 ErrorsFound,
    1068             :                                                                 DataLoopNode::ConnectionObjectType::CoilUserDefined,
    1069           6 :                                                                 state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1070             :                                                                 DataLoopNode::NodeFluidType::Air,
    1071             :                                                                 DataLoopNode::ConnectionType::Inlet,
    1072             :                                                                 static_cast<NodeInputManager::CompFluidStream>(ConnectionLoop),
    1073           6 :                                                                 DataLoopNode::ObjectIsNotParent);
    1074             : 
    1075          12 :                         const auto LoopStr = fmt::to_string(ConnectionLoop);
    1076             :                         // model input related internal variables
    1077          24 :                         SetupEMSInternalVariable(state,
    1078          12 :                                                  "Inlet Temperature for Air Connection " + LoopStr,
    1079           6 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1080             :                                                  "[C]",
    1081          12 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletTemp);
    1082          24 :                         SetupEMSInternalVariable(state,
    1083          12 :                                                  "Inlet Mass Flow Rate for Air Connection " + LoopStr,
    1084           6 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1085             :                                                  "[kg/s]",
    1086          12 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletMassFlowRate);
    1087          24 :                         SetupEMSInternalVariable(state,
    1088          12 :                                                  "Inlet Humidity Ratio for Air Connection " + LoopStr,
    1089           6 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1090             :                                                  "[kgWater/kgDryAir]",
    1091          12 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletHumRat);
    1092          24 :                         SetupEMSInternalVariable(state,
    1093          12 :                                                  "Inlet Density for Air Connection " + LoopStr,
    1094           6 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1095             :                                                  "[kg/m3]",
    1096          12 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletRho);
    1097          24 :                         SetupEMSInternalVariable(state,
    1098          12 :                                                  "Inlet Specific Heat for Air Connection " + LoopStr,
    1099           6 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1100             :                                                  "[J/kg-C]",
    1101          12 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletCp);
    1102             : 
    1103           6 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).OutletNodeNum =
    1104          18 :                             NodeInputManager::GetOnlySingleNode(state,
    1105           6 :                                                                 cAlphaArgs(aArgCount + 1),
    1106             :                                                                 ErrorsFound,
    1107             :                                                                 DataLoopNode::ConnectionObjectType::CoilUserDefined,
    1108           6 :                                                                 state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1109             :                                                                 DataLoopNode::NodeFluidType::Air,
    1110             :                                                                 DataLoopNode::ConnectionType::Outlet,
    1111             :                                                                 static_cast<NodeInputManager::CompFluidStream>(ConnectionLoop),
    1112           6 :                                                                 DataLoopNode::ObjectIsNotParent);
    1113          30 :                         SetupEMSActuator(state,
    1114          12 :                                          "Air Connection " + LoopStr,
    1115           6 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1116             :                                          "Outlet Temperature",
    1117             :                                          "[C]",
    1118           6 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1119          12 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).OutletTemp);
    1120          30 :                         SetupEMSActuator(state,
    1121          12 :                                          "Air Connection " + LoopStr,
    1122           6 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1123             :                                          "Outlet Humidity Ratio",
    1124             :                                          "[kgWater/kgDryAir]",
    1125           6 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1126          12 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).OutletHumRat);
    1127          30 :                         SetupEMSActuator(state,
    1128          12 :                                          "Air Connection " + LoopStr,
    1129           6 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1130             :                                          "Mass Flow Rate",
    1131             :                                          "[kg/s]",
    1132           6 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1133          12 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).OutletMassFlowRate);
    1134             : 
    1135           6 :                         BranchNodeConnections::TestCompSet(
    1136          12 :                             state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(aArgCount), cAlphaArgs(aArgCount + 1), "Air Nodes " + LoopStr);
    1137             :                     }
    1138             : 
    1139           6 :                     if (!lAlphaFieldBlanks(8)) {
    1140           6 :                         if (cAlphaArgs(8) == "YES") {
    1141           6 :                             state.dataUserDefinedComponents->UserCoil(CompLoop).PlantIsConnected = true;
    1142           0 :                         } else if (cAlphaArgs(8) == "NO") {
    1143           0 :                             state.dataUserDefinedComponents->UserCoil(CompLoop).PlantIsConnected = false;
    1144             :                         }
    1145             :                     } else {
    1146           0 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).PlantIsConnected = false;
    1147             :                     }
    1148             : 
    1149           6 :                     if (state.dataUserDefinedComponents->UserCoil(CompLoop).PlantIsConnected) { // get input
    1150           6 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.InletNodeNum =
    1151          12 :                             NodeInputManager::GetOnlySingleNode(state,
    1152           6 :                                                                 cAlphaArgs(9),
    1153             :                                                                 ErrorsFound,
    1154             :                                                                 DataLoopNode::ConnectionObjectType::CoilUserDefined,
    1155           6 :                                                                 cAlphaArgs(1),
    1156             :                                                                 DataLoopNode::NodeFluidType::Water,
    1157             :                                                                 DataLoopNode::ConnectionType::Inlet,
    1158             :                                                                 NodeInputManager::CompFluidStream::Tertiary,
    1159           6 :                                                                 DataLoopNode::ObjectIsNotParent);
    1160           6 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.OutletNodeNum =
    1161          12 :                             NodeInputManager::GetOnlySingleNode(state,
    1162           6 :                                                                 cAlphaArgs(10),
    1163             :                                                                 ErrorsFound,
    1164             :                                                                 DataLoopNode::ConnectionObjectType::CoilUserDefined,
    1165           6 :                                                                 cAlphaArgs(1),
    1166             :                                                                 DataLoopNode::NodeFluidType::Water,
    1167             :                                                                 DataLoopNode::ConnectionType::Outlet,
    1168             :                                                                 NodeInputManager::CompFluidStream::Tertiary,
    1169           6 :                                                                 DataLoopNode::ObjectIsNotParent);
    1170             : 
    1171           6 :                         BranchNodeConnections::TestCompSet(state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(9), cAlphaArgs(10), "Plant Nodes");
    1172             : 
    1173             :                         // this model is only for plant connections that are "Demand"
    1174           6 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.HowLoadServed = DataPlant::HowMet::NoneDemand;
    1175             :                         // this model is only for plant connections that are needy and turn loop on
    1176           6 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.FlowPriority = DataPlant::LoopFlowStatus::NeedyAndTurnsLoopOn;
    1177             : 
    1178             :                         // Setup Internal Variables
    1179             :                         // model input related internal variables
    1180          18 :                         SetupEMSInternalVariable(state,
    1181             :                                                  "Inlet Temperature for Plant Connection",
    1182           6 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1183             :                                                  "[C]",
    1184          18 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.InletTemp);
    1185          18 :                         SetupEMSInternalVariable(state,
    1186             :                                                  "Inlet Mass Flow Rate for Plant Connection",
    1187           6 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1188             :                                                  "[kg/s]",
    1189          18 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.InletMassFlowRate);
    1190          18 :                         SetupEMSInternalVariable(state,
    1191             :                                                  "Inlet Density for Plant Connection",
    1192           6 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1193             :                                                  "[kg/m3]",
    1194          18 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.InletRho);
    1195          18 :                         SetupEMSInternalVariable(state,
    1196             :                                                  "Inlet Specific Heat for Plant Connection",
    1197           6 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1198             :                                                  "[J/kg-C]",
    1199          18 :                                                  state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.InletCp);
    1200             :                         // model results related actuators
    1201          24 :                         SetupEMSActuator(state,
    1202             :                                          "Plant Connection",
    1203           6 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1204             :                                          "Outlet Temperature",
    1205             :                                          "[C]",
    1206           6 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1207          18 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.OutletTemp);
    1208          24 :                         SetupEMSActuator(state,
    1209             :                                          "Plant Connection",
    1210           6 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1211             :                                          "Mass Flow Rate",
    1212             :                                          "[kg/s]",
    1213           6 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1214          18 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.MassFlowRateRequest);
    1215             :                         // model initialization and sizing related actuators
    1216          24 :                         SetupEMSActuator(state,
    1217             :                                          "Plant Connection",
    1218           6 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1219             :                                          "Design Volume Flow Rate",
    1220             :                                          "[m3/s]",
    1221           6 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1222          18 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.DesignVolumeFlowRate);
    1223             : 
    1224          24 :                         SetupEMSActuator(state,
    1225             :                                          "Plant Connection",
    1226           6 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1227             :                                          "Minimum Mass Flow Rate",
    1228             :                                          "[kg/s]",
    1229           6 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1230          18 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.MassFlowRateMin);
    1231          24 :                         SetupEMSActuator(state,
    1232             :                                          "Plant Connection",
    1233           6 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1234             :                                          "Maximum Mass Flow Rate",
    1235             :                                          "[kg/s]",
    1236           6 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1237          18 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Loop.MassFlowRateMax);
    1238             :                     }
    1239             : 
    1240           6 :                     if (!lAlphaFieldBlanks(11)) {
    1241           0 :                         WaterManager::SetupTankDemandComponent(state,
    1242           0 :                                                                cAlphaArgs(1),
    1243             :                                                                cCurrentModuleObject,
    1244           0 :                                                                cAlphaArgs(11),
    1245             :                                                                ErrorsFound,
    1246           0 :                                                                state.dataUserDefinedComponents->UserCoil(CompLoop).Water.SupplyTankID,
    1247           0 :                                                                state.dataUserDefinedComponents->UserCoil(CompLoop).Water.SupplyTankDemandARRID);
    1248             : 
    1249           0 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).Water.SuppliedByWaterSystem = true;
    1250           0 :                         SetupEMSActuator(state,
    1251             :                                          "Water System",
    1252           0 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1253             :                                          "Supplied Volume Flow Rate",
    1254             :                                          "[m3/s]",
    1255           0 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1256           0 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Water.SupplyVdotRequest);
    1257             :                     }
    1258             : 
    1259           6 :                     if (!lAlphaFieldBlanks(12)) {
    1260           0 :                         WaterManager::SetupTankSupplyComponent(state,
    1261           0 :                                                                cAlphaArgs(1),
    1262             :                                                                cCurrentModuleObject,
    1263           0 :                                                                cAlphaArgs(12),
    1264             :                                                                ErrorsFound,
    1265           0 :                                                                state.dataUserDefinedComponents->UserCoil(CompLoop).Water.CollectionTankID,
    1266           0 :                                                                state.dataUserDefinedComponents->UserCoil(CompLoop).Water.CollectionTankSupplyARRID);
    1267           0 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).Water.CollectsToWaterSystem = true;
    1268           0 :                         SetupEMSActuator(state,
    1269             :                                          "Water System",
    1270           0 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1271             :                                          "Collected Volume Flow Rate",
    1272             :                                          "[m3/s]",
    1273           0 :                                          state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1274           0 :                                          state.dataUserDefinedComponents->UserCoil(CompLoop).Water.CollectedVdot);
    1275             :                     }
    1276             : 
    1277           6 :                     if (!lAlphaFieldBlanks(13)) {
    1278             : 
    1279           0 :                         state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ZoneNum =
    1280           0 :                             UtilityRoutines::FindItemInList(cAlphaArgs(13), state.dataHeatBal->Zone);
    1281           0 :                         if (state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ZoneNum == 0) {
    1282           0 :                             ShowSevereError(state,
    1283           0 :                                             cCurrentModuleObject + " = " + cAlphaArgs(1) + ":  Ambient Zone Name not found = " + cAlphaArgs(13));
    1284           0 :                             ErrorsFound = true;
    1285             :                         } else {
    1286           0 :                             state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.DeviceHasInternalGains = true;
    1287           0 :                             SetupZoneInternalGain(state,
    1288           0 :                                                   state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ZoneNum,
    1289           0 :                                                   cAlphaArgs(1),
    1290             :                                                   DataHeatBalance::IntGainType::CoilUserDefined,
    1291           0 :                                                   &state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ConvectionGainRate,
    1292           0 :                                                   &state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ReturnAirConvectionGainRate,
    1293           0 :                                                   &state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ThermalRadiationGainRate,
    1294           0 :                                                   &state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.LatentGainRate,
    1295           0 :                                                   &state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ReturnAirLatentGainRate,
    1296           0 :                                                   &state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.CarbonDioxideGainRate,
    1297           0 :                                                   &state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.GenericContamGainRate);
    1298             : 
    1299           0 :                             SetupEMSActuator(state,
    1300             :                                              "Component Zone Internal Gain",
    1301           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1302             :                                              "Sensible Heat Gain Rate",
    1303             :                                              "[W]",
    1304           0 :                                              state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1305           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ConvectionGainRate);
    1306           0 :                             SetupEMSActuator(state,
    1307             :                                              "Component Zone Internal Gain",
    1308           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1309             :                                              "Return Air Heat Sensible Gain Rate",
    1310             :                                              "[W]",
    1311           0 :                                              state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1312           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ReturnAirConvectionGainRate);
    1313           0 :                             SetupEMSActuator(state,
    1314             :                                              "Component Zone Internal Gain",
    1315           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1316             :                                              "Thermal Radiation Heat Gain Rate",
    1317             :                                              "[W]",
    1318           0 :                                              state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1319           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ThermalRadiationGainRate);
    1320           0 :                             SetupEMSActuator(state,
    1321             :                                              "Component Zone Internal Gain",
    1322           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1323             :                                              "Latent Heat Gain Rate",
    1324             :                                              "[W]",
    1325           0 :                                              state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1326           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.LatentGainRate);
    1327           0 :                             SetupEMSActuator(state,
    1328             :                                              "Component Zone Internal Gain",
    1329           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1330             :                                              "Return Air Latent Heat Gain Rate",
    1331             :                                              "[W]",
    1332           0 :                                              state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1333           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.ReturnAirLatentGainRate);
    1334           0 :                             SetupEMSActuator(state,
    1335             :                                              "Component Zone Internal Gain",
    1336           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1337             :                                              "Carbon Dioxide Gain Rate",
    1338             :                                              "[W]",
    1339           0 :                                              state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1340           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.CarbonDioxideGainRate);
    1341           0 :                             SetupEMSActuator(state,
    1342             :                                              "Component Zone Internal Gain",
    1343           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Name,
    1344             :                                              "Gaseous Contaminant Gain Rate",
    1345             :                                              "[W]",
    1346           0 :                                              state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp,
    1347           0 :                                              state.dataUserDefinedComponents->UserCoil(CompLoop).Zone.GenericContamGainRate);
    1348             :                         }
    1349             :                     }
    1350             :                 }
    1351             :             }
    1352             : 
    1353             :         } // NumUserCoils > 0
    1354             : 
    1355           4 :         if (ErrorsFound) {
    1356           0 :             ShowFatalError(state, "GetUserDefinedComponents: Errors found in processing " + cCurrentModuleObject + " input.");
    1357             :         }
    1358           4 :     }
    1359             : 
    1360           4 :     void GetUserDefinedComponents(EnergyPlusData &state)
    1361             :     {
    1362             : 
    1363             :         // SUBROUTINE INFORMATION:
    1364             :         //       AUTHOR         B. Griffith
    1365             :         //       DATE WRITTEN   Jan 2012
    1366             :         //       MODIFIED       na
    1367             :         //       RE-ENGINEERED  na
    1368             : 
    1369           4 :         bool ErrorsFound(false);
    1370             :         int NumAlphas; // Number of elements in the alpha array
    1371             :         int NumNums;   // Number of elements in the numeric array
    1372             :         int IOStat;    // IO Status when calling get input subroutine
    1373             :         int TotalArgs; // argument for call to GetObjectDefMaxArgs
    1374           8 :         Array1D_string cAlphaFieldNames;
    1375           8 :         Array1D_bool lAlphaFieldBlanks;
    1376           8 :         Array1D_string cAlphaArgs;
    1377           8 :         Array1D<Real64> rNumericArgs;
    1378           8 :         std::string cCurrentModuleObject;
    1379             : 
    1380           4 :         if (state.dataUserDefinedComponents->GetPlantCompInput) {
    1381           2 :             GetUserDefinedPlantComponents(state);
    1382           2 :             state.dataUserDefinedComponents->GetPlantCompInput = false;
    1383             :         }
    1384             : 
    1385           4 :         cCurrentModuleObject = "ZoneHVAC:ForcedAir:UserDefined";
    1386           4 :         state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(state, cCurrentModuleObject, TotalArgs, NumAlphas, NumNums);
    1387             : 
    1388           4 :         cAlphaFieldNames.allocate(NumAlphas);
    1389           4 :         cAlphaArgs.allocate(NumAlphas);
    1390           4 :         lAlphaFieldBlanks.dimension(NumAlphas, false);
    1391           4 :         rNumericArgs.dimension(NumNums, 0.0);
    1392             : 
    1393           4 :         state.dataUserDefinedComponents->NumUserZoneAir = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
    1394           4 :         if (state.dataUserDefinedComponents->NumUserZoneAir > 0) {
    1395           2 :             state.dataUserDefinedComponents->UserZoneAirHVAC.allocate(state.dataUserDefinedComponents->NumUserZoneAir);
    1396           2 :             state.dataUserDefinedComponents->CheckUserZoneAirName.dimension(state.dataUserDefinedComponents->NumUserZoneAir, true);
    1397           8 :             for (int CompLoop = 1; CompLoop <= state.dataUserDefinedComponents->NumUserZoneAir; ++CompLoop) {
    1398           6 :                 state.dataInputProcessing->inputProcessor->getObjectItem(state,
    1399             :                                                                          cCurrentModuleObject,
    1400             :                                                                          CompLoop,
    1401             :                                                                          cAlphaArgs,
    1402             :                                                                          NumAlphas,
    1403             :                                                                          rNumericArgs,
    1404             :                                                                          NumNums,
    1405             :                                                                          IOStat,
    1406             :                                                                          _,
    1407             :                                                                          lAlphaFieldBlanks,
    1408             :                                                                          cAlphaFieldNames,
    1409             :                                                                          _);
    1410           6 :                 UtilityRoutines::IsNameEmpty(state, cAlphaArgs(1), cCurrentModuleObject, ErrorsFound);
    1411           6 :                 state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name = cAlphaArgs(1);
    1412             : 
    1413             :                 // now get program manager for model simulations
    1414           6 :                 if (!lAlphaFieldBlanks(2)) {
    1415           6 :                     int StackMngrNum = UtilityRoutines::FindItemInList(cAlphaArgs(2), state.dataRuntimeLang->EMSProgramCallManager);
    1416           6 :                     if (StackMngrNum > 0) { // found it
    1417           5 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ErlSimProgramMngr = StackMngrNum;
    1418             :                     } else {
    1419           1 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).simPluginLocation =
    1420           1 :                             state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(2));
    1421           1 :                         if (state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).simPluginLocation == -1) {
    1422           0 :                             ShowSevereError(state, "Invalid " + cAlphaFieldNames(2) + '=' + cAlphaArgs(2));
    1423           0 :                             ShowContinueError(state, "Entered in " + cCurrentModuleObject + '=' + cAlphaArgs(1));
    1424           0 :                             ShowContinueError(state, "Program Manager Name not found as an EMS Program Manager or a Python Plugin Instance object.");
    1425           0 :                             ErrorsFound = true;
    1426             :                         }
    1427             :                     }
    1428             :                 }
    1429             : 
    1430             :                 // now get program manager for model initializations
    1431           6 :                 if (!lAlphaFieldBlanks(3)) {
    1432           5 :                     int StackMngrNum = UtilityRoutines::FindItemInList(cAlphaArgs(3), state.dataRuntimeLang->EMSProgramCallManager);
    1433           5 :                     if (StackMngrNum > 0) { // found it
    1434           5 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ErlInitProgramMngr = StackMngrNum;
    1435             :                     } else {
    1436           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).initPluginLocation =
    1437           0 :                             state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(3));
    1438           0 :                         if (state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).initPluginLocation == -1) {
    1439           0 :                             ShowSevereError(state, "Invalid " + cAlphaFieldNames(3) + '=' + cAlphaArgs(3));
    1440           0 :                             ShowContinueError(state, "Entered in " + cCurrentModuleObject + '=' + cAlphaArgs(1));
    1441           0 :                             ShowContinueError(state, "Program Manager Name not found as an EMS Program Manager or a Python Plugin Instance object.");
    1442           0 :                             ErrorsFound = true;
    1443             :                         }
    1444             :                     }
    1445             :                 }
    1446             : 
    1447           6 :                 state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.InletNodeNum =
    1448          18 :                     NodeInputManager::GetOnlySingleNode(state,
    1449           6 :                                                         cAlphaArgs(4),
    1450             :                                                         ErrorsFound,
    1451             :                                                         DataLoopNode::ConnectionObjectType::ZoneHVACForcedAirUserDefined,
    1452           6 :                                                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1453             :                                                         DataLoopNode::NodeFluidType::Air,
    1454             :                                                         DataLoopNode::ConnectionType::Inlet,
    1455             :                                                         NodeInputManager::CompFluidStream::Primary,
    1456           6 :                                                         DataLoopNode::ObjectIsNotParent);
    1457             :                 // model input related internal variables
    1458          18 :                 SetupEMSInternalVariable(state,
    1459             :                                          "Inlet Temperature for Primary Air Connection",
    1460           6 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1461             :                                          "[C]",
    1462          18 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.InletTemp);
    1463          18 :                 SetupEMSInternalVariable(state,
    1464             :                                          "Inlet Humidity Ratio for Primary Air Connection",
    1465           6 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1466             :                                          "[kgWater/kgDryAir]",
    1467          18 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.InletHumRat);
    1468          18 :                 SetupEMSInternalVariable(state,
    1469             :                                          "Inlet Density for Primary Air Connection",
    1470           6 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1471             :                                          "[kg/m3]",
    1472          18 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.InletRho);
    1473          18 :                 SetupEMSInternalVariable(state,
    1474             :                                          "Inlet Specific Heat for Primary Air Connection",
    1475           6 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1476             :                                          "[J/kg-C]",
    1477          18 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.InletCp);
    1478             : 
    1479          18 :                 SetupEMSInternalVariable(state,
    1480             :                                          "Remaining Sensible Load to Heating Setpoint",
    1481           6 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1482             :                                          "[W]",
    1483          18 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).RemainingOutputToHeatingSP);
    1484          18 :                 SetupEMSInternalVariable(state,
    1485             :                                          "Remaining Sensible Load to Cooling Setpoint",
    1486           6 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1487             :                                          "[W]",
    1488          18 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).RemainingOutputToCoolingSP);
    1489          18 :                 SetupEMSInternalVariable(state,
    1490             :                                          "Remaining Latent Load to Humidifying Setpoint",
    1491           6 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1492             :                                          "[kg/s]",
    1493          18 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).RemainingOutputReqToHumidSP);
    1494          18 :                 SetupEMSInternalVariable(state,
    1495             :                                          "Remaining Latent Load to Dehumidifying Setpoint",
    1496           6 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1497             :                                          "[kg/s]",
    1498          18 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).RemainingOutputReqToDehumidSP);
    1499             : 
    1500          24 :                 SetupEMSActuator(state,
    1501             :                                  "Primary Air Connection",
    1502           6 :                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1503             :                                  "Inlet Mass Flow Rate",
    1504             :                                  "[kg/s]",
    1505           6 :                                  state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1506          18 :                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.InletMassFlowRate);
    1507           6 :                 state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.OutletNodeNum =
    1508          18 :                     NodeInputManager::GetOnlySingleNode(state,
    1509           6 :                                                         cAlphaArgs(5),
    1510             :                                                         ErrorsFound,
    1511             :                                                         DataLoopNode::ConnectionObjectType::ZoneHVACForcedAirUserDefined,
    1512           6 :                                                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1513             :                                                         DataLoopNode::NodeFluidType::Air,
    1514             :                                                         DataLoopNode::ConnectionType::Outlet,
    1515             :                                                         NodeInputManager::CompFluidStream::Primary,
    1516           6 :                                                         DataLoopNode::ObjectIsNotParent);
    1517          24 :                 SetupEMSActuator(state,
    1518             :                                  "Primary Air Connection",
    1519           6 :                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1520             :                                  "Outlet Temperature",
    1521             :                                  "[C]",
    1522           6 :                                  state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1523          18 :                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.OutletTemp);
    1524          24 :                 SetupEMSActuator(state,
    1525             :                                  "Primary Air Connection",
    1526           6 :                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1527             :                                  "Outlet Humidity Ratio",
    1528             :                                  "[kgWater/kgDryAir]",
    1529           6 :                                  state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1530          18 :                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.OutletHumRat);
    1531          24 :                 SetupEMSActuator(state,
    1532             :                                  "Primary Air Connection",
    1533           6 :                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1534             :                                  "Outlet Mass Flow Rate",
    1535             :                                  "[kg/s]",
    1536           6 :                                  state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1537          18 :                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).ZoneAir.OutletMassFlowRate);
    1538             : 
    1539           6 :                 if (!lAlphaFieldBlanks(6)) {
    1540           6 :                     state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.InletNodeNum =
    1541          18 :                         NodeInputManager::GetOnlySingleNode(state,
    1542           6 :                                                             cAlphaArgs(6),
    1543             :                                                             ErrorsFound,
    1544             :                                                             DataLoopNode::ConnectionObjectType::ZoneHVACForcedAirUserDefined,
    1545           6 :                                                             state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1546             :                                                             DataLoopNode::NodeFluidType::Air,
    1547             :                                                             DataLoopNode::ConnectionType::Inlet,
    1548             :                                                             NodeInputManager::CompFluidStream::Secondary,
    1549           6 :                                                             DataLoopNode::ObjectIsNotParent);
    1550             :                     // model input related internal variables
    1551          18 :                     SetupEMSInternalVariable(state,
    1552             :                                              "Inlet Temperature for Secondary Air Connection",
    1553           6 :                                              state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1554             :                                              "[C]",
    1555          18 :                                              state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.InletTemp);
    1556             : 
    1557          18 :                     SetupEMSInternalVariable(state,
    1558             :                                              "Inlet Humidity Ratio for Secondary Air Connection",
    1559           6 :                                              state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1560             :                                              "[kgWater/kgDryAir]",
    1561          18 :                                              state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.InletHumRat);
    1562          18 :                     SetupEMSInternalVariable(state,
    1563             :                                              "Inlet Density for Secondary Air Connection",
    1564           6 :                                              state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1565             :                                              "[kg/m3]",
    1566          18 :                                              state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.InletRho);
    1567          18 :                     SetupEMSInternalVariable(state,
    1568             :                                              "Inlet Specific Heat for Secondary Air Connection",
    1569           6 :                                              state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1570             :                                              "[J/kg-C]",
    1571          18 :                                              state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.InletCp);
    1572          24 :                     SetupEMSActuator(state,
    1573             :                                      "Secondary Air Connection",
    1574           6 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1575             :                                      "Inlet Mass Flow Rate",
    1576             :                                      "[kg/s]",
    1577           6 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1578          18 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.InletMassFlowRate);
    1579             :                 }
    1580             : 
    1581           6 :                 if (!lAlphaFieldBlanks(7)) {
    1582           6 :                     state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.OutletNodeNum =
    1583          18 :                         NodeInputManager::GetOnlySingleNode(state,
    1584           6 :                                                             cAlphaArgs(7),
    1585             :                                                             ErrorsFound,
    1586             :                                                             DataLoopNode::ConnectionObjectType::ZoneHVACForcedAirUserDefined,
    1587           6 :                                                             state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1588             :                                                             DataLoopNode::NodeFluidType::Air,
    1589             :                                                             DataLoopNode::ConnectionType::Outlet,
    1590             :                                                             NodeInputManager::CompFluidStream::Secondary,
    1591           6 :                                                             DataLoopNode::ObjectIsNotParent);
    1592          24 :                     SetupEMSActuator(state,
    1593             :                                      "Secondary Air Connection",
    1594           6 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1595             :                                      "Outlet Temperature",
    1596             :                                      "[C]",
    1597           6 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1598          18 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.OutletTemp);
    1599          24 :                     SetupEMSActuator(state,
    1600             :                                      "Secondary Air Connection",
    1601           6 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1602             :                                      "Outlet Humidity Ratio",
    1603             :                                      "[kgWater/kgDryAir]",
    1604           6 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1605          18 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.OutletHumRat);
    1606          24 :                     SetupEMSActuator(state,
    1607             :                                      "Secondary Air Connection",
    1608           6 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1609             :                                      "Mass Flow Rate",
    1610             :                                      "[kg/s]",
    1611           6 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1612          18 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.OutletMassFlowRate);
    1613             :                 }
    1614             : 
    1615          12 :                 if ((state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.InletNodeNum > 0) &&
    1616           6 :                     (state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).SourceAir.OutletNodeNum > 0)) {
    1617             :                     //  CALL TestCompSet(state, TRIM(cCurrentModuleObject),cAlphaArgs(1),cAlphaArgs(6),cAlphaArgs(7),'Air Nodes')
    1618             :                 }
    1619             : 
    1620           6 :                 int NumPlantConnections = std::floor(rNumericArgs(1));
    1621           6 :                 state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).NumPlantConnections = NumPlantConnections;
    1622           6 :                 if ((NumPlantConnections >= 1) && (NumPlantConnections <= 3)) {
    1623           0 :                     state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop.allocate(NumPlantConnections);
    1624           0 :                     for (int ConnectionLoop = 1; ConnectionLoop <= NumPlantConnections; ++ConnectionLoop) {
    1625           0 :                         int aArgCount = (ConnectionLoop - 1) * 2 + 8;
    1626           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletNodeNum =
    1627           0 :                             NodeInputManager::GetOnlySingleNode(state,
    1628           0 :                                                                 cAlphaArgs(aArgCount),
    1629             :                                                                 ErrorsFound,
    1630             :                                                                 DataLoopNode::ConnectionObjectType::ZoneHVACForcedAirUserDefined,
    1631           0 :                                                                 cAlphaArgs(1),
    1632             :                                                                 DataLoopNode::NodeFluidType::Water,
    1633             :                                                                 DataLoopNode::ConnectionType::Inlet,
    1634           0 :                                                                 static_cast<NodeInputManager::CompFluidStream>(ConnectionLoop + 2),
    1635           0 :                                                                 DataLoopNode::ObjectIsNotParent);
    1636           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).OutletNodeNum =
    1637           0 :                             NodeInputManager::GetOnlySingleNode(state,
    1638           0 :                                                                 cAlphaArgs(aArgCount + 1),
    1639             :                                                                 ErrorsFound,
    1640             :                                                                 DataLoopNode::ConnectionObjectType::ZoneHVACForcedAirUserDefined,
    1641           0 :                                                                 cAlphaArgs(1),
    1642             :                                                                 DataLoopNode::NodeFluidType::Water,
    1643             :                                                                 DataLoopNode::ConnectionType::Outlet,
    1644           0 :                                                                 static_cast<NodeInputManager::CompFluidStream>(ConnectionLoop + 2),
    1645           0 :                                                                 DataLoopNode::ObjectIsNotParent);
    1646           0 :                         BranchNodeConnections::TestCompSet(
    1647           0 :                             state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(aArgCount), cAlphaArgs(aArgCount + 1), "Plant Nodes");
    1648           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).HowLoadServed = DataPlant::HowMet::NoneDemand;
    1649           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).FlowPriority =
    1650             :                             DataPlant::LoopFlowStatus::NeedyAndTurnsLoopOn;
    1651             :                         // Setup Internal Variables
    1652           0 :                         const auto LoopStr = fmt::to_string(ConnectionLoop);
    1653             :                         // model input related internal variables
    1654           0 :                         SetupEMSInternalVariable(state,
    1655           0 :                                                  "Inlet Temperature for Plant Connection " + LoopStr,
    1656           0 :                                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1657             :                                                  "[C]",
    1658           0 :                                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletTemp);
    1659           0 :                         SetupEMSInternalVariable(state,
    1660           0 :                                                  "Inlet Mass Flow Rate for Plant Connection " + LoopStr,
    1661           0 :                                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1662             :                                                  "[kg/s]",
    1663           0 :                                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletMassFlowRate);
    1664           0 :                         SetupEMSInternalVariable(state,
    1665           0 :                                                  "Inlet Density for Plant Connection " + LoopStr,
    1666           0 :                                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1667             :                                                  "[kg/m3]",
    1668           0 :                                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletRho);
    1669           0 :                         SetupEMSInternalVariable(state,
    1670           0 :                                                  "Inlet Specific Heat for Plant Connection " + LoopStr,
    1671           0 :                                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1672             :                                                  "[J/kg-C]",
    1673           0 :                                                  state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletCp);
    1674             :                         // model results related actuators
    1675           0 :                         SetupEMSActuator(state,
    1676           0 :                                          "Plant Connection " + LoopStr,
    1677           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1678             :                                          "Outlet Temperature",
    1679             :                                          "[C]",
    1680           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1681           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).OutletTemp);
    1682           0 :                         SetupEMSActuator(state,
    1683           0 :                                          "Plant Connection " + LoopStr,
    1684           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1685             :                                          "Mass Flow Rate",
    1686             :                                          "[kg/s]",
    1687           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1688           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).MassFlowRateRequest);
    1689             :                         // model initialization and sizing related actuators
    1690           0 :                         SetupEMSActuator(state,
    1691           0 :                                          "Plant Connection " + LoopStr,
    1692           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1693             :                                          "Minimum Mass Flow Rate",
    1694             :                                          "[kg/s]",
    1695           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1696           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).MassFlowRateMin);
    1697           0 :                         SetupEMSActuator(state,
    1698           0 :                                          "Plant Connection " + LoopStr,
    1699           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1700             :                                          "Maximum Mass Flow Rate",
    1701             :                                          "[kg/s]",
    1702           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1703           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).MassFlowRateMax);
    1704           0 :                         SetupEMSActuator(state,
    1705           0 :                                          "Plant Connection " + LoopStr,
    1706           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1707             :                                          "Design Volume Flow Rate",
    1708             :                                          "[m3/s]",
    1709           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1710           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).DesignVolumeFlowRate);
    1711             :                     }
    1712             :                 }
    1713             : 
    1714           6 :                 if (!lAlphaFieldBlanks(14)) {
    1715           0 :                     WaterManager::SetupTankDemandComponent(state,
    1716           0 :                                                            cAlphaArgs(1),
    1717             :                                                            cCurrentModuleObject,
    1718           0 :                                                            cAlphaArgs(14),
    1719             :                                                            ErrorsFound,
    1720           0 :                                                            state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Water.SupplyTankID,
    1721           0 :                                                            state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Water.SupplyTankDemandARRID);
    1722             : 
    1723           0 :                     state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Water.SuppliedByWaterSystem = true;
    1724           0 :                     SetupEMSActuator(state,
    1725             :                                      "Water System",
    1726           0 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1727             :                                      "Supplied Volume Flow Rate",
    1728             :                                      "[m3/s]",
    1729           0 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1730           0 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Water.SupplyVdotRequest);
    1731             :                 }
    1732             : 
    1733           6 :                 if (!lAlphaFieldBlanks(15)) {
    1734           0 :                     WaterManager::SetupTankSupplyComponent(
    1735             :                         state,
    1736           0 :                         cAlphaArgs(1),
    1737             :                         cCurrentModuleObject,
    1738           0 :                         cAlphaArgs(15),
    1739             :                         ErrorsFound,
    1740           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Water.CollectionTankID,
    1741           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Water.CollectionTankSupplyARRID);
    1742           0 :                     state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Water.CollectsToWaterSystem = true;
    1743           0 :                     SetupEMSActuator(state,
    1744             :                                      "Water System",
    1745           0 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1746             :                                      "Collected Volume Flow Rate",
    1747             :                                      "[m3/s]",
    1748           0 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1749           0 :                                      state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Water.CollectedVdot);
    1750             :                 }
    1751             : 
    1752           6 :                 if (!lAlphaFieldBlanks(16)) {
    1753             : 
    1754           0 :                     state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ZoneNum =
    1755           0 :                         UtilityRoutines::FindItemInList(cAlphaArgs(16), state.dataHeatBal->Zone);
    1756           0 :                     if (state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ZoneNum == 0) {
    1757           0 :                         ShowSevereError(state, cCurrentModuleObject + " = " + cAlphaArgs(1) + ":  Ambient Zone Name not found = " + cAlphaArgs(16));
    1758           0 :                         ErrorsFound = true;
    1759             :                     } else {
    1760           0 :                         state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.DeviceHasInternalGains = true;
    1761           0 :                         SetupZoneInternalGain(state,
    1762           0 :                                               state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ZoneNum,
    1763           0 :                                               cAlphaArgs(1),
    1764             :                                               DataHeatBalance::IntGainType::ZoneHVACForcedAirUserDefined,
    1765           0 :                                               &state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ConvectionGainRate,
    1766           0 :                                               &state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ReturnAirConvectionGainRate,
    1767           0 :                                               &state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ThermalRadiationGainRate,
    1768           0 :                                               &state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.LatentGainRate,
    1769           0 :                                               &state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ReturnAirLatentGainRate,
    1770           0 :                                               &state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.CarbonDioxideGainRate,
    1771           0 :                                               &state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.GenericContamGainRate);
    1772             : 
    1773           0 :                         SetupEMSActuator(state,
    1774             :                                          "Component Zone Internal Gain",
    1775           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1776             :                                          "Sensible Heat Gain Rate",
    1777             :                                          "[W]",
    1778           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1779           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ConvectionGainRate);
    1780           0 :                         SetupEMSActuator(state,
    1781             :                                          "Component Zone Internal Gain",
    1782           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1783             :                                          "Return Air Heat Sensible Gain Rate",
    1784             :                                          "[W]",
    1785           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1786           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ReturnAirConvectionGainRate);
    1787           0 :                         SetupEMSActuator(state,
    1788             :                                          "Component Zone Internal Gain",
    1789           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1790             :                                          "Thermal Radiation Heat Gain Rate",
    1791             :                                          "[W]",
    1792           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1793           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ThermalRadiationGainRate);
    1794           0 :                         SetupEMSActuator(state,
    1795             :                                          "Component Zone Internal Gain",
    1796           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1797             :                                          "Latent Heat Gain Rate",
    1798             :                                          "[W]",
    1799           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1800           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.LatentGainRate);
    1801           0 :                         SetupEMSActuator(state,
    1802             :                                          "Component Zone Internal Gain",
    1803           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1804             :                                          "Return Air Latent Heat Gain Rate",
    1805             :                                          "[W]",
    1806           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1807           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ReturnAirLatentGainRate);
    1808           0 :                         SetupEMSActuator(state,
    1809             :                                          "Component Zone Internal Gain",
    1810           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1811             :                                          "Carbon Dioxide Gain Rate",
    1812             :                                          "[m3/s]",
    1813           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1814           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.CarbonDioxideGainRate);
    1815           0 :                         SetupEMSActuator(state,
    1816             :                                          "Component Zone Internal Gain",
    1817           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name,
    1818             :                                          "Gaseous Contaminant Gain Rate",
    1819             :                                          "[m3/s]",
    1820           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1821           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.GenericContamGainRate);
    1822             :                     }
    1823             :                 }
    1824             :             }
    1825             :         } // NumUserZoneAir > 0
    1826             : 
    1827           4 :         if (ErrorsFound) {
    1828           0 :             ShowFatalError(state, "GetUserDefinedComponents: Errors found in processing " + cCurrentModuleObject + " input.");
    1829             :         }
    1830             : 
    1831           4 :         cCurrentModuleObject = "AirTerminal:SingleDuct:UserDefined";
    1832             : 
    1833           4 :         state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(state, cCurrentModuleObject, TotalArgs, NumAlphas, NumNums);
    1834             : 
    1835           4 :         cAlphaFieldNames.allocate(NumAlphas);
    1836           4 :         cAlphaArgs.allocate(NumAlphas);
    1837           4 :         lAlphaFieldBlanks.dimension(NumAlphas, false);
    1838           4 :         rNumericArgs.dimension(NumNums, 0.0);
    1839             : 
    1840           4 :         state.dataUserDefinedComponents->NumUserAirTerminals =
    1841           4 :             state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
    1842           4 :         if (state.dataUserDefinedComponents->NumUserAirTerminals > 0) {
    1843           2 :             state.dataUserDefinedComponents->UserAirTerminal.allocate(state.dataUserDefinedComponents->NumUserAirTerminals);
    1844           2 :             state.dataUserDefinedComponents->CheckUserAirTerminal.dimension(state.dataUserDefinedComponents->NumUserAirTerminals, true);
    1845          12 :             for (int CompLoop = 1; CompLoop <= state.dataUserDefinedComponents->NumUserAirTerminals; ++CompLoop) {
    1846          10 :                 state.dataInputProcessing->inputProcessor->getObjectItem(state,
    1847             :                                                                          cCurrentModuleObject,
    1848             :                                                                          CompLoop,
    1849             :                                                                          cAlphaArgs,
    1850             :                                                                          NumAlphas,
    1851             :                                                                          rNumericArgs,
    1852             :                                                                          NumNums,
    1853             :                                                                          IOStat,
    1854             :                                                                          _,
    1855             :                                                                          lAlphaFieldBlanks,
    1856             :                                                                          cAlphaFieldNames,
    1857             :                                                                          _);
    1858          10 :                 UtilityRoutines::IsNameEmpty(state, cAlphaArgs(1), cCurrentModuleObject, ErrorsFound);
    1859          10 :                 state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name = cAlphaArgs(1);
    1860             : 
    1861             :                 // now get program manager for model simulations
    1862          10 :                 if (!lAlphaFieldBlanks(2)) {
    1863          10 :                     int StackMngrNum = UtilityRoutines::FindItemInList(cAlphaArgs(2), state.dataRuntimeLang->EMSProgramCallManager);
    1864          10 :                     if (StackMngrNum > 0) { // found it
    1865          10 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).ErlSimProgramMngr = StackMngrNum;
    1866             :                     } else {
    1867           0 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).simPluginLocation =
    1868           0 :                             state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(2));
    1869           0 :                         if (state.dataUserDefinedComponents->UserAirTerminal(CompLoop).simPluginLocation == -1) {
    1870           0 :                             ShowSevereError(state, "Invalid " + cAlphaFieldNames(2) + '=' + cAlphaArgs(2));
    1871           0 :                             ShowContinueError(state, "Entered in " + cCurrentModuleObject + '=' + cAlphaArgs(1));
    1872           0 :                             ShowContinueError(state, "Program Manager Name not found as an EMS Program Manager or a Python Plugin Instance object.");
    1873           0 :                             ErrorsFound = true;
    1874             :                         }
    1875             :                     }
    1876             :                 }
    1877             : 
    1878             :                 // now get program manager for model initializations
    1879          10 :                 if (!lAlphaFieldBlanks(3)) {
    1880          10 :                     int StackMngrNum = UtilityRoutines::FindItemInList(cAlphaArgs(3), state.dataRuntimeLang->EMSProgramCallManager);
    1881          10 :                     if (StackMngrNum > 0) { // found it
    1882          10 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).ErlInitProgramMngr = StackMngrNum;
    1883             :                     } else {
    1884           0 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).initPluginLocation =
    1885           0 :                             state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(3));
    1886           0 :                         if (state.dataUserDefinedComponents->UserAirTerminal(CompLoop).initPluginLocation == -1) {
    1887           0 :                             ShowSevereError(state, "Invalid " + cAlphaFieldNames(3) + '=' + cAlphaArgs(3));
    1888           0 :                             ShowContinueError(state, "Entered in " + cCurrentModuleObject + '=' + cAlphaArgs(1));
    1889           0 :                             ShowContinueError(state, "Program Manager Name not found as an EMS Program Manager or a Python Plugin Instance object.");
    1890           0 :                             ErrorsFound = true;
    1891             :                         }
    1892             :                     }
    1893             :                 }
    1894             : 
    1895          10 :                 state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.InletNodeNum =
    1896          30 :                     NodeInputManager::GetOnlySingleNode(state,
    1897          10 :                                                         cAlphaArgs(4),
    1898             :                                                         ErrorsFound,
    1899             :                                                         DataLoopNode::ConnectionObjectType::AirTerminalSingleDuctUserDefined,
    1900          10 :                                                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1901             :                                                         DataLoopNode::NodeFluidType::Air,
    1902             :                                                         DataLoopNode::ConnectionType::Inlet,
    1903             :                                                         NodeInputManager::CompFluidStream::Primary,
    1904             :                                                         DataLoopNode::ObjectIsNotParent,
    1905          10 :                                                         cAlphaFieldNames(4));
    1906             :                 // model input related internal variables
    1907          30 :                 SetupEMSInternalVariable(state,
    1908             :                                          "Inlet Temperature for Primary Air Connection",
    1909          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1910             :                                          "[C]",
    1911          30 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.InletTemp);
    1912          30 :                 SetupEMSInternalVariable(state,
    1913             :                                          "Inlet Humidity Ratio for Primary Air Connection",
    1914          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1915             :                                          "[kgWater/kgDryAir]",
    1916          30 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.InletHumRat);
    1917          30 :                 SetupEMSInternalVariable(state,
    1918             :                                          "Inlet Density for Primary Air Connection",
    1919          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1920             :                                          "[kg/m3]",
    1921          30 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.InletRho);
    1922          30 :                 SetupEMSInternalVariable(state,
    1923             :                                          "Inlet Specific Heat for Primary Air Connection",
    1924          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1925             :                                          "[J/kg-C]",
    1926          30 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.InletCp);
    1927             : 
    1928          30 :                 SetupEMSInternalVariable(state,
    1929             :                                          "Remaining Sensible Load to Heating Setpoint",
    1930          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1931             :                                          "[W]",
    1932          30 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).RemainingOutputToHeatingSP);
    1933          30 :                 SetupEMSInternalVariable(state,
    1934             :                                          "Remaining Sensible Load to Cooling Setpoint",
    1935          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1936             :                                          "[W]",
    1937          30 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).RemainingOutputToCoolingSP);
    1938          30 :                 SetupEMSInternalVariable(state,
    1939             :                                          "Remaining Latent Load to Humidifying Setpoint",
    1940          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1941             :                                          "[kg/s]",
    1942          30 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).RemainingOutputReqToHumidSP);
    1943          30 :                 SetupEMSInternalVariable(state,
    1944             :                                          "Remaining Latent Load to Dehumidifying Setpoint",
    1945          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1946             :                                          "[kg/s]",
    1947          30 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).RemainingOutputReqToDehumidSP);
    1948             : 
    1949          40 :                 SetupEMSActuator(state,
    1950             :                                  "Primary Air Connection",
    1951          10 :                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1952             :                                  "Inlet Mass Flow Rate",
    1953             :                                  "[kg/s]",
    1954          10 :                                  state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1955          30 :                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.InletMassFlowRate);
    1956          10 :                 state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.OutletNodeNum =
    1957          30 :                     NodeInputManager::GetOnlySingleNode(state,
    1958          10 :                                                         cAlphaArgs(5),
    1959             :                                                         ErrorsFound,
    1960             :                                                         DataLoopNode::ConnectionObjectType::AirTerminalSingleDuctUserDefined,
    1961          10 :                                                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1962             :                                                         DataLoopNode::NodeFluidType::Air,
    1963             :                                                         DataLoopNode::ConnectionType::Outlet,
    1964             :                                                         NodeInputManager::CompFluidStream::Primary,
    1965             :                                                         DataLoopNode::ObjectIsNotParent,
    1966          10 :                                                         cAlphaFieldNames(5));
    1967          40 :                 SetupEMSActuator(state,
    1968             :                                  "Primary Air Connection",
    1969          10 :                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1970             :                                  "Outlet Temperature",
    1971             :                                  "[C]",
    1972          10 :                                  state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1973          30 :                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.OutletTemp);
    1974          40 :                 SetupEMSActuator(state,
    1975             :                                  "Primary Air Connection",
    1976          10 :                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1977             :                                  "Outlet Humidity Ratio",
    1978             :                                  "[kgWater/kgDryAir]",
    1979          10 :                                  state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1980          30 :                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.OutletHumRat);
    1981          40 :                 SetupEMSActuator(state,
    1982             :                                  "Primary Air Connection",
    1983          10 :                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    1984             :                                  "Outlet Mass Flow Rate",
    1985             :                                  "[kg/s]",
    1986          10 :                                  state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    1987          30 :                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.OutletMassFlowRate);
    1988          10 :                 BranchNodeConnections::TestCompSet(state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(4), cAlphaArgs(5), "Air Nodes");
    1989             : 
    1990          10 :                 int ADUNum = 0;
    1991          60 :                 for (ADUNum = 1; ADUNum <= (int)state.dataDefineEquipment->AirDistUnit.size(); ++ADUNum) {
    1992         100 :                     if (state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.OutletNodeNum ==
    1993          50 :                         state.dataDefineEquipment->AirDistUnit(ADUNum).OutletNodeNum) {
    1994             :                         //        AirDistUnit(ADUNum)%InletNodeNum = IndUnitIUNum)%InletNodeNum
    1995          10 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).ADUNum = ADUNum;
    1996             :                     }
    1997             :                 }
    1998             :                 // one assumes if there isn't one assigned, it's an error?
    1999          10 :                 if (state.dataUserDefinedComponents->UserAirTerminal(CompLoop).ADUNum == 0) {
    2000           0 :                     ShowSevereError(state,
    2001           0 :                                     "GetUserDefinedComponents: No matching Air Distribution Unit for " + cCurrentModuleObject + " = " +
    2002           0 :                                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name);
    2003           0 :                     ShowContinueError(
    2004             :                         state,
    2005           0 :                         "...should have outlet node=" +
    2006           0 :                             state.dataLoopNodes->NodeID(state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.OutletNodeNum));
    2007             :                     //          ErrorsFound=.TRUE.
    2008             :                 }
    2009             : 
    2010             :                 // Fill the Zone Equipment data with the inlet node number of this unit.
    2011          70 :                 for (int CtrlZone = 1; CtrlZone <= state.dataGlobal->NumOfZones; ++CtrlZone) {
    2012          60 :                     if (!state.dataZoneEquip->ZoneEquipConfig(CtrlZone).IsControlled) continue;
    2013         100 :                     for (int SupAirIn = 1; SupAirIn <= state.dataZoneEquip->ZoneEquipConfig(CtrlZone).NumInletNodes; ++SupAirIn) {
    2014         100 :                         if (state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.OutletNodeNum ==
    2015          50 :                             state.dataZoneEquip->ZoneEquipConfig(CtrlZone).InletNode(SupAirIn)) {
    2016          10 :                             if (state.dataZoneEquip->ZoneEquipConfig(CtrlZone).AirDistUnitCool(SupAirIn).OutNode > 0) {
    2017           0 :                                 ShowSevereError(state, "Error in connecting a terminal unit to a zone");
    2018           0 :                                 ShowContinueError(
    2019             :                                     state,
    2020           0 :                                     state.dataLoopNodes->NodeID(state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.OutletNodeNum) +
    2021             :                                         " already connects to another zone");
    2022           0 :                                 ShowContinueError(state,
    2023           0 :                                                   "Occurs for terminal unit " + cCurrentModuleObject + " = " +
    2024           0 :                                                       state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name);
    2025           0 :                                 ShowContinueError(state, "Check terminal unit node names for errors");
    2026           0 :                                 ErrorsFound = true;
    2027             :                             } else {
    2028          10 :                                 state.dataZoneEquip->ZoneEquipConfig(CtrlZone).AirDistUnitCool(SupAirIn).InNode =
    2029          10 :                                     state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.InletNodeNum;
    2030          10 :                                 state.dataZoneEquip->ZoneEquipConfig(CtrlZone).AirDistUnitCool(SupAirIn).OutNode =
    2031          10 :                                     state.dataUserDefinedComponents->UserAirTerminal(CompLoop).AirLoop.OutletNodeNum;
    2032             :                             }
    2033             : 
    2034          10 :                             state.dataUserDefinedComponents->UserAirTerminal(CompLoop).ActualCtrlZoneNum = CtrlZone;
    2035             :                         }
    2036             :                     }
    2037             :                 }
    2038             : 
    2039          10 :                 if (!lAlphaFieldBlanks(6)) {
    2040           0 :                     state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.InletNodeNum =
    2041           0 :                         NodeInputManager::GetOnlySingleNode(state,
    2042           0 :                                                             cAlphaArgs(6),
    2043             :                                                             ErrorsFound,
    2044             :                                                             DataLoopNode::ConnectionObjectType::AirTerminalSingleDuctUserDefined,
    2045           0 :                                                             state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2046             :                                                             DataLoopNode::NodeFluidType::Air,
    2047             :                                                             DataLoopNode::ConnectionType::Inlet,
    2048             :                                                             NodeInputManager::CompFluidStream::Secondary,
    2049             :                                                             DataLoopNode::ObjectIsNotParent,
    2050           0 :                                                             cAlphaFieldNames(6));
    2051             :                     // model input related internal variables
    2052           0 :                     SetupEMSInternalVariable(state,
    2053             :                                              "Inlet Temperature for Secondary Air Connection",
    2054           0 :                                              state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2055             :                                              "[C]",
    2056           0 :                                              state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.InletTemp);
    2057             : 
    2058           0 :                     SetupEMSInternalVariable(state,
    2059             :                                              "Inlet Humidity Ratio for Secondary Air Connection",
    2060           0 :                                              state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2061             :                                              "[kgWater/kgDryAir]",
    2062           0 :                                              state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.InletHumRat);
    2063           0 :                     SetupEMSInternalVariable(state,
    2064             :                                              "Inlet Density for Secondary Air Connection",
    2065           0 :                                              state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2066             :                                              "[kg/m3]",
    2067           0 :                                              state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.InletRho);
    2068           0 :                     SetupEMSInternalVariable(state,
    2069             :                                              "Inlet Specific Heat for Secondary Air Connection",
    2070           0 :                                              state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2071             :                                              "[J/kg-C]",
    2072           0 :                                              state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.InletCp);
    2073           0 :                     SetupEMSActuator(state,
    2074             :                                      "Secondary Air Connection",
    2075           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2076             :                                      "Inlet Mass Flow Rate",
    2077             :                                      "[kg/s]",
    2078           0 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2079           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.InletMassFlowRate);
    2080             :                 }
    2081             : 
    2082          10 :                 if (!lAlphaFieldBlanks(7)) {
    2083           0 :                     state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.OutletNodeNum =
    2084           0 :                         NodeInputManager::GetOnlySingleNode(state,
    2085           0 :                                                             cAlphaArgs(7),
    2086             :                                                             ErrorsFound,
    2087             :                                                             DataLoopNode::ConnectionObjectType::AirTerminalSingleDuctUserDefined,
    2088           0 :                                                             state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2089             :                                                             DataLoopNode::NodeFluidType::Air,
    2090             :                                                             DataLoopNode::ConnectionType::Outlet,
    2091             :                                                             NodeInputManager::CompFluidStream::Secondary,
    2092             :                                                             DataLoopNode::ObjectIsNotParent,
    2093           0 :                                                             cAlphaFieldNames(7));
    2094           0 :                     SetupEMSActuator(state,
    2095             :                                      "Secondary Air Connection",
    2096           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2097             :                                      "Outlet Temperature",
    2098             :                                      "[C]",
    2099           0 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2100           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.OutletTemp);
    2101           0 :                     SetupEMSActuator(state,
    2102             :                                      "Secondary Air Connection",
    2103           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2104             :                                      "Outlet Humidity Ratio",
    2105             :                                      "[kgWater/kgDryAir]",
    2106           0 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2107           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.OutletHumRat);
    2108           0 :                     SetupEMSActuator(state,
    2109             :                                      "Secondary Air Connection",
    2110           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2111             :                                      "Mass Flow Rate",
    2112             :                                      "[kg/s]",
    2113           0 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2114           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.OutletMassFlowRate);
    2115             :                 }
    2116             : 
    2117          10 :                 if ((state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.InletNodeNum > 0) &&
    2118           0 :                     (state.dataUserDefinedComponents->UserAirTerminal(CompLoop).SourceAir.OutletNodeNum > 0)) {
    2119             :                 }
    2120             : 
    2121          10 :                 int NumPlantConnections = std::floor(rNumericArgs(1));
    2122          10 :                 state.dataUserDefinedComponents->UserAirTerminal(CompLoop).NumPlantConnections = NumPlantConnections;
    2123          10 :                 if ((NumPlantConnections >= 1) && (NumPlantConnections <= 2)) {
    2124          10 :                     state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop.allocate(NumPlantConnections);
    2125          20 :                     for (int ConnectionLoop = 1; ConnectionLoop <= NumPlantConnections; ++ConnectionLoop) {
    2126          10 :                         int aArgCount = (ConnectionLoop - 1) * 2 + 8;
    2127          10 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletNodeNum =
    2128          20 :                             NodeInputManager::GetOnlySingleNode(state,
    2129          10 :                                                                 cAlphaArgs(aArgCount),
    2130             :                                                                 ErrorsFound,
    2131             :                                                                 DataLoopNode::ConnectionObjectType::AirTerminalSingleDuctUserDefined,
    2132          10 :                                                                 cAlphaArgs(1),
    2133             :                                                                 DataLoopNode::NodeFluidType::Water,
    2134             :                                                                 DataLoopNode::ConnectionType::Inlet,
    2135          10 :                                                                 static_cast<NodeInputManager::CompFluidStream>(ConnectionLoop + 2),
    2136             :                                                                 DataLoopNode::ObjectIsNotParent,
    2137          10 :                                                                 cAlphaFieldNames(aArgCount));
    2138          10 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).OutletNodeNum =
    2139          20 :                             NodeInputManager::GetOnlySingleNode(state,
    2140          10 :                                                                 cAlphaArgs(aArgCount + 1),
    2141             :                                                                 ErrorsFound,
    2142             :                                                                 DataLoopNode::ConnectionObjectType::AirTerminalSingleDuctUserDefined,
    2143          10 :                                                                 cAlphaArgs(1),
    2144             :                                                                 DataLoopNode::NodeFluidType::Water,
    2145             :                                                                 DataLoopNode::ConnectionType::Outlet,
    2146          10 :                                                                 static_cast<NodeInputManager::CompFluidStream>(ConnectionLoop + 2),
    2147             :                                                                 DataLoopNode::ObjectIsNotParent,
    2148          10 :                                                                 cAlphaFieldNames(aArgCount + 1));
    2149          20 :                         BranchNodeConnections::TestCompSet(
    2150          10 :                             state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(aArgCount), cAlphaArgs(aArgCount + 1), "Plant Nodes");
    2151          10 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).HowLoadServed = DataPlant::HowMet::NoneDemand;
    2152          10 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).FlowPriority =
    2153             :                             DataPlant::LoopFlowStatus::NeedyAndTurnsLoopOn;
    2154             :                         // Setup Internal Variables
    2155          20 :                         const auto LoopStr = fmt::to_string(ConnectionLoop);
    2156             :                         // model input related internal variables
    2157          40 :                         SetupEMSInternalVariable(state,
    2158          20 :                                                  "Inlet Temperature for Plant Connection " + LoopStr,
    2159          10 :                                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2160             :                                                  "[C]",
    2161          20 :                                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletTemp);
    2162          40 :                         SetupEMSInternalVariable(state,
    2163          20 :                                                  "Inlet Mass Flow Rate for Plant Connection " + LoopStr,
    2164          10 :                                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2165             :                                                  "[kg/s]",
    2166          20 :                                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletMassFlowRate);
    2167          40 :                         SetupEMSInternalVariable(state,
    2168          20 :                                                  "Inlet Density for Plant Connection " + LoopStr,
    2169          10 :                                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2170             :                                                  "[kg/m3]",
    2171          20 :                                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletRho);
    2172          40 :                         SetupEMSInternalVariable(state,
    2173          20 :                                                  "Inlet Specific Heat for Plant Connection " + LoopStr,
    2174          10 :                                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2175             :                                                  "[J/kg-C]",
    2176          20 :                                                  state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletCp);
    2177             :                         // model results related actuators
    2178          50 :                         SetupEMSActuator(state,
    2179          20 :                                          "Plant Connection " + LoopStr,
    2180          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2181             :                                          "Outlet Temperature",
    2182             :                                          "[C]",
    2183          10 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2184          20 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).OutletTemp);
    2185          50 :                         SetupEMSActuator(state,
    2186          20 :                                          "Plant Connection " + LoopStr,
    2187          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2188             :                                          "Mass Flow Rate",
    2189             :                                          "[kg/s]",
    2190          10 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2191          20 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).MassFlowRateRequest);
    2192             :                         // model initialization and sizing related actuators
    2193          50 :                         SetupEMSActuator(state,
    2194          20 :                                          "Plant Connection " + LoopStr,
    2195          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2196             :                                          "Minimum Mass Flow Rate",
    2197             :                                          "[kg/s]",
    2198          10 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2199          20 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).MassFlowRateMin);
    2200          50 :                         SetupEMSActuator(state,
    2201          20 :                                          "Plant Connection " + LoopStr,
    2202          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2203             :                                          "Maximum Mass Flow Rate",
    2204             :                                          "[kg/s]",
    2205          10 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2206          20 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).MassFlowRateMax);
    2207          50 :                         SetupEMSActuator(state,
    2208          20 :                                          "Plant Connection " + LoopStr,
    2209          10 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2210             :                                          "Design Volume Flow Rate",
    2211             :                                          "[m3/s]",
    2212          10 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2213          20 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).DesignVolumeFlowRate);
    2214             :                     }
    2215             :                 }
    2216             : 
    2217          10 :                 if (!lAlphaFieldBlanks(12)) {
    2218           0 :                     WaterManager::SetupTankDemandComponent(state,
    2219           0 :                                                            cAlphaArgs(1),
    2220             :                                                            cCurrentModuleObject,
    2221           0 :                                                            cAlphaArgs(12),
    2222             :                                                            ErrorsFound,
    2223           0 :                                                            state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Water.SupplyTankID,
    2224           0 :                                                            state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Water.SupplyTankDemandARRID);
    2225             : 
    2226           0 :                     state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Water.SuppliedByWaterSystem = true;
    2227           0 :                     SetupEMSActuator(state,
    2228             :                                      "Water System",
    2229           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2230             :                                      "Supplied Volume Flow Rate",
    2231             :                                      "[m3/s]",
    2232           0 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2233           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Water.SupplyVdotRequest);
    2234             :                 }
    2235             : 
    2236          10 :                 if (!lAlphaFieldBlanks(13)) {
    2237           0 :                     WaterManager::SetupTankSupplyComponent(
    2238             :                         state,
    2239           0 :                         cAlphaArgs(1),
    2240             :                         cCurrentModuleObject,
    2241           0 :                         cAlphaArgs(13),
    2242             :                         ErrorsFound,
    2243           0 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Water.CollectionTankID,
    2244           0 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Water.CollectionTankSupplyARRID);
    2245           0 :                     state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Water.CollectsToWaterSystem = true;
    2246           0 :                     SetupEMSActuator(state,
    2247             :                                      "Water System",
    2248           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2249             :                                      "Collected Volume Flow Rate",
    2250             :                                      "[m3/s]",
    2251           0 :                                      state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2252           0 :                                      state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Water.CollectedVdot);
    2253             :                 }
    2254             : 
    2255          10 :                 if (!lAlphaFieldBlanks(14)) {
    2256             : 
    2257           0 :                     state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ZoneNum =
    2258           0 :                         UtilityRoutines::FindItemInList(cAlphaArgs(14), state.dataHeatBal->Zone);
    2259           0 :                     if (state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ZoneNum == 0) {
    2260           0 :                         ShowSevereError(state, cCurrentModuleObject + " = " + cAlphaArgs(1) + ":  Ambient Zone Name not found = " + cAlphaArgs(14));
    2261           0 :                         ErrorsFound = true;
    2262             :                     } else {
    2263           0 :                         state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.DeviceHasInternalGains = true;
    2264           0 :                         SetupZoneInternalGain(state,
    2265           0 :                                               state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ZoneNum,
    2266           0 :                                               cAlphaArgs(1),
    2267             :                                               DataHeatBalance::IntGainType::AirTerminalUserDefined,
    2268           0 :                                               &state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ConvectionGainRate,
    2269           0 :                                               &state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ReturnAirConvectionGainRate,
    2270           0 :                                               &state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ThermalRadiationGainRate,
    2271           0 :                                               &state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.LatentGainRate,
    2272           0 :                                               &state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ReturnAirLatentGainRate,
    2273           0 :                                               &state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.CarbonDioxideGainRate,
    2274           0 :                                               &state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.GenericContamGainRate);
    2275             : 
    2276           0 :                         SetupEMSActuator(state,
    2277             :                                          "Component Zone Internal Gain",
    2278           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2279             :                                          "Sensible Heat Gain Rate",
    2280             :                                          "[W]",
    2281           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2282           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ConvectionGainRate);
    2283           0 :                         SetupEMSActuator(state,
    2284             :                                          "Component Zone Internal Gain",
    2285           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2286             :                                          "Return Air Heat Sensible Gain Rate",
    2287             :                                          "[W]",
    2288           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2289           0 :                                          state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Zone.ReturnAirConvectionGainRate);
    2290           0 :                         SetupEMSActuator(state,
    2291             :                                          "Component Zone Internal Gain",
    2292           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2293             :                                          "Thermal Radiation Heat Gain Rate",
    2294             :                                          "[W]",
    2295           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2296           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ThermalRadiationGainRate);
    2297           0 :                         SetupEMSActuator(state,
    2298             :                                          "Component Zone Internal Gain",
    2299           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2300             :                                          "Latent Heat Gain Rate",
    2301             :                                          "[W]",
    2302           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2303           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.LatentGainRate);
    2304           0 :                         SetupEMSActuator(state,
    2305             :                                          "Component Zone Internal Gain",
    2306           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2307             :                                          "Return Air Latent Heat Gain Rate",
    2308             :                                          "[W]",
    2309           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2310           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.ReturnAirLatentGainRate);
    2311           0 :                         SetupEMSActuator(state,
    2312             :                                          "Component Zone Internal Gain",
    2313           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2314             :                                          "Carbon Dioxide Gain Rate",
    2315             :                                          "[W]",
    2316           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2317           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.CarbonDioxideGainRate);
    2318           0 :                         SetupEMSActuator(state,
    2319             :                                          "Component Zone Internal Gain",
    2320           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name,
    2321             :                                          "Gaseous Contaminant Gain Rate",
    2322             :                                          "[W]",
    2323           0 :                                          state.dataUserDefinedComponents->lDummy_GetUserDefComp,
    2324           0 :                                          state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Zone.GenericContamGainRate);
    2325             :                     }
    2326             :                 }
    2327             :             }
    2328             :         } // NumUserZoneAir > 0
    2329             : 
    2330           4 :         if (ErrorsFound) {
    2331           0 :             ShowFatalError(state, "GetUserDefinedComponents: Errors found in processing " + cCurrentModuleObject + " input.");
    2332             :         }
    2333           4 :     }
    2334             : 
    2335       96130 :     void UserPlantComponentStruct::initialize(EnergyPlusData &state, int LoopNum, Real64 MyLoad)
    2336             :     {
    2337             :         // SUBROUTINE INFORMATION:
    2338             :         //       AUTHOR         <author>
    2339             :         //       DATE WRITTEN   <date_written>
    2340             :         //       MODIFIED       na
    2341             :         //       RE-ENGINEERED  na
    2342             : 
    2343             :         static constexpr std::string_view RoutineName("InitPlantUserComponent");
    2344             : 
    2345       96130 :         this->oneTimeInit(state);
    2346             : 
    2347       96130 :         if (LoopNum <= 0 || LoopNum > this->NumPlantConnections) return;
    2348             : 
    2349             :         // fill internal variable targets
    2350       95740 :         this->Loop(LoopNum).MyLoad = MyLoad;
    2351      287220 :         this->Loop(LoopNum).InletRho = FluidProperties::GetDensityGlycol(state,
    2352       95740 :                                                                          state.dataPlnt->PlantLoop(this->Loop(LoopNum).plantLoc.loopNum).FluidName,
    2353       95740 :                                                                          state.dataLoopNodes->Node(this->Loop(LoopNum).InletNodeNum).Temp,
    2354       95740 :                                                                          state.dataPlnt->PlantLoop(this->Loop(LoopNum).plantLoc.loopNum).FluidIndex,
    2355             :                                                                          RoutineName);
    2356       95740 :         this->Loop(LoopNum).InletCp =
    2357      287220 :             FluidProperties::GetSpecificHeatGlycol(state,
    2358       95740 :                                                    state.dataPlnt->PlantLoop(this->Loop(LoopNum).plantLoc.loopNum).FluidName,
    2359       95740 :                                                    state.dataLoopNodes->Node(this->Loop(LoopNum).InletNodeNum).Temp,
    2360       95740 :                                                    state.dataPlnt->PlantLoop(this->Loop(LoopNum).plantLoc.loopNum).FluidIndex,
    2361             :                                                    RoutineName);
    2362       95740 :         this->Loop(LoopNum).InletMassFlowRate = state.dataLoopNodes->Node(this->Loop(LoopNum).InletNodeNum).MassFlowRate;
    2363       95740 :         this->Loop(LoopNum).InletTemp = state.dataLoopNodes->Node(this->Loop(LoopNum).InletNodeNum).Temp;
    2364       95740 :         if (this->Air.InletNodeNum > 0) {
    2365      287220 :             this->Air.InletRho = Psychrometrics::PsyRhoAirFnPbTdbW(state,
    2366       95740 :                                                                    state.dataEnvrn->OutBaroPress,
    2367       95740 :                                                                    state.dataLoopNodes->Node(this->Air.InletNodeNum).Temp,
    2368       95740 :                                                                    state.dataLoopNodes->Node(this->Air.InletNodeNum).HumRat,
    2369             :                                                                    RoutineName);
    2370       95740 :             this->Air.InletCp = Psychrometrics::PsyCpAirFnW(state.dataLoopNodes->Node(this->Air.InletNodeNum).HumRat);
    2371       95740 :             this->Air.InletTemp = state.dataLoopNodes->Node(this->Air.InletNodeNum).Temp;
    2372       95740 :             this->Air.InletMassFlowRate = state.dataLoopNodes->Node(this->Air.InletNodeNum).MassFlowRate;
    2373       95740 :             this->Air.InletHumRat = state.dataLoopNodes->Node(this->Air.InletNodeNum).HumRat;
    2374             :         }
    2375             :     }
    2376             : 
    2377       80346 :     void UserCoilComponentStruct::initialize(EnergyPlusData &state)
    2378             :     {
    2379             : 
    2380             :         // SUBROUTINE INFORMATION:
    2381             :         //       AUTHOR         <author>
    2382             :         //       DATE WRITTEN   <date_written>
    2383             :         //       MODIFIED       na
    2384             :         //       RE-ENGINEERED  na
    2385             : 
    2386             :         static constexpr std::string_view RoutineName("InitCoilUserDefined");
    2387             : 
    2388       80346 :         if (this->myOneTimeFlag) {
    2389           6 :             if (this->PlantIsConnected) {
    2390           6 :                 bool errFlag = false;
    2391           6 :                 PlantUtilities::ScanPlantLoopsForObject(
    2392             :                     state, this->Name, DataPlant::PlantEquipmentType::CoilUserDefined, this->Loop.plantLoc, errFlag);
    2393           6 :                 if (errFlag) {
    2394           0 :                     ShowFatalError(state, "InitPlantUserComponent: Program terminated due to previous condition(s).");
    2395             :                 }
    2396             :                 // set user input for flow priority
    2397           6 :                 DataPlant::CompData::getPlantComponent(state, this->Loop.plantLoc).FlowPriority = this->Loop.FlowPriority;
    2398             : 
    2399             :                 // set user input for how loads served
    2400           6 :                 DataPlant::CompData::getPlantComponent(state, this->Loop.plantLoc).HowLoadServed = this->Loop.HowLoadServed;
    2401             :             }
    2402           6 :             this->myOneTimeFlag = false;
    2403             :         }
    2404             : 
    2405             :         // fill internal variable targets
    2406      160692 :         for (int loop = 1; loop <= this->NumAirConnections; ++loop) {
    2407      241038 :             this->Air(loop).InletRho = Psychrometrics::PsyRhoAirFnPbTdbW(state,
    2408       80346 :                                                                          state.dataEnvrn->OutBaroPress,
    2409       80346 :                                                                          state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).Temp,
    2410       80346 :                                                                          state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).HumRat,
    2411             :                                                                          RoutineName);
    2412             : 
    2413       80346 :             this->Air(loop).InletCp = Psychrometrics::PsyCpAirFnW(state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).HumRat);
    2414       80346 :             this->Air(loop).InletTemp = state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).Temp;
    2415       80346 :             this->Air(loop).InletMassFlowRate = state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).MassFlowRate;
    2416       80346 :             this->Air(loop).InletHumRat = state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).HumRat;
    2417             :         }
    2418             : 
    2419       80346 :         if (this->PlantIsConnected) {
    2420      241038 :             this->Loop.InletRho = FluidProperties::GetDensityGlycol(state,
    2421       80346 :                                                                     state.dataPlnt->PlantLoop(this->Loop.plantLoc.loopNum).FluidName,
    2422       80346 :                                                                     state.dataLoopNodes->Node(this->Loop.InletNodeNum).Temp,
    2423       80346 :                                                                     state.dataPlnt->PlantLoop(this->Loop.plantLoc.loopNum).FluidIndex,
    2424             :                                                                     RoutineName);
    2425      241038 :             this->Loop.InletCp = FluidProperties::GetSpecificHeatGlycol(state,
    2426       80346 :                                                                         state.dataPlnt->PlantLoop(this->Loop.plantLoc.loopNum).FluidName,
    2427       80346 :                                                                         state.dataLoopNodes->Node(this->Loop.InletNodeNum).Temp,
    2428       80346 :                                                                         state.dataPlnt->PlantLoop(this->Loop.plantLoc.loopNum).FluidIndex,
    2429             :                                                                         RoutineName);
    2430       80346 :             this->Loop.InletTemp = state.dataLoopNodes->Node(this->Loop.InletNodeNum).Temp;
    2431       80346 :             this->Loop.InletMassFlowRate = state.dataLoopNodes->Node(this->Loop.InletNodeNum).MassFlowRate;
    2432             :         }
    2433       80346 :     }
    2434             : 
    2435       24870 :     void UserZoneHVACForcedAirComponentStruct::initialize(EnergyPlusData &state, int const ZoneNum)
    2436             :     {
    2437             : 
    2438             :         // SUBROUTINE INFORMATION:
    2439             :         //       AUTHOR         Brent Griffith
    2440             :         //       DATE WRITTEN   Feb. 2012
    2441             :         //       MODIFIED       na
    2442             :         //       RE-ENGINEERED  na
    2443             : 
    2444             :         // PURPOSE OF THIS SUBROUTINE:
    2445             :         // initialize data for user-defined zone HVAC forced air component model
    2446             : 
    2447             :         static constexpr std::string_view RoutineName("InitZoneAirUserDefined");
    2448             : 
    2449       24870 :         if (this->myOneTimeFlag) {
    2450           6 :             if (this->NumPlantConnections > 0) {
    2451           0 :                 for (int loop = 1; loop <= this->NumPlantConnections; ++loop) {
    2452           0 :                     bool errFlag = false;
    2453           0 :                     PlantUtilities::ScanPlantLoopsForObject(state,
    2454             :                                                             this->Name,
    2455             :                                                             DataPlant::PlantEquipmentType::ZoneHVACAirUserDefined,
    2456           0 :                                                             this->Loop(loop).plantLoc,
    2457             :                                                             errFlag,
    2458             :                                                             _,
    2459             :                                                             _,
    2460             :                                                             _,
    2461           0 :                                                             this->Loop(loop).InletNodeNum,
    2462           0 :                                                             ObjexxFCL::Optional_int_const());
    2463           0 :                     if (errFlag) {
    2464           0 :                         ShowFatalError(state, "InitPlantUserComponent: Program terminated due to previous condition(s).");
    2465             :                     }
    2466             :                     // set user input for flow priority
    2467           0 :                     DataPlant::CompData::getPlantComponent(state, this->Loop(loop).plantLoc).FlowPriority = this->Loop(loop).FlowPriority;
    2468             : 
    2469             :                     // set user input for how loads served
    2470           0 :                     DataPlant::CompData::getPlantComponent(state, this->Loop(loop).plantLoc).HowLoadServed = this->Loop(loop).HowLoadServed;
    2471             :                 }
    2472             :             }
    2473           6 :             this->myOneTimeFlag = false;
    2474             :         }
    2475             :         // fill internal variable targets
    2476       24870 :         this->RemainingOutputToHeatingSP = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(ZoneNum).RemainingOutputReqToHeatSP;
    2477       24870 :         this->RemainingOutputToCoolingSP = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(ZoneNum).RemainingOutputReqToCoolSP;
    2478       24870 :         this->RemainingOutputReqToDehumidSP = state.dataZoneEnergyDemand->ZoneSysMoistureDemand(ZoneNum).RemainingOutputReqToDehumidSP;
    2479       24870 :         this->RemainingOutputReqToHumidSP = state.dataZoneEnergyDemand->ZoneSysMoistureDemand(ZoneNum).RemainingOutputReqToHumidSP;
    2480             : 
    2481       74610 :         this->ZoneAir.InletRho = Psychrometrics::PsyRhoAirFnPbTdbW(state,
    2482       24870 :                                                                    state.dataEnvrn->OutBaroPress,
    2483       24870 :                                                                    state.dataLoopNodes->Node(this->ZoneAir.InletNodeNum).Temp,
    2484       24870 :                                                                    state.dataLoopNodes->Node(this->ZoneAir.InletNodeNum).HumRat,
    2485             :                                                                    RoutineName);
    2486       24870 :         this->ZoneAir.InletCp = Psychrometrics::PsyCpAirFnW(state.dataLoopNodes->Node(this->ZoneAir.InletNodeNum).HumRat);
    2487       24870 :         this->ZoneAir.InletTemp = state.dataLoopNodes->Node(this->ZoneAir.InletNodeNum).Temp;
    2488       24870 :         this->ZoneAir.InletHumRat = state.dataLoopNodes->Node(this->ZoneAir.InletNodeNum).HumRat;
    2489             : 
    2490       24870 :         if (this->SourceAir.InletNodeNum > 0) {
    2491       74610 :             this->SourceAir.InletRho = Psychrometrics::PsyRhoAirFnPbTdbW(state,
    2492       24870 :                                                                          state.dataEnvrn->OutBaroPress,
    2493       24870 :                                                                          state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).Temp,
    2494       24870 :                                                                          state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).HumRat,
    2495             :                                                                          RoutineName);
    2496       24870 :             this->SourceAir.InletCp = Psychrometrics::PsyCpAirFnW(state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).HumRat);
    2497       24870 :             this->SourceAir.InletTemp = state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).Temp;
    2498       24870 :             this->SourceAir.InletHumRat = state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).HumRat;
    2499             :         }
    2500             : 
    2501       24870 :         if (this->NumPlantConnections > 0) {
    2502           0 :             for (int loop = 1; loop <= this->NumPlantConnections; ++loop) {
    2503           0 :                 this->Loop(loop).InletRho = FluidProperties::GetDensityGlycol(state,
    2504           0 :                                                                               state.dataPlnt->PlantLoop(this->Loop(loop).plantLoc.loopNum).FluidName,
    2505           0 :                                                                               state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp,
    2506           0 :                                                                               state.dataPlnt->PlantLoop(this->Loop(loop).plantLoc.loopNum).FluidIndex,
    2507             :                                                                               RoutineName);
    2508           0 :                 this->Loop(loop).InletCp =
    2509           0 :                     FluidProperties::GetSpecificHeatGlycol(state,
    2510           0 :                                                            state.dataPlnt->PlantLoop(this->Loop(loop).plantLoc.loopNum).FluidName,
    2511           0 :                                                            state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp,
    2512           0 :                                                            state.dataPlnt->PlantLoop(this->Loop(loop).plantLoc.loopNum).FluidIndex,
    2513             :                                                            RoutineName);
    2514           0 :                 this->Loop(loop).InletTemp = state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp;
    2515           0 :                 this->Loop(loop).InletMassFlowRate = state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).MassFlowRate;
    2516             :             }
    2517             :         }
    2518       24870 :     }
    2519             : 
    2520      120070 :     void UserAirTerminalComponentStruct::initialize(EnergyPlusData &state, int const ZoneNum)
    2521             :     {
    2522             : 
    2523             :         // SUBROUTINE INFORMATION:
    2524             :         //       AUTHOR         B. Griffith
    2525             :         //       DATE WRITTEN   March 2012
    2526             :         //       MODIFIED       na
    2527             :         //       RE-ENGINEERED  na
    2528             : 
    2529             :         static constexpr std::string_view RoutineName("InitAirTerminalUserDefined");
    2530             : 
    2531      120070 :         if (this->myOneTimeFlag) {
    2532          10 :             if (this->NumPlantConnections > 0) {
    2533          20 :                 for (int loop = 1; loop <= this->NumPlantConnections; ++loop) {
    2534          10 :                     bool errFlag = false;
    2535          20 :                     PlantUtilities::ScanPlantLoopsForObject(state,
    2536             :                                                             this->Name,
    2537             :                                                             DataPlant::PlantEquipmentType::AirTerminalUserDefined,
    2538          10 :                                                             this->Loop(loop).plantLoc,
    2539             :                                                             errFlag,
    2540             :                                                             _,
    2541             :                                                             _,
    2542             :                                                             _,
    2543          10 :                                                             this->Loop(loop).InletNodeNum,
    2544          20 :                                                             ObjexxFCL::Optional_int_const());
    2545          10 :                     if (errFlag) {
    2546           0 :                         ShowFatalError(state, "InitPlantUserComponent: Program terminated due to previous condition(s).");
    2547             :                     }
    2548             :                     // set user input for flow priority
    2549          10 :                     DataPlant::CompData::getPlantComponent(state, this->Loop(loop).plantLoc).FlowPriority = this->Loop(loop).FlowPriority;
    2550             : 
    2551             :                     // set user input for how loads served
    2552          10 :                     DataPlant::CompData::getPlantComponent(state, this->Loop(loop).plantLoc).HowLoadServed = this->Loop(loop).HowLoadServed;
    2553             :                 }
    2554             :             }
    2555          10 :             this->myOneTimeFlag = false;
    2556             :         }
    2557             :         // fill internal variable targets
    2558      120070 :         this->RemainingOutputToHeatingSP = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(ZoneNum).RemainingOutputReqToHeatSP;
    2559      120070 :         this->RemainingOutputToCoolingSP = state.dataZoneEnergyDemand->ZoneSysEnergyDemand(ZoneNum).RemainingOutputReqToCoolSP;
    2560      120070 :         this->RemainingOutputReqToDehumidSP = state.dataZoneEnergyDemand->ZoneSysMoistureDemand(ZoneNum).RemainingOutputReqToDehumidSP;
    2561      120070 :         this->RemainingOutputReqToHumidSP = state.dataZoneEnergyDemand->ZoneSysMoistureDemand(ZoneNum).RemainingOutputReqToHumidSP;
    2562             : 
    2563      360210 :         this->AirLoop.InletRho = Psychrometrics::PsyRhoAirFnPbTdbW(state,
    2564      120070 :                                                                    state.dataEnvrn->OutBaroPress,
    2565      120070 :                                                                    state.dataLoopNodes->Node(this->AirLoop.InletNodeNum).Temp,
    2566      120070 :                                                                    state.dataLoopNodes->Node(this->AirLoop.InletNodeNum).HumRat,
    2567             :                                                                    RoutineName);
    2568      120070 :         this->AirLoop.InletCp = Psychrometrics::PsyCpAirFnW(state.dataLoopNodes->Node(this->AirLoop.InletNodeNum).HumRat);
    2569      120070 :         this->AirLoop.InletTemp = state.dataLoopNodes->Node(this->AirLoop.InletNodeNum).Temp;
    2570      120070 :         this->AirLoop.InletHumRat = state.dataLoopNodes->Node(this->AirLoop.InletNodeNum).HumRat;
    2571             : 
    2572      120070 :         if (this->SourceAir.InletNodeNum > 0) {
    2573           0 :             this->SourceAir.InletRho = Psychrometrics::PsyRhoAirFnPbTdbW(state,
    2574           0 :                                                                          state.dataEnvrn->OutBaroPress,
    2575           0 :                                                                          state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).Temp,
    2576           0 :                                                                          state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).HumRat,
    2577             :                                                                          RoutineName);
    2578           0 :             this->SourceAir.InletCp = Psychrometrics::PsyCpAirFnW(state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).HumRat);
    2579           0 :             this->SourceAir.InletTemp = state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).Temp;
    2580           0 :             this->SourceAir.InletHumRat = state.dataLoopNodes->Node(this->SourceAir.InletNodeNum).HumRat;
    2581             :         }
    2582             : 
    2583      120070 :         if (this->NumPlantConnections > 0) {
    2584      240140 :             for (int loop = 1; loop <= this->NumPlantConnections; ++loop) {
    2585      360210 :                 this->Loop(loop).InletRho = FluidProperties::GetDensityGlycol(state,
    2586      120070 :                                                                               state.dataPlnt->PlantLoop(this->Loop(loop).plantLoc.loopNum).FluidName,
    2587      120070 :                                                                               state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp,
    2588      120070 :                                                                               state.dataPlnt->PlantLoop(this->Loop(loop).plantLoc.loopNum).FluidIndex,
    2589             :                                                                               RoutineName);
    2590      120070 :                 this->Loop(loop).InletCp =
    2591      360210 :                     FluidProperties::GetSpecificHeatGlycol(state,
    2592      120070 :                                                            state.dataPlnt->PlantLoop(this->Loop(loop).plantLoc.loopNum).FluidName,
    2593      120070 :                                                            state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp,
    2594      120070 :                                                            state.dataPlnt->PlantLoop(this->Loop(loop).plantLoc.loopNum).FluidIndex,
    2595             :                                                            RoutineName);
    2596      120070 :                 this->Loop(loop).InletTemp = state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp;
    2597      120070 :                 this->Loop(loop).InletMassFlowRate = state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).MassFlowRate;
    2598             :             }
    2599             :         }
    2600      120070 :     }
    2601             : 
    2602       95740 :     void UserPlantComponentStruct::report(EnergyPlusData &state, int const LoopNum)
    2603             :     {
    2604             : 
    2605             :         // SUBROUTINE INFORMATION:
    2606             :         //       AUTHOR         B. Griffith
    2607             :         //       DATE WRITTEN   Feb. 2012
    2608             :         //       MODIFIED       na
    2609             :         //       RE-ENGINEERED  na
    2610             : 
    2611             :         // PURPOSE OF THIS SUBROUTINE:
    2612             :         // report model results
    2613             : 
    2614             :         // METHODOLOGY EMPLOYED:
    2615             :         // copy actuated values to structures elsewhere in program.
    2616             : 
    2617       95740 :         PlantUtilities::SafeCopyPlantNode(state, this->Loop(LoopNum).InletNodeNum, this->Loop(LoopNum).OutletNodeNum);
    2618             : 
    2619             :         // unload Actuators to node data structure
    2620             : 
    2621       95740 :         state.dataLoopNodes->Node(this->Loop(LoopNum).OutletNodeNum).Temp = this->Loop(LoopNum).OutletTemp;
    2622             : 
    2623             :         // make mass flow requests, just this loop
    2624      382960 :         PlantUtilities::SetComponentFlowRate(state,
    2625       95740 :                                              this->Loop(LoopNum).MassFlowRateRequest,
    2626       95740 :                                              this->Loop(LoopNum).InletNodeNum,
    2627       95740 :                                              this->Loop(LoopNum).OutletNodeNum,
    2628       95740 :                                              this->Loop(LoopNum).plantLoc);
    2629             : 
    2630       95740 :         if (this->Air.OutletNodeNum > 0) {
    2631       95740 :             state.dataLoopNodes->Node(this->Air.OutletNodeNum).Temp = this->Air.OutletTemp;
    2632       95740 :             state.dataLoopNodes->Node(this->Air.OutletNodeNum).HumRat = this->Air.OutletHumRat;
    2633       95740 :             state.dataLoopNodes->Node(this->Air.OutletNodeNum).MassFlowRate = this->Air.OutletMassFlowRate;
    2634       95740 :             state.dataLoopNodes->Node(this->Air.OutletNodeNum).Enthalpy = Psychrometrics::PsyHFnTdbW(this->Air.OutletTemp, this->Air.OutletHumRat);
    2635             :         }
    2636             : 
    2637       95740 :         if (this->Water.SuppliedByWaterSystem) {
    2638           0 :             state.dataWaterData->WaterStorage(this->Water.SupplyTankID).VdotRequestDemand(this->Water.SupplyTankDemandARRID) =
    2639           0 :                 this->Water.SupplyVdotRequest;
    2640             :         }
    2641             : 
    2642       95740 :         if (this->Water.CollectsToWaterSystem) {
    2643           0 :             state.dataWaterData->WaterStorage(this->Water.CollectionTankID).VdotAvailSupply(this->Water.CollectionTankSupplyARRID) =
    2644           0 :                 this->Water.CollectedVdot;
    2645             :         }
    2646             : 
    2647       95740 :         if (this->Loop(LoopNum).HowLoadServed == DataPlant::HowMet::ByNominalCapLowOutLimit) {
    2648       95740 :             DataPlant::CompData::getPlantComponent(state, this->Loop(LoopNum).plantLoc).MinOutletTemp = this->Loop(LoopNum).LowOutTempLimit;
    2649             :         }
    2650             : 
    2651       95740 :         if (this->Loop(LoopNum).HowLoadServed == DataPlant::HowMet::ByNominalCapHiOutLimit) {
    2652           0 :             DataPlant::CompData::getPlantComponent(state, this->Loop(LoopNum).plantLoc).MaxOutletTemp = this->Loop(LoopNum).HiOutTempLimit;
    2653             :         }
    2654       95740 :     }
    2655       96130 :     void UserPlantComponentStruct::oneTimeInit(EnergyPlusData &state)
    2656             :     {
    2657             : 
    2658       96130 :         if (this->myOneTimeFlag) {
    2659             :             // locate the connections to the plant loops
    2660           4 :             for (int ConnectionNum = 1; ConnectionNum <= this->NumPlantConnections; ++ConnectionNum) {
    2661           2 :                 bool errFlag = false;
    2662           4 :                 PlantUtilities::ScanPlantLoopsForObject(state,
    2663             :                                                         this->Name,
    2664             :                                                         DataPlant::PlantEquipmentType::PlantComponentUserDefined,
    2665           2 :                                                         this->Loop(ConnectionNum).plantLoc,
    2666             :                                                         errFlag,
    2667             :                                                         _,
    2668             :                                                         _,
    2669             :                                                         _,
    2670           2 :                                                         this->Loop(ConnectionNum).InletNodeNum,
    2671           4 :                                                         ObjexxFCL::Optional_int_const());
    2672           2 :                 if (errFlag) {
    2673           0 :                     ShowFatalError(state, "InitPlantUserComponent: Program terminated due to previous condition(s).");
    2674             :                 }
    2675             : 
    2676             :                 // set user input for flow priority
    2677           2 :                 DataPlant::CompData::getPlantComponent(state, this->Loop(ConnectionNum).plantLoc).FlowPriority =
    2678           2 :                     this->Loop(ConnectionNum).FlowPriority;
    2679             : 
    2680             :                 // set user input for how loads served
    2681           2 :                 DataPlant::CompData::getPlantComponent(state, this->Loop(ConnectionNum).plantLoc).HowLoadServed =
    2682           2 :                     this->Loop(ConnectionNum).HowLoadServed;
    2683             :             }
    2684             : 
    2685           2 :             this->myOneTimeFlag = false;
    2686             :         }
    2687       96130 :     }
    2688             : 
    2689       80346 :     void UserCoilComponentStruct::report(EnergyPlusData &state)
    2690             :     {
    2691             : 
    2692             :         // SUBROUTINE INFORMATION:
    2693             :         //       AUTHOR         B. Griffith
    2694             :         //       DATE WRITTEN   Feb. 2012
    2695             :         //       MODIFIED       na
    2696             :         //       RE-ENGINEERED  na
    2697             : 
    2698             :         // PURPOSE OF THIS SUBROUTINE:
    2699             :         // report model outputs
    2700             : 
    2701      160692 :         for (int loop = 1; loop <= this->NumAirConnections; ++loop) {
    2702       80346 :             if (this->Air(loop).OutletNodeNum > 0) {
    2703       80346 :                 state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).Temp = this->Air(loop).OutletTemp;
    2704       80346 :                 state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).HumRat = this->Air(loop).OutletHumRat;
    2705       80346 :                 state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).MassFlowRate = this->Air(loop).OutletMassFlowRate;
    2706       80346 :                 state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).Enthalpy =
    2707       80346 :                     Psychrometrics::PsyHFnTdbW(this->Air(loop).OutletTemp, this->Air(loop).OutletHumRat);
    2708             : 
    2709       80346 :                 state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).MassFlowRateMinAvail =
    2710       80346 :                     state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).MassFlowRateMinAvail;
    2711       80346 :                 state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).MassFlowRateMaxAvail =
    2712       80346 :                     state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).MassFlowRateMaxAvail;
    2713             :             }
    2714             :         }
    2715             : 
    2716       80346 :         if (this->PlantIsConnected) {
    2717             :             // make mass flow requests
    2718       80346 :             PlantUtilities::SetComponentFlowRate(
    2719             :                 state, this->Loop.MassFlowRateRequest, this->Loop.InletNodeNum, this->Loop.OutletNodeNum, this->Loop.plantLoc);
    2720       80346 :             PlantUtilities::SafeCopyPlantNode(state, this->Loop.InletNodeNum, this->Loop.OutletNodeNum);
    2721             :             // unload Actuators to node data structure
    2722       80346 :             state.dataLoopNodes->Node(this->Loop.OutletNodeNum).Temp = this->Loop.OutletTemp;
    2723             :         }
    2724             : 
    2725       80346 :         if (this->Water.SuppliedByWaterSystem) {
    2726           0 :             state.dataWaterData->WaterStorage(this->Water.SupplyTankID).VdotRequestDemand(this->Water.SupplyTankDemandARRID) =
    2727           0 :                 this->Water.SupplyVdotRequest;
    2728             :         }
    2729             : 
    2730       80346 :         if (this->Water.CollectsToWaterSystem) {
    2731           0 :             state.dataWaterData->WaterStorage(this->Water.CollectionTankID).VdotAvailSupply(this->Water.CollectionTankSupplyARRID) =
    2732           0 :                 this->Water.CollectedVdot;
    2733             :         }
    2734       80346 :     }
    2735             : 
    2736       24690 :     void UserZoneHVACForcedAirComponentStruct::report(EnergyPlusData &state)
    2737             :     {
    2738             : 
    2739             :         // SUBROUTINE INFORMATION:
    2740             :         //       AUTHOR         B. Griffith
    2741             :         //       DATE WRITTEN   Feb. 2012
    2742             :         //       MODIFIED       na
    2743             :         //       RE-ENGINEERED  na
    2744             : 
    2745             :         // PURPOSE OF THIS SUBROUTINE:
    2746             :         // report model outputs
    2747             : 
    2748       24690 :         state.dataLoopNodes->Node(this->ZoneAir.InletNodeNum).MassFlowRate = this->ZoneAir.InletMassFlowRate;
    2749             : 
    2750       24690 :         state.dataLoopNodes->Node(this->ZoneAir.OutletNodeNum).Temp = this->ZoneAir.OutletTemp;
    2751       24690 :         state.dataLoopNodes->Node(this->ZoneAir.OutletNodeNum).HumRat = this->ZoneAir.OutletHumRat;
    2752       24690 :         state.dataLoopNodes->Node(this->ZoneAir.OutletNodeNum).MassFlowRate = this->ZoneAir.OutletMassFlowRate;
    2753       24690 :         state.dataLoopNodes->Node(this->ZoneAir.OutletNodeNum).Enthalpy =
    2754       24690 :             Psychrometrics::PsyHFnTdbW(this->ZoneAir.OutletTemp, this->ZoneAir.OutletHumRat);
    2755             : 
    2756       24690 :         if (this->SourceAir.OutletNodeNum > 0) {
    2757       24690 :             state.dataLoopNodes->Node(this->SourceAir.OutletNodeNum).Temp = this->SourceAir.OutletTemp;
    2758       24690 :             state.dataLoopNodes->Node(this->SourceAir.OutletNodeNum).HumRat = this->SourceAir.OutletHumRat;
    2759       24690 :             state.dataLoopNodes->Node(this->SourceAir.OutletNodeNum).MassFlowRate = this->SourceAir.OutletMassFlowRate;
    2760       24690 :             state.dataLoopNodes->Node(this->SourceAir.OutletNodeNum).Enthalpy =
    2761       24690 :                 Psychrometrics::PsyHFnTdbW(this->SourceAir.OutletTemp, this->SourceAir.OutletHumRat);
    2762             :         }
    2763             : 
    2764       24690 :         if (this->NumPlantConnections > 0) {
    2765           0 :             for (int loop = 1; loop <= this->NumPlantConnections; ++loop) {
    2766             :                 // make mass flow requests
    2767           0 :                 PlantUtilities::SetComponentFlowRate(state,
    2768           0 :                                                      this->Loop(loop).MassFlowRateRequest,
    2769           0 :                                                      this->Loop(loop).InletNodeNum,
    2770           0 :                                                      this->Loop(loop).OutletNodeNum,
    2771           0 :                                                      this->Loop(loop).plantLoc);
    2772           0 :                 PlantUtilities::SafeCopyPlantNode(state, this->Loop(loop).InletNodeNum, this->Loop(loop).OutletNodeNum);
    2773             :                 // unload Actuators to node data structure
    2774           0 :                 state.dataLoopNodes->Node(this->Loop(loop).OutletNodeNum).Temp = this->Loop(loop).OutletTemp;
    2775             :             }
    2776             :         }
    2777             : 
    2778       24690 :         if (this->Water.SuppliedByWaterSystem) {
    2779           0 :             state.dataWaterData->WaterStorage(this->Water.SupplyTankID).VdotRequestDemand(this->Water.SupplyTankDemandARRID) =
    2780           0 :                 this->Water.SupplyVdotRequest;
    2781             :         }
    2782             : 
    2783       24690 :         if (this->Water.CollectsToWaterSystem) {
    2784           0 :             state.dataWaterData->WaterStorage(this->Water.CollectionTankID).VdotAvailSupply(this->Water.CollectionTankSupplyARRID) =
    2785           0 :                 this->Water.CollectedVdot;
    2786             :         }
    2787       24690 :     }
    2788             : 
    2789      119640 :     void UserAirTerminalComponentStruct::report(EnergyPlusData &state)
    2790             :     {
    2791             : 
    2792             :         // SUBROUTINE INFORMATION:
    2793             :         //       AUTHOR         B. Griffith
    2794             :         //       DATE WRITTEN   March 2012
    2795             :         //       MODIFIED       na
    2796             :         //       RE-ENGINEERED  na
    2797             : 
    2798      119640 :         state.dataLoopNodes->Node(this->AirLoop.InletNodeNum).MassFlowRate = this->AirLoop.InletMassFlowRate;
    2799             : 
    2800      119640 :         state.dataLoopNodes->Node(this->AirLoop.OutletNodeNum).Temp = this->AirLoop.OutletTemp;
    2801      119640 :         state.dataLoopNodes->Node(this->AirLoop.OutletNodeNum).HumRat = this->AirLoop.OutletHumRat;
    2802      119640 :         state.dataLoopNodes->Node(this->AirLoop.OutletNodeNum).MassFlowRate = this->AirLoop.OutletMassFlowRate;
    2803      119640 :         state.dataLoopNodes->Node(this->AirLoop.OutletNodeNum).Enthalpy =
    2804      119640 :             Psychrometrics::PsyHFnTdbW(this->AirLoop.OutletTemp, this->AirLoop.OutletHumRat);
    2805      119640 :         if (this->SourceAir.OutletNodeNum > 0) {
    2806           0 :             state.dataLoopNodes->Node(this->SourceAir.OutletNodeNum).Temp = this->SourceAir.OutletTemp;
    2807           0 :             state.dataLoopNodes->Node(this->SourceAir.OutletNodeNum).HumRat = this->SourceAir.OutletHumRat;
    2808           0 :             state.dataLoopNodes->Node(this->SourceAir.OutletNodeNum).MassFlowRate = this->SourceAir.OutletMassFlowRate;
    2809           0 :             state.dataLoopNodes->Node(this->SourceAir.OutletNodeNum).Enthalpy =
    2810           0 :                 Psychrometrics::PsyHFnTdbW(this->SourceAir.OutletTemp, this->SourceAir.OutletHumRat);
    2811             :         }
    2812             : 
    2813      119640 :         if (this->NumPlantConnections > 0) {
    2814      239280 :             for (int loop = 1; loop <= this->NumPlantConnections; ++loop) {
    2815             :                 // make mass flow requests
    2816      478560 :                 PlantUtilities::SetComponentFlowRate(state,
    2817      119640 :                                                      this->Loop(loop).MassFlowRateRequest,
    2818      119640 :                                                      this->Loop(loop).InletNodeNum,
    2819      119640 :                                                      this->Loop(loop).OutletNodeNum,
    2820      119640 :                                                      this->Loop(loop).plantLoc);
    2821      119640 :                 PlantUtilities::SafeCopyPlantNode(state, this->Loop(loop).InletNodeNum, this->Loop(loop).OutletNodeNum);
    2822             :                 // unload Actuators to node data structure
    2823      119640 :                 state.dataLoopNodes->Node(this->Loop(loop).OutletNodeNum).Temp = this->Loop(loop).OutletTemp;
    2824             :             }
    2825             :         }
    2826             : 
    2827      119640 :         if (this->Water.SuppliedByWaterSystem) {
    2828           0 :             state.dataWaterData->WaterStorage(this->Water.SupplyTankID).VdotRequestDemand(this->Water.SupplyTankDemandARRID) =
    2829           0 :                 this->Water.SupplyVdotRequest;
    2830             :         }
    2831             : 
    2832      119640 :         if (this->Water.CollectsToWaterSystem) {
    2833           0 :             state.dataWaterData->WaterStorage(this->Water.CollectionTankID).VdotAvailSupply(this->Water.CollectionTankSupplyARRID) =
    2834           0 :                 this->Water.CollectedVdot;
    2835             :         }
    2836      119640 :     }
    2837             : 
    2838           0 :     void GetUserDefinedCoilIndex(
    2839             :         EnergyPlusData &state, std::string const &CoilName, int &CoilIndex, bool &ErrorsFound, std::string const &CurrentModuleObject)
    2840             :     {
    2841             : 
    2842             :         // SUBROUTINE INFORMATION:
    2843             :         //       AUTHOR         Richard Raustad
    2844             :         //       DATE WRITTEN   August 2013
    2845             :         //       MODIFIED       na
    2846             :         //       RE-ENGINEERED  na
    2847             : 
    2848             :         // PURPOSE OF THIS SUBROUTINE:
    2849             :         // This subroutine sets an index for a given user defined Cooling Coil -- issues error message if that
    2850             :         // coil is not a legal user defined Cooling Coil.
    2851             : 
    2852             :         // Obtains and allocates TESCoil related parameters from input file
    2853           0 :         if (state.dataUserDefinedComponents->GetInput) { // First time subroutine has been called, get input data
    2854           0 :             GetUserDefinedComponents(state);
    2855           0 :             state.dataUserDefinedComponents->GetInput = false; // Set logic flag to disallow getting the input data on future calls to this subroutine
    2856             :         }
    2857             : 
    2858           0 :         if (state.dataUserDefinedComponents->NumUserCoils > 0) {
    2859           0 :             CoilIndex = UtilityRoutines::FindItem(CoilName, state.dataUserDefinedComponents->UserCoil, state.dataUserDefinedComponents->NumUserCoils);
    2860             :         } else {
    2861           0 :             CoilIndex = 0;
    2862             :         }
    2863             : 
    2864           0 :         if (CoilIndex == 0) {
    2865           0 :             ShowSevereError(state, CurrentModuleObject + ", GetUserDefinedCoilIndex: User Defined Cooling Coil not found=" + CoilName);
    2866           0 :             ErrorsFound = true;
    2867             :         }
    2868           0 :     }
    2869             : 
    2870           0 :     void GetUserDefinedCoilAirInletNode(
    2871             :         EnergyPlusData &state, std::string const &CoilName, int &CoilAirInletNode, bool &ErrorsFound, std::string const &CurrentModuleObject)
    2872             :     {
    2873             : 
    2874             :         // SUBROUTINE INFORMATION:
    2875             :         //       AUTHOR         Richard Raustad
    2876             :         //       DATE WRITTEN   July 2015
    2877             :         //       MODIFIED       na
    2878             :         //       RE-ENGINEERED  na
    2879             : 
    2880             :         // PURPOSE OF THIS SUBROUTINE:
    2881             :         // This subroutine gets a given user defined Cooling Coil's air inlet node -- issues error message if that
    2882             :         // coil is not a legal user defined Cooling Coil and sets air node to 0, otherwise, returns inlet air node number.
    2883             : 
    2884             :         int CoilIndex;
    2885             : 
    2886             :         // Obtains and allocates TESCoil related parameters from input file
    2887           0 :         if (state.dataUserDefinedComponents->GetInput) { // First time subroutine has been called, get input data
    2888           0 :             GetUserDefinedComponents(state);
    2889           0 :             state.dataUserDefinedComponents->GetInput = false; // Set logic flag to disallow getting the input data on future calls to this subroutine
    2890             :         }
    2891             : 
    2892           0 :         if (state.dataUserDefinedComponents->NumUserCoils > 0) {
    2893           0 :             CoilIndex = UtilityRoutines::FindItem(CoilName, state.dataUserDefinedComponents->UserCoil, state.dataUserDefinedComponents->NumUserCoils);
    2894             :         } else {
    2895           0 :             CoilIndex = 0;
    2896             :         }
    2897             : 
    2898           0 :         if (CoilIndex == 0) {
    2899           0 :             ShowSevereError(state, CurrentModuleObject + ", GetTESCoilIndex: TES Cooling Coil not found=" + CoilName);
    2900           0 :             ErrorsFound = true;
    2901           0 :             CoilAirInletNode = 0;
    2902             :         } else {
    2903           0 :             CoilAirInletNode = state.dataUserDefinedComponents->UserCoil(CoilIndex).Air(1).InletNodeNum;
    2904             :         }
    2905           0 :     }
    2906             : 
    2907           0 :     void GetUserDefinedCoilAirOutletNode(
    2908             :         EnergyPlusData &state, std::string const &CoilName, int &CoilAirOutletNode, bool &ErrorsFound, std::string const &CurrentModuleObject)
    2909             :     {
    2910             : 
    2911             :         // SUBROUTINE INFORMATION:
    2912             :         //       AUTHOR         Richard Raustad
    2913             :         //       DATE WRITTEN   July 2015
    2914             :         //       MODIFIED       na
    2915             :         //       RE-ENGINEERED  na
    2916             : 
    2917             :         // PURPOSE OF THIS SUBROUTINE:
    2918             :         // This subroutine gets a given user defined Cooling Coil's air outlet node -- issues error message if that
    2919             :         // coil is not a legal user defined Cooling Coil and sets air node to 0, otherwise, returns outlet air node number.
    2920             : 
    2921             :         int CoilIndex;
    2922             : 
    2923             :         // Obtains and allocates TESCoil related parameters from input file
    2924           0 :         if (state.dataUserDefinedComponents->GetInput) { // First time subroutine has been called, get input data
    2925           0 :             GetUserDefinedComponents(state);
    2926           0 :             state.dataUserDefinedComponents->GetInput = false; // Set logic flag to disallow getting the input data on future calls to this subroutine
    2927             :         }
    2928             : 
    2929           0 :         if (state.dataUserDefinedComponents->NumUserCoils > 0) {
    2930           0 :             CoilIndex = UtilityRoutines::FindItem(CoilName, state.dataUserDefinedComponents->UserCoil, state.dataUserDefinedComponents->NumUserCoils);
    2931             :         } else {
    2932           0 :             CoilIndex = 0;
    2933             :         }
    2934             : 
    2935           0 :         if (CoilIndex == 0) {
    2936           0 :             ShowSevereError(state, CurrentModuleObject + ", GetTESCoilIndex: TES Cooling Coil not found=" + CoilName);
    2937           0 :             ErrorsFound = true;
    2938           0 :             CoilAirOutletNode = 0;
    2939             :         } else {
    2940           0 :             CoilAirOutletNode = state.dataUserDefinedComponents->UserCoil(CoilIndex).Air(1).OutletNodeNum;
    2941             :         }
    2942           0 :     }
    2943             : 
    2944             : } // namespace UserDefinedComponents
    2945             : 
    2946        2313 : } // namespace EnergyPlus

Generated by: LCOV version 1.13