diff --git a/OMPython/ModelicaSystem.py b/OMPython/ModelicaSystem.py index 7acc372d..59efe177 100644 --- a/OMPython/ModelicaSystem.py +++ b/OMPython/ModelicaSystem.py @@ -22,7 +22,6 @@ from OMPython.OMCSession import ( OMCSessionException, OMCSessionRunData, - OMCSessionZMQ, OMCSession, OMCSessionLocal, OMCPath, @@ -98,7 +97,7 @@ class ModelicaSystemCmd: def __init__( self, - session: OMCSessionZMQ, + session: OMCSession, runpath: OMCPath, modelname: Optional[str] = None, ) -> None: @@ -296,7 +295,7 @@ def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, Any] | n class ModelicaSystem: """ - Class to simulate a Modelica model using OpenModelica via OMCSessionZMQ. + Class to simulate a Modelica model using OpenModelica via OMCSession. """ def __init__( @@ -315,7 +314,7 @@ def __init__( work_directory: Path to a directory to be used for temporary files like the model executable. If left unspecified, a tmp directory will be created. - omhome: path to OMC to be used when creating the OMC session (see OMCSessionZMQ). + omhome: path to OMC to be used when creating the OMC session (see OMCSession). session: definition of a (local) OMC session to be used. If unspecified, a new local session will be created. """ @@ -345,9 +344,9 @@ def __init__( self._linearized_states: list[str] = [] # linearization states list if session is not None: - self._session = OMCSessionZMQ(omc_process=session) + self._session = session else: - self._session = OMCSessionZMQ(omhome=omhome) + self._session = OMCSessionLocal(omhome=omhome) # set commandLineOptions using default values or the user defined list if command_line_options is None: @@ -432,13 +431,13 @@ def model( if model_file is not None: file_path = pathlib.Path(model_file) # special handling for OMCProcessLocal - consider a relative path - if isinstance(self._session.omc_process, OMCSessionLocal) and not file_path.is_absolute(): + if isinstance(self._session, OMCSessionLocal) and not file_path.is_absolute(): file_path = pathlib.Path.cwd() / file_path if not file_path.is_file(): raise IOError(f"Model file {file_path} does not exist!") self._file_name = self.getWorkDirectory() / file_path.name - if (isinstance(self._session.omc_process, OMCSessionLocal) + if (isinstance(self._session, OMCSessionLocal) and file_path.as_posix() == self._file_name.as_posix()): pass elif self._file_name.is_file(): @@ -453,7 +452,7 @@ def model( if build: self.buildModel(variable_filter) - def get_session(self) -> OMCSessionZMQ: + def get_session(self) -> OMCSession: """ Return the OMC session used for this class. """ @@ -1168,7 +1167,7 @@ def plot( plot is created by OMC which needs access to the local display. This is not the case for docker and WSL. """ - if not isinstance(self._session.omc_process, OMCSessionLocal): + if not isinstance(self._session, OMCSessionLocal): raise ModelicaSystemError("Plot is using the OMC plot functionality; " "thus, it is only working if OMC is running locally!") @@ -1974,7 +1973,7 @@ def __init__( self._doe_def: Optional[dict[str, dict[str, Any]]] = None self._doe_cmd: Optional[dict[str, OMCSessionRunData]] = None - def get_session(self) -> OMCSessionZMQ: + def get_session(self) -> OMCSession: """ Return the OMC session used for this class. """ diff --git a/OMPython/OMCSession.py b/OMPython/OMCSession.py index 70fd644e..861f2a3a 100644 --- a/OMPython/OMCSession.py +++ b/OMPython/OMCSession.py @@ -70,9 +70,9 @@ class OMCSessionCmd: Implementation of Open Modelica Compiler API functions. Depreciated! """ - def __init__(self, session: OMCSessionZMQ, readonly: bool = False): - if not isinstance(session, OMCSessionZMQ): - raise OMCSessionException("Invalid session definition!") + def __init__(self, session: OMCSession, readonly: bool = False): + if not isinstance(session, OMCSession): + raise OMCSessionException("Invalid OMC process definition!") self._session = session self._readonly = readonly self._omc_cache: dict[tuple[str, bool], Any] = {} diff --git a/tests/test_OMSessionCmd.py b/tests/test_OMSessionCmd.py index 2de03a5a..bff4afde 100644 --- a/tests/test_OMSessionCmd.py +++ b/tests/test_OMSessionCmd.py @@ -3,7 +3,7 @@ def test_isPackage(): omczmq = OMPython.OMCSessionZMQ() - omccmd = OMPython.OMCSessionCmd(session=omczmq) + omccmd = OMPython.OMCSessionCmd(session=omczmq.omc_process) assert not omccmd.isPackage('Modelica')