Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

OpenModelica Interactive simulation

OpenModelica Interactive simulation

Hello

I would like to ask about interactive simulation. So it is the simulation where i can change for example(as shown in documentation) input flow of water into a tank during the simulation externally for example by sending requested value by sockets.  I can achieve it by using “OpenModelica Interactive” (OMI). This OMI can be started by $omc +d=interactive  . About it is written in chapter 6 of PDF document.  I am trying to make my own GUI which will comunicate by sockets and sends inputflow to tank to openmodelica. But this is not stated in chapter 6 more.. only results of an example (no commands no how to run a model in interactive simulation etc... ) . Where could i find how to do it ? Or am I doing sth wrong? Thanks for reply

Re: OpenModelica Interactive simulation

+d=interactive has nothing to do with OMI. Which is very old indeed and no longer part of omc.

Re: OpenModelica Interactive simulation

Thank you current/smile. This information really helped:) and is there a kind of API which could do something like OMI? like i described in first post:)  (or for example running a simulation, more/less in realtime where i could change some variables/parameters from outside (e.g. sockets,or some IPC like pipe, shared memory etc (it can work on linux)) ? without FMI i mean if sth exists:)

Edited by: bumino - Mar-21-15 20:30:19

Re: OpenModelica Interactive simulation

Hi,

There are several ways of dealing with this:
1. use OpenModelica 1.8.1 which still has the interactive stuff
2. use external functions in when equations to set the values of the variables you're interested in
3. use FMI, export your model in an FMU and load it and then you can change the values of variables.

For 3 you will need an FMI library to load the fmu in your process.


Re: OpenModelica Interactive simulation

Thanks  for reply current/smile
I would like to ask an question about option 2. Will the simulation wait for the result of a externally called function(if i use something to slow execution of function  ? Or is there a way to make simulation synchronous with real time? So when I start simulation it wont run fast (all at once) but will be executed in time(eg. 10 sec of simulation is about 10 sec in real life current/big_smile ) Thanks.

Re: OpenModelica Interactive simulation

Re: OpenModelica Interactive simulation

If your external function is blocking then it will wait until a result.
You can also use:

Code:


when sample(0, 10)  then
  reinit(variable, externalFunctionCall(time)); // the externalFunctionCall will return the new variable value
end when;

For some code examples have a look at:
https://openmodelica.org/openmodelicawo … s-examples
CDAC Real Time Application.zip
Is quite old and uses SimForge as graphical editor but the idea should work fine.
Unfortunately the code is missing the external library.

Re: OpenModelica Interactive simulation

thank you both current/smile this is really very helpful. I will look into this solutions more:))

Re: OpenModelica Interactive simulation

Hello,
I was going through this post but as it has been said the external libraries are missing fr CDACRealtimeSynchronousization library.

But is it possible to get it from somewhere so that I can run this code and check it out.

As for my work I need something related to that. Where I will run a server from OpenModelica via call of external C functions but when I run the server it simulates and stop I want to call from a outside client and want to run the server then I want OpenModelica model to get the value from the client send and then process it and send it again. Can you please tell me how to do it ?

Re: OpenModelica Interactive simulation

I now updated the CDAC zip to contain the external C code:
https://openmodelica.org/openmodelicawo … s-examples

Re: OpenModelica Interactive simulation

Hi all, I am using OpenModelica since some months ago and I have a issue with the real time. After a week researching about how to simulate a model in real time, I found out your example with several tanks and with the implementation DACSRealTimeSynchronization. It looked as a promising up to date to solve my issue.  I added de .h and .c files to my folder. I have check the model and everyting was fine. But when OM is compiling the program, the following problem arose:

"
[DACSRealTimeSynchronization: 14:3-19:19]: Could not find library libTimerFunction.o in either of:
  C:/OpenModelica//lib//libTimerFunction.o.dll
  C:/OpenModelica//lib//liblibTimerFunction.o.a
  C:/OpenModelica//lib//liblibTimerFunction.o.lib
  C:/OpenModelica//lib//omc/libTimerFunction.o.dll
  C:/OpenModelica//lib//omc/liblibTimerFunction.o.a
  C:/OpenModelica//lib//omc/liblibTimerFunction.o.lib
  %APPDATA%/.openmodelica/binaries/Bombeo/libTimerFunction.o.dll
  %APPDATA%/.openmodelica/binaries/Bombeo/liblibTimerFunction.o.a
  %APPDATA%/.openmodelica/binaries/Bombeo/liblibTimerFunction.o.lib
  C:/Users/sldmca/Documents/Dymola/Resources/Library/mingw32/libTimerFunction.o.dll
  C:/Users/sldmca/Documents/Dymola/Resources/Library/mingw32/liblibTimerFunction.o.a
  C:/Users/sldmca/Documents/Dymola/Resources/Library/mingw32/liblibTimerFunction.o.lib
  C:/Users/sldmca/Documents/Dymola/Resources/Library/win32/libTimerFunction.o.dll
  C:/Users/sldmca/Documents/Dymola/Resources/Library/win32/liblibTimerFunction.o.a
  C:/Users/sldmca/Documents/Dymola/Resources/Library/win32/liblibTimerFunction.o.lib
  C:/Users/sldmca/Documents/Dymola/Resources/Library/libTimerFunction.o.dll
  C:/Users/sldmca/Documents/Dymola/Resources/Library/liblibTimerFunction.o.a
  C:/Users/sldmca/Documents/Dymola/Resources/Library/liblibTimerFunction.o.lib"

In addition,  The compiler dialog said:
"
c:/openmodelica/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -llibModelicaRead.o
c:/openmodelica/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -llibTimerFunction.o
c:/openmodelica/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -llibModelicaPrint.o
collect2: ld returned 1 exit status
\MinGW\bin\mingw32-make: *** [omc_main_target] Error 1
Compilation process failed. Exited with code 2."

I am a bit lost. I am not sure how to make OM créate the neccesary .o file or if I am loosing any step.

I would be very pleased if anyone could help.

Kind regards

Re: OpenModelica Interactive simulation

If you use the nightly builds, you can try the new real-time flags for OM simulations: https://openmodelica.org/doc/OpenModeli … mpiler-omc

Re: OpenModelica Interactive simulation

Dear sjoelund.se,

Thank yoy very much for your reply. According to your advice, I downloaded the last nighty build and used the rt simflag.

When executing this:


simulate(dcmotor, startTime=0.0, stopTime=30.0, cflags="-g", measureTime=true, simflags="-rt 0.5");


I see in fact the Time Simulation is fairly 15s. If instead of 0.5 I use -rt 2, the Time Simulation changes to 60s, which is fine.

The problema is that at the end I get the final plot, instead of a real time plotting which is generated as real time passes.

How could I see the outpout plot being generated as real time passes?

Best regards,

P.S.: With Dymola as well as with Wolfram, just by selecting in 'Simulate Options' the option "Real-time synchronization", I achieved my goal of watching the outputs being plotted as the simulation takes places following real time. I would need to perform the same with OM.

Re: OpenModelica Interactive simulation

You get real-time plotting by implementing that plotting yourself. For example through the OPC UA interface. OMEdit does not have this support yet.

Re: OpenModelica Interactive simulation

Ok, I will try with this,

On the other hand, and related to this, I'd have a second question.

Imagine the output I am plotting with your method is a tank level sensor. Suppose the level is achieving the top tank level, and in orther to avoid overflow I need to change a model input via keyboard as can be a valve opening. Would this be posible with OM?

Thank you very much indeed.

Re: OpenModelica Interactive simulation

Ok, I will try with this,

On the other hand, and related to this, I'd have a second question.

Imagine the output I am plotting with your method is a tank level sensor. Suppose the level is achieving the top tank level, and in orther to avoid overflow I need to change a model input via keyboard as can be a valve opening. Would this be posible with OM?

Thank you very much indeed.

Re: OpenModelica Interactive simulation

You can change inputs with OPC UA or by using Linux and the device drivers library (I suppose).

Re: OpenModelica Interactive simulation

There is one issue that I don´t understand completely.
in OM versión 1.8.1 I am able to perform interactive simulations with inputs and responses from the program. Unfortunately, this function seems that have been deactivated for the following OM versions.

Hi,

There are several ways of dealing with this:
1. use OpenModelica 1.8.1 which still has the interactive stuff
2. use external functions in when equations to set the values of the variables you're interested in
3. use FMI, export your model in an FMU and load it and then you can change the values of variables.

For 3 you will need an FMI library to load the fmu in your process.

However, Real Time simulation is only available after up to date 1.10.1 , as it is explained in the link that you provided last friday https://openmodelica.org/doc/OpenModeli … mpiler-omc

I am not sure if I if I will run an interactive simulation in 1.8.1 the time step is synchronised with the real time. I suppose that no. In point 2, using external functions, does there exist any documentation about how to perform this task? Is this perform made with the OPC UA tool?

Again, that a lot for your quick responses, are being very very useful!
Regards



Re: OpenModelica Interactive simulation

There is one issue that I don´t understand completely.
in OM versión 1.8.1 I am able to perform interactive simulations with inputs and responses from the program. Unfortunately, this function seems that have been deactivated for the following OM versions.

Hi,

There are several ways of dealing with this:
1. use OpenModelica 1.8.1 which still has the interactive stuff
2. use external functions in when equations to set the values of the variables you're interested in
3. use FMI, export your model in an FMU and load it and then you can change the values of variables.

For 3 you will need an FMI library to load the fmu in your process.

However, Real Time simulation is only available after up to date 1.10.1 , as it is explained in the link that you provided last friday https://openmodelica.org/doc/OpenModeli … mpiler-omc

I am not sure if I if I will run an interactive simulation in 1.8.1 the time step is synchronised with the real time. I suppose that no. In point 2, using external functions, does there exist any documentation about how to perform this task? Is this perform made with the OPC UA tool?

Again, that a lot for your quick responses, are being very very useful!
Regards



Re: OpenModelica Interactive simulation

Dear sjoelund.se,

I am trying the UA Interface as you suggested for the interactive simulation. I have been testing the UA Server and UA Client for using some demo variables from the software.

The one thing I need is to link the server to the OpenModelica, so as the client can ask for some variables during the simulation.

How can I do this link? How can I link the compiled .exe from OpenModelica to the UAServer?

I have not found anything at all about the procedure for doing so.

Thank you very much in advance,

Best regards,
Mary

Re: OpenModelica Interactive simulation

By starting the executable with flag -embeddedServer=opc-ua, the OM OPC UA server is started,

Re: OpenModelica Interactive simulation

Dear sjoelund.se ,

It worked out, you're amazing!
Thank you for your kindness and your fast reply, I really appreciate it.

When receiving in the UA Client the variables once the .exe runs at real time, I cannot see all the model variables (those which I would see after having run normally the model in OM in the 'Plot' tab). With which criteria does OpenModelica sets the variables which will be sent to the client? Can they be modified so as to include those that are left?

Best regards,
Mary.

Re: OpenModelica Interactive simulation

The latest version show Real and Boolean variables (states, inputs, continuous), but does not show parameters or constant variables (yet). Constants can be retrieved from the _init.xml file I believe.

Re: OpenModelica Interactive simulation

Dear Sjoelund.se:

My concern now is about the variables that are received in my UA Expert:

https://openmodelica.org/images/agorapro/attachments/5020/mini_ScreenShot525.jpg

As you can see in the image attached (From the modelica.fluids.examples.tanks.emptytanks), there exist variables that are not shown in the UA expert meanwhile the OMEdit it does. For example, the variable pipe.port_a.m_flow is not shown in the UAExpert. Am I missing something when I create the .exe or running the program?

this is the code that I use to compile the program:

Code:

loadModel(Modelica); 

loadFile("C:/Users/sldmca/Documents/Dymola/emptytanks.mo");
simulate(emptytanks,startTime=0.0, stopTime=100.0);

And this to run the program with the UA server:

Code:

 emptytanks.exe -embeddedServer=opc-ua -rt=1

Thanks a lot for your help, with your tips I am getting further that I expected! I am sure that at the end I will manage to futfill my task!

Kind regards

Attachments:

Re: OpenModelica Interactive simulation

It is listed in freeopcua-client, but I know that earlier versions did not support alias variables. So perhaps you just need to update your OMC. It is a new and experimental feature, so things may change quickly.

Re: OpenModelica Interactive simulation

sjoelund.se wrote:


It is listed in freeopcua-client, but I know that earlier versions did not support alias variables. So perhaps you just need to update your OMC. It is a new and experimental feature, so things may change quickly.

What are the best options for interactive simulation nowadays? OMI is deprecated, OPC is being developed, so the good options are FMUs and external functions?

There are 0 guests and 0 other users also viewing this topic
You are here: