Skip to content

Commit f4bb35e

Browse files
committed
[ModelicaSystem/ModelicaSystemDoE] improve session handling
* add ModelicaSystem.session() - returns _getconn * add ModelicaSystemDoE.session() - returns _mod.session() reasoning: * do not access private variables of a class * limit chain access to (sub)data
1 parent 7c56957 commit f4bb35e

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ def __init__(
439439
if build:
440440
self.buildModel(variableFilter)
441441

442+
def session(self) -> OMCSessionZMQ:
443+
"""
444+
Return the OMC session used for this class.
445+
"""
446+
return self._getconn
447+
442448
def setCommandLineOptions(self, commandLineOptions: str):
443449
"""
444450
Set the provided command line option via OMC setCommandLineOptions().
@@ -1858,9 +1864,9 @@ def __init__(
18581864
self._timeout = timeout
18591865

18601866
if resultpath is not None:
1861-
self._resultpath = self._mod._getconn.omcpath(resultpath)
1867+
self._resultpath = self.session().omcpath(resultpath)
18621868
else:
1863-
self._resultpath = self._mod._getconn.omcpath_tempdir()
1869+
self._resultpath = self.session().omcpath_tempdir()
18641870

18651871
if not self._resultpath.is_dir():
18661872
raise ModelicaSystemError(f"Resultpath {self._resultpath.as_posix()} does not exists!")
@@ -1873,6 +1879,12 @@ def __init__(
18731879
self._sim_dict: Optional[dict[str, dict[str, Any]]] = None
18741880
self._sim_task_query: queue.Queue = queue.Queue()
18751881

1882+
def session(self) -> OMCSessionZMQ:
1883+
"""
1884+
Return the OMC session used for this class.
1885+
"""
1886+
return self._mod.session()
1887+
18761888
def prepare(self) -> int:
18771889
"""
18781890
Prepare the DoE by evaluating the parameters. Each structural parameter requires a new instance of
@@ -2014,7 +2026,7 @@ def worker(worker_id, task_queue):
20142026
raise ModelicaSystemError("Missing simulation definition!")
20152027

20162028
resultfile = mscmd.arg_get(key='r')
2017-
resultpath = self._mod._getconn.omcpath(resultfile)
2029+
resultpath = self.session().omcpath(resultfile)
20182030

20192031
logger.info(f"[Worker {worker_id}] Performing task: {resultpath.name}")
20202032

0 commit comments

Comments
 (0)