2

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

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
BaseboardHeater's avatar
87
BaseboardHeater
asked 2021-08-05 07:03:23 -0500
Aaron Boranian's avatar
14.1k
Aaron Boranian
updated 2021-08-05 08:23:40 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

2

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...)

Julien Marrec's avatar
29.7k
Julien Marrec
answered 2021-08-06 10:11:07 -0500
edit flag offensive 0 remove flag delete 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 (2021-09-01 07:13:35 -0500) edit

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 (2021-09-02 03:17:44 -0500) edit
add a comment see more comments