Skip to content

Commit

Permalink
move HVACControllers to state
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchute committed Mar 12, 2021
1 parent 2577e2f commit b7b900e
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 155 deletions.
12 changes: 6 additions & 6 deletions src/EnergyPlus/FaultsManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -873,25 +873,25 @@ namespace FaultsManager {
ErrorsFound = true;
}
// Read in controller input if not done yet
if (HVACControllers::GetControllerInputFlag) {
if (state.dataHVACControllers->GetControllerInputFlag) {
HVACControllers::GetControllerInput(state);
HVACControllers::GetControllerInputFlag = false;
state.dataHVACControllers->GetControllerInputFlag = false;
}
// Check the controller name
int ControlNum = UtilityRoutines::FindItemInList(state.dataFaultsMgr->FaultsCoilSATSensor(jFault_CoilSAT).WaterCoilControllerName,
HVACControllers::ControllerProps,
state.dataHVACControllers->ControllerProps,
&HVACControllers::ControllerPropsType::ControllerName);
if (ControlNum <= 0) {
ShowSevereError(state, cFaultCurrentObject + " = \"" + cAlphaArgs(1) + "\" invalid " + cAlphaFieldNames(6) + " = \"" +
cAlphaArgs(6) + "\" not found.");
ErrorsFound = true;
} else {
// Link the controller with the fault model
HVACControllers::ControllerProps(ControlNum).FaultyCoilSATFlag = true;
HVACControllers::ControllerProps(ControlNum).FaultyCoilSATIndex = jFault_CoilSAT;
state.dataHVACControllers->ControllerProps(ControlNum).FaultyCoilSATFlag = true;
state.dataHVACControllers->ControllerProps(ControlNum).FaultyCoilSATIndex = jFault_CoilSAT;

// Check whether the controller match the coil
if (HVACControllers::ControllerProps(ControlNum).SensedNode != state.dataWaterCoils->WaterCoil(CoilNum).AirOutletNodeNum) {
if (state.dataHVACControllers->ControllerProps(ControlNum).SensedNode != state.dataWaterCoils->WaterCoil(CoilNum).AirOutletNodeNum) {
ShowSevereError(state, cFaultCurrentObject + " = \"" + cAlphaArgs(1) + "\" invalid " + cAlphaFieldNames(6) + " = \"" +
cAlphaArgs(6) + "\" does not match " + cAlphaFieldNames(5) + " = \"" + cAlphaArgs(5));
ErrorsFound = true;
Expand Down
184 changes: 103 additions & 81 deletions src/EnergyPlus/HVACControllers.cc

Large diffs are not rendered by default.

53 changes: 28 additions & 25 deletions src/EnergyPlus/HVACControllers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,6 @@ namespace HVACControllers {
Heating,
};

// MODULE VARIABLE DECLARATIONS:
extern int NumControllers; // The number of controllers found in the Input
extern int NumAirLoopStats; // Same size as NumPrimaryAirSys if controllers
// are defined, 0 otherwise.
// all controllers per air loop
extern Array1D_bool CheckEquipName;

// Flag set to make sure you get input once
extern bool GetControllerInputFlag;

// Types

struct SolutionTrackerType
{
// Members
Expand Down Expand Up @@ -264,16 +252,6 @@ namespace HVACControllers {
}
};

// Object Data
extern Array1D<ControllerPropsType> ControllerProps;
extern Array1D<RootFinderDataType> RootFinders;
extern Array1D<AirLoopStatsType> AirLoopStats; // Statistics array to analyze computational profile for

// Functions

// Needed for unit tests, should not be normally called.
void clear_state();

void ManageControllers(EnergyPlusData &state,
std::string const &ControllerName,
int &ControllerIndex,
Expand Down Expand Up @@ -317,11 +295,11 @@ namespace HVACControllers {

void CheckTempAndHumRatCtrl(EnergyPlusData &state, int ControlNum, bool &IsConvergedFlag);

void SaveSimpleController(int ControlNum, bool FirstHVACIteration, bool IsConvergedFlag);
void SaveSimpleController(EnergyPlusData &state, int ControlNum, bool FirstHVACIteration, bool IsConvergedFlag);

void UpdateController(EnergyPlusData &state, int ControlNum);

void ExitCalcController(int ControlNum, Real64 NextActuatedValue, int Mode, bool &IsConvergedFlag, bool &IsUpToDateFlag);
void ExitCalcController(EnergyPlusData &state, int ControlNum, Real64 NextActuatedValue, int Mode, bool &IsConvergedFlag, bool &IsUpToDateFlag);

void TrackAirLoopControllers(
EnergyPlusData &state, int AirLoopNum, int WarmRestartStatus, int AirLoopIterMax, int AirLoopIterTot, int AirLoopNumCalls);
Expand All @@ -345,7 +323,7 @@ namespace HVACControllers {
void TraceIterationStamp(
EnergyPlusData &state, InputOutputFile &TraceFile, bool FirstHVACIteration, int AirLoopPass, bool AirLoopConverged, int AirLoopNumCalls);

void TraceAirLoopController(InputOutputFile &TraceFile, int ControlNum);
void TraceAirLoopController(EnergyPlusData &state, InputOutputFile &TraceFile, int ControlNum);

void SetupIndividualControllerTracer(EnergyPlusData &state, int ControlNum);

Expand Down Expand Up @@ -390,9 +368,34 @@ namespace HVACControllers {

struct HVACControllersData : BaseGlobalStruct
{
int NumControllers = 0; // The number of controllers found in the Input
int NumAirLoopStats = 0; // Same size as NumPrimaryAirSys if controllers
Array1D_bool CheckEquipName;
bool GetControllerInputFlag = true;
bool InitControllerOneTimeFlag = true;
bool InitControllerSetPointCheckFlag = true;
Array1D<HVACControllers::ControllerPropsType> ControllerProps;
Array1D<HVACControllers::RootFinderDataType> RootFinders;
Array1D<HVACControllers::AirLoopStatsType> AirLoopStats; // Statistics array to analyze computational profile for
Array1D_bool MyEnvrnFlag;
Array1D_bool MySizeFlag;
Array1D_bool MyPlantIndexsFlag;


void clear_state() override
{
this->NumControllers = 0;
this->NumAirLoopStats = 0;
this->CheckEquipName.deallocate();
this->GetControllerInputFlag = true;
this->InitControllerOneTimeFlag = true;
this->InitControllerSetPointCheckFlag = true;
this->ControllerProps.deallocate();
this->RootFinders.deallocate();
this->AirLoopStats.deallocate();
this->MyEnvrnFlag.deallocate();
this->MySizeFlag.deallocate();
this->MyPlantIndexsFlag.deallocate();
}
};

Expand Down
9 changes: 4 additions & 5 deletions src/EnergyPlus/MixedAir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ namespace EnergyPlus::MixedAir {
using HeatingCoils::SimulateHeatingCoilComponents;
using HeatRecovery::SimHeatRecovery;
using Humidifiers::SimHumidifier;
using HVACControllers::ControllerProps;
using HVACDXHeatPumpSystem::SimDXHeatPumpSystem;
using HVACDXSystem::SimDXCoolingSystem;
using HVACHXAssistedCoolingCoil::HXAssistedCoil;
Expand Down Expand Up @@ -478,7 +477,7 @@ namespace EnergyPlus::MixedAir {
state.dataWaterCoils->WaterCoil(CompIndex).ControllerIndex,
false);
// set flag to tell HVAC controller it will be simulated only in SolveWaterCoilController()
ControllerProps(state.dataWaterCoils->WaterCoil(CompIndex).ControllerIndex).BypassControllerCalc = true;
state.dataHVACControllers->ControllerProps(state.dataWaterCoils->WaterCoil(CompIndex).ControllerIndex).BypassControllerCalc = true;
}
OACoolingCoil = true;
} else if (SELECT_CASE_var == WaterCoil_SimpleHeat) { // 'Coil:Heating:Water')
Expand All @@ -495,7 +494,7 @@ namespace EnergyPlus::MixedAir {
state.dataWaterCoils->WaterCoil(CompIndex).ControllerIndex,
false);
// set flag to tell HVAC controller it will be simulated only in SolveWaterCoilController()
ControllerProps(state.dataWaterCoils->WaterCoil(CompIndex).ControllerIndex).BypassControllerCalc = true;
state.dataHVACControllers->ControllerProps(state.dataWaterCoils->WaterCoil(CompIndex).ControllerIndex).BypassControllerCalc = true;
}
OAHeatingCoil = true;
} else if (SELECT_CASE_var == SteamCoil_AirHeat) { // 'Coil:Heating:Steam'
Expand All @@ -517,7 +516,7 @@ namespace EnergyPlus::MixedAir {
state.dataWaterCoils->WaterCoil(CompIndex).ControllerIndex,
false);
// set flag to tell HVAC controller it will be simulated only in SolveWaterCoilController()
ControllerProps(state.dataWaterCoils->WaterCoil(CompIndex).ControllerIndex).BypassControllerCalc = true;
state.dataHVACControllers->ControllerProps(state.dataWaterCoils->WaterCoil(CompIndex).ControllerIndex).BypassControllerCalc = true;
}
OACoolingCoil = true;
} else if (SELECT_CASE_var == Coil_ElectricHeat) { // 'Coil:Heating:Electric'
Expand Down Expand Up @@ -546,7 +545,7 @@ namespace EnergyPlus::MixedAir {
HXAssistedCoil(CompIndex).ControllerIndex,
true);
// set flag to tell HVAC controller it will be simulated only in SolveWaterCoilController()
ControllerProps(HXAssistedCoil(CompIndex).ControllerIndex).BypassControllerCalc = true;
state.dataHVACControllers->ControllerProps(HXAssistedCoil(CompIndex).ControllerIndex).BypassControllerCalc = true;
}
OACoolingCoil = true;
} else if (SELECT_CASE_var == DXSystem) { // CoilSystem:Cooling:DX old 'AirLoopHVAC:UnitaryCoolOnly'
Expand Down
8 changes: 4 additions & 4 deletions src/EnergyPlus/SimAirServingZones.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2840,7 +2840,7 @@ namespace EnergyPlus::SimAirServingZones {
for (int AirLoopControlNum = 1; AirLoopControlNum <= PrimaryAirSystems(AirLoopNum).NumControllers; ++AirLoopControlNum) {
PrimaryAirSystems(AirLoopNum).ControllerIndex(AirLoopControlNum) =
HVACControllers::GetControllerIndex(state, PrimaryAirSystems(AirLoopNum).ControllerName(AirLoopControlNum));
HVACControllers::ControllerProps(PrimaryAirSystems(AirLoopNum).ControllerIndex(AirLoopControlNum)).AirLoopControllerIndex =
state.dataHVACControllers->ControllerProps(PrimaryAirSystems(AirLoopNum).ControllerIndex(AirLoopControlNum)).AirLoopControllerIndex =
AirLoopControlNum;
}
// When using controllers, size air loop coils so ControllerProps (e.g., Min/Max Actuated) can be set
Expand Down Expand Up @@ -3111,7 +3111,7 @@ namespace EnergyPlus::SimAirServingZones {
// if the controller can be locked out by the economizer operation and the economizer is active, leave the controller inactive
if (AirLoopCheck) {
if (AirLoopControlInfo(AirLoopNum).EconoActive) {
if (PrimaryAirSystems(AirLoopNum).CanBeLockedOutByEcono(HVACControllers::ControllerProps(ControllerIndex).AirLoopControllerIndex)) {
if (PrimaryAirSystems(AirLoopNum).CanBeLockedOutByEcono(state.dataHVACControllers->ControllerProps(ControllerIndex).AirLoopControllerIndex)) {
ControllerConvergedFlag = true;
}
}
Expand All @@ -3133,7 +3133,7 @@ namespace EnergyPlus::SimAirServingZones {
BypassOAController);

if (AirLoopCheck) {
PrimaryAirSystems(AirLoopNum).ControlConverged(HVACControllers::ControllerProps(ControllerIndex).AirLoopControllerIndex) =
PrimaryAirSystems(AirLoopNum).ControlConverged(state.dataHVACControllers->ControllerProps(ControllerIndex).AirLoopControllerIndex) =
ControllerConvergedFlag;
}

Expand Down Expand Up @@ -3196,7 +3196,7 @@ namespace EnergyPlus::SimAirServingZones {

// pass convergence of OA system water coils back to SolveAirLoopControllers via PrimaryAirSystem().ControlConverged flag
if (AirLoopCheck) {
PrimaryAirSystems(AirLoopNum).ControlConverged(HVACControllers::ControllerProps(ControllerIndex).AirLoopControllerIndex) =
PrimaryAirSystems(AirLoopNum).ControlConverged(state.dataHVACControllers->ControllerProps(ControllerIndex).AirLoopControllerIndex) =
ControllerConvergedFlag;
AirLoopControlInfo(AirLoopNum).ConvergedFlag = AirLoopControlInfo(AirLoopNum).ConvergedFlag && ControllerConvergedFlag;
}
Expand Down
2 changes: 0 additions & 2 deletions src/EnergyPlus/StateManagement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
#include <EnergyPlus/General.hh>
#include <EnergyPlus/GeneralRoutines.hh>
#include <EnergyPlus/GroundTemperatureModeling/GroundTemperatureModelManager.hh>
#include <EnergyPlus/HVACControllers.hh>
#include <EnergyPlus/HVACCooledBeam.hh>
#include <EnergyPlus/HVACDXSystem.hh>
#include <EnergyPlus/HVACDuct.hh>
Expand Down Expand Up @@ -159,7 +158,6 @@ void EnergyPlus::clearAllStates(EnergyPlusData &state)
HeatingCoils::clear_state();
HighTempRadiantSystem::clear_state();
Humidifiers::clear_state();
HVACControllers::clear_state();
HVACCooledBeam::clear_state();
HVACDuct::clear_state();
HVACDXSystem::clear_state();
Expand Down
4 changes: 2 additions & 2 deletions tst/EnergyPlus/unit/FaultsManager.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ TEST_F(EnergyPlusFixture, FaultsManager_TemperatureSensorOffset_CoilSAT)
// Check
EXPECT_EQ(2.0, state->dataFaultsMgr->FaultsCoilSATSensor(1).Offset);
EXPECT_EQ("COIL:COOLING:WATER", state->dataFaultsMgr->FaultsCoilSATSensor(1).CoilType);
EXPECT_TRUE(HVACControllers::ControllerProps(1).FaultyCoilSATFlag);
EXPECT_EQ(1, HVACControllers::ControllerProps(1).FaultyCoilSATIndex);
EXPECT_TRUE(state->dataHVACControllers->ControllerProps(1).FaultyCoilSATFlag);
EXPECT_EQ(1, state->dataHVACControllers->ControllerProps(1).FaultyCoilSATIndex);
}

TEST_F(EnergyPlusFixture, FaultsManager_FaultChillerSWTSensor_CalFaultChillerSWT)
Expand Down
Loading

0 comments on commit b7b900e

Please sign in to comment.