Skip to content

Commit

Permalink
Merge pull request #10585 from NREL/Begin_init_state_use
Browse files Browse the repository at this point in the history
Move getInputs to init_state and update unit tests
  • Loading branch information
Myoldmopar authored Jul 11, 2024
2 parents 5e4cb34 + e4ad216 commit 0645a51
Show file tree
Hide file tree
Showing 56 changed files with 221 additions and 219 deletions.
9 changes: 6 additions & 3 deletions src/EnergyPlus/Data/EnergyPlusData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ EnergyPlusData::~EnergyPlusData() = default;
void EnergyPlusData::clear_state()
{
this->ready = true;
this->init_state_called = false;
this->dataAirLoop->clear_state();
this->dataAirLoopHVACDOAS->clear_state();
this->dataAirSystemsData->clear_state();
Expand Down Expand Up @@ -570,11 +571,15 @@ void EnergyPlusData::clear_state()

void EnergyPlusData::init_state(EnergyPlusData &state)
{
if (this->init_state_called) return;
this->init_state_called = true;
// The order in which we do this matters. We're going to try to
// do this in "topological" order meaning the first to go are the
// objects that do not reference any other objects, like fluids,
// schedules, curves, etc.
this->dataFluidProps->init_state(state);
this->dataSimulationManager->init_state(state); // GetProjectData
this->dataFluidProps->init_state(state); // GetFluidPropertiesData
this->dataPsychrometrics->init_state(state); // InitializePsychRoutines

this->dataAirLoop->init_state(state);
this->dataAirLoopHVACDOAS->init_state(state);
Expand Down Expand Up @@ -736,7 +741,6 @@ void EnergyPlusData::init_state(EnergyPlusData &state)
this->dataPollution->init_state(state);
this->dataPondGHE->init_state(state);
this->dataPowerInductionUnits->init_state(state);
this->dataPsychrometrics->init_state(state);
this->dataPsychCache->init_state(state);
this->dataPumps->init_state(state);
this->dataPurchasedAirMgr->init_state(state);
Expand All @@ -758,7 +762,6 @@ void EnergyPlusData::init_state(EnergyPlusData &state)
this->dataSetPointManager->init_state(state);
this->dataShadowComb->init_state(state);
this->dataSimAirServingZones->init_state(state);
this->dataSimulationManager->init_state(state);
this->dataSingleDuct->init_state(state);
this->dataSize->init_state(state);
this->dataSizingManager->init_state(state);
Expand Down
1 change: 1 addition & 0 deletions src/EnergyPlus/Data/EnergyPlusData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ struct EnergyPlusData : BaseGlobalStruct
EnergyPlusData(EnergyPlusData &&) = delete;

void init_state([[maybe_unused]] EnergyPlusData &state) override;
bool init_state_called = false;

void clear_state() override;
};
Expand Down
134 changes: 8 additions & 126 deletions src/EnergyPlus/FluidProperties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ namespace FluidProperties {
// supplying the same data for concentrations of 0.0 and 1.0 only.
// Temperature data has to be supplied in ascending order only.

void InitializeGlycRoutines()
{
// TODO: Delete this, the cache is now part of state and initialized with the state constructor
}

void GetFluidPropertiesData(EnergyPlusData &state)
{

Expand Down Expand Up @@ -162,6 +157,9 @@ namespace FluidProperties {
// Array initializer only takes one argument. std::bind is used to convert the
// actual initializer into a function of one argument.

state.dataFluidProps->NumOfRefrigerants = 0;
state.dataFluidProps->NumOfGlycols = 0;

// For default "glycol" fluids of Water, Ethylene Glycol, and Propylene Glycol

static constexpr std::array<Real64, DefaultNumGlyTemps> DefaultGlycolTemps = {
Expand Down Expand Up @@ -657,8 +655,6 @@ namespace FluidProperties {
cNumericFieldNames = "";
lNumericFieldBlanks = false;

InitializeGlycRoutines();

// Check to see if there is any FluidName input. If not, this is okay as
// long as the user only desires to simulate loops with water. More than
// one FluidName input is not allowed.
Expand Down Expand Up @@ -4926,8 +4922,6 @@ namespace FluidProperties {
Real64 Temperature; // Temperature to drive values
Real64 ReturnValue; // Values returned from glycol functions

state.dataFluidProps->GetInput = false; // input has already been gotten

for (int GlycolNum = 1; GlycolNum <= state.dataFluidProps->NumOfGlycols; ++GlycolNum) {
auto &glycol = state.dataFluidProps->GlycolData(GlycolNum);
int GlycolIndex = 0; // used in routine calls -- value is returned when first 0
Expand Down Expand Up @@ -5168,8 +5162,6 @@ namespace FluidProperties {
Real64 Temperature; // Temperature to drive values
Real64 ReturnValue; // Values returned from refrigerant functions

state.dataFluidProps->GetInput = false; // input has already been gotten

for (int RefrigNum = 1; RefrigNum <= state.dataFluidProps->NumOfRefrigerants; ++RefrigNum) {
int RefrigIndex = 0; // used in routine calls -- value is returned when first 0
// Lay out the basic values:
Expand Down Expand Up @@ -5606,23 +5598,15 @@ namespace FluidProperties {
// FUNCTION LOCAL VARIABLE DECLARATIONS:
int HiTempIndex; // index value of next highest Temperature from table
int LoTempIndex; // index value of next lowest Temperature from table
int RefrigNum; // index for refrigerant under consideration
Real64 TempInterpRatio; // ratio to interpolate in temperature domain
// error counters and dummy string
bool ErrorFlag; // error flag for current call

if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

RefrigNum = 0;
int RefrigNum = 0; // index for refrigerant under consideration
if (state.dataFluidProps->NumOfRefrigerants == 0) {
ReportFatalRefrigerantErrors(
state, state.dataFluidProps->NumOfRefrigerants, RefrigNum, true, Refrigerant, "GetSatPressureRefrig", "properties", CalledFrom);
}

ErrorFlag = false;
bool ErrorFlag = false;

if (RefrigIndex > 0) {
RefrigNum = RefrigIndex;
Expand Down Expand Up @@ -5717,23 +5701,15 @@ namespace FluidProperties {
// FUNCTION LOCAL VARIABLE DECLARATIONS:
int HiPresIndex; // index value of next highest Temperature from table
int LoPresIndex; // index value of next lowest Temperature from table
int RefrigNum; // index for refrigerant under consideration
Real64 PresInterpRatio; // ratio to interpolate in temperature domain
// error counters and dummy string
bool ErrorFlag; // error flag for current call

if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

RefrigNum = 0;
int RefrigNum = 0; // index for refrigerant under consideration
if (state.dataFluidProps->NumOfRefrigerants == 0) {
ReportFatalRefrigerantErrors(
state, state.dataFluidProps->NumOfRefrigerants, RefrigNum, true, Refrigerant, "GetSatTemperatureRefrig", "properties", CalledFrom);
}

ErrorFlag = false;
bool ErrorFlag = false;

if (RefrigIndex > 0) {
RefrigNum = RefrigIndex;
Expand Down Expand Up @@ -5832,14 +5808,7 @@ namespace FluidProperties {
static constexpr std::string_view RoutineName("GetSatEnthalpyRefrig");

// FUNCTION LOCAL VARIABLE DECLARATIONS:
int RefrigNum; // index for refrigerant under consideration

if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

RefrigNum = 0;
int RefrigNum = 0;
if (state.dataFluidProps->NumOfRefrigerants == 0) {
ReportFatalRefrigerantErrors(
state, state.dataFluidProps->NumOfRefrigerants, RefrigNum, true, Refrigerant, RoutineName, "properties", CalledFrom);
Expand Down Expand Up @@ -5905,13 +5874,6 @@ namespace FluidProperties {
Real64 HiSatProp; // Sat. prop. at higher temp & given quality
Real64 TempInterpRatio; // ratio to interpolate in temperature domain

// error counters and dummy string

if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

int RefrigNum = 0;
if (state.dataFluidProps->NumOfRefrigerants == 0) {
ReportFatalRefrigerantErrors(
Expand Down Expand Up @@ -6040,11 +6002,6 @@ namespace FluidProperties {
// FUNCTION PARAMETER DEFINITIONS:
static constexpr std::string_view RoutineName("GetSatSpecificHeatRefrig: ");

if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

int RefrigNum = 0;
if (state.dataFluidProps->NumOfRefrigerants == 0) {
ReportFatalRefrigerantErrors(
Expand Down Expand Up @@ -6146,12 +6103,6 @@ namespace FluidProperties {
int HiTempIndex; // high temperature index value
int HiPressIndex; // high pressure index value

// see if data is there
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

int RefrigNum = 0;
if (state.dataFluidProps->NumOfRefrigerants == 0) {
ReportFatalRefrigerantErrors(
Expand Down Expand Up @@ -6398,11 +6349,6 @@ namespace FluidProperties {
int LoEnthalpyIndex; // Index value of lower enthalpy from data
int HiEnthalpyIndex; // Index value of higher enthalpy from data

if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

int RefrigNum = 0;
if (state.dataFluidProps->NumOfRefrigerants == 0) {
ReportFatalRefrigerantErrors(
Expand Down Expand Up @@ -6674,11 +6620,6 @@ namespace FluidProperties {
Real64 RefTSat; // Saturated temperature of the refrigerant. Used to check whether the refrigernat is in the superheat area
Real64 Temp; // Temperature of the superheated refrigerant at the given enthalpy and pressure

if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

RefrigNum = 0;
if (state.dataFluidProps->NumOfRefrigerants == 0) {
ReportFatalRefrigerantErrors(
Expand Down Expand Up @@ -6822,12 +6763,6 @@ namespace FluidProperties {
int HiTempIndex; // high temperature index value
int HiPressIndex; // high pressure index value

// see if data is there
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

int RefrigNum = 0;
if (state.dataFluidProps->NumOfRefrigerants == 0) {
ReportFatalRefrigerantErrors(
Expand Down Expand Up @@ -7091,12 +7026,6 @@ namespace FluidProperties {
// FUNCTION PARAMETERS:
static constexpr std::string_view RoutineName("GetSpecificHeatGlycol: ");

// Get the input if we haven't already
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

// If no glycols, no fluid properties can be evaluated
int GlycolNum(0);
if (state.dataFluidProps->NumOfGlycols == 0)
Expand Down Expand Up @@ -7243,12 +7172,6 @@ namespace FluidProperties {
bool LowErrorThisTime = false;
bool HighErrorThisTime = false;

// Get the input if we haven't already
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

// If no glycols, no fluid properties can be evaluated
int GlycolNum = 0;
if (state.dataFluidProps->NumOfGlycols == 0)
Expand Down Expand Up @@ -7406,12 +7329,6 @@ namespace FluidProperties {
bool LowErrorThisTime = false;
bool HighErrorThisTime = false;

// Get the input if we haven't already
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

// If no glycols, no fluid properties can be evaluated
int GlycolNum = 0;
if (state.dataFluidProps->NumOfGlycols == 0)
Expand Down Expand Up @@ -7572,12 +7489,6 @@ namespace FluidProperties {
bool LowErrorThisTime = false;
bool HighErrorThisTime = false;

// Get the input if we haven't already
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

// If no glycols, no fluid properties can be evaluated
int GlycolNum = 0;
if (state.dataFluidProps->NumOfGlycols == 0)
Expand Down Expand Up @@ -7727,12 +7638,6 @@ namespace FluidProperties {
// Return value
int FindRefrigerant;

// Make sure we have already read in the input
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

// Check to see if this glycol shows up in the glycol data
int Found = Util::FindItemInList(Util::makeUPPER(Refrigerant), state.dataFluidProps->RefrigData);

Expand Down Expand Up @@ -7769,12 +7674,6 @@ namespace FluidProperties {
// Return value
int FindGlycol;

// Make sure we have already read in the input
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

// Check to see if this glycol shows up in the glycol data
int Found = Util::FindItemInList(Util::makeUPPER(Glycol),
state.dataFluidProps->GlycolData,
Expand Down Expand Up @@ -8024,11 +7923,6 @@ namespace FluidProperties {
// Return value
int CheckFluidPropertyName;

if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

// Item must be either in Refrigerant or Glycol list
int Found = 0;
if (state.dataFluidProps->NumOfRefrigerants > 0) {
Expand Down Expand Up @@ -8192,12 +8086,6 @@ namespace FluidProperties {
void GetFluidDensityTemperatureLimits(EnergyPlusData &state, int const FluidIndex, Real64 &MinTempLimit, Real64 &MaxTempLimit)
{

// Get the input if we haven't already
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

if (FluidIndex > 0) {
MinTempLimit = state.dataFluidProps->GlycolData(FluidIndex).RhoLowTempValue;
MaxTempLimit = state.dataFluidProps->GlycolData(FluidIndex).RhoHighTempValue;
Expand All @@ -8206,12 +8094,6 @@ namespace FluidProperties {

void GetFluidSpecificHeatTemperatureLimits(EnergyPlusData &state, int const FluidIndex, Real64 &MinTempLimit, Real64 &MaxTempLimit)
{
// Get the input if we haven't already
if (state.dataFluidProps->GetInput) {
GetFluidPropertiesData(state);
state.dataFluidProps->GetInput = false;
}

if (FluidIndex > 0) {
MinTempLimit = state.dataFluidProps->GlycolData(FluidIndex).CpLowTempValue;
MaxTempLimit = state.dataFluidProps->GlycolData(FluidIndex).CpHighTempValue;
Expand Down
4 changes: 0 additions & 4 deletions src/EnergyPlus/FluidProperties.hh
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ namespace FluidProperties {
}
};

void InitializeGlycRoutines();

void GetFluidPropertiesData(EnergyPlusData &state);

template <size_t NumOfTemps, size_t NumOfConcs>
Expand Down Expand Up @@ -627,7 +625,6 @@ namespace FluidProperties {
struct FluidPropertiesData : BaseGlobalStruct
{

bool GetInput = true; // Used to get the input once only
int NumOfRefrigerants = 0; // Total number of refrigerants input by user
int NumOfGlycols = 0; // Total number of glycols input by user
bool DebugReportGlycols = false;
Expand Down Expand Up @@ -665,7 +662,6 @@ struct FluidPropertiesData : BaseGlobalStruct
void init_state(EnergyPlusData &state) override
{
FluidProperties::GetFluidPropertiesData(state);
this->GetInput = false;
}

void clear_state() override
Expand Down
Loading

5 comments on commit 0645a51

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-MacOS-10.18-clang-15.0.0: OK (2846 of 2846 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (2867 of 2867 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2845 of 2845 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (795 of 795 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (2053 of 2053 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.