1

A long time ago, I used JModelica/pymodelica to compile modelica models into FMUs, using a simple python script. Now I learn that JModelica is discontinued as an open-source project. (The libraries to run an FMU seems to have been branched out into new open-source projects, but I did not find the compiler.)

Is there an alternative which is up-to-date, open source, and equally simple?

The script I have from back when is the following, and I hope to find something which lets me update this to Python3 and continue where I left off so many years ago.

#! /local/opt/modelica/bin/jm_python.sh
# Import the compiler function
from pymodelica import compile_fmu

import optparse
parser = optparse.OptionParser()
(options,args) = parser.parse_args()

# Specify Modelica model and model file (.mo or .mop)
mo_file = args[0]
model_name = mo_file.split(".")[0]
print mo_file, model_name

# Compile the model and save the return argument, which is the file name of the FMU
my_fmu = compile_fmu(model_name, mo_file, target='cs')
George
  • 11
  • 3

1 Answers1

2

The only open-source alternative left is OpenModelica. Of course, JModelica is still there in some github forks but I'm unsure if is still updated and supported.

You could try to use OpenModelica and OMPython. https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/ompython.html

See also: https://www.openmodelica.org/forum/default-topic/3121-compile-cosimulation-fmu-via-ompython-api-call

I guess to generate an FMU it would go something like this:

from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
model_path=omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/"
from OMPython import ModelicaSystem
mod=ModelicaSystem(model_path + "BouncingBall.mo","BouncingBall")
ffmu = mod.convertMo2Fmu()
Adrian Pop
  • 4,034
  • 13
  • 16