diff --git a/src/EnergyPlus/UnitarySystem.cc b/src/EnergyPlus/UnitarySystem.cc index 4e88cf29c1e..039717a4adf 100644 --- a/src/EnergyPlus/UnitarySystem.cc +++ b/src/EnergyPlus/UnitarySystem.cc @@ -4718,8 +4718,8 @@ namespace UnitarySystems { // **** How to get this info **** // UnitarySystem( UnitarySysNum ).DesignHeatingCapacity = // GetWtoAHPCoilCapacity(CoolingCoilType, this->m_CoolingCoilName, errFlag ); - HeatingCoilInletNode = thisHeatCoil.Air(1).InletNodeNum; - HeatingCoilOutletNode = thisHeatCoil.Air(1).OutletNodeNum; + HeatingCoilInletNode = thisHeatCoil.AirConnections[primaryConnIdx].InletNodeNum; + HeatingCoilOutletNode = thisHeatCoil.AirConnections[primaryConnIdx].OutletNodeNum; } } @@ -5396,8 +5396,8 @@ namespace UnitarySystems { // **** How to get this info **** // UnitarySystem( UnitarySysNum ).DesignCoolingCapacity = // GetWtoAHPCoilCapacity(CoolingCoilType, this->m_CoolingCoilName, errFlag ); - CoolingCoilInletNode = thisCoolCoil.Air(1).InletNodeNum; - CoolingCoilOutletNode = thisCoolCoil.Air(1).OutletNodeNum; + CoolingCoilInletNode = thisCoolCoil.AirConnections[primaryConnIdx].InletNodeNum; + CoolingCoilOutletNode = thisCoolCoil.AirConnections[primaryConnIdx].OutletNodeNum; } } @@ -5432,9 +5432,8 @@ namespace UnitarySystems { } } - } else { // IF(.NOT. lAlphaBlanks(16))THEN + } else { ShowSevereError(state, EnergyPlus::format("{} = {}", cCurrentModuleObject, thisObjectName)); - // ShowContinueError(state, format("Illegal {} = {}", cAlphaFields(iCoolingCoilTypeAlphaNum), Alphas(iCoolingCoilTypeAlphaNum))); errorsFound = true; } @@ -5714,9 +5713,9 @@ namespace UnitarySystems { errFlag = false; } else { auto const &thisSuppCoil = state.dataUserDefinedComponents->UserCoil(this->m_SuppHeatCoilIndex); - SupHeatCoilInletNode = thisSuppCoil.Air(1).InletNodeNum; + SupHeatCoilInletNode = thisSuppCoil.AirConnections[primaryConnIdx].InletNodeNum; this->m_SuppCoilAirInletNode = SupHeatCoilInletNode; - SupHeatCoilOutletNode = thisSuppCoil.Air(1).OutletNodeNum; + SupHeatCoilOutletNode = thisSuppCoil.AirConnections[primaryConnIdx].OutletNodeNum; this->SuppCoilOutletNodeNum = SupHeatCoilOutletNode; } } diff --git a/src/EnergyPlus/UserDefinedComponents.cc b/src/EnergyPlus/UserDefinedComponents.cc index 9b056adc167..f363e7f7b60 100644 --- a/src/EnergyPlus/UserDefinedComponents.cc +++ b/src/EnergyPlus/UserDefinedComponents.cc @@ -113,37 +113,39 @@ namespace UserDefinedComponents { void UserPlantComponentStruct::onInitLoopEquip(EnergyPlusData &state, const PlantLocation &calledFromLocation) { Real64 myLoad = 0.0; - int thisLoop = 0; + int thisLoop = -1; - this->initialize(state, calledFromLocation.loopNum, myLoad); + this->oneTimeInit(state); - for (int loop = 1; loop <= this->NumPlantConnections; ++loop) { - if (calledFromLocation.loopNum != this->Loop(loop).plantLoc.loopNum) { + for (int loop = 0; loop < this->NumPlantConnections; ++loop) { + if (calledFromLocation.loopNum != this->Loop[loop].plantLoc.loopNum) { continue; } - if (calledFromLocation.loopSideNum != this->Loop(loop).plantLoc.loopSideNum) { + if (calledFromLocation.loopSideNum != this->Loop[loop].plantLoc.loopSideNum) { continue; } thisLoop = loop; + break; } - if (thisLoop > 0) { - if (this->Loop(thisLoop).ErlInitProgramMngr > 0) { + if (thisLoop >= 0) { + this->initialize(state, thisLoop, myLoad); + + auto &plantConnection = this->Loop[thisLoop]; + + if (plantConnection.ErlInitProgramMngr > 0) { bool anyEMSRan; - EMSManager::ManageEMS(state, EMSManager::EMSCallFrom::UserDefinedComponentModel, anyEMSRan, this->Loop(thisLoop).ErlInitProgramMngr); - } else if (this->Loop(thisLoop).initPluginLocation > -1) { - state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(state, this->Loop(thisLoop).initPluginLocation); - } else if (this->Loop(thisLoop).initCallbackIndex > -1) { - state.dataPluginManager->pluginManager->runSingleUserDefinedCallback(state, this->Loop(thisLoop).initCallbackIndex); + EMSManager::ManageEMS(state, EMSManager::EMSCallFrom::UserDefinedComponentModel, anyEMSRan, plantConnection.ErlInitProgramMngr); + } else if (plantConnection.initPluginLocation > -1) { + state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(state, plantConnection.initPluginLocation); + } else if (plantConnection.initCallbackIndex > -1) { + state.dataPluginManager->pluginManager->runSingleUserDefinedCallback(state, plantConnection.initCallbackIndex); } - PlantUtilities::InitComponentNodes(state, - this->Loop(thisLoop).MassFlowRateMin, - this->Loop(thisLoop).MassFlowRateMax, - this->Loop(thisLoop).InletNodeNum, - this->Loop(thisLoop).OutletNodeNum); + PlantUtilities::InitComponentNodes( + state, plantConnection.MassFlowRateMin, plantConnection.MassFlowRateMax, plantConnection.InletNodeNum, plantConnection.OutletNodeNum); - PlantUtilities::RegisterPlantCompDesignFlow(state, this->Loop(thisLoop).InletNodeNum, this->Loop(thisLoop).DesignVolumeFlowRate); + PlantUtilities::RegisterPlantCompDesignFlow(state, plantConnection.InletNodeNum, plantConnection.DesignVolumeFlowRate); } else { // throw warning @@ -159,20 +161,31 @@ namespace UserDefinedComponents { void UserPlantComponentStruct::getDesignCapacities( [[maybe_unused]] EnergyPlusData &state, const PlantLocation &calledFromLocation, Real64 &MaxLoad, Real64 &MinLoad, Real64 &OptLoad) { - int thisLoop = 0; - for (int loop = 1; loop <= this->NumPlantConnections; ++loop) { - if (calledFromLocation.loopNum != this->Loop(loop).plantLoc.loopNum) { + int thisLoop = -1; + for (int loop = 0; loop < this->NumPlantConnections; ++loop) { + if (calledFromLocation.loopNum != this->Loop[loop].plantLoc.loopNum) { continue; } - if (calledFromLocation.loopSideNum != this->Loop(loop).plantLoc.loopSideNum) { + if (calledFromLocation.loopSideNum != this->Loop[loop].plantLoc.loopSideNum) { continue; } thisLoop = loop; + break; + } + + if (thisLoop < 0) { + ShowFatalError(state, + EnergyPlus::format("SimUserDefinedPlantComponent: did not find plant connection for {}. Loop number called from ={}, " + "loop side called from ={}.", + this->Name, + calledFromLocation.loopNum, + calledFromLocation.loopSideNum)); } - MinLoad = this->Loop(thisLoop).MinLoad; - MaxLoad = this->Loop(thisLoop).MaxLoad; - OptLoad = this->Loop(thisLoop).OptLoad; + auto const &plantConnection = this->Loop[thisLoop]; + MinLoad = plantConnection.MinLoad; + MaxLoad = plantConnection.MaxLoad; + OptLoad = plantConnection.OptLoad; } void UserPlantComponentStruct::UserPlantComponentStruct::simulate(EnergyPlusData &state, @@ -195,28 +208,38 @@ namespace UserDefinedComponents { } bool anyEMSRan; - int thisLoop = 0; + int thisLoop = -1; - for (int loop = 1; loop <= this->NumPlantConnections; ++loop) { - if (calledFromLocation.loopNum != this->Loop(loop).plantLoc.loopNum) { + for (int loop = 0; loop < this->NumPlantConnections; ++loop) { + if (calledFromLocation.loopNum != this->Loop[loop].plantLoc.loopNum) { continue; } - if (calledFromLocation.loopSideNum != this->Loop(loop).plantLoc.loopSideNum) { + if (calledFromLocation.loopSideNum != this->Loop[loop].plantLoc.loopSideNum) { continue; } thisLoop = loop; + break; + } + + if (thisLoop < 0) { + ShowFatalError(state, + EnergyPlus::format("SimUserDefinedPlantComponent: did not find plant connection for {}. Loop number called from ={}, " + "loop side called from ={}.", + this->Name, + calledFromLocation.loopNum, + calledFromLocation.loopSideNum)); } this->initialize(state, thisLoop, CurLoad); - if (thisLoop > 0) { - if (this->Loop(thisLoop).ErlSimProgramMngr > 0) { - EMSManager::ManageEMS(state, EMSManager::EMSCallFrom::UserDefinedComponentModel, anyEMSRan, this->Loop(thisLoop).ErlSimProgramMngr); - } else if (this->Loop(thisLoop).simPluginLocation > -1) { - state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(state, this->Loop(thisLoop).simPluginLocation); - } else if (this->Loop(thisLoop).simCallbackIndex > -1) { - state.dataPluginManager->pluginManager->runSingleUserDefinedCallback(state, this->Loop(thisLoop).simCallbackIndex); - } + auto &plantConnection = this->Loop[thisLoop]; + + if (plantConnection.ErlSimProgramMngr > 0) { + EMSManager::ManageEMS(state, EMSManager::EMSCallFrom::UserDefinedComponentModel, anyEMSRan, plantConnection.ErlSimProgramMngr); + } else if (plantConnection.simPluginLocation > -1) { + state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(state, plantConnection.simPluginLocation); + } else if (plantConnection.simCallbackIndex > -1) { + state.dataPluginManager->pluginManager->runSingleUserDefinedCallback(state, plantConnection.simCallbackIndex); } if (this->ErlSimProgramMngr > 0) { @@ -268,7 +291,7 @@ namespace UserDefinedComponents { state.dataUserDefinedComponents->NumUserCoils, EquipName)); } - if (state.dataUserDefinedComponents->CheckUserCoilName(CompNum)) { + if (state.dataUserDefinedComponents->CheckUserCoilName[CompNum - 1]) { if (EquipName != state.dataUserDefinedComponents->UserCoil(CompNum).Name) { ShowFatalError(state, EnergyPlus::format( @@ -277,7 +300,7 @@ namespace UserDefinedComponents { EquipName, state.dataUserDefinedComponents->UserCoil(CompNum).Name)); } - state.dataUserDefinedComponents->CheckUserCoilName(CompNum) = false; + state.dataUserDefinedComponents->CheckUserCoilName[CompNum - 1] = false; } } bool anyEMSRan; @@ -327,16 +350,15 @@ namespace UserDefinedComponents { state.dataUserDefinedComponents->UserCoil(CompNum).report(state); if (AirLoopNum != -1) { // IF the system is not an equipment of outdoor air unit + auto const &primaryAirConnection = state.dataUserDefinedComponents->UserCoil(CompNum).AirConnections[primaryConnIdx]; // determine if heating or cooling on primary air stream - HeatingActive = state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).InletNodeNum).Temp < - state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).OutletNodeNum).Temp; - - Real64 EnthInlet = - Psychrometrics::PsyHFnTdbW(state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).InletNodeNum).Temp, - state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).InletNodeNum).HumRat); - Real64 EnthOutlet = - Psychrometrics::PsyHFnTdbW(state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).OutletNodeNum).Temp, - state.dataLoopNodes->Node(state.dataUserDefinedComponents->UserCoil(CompNum).Air(1).OutletNodeNum).HumRat); + HeatingActive = state.dataLoopNodes->Node(primaryAirConnection.InletNodeNum).Temp < + state.dataLoopNodes->Node(primaryAirConnection.OutletNodeNum).Temp; + + Real64 EnthInlet = Psychrometrics::PsyHFnTdbW(state.dataLoopNodes->Node(primaryAirConnection.InletNodeNum).Temp, + state.dataLoopNodes->Node(primaryAirConnection.InletNodeNum).HumRat); + Real64 EnthOutlet = Psychrometrics::PsyHFnTdbW(state.dataLoopNodes->Node(primaryAirConnection.OutletNodeNum).Temp, + state.dataLoopNodes->Node(primaryAirConnection.OutletNodeNum).HumRat); CoolingActive = EnthInlet > EnthOutlet; } } @@ -380,7 +402,7 @@ namespace UserDefinedComponents { state.dataUserDefinedComponents->NumUserZoneAir, CompName)); } - if (state.dataUserDefinedComponents->CheckUserZoneAirName(CompNum)) { + if (state.dataUserDefinedComponents->CheckUserZoneAirName[CompNum - 1]) { if (CompName != state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Name) { ShowFatalError(state, EnergyPlus::format( @@ -389,7 +411,7 @@ namespace UserDefinedComponents { CompName, state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Name)); } - state.dataUserDefinedComponents->CheckUserZoneAirName(CompNum) = false; + state.dataUserDefinedComponents->CheckUserZoneAirName[CompNum - 1] = false; } } bool anyEMSRan; @@ -409,18 +431,16 @@ namespace UserDefinedComponents { state, state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).initCallbackIndex); } if (state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).NumPlantConnections > 0) { - for (int Loop = 1; Loop <= state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).NumPlantConnections; ++Loop) { + for (int loop = 0; loop < state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).NumPlantConnections; ++loop) { + auto const &plantConnection = state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop[loop]; PlantUtilities::InitComponentNodes(state, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).MassFlowRateMin, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).MassFlowRateMax, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).InletNodeNum, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).OutletNodeNum); + plantConnection.MassFlowRateMin, + plantConnection.MassFlowRateMax, + plantConnection.InletNodeNum, + plantConnection.OutletNodeNum); - PlantUtilities::RegisterPlantCompDesignFlow( - state, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).InletNodeNum, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompNum).Loop(Loop).DesignVolumeFlowRate); + PlantUtilities::RegisterPlantCompDesignFlow(state, plantConnection.InletNodeNum, plantConnection.DesignVolumeFlowRate); } } @@ -504,7 +524,7 @@ namespace UserDefinedComponents { state.dataUserDefinedComponents->NumUserAirTerminals, CompName)); } - if (state.dataUserDefinedComponents->CheckUserAirTerminal(CompNum)) { + if (state.dataUserDefinedComponents->CheckUserAirTerminal[CompNum - 1]) { if (CompName != state.dataUserDefinedComponents->UserAirTerminal(CompNum).Name) { ShowFatalError(state, EnergyPlus::format( @@ -513,7 +533,7 @@ namespace UserDefinedComponents { CompName, state.dataUserDefinedComponents->UserAirTerminal(CompNum).Name)); } - state.dataUserDefinedComponents->CheckUserAirTerminal(CompNum) = false; + state.dataUserDefinedComponents->CheckUserAirTerminal[CompNum - 1] = false; } } bool anyEMSRan; @@ -533,18 +553,16 @@ namespace UserDefinedComponents { state, state.dataUserDefinedComponents->UserAirTerminal(CompNum).initCallbackIndex); } if (state.dataUserDefinedComponents->UserAirTerminal(CompNum).NumPlantConnections > 0) { - for (int Loop = 1; Loop <= state.dataUserDefinedComponents->UserAirTerminal(CompNum).NumPlantConnections; ++Loop) { + for (int loop = 0; loop < state.dataUserDefinedComponents->UserAirTerminal(CompNum).NumPlantConnections; ++loop) { + auto const &plantConnection = state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop[loop]; PlantUtilities::InitComponentNodes(state, - state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).MassFlowRateMin, - state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).MassFlowRateMax, - state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).InletNodeNum, - state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).OutletNodeNum); + plantConnection.MassFlowRateMin, + plantConnection.MassFlowRateMax, + plantConnection.InletNodeNum, + plantConnection.OutletNodeNum); - PlantUtilities::RegisterPlantCompDesignFlow( - state, - state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).InletNodeNum, - state.dataUserDefinedComponents->UserAirTerminal(CompNum).Loop(Loop).DesignVolumeFlowRate); + PlantUtilities::RegisterPlantCompDesignFlow(state, plantConnection.InletNodeNum, plantConnection.DesignVolumeFlowRate); } } @@ -595,7 +613,7 @@ namespace UserDefinedComponents { state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject); if (state.dataUserDefinedComponents->NumUserPlantComps > 0) { state.dataUserDefinedComponents->UserPlantComp.allocate(state.dataUserDefinedComponents->NumUserPlantComps); - state.dataUserDefinedComponents->CheckUserPlantCompName.dimension(state.dataUserDefinedComponents->NumUserPlantComps, true); + state.dataUserDefinedComponents->CheckUserPlantCompName.assign(state.dataUserDefinedComponents->NumUserPlantComps, true); for (int CompLoop = 1; CompLoop <= state.dataUserDefinedComponents->NumUserPlantComps; ++CompLoop) { state.dataInputProcessing->inputProcessor->getObjectItem(state, cCurrentModuleObject, @@ -637,82 +655,79 @@ namespace UserDefinedComponents { } int NumPlantConnections = std::floor(rNumericArgs(1)); + auto &userPlantComp = state.dataUserDefinedComponents->UserPlantComp(CompLoop); if ((NumPlantConnections >= 1) && (NumPlantConnections <= 4)) { - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop.allocate(NumPlantConnections); - state.dataUserDefinedComponents->UserPlantComp(CompLoop).NumPlantConnections = NumPlantConnections; - for (int ConnectionLoop = 1; ConnectionLoop <= NumPlantConnections; ++ConnectionLoop) { - const std::string LoopStr = fmt::to_string(ConnectionLoop); - int aArgCount = (ConnectionLoop - 1) * 6 + 3; - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletNodeNum = - Node::GetOnlySingleNode(state, - cAlphaArgs(aArgCount), - ErrorsFound, - Node::ConnectionObjectType::PlantComponentUserDefined, - cAlphaArgs(1), - Node::FluidType::Water, - Node::ConnectionType::Inlet, - static_cast(ConnectionLoop), - Node::ObjectIsNotParent); - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).OutletNodeNum = - Node::GetOnlySingleNode(state, - cAlphaArgs(aArgCount + 1), - ErrorsFound, - Node::ConnectionObjectType::PlantComponentUserDefined, - cAlphaArgs(1), - Node::FluidType::Water, - Node::ConnectionType::Outlet, - static_cast(ConnectionLoop), - Node::ObjectIsNotParent); + userPlantComp.Loop.resize(NumPlantConnections); + userPlantComp.NumPlantConnections = NumPlantConnections; + for (int connectionIndex = 0; connectionIndex < NumPlantConnections; ++connectionIndex) { + int const connectionNum = connectionIndex + 1; + auto &plantConnection = userPlantComp.Loop[connectionIndex]; + const std::string LoopStr = fmt::to_string(connectionNum); + int aArgCount = connectionIndex * 6 + 3; + plantConnection.InletNodeNum = Node::GetOnlySingleNode(state, + cAlphaArgs(aArgCount), + ErrorsFound, + Node::ConnectionObjectType::PlantComponentUserDefined, + cAlphaArgs(1), + Node::FluidType::Water, + Node::ConnectionType::Inlet, + static_cast(connectionNum), + Node::ObjectIsNotParent); + plantConnection.OutletNodeNum = Node::GetOnlySingleNode(state, + cAlphaArgs(aArgCount + 1), + ErrorsFound, + Node::ConnectionObjectType::PlantComponentUserDefined, + cAlphaArgs(1), + Node::FluidType::Water, + Node::ConnectionType::Outlet, + static_cast(connectionNum), + Node::ObjectIsNotParent); Node::TestCompSet( state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(aArgCount), cAlphaArgs(aArgCount + 1), "Plant Nodes " + LoopStr); { - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HowLoadServed = - static_cast( - getEnumValue(DataPlant::HowMetTypeNamesUC, Util::makeUPPER(cAlphaArgs(aArgCount + 2)))); - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HowLoadServed == - DataPlant::HowMet::ByNominalCapLowOutLimit) { + plantConnection.HowLoadServed = static_cast( + getEnumValue(DataPlant::HowMetTypeNamesUC, Util::makeUPPER(cAlphaArgs(aArgCount + 2)))); + if (plantConnection.HowLoadServed == DataPlant::HowMet::ByNominalCapLowOutLimit) { // actuator for low out limit SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "Low Outlet Temperature Limit", "[C]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).LowOutTempLimit); - } else if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HowLoadServed == - DataPlant::HowMet::ByNominalCapHiOutLimit) { + plantConnection.LowOutTempLimit); + } else if (plantConnection.HowLoadServed == DataPlant::HowMet::ByNominalCapHiOutLimit) { // actuator for hi out limit SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "High Outlet Temperature Limit", "[C]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HiOutTempLimit); + plantConnection.HiOutTempLimit); } } { - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).FlowPriority = - static_cast( - getEnumValue(DataPlant::LoopFlowStatusTypeNamesUC, Util::makeUPPER(cAlphaArgs(aArgCount + 3)))); + plantConnection.FlowPriority = static_cast( + getEnumValue(DataPlant::LoopFlowStatusTypeNamesUC, Util::makeUPPER(cAlphaArgs(aArgCount + 3)))); } // find program manager for initial setup, begin environment and sizing of this plant connection if (!lAlphaFieldBlanks(aArgCount + 4)) { int StackMngrNum = Util::FindItemInList(cAlphaArgs(aArgCount + 4), state.dataRuntimeLang->EMSProgramCallManager); if (StackMngrNum > 0) { // found it - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).ErlInitProgramMngr = StackMngrNum; + plantConnection.ErlInitProgramMngr = StackMngrNum; } else { - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).initPluginLocation = + plantConnection.initPluginLocation = state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(aArgCount + 4)); - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).initPluginLocation == -1) { - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).initCallbackIndex = + if (plantConnection.initPluginLocation == -1) { + plantConnection.initCallbackIndex = state.dataPluginManager->pluginManager->getUserDefinedCallbackIndex(state, cAlphaArgs(aArgCount + 4)); - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).initCallbackIndex == -1) { + if (plantConnection.initCallbackIndex == -1) { ShowSevereError( state, EnergyPlus::format("Invalid {}={}", cAlphaFieldNames(aArgCount + 4), cAlphaArgs(aArgCount + 4))); ShowContinueError(state, EnergyPlus::format("Entered in {}={}", cCurrentModuleObject, cAlphaArgs(1))); @@ -729,14 +744,14 @@ namespace UserDefinedComponents { if (!lAlphaFieldBlanks(aArgCount + 5)) { int StackMngrNum = Util::FindItemInList(cAlphaArgs(aArgCount + 5), state.dataRuntimeLang->EMSProgramCallManager); if (StackMngrNum > 0) { // found it - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).ErlSimProgramMngr = StackMngrNum; + plantConnection.ErlSimProgramMngr = StackMngrNum; } else { - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).simPluginLocation = + plantConnection.simPluginLocation = state.dataPluginManager->pluginManager->getLocationOfUserDefinedPlugin(state, cAlphaArgs(aArgCount + 5)); - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).simPluginLocation == -1) { - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).simCallbackIndex = + if (plantConnection.simPluginLocation == -1) { + plantConnection.simCallbackIndex = state.dataPluginManager->pluginManager->getUserDefinedCallbackIndex(state, cAlphaArgs(aArgCount + 5)); - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).simCallbackIndex == -1) { + if (plantConnection.simCallbackIndex == -1) { ShowSevereError( state, EnergyPlus::format("Invalid {}={}", cAlphaFieldNames(aArgCount + 4), cAlphaArgs(aArgCount + 4))); ShowContinueError(state, EnergyPlus::format("Entered in {}={}", cCurrentModuleObject, cAlphaArgs(1))); @@ -748,92 +763,79 @@ namespace UserDefinedComponents { } // Setup Internal Variables // model input related internal variables - SetupEMSInternalVariable(state, - "Inlet Temperature for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, - "[C]", - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletTemp); + SetupEMSInternalVariable( + state, "Inlet Temperature for Plant Connection " + LoopStr, userPlantComp.Name, "[C]", plantConnection.InletTemp); SetupEMSInternalVariable(state, "Inlet Mass Flow Rate for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "[kg/s]", - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletMassFlowRate); - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).HowLoadServed != - DataPlant::HowMet::NoneDemand) { - SetupEMSInternalVariable(state, - "Load Request for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, - "[W]", - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MyLoad); + plantConnection.InletMassFlowRate); + if (plantConnection.HowLoadServed != DataPlant::HowMet::NoneDemand) { + SetupEMSInternalVariable( + state, "Load Request for Plant Connection " + LoopStr, userPlantComp.Name, "[W]", plantConnection.MyLoad); } - SetupEMSInternalVariable(state, - "Inlet Density for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, - "[kg/m3]", - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletRho); - SetupEMSInternalVariable(state, - "Inlet Specific Heat for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, - "[J/kg-C]", - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).InletCp); + SetupEMSInternalVariable( + state, "Inlet Density for Plant Connection " + LoopStr, userPlantComp.Name, "[kg/m3]", plantConnection.InletRho); + SetupEMSInternalVariable( + state, "Inlet Specific Heat for Plant Connection " + LoopStr, userPlantComp.Name, "[J/kg-C]", plantConnection.InletCp); // model results related actuators SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "Outlet Temperature", "[C]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).OutletTemp); + plantConnection.OutletTemp); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MassFlowRateRequest); + plantConnection.MassFlowRateRequest); // model initialization and sizing related actuators SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "Minimum Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MassFlowRateMin); + plantConnection.MassFlowRateMin); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "Maximum Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MassFlowRateMax); + plantConnection.MassFlowRateMax); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "Design Volume Flow Rate", "[m3/s]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).DesignVolumeFlowRate); + plantConnection.DesignVolumeFlowRate); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "Minimum Loading Capacity", "[W]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MinLoad); + plantConnection.MinLoad); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "Maximum Loading Capacity", "[W]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).MaxLoad); + plantConnection.MaxLoad); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Name, + userPlantComp.Name, "Optimal Loading Capacity", "[W]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).OptLoad); + plantConnection.OptLoad); } } @@ -1025,26 +1027,26 @@ namespace UserDefinedComponents { // make sure user has entered at least some erl program managers to actually calculate something int MgrCountTest = 0; - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).ErlSimProgramMngr > 0) { + if (userPlantComp.ErlSimProgramMngr > 0) { MgrCountTest = 1; } - for (int ConnectionLoop = 1; ConnectionLoop <= NumPlantConnections; ++ConnectionLoop) { - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).ErlInitProgramMngr > 0) { + for (auto const &plantConnection : userPlantComp.Loop) { + if (plantConnection.ErlInitProgramMngr > 0) { ++MgrCountTest; } - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).ErlSimProgramMngr > 0) { + if (plantConnection.ErlSimProgramMngr > 0) { ++MgrCountTest; } - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).initPluginLocation >= 0) { + if (plantConnection.initPluginLocation >= 0) { ++MgrCountTest; } - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).simPluginLocation >= 0) { + if (plantConnection.simPluginLocation >= 0) { ++MgrCountTest; } - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).initCallbackIndex >= 0) { + if (plantConnection.initCallbackIndex >= 0) { ++MgrCountTest; } - if (state.dataUserDefinedComponents->UserPlantComp(CompLoop).Loop(ConnectionLoop).simCallbackIndex >= 0) { + if (plantConnection.simCallbackIndex >= 0) { ++MgrCountTest; } } @@ -1072,7 +1074,7 @@ namespace UserDefinedComponents { if (state.dataUserDefinedComponents->NumUserCoils > 0) { state.dataUserDefinedComponents->UserCoil.allocate(state.dataUserDefinedComponents->NumUserCoils); - state.dataUserDefinedComponents->CheckUserCoilName.dimension(state.dataUserDefinedComponents->NumUserCoils, true); + state.dataUserDefinedComponents->CheckUserCoilName.assign(state.dataUserDefinedComponents->NumUserCoils, true); for (int CompLoop = 1; CompLoop <= state.dataUserDefinedComponents->NumUserCoils; ++CompLoop) { state.dataInputProcessing->inputProcessor->getObjectItem(state, cCurrentModuleObject, @@ -1139,81 +1141,70 @@ namespace UserDefinedComponents { } int NumAirConnections = std::floor(rNumericArgs(1)); + auto &userCoil = state.dataUserDefinedComponents->UserCoil(CompLoop); if ((NumAirConnections >= 1) && (NumAirConnections <= 2)) { - state.dataUserDefinedComponents->UserCoil(CompLoop).Air.allocate(NumAirConnections); - state.dataUserDefinedComponents->UserCoil(CompLoop).NumAirConnections = NumAirConnections; - for (int ConnectionLoop = 1; ConnectionLoop <= NumAirConnections; ++ConnectionLoop) { - int aArgCount = (ConnectionLoop - 1) * 2 + 4; - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletNodeNum = - Node::GetOnlySingleNode(state, - cAlphaArgs(aArgCount), - ErrorsFound, - Node::ConnectionObjectType::CoilUserDefined, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, - Node::FluidType::Air, - Node::ConnectionType::Inlet, - static_cast(ConnectionLoop), - Node::ObjectIsNotParent); - - const std::string LoopStr = fmt::to_string(ConnectionLoop); + userCoil.AirConnections.resize(NumAirConnections); + userCoil.NumAirConnections = NumAirConnections; + for (int connectionIndex = 0; connectionIndex < NumAirConnections; ++connectionIndex) { + int const connectionNum = connectionIndex + 1; + int aArgCount = connectionIndex * 2 + 4; + auto &airConnection = userCoil.AirConnections[connectionIndex]; + airConnection.InletNodeNum = Node::GetOnlySingleNode(state, + cAlphaArgs(aArgCount), + ErrorsFound, + Node::ConnectionObjectType::CoilUserDefined, + userCoil.Name, + Node::FluidType::Air, + Node::ConnectionType::Inlet, + static_cast(connectionNum), + Node::ObjectIsNotParent); + + const std::string LoopStr = fmt::to_string(connectionNum); // model input related internal variables - SetupEMSInternalVariable(state, - "Inlet Temperature for Air Connection " + LoopStr, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, - "[C]", - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletTemp); - SetupEMSInternalVariable(state, - "Inlet Mass Flow Rate for Air Connection " + LoopStr, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, - "[kg/s]", - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletMassFlowRate); + SetupEMSInternalVariable( + state, "Inlet Temperature for Air Connection " + LoopStr, userCoil.Name, "[C]", airConnection.InletTemp); + SetupEMSInternalVariable( + state, "Inlet Mass Flow Rate for Air Connection " + LoopStr, userCoil.Name, "[kg/s]", airConnection.InletMassFlowRate); SetupEMSInternalVariable(state, "Inlet Humidity Ratio for Air Connection " + LoopStr, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, + userCoil.Name, "[kgWater/kgDryAir]", - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletHumRat); - SetupEMSInternalVariable(state, - "Inlet Density for Air Connection " + LoopStr, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, - "[kg/m3]", - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletRho); - SetupEMSInternalVariable(state, - "Inlet Specific Heat for Air Connection " + LoopStr, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, - "[J/kg-C]", - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).InletCp); - - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).OutletNodeNum = - Node::GetOnlySingleNode(state, - cAlphaArgs(aArgCount + 1), - ErrorsFound, - Node::ConnectionObjectType::CoilUserDefined, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, - Node::FluidType::Air, - Node::ConnectionType::Outlet, - static_cast(ConnectionLoop), - Node::ObjectIsNotParent); + airConnection.InletHumRat); + SetupEMSInternalVariable( + state, "Inlet Density for Air Connection " + LoopStr, userCoil.Name, "[kg/m3]", airConnection.InletRho); + SetupEMSInternalVariable( + state, "Inlet Specific Heat for Air Connection " + LoopStr, userCoil.Name, "[J/kg-C]", airConnection.InletCp); + + airConnection.OutletNodeNum = Node::GetOnlySingleNode(state, + cAlphaArgs(aArgCount + 1), + ErrorsFound, + Node::ConnectionObjectType::CoilUserDefined, + userCoil.Name, + Node::FluidType::Air, + Node::ConnectionType::Outlet, + static_cast(connectionNum), + Node::ObjectIsNotParent); SetupEMSActuator(state, "Air Connection " + LoopStr, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, + userCoil.Name, "Outlet Temperature", "[C]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).OutletTemp); + airConnection.OutletTemp); SetupEMSActuator(state, "Air Connection " + LoopStr, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, + userCoil.Name, "Outlet Humidity Ratio", "[kgWater/kgDryAir]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).OutletHumRat); + airConnection.OutletHumRat); SetupEMSActuator(state, "Air Connection " + LoopStr, - state.dataUserDefinedComponents->UserCoil(CompLoop).Name, + userCoil.Name, "Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_EMSActuatedPlantComp, - state.dataUserDefinedComponents->UserCoil(CompLoop).Air(ConnectionLoop).OutletMassFlowRate); + airConnection.OutletMassFlowRate); Node::TestCompSet( state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(aArgCount), cAlphaArgs(aArgCount + 1), "Air Nodes " + LoopStr); @@ -1476,7 +1467,7 @@ namespace UserDefinedComponents { state.dataUserDefinedComponents->NumUserZoneAir = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject); if (state.dataUserDefinedComponents->NumUserZoneAir > 0) { state.dataUserDefinedComponents->UserZoneAirHVAC.allocate(state.dataUserDefinedComponents->NumUserZoneAir); - state.dataUserDefinedComponents->CheckUserZoneAirName.dimension(state.dataUserDefinedComponents->NumUserZoneAir, true); + state.dataUserDefinedComponents->CheckUserZoneAirName.assign(state.dataUserDefinedComponents->NumUserZoneAir, true); int IOStat; // IO Status when calling get input subroutine for (int CompLoop = 1; CompLoop <= state.dataUserDefinedComponents->NumUserZoneAir; ++CompLoop) { state.dataInputProcessing->inputProcessor->getObjectItem(state, @@ -1714,96 +1705,87 @@ namespace UserDefinedComponents { } int NumPlantConnections = std::floor(rNumericArgs(1)); - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).NumPlantConnections = NumPlantConnections; + auto &userZoneAirHVAC = state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop); if ((NumPlantConnections >= 1) && (NumPlantConnections <= 3)) { - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop.allocate(NumPlantConnections); - for (int ConnectionLoop = 1; ConnectionLoop <= NumPlantConnections; ++ConnectionLoop) { - int aArgCount = (ConnectionLoop - 1) * 2 + 8; - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletNodeNum = - Node::GetOnlySingleNode(state, - cAlphaArgs(aArgCount), - ErrorsFound, - Node::ConnectionObjectType::ZoneHVACForcedAirUserDefined, - cAlphaArgs(1), - Node::FluidType::Water, - Node::ConnectionType::Inlet, - static_cast(ConnectionLoop + 2), - Node::ObjectIsNotParent); - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).OutletNodeNum = - Node::GetOnlySingleNode(state, - cAlphaArgs(aArgCount + 1), - ErrorsFound, - Node::ConnectionObjectType::ZoneHVACForcedAirUserDefined, - cAlphaArgs(1), - Node::FluidType::Water, - Node::ConnectionType::Outlet, - static_cast(ConnectionLoop + 2), - Node::ObjectIsNotParent); + userZoneAirHVAC.NumPlantConnections = NumPlantConnections; + userZoneAirHVAC.Loop.resize(NumPlantConnections); + for (int connectionIndex = 0; connectionIndex < NumPlantConnections; ++connectionIndex) { + int const connectionNum = connectionIndex + 1; + int aArgCount = connectionIndex * 2 + 8; + auto &plantConnection = userZoneAirHVAC.Loop[connectionIndex]; + plantConnection.InletNodeNum = Node::GetOnlySingleNode(state, + cAlphaArgs(aArgCount), + ErrorsFound, + Node::ConnectionObjectType::ZoneHVACForcedAirUserDefined, + cAlphaArgs(1), + Node::FluidType::Water, + Node::ConnectionType::Inlet, + static_cast(connectionNum + 2), + Node::ObjectIsNotParent); + plantConnection.OutletNodeNum = Node::GetOnlySingleNode(state, + cAlphaArgs(aArgCount + 1), + ErrorsFound, + Node::ConnectionObjectType::ZoneHVACForcedAirUserDefined, + cAlphaArgs(1), + Node::FluidType::Water, + Node::ConnectionType::Outlet, + static_cast(connectionNum + 2), + Node::ObjectIsNotParent); Node::TestCompSet( state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(aArgCount), cAlphaArgs(aArgCount + 1), "Plant Nodes"); - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).HowLoadServed = DataPlant::HowMet::NoneDemand; - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).FlowPriority = - DataPlant::LoopFlowStatus::NeedyAndTurnsLoopOn; + plantConnection.HowLoadServed = DataPlant::HowMet::NoneDemand; + plantConnection.FlowPriority = DataPlant::LoopFlowStatus::NeedyAndTurnsLoopOn; // Setup Internal Variables - const std::string LoopStr = fmt::to_string(ConnectionLoop); + const std::string LoopStr = fmt::to_string(connectionNum); // model input related internal variables - SetupEMSInternalVariable(state, - "Inlet Temperature for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name, - "[C]", - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletTemp); + SetupEMSInternalVariable( + state, "Inlet Temperature for Plant Connection " + LoopStr, userZoneAirHVAC.Name, "[C]", plantConnection.InletTemp); SetupEMSInternalVariable(state, "Inlet Mass Flow Rate for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name, + userZoneAirHVAC.Name, "[kg/s]", - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletMassFlowRate); - SetupEMSInternalVariable(state, - "Inlet Density for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name, - "[kg/m3]", - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletRho); - SetupEMSInternalVariable(state, - "Inlet Specific Heat for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name, - "[J/kg-C]", - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).InletCp); + plantConnection.InletMassFlowRate); + SetupEMSInternalVariable( + state, "Inlet Density for Plant Connection " + LoopStr, userZoneAirHVAC.Name, "[kg/m3]", plantConnection.InletRho); + SetupEMSInternalVariable( + state, "Inlet Specific Heat for Plant Connection " + LoopStr, userZoneAirHVAC.Name, "[J/kg-C]", plantConnection.InletCp); // model results related actuators SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name, + userZoneAirHVAC.Name, "Outlet Temperature", "[C]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).OutletTemp); + plantConnection.OutletTemp); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name, + userZoneAirHVAC.Name, "Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).MassFlowRateRequest); + plantConnection.MassFlowRateRequest); // model initialization and sizing related actuators SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name, + userZoneAirHVAC.Name, "Minimum Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).MassFlowRateMin); + plantConnection.MassFlowRateMin); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name, + userZoneAirHVAC.Name, "Maximum Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).MassFlowRateMax); + plantConnection.MassFlowRateMax); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Name, + userZoneAirHVAC.Name, "Design Volume Flow Rate", "[m3/s]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserZoneAirHVAC(CompLoop).Loop(ConnectionLoop).DesignVolumeFlowRate); + plantConnection.DesignVolumeFlowRate); } } @@ -1958,7 +1940,7 @@ namespace UserDefinedComponents { state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject); if (state.dataUserDefinedComponents->NumUserAirTerminals > 0) { state.dataUserDefinedComponents->UserAirTerminal.allocate(state.dataUserDefinedComponents->NumUserAirTerminals); - state.dataUserDefinedComponents->CheckUserAirTerminal.dimension(state.dataUserDefinedComponents->NumUserAirTerminals, true); + state.dataUserDefinedComponents->CheckUserAirTerminal.assign(state.dataUserDefinedComponents->NumUserAirTerminals, true); int IOStat; // IO Status when calling get input subroutine for (int CompLoop = 1; CompLoop <= state.dataUserDefinedComponents->NumUserAirTerminals; ++CompLoop) { state.dataInputProcessing->inputProcessor->getObjectItem(state, @@ -2262,98 +2244,89 @@ namespace UserDefinedComponents { } int NumPlantConnections = std::floor(rNumericArgs(1)); - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).NumPlantConnections = NumPlantConnections; + auto &userAirTerminal = state.dataUserDefinedComponents->UserAirTerminal(CompLoop); if ((NumPlantConnections >= 1) && (NumPlantConnections <= 2)) { - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop.allocate(NumPlantConnections); - for (int ConnectionLoop = 1; ConnectionLoop <= NumPlantConnections; ++ConnectionLoop) { - int aArgCount = (ConnectionLoop - 1) * 2 + 8; - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletNodeNum = - Node::GetOnlySingleNode(state, - cAlphaArgs(aArgCount), - ErrorsFound, - Node::ConnectionObjectType::AirTerminalSingleDuctUserDefined, - cAlphaArgs(1), - Node::FluidType::Water, - Node::ConnectionType::Inlet, - static_cast(ConnectionLoop + 2), - Node::ObjectIsNotParent, - cAlphaFieldNames(aArgCount)); - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).OutletNodeNum = - Node::GetOnlySingleNode(state, - cAlphaArgs(aArgCount + 1), - ErrorsFound, - Node::ConnectionObjectType::AirTerminalSingleDuctUserDefined, - cAlphaArgs(1), - Node::FluidType::Water, - Node::ConnectionType::Outlet, - static_cast(ConnectionLoop + 2), - Node::ObjectIsNotParent, - cAlphaFieldNames(aArgCount + 1)); + userAirTerminal.NumPlantConnections = NumPlantConnections; + userAirTerminal.Loop.resize(NumPlantConnections); + for (int connectionIndex = 0; connectionIndex < NumPlantConnections; ++connectionIndex) { + int const connectionNum = connectionIndex + 1; + int aArgCount = connectionIndex * 2 + 8; + auto &plantConnection = userAirTerminal.Loop[connectionIndex]; + plantConnection.InletNodeNum = Node::GetOnlySingleNode(state, + cAlphaArgs(aArgCount), + ErrorsFound, + Node::ConnectionObjectType::AirTerminalSingleDuctUserDefined, + cAlphaArgs(1), + Node::FluidType::Water, + Node::ConnectionType::Inlet, + static_cast(connectionNum + 2), + Node::ObjectIsNotParent, + cAlphaFieldNames(aArgCount)); + plantConnection.OutletNodeNum = Node::GetOnlySingleNode(state, + cAlphaArgs(aArgCount + 1), + ErrorsFound, + Node::ConnectionObjectType::AirTerminalSingleDuctUserDefined, + cAlphaArgs(1), + Node::FluidType::Water, + Node::ConnectionType::Outlet, + static_cast(connectionNum + 2), + Node::ObjectIsNotParent, + cAlphaFieldNames(aArgCount + 1)); Node::TestCompSet( state, cCurrentModuleObject, cAlphaArgs(1), cAlphaArgs(aArgCount), cAlphaArgs(aArgCount + 1), "Plant Nodes"); - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).HowLoadServed = DataPlant::HowMet::NoneDemand; - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).FlowPriority = - DataPlant::LoopFlowStatus::NeedyAndTurnsLoopOn; + plantConnection.HowLoadServed = DataPlant::HowMet::NoneDemand; + plantConnection.FlowPriority = DataPlant::LoopFlowStatus::NeedyAndTurnsLoopOn; // Setup Internal Variables - const std::string LoopStr = fmt::to_string(ConnectionLoop); + const std::string LoopStr = fmt::to_string(connectionNum); // model input related internal variables - SetupEMSInternalVariable(state, - "Inlet Temperature for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name, - "[C]", - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletTemp); + SetupEMSInternalVariable( + state, "Inlet Temperature for Plant Connection " + LoopStr, userAirTerminal.Name, "[C]", plantConnection.InletTemp); SetupEMSInternalVariable(state, "Inlet Mass Flow Rate for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name, + userAirTerminal.Name, "[kg/s]", - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletMassFlowRate); - SetupEMSInternalVariable(state, - "Inlet Density for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name, - "[kg/m3]", - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletRho); - SetupEMSInternalVariable(state, - "Inlet Specific Heat for Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name, - "[J/kg-C]", - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).InletCp); + plantConnection.InletMassFlowRate); + SetupEMSInternalVariable( + state, "Inlet Density for Plant Connection " + LoopStr, userAirTerminal.Name, "[kg/m3]", plantConnection.InletRho); + SetupEMSInternalVariable( + state, "Inlet Specific Heat for Plant Connection " + LoopStr, userAirTerminal.Name, "[J/kg-C]", plantConnection.InletCp); // model results related actuators SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name, + userAirTerminal.Name, "Outlet Temperature", "[C]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).OutletTemp); + plantConnection.OutletTemp); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name, + userAirTerminal.Name, "Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).MassFlowRateRequest); + plantConnection.MassFlowRateRequest); // model initialization and sizing related actuators SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name, + userAirTerminal.Name, "Minimum Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).MassFlowRateMin); + plantConnection.MassFlowRateMin); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name, + userAirTerminal.Name, "Maximum Mass Flow Rate", "[kg/s]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).MassFlowRateMax); + plantConnection.MassFlowRateMax); SetupEMSActuator(state, "Plant Connection " + LoopStr, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Name, + userAirTerminal.Name, "Design Volume Flow Rate", "[m3/s]", state.dataUserDefinedComponents->lDummy_GetUserDefComp, - state.dataUserDefinedComponents->UserAirTerminal(CompLoop).Loop(ConnectionLoop).DesignVolumeFlowRate); + plantConnection.DesignVolumeFlowRate); } } @@ -2489,18 +2462,19 @@ namespace UserDefinedComponents { this->oneTimeInit(state); - if (LoopNum <= 0 || LoopNum > this->NumPlantConnections) { + if (LoopNum < 0 || LoopNum >= this->NumPlantConnections) { return; } // fill internal variable targets - this->Loop(LoopNum).MyLoad = MyLoad; - this->Loop(LoopNum).InletRho = this->Loop(LoopNum).plantLoc.loop->glycol->getDensity( - state, state.dataLoopNodes->Node(this->Loop(LoopNum).InletNodeNum).Temp, RoutineName); - this->Loop(LoopNum).InletCp = this->Loop(LoopNum).plantLoc.loop->glycol->getSpecificHeat( - state, state.dataLoopNodes->Node(this->Loop(LoopNum).InletNodeNum).Temp, RoutineName); - this->Loop(LoopNum).InletMassFlowRate = state.dataLoopNodes->Node(this->Loop(LoopNum).InletNodeNum).MassFlowRate; - this->Loop(LoopNum).InletTemp = state.dataLoopNodes->Node(this->Loop(LoopNum).InletNodeNum).Temp; + auto &plantConnection = this->Loop[LoopNum]; + plantConnection.MyLoad = MyLoad; + plantConnection.InletRho = + plantConnection.plantLoc.loop->glycol->getDensity(state, state.dataLoopNodes->Node(plantConnection.InletNodeNum).Temp, RoutineName); + plantConnection.InletCp = + plantConnection.plantLoc.loop->glycol->getSpecificHeat(state, state.dataLoopNodes->Node(plantConnection.InletNodeNum).Temp, RoutineName); + plantConnection.InletMassFlowRate = state.dataLoopNodes->Node(plantConnection.InletNodeNum).MassFlowRate; + plantConnection.InletTemp = state.dataLoopNodes->Node(plantConnection.InletNodeNum).Temp; if (this->Air.InletNodeNum > 0) { this->Air.InletRho = Psychrometrics::PsyRhoAirFnPbTdbW(state, state.dataEnvrn->OutBaroPress, @@ -2543,17 +2517,18 @@ namespace UserDefinedComponents { } // fill internal variable targets - for (int loop = 1; loop <= this->NumAirConnections; ++loop) { - this->Air(loop).InletRho = Psychrometrics::PsyRhoAirFnPbTdbW(state, - state.dataEnvrn->OutBaroPress, - state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).Temp, - state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).HumRat, - RoutineName); + for (int loop = 0; loop < this->NumAirConnections; ++loop) { + auto &airConnection = this->AirConnections[loop]; + airConnection.InletRho = Psychrometrics::PsyRhoAirFnPbTdbW(state, + state.dataEnvrn->OutBaroPress, + state.dataLoopNodes->Node(airConnection.InletNodeNum).Temp, + state.dataLoopNodes->Node(airConnection.InletNodeNum).HumRat, + RoutineName); - this->Air(loop).InletCp = Psychrometrics::PsyCpAirFnW(state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).HumRat); - this->Air(loop).InletTemp = state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).Temp; - this->Air(loop).InletMassFlowRate = state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).MassFlowRate; - this->Air(loop).InletHumRat = state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).HumRat; + airConnection.InletCp = Psychrometrics::PsyCpAirFnW(state.dataLoopNodes->Node(airConnection.InletNodeNum).HumRat); + airConnection.InletTemp = state.dataLoopNodes->Node(airConnection.InletNodeNum).Temp; + airConnection.InletMassFlowRate = state.dataLoopNodes->Node(airConnection.InletNodeNum).MassFlowRate; + airConnection.InletHumRat = state.dataLoopNodes->Node(airConnection.InletNodeNum).HumRat; } if (this->PlantIsConnected) { @@ -2582,26 +2557,27 @@ namespace UserDefinedComponents { if (this->myOneTimeFlag) { if (this->NumPlantConnections > 0) { - for (int loop = 1; loop <= this->NumPlantConnections; ++loop) { + for (int loop = 0; loop < this->NumPlantConnections; ++loop) { + auto &plantConnection = this->Loop[loop]; bool errFlag = false; PlantUtilities::ScanPlantLoopsForObject(state, this->Name, DataPlant::PlantEquipmentType::ZoneHVACAirUserDefined, - this->Loop(loop).plantLoc, + plantConnection.plantLoc, errFlag, _, _, _, - this->Loop(loop).InletNodeNum, + plantConnection.InletNodeNum, ObjexxFCL::Optional_int_const()); if (errFlag) { ShowFatalError(state, "InitPlantUserComponent: Program terminated due to previous condition(s)."); } // set user input for flow priority - DataPlant::CompData::getPlantComponent(state, this->Loop(loop).plantLoc).FlowPriority = this->Loop(loop).FlowPriority; + DataPlant::CompData::getPlantComponent(state, plantConnection.plantLoc).FlowPriority = plantConnection.FlowPriority; // set user input for how loads served - DataPlant::CompData::getPlantComponent(state, this->Loop(loop).plantLoc).HowLoadServed = this->Loop(loop).HowLoadServed; + DataPlant::CompData::getPlantComponent(state, plantConnection.plantLoc).HowLoadServed = plantConnection.HowLoadServed; } } this->myOneTimeFlag = false; @@ -2633,13 +2609,14 @@ namespace UserDefinedComponents { } if (this->NumPlantConnections > 0) { - for (int loop = 1; loop <= this->NumPlantConnections; ++loop) { - this->Loop(loop).InletRho = this->Loop(loop).plantLoc.loop->glycol->getDensity( - state, state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp, RoutineName); - this->Loop(loop).InletCp = this->Loop(loop).plantLoc.loop->glycol->getSpecificHeat( - state, state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp, RoutineName); - this->Loop(loop).InletTemp = state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp; - this->Loop(loop).InletMassFlowRate = state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).MassFlowRate; + for (int loop = 0; loop < this->NumPlantConnections; ++loop) { + auto &plantConnection = this->Loop[loop]; + plantConnection.InletRho = plantConnection.plantLoc.loop->glycol->getDensity( + state, state.dataLoopNodes->Node(plantConnection.InletNodeNum).Temp, RoutineName); + plantConnection.InletCp = plantConnection.plantLoc.loop->glycol->getSpecificHeat( + state, state.dataLoopNodes->Node(plantConnection.InletNodeNum).Temp, RoutineName); + plantConnection.InletTemp = state.dataLoopNodes->Node(plantConnection.InletNodeNum).Temp; + plantConnection.InletMassFlowRate = state.dataLoopNodes->Node(plantConnection.InletNodeNum).MassFlowRate; } } } @@ -2657,26 +2634,27 @@ namespace UserDefinedComponents { if (this->myOneTimeFlag) { if (this->NumPlantConnections > 0) { - for (int loop = 1; loop <= this->NumPlantConnections; ++loop) { + for (int loop = 0; loop < this->NumPlantConnections; ++loop) { + auto &plantConnection = this->Loop[loop]; bool errFlag = false; PlantUtilities::ScanPlantLoopsForObject(state, this->Name, DataPlant::PlantEquipmentType::AirTerminalUserDefined, - this->Loop(loop).plantLoc, + plantConnection.plantLoc, errFlag, _, _, _, - this->Loop(loop).InletNodeNum, + plantConnection.InletNodeNum, ObjexxFCL::Optional_int_const()); if (errFlag) { ShowFatalError(state, "InitPlantUserComponent: Program terminated due to previous condition(s)."); } // set user input for flow priority - DataPlant::CompData::getPlantComponent(state, this->Loop(loop).plantLoc).FlowPriority = this->Loop(loop).FlowPriority; + DataPlant::CompData::getPlantComponent(state, plantConnection.plantLoc).FlowPriority = plantConnection.FlowPriority; // set user input for how loads served - DataPlant::CompData::getPlantComponent(state, this->Loop(loop).plantLoc).HowLoadServed = this->Loop(loop).HowLoadServed; + DataPlant::CompData::getPlantComponent(state, plantConnection.plantLoc).HowLoadServed = plantConnection.HowLoadServed; } } this->myOneTimeFlag = false; @@ -2708,13 +2686,14 @@ namespace UserDefinedComponents { } if (this->NumPlantConnections > 0) { - for (int loop = 1; loop <= this->NumPlantConnections; ++loop) { - this->Loop(loop).InletRho = this->Loop(loop).plantLoc.loop->glycol->getDensity( - state, state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp, RoutineName); - this->Loop(loop).InletCp = this->Loop(loop).plantLoc.loop->glycol->getSpecificHeat( - state, state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp, RoutineName); - this->Loop(loop).InletTemp = state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).Temp; - this->Loop(loop).InletMassFlowRate = state.dataLoopNodes->Node(this->Loop(loop).InletNodeNum).MassFlowRate; + for (int loop = 0; loop < this->NumPlantConnections; ++loop) { + auto &plantConnection = this->Loop[loop]; + plantConnection.InletRho = plantConnection.plantLoc.loop->glycol->getDensity( + state, state.dataLoopNodes->Node(plantConnection.InletNodeNum).Temp, RoutineName); + plantConnection.InletCp = plantConnection.plantLoc.loop->glycol->getSpecificHeat( + state, state.dataLoopNodes->Node(plantConnection.InletNodeNum).Temp, RoutineName); + plantConnection.InletTemp = state.dataLoopNodes->Node(plantConnection.InletNodeNum).Temp; + plantConnection.InletMassFlowRate = state.dataLoopNodes->Node(plantConnection.InletNodeNum).MassFlowRate; } } } @@ -2734,18 +2713,21 @@ namespace UserDefinedComponents { // METHODOLOGY EMPLOYED: // copy actuated values to structures elsewhere in program. - PlantUtilities::SafeCopyPlantNode(state, this->Loop(LoopNum).InletNodeNum, this->Loop(LoopNum).OutletNodeNum); + if (LoopNum < 0 || LoopNum >= this->NumPlantConnections) { + return; + } + + auto &plantConnection = this->Loop[LoopNum]; + + PlantUtilities::SafeCopyPlantNode(state, plantConnection.InletNodeNum, plantConnection.OutletNodeNum); // unload Actuators to node data structure - state.dataLoopNodes->Node(this->Loop(LoopNum).OutletNodeNum).Temp = this->Loop(LoopNum).OutletTemp; + state.dataLoopNodes->Node(plantConnection.OutletNodeNum).Temp = plantConnection.OutletTemp; // make mass flow requests, just this loop - PlantUtilities::SetComponentFlowRate(state, - this->Loop(LoopNum).MassFlowRateRequest, - this->Loop(LoopNum).InletNodeNum, - this->Loop(LoopNum).OutletNodeNum, - this->Loop(LoopNum).plantLoc); + PlantUtilities::SetComponentFlowRate( + state, plantConnection.MassFlowRateRequest, plantConnection.InletNodeNum, plantConnection.OutletNodeNum, plantConnection.plantLoc); if (this->Air.OutletNodeNum > 0) { state.dataLoopNodes->Node(this->Air.OutletNodeNum).Temp = this->Air.OutletTemp; @@ -2764,12 +2746,12 @@ namespace UserDefinedComponents { this->Water.CollectedVdot; } - if (this->Loop(LoopNum).HowLoadServed == DataPlant::HowMet::ByNominalCapLowOutLimit) { - DataPlant::CompData::getPlantComponent(state, this->Loop(LoopNum).plantLoc).MinOutletTemp = this->Loop(LoopNum).LowOutTempLimit; + if (plantConnection.HowLoadServed == DataPlant::HowMet::ByNominalCapLowOutLimit) { + DataPlant::CompData::getPlantComponent(state, plantConnection.plantLoc).MinOutletTemp = plantConnection.LowOutTempLimit; } - if (this->Loop(LoopNum).HowLoadServed == DataPlant::HowMet::ByNominalCapHiOutLimit) { - DataPlant::CompData::getPlantComponent(state, this->Loop(LoopNum).plantLoc).MaxOutletTemp = this->Loop(LoopNum).HiOutTempLimit; + if (plantConnection.HowLoadServed == DataPlant::HowMet::ByNominalCapHiOutLimit) { + DataPlant::CompData::getPlantComponent(state, plantConnection.plantLoc).MaxOutletTemp = plantConnection.HiOutTempLimit; } } void UserPlantComponentStruct::oneTimeInit(EnergyPlusData &state) @@ -2777,29 +2759,28 @@ namespace UserDefinedComponents { if (this->myOneTimeFlag) { // locate the connections to the plant loops - for (int ConnectionNum = 1; ConnectionNum <= this->NumPlantConnections; ++ConnectionNum) { + for (int connectionIndex = 0; connectionIndex < this->NumPlantConnections; ++connectionIndex) { + auto &plantConnection = this->Loop[connectionIndex]; bool errFlag = false; PlantUtilities::ScanPlantLoopsForObject(state, this->Name, DataPlant::PlantEquipmentType::PlantComponentUserDefined, - this->Loop(ConnectionNum).plantLoc, + plantConnection.plantLoc, errFlag, _, _, _, - this->Loop(ConnectionNum).InletNodeNum, + plantConnection.InletNodeNum, ObjexxFCL::Optional_int_const()); if (errFlag) { ShowFatalError(state, "InitPlantUserComponent: Program terminated due to previous condition(s)."); } // set user input for flow priority - DataPlant::CompData::getPlantComponent(state, this->Loop(ConnectionNum).plantLoc).FlowPriority = - this->Loop(ConnectionNum).FlowPriority; + DataPlant::CompData::getPlantComponent(state, plantConnection.plantLoc).FlowPriority = plantConnection.FlowPriority; // set user input for how loads served - DataPlant::CompData::getPlantComponent(state, this->Loop(ConnectionNum).plantLoc).HowLoadServed = - this->Loop(ConnectionNum).HowLoadServed; + DataPlant::CompData::getPlantComponent(state, plantConnection.plantLoc).HowLoadServed = plantConnection.HowLoadServed; } this->myOneTimeFlag = false; @@ -2818,18 +2799,19 @@ namespace UserDefinedComponents { // PURPOSE OF THIS SUBROUTINE: // report model outputs - for (int loop = 1; loop <= this->NumAirConnections; ++loop) { - if (this->Air(loop).OutletNodeNum > 0) { - state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).Temp = this->Air(loop).OutletTemp; - state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).HumRat = this->Air(loop).OutletHumRat; - state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).MassFlowRate = this->Air(loop).OutletMassFlowRate; - state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).Enthalpy = - Psychrometrics::PsyHFnTdbW(this->Air(loop).OutletTemp, this->Air(loop).OutletHumRat); - - state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).MassFlowRateMinAvail = - state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).MassFlowRateMinAvail; - state.dataLoopNodes->Node(this->Air(loop).OutletNodeNum).MassFlowRateMaxAvail = - state.dataLoopNodes->Node(this->Air(loop).InletNodeNum).MassFlowRateMaxAvail; + for (int loop = 0; loop < this->NumAirConnections; ++loop) { + auto &airConnection = this->AirConnections[loop]; + if (airConnection.OutletNodeNum > 0) { + state.dataLoopNodes->Node(airConnection.OutletNodeNum).Temp = airConnection.OutletTemp; + state.dataLoopNodes->Node(airConnection.OutletNodeNum).HumRat = airConnection.OutletHumRat; + state.dataLoopNodes->Node(airConnection.OutletNodeNum).MassFlowRate = airConnection.OutletMassFlowRate; + state.dataLoopNodes->Node(airConnection.OutletNodeNum).Enthalpy = + Psychrometrics::PsyHFnTdbW(airConnection.OutletTemp, airConnection.OutletHumRat); + + state.dataLoopNodes->Node(airConnection.OutletNodeNum).MassFlowRateMinAvail = + state.dataLoopNodes->Node(airConnection.InletNodeNum).MassFlowRateMinAvail; + state.dataLoopNodes->Node(airConnection.OutletNodeNum).MassFlowRateMaxAvail = + state.dataLoopNodes->Node(airConnection.InletNodeNum).MassFlowRateMaxAvail; } } @@ -2882,16 +2864,17 @@ namespace UserDefinedComponents { } if (this->NumPlantConnections > 0) { - for (int loop = 1; loop <= this->NumPlantConnections; ++loop) { + for (int loop = 0; loop < this->NumPlantConnections; ++loop) { + auto &plantConnection = this->Loop[loop]; // make mass flow requests PlantUtilities::SetComponentFlowRate(state, - this->Loop(loop).MassFlowRateRequest, - this->Loop(loop).InletNodeNum, - this->Loop(loop).OutletNodeNum, - this->Loop(loop).plantLoc); - PlantUtilities::SafeCopyPlantNode(state, this->Loop(loop).InletNodeNum, this->Loop(loop).OutletNodeNum); + plantConnection.MassFlowRateRequest, + plantConnection.InletNodeNum, + plantConnection.OutletNodeNum, + plantConnection.plantLoc); + PlantUtilities::SafeCopyPlantNode(state, plantConnection.InletNodeNum, plantConnection.OutletNodeNum); // unload Actuators to node data structure - state.dataLoopNodes->Node(this->Loop(loop).OutletNodeNum).Temp = this->Loop(loop).OutletTemp; + state.dataLoopNodes->Node(plantConnection.OutletNodeNum).Temp = plantConnection.OutletTemp; } } @@ -2931,16 +2914,17 @@ namespace UserDefinedComponents { } if (this->NumPlantConnections > 0) { - for (int loop = 1; loop <= this->NumPlantConnections; ++loop) { + for (int loop = 0; loop < this->NumPlantConnections; ++loop) { + auto &plantConnection = this->Loop[loop]; // make mass flow requests PlantUtilities::SetComponentFlowRate(state, - this->Loop(loop).MassFlowRateRequest, - this->Loop(loop).InletNodeNum, - this->Loop(loop).OutletNodeNum, - this->Loop(loop).plantLoc); - PlantUtilities::SafeCopyPlantNode(state, this->Loop(loop).InletNodeNum, this->Loop(loop).OutletNodeNum); + plantConnection.MassFlowRateRequest, + plantConnection.InletNodeNum, + plantConnection.OutletNodeNum, + plantConnection.plantLoc); + PlantUtilities::SafeCopyPlantNode(state, plantConnection.InletNodeNum, plantConnection.OutletNodeNum); // unload Actuators to node data structure - state.dataLoopNodes->Node(this->Loop(loop).OutletNodeNum).Temp = this->Loop(loop).OutletTemp; + state.dataLoopNodes->Node(plantConnection.OutletNodeNum).Temp = plantConnection.OutletTemp; } } @@ -3021,7 +3005,7 @@ namespace UserDefinedComponents { ErrorsFound = true; CoilAirInletNode = 0; } else { - CoilAirInletNode = state.dataUserDefinedComponents->UserCoil(CoilIndex).Air(1).InletNodeNum; + CoilAirInletNode = state.dataUserDefinedComponents->UserCoil(CoilIndex).AirConnections[primaryConnIdx].InletNodeNum; } } @@ -3058,7 +3042,7 @@ namespace UserDefinedComponents { ErrorsFound = true; CoilAirOutletNode = 0; } else { - CoilAirOutletNode = state.dataUserDefinedComponents->UserCoil(CoilIndex).Air(1).OutletNodeNum; + CoilAirOutletNode = state.dataUserDefinedComponents->UserCoil(CoilIndex).AirConnections[primaryConnIdx].OutletNodeNum; } } diff --git a/src/EnergyPlus/UserDefinedComponents.hh b/src/EnergyPlus/UserDefinedComponents.hh index 20eabb79419..a9cdde3c831 100644 --- a/src/EnergyPlus/UserDefinedComponents.hh +++ b/src/EnergyPlus/UserDefinedComponents.hh @@ -48,8 +48,8 @@ #ifndef UserDefinedComponents_hh_INCLUDED #define UserDefinedComponents_hh_INCLUDED -// ObjexxFCL Headers -#include +// C++ Headers +#include // EnergyPlus Headers #include @@ -64,6 +64,8 @@ namespace EnergyPlus { // Forward declarations struct EnergyPlusData; +int constexpr primaryConnIdx = 0; + namespace UserDefinedComponents { struct PlantConnectionStruct @@ -176,8 +178,8 @@ namespace UserDefinedComponents { int ErlSimProgramMngr; // EMS:ProgramManager to always run when this model is called int simPluginLocation; // If Python Plugins are used to simulate this, this defines the location in the plugin structure int simCallbackIndex = -1; - int NumPlantConnections; // count of how many plant loop connections there are - Array1D Loop; // collect data for each plant loop connection + int NumPlantConnections; // count of how many plant loop connections there are + std::vector Loop; // collect data for each plant loop connection AirConnectionStruct Air; WaterUseTankConnectionStruct Water; ZoneInternalGainsStruct Zone; @@ -217,7 +219,7 @@ namespace UserDefinedComponents { int simCallbackIndex = -1; // If API callbacks are used to simulate this, this defines the location in the vector int NumAirConnections; // count of how many air connections there are bool PlantIsConnected; - Array1D Air; + std::vector AirConnections; PlantConnectionStruct Loop; WaterUseTankConnectionStruct Water; ZoneInternalGainsStruct Zone; @@ -246,8 +248,8 @@ namespace UserDefinedComponents { int initCallbackIndex = -1; // If API callbacks are used to init this, this defines the location in the vector int simCallbackIndex = -1; // If API callbacks are used to simulate this, this defines the location in the vector AirConnectionStruct SourceAir; - int NumPlantConnections; // count of how many plant loop (demand) connections there are - Array1D Loop; // collect data for each plant loop connection + int NumPlantConnections; // count of how many plant loop (demand) connections there are + std::vector Loop; // collect data for each plant loop connection WaterUseTankConnectionStruct Water; ZoneInternalGainsStruct Zone; // for skin losses Real64 RemainingOutputToHeatingSP; // sensible load remaining for device, to heating setpoint [W] @@ -344,10 +346,10 @@ struct UserDefinedComponentsData : BaseGlobalStruct bool GetAirTerminalInput = true; bool GetPlantCompInput = true; - Array1D_bool CheckUserPlantCompName; - Array1D_bool CheckUserCoilName; - Array1D_bool CheckUserZoneAirName; - Array1D_bool CheckUserAirTerminal; + std::vector CheckUserPlantCompName; + std::vector CheckUserCoilName; + std::vector CheckUserZoneAirName; + std::vector CheckUserAirTerminal; // Object Data EPVector UserPlantComp; @@ -374,10 +376,10 @@ struct UserDefinedComponentsData : BaseGlobalStruct this->NumUserCoils = 0; this->NumUserZoneAir = 0; this->NumUserAirTerminals = 0; - this->CheckUserPlantCompName.deallocate(); - this->CheckUserCoilName.deallocate(); - this->CheckUserZoneAirName.deallocate(); - this->CheckUserAirTerminal.deallocate(); + this->CheckUserPlantCompName.clear(); + this->CheckUserCoilName.clear(); + this->CheckUserZoneAirName.clear(); + this->CheckUserAirTerminal.clear(); this->UserPlantComp.deallocate(); this->UserCoil.deallocate(); this->UserZoneAirHVAC.deallocate();