Skip to content

Commit a686554

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 b3649ff commit a686554

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().
@@ -1872,9 +1878,9 @@ def __init__(
18721878
self._timeout = timeout
18731879

18741880
if resultpath is not None:
1875-
self._resultpath = self._mod._getconn.omcpath(resultpath)
1881+
self._resultpath = self.session().omcpath(resultpath)
18761882
else:
1877-
self._resultpath = self._mod._getconn.omcpath_tempdir()
1883+
self._resultpath = self.session().omcpath_tempdir()
18781884

18791885
if not self._resultpath.is_dir():
18801886
raise ModelicaSystemError(f"Resultpath {self._resultpath.as_posix()} does not exists!")
@@ -1887,6 +1893,12 @@ def __init__(
18871893
self._sim_dict: Optional[dict[str, dict[str, Any]]] = None
18881894
self._sim_task_query: queue.Queue = queue.Queue()
18891895

1896+
def session(self) -> OMCSessionZMQ:
1897+
"""
1898+
Return the OMC session used for this class.
1899+
"""
1900+
return self._mod.session()
1901+
18901902
def prepare(self) -> int:
18911903
"""
18921904
Prepare the DoE by evaluating the parameters. Each structural parameter requires a new instance of
@@ -2028,7 +2040,7 @@ def worker(worker_id, task_queue):
20282040
raise ModelicaSystemError("Missing simulation definition!")
20292041

20302042
resultfile = mscmd.arg_get(key='r')
2031-
resultpath = self._mod._getconn.omcpath(resultfile)
2043+
resultpath = self.session().omcpath(resultfile)
20322044

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

0 commit comments

Comments
 (0)