1

Text based control algorithim for modelica

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;
equation
  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
  else
    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.

grid_designer's avatar
35
grid_designer
asked 2023-05-02 17:49:27 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

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.

Michael Wetter's avatar
1.7k
Michael Wetter
answered 2023-05-03 16:35:58 -0500
edit flag offensive 0 remove flag delete link

Comments

@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: https://simulationresearch.lbl.gov/mo...

Michael Wetter's avatar Michael Wetter (2023-05-09 08:55:48 -0500) edit
add a comment see more comments