I am having problems running my model in openmodelica on Ubuntu 20. I tried exporting the path following the documentation and installed libpython3.8-dev
.
https://build.openmodelica.org/Documentation/Buildings.Utilities.IO.Python_3_8.UsersGuide.html
I ran the model, but I am getting this error, but I am not sure if it is my python code or it is something wrong the pythonpath
Simulation process failed. Exited with code 255.
/tmp/OpenModelica_sigi-laptop/OMEdit/peakShavingPythonModule/peakShavingPythonModule -port=36007 -logFormat=xmltcp -override=startTime=0,stopTime=10,stepSize=1,tolerance=1e-6,solver=dassl,outputFormat=mat,variableFilter=.* -r=/tmp/OpenModelica_sigi-laptop/OMEdit/peakShavingPythonModule/peakShavingPythonModule_res.mat -w -lv=LOG_STATS -inputPath=/tmp/OpenModelica_sigi-laptop/OMEdit/peakShavingPythonModule -outputPath=/tmp/OpenModelica_sigi-laptop/OMEdit/peakShavingPythonModule
The initialization finished successfully without homotopy method.
Failed to load "/home/sigi-laptop/.openmodelica/libraries/Buildings 9.1.0/Resources/Python-Sources/peak_shaving_no_soc.py". This may occur if you did not set the PYTHONPATH environment variable or if the Python module contains a syntax error. The error message is "(null)"
My modelica code
model peakShavingPythonModule
Buildings.Utilities.IO.Python_3_8.Real_Real peak_shaving_test(functionName = "peak_shaving", moduleName = "/home/sigi-laptop/.openmodelica/libraries/Buildings 9.1.0/Resources/Python-Sources/peak_shaving_no_soc.py", nDblRea = 1, nDblWri = 1, samplePeriod = 1) annotation(
Placement(visible = true, transformation(origin = {-14, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Sources.CombiTimeTable combiTimeTable(table = [0, 0; 1, 100; 2, -100; 3, 150; 4, -150; 5, 75; 6, 30; 7, 10; 8, -5; 9, -32; 10, 42]) annotation(
Placement(visible = true, transformation(origin = {-64, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(combiTimeTable.y, peak_shaving_test.uR) annotation(
Line(points = {{-52, 30}, {-26, 30}}, color = {0, 0, 127}, thickness = 0.5));
annotation(
uses(Buildings(version = "9.1.0"), Modelica(version = "4.0.0")),
experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 1),
__OpenModelica_commandLineOptions = "--matchingAlgorithm=PFPlusExt --indexReductionMethod=dynamicStateSelection -d=initialization,NLSanalyticJacobian",
__OpenModelica_simulationFlags(lv = "LOG_STATS", s = "dassl", variableFilter = ".*"));
end peakShavingPythonModule;
My python code (saved to /.openmodelica/libraries/Buildings 9.1.0/Resources/Python-Sources):
def peak_shaving(net_load):
if (net_load <= -15) and (net_load >= -100):
ivt_ctrl = abs(net_load + 15)
elif (net_load <= -100):
ivt_ctrl = 100
elif (net_load >= 0) and (net_load < 100):
ivt_ctrl = -1*(net_load);
elif (net_load < 100):
ivt_ctrl = -100
else:
ivt_ctrl = 0
return int(ivt_ctrl)
Thank you for the help