Skip to content

Commit

Permalink
add average building temperature to PythonPluginCustomSchedule
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchute committed Apr 14, 2020
1 parent a6c75db commit 3c3d6fd
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
24 changes: 24 additions & 0 deletions testfiles/PythonPluginCustomSchedule.idf
Original file line number Diff line number Diff line change
Expand Up @@ -6100,7 +6100,31 @@
PythonPluginCustomSchedule, !- Python Module Name
CoolingSetPoint; !- Plugin Class Name

PythonPlugin:Instance,
Average Building Temperature, !- Name
Yes, !- Run During Warmup Days
PythonPluginCustomSchedule, !- Python Module Name
AverageZoneTemps; !- Plugin Class Name

PythonPlugin:Variables,
MyGlobals,
AverageBuildingTemp;

PythonPlugin:OutputVariable,
Averaged Building Temperature, !- Name
AverageBuildingTemp, !- PythonPlugin:Variable Name
Averaged, !- Type of Data in Variable
ZoneTimestep, !- Update Frequency
C; !- Units

Output:Variable,
Averaged Building Temperature,
PythonPlugin:OutputVariable,
Timestep;

Output:Variable,HTGSETP_SCH,Schedule Value,timestep;

Output:Variable,CLGSETP_SCH,Schedule Value,timestep;



65 changes: 64 additions & 1 deletion testfiles/PythonPluginCustomSchedule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from pyenergyplus.plugin import EnergyPlusPlugin


Expand Down Expand Up @@ -73,3 +72,67 @@ def on_begin_timestep_before_predictor(self) -> int:
elif hour > 22:
self.actuate(30)
return 0


class AverageZoneTemps(EnergyPlusPlugin):

def __init__(self):
super().__init__()
self.need_to_get_handles = True
self.T1_handle = None
self.T2_handle = None
self.T3_handle = None
self.T4_handle = None
self.T5_handle = None

self.Zn1vol = None
self.Zn2vol = None
self.Zn3vol = None
self.Zn4vol = None
self.Zn5vol = None

self.ave_bldg_temp_handle = None

def on_end_of_zone_timestep_before_zone_reporting(self) -> int:

# check if API ready
if self.api.exchange.api_data_fully_ready():
# get handles if needed
if self.need_to_get_handles:
self.T1_handle = self.api.exchange.get_variable_handle("Zone Mean Air Temperature", "Perimeter_ZN_1")
self.T2_handle = self.api.exchange.get_variable_handle("Zone Mean Air Temperature", "Perimeter_ZN_2")
self.T3_handle = self.api.exchange.get_variable_handle("Zone Mean Air Temperature", "Perimeter_ZN_3")
self.T4_handle = self.api.exchange.get_variable_handle("Zone Mean Air Temperature", "Perimeter_ZN_4")
self.T5_handle = self.api.exchange.get_variable_handle("Zone Mean Air Temperature", "Core_ZN")

Zn1vol_handle = self.api.exchange.get_internal_variable_handle("Zone Air Volume", "Perimeter_ZN_1")
Zn2vol_handle = self.api.exchange.get_internal_variable_handle("Zone Air Volume", "Perimeter_ZN_2")
Zn3vol_handle = self.api.exchange.get_internal_variable_handle("Zone Air Volume", "Perimeter_ZN_3")
Zn4vol_handle = self.api.exchange.get_internal_variable_handle("Zone Air Volume", "Perimeter_ZN_4")
Zn5vol_handle = self.api.exchange.get_internal_variable_handle("Zone Air Volume", "Core_ZN")

self.Zn1vol = self.api.exchange.get_internal_variable_value(Zn1vol_handle)
self.Zn2vol = self.api.exchange.get_internal_variable_value(Zn2vol_handle)
self.Zn3vol = self.api.exchange.get_internal_variable_value(Zn3vol_handle)
self.Zn4vol = self.api.exchange.get_internal_variable_value(Zn4vol_handle)
self.Zn5vol = self.api.exchange.get_internal_variable_value(Zn5vol_handle)

self.ave_bldg_temp_handle = self.api.exchange.get_global_handle("AverageBuildingTemp")

self.need_to_get_handles = False

# calculations
T1 = self.api.exchange.get_variable_value(self.T1_handle)
T2 = self.api.exchange.get_variable_value(self.T2_handle)
T3 = self.api.exchange.get_variable_value(self.T3_handle)
T4 = self.api.exchange.get_variable_value(self.T4_handle)
T5 = self.api.exchange.get_variable_value(self.T5_handle)

num = T1 * self.Zn1vol + T2 * self.Zn2vol + T3 * self.Zn3vol + T4 * self.Zn4vol + T5 * self.Zn5vol
den = self.Zn1vol + self.Zn2vol + self.Zn3vol + self.Zn4vol + self.Zn5vol

self.api.exchange.set_global_value(self.ave_bldg_temp_handle, num / den)

return 0
else:
return 0

7 comments on commit 3c3d6fd

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

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

pyems_examples (mitchute) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (2809 of 2810 tests passed, 9 test warnings)

Messages:\n

  • 7 tests had: ERR diffs.
  • 2 tests had: AUD diffs.
  • 1 test had: MDD diffs.
  • 1 test had: MTD diffs.
  • 2 tests had: RDD diffs.

Failures:\n

integration Test Summary

  • Passed: 698
  • Failed: 1

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

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

pyems_examples (mitchute) - x86_64-Linux-Ubuntu-18.04-cppcheck: OK (0 of 0 tests passed, 0 test warnings)

Build Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

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

pyems_examples (mitchute) - x86_64-Linux-Ubuntu-18.04-custom_check: Build Failed

Build Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

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

pyems_examples (mitchute) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: OK (1380 of 1380 tests passed, 0 test warnings)

Build Badge Test Badge Coverage 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.

pyems_examples (mitchute) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (698 of 699 tests passed, 0 test warnings)

Failures:\n

integration Test Summary

  • Passed: 698
  • Failed: 1

Build Badge Test Badge Coverage Badge

@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.

pyems_examples (mitchute) - x86_64-MacOS-10.13-clang: OK (2769 of 2770 tests passed, 9 test warnings)

Messages:\n

  • 7 tests had: ERR diffs.
  • 2 tests had: AUD diffs.
  • 1 test had: MDD diffs.
  • 1 test had: MTD diffs.
  • 2 tests had: RDD diffs.

Failures:\n

integration Test Summary

  • Passed: 695
  • Failed: 1

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.

pyems_examples (mitchute) - Win64-Windows-10-VisualStudio-16: OK (2746 of 2766 tests passed, 9 test warnings)

Messages:\n

  • 7 tests had: ERR diffs.
  • 2 tests had: AUD diffs.
  • 1 test had: MDD diffs.
  • 1 test had: MTD diffs.
  • 2 tests had: RDD diffs.

Failures:\n

API Test Summary

  • Passed: 3
  • notrun: 1

DataExchangeAPIUnitTestFixture Test Summary

  • Passed: 1
  • Failed: 16

EnergyPlusFixture Test Summary

  • Passed: 923
  • Failed: 2

integration Test Summary

  • Passed: 695
  • Failed: 1

Build Badge Test Badge

Please # to comment.