First time here? Check out the Help page!

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

How can I simulate just one time-step (dt = 60s) with the E+-API?

asked 3 years ago

BaseboardHeater's avatar

updated 3 years ago

I still have some questions because of the EnergyPlus-API for Python :)

How I can simulate just one step with the api? Because there is just the function run_energyplus(state: ctypes.c_void_p, command_line_args: List[Union[str, bytes]]) and it simulates the whole time span.

In my function, I want to simulate one step, calculate one actuator value with an external function, use api.exchange.set_actuator_value() to set the actuator for the baseboard heater and simulate the next time step.

Previously we used the FMU-simulation in python and there we could define a do_step function.

Thank you very much :)

def do_step(self, setpoints):
    """
    Simulate one step
    :param setpoints: dict of setpoints
    :return: variables
    """
    # set set-points and do sim-step
    for key in setpoints.keys():
        self.model.set(key, setpoints[key])

    self.model.do_step(self.model._get_time(), self.config["dt_s"])
    # time.append(model._get_time())
    # get values for variables in varliable-list:
    var_dict = {var_name: self.model.get(var_name) for var_name in self.var_list}
    return var_dict
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 3 years ago

You need to use the callback functions https://nrel.github.io/EnergyPlus/api...

There are different calling point, for which you should read the EnergyManagementSystem's documentation to understand them: https://bigladdersoftware.com/epx/doc...

For eg callback_begin_system_timestep_before_predictor corresponds to BeginTimestepBeforePredictor.

I have one example at https://github.com/jmarrec/OpenStudio...

For your information, you may also use the Python:Pluginobject in which case you would keep running your simulation the same way you did before (via the command line interface (CLI, energyplus.exe) or EP-Launch). This would be exactly like using EnergyManagementSystem except the EnergyManagementSystem:Program is actually defined in an external .py file. Have a look at the Example Files that start with "PythonPlugin" (eg: https://github.com/NREL/EnergyPlus/bl...)

Preview: (hide)
link

Comments

In our case we want to simulate the whole town with electric grids, heat pumps, houses and eventually the heating network. The main aim is the development of a control algorithm to optimize the power flows. So every aspect of the simulation is written in python. Therefore, the Python:Plugin object cannot be used in our case, because we want to have the whole simulation structure in python, and they have to communicate in python for parallel computing. So your approach in your example is the right way to go, or do I misunderstand something? (I already read all docs on Plugin- and Library-Mode)

BaseboardHeater's avatar BaseboardHeater  ( 3 years ago )

That's likely correct, in that case you want to use the feature in API mode, not the Python:Plugin approach.

Julien Marrec's avatar Julien Marrec  ( 3 years ago )

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: 3 years ago

Seen: 309 times

Last updated: Aug 26 '21