Skip to content

Commit 571ce75

Browse files
committed
[ModelicaSystem] fix usage of OMCPath; replace by OMPathABC
1 parent 3f48c24 commit 571ce75

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
OMPathABC,
3333
)
3434

35-
OMCPath = OMPathABC
36-
3735
# define logger using the current module name as ID
3836
logger = logging.getLogger(__name__)
3937

@@ -389,13 +387,13 @@ def __init__(
389387
self._version = self._session.get_version()
390388

391389
self._simulated = False # True if the model has already been simulated
392-
self._result_file: Optional[OMCPath] = None # for storing result file
390+
self._result_file: Optional[OMPathABC] = None # for storing result file
393391

394-
self._work_dir: OMCPath = self.setWorkDirectory(work_directory)
392+
self._work_dir: OMPathABC = self.setWorkDirectory(work_directory)
395393

396394
self._model_name: Optional[str] = None
397395
self._libraries: Optional[list[str | tuple[str, str]]] = None
398-
self._file_name: Optional[OMCPath] = None
396+
self._file_name: Optional[OMPathABC] = None
399397
self._variable_filter: Optional[str] = None
400398

401399
def get_session(self) -> OMCSession:
@@ -413,7 +411,7 @@ def get_model_name(self) -> str:
413411

414412
return self._model_name
415413

416-
def setWorkDirectory(self, work_directory: Optional[str | os.PathLike] = None) -> OMCPath:
414+
def setWorkDirectory(self, work_directory: Optional[str | os.PathLike] = None) -> OMPathABC:
417415
"""
418416
Define the work directory for the ModelicaSystem / OpenModelica session. The model is build within this
419417
directory. If no directory is defined a unique temporary directory is created.
@@ -435,7 +433,7 @@ def setWorkDirectory(self, work_directory: Optional[str | os.PathLike] = None) -
435433
# ... and also return the defined path
436434
return workdir
437435

438-
def getWorkDirectory(self) -> OMCPath:
436+
def getWorkDirectory(self) -> OMPathABC:
439437
"""
440438
Return the defined working directory for this ModelicaSystem / OpenModelica session.
441439
"""
@@ -460,7 +458,7 @@ def check_model_executable(self):
460458
if returncode != 0:
461459
raise ModelicaSystemError("Model executable not working!")
462460

463-
def _xmlparse(self, xml_file: OMCPath):
461+
def _xmlparse(self, xml_file: OMPathABC):
464462
if not xml_file.is_file():
465463
raise ModelicaSystemError(f"XML file not generated: {xml_file}")
466464

@@ -834,7 +832,7 @@ def parse_om_version(version: str) -> tuple[int, int, int]:
834832

835833
def simulate_cmd(
836834
self,
837-
result_file: OMCPath,
835+
result_file: OMPathABC,
838836
simflags: Optional[str] = None,
839837
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
840838
) -> ModelExecutionCmd:
@@ -949,14 +947,14 @@ def simulate(
949947
if resultfile is None:
950948
# default result file generated by OM
951949
self._result_file = self.getWorkDirectory() / f"{self._model_name}_res.mat"
952-
elif isinstance(resultfile, OMCPath):
950+
elif isinstance(resultfile, OMPathABC):
953951
self._result_file = resultfile
954952
else:
955953
self._result_file = self._session.omcpath(resultfile)
956954
if not self._result_file.is_absolute():
957955
self._result_file = self.getWorkDirectory() / resultfile
958956

959-
if not isinstance(self._result_file, OMCPath):
957+
if not isinstance(self._result_file, OMPathABC):
960958
raise ModelicaSystemError(f"Invalid result file path: {self._result_file} - must be an OMCPath object!")
961959

962960
om_cmd = self.simulate_cmd(
@@ -1281,7 +1279,7 @@ def setInputs(
12811279

12821280
return True
12831281

1284-
def _createCSVData(self, csvfile: Optional[OMCPath] = None) -> OMCPath:
1282+
def _createCSVData(self, csvfile: Optional[OMPathABC] = None) -> OMPathABC:
12851283
"""
12861284
Create a csv file with inputs for the simulation/optimization of the model. If csvfile is provided as argument,
12871285
this file is used; else a generic file name is created.
@@ -1616,7 +1614,7 @@ def set_command_line_options(self, command_line_option: str):
16161614
exp = f'setCommandLineOptions("{command_line_option}")'
16171615
self.sendExpression(exp)
16181616

1619-
def _loadFile(self, fileName: OMCPath):
1617+
def _loadFile(self, fileName: OMPathABC):
16201618
# load file
16211619
self.sendExpression(f'loadFile("{fileName.as_posix()}")')
16221620

@@ -1997,7 +1995,7 @@ def convertMo2Fmu(
19971995
fmuType: str = "me_cs",
19981996
fileNamePrefix: Optional[str] = None,
19991997
includeResources: bool = True,
2000-
) -> OMCPath:
1998+
) -> OMPathABC:
20011999
"""Translate the model into a Functional Mockup Unit.
20022000
20032001
Args:
@@ -2036,7 +2034,7 @@ def convertMo2Fmu(
20362034
def convertFmu2Mo(
20372035
self,
20382036
fmu: os.PathLike,
2039-
) -> OMCPath:
2037+
) -> OMPathABC:
20402038
"""
20412039
In order to load FMU, at first it needs to be translated into Modelica model. This method is used to generate
20422040
Modelica model from the given FMU. It generates "fmuName_me_FMU.mo".
@@ -2503,7 +2501,7 @@ def get_doe_solutions(
25032501

25042502
def doe_get_solutions(
25052503
msomc: ModelicaSystemOMC,
2506-
resultpath: OMCPath,
2504+
resultpath: OMPathABC,
25072505
doe_def: Optional[dict] = None,
25082506
var_list: Optional[list] = None,
25092507
) -> Optional[tuple[str] | dict[str, dict[str, np.ndarray]]]:

0 commit comments

Comments
 (0)