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

Text based control algorithim for modelica

asked 2023-05-02 17:49:27 -0500

grid_designer's avatar

Hello all, I am trying to model a microgrid simulation using the modelica buildings library. I am using OMEdit to model the system, but would prefer to write the code for the control algorithm for the bi-directional battery inverter in text format as I come from C/Python background and find it easier to follow compared to a visual system. I wrote this code:

model battery_control
  Modelica.Blocks.Interfaces.RealInput SOC;
  Modelica.Blocks.Interfaces.RealOutput inverterInput;
  Modelica.Blocks.Interfaces.RealInput meterInput;
  if (meterInput <= -20) and (SOC > 20) and (meterInput >= -100) then
    inverterInput = abs(inverterInput + 20);
  elseif (meterInput >= -100) and (SOC > 20) then
    inverterInput = 100;
  elseif (meterInput >= 5) and (SOC < 90) and (meterInput < 100 ) then
    inverterInput = -1 * (inverterInput - 5);
  elseif (SOC < 90) and (meterInput < 100 ) then
    inverterInput = -100
    inverterInput = 0;
  end if;
end battery_control;

However, OMEdit does not let me save this code. I am not sure what is wrong. Basically, I want to create a block that connects to the input and ouput, but it is text-based control. Also, is it possble to run python code in modelica, not the reverse(run modelica in python: PyFmi). Thank you for the help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-05-03 16:35:58 -0500

If you try to save this in OpenModelica's OMEdit, it gives the error message:

`[3] 14:31:35 Syntax Error which is because of the missing semi-colon on line 14.

Regarding your other question, you can call Python from blocks in the Modelica Buildings Library.

edit flag offensive delete link more


@Michael Wetter, how would I call Python from the blocks?

grid_designer's avatar grid_designer  ( 2023-05-08 10:31:20 -0500 )edit

Please read the documentation of the Python package:

Michael Wetter's avatar Michael Wetter  ( 2023-05-09 08:55:48 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops


Question Tools

1 follower


Asked: 2023-05-02 17:49:27 -0500

Seen: 60 times

Last updated: May 08 '23