Skip to content

Commit 69a9be0

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 7e61a90 commit 69a9be0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

OMPython/ModelicaSystem.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ def __init__(
478478
if build:
479479
self.buildModel(variableFilter)
480480

481+
def session(self) -> OMCSessionZMQ:
482+
"""
483+
Return the OMC session used for this class.
484+
"""
485+
return self._getconn
486+
481487
def setCommandLineOptions(self, commandLineOptions: str):
482488
"""
483489
Set the provided command line option via OMC setCommandLineOptions().
@@ -1893,9 +1899,9 @@ def __init__(
18931899
self._timeout = timeout
18941900

18951901
if resultpath is not None:
1896-
self._resultpath = self._mod._getconn.omcpath(resultpath)
1902+
self._resultpath = self.session().omcpath(resultpath)
18971903
else:
1898-
self._resultpath = self._mod._getconn.omcpath_tempdir()
1904+
self._resultpath = self.session().omcpath_tempdir()
18991905

19001906
if not self._resultpath.is_dir():
19011907
raise ModelicaSystemError(f"Resultpath {self._resultpath.as_posix()} does not exists!")
@@ -1908,6 +1914,12 @@ def __init__(
19081914
self._sim_dict: Optional[dict[str, dict[str, Any]]] = None
19091915
self._sim_task_query: queue.Queue = queue.Queue()
19101916

1917+
def session(self) -> OMCSessionZMQ:
1918+
"""
1919+
Return the OMC session used for this class.
1920+
"""
1921+
return self._mod.session()
1922+
19111923
def prepare(self) -> int:
19121924
"""
19131925
Prepare the DoE by evaluating the parameters. Each structural parameter requires a new instance of
@@ -2049,7 +2061,7 @@ def worker(worker_id, task_queue):
20492061
raise ModelicaSystemError("Missing simulation definition!")
20502062

20512063
resultfile = mscmd.arg_get(key='r')
2052-
resultpath = self._mod._getconn.omcpath(resultfile)
2064+
resultpath = self.session().omcpath(resultfile)
20532065

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

0 commit comments

Comments
 (0)