Skip to content

Commit df3e39a

Browse files
committed
[ModelicaSystem] allow to modify default command line options
1 parent 63139e9 commit df3e39a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

OMPython/ModelicaSystem.py

Lines changed: 15 additions & 11 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,17 @@ 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 for linearization as
433+
# linearize() will use the simulation executable and runtime
434+
# flag -l to perform linearization
435+
commandLineOptions = [
436+
"--linearizationDumpLanguage=python",
437+
"--generateSymbolicLinearization",
438+
]
439+
for opt in commandLineOptions:
440+
self.setCommandLineOptions(commandLineOptions=opt)
431441

432442
if lmodel is None:
433443
lmodel = []
@@ -445,12 +455,6 @@ def __init__(
445455
if self._file_name is not None and not self._file_name.is_file(): # if file does not exist
446456
raise IOError(f"{self._file_name} does not exist!")
447457

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-
454458
self._work_dir: pathlib.Path = self.setWorkDirectory(customBuildDirectory)
455459

456460
if self._file_name is not None:

0 commit comments

Comments
 (0)