content
官方文档
官方链接
链接: 快速上手手册.
链接: 输入输出参考模板.
链接: 官方樣例代碼.
官方代碼試跑
TestRuntime
首先跑的是這個 TestRuntime.py
class runtime.Runtime(api: <ctypes.LibraryLoader object at 0x7fdff3d3bb70>)[source]
Bases: object
This API class enables a client to hook into EnergyPlus at runtime and sense/actuate data in a running simulation.
The pattern is quite simple: create a callback function in Python, and register it with one of the registration methods on this class to allow the callback to be called at a specific point in the simulation.
Inside the callback function, the client can get sensor values and set actuator values using the DataTransfer API methods, and also look up values and perform calculations using EnergyPlus internal methods via the Functional API methods.
这个API类允许客户端在运行时挂钩到EnergyPlus,并在运行模拟中感知/启动数据。
这个模式非常简单:在Python中创建一个回调函数,并将其注册到该类的一个注册方法中,以允许在模拟中的特定点调用回调函数。
在回调函数中,客户端可以使用DataTransfer API方法获取传感器值和设置执行器值,也可以通过Functional API方法使用EnergyPlus内部方法查找值并执行计算。
TestRuntime.py 代碼如下
- 导入energyplus库
import sys
sys.path.insert(0, 'C:\EnergyPlusV9-5-0') # 这里注意路径要写你自己电脑上energyplus的路径
from pyenergyplus.api import EnergyPlusAPI
- 定义三个回调函数(callback function)
def environment_handler(_state) -> None: # 环境句柄
print("OH HAI ENVIRONMENT")
sys.stdout.flush()
def progress_handler(progress: int) -> None: # 进程句柄
if 49 < progress < 51:
print("HALFWAY THERE!!")
sys.stdout.flush()
def error_handler(severity: int, message: bytes) -> None: # 错误句柄
if b'Warning' in message:
print("GOT A WARNING UH OH!")
sys.stdout.flush()
- 初始化
api = EnergyPlusAPI() # 实例化一个API类
state = api.state_manager.new_state() # 从状态管理 获取一个新的状态
api.runtime.callback_begin_new_environment(state, environment_handler) # 设置环境句柄
api.runtime.callback_progress(state, progress_handler)
api.functional.callback_error(state, error_handler)
filename_to_run = 'C:\EnergyPlusV9-5-0\ExampleFiles\ChillerPartLoadCurve_RefBldgLargeOfficeNew2004_Chicago.idf'
argvList = [
'-w', r'C:\EnergyPlusV9-5-0\WeatherData\USA_CO_Golden-NREL.724666_TMY3.epw',
'-d', 'out',
filename_to_run ]
api.runtime.run_energyplus(state, argvList)
运行即可看到结果了