Skip to content

Commit 81ce0a5

Browse files
committed
[ModelicaSystem*] fix definitions of *Base and *OMC
1 parent ae413fb commit 81ce0a5

File tree

1 file changed

+44
-22
lines changed

1 file changed

+44
-22
lines changed

OMPython/ModelicaSystem.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,20 @@ def __getitem__(self, index: int):
9090

9191
class ModelicaSystemBase:
9292
"""
93-
Class to simulate a Modelica model using OpenModelica via OMCSession.
93+
Base class to simulate a Modelica models.
9494
"""
9595

9696
def __init__(
9797
self,
98-
command_line_options: Optional[list[str]] = None,
98+
session: OMCSession,
9999
work_directory: Optional[str | os.PathLike] = None,
100-
omhome: Optional[str] = None,
101-
session: Optional[OMCSession] = None,
102100
) -> None:
103101
"""Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo().
104102
105103
Args:
106-
command_line_options: List with extra command line options as elements. The list elements are
107-
provided to omc via setCommandLineOptions(). If set, the default values will be overridden.
108-
To disable any command line options, use an empty list.
109104
work_directory: Path to a directory to be used for temporary
110105
files like the model executable. If left unspecified, a tmp
111106
directory will be created.
112-
omhome: path to OMC to be used when creating the OMC session (see OMCSession).
113107
session: definition of a (local) OMC session to be used. If
114108
unspecified, a new local session will be created.
115109
"""
@@ -135,23 +129,10 @@ def __init__(
135129
self._linearized_outputs: list[str] = [] # linearization output list
136130
self._linearized_states: list[str] = [] # linearization states list
137131

138-
if session is not None:
139-
self._session = session
140-
else:
141-
self._session = OMCSessionLocal(omhome=omhome)
132+
self._session = session
142133

143134
# get OpenModelica version
144135
self._version = self._session.get_version()
145-
# set commandLineOptions using default values or the user defined list
146-
if command_line_options is None:
147-
# set default command line options to improve the performance of linearization and to avoid recompilation if
148-
# the simulation executable is reused in linearize() via the runtime flag '-l'
149-
command_line_options = [
150-
"--linearizationDumpLanguage=python",
151-
"--generateSymbolicLinearization",
152-
]
153-
for opt in command_line_options:
154-
self.set_command_line_options(command_line_option=opt)
155136

156137
self._simulated = False # True if the model has already been simulated
157138
self._result_file: Optional[OMCPath] = None # for storing result file
@@ -1243,8 +1224,49 @@ def getLinearStates(self) -> list[str]:
12431224

12441225

12451226
class ModelicaSystemOMC(ModelicaSystemBase):
1227+
"""
1228+
Class to simulate a Modelica model using OpenModelica via OMCSession.
1229+
"""
12461230

1231+
def __init__(
1232+
self,
1233+
command_line_options: Optional[list[str]] = None,
1234+
work_directory: Optional[str | os.PathLike] = None,
1235+
omhome: Optional[str] = None,
1236+
session: Optional[OMCSession] = None,
1237+
) -> None:
1238+
"""Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo().
1239+
1240+
Args:
1241+
command_line_options: List with extra command line options as elements. The list elements are
1242+
provided to omc via setCommandLineOptions(). If set, the default values will be overridden.
1243+
To disable any command line options, use an empty list.
1244+
work_directory: Path to a directory to be used for temporary
1245+
files like the model executable. If left unspecified, a tmp
1246+
directory will be created.
1247+
omhome: path to OMC to be used when creating the OMC session (see OMCSession).
1248+
session: definition of a (local) OMC session to be used. If
1249+
unspecified, a new local session will be created.
1250+
"""
12471251

1252+
if session is None:
1253+
session = OMCSessionLocal(omhome=omhome)
1254+
1255+
super().__init__(
1256+
session=session,
1257+
work_directory=work_directory,
1258+
)
1259+
1260+
# set commandLineOptions using default values or the user defined list
1261+
if command_line_options is None:
1262+
# set default command line options to improve the performance of linearization and to avoid recompilation if
1263+
# the simulation executable is reused in linearize() via the runtime flag '-l'
1264+
command_line_options = [
1265+
"--linearizationDumpLanguage=python",
1266+
"--generateSymbolicLinearization",
1267+
]
1268+
for opt in command_line_options:
1269+
self.set_command_line_options(command_line_option=opt)
12481270

12491271
def model(
12501272
self,

0 commit comments

Comments
 (0)