Skip to content

Commit ad91868

Browse files
authored
[ModelicaSystem] allow to modify default command line options (#349)
* [ModelicaSystem] allow to modify default command line options * [ModelicaSystem] update setCommandLineOptions() * [ModelicaSystem] improve comment
1 parent 382b006 commit ad91868

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

OMPython/ModelicaSystem.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def __init__(
352352
fileName: Optional[str | os.PathLike | pathlib.Path] = None,
353353
modelName: Optional[str] = None,
354354
lmodel: Optional[list[str | tuple[str, str]]] = None,
355-
commandLineOptions: Optional[str] = None,
355+
commandLineOptions: Optional[list[str]] = None,
356356
variableFilter: Optional[str] = None,
357357
customBuildDirectory: Optional[str | os.PathLike] = None,
358358
omhome: Optional[str] = None,
@@ -374,8 +374,9 @@ def __init__(
374374
lmodel=["Modelica"] for just the library name
375375
and lmodel=[("Modelica","3.2.3")] for specifying both the name
376376
and the version.
377-
commandLineOptions: String with extra command line options to be
378-
provided to omc via setCommandLineOptions().
377+
commandLineOptions: List with extra command line options as elements. The list elements are
378+
provided to omc via setCommandLineOptions(). If set, the default values will be overridden.
379+
To disable any command line options, use an empty list.
379380
variableFilter: A regular expression. Only variables fully
380381
matching the regexp will be stored in the result file.
381382
Leaving it unspecified is equivalent to ".*".
@@ -426,8 +427,16 @@ def __init__(
426427
else:
427428
self._getconn = OMCSessionZMQ(omhome=omhome)
428429

429-
# set commandLineOptions if provided by users
430-
self.setCommandLineOptions(commandLineOptions=commandLineOptions)
430+
# set commandLineOptions using default values or the user defined list
431+
if commandLineOptions is None:
432+
# set default command line options to improve the performance of linearization and to avoid recompilation if
433+
# the simulation executable is reused in linearize() via the runtime flag '-l'
434+
commandLineOptions = [
435+
"--linearizationDumpLanguage=python",
436+
"--generateSymbolicLinearization",
437+
]
438+
for opt in commandLineOptions:
439+
self.setCommandLineOptions(commandLineOptions=opt)
431440

432441
if lmodel is None:
433442
lmodel = []
@@ -445,12 +454,6 @@ def __init__(
445454
if self._file_name is not None and not self._file_name.is_file(): # if file does not exist
446455
raise IOError(f"{self._file_name} does not exist!")
447456

448-
# set default command Line Options for linearization as
449-
# linearize() will use the simulation executable and runtime
450-
# flag -l to perform linearization
451-
self.setCommandLineOptions("--linearizationDumpLanguage=python")
452-
self.setCommandLineOptions("--generateSymbolicLinearization")
453-
454457
self._work_dir: pathlib.Path = self.setWorkDirectory(customBuildDirectory)
455458

456459
if self._file_name is not None:
@@ -464,10 +467,10 @@ def __init__(
464467
if build:
465468
self.buildModel(variableFilter)
466469

467-
def setCommandLineOptions(self, commandLineOptions: Optional[str] = None):
468-
# set commandLineOptions if provided by users
469-
if commandLineOptions is None:
470-
return
470+
def setCommandLineOptions(self, commandLineOptions: str):
471+
"""
472+
Set the provided command line option via OMC setCommandLineOptions().
473+
"""
471474
exp = f'setCommandLineOptions("{commandLineOptions}")'
472475
self.sendExpression(exp)
473476

0 commit comments

Comments
 (0)