Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Translate EMS Example Files to PythonPlugin #7915

Merged
merged 64 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
d2af34f
begin transitioning EMSPlantLoopOverrideControl to python
mitchute Apr 8, 2020
c0a6221
working PlantLoopOverrideControl
mitchute Apr 8, 2020
d662f05
Merge remote-tracking branch 'origin/APIFollowUp2' into pyems_examples
mitchute Apr 8, 2020
59c6a70
translating EMS to Python for UserDefinedWindACAuto
mitchute Apr 8, 2020
0c4da0d
converting EMS to Py UserDefinedWindACAuto
mitchute Apr 8, 2020
c92288f
translating UserDefindedWindACAuto
mitchute Apr 9, 2020
1256170
working on UserDefinedWindACAuto
mitchute Apr 10, 2020
8b8fba6
convert EMSPluginAirflowNetworkOpeningControlByHumidity to python
mitchute Apr 13, 2020
46ac09c
adding PythonPluginConstantVolumePurchasedAir files
mitchute Apr 13, 2020
c9aabad
revert bad stash-pop
mitchute Apr 13, 2020
a6c75db
fixup some logic. working on ConstantVolumePurchasedAir conversion
mitchute Apr 14, 2020
3c3d6fd
add average building temperature to PythonPluginCustomSchedule
mitchute Apr 14, 2020
37f887e
stub out Python CurveOverride_PTHP
mitchute Apr 14, 2020
d49c125
stub files for PythonPluginDemandManager_LargeOffice
mitchute Apr 15, 2020
c4607aa
add PlantOperation_largeOff files
mitchute Apr 16, 2020
161166d
Merge branch 'APIFollowUp2' into pyems_examples
mitchute Apr 21, 2020
88ad6cc
Merge branch 'APIFollowUp2' into pyems_examples
mitchute Apr 22, 2020
1f1700e
finish converting CurveOverride_PTHP files to Python
mitchute Apr 23, 2020
d5110a6
Merge branch 'APIFollowUp2' into pyems_examples
mitchute Apr 23, 2020
adf90b6
wrap up ConstantVolumePurchAir conversion
mitchute Apr 23, 2020
7a9a236
delete old EMS from CurveOverride_PTHP
mitchute Apr 23, 2020
1c8f5fd
misc. file cleanups
mitchute Apr 23, 2020
f001048
attempt to resolve diff in UserDefined5ZoneAirCooled, update CMakeLists
mitchute Apr 24, 2020
27ec6dc
minor fixups on UserDefined5ZoneAirCooled
mitchute Apr 24, 2020
0e75cfa
finish EMS-to-Py for UserDefinedWindACAuto, fix minor string format f…
mitchute Apr 24, 2020
f5eb11a
Convert ThermochromicWindow files to Python
dareumnam Apr 24, 2020
cf78029
Merge branch 'pyems_examples' of https://github.com/NREL/EnergyPlus i…
dareumnam Apr 28, 2020
62faba6
Added to CMakeList: ThermochromicWindow & PlantOperation_largeOff
dareumnam Apr 29, 2020
db29f47
Merge remote-tracking branch 'origin/develop' into pyems_examples
Myoldmopar Apr 29, 2020
81f6856
testing LrgOff_GridStorageSmoothing
mitchute Apr 29, 2020
21b308a
Merge branch 'pyems_examples' of github.com:NREL/EnergyPlus into pyem…
mitchute Apr 29, 2020
c4db1a0
Merge remote-tracking branch 'origin/APIFollowUp2' into pyems_examples
Myoldmopar Apr 29, 2020
6001fc4
Check handle values instead of fullyReady flag for early actuation
Myoldmopar Apr 29, 2020
884e02f
Merge branch 'pyems_examples' of github.com:NREL/EnergyPlus into pyem…
Myoldmopar Apr 29, 2020
30b9455
Convert PlantOperation_largeOff to Python partial
dareumnam Apr 29, 2020
4ee1677
Convert PlantOperation_largeOff to Python partial 2
dareumnam Apr 29, 2020
1f493b4
Convert PlantOperation_largeOff to Python partial 3
dareumnam Apr 29, 2020
9135109
Merge remote-tracking branch 'origin/develop' into pyems_examples
Myoldmopar Apr 30, 2020
e8ef4dd
Merge remote-tracking branch 'origin/develop' into pyems_examples
Myoldmopar Apr 30, 2020
219ae38
update Python AFNNetworkOpeningControlByHumidity file
mitchute Apr 30, 2020
939f54c
update handles in UserDefinedWindACAuto
mitchute Apr 30, 2020
af3cfe3
revising handles in UserDefined5ZoneAirCooled
mitchute Apr 30, 2020
9a8e6ec
revising handles in LrgOff_GridStorageSmoothing
mitchute Apr 30, 2020
5dcdc17
add stubs for ReplaceTraditionalManagers_LargeOffice
mitchute Apr 30, 2020
86cf437
Convert PlantOperation_largeOff to Python
dareumnam Apr 30, 2020
526c44c
Resolve conflicts in CMakeLists
dareumnam Apr 30, 2020
ec07d35
Added to CMakeLists: PlantOperation_largeOff and ThermochromicWindow
dareumnam Apr 30, 2020
85641eb
Finish converting PlantOperation_largeOff to Python
dareumnam May 1, 2020
744f130
Better respond whether any ems ran or not
Myoldmopar May 4, 2020
74580c6
Merge remote-tracking branch 'origin/develop' into pyems_examples
Myoldmopar May 4, 2020
0fb250d
Fix grid smoothing, add begin environ support for plugin vars and trends
Myoldmopar May 4, 2020
f1a3327
Update variable used for trending
Myoldmopar May 4, 2020
e3df126
translate EMSReplaceTraditionalManagers_LargeOffice to PythonPlugins
mitchute May 4, 2020
f6de6b5
Split user defined class into two, fix index problem
Myoldmopar May 5, 2020
9d0ea62
Merge branch 'pyems_examples' of github.com:NREL/EnergyPlus into pyem…
Myoldmopar May 5, 2020
eac1fb1
Uncommented needed actuators in code to bypass error checking, fix mi…
Myoldmopar May 5, 2020
632287a
added to CMakeList: DemandManager_LargeOffice.idf
dareumnam May 5, 2020
966c1c1
Merge branch 'pyems_examples' of https://github.com/NREL/EnergyPlus i…
dareumnam May 5, 2020
cf33794
DemandManager_LargeOffice partial
dareumnam May 5, 2020
dc28dd4
DemandManager_LargeOffice partial 2
dareumnam May 5, 2020
9f2b0da
Revert back the demand manager file temporarily
Myoldmopar May 6, 2020
f9bdd72
Wrap up demand manager large office
Myoldmopar May 6, 2020
2a2ff7c
Merge remote-tracking branch 'origin/develop' into pyems_examples
Myoldmopar May 6, 2020
77eee74
Cleanups only, ready to go
Myoldmopar May 7, 2020
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
5 changes: 4 additions & 1 deletion src/EnergyPlus/EMSManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ namespace EMSManager {
anyProgramRan = false;
if (!AnyEnergyManagementSystemInModel) return; // quick return if nothing to do

if (iCalledFrom == DataGlobals::emsCallFromBeginNewEvironment) BeginEnvrnInitializeRuntimeLanguage();
if (iCalledFrom == DataGlobals::emsCallFromBeginNewEvironment) {
BeginEnvrnInitializeRuntimeLanguage();
PluginManagement::onBeginEnvironment();
}
Copy link
Member

Choose a reason for hiding this comment

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

Added a new begin environment calling point in the plugins to clear trends and reset stuff. This is a big improvement.


InitEMS(iCalledFrom);

Expand Down
24 changes: 19 additions & 5 deletions src/EnergyPlus/PluginManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,17 @@ namespace PluginManagement {
callbacks[iCalledFrom].push_back(f);
}

void onBeginEnvironment() {
// reset vars and trends -- sensors and actuators are reset by EMS
for (auto & v : globalVariableValues) {
v = 0;
}
// reinitialize trend variables so old data are purged
for (auto & tr : trends) {
tr.reset();
}
}

int PluginManager::numActiveCallbacks()
{
return (int)callbacks.size();
Expand All @@ -422,8 +433,8 @@ namespace PluginManagement {
#if LINK_WITH_PYTHON == 1
for (auto &plugin : plugins) {
if (plugin.runDuringWarmup || !DataGlobals::WarmupFlag) {
plugin.run(iCalledFrom);
anyRan = true;
bool const didOneRun = plugin.run(iCalledFrom);
if (didOneRun) anyRan = true;
Copy link
Member

Choose a reason for hiding this comment

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

Properly return whether a plugin actually ran, not just if we tried to run plugins. This is another big improvement.

}
}
#endif
Expand Down Expand Up @@ -1191,8 +1202,9 @@ namespace PluginManagement {
}

#if LINK_WITH_PYTHON == 1
void PluginInstance::run(int iCalledFrom) const
bool PluginInstance::run(int iCalledFrom) const
{
// returns true if a plugin actually ran
const char *functionName = nullptr;
if (iCalledFrom == DataGlobals::emsCallFromBeginNewEvironment) {
if (this->bHasBeginNewEnvironment) {
Expand Down Expand Up @@ -1266,7 +1278,7 @@ namespace PluginManagement {

// leave if we didn't find a match
if (!functionName) {
return;
return false;
}

// then call the main function
Expand Down Expand Up @@ -1297,10 +1309,12 @@ namespace PluginManagement {
if (EnergyPlus::PluginManagement::apiErrorFlag) {
EnergyPlus::ShowFatalError("API problems encountered while running plugin cause program termination.");
}
return true;
}
#else
void PluginInstance::run(int EP_UNUSED(iCalledFrom)) const
bool PluginInstance::run(int EP_UNUSED(iCalledFrom)) const
{
return false;
}
#endif

Expand Down
9 changes: 8 additions & 1 deletion src/EnergyPlus/PluginManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace PluginManagement {

void registerNewCallback(int iCalledFrom, const std::function<void ()>& f);
void runAnyRegisteredCallbacks(int iCalledFrom, bool &anyRan);
void onBeginEnvironment();
std::string pythonStringForUsage();

void clear_state();
Expand Down Expand Up @@ -96,7 +97,7 @@ namespace PluginManagement {

// methods
static void reportPythonError();
void run(int iCallingPoint) const; // calls main() on this plugin instance
bool run(int iCallingPoint) const; // calls main() on this plugin instance

// plugin calling point hooks
const char * sHookBeginNewEnvironment = "on_begin_new_environment";
Expand Down Expand Up @@ -185,6 +186,12 @@ namespace PluginManagement {
this->times.push_back(-loop * DataGlobals::TimeStepZone);
}
}
void reset() {
this->values.clear();
for (int i = 1; i <= this->numValues; i++) {
this->values.push_back(0);
}
}
};

extern std::unique_ptr<PluginManager> pluginManager;
Expand Down
4 changes: 2 additions & 2 deletions src/EnergyPlus/RuntimeLanguageProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,7 @@ namespace RuntimeLanguageProcessor {
}
} else if (UnitsB == "" && UnitsA != "") {
UnitsB = UnitsA;
ShowWarningError(RoutineName + cCurrentModuleObject + "=\"" + cAlphaArgs(1) + " using deprecated units designation.");
ShowWarningError(RoutineName + cCurrentModuleObject + "=\"" + cAlphaArgs(1) + "\" using deprecated units designation.");
ShowContinueError("...Units entered in " + cAlphaFieldNames(1) + " (deprecated use)=\"" + UnitsA + "\"");
}
}
Expand Down Expand Up @@ -3228,7 +3228,7 @@ namespace RuntimeLanguageProcessor {
}
} else if (UnitsB == "" && UnitsA != "") {
UnitsB = UnitsA;
ShowWarningError(RoutineName + cCurrentModuleObject + "=\"" + cAlphaArgs(1) + " using deprecated units designation.");
ShowWarningError(RoutineName + cCurrentModuleObject + "=\"" + cAlphaArgs(1) + "\" using deprecated units designation.");
ShowContinueError("...Units entered in " + cAlphaFieldNames(1) + " (deprecated use)=\"" + UnitsA + "\"");
}
}
Expand Down
15 changes: 12 additions & 3 deletions testfiles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,23 @@ ADD_SIMULATION_TEST(IDF_FILE PurchAirWithDaylightingAndShadeControl.idf EPW_FILE
ADD_SIMULATION_TEST(IDF_FILE PurchAirWithDaylightingAngleFac.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PurchAirWithDoubleFacadeDaylighting.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
if (LINK_WITH_PYTHON)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginAirflowNetworkOpeningControlByHumidity.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginConstantVolumePurchasedAir.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginCurveOverride_PackagedTerminalHeatPump.idf EPW_FILE USA_FL_Miami.Intl.AP.722020_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginCustomOutputVariable.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginCustomTrendVariable.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginCustomSchedule.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginLrgOff_GridStorageSmoothing.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginWindowShadeControl.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginDemandManager_LargeOffice.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginDiscreteAirSystemSizes.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginPlantLoopOverrideControl.idf EPW_FILE USA_FL_Orlando.Intl.AP.722050_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginPlantOperation_largeOff.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginReplaceTraditionalManagers_LargeOffice.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginTestMathAndKill.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw EXPECT_FATAL) # Expected to Fatal
ADD_SIMULATION_TEST(IDF_FILE PythonPluginThermochromicWindow.idf EPW_FILE USA_NV_Las.Vegas-McCarran.Intl.AP.723860_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginUserDefined5ZoneAirCooled.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginUserDefinedWindACAuto.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginWindowShadeControl.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginLrgOff_GridStorageSmoothing.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE PythonPluginCustomTrendVariable.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
Copy link
Member

Choose a reason for hiding this comment

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

Added gobs of new python plugin test cases that match the EMS cases. We are showing we can match the results of EMS which is a huge step.

endif()
ADD_SIMULATION_TEST(IDF_FILE QTFtest.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE RadHiTempElecTermReheat.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
Expand Down
3 changes: 3 additions & 0 deletions testfiles/EMSCurveOverride_PackagedTerminalHeatPump.idf
Original file line number Diff line number Diff line change
Expand Up @@ -2115,3 +2115,6 @@
HTML; !- Column Separator

!- =========== ALL OBJECTS IN CLASS: OUTPUT:VARIABLE ===========
Output:Variable,Zone1PTHPDXCoolCoil,Cooling Coil Total Cooling Rate,timestep;
Output:Variable,Zone2PTHPDXCoolCoil,Cooling Coil Total Cooling Rate,timestep;
Output:Variable,Zone3PTHPDXCoolCoil,Cooling Coil Total Cooling Rate,timestep;
Copy link
Member

Choose a reason for hiding this comment

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

Just added a few extra outputs to a couple EMS files for debugging, they aren't hurting anything but I may take them out if I need to do more commits.

2 changes: 2 additions & 0 deletions testfiles/EMSUserDefinedWindACAuto.idf
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,8 @@

Output:Variable,*,Zone 1 WinAC Electricity Power,hourly;

Output:Variable,*,Zone 1 WinAC Electricity Consumption,hourly;

Output:Variable,Zone1WindACAirOutletNode,System Node Mass Flow Rate,hourly;

Output:Variable,Zone2WindACAirOutletNode,System Node Mass Flow Rate,hourly;
Expand Down
Loading