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

grid_designer's profile - activity

2024-04-01 23:02:53 -0500 asked a question Where to get more information on openmodelica scripting

Where to get more information on openmodelica scripting Dear all, I am trying to automate my modelica building/openmode

2024-01-18 15:40:25 -0500 asked a question OMPython Problem

OMPython Problem Hello, I am new to OMPython, and not sure what I am doing wrong. I am trying to run my .mo using OMPyth

2023-08-04 22:55:26 -0500 asked a question segmenation fault when running cvxpy in modelica buildings python module

segmenation fault when running cvxpy in modelica buildings python module Hello all, I am not sure if this is a CVXPy,

2023-08-04 22:50:09 -0500 asked a question segmenation fault when running cvxpy in modelica buildings python module

segmenation fault when running cvxpy in modelica buildings python module Hello all, I am not sure if this is a CVXPy, m

2023-08-01 22:43:22 -0500 edited question Mismatch of equations and variables

Mismatch of equations and variables Hello all, I am getting an error of 297 equations and 300 variables. Previous all o

2023-08-01 22:36:38 -0500 asked a question Mismatch of equations and variables

Mismatch of equations and variables Hello all, I am getting an error of 297 equations and 300 variables. Previous all of

2023-05-27 16:55:53 -0500 commented answer How to use python libraries in the Buildings.Utilities.IO.Python_3_8 Real_Real module

It works now thank you. I was exporting the PYTHONPATH correctly, but my problem was that while I had libraries installe

2023-05-27 16:52:27 -0500 marked best answer How to use python libraries in the Buildings.Utilities.IO.Python_3_8 Real_Real module

Hello, I have successfully used my own python function for peak-shaving for my microgrid in openmodelica. I am trying to port a load forecasting machine learning algorithm to the modelica simulation, but the Real_Real module does not seem to run any python code that has an external library. How are external libraries such pandas, numpy, scikit-learn, etc exported to the PYTHONPATH, and read by the Real_Real module? I have a very simple example that I am trying to implement just to test using an external library, but I cannot get it to work. Thank you for the help.

Modelica and python code:

https://drive.google.com/drive/folder...

Modelica model:

model test_python_library
  Buildings.Utilities.IO.Python_3_8.Real_Real random_output(functionName = "random_output", moduleName = "random_output", nDblRea = 1, nDblWri = 1, samplePeriod = 1)  annotation(

 Placement(visible = true, transformation(origin = {-2, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Sources.Constant const(k = 1)  annotation(
    Placement(visible = true, transformation(origin = {-72, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(const.y, random_output.uR[1]) annotation(
    Line(points = {{-61, 4}, {-14, 4}}, color = {0, 0, 127}));

annotation(
    uses(Buildings(version = "9.1.0"), Modelica(version = "4.0.0")),
    experiment(StartTime = 0, StopTime = 100, Tolerance = 1e-6, Interval = 1),
    __OpenModelica_commandLineOptions = "--matchingAlgorithm=PFPlusExt --indexReductionMethod=dynamicStateSelection -d=initialization,NLSanalyticJacobian",
    __OpenModelica_simulationFlags(lv = "LOG_STATS", s = "dassl"));
end test_python_library;

Python code (Note if I comment out line 2 and 4, and uncomment line 3, the model runs perfectly, so I know the python library is causing the error):

def random_output(input):
    import numpy as np
    #return 5
    return np.random.randint(100)
2023-05-26 21:00:26 -0500 commented answer How to use python libraries in the Buildings.Utilities.IO.Python_3_8 Real_Real module

Does this only work for Dymola or has it only been tested on Dymola. I am using OpenModelica,

2023-05-25 22:22:56 -0500 edited question How to use python libraries in the Buildings.Utilities.IO.Python_3_8 Real_Real module

How to use python libraries in the Buildings.Utilities.IO.Python_3_8 Real_Real module Hello, I have successfully used my

2023-05-25 22:19:17 -0500 edited question How to use python libraries in the Buildings.Utilities.IO.Python_3_8 Real_Real module

How to use python libraries in the Buildings.Utilities.IO.Python_3_8 Real_Real module Hello, I have successfully used my

2023-05-25 22:16:41 -0500 asked a question How to use python libraries in the Buildings.Utilities.IO.Python_3_8 Real_Real module

How to use python libraries in the Buildings.Utilities.IO.Python_3_8 Real_Real module Hello, I am have successfully used

2023-05-16 21:21:40 -0500 asked a question Python Module does not work in OpenModelica

Python Module does not work in OpenModelica Hello everyone, I am trying to implement a peak-shaving algorithm for a micr

2023-05-08 12:11:10 -0500 received badge  Student (source)
2023-05-08 12:08:21 -0500 commented answer Text based control algorithim for modelica

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

2023-05-08 10:30:38 -0500 marked best answer 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.

2023-05-08 10:30:38 -0500 received badge  Scholar (source)
2023-05-08 10:30:36 -0500 received badge  Supporter (source)
2023-05-03 09:57:11 -0500 asked a question Text based control algorithim for modelica

Text based control algorithim for modelica Hello all, I am trying to model a microgrid simulation using the modelica bu

2023-03-31 09:01:19 -0500 commented answer Modelica buildings outputs error when connecting the terminal

The renewable_source.mo is an example from the library. My model is the my_microgrid.mo. I will include an updated versi

2023-03-28 14:35:45 -0500 commented question Modelica buildings outputs error when connecting the terminal

@Aaron Boranian Done, I was not sure if this forum was okay with external links. Thanks

2023-03-28 09:52:47 -0500 asked a question Modelica buildings outputs error when connecting the terminal

Modelica buildings outputs error when connecting the terminal Hello, I am trying to connect the grid to a line in the mo

2023-03-28 09:51:39 -0500 asked a question Modelica Buildings Electrical Problem

Modelica Buildings Electrical Problem Hello all, I am trying to connect my 3 generation sources to the load, but I am ha

2023-03-28 09:51:32 -0500 asked a question Lines in Buildings Library do not seem to connect

Lines in Buildings Library do not seem to connect Hello all, This is probably a really stupid question, but how would I