Recent Changes - Search:

edit SideBar

JModelica FMI

See JModelica for notes about building JModelica under Linux and Mac OS X.

This page is about how to use JModelica and FMUs.

To export a FMU from JModelica

/usr/local/jmodelica/bin/jm_python.sh <<EoF
from pymodelica import compile_fmu
model_name = 'AMS'
mo_file ='AMS.mo'
my_fmu =compile_fmu(model_name, mo_file, target='cs')
EoF

Problems

Split up by platform, sorted by most recent first.

Red Hat Enterprise Linux (RHEL) Problems

RHEL undefined reference to `_gfortran_transfer_integer_write'

3/5/2015 - While exporting a FMU ($PTII/ptolemy/actor/lib/fmi/fmus/jmodelica/CoupledClutches/CoupledClutches.mo), there are link problems:

[cxh@terra CoupledClutches]$ cat CoupledClutchesToFMU
#!/bin/sh
# $Id: AMSToFMU 69601 2014-07-30 13:51:01Z cxh $
# Export the AMS.mo model as a fmu using jmodelica

/usr/local/jmodelica/bin/jm_python.sh <<EoF
from pymodelica import compile_fmu

#className = 'Modelica.Mechanics.Rotational.Examples.CoupledClutches'
#my_fmu = compile_fmu(className, target='me')

# Add compiler_log_level='i' to the compile_fmu line to get the link command.
my_fmu = compile_fmu('CoupledClutches', 'CoupledClutches.mo', target='me+cs', version='2.0')
EoF
[cxh@terra CoupledClutches]$ ./CoupledClutchesToFMU
/usr/local/jmodelica/lib/RuntimeLibrary/liblapack.a(dlamch.f.o): In function `dlamc2_':
dlamch.f:(.text+0x136d): undefined reference to `_gfortran_transfer_integer_write'
/usr/local/jmodelica/lib/RuntimeLibrary/libblas.a(xerbla.f.o): In function `xerbla_':
xerbla.f:(.text+0x5c): undefined reference to `_gfortran_transfer_character_write'
xerbla.f:(.text+0x6c): undefined reference to `_gfortran_transfer_integer_write'
collect2: ld returned 1 exit status
make[1]: *** [fmucs20_] Error 1
make: *** [fmumecs20] Error 2
Unknown program error, org.jmodelica.util.exceptions.CcodeCompilationException: Compilation of generated C code failed.
C file location: /tmp/jmc1114508314399726359out/sources/CoupledClutches.c
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
File "/usr/local/jmodelica/Python/pymodelica/compiler.py", line 150, in compile_fmu
separate_process, jvm_args)
File "/usr/local/jmodelica/Python/pymodelica/compiler.py", line 354, in _compile_unit
compiler_options, compile_to, compiler_log_level, jvm_args)
File "/usr/local/jmodelica/Python/pymodelica/compiler.py", line 473, in compile_separate_process
return log.end();
File "/usr/local/jmodelica/Python/pymodelica/compiler_logging.py", line 323, in end
raise CcodeCompilationError(exception.message)
pymodelica.compiler_exceptions.CcodeCompilationError: Compilation of generated C code failed.
C file location: /tmp/jmc1114508314399726359out/sources/CoupledClutches.c
[cxh@terra CoupledClutches]$

The missing symbol is in a static library:

[cxh@terra CoupledClutches]$ nm /usr/local/jmodelica/lib/RuntimeLibrary/liblapack.a | grep gfortran_transfer
U _gfortran_transfer_integer_write

Here a similar post: http://www.jmodelica.org/9163

However, that solution did not work.

To debug FMU Generation, edit the CoupledClutchesToFMU script and Add compiler_log_level='i' to the compile_fmu line to get the link command

  my_fmu = compile_fmu('CoupledClutches', 'CoupledClutches.mo', target='me+cs', version='2.0', compiler_log_level='i') 

I tried poking around with the link command and added -Wl,--verbose and adding -lgfortran to the end.

Solution: Use gcc-4.9.2:

  export PATH=/usr/local/gcc-4.9.2/bin:${PATH}

Then CoupledClutchesToFMU worked. Perhaps this is because JModelica was built with gcc-4.9.2

Mac OS X Problems

No Mac-specific problems yet!

Platform Independent Problems

Problem: Invalid fmuResourceLocation

What is happening here is that JModelica/RuntimeLibrary/src/fmi2/fmi2_me.c has a method called uri_to_path() that seems to require resources to start with file:///

p. 19 of the "Functional Mock-up Interface 2.0" from July 25, 2014 says:

"Argument fmuResourceLocation is an URI according to the IETF RFC3986 syntax to indicate the location to the “resources” directory of the unzipped FMU archive. The following schemes must be understood by the FMU:"
  • Mandatory: “file” with absolute path (either including or omitting the authority component)
  • Optional: “http”, “https”, “ftp”
  • Reserved: “fmi2” for FMI for PLM.
"[Example: An FMU is unzipped in directory “C:\temp\MyFMU”, then fmuResourceLocation = "file:///C:/temp/MyFMU resources" or "file:/C:/temp/MyFMU/resources". Function fmi2Instantiate is then able to read all needed resources from this directory, for example maps or tables used by the FMU.]"

The change in the JModelica source is https://trac.jmodelica.org/changeset/6192/trunk/RuntimeLibrary/src/fmi2/fmi2_me.c

"2014-04-08 09:57:26 (11 months ago)"
"Author: jkampe"
Message: #2814 Finding Resource folder from FMU. An implementation of loadResource() as a built-in. Copies used resources to fmu and locates them in runtime."

There was an issue on the fmi-standard site: Mandatory file:// should be changed to file:/ for fmuResourceLocation

My solution was to edit JModelica/RuntimeLibrary/src/fmi2/fmi2_me.c

+++ /Users/cxh/src/JModelica/RuntimeLibrary/src/fmi2/fmi2_me.c (working copy)
@@ -767,25 +767,31 @@

/* Local helper for fmi2_me_instantiate. */
int uri_to_path(char *path, const char* uri) {
- char* scheme = "file://";
+ char* scheme = "file:";
Edit - History - Print - Recent Changes - Search
Page last modified on March 05, 2015, at 07:35 pm