1

In JModelica I want to create models using components from multiple existing libraries.

This means that it would be very useful to add the multiple libraries to the MODELICAPATH so components can be referenced without changing their existing paths. Something similar seems possible in Dymola.

In JModelica 1.13 it seems that this was once possible using:

c_opts =
    {'extra_lib_dirs':['c:\MyLibs1','c:\MyLibs2']}

compile_fmu(class_path, compiler_options=c_opts)

I have read through the JModelica 2.1 document and there seems to be no mention of this argument. I have also tried running the script above and the compiler is not able to locate the path of the model contained within a library listed in the options.

Adding libraries to the Third Party MSL Folder inside the JModelica installation is not an option, as the multiple libraries I'll be working with are GitHub repos.

Is it possible to add these multiple libraries to the MODELICAPATH via startup script or IPython code?

alkey
  • 986
  • 4
  • 16
  • 33

2 Answers2

2

The option "extra_lib_dirs" has been removed in favour of the simpler interface:

from pymodelica import compile_fmu

name = compile_fmu("MyModel", ["MyModelicaFile.mo", "C:\My\Modelica\Lib", ...])

The list after the model is specificed can take any number of Modelica files or directories to where Modelica libraries are located.

Christian Winther
  • 1,113
  • 1
  • 9
  • 17
1

Yes, JModelica.org looks at the environment variable MODELICAPATH for additional locations of Modelica libraries (as per the Modelica language specification, section 13.2.4).

Either you modify the variable in batch before starting JModelica.org, or you modify the environment inside Python:

import os
os.environ['MODELICAPATH'] = "C:/somePath/;" + os.environ['JMODELICA_HOME'] + "/ThirdParty/MSL"
from pymodelica import compile_fmu
compile_fmu("SomeLibrary.SomeModel")

Note, if you're going to compile models from MSL or models using parts of MSL, then you have to add the MSL folder from the JModelica.org installation to the MODELICAPATH as well. The reason for this is that we are overriding the default MODELICAPATH and JModelica.org uses MODELICAPATH to find MSL.

I might add that it is more efficient to add the library folders to MODELICAPATH than listing them in the compile_fmu command. The reason for this is that if you list them to the compile_fmu command, then all the libraries will be parsed, while, if you add them (or rather the parent folder) to MODELICAPATH, then they are loaded as needed.

Jon S
  • 15,846
  • 4
  • 44
  • 45