Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Unable to Retrieve Updated Variable Values/Files Using EnergyPlus API #10475

Closed
IrfanULLAH97 opened this issue Apr 22, 2024 · 1 comment
Closed

Comments

@IrfanULLAH97
Copy link

Description:

I've implemented a custom logic in Python using the EnergyPlus API to generate simulation results. However, I'm facing an issue where the updated values of variables are not reflected in the output files.

Problem:

During the runtime of the simulation, I have custom logic in place to update the value of the actuator on each timestamp. 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 attempted to generate a CSV file of output using ReadVarsESO.exe, but the changes are not captured there either.

Efforts:

I have 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'm relatively new to working with EnergyPlus and the EnergyPlus API. 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.

@jmarrec
Copy link
Contributor

jmarrec commented May 27, 2024

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/docs/23-2/ems-application-guide/index.html

I'd start with AfterPredictorAfterHVACManagers or something like that.

As a side note, I see you've asked this question on unmethours.com at https://unmethours.com/question/98821/updated-variable-values-not-reflecting-in-energyplus-output-files/ , and that's sufficient for this type of questions. Github issues are meant to report issues or file enhancement requests.

@jmarrec jmarrec closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants