Skip to content

Instantly share code, notes, and snippets.

@TStesco
Created May 17, 2018 20:41
Show Gist options
  • Save TStesco/d02d19e7e382ab8c37d51c96d7891f6d to your computer and use it in GitHub Desktop.
Save TStesco/d02d19e7e382ab8c37d51c96d7891f6d to your computer and use it in GitHub Desktop.
Example usage of energyplus.fmu with JModelica and PyFMI
import os
from pymodelica import compile_fmu
from pyfmi import load_fmu
import matplotlib.pyplot as plt
# add energyplus cli script to $PATH, not needed if already in $PATH
os.environ['PATH'] = os.environ['PATH'] +":/opt/EnergyPlus/EnergyPlus-8-9-0"
# load .fmu with pyfmi
fmu_path = '<path>/_fmu_export_variable.fmu'
model = load_fmu(fmu=fmu_path)
# change input variable (default in .idf is given to be 6)
model.set('yShadeFMU', 1)
# get options object
opts = model.simulate_options()
# set number of communication points dependent on final_time and .idf steps per hour
final_time = 60*60*72. # 72 hour simulation
idf_steps_per_hour = 6
ncp = final_time/(3600./idf_steps_per_hour)
opts['ncp'] = ncp
# run simulation and return results
res = model.simulate(start_time=0., final_time=final_time, options=opts)
print(res.keys()) # show result variables names
# plot results
fig, ax1 = plt.subplots()
ax1.plot(res['time'], res['TRoo'], 'b-')
ax1.set_xlabel('time (s)')
ax1.set_ylabel('Room Temperature', color='b')
ax1.tick_params('y', colors='b')
ax2 = ax1.twinx()
ax2.plot(res['time'], res['ISolExt'], 'r.')
ax2.set_ylabel('Solar Radiation', color='r')
ax2.tick_params('y', colors='r')
fig.tight_layout()
plt.show()
@lymereJ
Copy link

lymereJ commented Aug 29, 2019

@TStesco - When I plot a time series of yShadeFMU, it's always 0. I've tried running several days and also using the input parameter of simulate but yShadeFMU seem to always be 0. Have you noticed the same thing?

@stef-papathan
Copy link

Hi there. I am experimenting with FMU at the moment. I would really appreciate it if you could share the IDF file that goes along with this. It would help me understand how the IDF file should be structured in order to get this to work. Thanks!

@lymereJ
Copy link

lymereJ commented Jun 4, 2020

Seems like 0s are expected, see here. The IDF should be the ones that come as examples with EnergyPlusToFMU.

@JChung-rpi
Copy link

JChung-rpi commented May 14, 2024

Hi @stef-papathan and @lymereJ , I am wondering if you have solved this issue. I am struggling with the same issue. I am working with this EnergyPlusToFMU (v.3.1.0, latest version) example file: https://raw.githubusercontent.com/lbl-srg/EnergyPlusToFMU/master/Examples/Actuator/_fmu-export-actuator.idf
My version of EnergyPlus is v.9.4.0 which is the same as the version of the IDF file. Thank you.

Here is the result I got:
screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment