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

Modelica interpreter

Modelica interpreter

Does it exist a Modelica language interpreter?

I'm developing an educational application for interactive simulation of very simple models.

I'd like that the switching from connections editing to simulating be faster than the perceived now. As this switching involves compilation of the model, the process is complex and takes about 10 seconds even for simple models. As the application is for test an error, i'm afraid having to wait so many times is not good.

I'm wondering if using an interpreter I could have a faster response from editing the model and simulating it, and if it would allow interactive simulation.

1. Is there any option for this with OpenModelica?
2. Does anyone know if such solution exist outside OpenModelica?
3. Which steps should I follow if I had to build the interpreter based on OMC from source?

Re: Modelica interpreter

Modelica is equation-based, and equations must be solved simultaneously. Therefore I suppose it is impossible to make an interpreted version of it.

However I use it for teaching, and the majority of time one discusses and prepares models. Compilations are not that many, Moreover, that if you have to iteratively  find the right value of a non-structural parameter, you can re-run the simulation very fast without rebuilding the model.
So Modelica and OM are good for teaching.

IMO OM has a single issue that partly jeopardises teaching: it is slow in opening models and in moving parts of a diagram around with arrow keys.
However this issue is not so severe and, according to what I read from the programmers, it will be solved in the coming months, when release 2.0 becomes available.

Re: Modelica interpreter

Hi ceraolo, I'm glad for your answer.

My issue is really in the switching from modeling and simulation, and, as my application is going to explore this feature, for trial and error modeling, it's important to me.

About Modelica being equation-based, and maybe being impossible to solve iteratively, I was thinking just now if we could use the causality of the system and solve iteratively by substitution, equation by equation. It would need a sorting of the equations, and I don't know how it would behave with differential equations, but maybe this is a possibility?

Re: Modelica interpreter

The real beauty if Modelica is its acausal approach.
If you want to teach modelica, IMO you cannot give up this feature.

Yes modelica simulates as well causal control systems, algorithms, but these are additions to its very core that is acausual, equation-based simulation.
All tools accept tricks to obtain special results.
But when too many tricks are needed with a tool or language to obtain a purpose, maybe it is better to explore a different tool or language.

Re: Modelica interpreter

(please disconsider this answer)

Edited by: brunoleos - Jan-17-17 17:43:32

Re: Modelica interpreter

Hi ceraolo,

My question is not about teaching Modelica.

And take care with your concept of "acausal", which seems misleading. The compilation process goes through a "causalization" stage, which is needed for numerical simulation. This works besides the acausal approach of systems modeling, which is explored by Modelica, but of property of the underlying physics.

Please consider verifying the far right section of this picture: https://www.openmodelica.org/svn/OpenMo … iagram.jpg

I, as you, don't know if an interpreter is feasible, or even possible. So let's consider the opinion of those expert in the compiler development, which can give us a much better answer.

Edited by: brunoleos - Jan-17-17 17:43:54

Re: Modelica interpreter

An interpreter for Modelica language is surely possible and we have it partially as part of the OpenModelica compiler (for function interpretation).

However, I don't think any of the Modelica tools are following this path as you need access to numerical solver libraries (which are mostly in C or Fortran) and you need to link with them.

OpenModelica also does extensive symbolic manipulation and can solve some systems using substitutions but it highly depends on the system complexity.

Re: Modelica interpreter

Thank you adrpo,

I see, the numerical simulation is really going to be a problem.

Could you direct me to the sources where the interpreter is implemented?

Also, about the possibility of symbolic substitutions, could you direct me to some commands?

Edited by: brunoleos - Jan-17-17 18:54:42

Re: Modelica interpreter


The code for the function evaluation interpreter is here:
https://github.com/OpenModelica/OMCompi … unction.mo
It basically goes over each function algorithm statement and interprets it in an environment with variables.

The compiler code is not that easy to understand, is written in MetaMoldelica (out own functional language).
You can find more about it here:
https://openmodelica.org/developersresources/courses
https://openmodelica.org/developersreso … umentation

Re: Modelica interpreter

Thank you again adrpo.

And, about the possibility of symbolic substitutions that you also mentioned, could you direct me to some commands or documents?

Edited by: brunoleos - Jan-17-17 18:57:15

Re: Modelica interpreter

There are no API commands for substitution, is done automatically to evaluate expressions involving parameters or constants, basically to optimize the systems when calling buildModel or simulate.

In the front-end we only do this kind of things for structural parameters (array dimensions, etc), in the back-end depending on the the given flags there are more optimizations going on. I'm affraid we don't have too much documentation about the back-end so you'll have to look in the code:
https://github.com/OpenModelica/OMCompi … er/BackEnd
For a bit of outdated overview of the back-end you can look here:
https://openmodelica.org/svn/OpenModeli … r/BackEnd/
Some information about what the back-end does is here but is quite old too:
https://www.openmodelica.org/images/doc … ackend.pdf
I'll ask one of the back-end developers if there is anything newer and get back to you.

There are 0 guests and 0 other users also viewing this topic