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

Simulation Procedure

Simulation Procedure

Hi Everybody!

I try to implement exported C/C++ files of model from Openmodelica into ARM platform. But first of all I need to understand the hierarchy and mechanism of the C/C++ files executing of the exported model.

I found out that in the  "modelname".c are situated functions for the model simulation (fetch inputs, evaluate the equations, set outputs, etc.), but I can't see what calls these functions. I mean I can't find the main mechanism, kind of state-machine I guess, which runs these functions. Is it the solver? If so how does it work? Is there anybody how can help me? Or are there any docs about this topic? Thanks for any feedback guys.

Cheers

Ondrej

Re: Simulation Procedure

libOpenModelicaSimulationRuntimeC.so calls these files; note that you could simply run OpenModelica on a raspberry pi or similar; the entire compiler runs on ARM. You can also create ARM FMUs directly from OpenModelica; see for example https://github.com/OpenModelica/OpenMod … ompile.mos which generates the FMU in https://test.openmodelica.org/hudson/jo … MUs.tar.xz

Re: Simulation Procedure

I am just a newbie, but here what I see: simply compiling with omc e.g.

Code:

omc +s model.mo

produces unreadable code.
If you translate into FMU, this it may be helpful: you should run

Code:

omc build_model.mos

where build_model.mos
should load each dependency like this:

Code:


loadModel(Modelica);
loadFile("model.mo");
loadFile("model_dependency.mo");
buildModelFMU(model, version="2.0", fmuType="cs", platforms={"dynamic"}, includeResources=true);
getErrorString()

Here you will find an output: if you unzip model.fmu like it was a zip file (actually it is), you will find more useful sources and binaries.

These are my 2cents

Re: Simulation Procedure

Hi Guys!

First of all, thanks for your replays.

I finally got myself oriented in that bunch of the C files. I found that very interesting file for me is modelName_FMU.c in the root of the FMU archive. Which is kind of starting point to me, because there is done necessary "linking" between the FMI interface and the model itself and the solver of course.

No, I try to compile all these files in the Visual Studio 2018, just to get sure which files I will definitively need to include to get model operating. But I hit the problem with the pthread.h file... I can't find it anywhere. do you now what is this guy about?

Thanks for the feedbacks guys.

Ondrej

Re: Simulation Procedure

pthread is the POSIX threads library for handling threads that is typical of Unix-like systems.
I'm not a big expert, but you hit something like this it means that the code is not well suited to run in a Win environment.

I was trying to compile myself the code with VS2017 (is VS2018 around yet? wow) but I did not hit this problem.
Look here to see my tentatives

Some questions:
1- are you trying to recompile the FMU sources (those coming from running the script with the buildModelFMU command)
OR
2- are you trying to compile the sources that comes out from omc +s <modelname>.mo

If you are trying to do (1) be aware that those source files SEEMS TO be generated by buildModelFMU in order to be compiled with make, so Unix-like systems. They cannot be compiled with MSVC without heavy modifications. In fact, in buildModelFMU you cannot tell for which compiler you want the source files* for. Having hit pthread may confirm this.

If you are trying to do (2) you can us something like this

%OPENMODELICAHOME%bin\omc +s +simCodeTarget=Cpp +target=msvc15 <modelname>.mo <modeldependecies.mo...>

but I anticipate that you will get a lot of errors (they vary depending if you set simCodeTarget=C or simCodeTarget=Cpp) unless you compile with Build Tools bundled in VS2013 (yes, because some boost related stuff has been compile with an older compiler that is not compatible with the new ones, I think)

I tried also

omc +target=msvc15 build_model.mos

but I got errors

fullvehicle3D_Pacejka_FMU.makefile(5) : fatal error U1052: file '$(RUNTIMEDIR)/Makefile.objs' not found
Stop.
RESULT: 2

but maybe something can be done...

Edited by: DarioMangoni - Jan-11-18 16:15:01

Re: Simulation Procedure

The code can be compiled without pthreads; use the define OMC_MINIMAL_RUNTIME. You might want to check https://github.com/OpenModelica/OMCompi … nfigure.ac for how the Unix systems configure and/or cross-compile the FMU.

Re: Simulation Procedure

Sorry for a late replay folks.

Well, my original aim was to export a model from OpenModelica as a C code and recompile it and run on the ARM A9 in the Xilinx Zynq device as a bare metal app for HIL simulation purposes. DarioMangoni, that means I try to do option 1.

If I understand you well guys, are you telling me that those models require some OS to execute them? and there is no option to run them as bare metal app?

thanks for any replays guys

Ondrej

Re: Simulation Procedure

Hi guys,

i did a little research and changed the target platform from ZYNQ to NI CompactRio with ARMv7 architecture and NI RT Linux onboard. This platform should be a better choice than ZYNQ and bare metal app, should be not? I found that I can choose the target platform before I export the FMU. Under Tools -> Options, there is FMI page and there I should be able to set platform but I got only "Static" or "Dynamic"/ I found that there should be a string input somewhere, to put the platform string like this: "arm-linux-gnueabihf" . But I got no such a string input there. Can anybody help me? I found that info here: https://trac.openmodelica.org/OpenModelica/ticket/3775

Thanks a lot

Ondrej

Re: Simulation Procedure

I haven't got any real answer here, but I can say that, using command line, you have few more settings.
As I wrote in the previous post you can format a .mos file that launches your FMU translation:

DarioMangoni wrote:

Code:

loadModel(Modelica);
loadFile("model.mo");
loadFile("model_dependency.mo");
buildModelFMU(model, version="2.0", fmuType="cs", platforms={"dynamic"}, includeResources=true);
getErrorString()

where in platforms={"dynamic"} you are actually implying "build a dynamic library for the current platform".

However, the OpenModelica User Guide says that you have multiple choices
The list of platforms to generate code for:
"dynamic"=current platform, dynamically link the runtime.
"static"=current platform, statically link everything.
Else, use a host triple, e.g. "x86_64-linux-gnu" or "x86_64-w64-mingw32".

I don't know if this can be of any help.
BTW, I'm not sure that they actually work  current/big_smile
For me it does not work the simple "static" option either.

Re: Simulation Procedure

Thanks DarioMangoni  for quick answer.

well maybe I know why there is no option like "arm-linux-gnueabih" or any other in the FMI export settings. The answer is maybe 'cause I got none of any other compiler installed on the current machine. The fact is that there is one computer with openmodelica  and the other computer with NI IDE for that CompactRio and I need to move the exported FMU to the other machine. Don't ask me why... The question is, How can I specify the path to the desired compiler... I'll try some experiments tomorrow and let you know.

Thanks a lot

Ondrej

Re: Simulation Procedure

Well, if things are working as they should, you just have to set the PATH environmental variable accordingly, so that it includes the path to the gcc*.

If you are on Linux something like this
https://stackoverflow.com/questions/146 … linux-unix

if you are on windows just go to My PC > Properties > Advanced System Settings > Environmental Variables...

However, looking for a path that ends with *cc seems to suggest that GCC compilers are the only choice*...

Re: Simulation Procedure

If you don't have an ARM compiler installed on your computer, the easy solution is to install the toolchain. On Ubuntu, "sudo apt install gcc-arm-linux-gnueabihf". The other alternative is to only export source-code (or static), and just send the FMU to the other machine. Then do:

unzip M.fmu -d M.fmutmp
cd M.fmutmp/sources
./configure CFLAGS=MYCFLAGS ETC=ETC
make -j4

This should overwrite the original FMU with an FMU that supports both machines. No OpenModelica necessary on the second machine.

Re: Simulation Procedure

sjoelund.se when and by whom is this configure file called?

thanks

Re: Simulation Procedure

The configure script is usually called when cross-compiling (on the machine generating the FMU) automatically by OMC. But if you don't have a cross-compilation toolchain, it would be done manually by the user who wants to compile the FMU on a different machine before trying to import the FMU in some other tool.

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