- Index
- » Users
- » Mota
- » Profile
Posts
Posts
Since I am not sure if the following is a bug on the OpenModelica side, or just something which can be solved with some background knowledge, I post this question related to the trac https://trac.openmodelica.org/OpenModel … 160#ticket here, too.
We created a toolbox for the simulation of microgrids.
In the first run, everything was just written in a single ".mo" file, in this case grid.mo. Not really structured and pretty slow, since a really big file needs to be changed with every action.
The following file of a older branch shows the structure of the old model:
https://github.com/upb-lea/openmodelica-microgrid-gym/blob/feature_41_construction_branch/fmu/grid.mo
Later on, we followed the example of many other OpenModelica libraries, and made a library out of it, which is structured in many different files and folders, which are connected to each other. Way faster, tidier, and looks better.
The package.mo file opens the library:
https://github.com/upb-lea/openmodelica-microgrid-gym/tree/feature_75_library/OpenModelica_Microgrids
Problem:
Creating a FMU (2.0, ME) from both versions works totally fine, simulating it in python works with identical results, except one point:
After the strucure change, it is not possible to change parameters anymore via PyFMI. The value itself gets changed, which is visible by plotting the direct value (for example something like resistor1.R). But for the simulation results (like currents, voltages), the default value which was set in OpenModelica is used.
The main difference - at least for my point of view - is that not all ODEs are in the same folder, and something with the parametertransfer between the different folders goes wrong, but this is just an absolutely blind guess.
If anyone knows more about the topic, or even has a solution for us that we could keep on using the new, structured library, please let me know :-)
Best Regards!
Henrik
Since the installation of OepnModelica on a Mac seems to be according the homepage quiet difficult and annoying, providing a docker image and making this the recommended way of might be an idea.
I think the current procedure might prevent some Mac users from installing this nice program, so this could be a handy workaround and simplification for the installation process :-)
Or are there any problems/disadvantages I havn´t thought about?
Thanks!
After setting this flag
Code:
OpenModelica.Scripting.loadFile("grid.mo"); getErrorString();
OpenModelica.Scripting.loadFile("network_ctrl_lim2.mo"); getErrorString();
setCommandLineOptions("-d=newInst"); getErrorString();
setCommandLineOptions("-d=initialization"); getErrorString();
//setCommandLineOptions("--simCodeTarget=Cpp"); getErrorString();
setCommandLineOptions("-d=-disableDirectionalDerivatives"); getErrorString();
setCommandLineOptions("--fmiFlags=s:cvode"); getErrorString();
OpenModelica.Scripting.translateModelFMU(network_ctrl_lim2, version="2.0", fmuType = "cs"); getErrorString();
I receive following error message while trying to execute the file:
Code:
Traceback (most recent call last):
File "C:\Users\hbode\Miniconda3\envs\omgtest\lib\site-packages\fmpy\fmi1.py", line 142, in __init__
self.dll = cdll.LoadLibrary(libraryPath)
File "C:\Users\hbode\Miniconda3\envs\omgtest\lib\ctypes\__init__.py", line 442, in LoadLibrary
return self._dlltype(name)
File "C:\Users\hbode\Miniconda3\envs\omgtest\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] Das angegebene Modul wurde nicht gefunden
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/hbode/PycharmProjects/omg/examples/test_pll.py", line 89, in <module>
simulate_custom_input()
File "C:/Users/hbode/PycharmProjects/omg/examples/test_pll.py", line 34, in simulate_custom_input
instanceName='instance1')
File "C:\Users\hbode\Miniconda3\envs\omgtest\lib\site-packages\fmpy\fmi2.py", line 509, in __init__
super(FMU2Slave, self).__init__(**kwargs)
File "C:\Users\hbode\Miniconda3\envs\omgtest\lib\site-packages\fmpy\fmi2.py", line 85, in __init__
super(_FMU2, self).__init__(**kwargs)
File "C:\Users\hbode\Miniconda3\envs\omgtest\lib\site-packages\fmpy\fmi1.py", line 144, in __init__
raise Exception("Failed to load shared library %s. %s" % (libraryPath, e))
Exception: Failed to load shared library C:\Users\hbode\AppData\Local\Temp\tmpzlcvhz9b\binaries\win64\network_ctrl_lim2.dll. [WinError 126] Das angegebene Modul wurde nicht gefunden
The german Error messages (Winerror126) mean: "This module could not be found".
Except this flag, everything is the same. Anyone an idea, why this happens, and how to solve it? :-)
By now, there should be two available solvers for CS, Euler and CVODE.
How can i select the solver I want to use?
I just found the tracs which confimes that CVODE is available, but in the user-guides, this possibility is (as far as i have seen) not available.
I am using the newest nightly build of OMEdit and FMpy for the transfer to python.
Best regards,
Henrik
Is it possible to extract the ODE System from OpenModelica?
Using the nice GUI of OpenModelica to generate an ODE System which can be solved for further processings for example in Python would be really nice!
I know about the FMI interface, which we use at the moment for our simulations, but due to many bugs and problems which occur especially by the usage of PyFMI, just using ODE system might give us more control and stability in our further research.
I have a model, create an FMU out of it, and want to import it in to python.
Having inputs on the first canvas works, and transferring them to the blocks which are used works, too.
Because of the architecture of the python code, i need to have the prefix for the inputs as for the rest of the block.
I made a minimal example:
Code:
package testi
model source
Modelica.Electrical.Analog.Sources.SignalVoltage signalVoltage annotation(
Placement(visible = true, transformation(origin = {0, 36}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Analog.Basic.Ground ground annotation(
Placement(visible = true, transformation(origin = {48, 22}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Analog.Interfaces.Pin pin annotation(
Placement(visible = true, transformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Blocks.Interfaces.RealInput u annotation(
Placement(visible = true, transformation(origin = {0, 108}, extent = {{-20, -20}, {20, 20}}, rotation = -90), iconTransformation(origin = {0, 108}, extent = {{-20, -20}, {20, 20}}, rotation = -90)));
equation
connect(signalVoltage.n, ground.p) annotation(
Line(points = {{10, 36}, {48, 36}, {48, 32}}, color = {0, 0, 255}));
connect(signalVoltage.p, pin) annotation(
Line(points = {{-10, 36}, {-20, 36}, {-20, 0}, {100, 0}, {100, 0}}, color = {0, 0, 255}));
connect(signalVoltage.v, u) annotation(
Line(points = {{0, 48}, {0, 48}, {0, 108}, {0, 108}}, color = {0, 0, 127}));
end source;
model base
testi.source source1 annotation(
Placement(visible = true, transformation(origin = {-42, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
testi.measurement measurement1 annotation(
Placement(visible = true, transformation(origin = {44, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(source1.pin, measurement1.pin) annotation(
Line(points = {{-32, 40}, {34, 40}}, color = {0, 0, 255}));
end base;
model measurement
Modelica.Electrical.Analog.Basic.Resistor resistor annotation(
Placement(visible = true, transformation(origin = {-24, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Analog.Interfaces.Pin pin annotation(
Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Analog.Basic.Ground ground annotation(
Placement(visible = true, transformation(origin = {30, -28}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(pin, resistor.p) annotation(
Line(points = {{-100, 0}, {-34, 0}}, color = {0, 0, 255}));
connect(resistor.n, ground.p) annotation(
Line(points = {{-14, 0}, {30, 0}, {30, -18}, {30, -18}}, color = {0, 0, 255}));
end measurement;
annotation(
uses(Modelica(version = "3.2.3")));
end testi;
Trying to create the FMU causes the error: Undetermined equation system: 23 equations, 24 variables, although i would provide the input "source.u" via python. If I create an additional Input directly in the base model and connect it to the input of the source, it works, but then i do not have the same prefix "source.u" in my python code, which i would really like to have.
Does anyone know a way to solve this problem?
I tried to create a FMU of a running model.
Doing this caused error (translatet, see attachment for original):
Code:
[C:/dev/OM64bit/OMCompiler/Compiler/BackEnd/Differentiate.mo:265:5-265:157:writable] Error: Derivation of expression "active_pll1.active_pll2.rms.i_sq_f = active_pll1.active_pll2.rms.i_sq - delay(2, active_pll1.active_pll2.rms.i_sq, active_pll1.active_pll2.rms.dt, 10000.0)" according "dummyVarFMIDER" does not exist.
Error: Internal error SymbolicJacobian.deriveAll failed
[C:/dev/OM64bit/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo:2261:7-2261:87:writable] Error: Interner Fehler function generateSymbolicJacobian failed
[C:/dev/OM64bit/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo:2053:9-2053:79:writable] Error: Interner Fehler function createJacobian failed
[C:/dev/OM64bit/OMCompiler/Compiler/BackEnd/SymbolicJacobian.mo:1766:3-1766:84:writable] Error: Interner Fehler function createFMIModelDerivatives failed
The model itself is pretty big, around 500 equations. The error only occurs when i include my RMS measurement, which include the critical line.
Code:
model RMS
constant Real f_max = 10000;
Modelica.Blocks.Interfaces.RealInput f annotation(
Placement(visible = true, transformation(origin = {0, 106}, extent = {{-20, -20}, {20, 20}}, rotation = -90), iconTransformation(origin = {0, 106}, extent = {{-20, -20}, {20, 20}}, rotation = -90)));
Modelica.Blocks.Interfaces.RealInput signal annotation(
Placement(visible = true, transformation(origin = {-108, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-108, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
Real dt = 1 / f;
Real rms = if time < dt then if time < 1e-6 then signal else sqrt(i_sq / time) else sqrt(i_sq_f / dt);
Real i_sq(start = 0, fixed = true);
Real i_sq_f = i_sq - delay(i_sq, dt, f_max);
Modelica.Blocks.Interfaces.RealOutput y annotation(
Placement(visible = true, transformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
der(i_sq) = signal ^ 2;
y = rms;
end RMS;
Creating an FMU of only this block does not seem to be problematical, but including it in networks causes errors. Anyone any idea what the reason is, or even how to solve it?
Thanks!
Edit: Trying to upload the error messages returns: This page can not be found
I want to measure the time between zero crossings of an AC voltage to measure calculate the frequency.
Some tries with the Modelica.Blocks.Discrete.TriggeredSampler as well as the eventclock from the modelica_synchronous package were not successful.
I need something which detects the zero crossings and returns the last measured period of time between (or even better: the half reciprocal as its frequency) the last two. If the time is 0 (start of the simulation) it should return 50 Hz or 0.1 s.
Maybe some sort of event triggered integrator could do the job? I couldn´t find something similar and my tries to do build one myself failed.
If anyone has an other Idea, feel free to share it.
Attached is a minimal example. For the first some milliseconds, the integrator (or something else) should return 50 Hz (or 0.1 ms), afterwards, it should return 49 Hz (the real frequency of the voltage source.
Just grabbing the real frequency is not an option, since it is a varying result of a controlled in the real model.
Thanks in advance and best regards,
Henrik
zerocrossing.mo
Hello,
I want to create FMUs with binaries for Windows and Linux, both 64 bit, inside.
I am running a 64 bit Windows 10 and tried to stick to https://trac.openmodelica.org/OpenModelica/ticket/3775
My .mos looks like the following:
Code:
OpenModelica.Scripting.loadFile("grid.mo"); getErrorString();
setCommandLineOptions("-d=newInst"); getErrorString();
setCommandLineOptions("-d=initialization"); getErrorString();
setCommandLineOptions("--simCodeTarget=Cpp"); getErrorString();
setCommandLineOptions("-d=-disableDirectionalDerivatives"); getErrorString();
OpenModelica.Scripting.buildModelFMU(grid.network, version = "2.0",
fmuType = "me", platforms = {
"x86_64-w64-mingw32"}); getErrorString();
Every time i write a specific platform, i just receive errors that something cannot be found.
What do I need to write down and what do I need to install to get it running?
Any help would be really welcome :-)
Best regards
Henrik
Works perfectly, thank you :-)
Hello,
i want to generate an FMU file from a model.mo which is located in the same folder.
The folder is part of a git repository, which has many users, so the absolute path changes.
The .mos file works, but it draws the model.mo from the default path Openmodelica/lib/omlibrary
My File is
Code:
loadModel(grid); getErrorString();
setCommandLineOptions("-d=newInst"); getErrorString();
setCommandLineOptions("-d=initialization"); getErrorString();
setCommandLineOptions("--simCodeTarget=Cpp"); getErrorString();
setCommandLineOptions("-d=-disableDirectionalDerivatives"); getErrorString();
translateModelFMU(grid.network); getErrorString();
According to https://openmodelica.org/forum/default- … ndline-use , i should be able to set an absolute model path directly as a string in the loadModel("C:\Users\myname\PycharmProjects\projectName/grid.mo"); but even this doess not work, i just receive the error (translated) Class loadModel could not be found in the aim area (global scope).
Can anyone give me the right command line to load the model directly from the current directory from where the .mos file is called? Would be awesome :-)
Best regards
Henrik
Hello,
does anyone know if there is any possibility to switch the ODE System in an FMU?
I am simulating electrical Grids, which shall be able to change over team, for example by adding a Load, uncoupling a powersource, and so on. Using the switches which are implemented is not really an option, because they don´t really switch, they just change the resistance between to coupled parts.
Using low resistors, the parts are not really uncoupled, and using high resistors makes the ODE System stiff, which makes it way more costly and causes numerical issues.
So changing the whole ODE system inside a simulation ( in my case in python, using PyFMI) is the only idea which i have left. Creating at least two model.mo files, two model.fmu files, and lots of adjustings in the code for every set-up.
Especially in the scope of the open-source toolbox we want to publish is this not a real solution, because no one wants to use a software which is so complicated and not intuitive at all.
So if anyone has an idea how to realize those loadsteps, you are really welcome to share them :-)
Best regards,
Henrik
Hey,
I want to use a switch to isolate two parts of a circuit completely from each other, or at least make the connection as low / as short as possible.
From the technical side of view, it´s clear that just "opening" the circuit does not work due to the inductive loads.
Is there any possible work-around? Using a switch with an arc should solve the problem from the technical side of view, even when there is an inductive load?
I made some tests, but having an open switch conductance "Goff" = 0, the simulations throws errors at the point the switch opens (or should reach zero when there is a switch with an arc)
Hello,
yes, in openmodelica, the model runs without any problems.
But when i try to export the FMU and run them in co-simulation via PyFMI Master, it doesnt work with those pins.
Then i just receive the error message:
pin.v is not defined as output
I fixed the problem with the the output, but not the problem with the input.
So I would be really thankful for any help!
Best regards
Mota
I found a solution for the Output:
Code:
connector Pin_Out "Pin of an electrical component"
output SI.ElectricPotential v;
flow output SI.Current i;
annotation(...);
end Pin_Out;
But defining a pin as an input does not work like this, at least I could not figure out why. Every time i try, i just get over- or underdetermined equation system when i try to generate the FMU.
Running a simulation with a direct connection works with a similar input-pin
Code:
connector Pin_in2 "Pin of an electrical component"
input SI.ElectricPotential v;
flow input SI.Current i;
annotation(...);
end Pin_in2;
I think the problem is that i can not include equations in a connector. Using a model-block instead, inserting a normal pin creates an additional equation which overdetermines my system.
Anyone any idea how to solve this problem and write an exportable input pin?
Best regards
Mota
Hello,
i want to use FMU´s which calculate electrical circuits to run in CO-Simulation.
With Real-values, everything works fine, but with currents and voltages, it doesn´t work.
I use the PyFMI Master, which means, I simulate with to separate FMU´s.
When i try to transfer the currents and voltages through the Pin via following line, i receive the Error:
Code:
connections = [( spannung ,"pin.i",widerstand ,"pin.i"),
( spannung ,"pin.v",widerstand ,"pin.v")]
The connection variable pin.i in model spannung is not an output.
For me, the best would be if I could directly connect the pins. Is that somehow possible?
Or can the "pin" be redefined as an output?
My tries to do this didn´t work, probably because of problems with the flowing current.
I would really appreciate any help!
Regards
Mota
Thank you for your Answer.
Yes, you are right, the model is only loaded once, in the beginning of the program. Probably i didn´t formulate it in a clear way.
In Reinforcement Learning, I have to run the same simulation several thousand times, to get proper results. And after each step, I have go stop the simulation to get transfer the results to my RL-Agent, making the decision for the next action. So for one run, i will use about a million times "model.simulate(...)". Having a smaller model should decrease the simulation time, especially with the huge number of iterations.
Using the dynamic model doesn´t work while simulating the FMU in Python, but that was a good hint.
Something like "Tidying up" the the FMU would be awesome. Basically, there are just 250 ODEs to be solved, where by far the most of them are just trivial equations, so getting rid of the most of the unused overhead like many (standard) libraries would be awesome, just like any other way of reducing the size and complexity of the FMU :-)
Hello,
I am using a FMU created with Openmodelica for Reinforcement Learning in Python, using the modelicagym environment. Everything works, but the bottleneck regarding the simulation time seems to be the "opening" process of the FMU while starting the simulation. In RL, this needs to be done after every time-step. My hope is to improve the speed of this process by reducing the size of the FMU. Even a small RLC-Circuit with some voltage and current measurement (size: 9 kilobyte) has after the FMU Export (FMI 2.0, Model Exchange) 1323 kilobytes.
Are there some ways like unloading unused libraries (not sure if they are exported, too) to reduce this size? Like unloading unused libraries? Or does anyone have any other ideas how to speed up this process? Any idea would be helpful :-)
Best regards
RLC-Network.mo
Hello,
following the example of the Lund University (https://portal.research.lu.se/portal/fi … i_tech.pdf , page 12, 4.3. Simulation of coupled models), i wanted to couple to FMUs. One is a simple RL-Circuit with an adjustable source (signalvoltage), the other one is a PID-Controller which sets the voltage according to the demanded current.
In Python, i want to import the FMUs and run the models with following lines:
Code:
from pyfmi import load_fmu
from pyfmi.master import Master
controller = load_fmu("controller.fmu")
RL = load_fmu("RL_Tester.fmu")
connections = [( RL ,"currentSensor1.i",controller ,"feedback1.u2"),
(controller ,"PID.y",RL ,"signalVoltage1.v")]
models = [RL , controller]
master_simulator = Master(models , connections)
res = master_simulator.simulate(final_time =1)
The connections between my Currentsensor and the PID-Controller are set in Python.
So each model individually is underdetermined, which means i create an Error when I try to build a FMU of the Models.
How can I build the FMUs which i need for this type of CO-Simulation?
The Code for Both Modelica models is attached, i only used the modelica standard libraries.
Best regards and thanks in advance!
Henrik
Code:
model RL_TesterMaster
Modelica.Electrical.Analog.Basic.Resistor resistor1(R = 0.01) annotation(
Placement(visible = true, transformation(origin = {-26, 46}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Analog.Basic.Inductor inductor1(L = 0.0001) annotation(
Placement(visible = true, transformation(origin = {8, 46}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Analog.Basic.Ground ground1 annotation(
Placement(visible = true, transformation(origin = {-66, -14}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Modelica.Electrical.Analog.Sources.SignalVoltage signalVoltage1 annotation(
Placement(visible = true, transformation(origin = {-66, 30}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor1 annotation(
Placement(visible = true, transformation(origin = {42, 46}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(inductor1.n, currentSensor1.p) annotation(
Line(points = {{18, 46}, {32, 46}}, color = {0, 0, 255}));
connect(currentSensor1.n, signalVoltage1.n) annotation(
Line(points = {{52, 46}, {58, 46}, {58, 20}, {-66, 20}}, color = {0, 0, 255}));
connect(resistor1.n, inductor1.p) annotation(
Line(points = {{-16, 46}, {-2, 46}}, color = {0, 0, 255}));
connect(signalVoltage1.p, resistor1.p) annotation(
Line(points = {{-66, 40}, {-65.5, 40}, {-65.5, 46}, {-36, 46}}, color = {0, 0, 255}));
connect(signalVoltage1.n, ground1.p) annotation(
Line(points = {{-66, 20}, {-66, -4}}, color = {0, 0, 255}));
annotation(
uses(Modelica(version = "3.2.3")));
end RL_TesterMaster;
Code:
model controllerMaster
Modelica.Blocks.Math.Feedback feedback1 annotation(
Placement(visible = true, transformation(origin = {32, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
Modelica.Blocks.Sources.RealExpression realExpression1(y = 100) annotation(
Placement(visible = true, transformation(origin = {82, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
Modelica.Blocks.Continuous.PID PID(Td = 0.0001, Ti = 0.001, k = 0.1) annotation(
Placement(visible = true, transformation(origin = {38, -36}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(feedback1.u1, realExpression1.y) annotation(
Line(points = {{40, 0}, {72, 0}}, color = {0, 0, 127}));
connect(PID.u, feedback1.y) annotation(
Line(points = {{26, -36}, {-7, -36}, {-7, 0}, {23, 0}}, color = {0, 0, 127}));
end controllerMaster;
Some additional thoughts given to this problem:
Is it possible to run the whole simulation in in a high resolution, for example 1 ms, and set something like a "Trigger-Function" which activates solving the model?
Then i could set-up the trigger function in the required intervals much faster (every 5 ms) than in the "usual" setup (every 200 ms).
According to my Matlab Simulink knowledge, could work there, but i really want to work on an open source platform.
And - if something like this works - does it affect the simulation performance in a bad way during the normal trigger intervals of 200 ms?
Thanks!
Hello,
i want to simulate a energy grid where at certain moments some events happen.
For example a closed switch, where a new load or plant gets added to the system.
Is there any possibility to simulate seconds 0-59 with 5 steps per second, seconds 59-61 with 200 steps per second, and 61-500 again with only 5 steps per second?
Couldn´t find such an option in the documentation or the Simulation Setup menu.
At the end, everything should be controlled via python.
As far as i have seen, it is possible to store all variables at t = 59s in a .mat file, restart the simulation at time 59, define another step size, restart the simulation for the time from s59-s61, and so on?
One simulation would be by far the preferred way.
Or is the any idea i havn't thought about?
Would be really thankful for any hint, idea or advice :-)
Best regards
Mota
- Index
- » Users
- » Mota
- » Profile