Skip to content

Commit 3f9294e

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 135bc61 commit 3f9294e

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
@@ -442,6 +442,12 @@ def __init__(
442442
if build:
443443
self.buildModel(variableFilter)
444444

445+
def session(self) -> OMCSessionZMQ:
446+
"""
447+
Return the OMC session used for this class.
448+
"""
449+
return self._getconn
450+
445451
def setCommandLineOptions(self, commandLineOptions: str):
446452
"""
447453
Set the provided command line option via OMC setCommandLineOptions().
@@ -1861,9 +1867,9 @@ def __init__(
18611867
self._timeout = timeout
18621868

18631869
if resultpath is not None:
1864-
self._resultpath = self._mod._getconn.omcpath(resultpath)
1870+
self._resultpath = self.session().omcpath(resultpath)
18651871
else:
1866-
self._resultpath = self._mod._getconn.omcpath_tempdir()
1872+
self._resultpath = self.session().omcpath_tempdir()
18671873

18681874
if not self._resultpath.is_dir():
18691875
raise ModelicaSystemError(f"Resultpath {self._resultpath.as_posix()} does not exists!")
@@ -1876,6 +1882,12 @@ def __init__(
18761882
self._sim_dict: Optional[dict[str, dict[str, Any]]] = None
18771883
self._sim_task_query: queue.Queue = queue.Queue()
18781884

1885+
def session(self) -> OMCSessionZMQ:
1886+
"""
1887+
Return the OMC session used for this class.
1888+
"""
1889+
return self._mod.session()
1890+
18791891
def prepare(self) -> int:
18801892
"""
18811893
Prepare the DoE by evaluating the parameters. Each structural parameter requires a new instance of
@@ -2017,7 +2029,7 @@ def worker(worker_id, task_queue):
20172029
raise ModelicaSystemError("Missing simulation definition!")
20182030

20192031
resultfile = mscmd.arg_get(key='r')
2020-
resultpath = self._mod._getconn.omcpath(resultfile)
2032+
resultpath = self.session().omcpath(resultfile)
20212033

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

0 commit comments

Comments
 (0)