Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions OMPython/ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
OMCSessionException,
OMCSession,
OMCSessionLocal,
OMCPath,

OMPathABC,
)

# define logger using the current module name as ID
Expand Down Expand Up @@ -387,13 +388,13 @@ def __init__(
self._version = self._parse_om_version(version=version_str)

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

self._work_dir: OMCPath = self.setWorkDirectory(work_directory)
self._work_dir: OMPathABC = self.setWorkDirectory(work_directory)

self._model_name: Optional[str] = None
self._libraries: Optional[list[str | tuple[str, str]]] = None
self._file_name: Optional[OMCPath] = None
self._file_name: Optional[OMPathABC] = None
self._variable_filter: Optional[str] = None

def get_session(self) -> OMCSession:
Expand All @@ -411,7 +412,7 @@ def get_model_name(self) -> str:

return self._model_name

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

def getWorkDirectory(self) -> OMCPath:
def getWorkDirectory(self) -> OMPathABC:
"""
Return the defined working directory for this ModelicaSystem / OpenModelica session.
"""
Expand All @@ -458,7 +459,7 @@ def check_model_executable(self):
if returncode != 0:
raise ModelicaSystemError("Model executable not working!")

def _xmlparse(self, xml_file: OMCPath):
def _xmlparse(self, xml_file: OMPathABC):
if not xml_file.is_file():
raise ModelicaSystemError(f"XML file not generated: {xml_file}")

Expand Down Expand Up @@ -832,7 +833,7 @@ def _parse_om_version(version: str) -> tuple[int, int, int]:
def _process_override_data(
self,
om_cmd: ModelExecutionCmd,
override_file: OMCPath,
override_file: OMPathABC,
override_var: dict[str, str],
override_sim: dict[str, str],
) -> None:
Expand Down Expand Up @@ -868,7 +869,7 @@ def _process_override_data(

def simulate_cmd(
self,
result_file: OMCPath,
result_file: OMPathABC,
simflags: Optional[str] = None,
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
) -> ModelExecutionCmd:
Expand Down Expand Up @@ -966,14 +967,14 @@ def simulate(
if resultfile is None:
# default result file generated by OM
self._result_file = self.getWorkDirectory() / f"{self._model_name}_res.mat"
elif isinstance(resultfile, OMCPath):
elif isinstance(resultfile, OMPathABC):
self._result_file = resultfile
else:
self._result_file = self._session.omcpath(resultfile)
if not self._result_file.is_absolute():
self._result_file = self.getWorkDirectory() / resultfile

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

om_cmd = self.simulate_cmd(
Expand Down Expand Up @@ -1298,7 +1299,7 @@ def setInputs(

return True

def _createCSVData(self, csvfile: Optional[OMCPath] = None) -> OMCPath:
def _createCSVData(self, csvfile: Optional[OMPathABC] = None) -> OMPathABC:
"""
Create a csv file with inputs for the simulation/optimization of the model. If csvfile is provided as argument,
this file is used; else a generic file name is created.
Expand Down Expand Up @@ -1626,7 +1627,7 @@ def set_command_line_options(self, command_line_option: str):
expr = f'setCommandLineOptions("{command_line_option}")'
self.sendExpression(expr=expr, parsed=False)

def _loadFile(self, fileName: OMCPath):
def _loadFile(self, fileName: OMPathABC):
# load file
self.sendExpression(expr=f'loadFile("{fileName.as_posix()}")')

Expand Down Expand Up @@ -2007,7 +2008,7 @@ def convertMo2Fmu(
fmuType: str = "me_cs",
fileNamePrefix: Optional[str] = None,
includeResources: bool = True,
) -> OMCPath:
) -> OMPathABC:
"""Translate the model into a Functional Mockup Unit.

Args:
Expand Down Expand Up @@ -2046,7 +2047,7 @@ def convertMo2Fmu(
def convertFmu2Mo(
self,
fmu: os.PathLike,
) -> OMCPath:
) -> OMPathABC:
"""
In order to load FMU, at first it needs to be translated into Modelica model. This method is used to generate
Modelica model from the given FMU. It generates "fmuName_me_FMU.mo".
Expand Down Expand Up @@ -2513,7 +2514,7 @@ def get_doe_solutions(

def doe_get_solutions(
msomc: ModelicaSystemOMC,
resultpath: OMCPath,
resultpath: OMPathABC,
doe_def: Optional[dict] = None,
var_list: Optional[list] = None,
) -> Optional[tuple[str] | dict[str, dict[str, np.ndarray]]]:
Expand Down
Loading
Loading