Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/EnergyPlus/DataRuntimeLanguage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,12 @@ namespace DataRuntimeLanguage {
int TrendVarPointer; // index to match in TrendVariable structure
std::string Error; // holds error message string for reporting
bool initialized; // true if number value has been SET (ie. has been on LHS in SET expression)
bool SetupInit; // false when marked by an uninitialized-variable evaluation error so it can be treated as uninitialized later

// Default Constructor
ErlValueType() : Type(Value::Null), Number(0.0), Variable(0), Expression(0), TrendVariable(false), TrendVarPointer(0), initialized(false)
ErlValueType()
: Type(Value::Null), Number(0.0), Variable(0), Expression(0), TrendVariable(false), TrendVarPointer(0), initialized(false),
SetupInit(true)
{
}

Expand All @@ -379,9 +382,10 @@ namespace DataRuntimeLanguage {
bool const TrendVariable, // true if Erl variable is really a trend variable
int const TrendVarPointer, // index to match in TrendVariable structure
std::string const &Error, // holds error message string for reporting
bool const initialized)
bool const initialized,
bool const SetupInit)
: Type(Type), Number(Number), String(String), Variable(Variable), Expression(Expression), TrendVariable(TrendVariable),
TrendVarPointer(TrendVarPointer), Error(Error), initialized(initialized)
TrendVarPointer(TrendVarPointer), Error(Error), initialized(initialized), SetupInit(SetupInit)
{
}
};
Expand Down Expand Up @@ -803,11 +807,11 @@ struct RuntimeLanguageData : BaseGlobalStruct
Array1D<DataRuntimeLanguage::InternalVarsUsedType> EMSInternalVarsUsed; // internal data that are used
Array1D<DataRuntimeLanguage::EMSProgramCallManagementType> EMSProgramCallManager; // program calling managers
DataRuntimeLanguage::ErlValueType Null = DataRuntimeLanguage::ErlValueType(
DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true); // special "null" Erl variable value instance
DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true, true); // special "null" Erl variable value instance
DataRuntimeLanguage::ErlValueType False = DataRuntimeLanguage::ErlValueType(
DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true); // special "false" Erl variable value instance
DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true, true); // special "false" Erl variable value instance
DataRuntimeLanguage::ErlValueType True = DataRuntimeLanguage::ErlValueType(
DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true); // special "True" Erl variable value instance, gets reset
DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true, true); // special "True" Erl variable value instance, gets reset

std::map<std::tuple<std::string, std::string, std::string>, int> EMSActuatorAvailableMap;

Expand Down Expand Up @@ -866,9 +870,9 @@ struct RuntimeLanguageData : BaseGlobalStruct
this->EMSInternalVarsAvailable.deallocate();
this->EMSInternalVarsUsed.deallocate();
this->EMSProgramCallManager.deallocate();
this->Null = DataRuntimeLanguage::ErlValueType(DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true);
this->False = DataRuntimeLanguage::ErlValueType(DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true);
this->True = DataRuntimeLanguage::ErlValueType(DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true);
this->Null = DataRuntimeLanguage::ErlValueType(DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true, true);
this->False = DataRuntimeLanguage::ErlValueType(DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true, true);
this->True = DataRuntimeLanguage::ErlValueType(DataRuntimeLanguage::Value::Null, 0.0, "", 0, 0, false, 0, "", true, true);

this->EMSActuatorAvailableMap.clear();
}
Expand Down
21 changes: 12 additions & 9 deletions src/EnergyPlus/RuntimeLanguageProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ void BeginEnvrnInitializeRuntimeLanguage(EnergyPlusData &state)
if (state.dataRuntimeLang->ErlVariable(ErlVariableNum).Value.initialized) {
state.dataRuntimeLang->ErlVariable(ErlVariableNum).Value =
SetErlValueNumber(0.0, state.dataRuntimeLang->ErlVariable(ErlVariableNum).Value);

if (!state.dataRuntimeLang->ErlVariable(ErlVariableNum).Value.SetupInit) {
state.dataRuntimeLang->ErlVariable(ErlVariableNum).Value.initialized = false;
}
Comment on lines +314 to +316
Copy link
Copy Markdown
Collaborator Author

@joseph-robertson joseph-robertson Apr 28, 2026

Choose a reason for hiding this comment

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

Right before BeginNewEnvironment, "un-initialize" any Erl variables that had originally hit the EvaluateExpression: Variable = 'xyz' used in expression has not been initialized! error. If BeginNewEnvironment initializes them, then initialized is set back to true and we're good; if the variable doesn't get re-initialized, or there are other legitimate Erl variable initialization errors, the EvaluateExpression ... will throw (i.e., again, but with fatal this time).

}
}
// reinitialize state of actuators
Expand Down Expand Up @@ -1806,19 +1810,18 @@ ErlValueType EvaluateExpression(EnergyPlusData &state, int const ExpressionNum,
}

} else if (thisOperand.Type == Value::Variable) {
auto const &thisErlVar = state.dataRuntimeLang->ErlVariable(thisOperand.Variable);
auto &thisErlVar = state.dataRuntimeLang->ErlVariable(thisOperand.Variable);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Remove const since we may be updating Value.SetupInit.

if (thisErlVar.Value.initialized) { // check that value has been initialized
thisOperand = thisErlVar.Value;
} else { // value has never been set
// During setup (before simulation), we want to avoid initializing variables to zero without throwing an error.
// Throw the error, and write it to edd file, if variable is uninitialized and is *not* a global or internal variable.
// The assumption is that if we made it here for a global variable, it is initialized in another program.
// E.g., if it's initialized in a program with BeginNewEnvironment calling point, setup won't set it but simulation will.
if ((!state.dataGlobal->DoingSizing && !state.dataGlobal->KickOffSimulation && !state.dataEMSMgr->FinishProcessingUserInput) ||
(!(thisErlVar.SetByGlobalVariable || thisErlVar.SetByInternalVariable))) {

ReturnValue.Type = Value::Error;
ReturnValue.Error = "EvaluateExpression: Variable = '" + thisErlVar.Name + "' used in expression has not been initialized!";
ReturnValue.Type = Value::Error;
ReturnValue.Error =
EnergyPlus::format("EvaluateExpression: Variable = '{}' used in expression has not been initialized!", thisErlVar.Name);
// Use SetupInit in BeginEnvrnInitializeRuntimeLanguage for "un-initializing" Erl variables that may have been
// initialized to zero during setup. This can happen since SetupSimulation does not call BeginNewEnvironment.
thisErlVar.Value.SetupInit = false;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Revert the change from #11409, and instead just add this single line.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this need to be guarded with

if (state.dataGlobal->SetupFlag)

?

if (!state.dataGlobal->DoingSizing && !state.dataGlobal->KickOffSimulation && !state.dataEMSMgr->FinishProcessingUserInput) {

// check if this is an arg in CurveValue,
if (thisErlExpression.Operator !=
Expand Down
37 changes: 0 additions & 37 deletions testfiles/HospitalBaselineReheatReportEMS.idf
Original file line number Diff line number Diff line change
Expand Up @@ -77655,43 +77655,6 @@
Flr_1_Stor_DT2, !- <none>
Flr_1_Waiting_DT2; !- <none>

EnergyManagementSystem:GlobalVariable,
A, !- Erl Variable 1 Name
B, !- Erl Variable 2 Name
C, !- Erl Variable 3 Name
D, !- <none>
E, !- <none>
F, !- <none>
G, !- <none>
H, !- <none>
I, !- <none>
J, !- <none>
K, !- <none>
L, !- <none>
M, !- <none>
N, !- <none>
O, !- <none>
P, !- <none>
Q, !- <none>
R, !- <none>
S, !- <none>
T, !- <none>
U, !- <none>
V, !- <none>
W, !- <none>
X, !- <none>
Y, !- <none>
Z, !- <none>
AA, !- <none>
BB, !- <none>
CC, !- <none>
DD, !- <none>
EE, !- <none>
FF, !- <none>
GG, !- <none>
HH, !- <none>
II; !- <none>
Comment on lines -77658 to -77693
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This reverts the IDF additions from #11409.


!- =========== ALL OBJECTS IN CLASS: ENERGYMANAGEMENTSYSTEM:OUTPUTVARIABLE ===========

EnergyManagementSystem:OutputVariable,
Expand Down
15 changes: 11 additions & 4 deletions testfiles/RetailPackagedTESCoil.idf
Original file line number Diff line number Diff line change
Expand Up @@ -7948,6 +7948,10 @@
SET SumReliefMCT = SumReliefMCT + (h_Relief_3 * mdotRelief_3 ), !- <none>
SET SumReliefMCT = SumReliefMCT + (h_Relief_4 * mdotRelief_4 ); !- <none>

EnergyManagementSystem:Program,
InitializeRoofTemperature, !- Name
Set Troof = 0.0; !- Program Line 1

EnergyManagementSystem:Program,
InitializeParameters, !- Name
Set CV_Height = 1.0, !- Program Line 1
Expand Down Expand Up @@ -8066,10 +8070,8 @@

EnergyManagementSystem:GlobalVariable,
Troof, !- Erl Variable 1 Name
DeltaT, !- Erl Variable 2 Name
ratioT, !- Erl Variable 3 Name
Comment on lines -8069 to -8070
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This reverts the IDF additions from #11409.

CV_Height, !- <none>
CV_crossSectArea, !- <none>
CV_Height, !- Erl Variable 2 Name
CV_crossSectArea, !- Erl Variable 3 Name
C_v, !- <none>
rhoAir, !- <none>
CpAir, !- <none>
Expand Down Expand Up @@ -8100,6 +8102,11 @@
Set NatBouyMC = rhoAir * C_d * A_roof * temp2 * CpAir, !- <none>
Set NatBouyMCT = NatBouyMC * Ta; !- <none>

EnergyManagementSystem:ProgramCallingManager,
InitializeRoofTemperatureOnBeginNewEnvironment, !- Name
BeginNewEnvironment, !- EnergyPlus Model Calling Point
InitializeRoofTemperature; !- Program Name 1

EnergyManagementSystem:ProgramCallingManager,
Model Flat Roof Microclimate, !- Name
BeginTimestepBeforePredictor, !- EnergyPlus Model Calling Point
Expand Down
17 changes: 12 additions & 5 deletions testfiles/_ResidentialBase.idf
Original file line number Diff line number Diff line change
Expand Up @@ -7279,6 +7279,11 @@

!- =========== ALL OBJECTS IN CLASS: ENERGYMANAGEMENTSYSTEM:PROGRAMCALLINGMANAGER ===========

EnergyManagementSystem:ProgramCallingManager,
init calling manager, !- Name
BeginNewEnvironment, !- EnergyPlus Model Calling Point
init; !- Program Name 1

EnergyManagementSystem:ProgramCallingManager,
attic_unvented_1_duct_leakage_imbalance_infil_program calling manager, !- Name
BeginZoneTimestepAfterInitHeatBalance, !- EnergyPlus Model Calling Point
Expand Down Expand Up @@ -7336,6 +7341,13 @@

!- =========== ALL OBJECTS IN CLASS: ENERGYMANAGEMENTSYSTEM:PROGRAM ===========

EnergyManagementSystem:Program,
init, !- Name
Set CENTRAL_AC_AND_FURNACE_AIRLOOP_0_DUCTIMBALLKSUPFANEQUIVDZ = 0.0, !- Program Line 1
Set CENTRAL_AC_AND_FURNACE_AIRLOOP_0_DUCTIMBALLKEXHFANEQUIVDZ = 0.0, !- Program Line 2
Set CENTRAL_AC_AND_FURNACE_AIRLOOP_0_DUCTIMBALLKSUPFANEQUIVCOND = 0.0, !- <none>
Set CENTRAL_AC_AND_FURNACE_AIRLOOP_0_DUCTIMBALLKEXHFANEQUIVCOND = 0.0; !- <none>

EnergyManagementSystem:Program,
attic_unvented_1_duct_leakage_imbalance_infil_program, !- Name
Set Qducts = 0, !- Program Line 1
Expand Down Expand Up @@ -7785,11 +7797,6 @@
EnergyManagementSystem:GlobalVariable,
natural_vent_program_Qwhf; !- Erl Variable 1 Name

EnergyManagementSystem:GlobalVariable,
Qducts, !- Erl Variable 1 Name
Qsupply, !- Erl Variable 2 Name
Qexhaust; !- Erl Variable 3 Name
Comment on lines -7788 to -7791
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This reverts the IDF additions from #11409.


!- =========== ALL OBJECTS IN CLASS: ENERGYMANAGEMENTSYSTEM:OUTPUTVARIABLE ===========

EnergyManagementSystem:OutputVariable,
Expand Down
Loading