Skip to content

Commit 8623d71

Browse files
Add failing EMS unit test to demonstrate that variable initialized after reference does not throw error.
1 parent bc3524d commit 8623d71

File tree

1 file changed

+120
-1
lines changed

1 file changed

+120
-1
lines changed

tst/EnergyPlus/unit/EMSManager.unit.cc

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
// EnergyPlus Headers
5454
#include "Fixtures/EnergyPlusFixture.hh"
55+
#include <EnergyPlus/ConfiguredFunctions.hh>
5556
#include <EnergyPlus/Construction.hh>
5657
#include <EnergyPlus/CurveManager.hh>
5758
#include <EnergyPlus/Data/EnergyPlusData.hh>
@@ -936,7 +937,7 @@ TEST_F(EnergyPlusFixture, TestUnInitializedEMSVariable2)
936937
state->dataEMSMgr->FinishProcessingUserInput = true;
937938
bool anyRan;
938939
EMSManager::ManageEMS(*state, EMSManager::EMSCallFrom::SetupSimulation, anyRan, ObjexxFCL::Optional_int_const());
939-
// Expect the variable to not yet be initialized, call EvaluateExpresssion and check argument
940+
// Expect the variable to not yet be initialized, call EvaluateExpression and check argument
940941

941942
ErlValueType ReturnValue;
942943
bool seriousErrorFound = false;
@@ -958,6 +959,124 @@ TEST_F(EnergyPlusFixture, TestUnInitializedEMSVariable2)
958959
EXPECT_FALSE(seriousErrorFound);
959960
}
960961

962+
TEST_F(EnergyPlusFixture, TestUnInitializedEMSVariable3)
963+
{
964+
// this tests the variable is initialized before it is referenced, for issue #11360
965+
std::string const idf_objects = delimited_string({
966+
"Version," + DataStringGlobals::MatchVersion + ";",
967+
968+
"RunPeriod,",
969+
" Run Period 1, !- Name",
970+
" 1, !- Begin Month",
971+
" 1, !- Begin Day of Month",
972+
" 2007, !- Begin Year",
973+
" 1, !- End Month",
974+
" 1, !- End Day of Month",
975+
" 2007, !- End Year",
976+
" Monday, !- Day of Week for Start Day",
977+
" No, !- Use Weather File Holidays and Special Days",
978+
" No, !- Use Weather File Daylight Saving Period",
979+
" No, !- Apply Weekend Holiday Rule",
980+
" Yes, !- Use Weather File Rain Indicators",
981+
" Yes; !- Use Weather File Snow Indicators",
982+
983+
"SimulationControl,",
984+
" No, !- Do Zone Sizing Calculation",
985+
" No, !- Do System Sizing Calculation",
986+
" No, !- Do Plant Sizing Calculation",
987+
" No, !- Run Simulation for Sizing Periods",
988+
" Yes, !- Run Simulation for Weather File Run Periods",
989+
" , !- Do HVAC Sizing Simulation for Sizing Periods",
990+
" ; !- Maximum Number of HVAC Sizing Simulation Passes",
991+
992+
"Site:Location,",
993+
" Denver Stapleton Intl Arpt CO USA WMO=724690, !- Name",
994+
" 39.77, !- Latitude {deg}",
995+
" -104.87, !- Longitude {deg}",
996+
" -7.00, !- Time Zone {hr}",
997+
" 1611.00; !- Elevation {m}",
998+
999+
"Material,",
1000+
" Concrete Block, !- Name",
1001+
" MediumRough, !- Roughness",
1002+
" 0.1014984, !- Thickness {m}",
1003+
" 0.3805070, !- Conductivity {W/m-K}",
1004+
" 608.7016, !- Density {kg/m3}",
1005+
" 836.8000; !- Specific Heat {J/kg-K}",
1006+
1007+
"Construction,",
1008+
" ConcConstruction, !- Name",
1009+
" Concrete Block; !- Outside Layer",
1010+
1011+
"BuildingSurface:Detailed,"
1012+
" Wall, !- Name",
1013+
" Wall, !- Surface Type",
1014+
" ConcConstruction, !- Construction Name",
1015+
" Zone, !- Zone Name",
1016+
" , !- Space Name",
1017+
" Outdoors, !- Outside Boundary Condition",
1018+
" , !- Outside Boundary Condition Object",
1019+
" SunExposed, !- Sun Exposure",
1020+
" WindExposed, !- Wind Exposure",
1021+
" 0.5000000, !- View Factor to Ground",
1022+
" 4, !- Number of Vertices",
1023+
" 0.000000,0.000000,10.00000, !- X,Y,Z ==> Vertex 1 {m}",
1024+
" 0.000000,0.000000,0, !- X,Y,Z ==> Vertex 2 {m}",
1025+
" 10.00000,0.000000,0, !- X,Y,Z ==> Vertex 3 {m}",
1026+
" 10.00000,0.000000,10.00000; !- X,Y,Z ==> Vertex 4 {m}",
1027+
1028+
"Zone,"
1029+
" Zone, !- Name",
1030+
" 0, !- Direction of Relative North {deg}",
1031+
" 6.000000, !- X Origin {m}",
1032+
" 6.000000, !- Y Origin {m}",
1033+
" 0, !- Z Origin {m}",
1034+
" 1, !- Type",
1035+
" 1, !- Multiplier",
1036+
" autocalculate, !- Ceiling Height {m}",
1037+
" autocalculate; !- Volume {m3}",
1038+
1039+
"EnergyManagementSystem:Actuator,",
1040+
" battery_discharge_power_act, !- Name",
1041+
" Wall, !- Actuated Component Unique Name",
1042+
" Surface, !- Actuated Component Type",
1043+
" View Factor To Ground; !- Actuated Component Control Type",
1044+
1045+
"EnergyManagementSystem:Program,",
1046+
" ev_discharge_program, !- Name",
1047+
" Set power_mult = site_temp_adj, !- Program Line 1",
1048+
" Set site_temp_adj = 0.1, !- Program Line 2",
1049+
" Set battery_discharge_power_act = power_mult; !- Program Line 3",
1050+
1051+
"EnergyManagementSystem:ProgramCallingManager,",
1052+
" ev_discharge_pcm, !- Name",
1053+
" BeginTimestepBeforePredictor, !- EnergyPlus Model Calling Point",
1054+
" ev_discharge_program; !- Program Name 1",
1055+
});
1056+
1057+
ASSERT_TRUE(process_idf(idf_objects));
1058+
state->init_state(*state);
1059+
1060+
state->dataWeather->WeatherFileExists = true;
1061+
state->files.inputWeatherFilePath.filePath = configured_source_directory() / "weather/USA_CO_Golden-NREL.724666_TMY3.epw";
1062+
1063+
SimulationManager::ManageSimulation(*state);
1064+
1065+
int wallSurfNum = Util::FindItemInList("WALL", state->dataSurface->Surface);
1066+
bool anyRan;
1067+
EMSManager::ManageEMS(*state, EMSManager::EMSCallFrom::BeginTimestepBeforePredictor, anyRan, ObjexxFCL::Optional_int_const());
1068+
// EXPECT_EQ(state->dataSurface->Surface(wallSurfNum).ViewFactorGround, 0.1);
1069+
1070+
// Expect the variable to not yet be initialized, call EvaluateExpression and check argument
1071+
ErlValueType ReturnValue;
1072+
bool seriousErrorFound = false;
1073+
ReturnValue = RuntimeLanguageProcessor::EvaluateExpression(
1074+
*state,
1075+
state->dataRuntimeLang->ErlStack(Util::FindItemInList("EV_DISCHARGE_PROGRAM", state->dataRuntimeLang->ErlStack)).Instruction(1).Argument2,
1076+
seriousErrorFound);
1077+
EXPECT_TRUE(seriousErrorFound);
1078+
}
1079+
9611080
TEST_F(EnergyPlusFixture, EMSManager_CheckIfAnyEMS_OutEMS)
9621081
{
9631082
std::string const idf_objects = delimited_string({

0 commit comments

Comments
 (0)