Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
1

Updated Variable Values Not Reflecting in EnergyPlus Output Files

asked 2024-04-24 01:19:46 -0600

Irfan's avatar

updated 2024-04-24 09:50:58 -0600

Description:
I'm relatively new to working with EnergyPlus and the EnergyPlus API. I've implemented a custom logic in Python to update the value of actuators during the runtime of a simulation. However, despite observing these updates during runtime, the generated output files (e.g., <Prefix>out.csv, <Prefix>ssz.csv, <Prefix>szsz.csv) do not reflect these changes. I've also tried using ReadVarsESO.exe to generate a CSV file of output, but the changes are not captured there either.

Efforts Made:
I've thoroughly debugged the code and confirmed that during runtime, the values of the actuators are indeed being updated as expected. Here's a snippet of the output showing the actuator values being updated:

...

zone_air_temp : 17.19054414796448

actuator_value : 13.249069956310262

actuator_updated_value : 13.19054414796448

zone_air_temp : 17.13274368005318

actuator_value : 13.19054414796448

actuator_updated_value : 13.132743680053181

...

Code Snippet:

import sys
from pyenergyplus.api import EnergyPlusAPI

one_time = True
zone_air_temp = 0
fan_actuator = 0

def my_callback(state):
  global one_time, zone_air_temp, fan_actuator

  if one_time:
    if not api.exchange.api_data_fully_ready(state):
      return
    zone_air_temp = api.exchange.get_variable_handle(state, "Zone Air Temperature", "Thermal Zone 1")
    fan_actuator = api.exchange.get_actuator_handle(state, "Fan", "Fan Air Mass Flow Rate", "Standard Fan")
    one_time = False

  zone_air_temp_value = api.exchange.get_variable_value(state, zone_air_temp)
  print("zone_air_temp :  ", zone_air_temp_value)
  fan_actuator_value = api.exchange.get_actuator_value(state, fan_actuator)
  print("actuator_value : ",fan_actuator_value)

  # Custom logic is here:
  api.exchange.set_actuator_value(state, fan_actuator, zone_air_temp_value-4)

  fan_actuator_value = api.exchange.get_actuator_value(state,fan_actuator)
  print("actuator_updated_value : ",fan_actuator_value)

api = EnergyPlusAPI()
state = api.state_manager.new_state()

api.runtime.callback_end_zone_timestep_after_zone_reporting(state, my_callback)
api.exchange.request_variable(state, "Fan Air Mass Flow Rate", "Thermal Zone 1")

api.runtime.run_energyplus(state, sys.argv[1:])

Request for Assistance:
I would appreciate any insights or suggestions on why the updated variable values are not being reflected in the output files. Additionally, if there are any alternative methods to capture these changes effectively, I'm open to exploring those as well.

Thank you for your assistance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2024-05-27 03:24:49 -0600

This is just the wrong EMS calling point, You're using callback_end_zone_timestep_after_zone_reporting.

Please refer to the EMS application guide: https://bigladdersoftware.com/epx/doc...

I'd start with AfterPredictorAfterHVACManagers or something like that. Tweak the calling point until you see it working. Maybe you'll need to put it at InsideHVACSystemIterationLoop, but that's going to slow down the execution time.

edit flag offensive delete link more

Comments

@Julien Marrec Is it also possible to use the EndZoneStepBeforeZoneReporting callback to get the used acutator values? I see that the actuator values are not the ones from the schedule when using this callback. They are near, but not identical.

sz1980's avatar sz1980  ( 2024-08-20 14:24:35 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2024-04-24 01:19:46 -0600

Seen: 79 times

Last updated: May 27