[Question] OpenModelica Integration

classic Classic list List threaded Threaded
7 messages Options
Bitiquinho Bitiquinho
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Question] OpenModelica Integration

(I moved this topic here as it is somehow related and this list seems more lively)

Hi, all

Being able to use Modelica blocks inside XCos for me is one of the main selling points for Scilab. But in the current release it looks somehow broken (only compilation with --without-modelica flag works).

There is this GSoC idea about integrating OpenModelica to Scilab, in order to not have to maintain an in-house compiler, which is pretty neat, as it would be one less source of maintenance burden and bugs to be fixed.

However, that task is the highest ranked in difficulty. So I got curious: is the amount of worked needed for it that huge ? Which tasks would it involve, in detail ?

That's not a formal proposition to work on it (for now), but I would be really grateful if someone could give me these pointers.

Thanks in advance.

Att,
Leonardo
Clément David-2 Clément David-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Question] OpenModelica Integration

Hi Leonardo,

This is quiet a complex subject but first about the `without-modelica` flag : building the modelica
compiler requires a working OCaml stack and a Scilab OCaml build ; this is not always the case (for
example on parallel build with OCaml 4.0)and I spent already some time trying to fix the build issue
without success.

As our official build does not have this issue and ship with modelica, this is a low priority bug.

In a wider view, using Modelica is indeed a great feature of Xcos. Using a more complete / featured
/ maintained Modelica compiler is a huge interest task ! As OpenModelica is open-source, we might be
able to integrate some binary to dynamically generate C code and compile / simulate as it is
currently done for Modelicac.

You can split the tasks as :
 1. build a simple OMCompiler
 2. get into the code to discover how to generate FMI2 API (or internal API)
 3. write a scicos_block4 compatible block generator (either using a wrapper or a new code
generator)
 4. package everything for all Scilab supported platforms (in thirdparties).

IMHO this is a huge task which requires some understanding about 1D simulation and Xcos/Scicos
simulation engine behavior. IDA solvers (Sundials in our case) understanding is also required. This
seems very challenging at first but this will remove *a lot* of issues (by improving our Modelica
support).

Thanks,

--
Clément

Le samedi 04 mars 2017 à 20:45 -0700, Bitiquinho a écrit :

> (I moved this topic here as it is somehow related and this list seems more
> lively)
>
> Hi, all
>
> Being able to use Modelica blocks inside XCos for me is one of the main
> selling points for Scilab. But in the current release it looks somehow
> broken (only compilation with --without-modelica flag works).
>
> There is this GSoC idea about integrating OpenModelica to Scilab, in order
> to not have to maintain an in-house compiler, which is pretty neat, as it
> would be one less source of maintenance burden and bugs to be fixed.
>
> However, that task is the highest ranked in difficulty. So I got curious: is
> the amount of worked needed for it that huge ? Which tasks would it involve,
> in detail ?
>
> That's not a formal proposition to work on it (for now), but I would be
> really grateful if someone could give me these pointers.
>
> Thanks in advance.
>
> Att,
> Leonardo 
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/Question-OpenModelica-Integration-tp4
> 035710.html
> Sent from the Scilab / GSOC - Mailing Lists Archives mailing list archive at Nabble.com.
> _______________________________________________
> gsoc mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/gsoc
_______________________________________________
gsoc mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/gsoc
Bitiquinho Bitiquinho
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Question] OpenModelica Integration

Hi Clément,


First of all, thanks for answering and for the compilation tip. This will help a lot here.


As I was taking a look at the OpenModelica matter, I was already able to build a minimal version of the project (according to https://github.com/OpenModelica/OpenModelica/blob/master/README.md) and use OMCompiler to generate an executable from one of the test .mos files.


Regarding integration, I got a few questions:


- Should this be implemented at the core application or as a XCos package ?

- Does the integration involve linking OMCompiler (it seems to have a C API) code to Scilab/package or calling the external omc binary somehow ?

- Are the same compilation steps performed by the current compiler ? Where in the code could I take a look at how this is implemented ?

- Is there a place outside of Coselica package where Modelica is used for Scilab ?

- I'm interested in this task, mainly considering its importance, but not sure about how much I would be able to accomplish. Is there an intermediate milestone that could be considered a relevant GSoC project, leaving remaining work as extra milestones to be achieved as time permits ?


Thanks in advance.



Att,

Leonardo



De: gsoc <[hidden email]> em nome de Clément David <[hidden email]>
Enviado: quarta-feira, 8 de março de 2017 05:45
Para: [hidden email]
Assunto: Re: [Gsoc] [Question] OpenModelica Integration
 
Hi Leonardo,

This is quiet a complex subject but first about the `without-modelica` flag : building the modelica
compiler requires a working OCaml stack and a Scilab OCaml build ; this is not always the case (for
example on parallel build with OCaml 4.0)and I spent already some time trying to fix the build issue
without success.

As our official build does not have this issue and ship with modelica, this is a low priority bug.

In a wider view, using Modelica is indeed a great feature of Xcos. Using a more complete / featured
/ maintained Modelica compiler is a huge interest task ! As OpenModelica is open-source, we might be
able to integrate some binary to dynamically generate C code and compile / simulate as it is
currently done for Modelicac.

You can split the tasks as :
 1. build a simple OMCompiler
 2. get into the code to discover how to generate FMI2 API (or internal API)
 3. write a scicos_block4 compatible block generator (either using a wrapper or a new code
generator)
 4. package everything for all Scilab supported platforms (in thirdparties).

IMHO this is a huge task which requires some understanding about 1D simulation and Xcos/Scicos
simulation engine behavior. IDA solvers (Sundials in our case) understanding is also required. This
seems very challenging at first but this will remove *a lot* of issues (by improving our Modelica
support).

Thanks,

--
Clément

Le samedi 04 mars 2017 à 20:45 -0700, Bitiquinho a écrit :
> (I moved this topic here as it is somehow related and this list seems more
> lively)
>
> Hi, all
>
> Being able to use Modelica blocks inside XCos for me is one of the main
> selling points for Scilab. But in the current release it looks somehow
> broken (only compilation with --without-modelica flag works).
>
> There is this GSoC idea about integrating OpenModelica to Scilab, in order
> to not have to maintain an in-house compiler, which is pretty neat, as it
> would be one less source of maintenance burden and bugs to be fixed.
>
> However, that task is the highest ranked in difficulty. So I got curious: is
> the amount of worked needed for it that huge ? Which tasks would it involve,
> in detail ?
>
> That's not a formal proposition to work on it (for now), but I would be
> really grateful if someone could give me these pointers.
>
> Thanks in advance.
>
> Att,
> Leonardo 
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/Question-OpenModelica-Integration-tp4
> 035710.html
> Sent from the Scilab / GSOC - Mailing Lists Archives mailing list archive at Nabble.com.
> _______________________________________________
> gsoc mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/gsoc
lists.scilab.org
Your email address: Your name (optional): You may enter a privacy password below. This provides only mild security, but should prevent others from messing ...

_______________________________________________
gsoc mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/gsoc
lists.scilab.org
Your email address: Your name (optional): You may enter a privacy password below. This provides only mild security, but should prevent others from messing ...


_______________________________________________
gsoc mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/gsoc
Clément David-2 Clément David-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Question] OpenModelica Integration

Hi Leonardo,

<answered in-line>

Le mercredi 08 mars 2017 à 15:11 +0000, Leonardo José Consoni a écrit :
> - Should this be implemented at the core application or as a XCos package ?

Probably inside Scilab, there is some scilab macros that call directly the modelicac / modelicat
binaries.

> - Does the integration involve linking OMCompiler (it seems to have a C API) code to
> Scilab/package or calling the external omc binary somehow ?

Currently I only expect to successfully call the binary using something like `omc -s MyModel.mo` to
generate some C code and then integrate this code as an Xcos (formally Scicos) block. This block API
generation (or wrapping) is probably the harder task. You have to learn how functions are called
both on Xcos and OpenModelica and try to get the same functionalities :

 * using IDA solver
 * with Zero crossing management
 * and Jacobian computation

See wikipedia, Modelica, Scicos papers and source code to understand these terms :).

> - Are the same compilation steps performed by the current compiler ? Where in the code could I
> take a look at how this is implemented ?

Currently the compiler (modelicac and omc) are similar but offers different API. I currently only
target the same functionnal scope (without index reduction for example) at first so this should be
feasible without solver / simulator modification.

> - Is there a place outside of Coselica package where Modelica is used for Scilab ?

In Xcos, there is an Electrical and an Hydraulic palette available. Coselica will be of course the
first "complex" Modelica library to support.

> - I'm interested in this task, mainly considering its importance, but not sure about how much I
> would be able to accomplish. Is there an intermediate milestone that could be considered a
> relevant GSoC project, leaving remaining work as extra milestones to be achieved as time permits ?

Yep that's not easy to get, probably a first milestone might be to compile a "small"
OpenModelicaCompiler on each supported platform (Linux x86, Linux x86_64, Windows x86, Windows x64
and MacOS X) and write documentation about it. A second milestone to update Scilab internals to call
OpenModelica compiler instead of modelicac. And a third milestone to implement a scicos_block4 API
for the generated code and validate everything.

Thanks,

--
Clément
_______________________________________________
gsoc mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/gsoc
Bitiquinho Bitiquinho
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Question] OpenModelica Integration

This post was updated on .
In reply to this post by Clément David-2
Hi again,

I'm still trying to get a better understanding of all those concepts, but it looks like compiling a .mo modelica model file with "omc -s --simCodeTarget=sfmi <model_name>.mo" generates a XML model description file and a single .cpp source implementing the model and exporting all FMI2 interface functions (as in standard fmi2Functions.h header).

(It is also possible to generate a FMU .zip package which also contain a makefile)

From what I understand, currently every modelica block in XCos is translated by modelicac into a C source file and then into a shared library (.dll/.so/.dynlib) linked to a full simulation executable, is that right ? If so, the same would be made for OMCompiler, just with the appropriate changes to compile_modelica(...) function (different source and header names), right ?

Does scicos_block4 already make FMI2 calls ? If that's not the case, that's what you mean by implementing a wrapper ? To translate internal block calls to and from FMI2 in order to use the generated block library ?

Also, regarding solvers, the FMI 2.0 specification describes 2 modes of FMU export/import (implemented by OpenModelica): Model Exchange, that leaves integration to external solvers, and Co-Simulation, that ships the solver into generated source code/binary library.

Which one would be more desirable ? As I understand, Model Exchange would allow Modelica blocks to use the same (dynamically switchable) solver as the rest of the XCos model, and Co-Simulation would offer easier implementation, but limited to using only an forward Euler solver.


Thanks again

Att,
Leonardo
Clément David-3 Clément David-3
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Question] OpenModelica Integration

In reply to this post by Clément David-2
Hi Leonardo,

Le lundi 20 mars 2017 à 09:59 -0700, Bitiquinho a écrit :
> Which one would be more desirable ? As I understand, Model Exchange would
> allow Modelica blocks to use the same (dynamically switchable) solver as the
> rest of the XCos model, and Co-Simulation would offer easier implementation,
> but  limited to using only an forward Euler solver
> <https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/fmi.html#fmi-export

IMHO to integrate Modelica the ModelExchange mode should be used. Currently a ModelExchange-like
interface is used and it allow us to simply "read" a Modelica value within Xcos. The Xcos solver
settings will also be applicable in that case.

Thanks,

--
Clément
_______________________________________________
gsoc mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/gsoc
Clément David-3 Clément David-3
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Question] OpenModelica Integration

In reply to this post by Bitiquinho
Hi Leonardo,

Le dimanche 19 mars 2017 à 15:26 -0700, Bitiquinho a écrit :

> Hi again,
>
> I'm still trying to get a better understanding of all those concepts, but it
> looks like compiling a .mo modelica model file with "omc -s
> --simCodeTarget=sfmi <model_name>.mo" generates a XML model description file
> and a single .cpp source implementing the model and exporting all FMI2
> interface functions (as in standard fmi2Functions.h header).
>
> (It is also possible to generate a FMU .zip package which also contain a
> makefile)
>
> From what I understand, currently every modelica block in XCos is translated
> by modelicac into a C source file and then into a shared library
> (.dll/.so/.dynlib) linked to a full simulation executable, is that right ?
> If so, the same would be made for OMCompiler, just with the appropriate
> changes to compile_modelica(...) function (different source and header
> names), right ?

Yes exactly, the Modelica "compiler" should be switched from modelicac to OpenModelica but the
simulation engine should be preserved.

> Does scicos_block4 already make FMI2 calls ? If that's not the case, that's
> what you mean by implementing a wrapper ? To translate internal block calls
> to and from FMI2 in order to use the generated block library ?

Currently scicos_block4 does not fully implement the FMI2 interface but is compatible in some way.
The implementation should "adapt" (as in the adapter pattern) the FMI API as a scicos_block4 one to
allow a mixed-simulation.

Thanks,

--
Clément
_______________________________________________
gsoc mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/gsoc
Loading...