Skip to content

Commit ad91629

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 be9842a commit ad91629

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

443+
def session(self) -> OMCSessionZMQ:
444+
"""
445+
Return the OMC session used for this class.
446+
"""
447+
return self._getconn
448+
443449
def setCommandLineOptions(self, commandLineOptions: str):
444450
"""
445451
Set the provided command line option via OMC setCommandLineOptions().
@@ -1909,9 +1915,9 @@ def __init__(
19091915
self._timeout = timeout
19101916

19111917
if resultpath is not None:
1912-
self._resultpath = self._mod._getconn.omcpath(resultpath)
1918+
self._resultpath = self.session().omcpath(resultpath)
19131919
else:
1914-
self._resultpath = self._mod._getconn.omcpath_tempdir()
1920+
self._resultpath = self.session().omcpath_tempdir()
19151921

19161922
if not self._resultpath.is_dir():
19171923
raise ModelicaSystemError(f"Resultpath {self._resultpath.as_posix()} does not exists!")
@@ -1924,6 +1930,12 @@ def __init__(
19241930
self._sim_dict: Optional[dict[str, dict[str, Any]]] = None
19251931
self._sim_task_query: queue.Queue = queue.Queue()
19261932

1933+
def session(self) -> OMCSessionZMQ:
1934+
"""
1935+
Return the OMC session used for this class.
1936+
"""
1937+
return self._mod.session()
1938+
19271939
def prepare(self) -> int:
19281940
"""
19291941
Prepare the DoE by evaluating the parameters. Each structural parameter requires a new instance of
@@ -2065,7 +2077,7 @@ def worker(worker_id, task_queue):
20652077
raise ModelicaSystemError("Missing simulation definition!")
20662078

20672079
resultfile = mscmd.arg_get(key='r')
2068-
resultpath = self._mod._getconn.omcpath(resultfile)
2080+
resultpath = self.session().omcpath(resultfile)
20692081

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

0 commit comments

Comments
 (0)