Skip to content

Commit 71616b0

Browse files
committed
[ModelicaSystemDoE] update variable handling / remove variables not needed
1 parent 4acf74a commit 71616b0

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

OMPython/ModelicaSystem.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,52 +1725,52 @@ def run_doe():
17251725

17261726
def __init__(
17271727
self,
1728-
fileName: Optional[str | os.PathLike | pathlib.Path] = None,
1728+
# data to be used for ModelicaSystem
1729+
fileName: Optional[str | os.PathLike] = None,
17291730
modelName: Optional[str] = None,
17301731
lmodel: Optional[list[str | tuple[str, str]]] = None,
17311732
commandLineOptions: Optional[str] = None,
17321733
variableFilter: Optional[str] = None,
1733-
customBuildDirectory: Optional[str | os.PathLike | pathlib.Path] = None,
1734+
customBuildDirectory: Optional[str | os.PathLike] = None,
17341735
omhome: Optional[str] = None,
1735-
1736-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1736+
omc_process: Optional[OMCProcessLocal] = None, # TODO: use omc session
1737+
# simulation specific input
1738+
# TODO: add more settings (simulation options, input options, ...)
1739+
simargs: Optional[dict[str, Optional[str | dict[str, Any]]]] = None,
17371740
timeout: Optional[int] = None,
1738-
1739-
resultpath: Optional[pathlib.Path] = None,
1741+
# DoE specific inputs
1742+
resultpath: Optional[str | os.PathLike] = None,
17401743
parameters: Optional[dict[str, list[str] | list[int] | list[float]]] = None,
17411744
) -> None:
17421745
"""
17431746
Initialisation of ModelicaSystemDoE. The parameters are based on: ModelicaSystem.__init__() and
17441747
ModelicaSystem.simulate(). Additionally, the path to store the result files is needed (= resultpath) as well as
17451748
a list of parameters to vary for the Doe (= parameters). All possible combinations are considered.
17461749
"""
1747-
self._lmodel = lmodel
1748-
self._modelName = modelName
1749-
self._fileName = fileName
1750-
1751-
self._CommandLineOptions = commandLineOptions
1752-
self._variableFilter = variableFilter
1753-
self._customBuildDirectory = customBuildDirectory
1754-
self._omhome = omhome
17551750

1756-
# reference for the model; not used for any simulations but to evaluate parameters, etc.
17571751
self._mod = ModelicaSystem(
1758-
fileName=self._fileName,
1759-
modelName=self._modelName,
1760-
lmodel=self._lmodel,
1761-
commandLineOptions=self._CommandLineOptions,
1762-
variableFilter=self._variableFilter,
1763-
customBuildDirectory=self._customBuildDirectory,
1764-
omhome=self._omhome,
1752+
fileName=fileName,
1753+
modelName=modelName,
1754+
lmodel=lmodel,
1755+
commandLineOptions=commandLineOptions,
1756+
variableFilter=variableFilter,
1757+
customBuildDirectory=customBuildDirectory,
1758+
omhome=omhome,
1759+
omc_process=omc_process,
17651760
)
17661761

1762+
self._model_name = modelName
1763+
17671764
self._simargs = simargs
17681765
self._timeout = timeout
17691766

1770-
if isinstance(resultpath, pathlib.Path):
1771-
self._resultpath = resultpath
1767+
if resultpath is None:
1768+
self._resultpath = self._mod._getconn.omcpath_tempdir()
17721769
else:
1773-
self._resultpath = pathlib.Path('.')
1770+
self._resultpath = self._mod._getconn.omcpath(resultpath)
1771+
if not self._resultpath.is_dir():
1772+
raise ModelicaSystemError("Argument resultpath must be set to a valid path within the environment used "
1773+
f"for the OpenModelica session: {resultpath}!")
17741774

17751775
if isinstance(parameters, dict):
17761776
self._parameters = parameters
@@ -1817,15 +1817,15 @@ def prepare(self) -> int:
18171817

18181818
pk_value = pc_structure[idx_structure]
18191819
if isinstance(pk_value, str):
1820-
expression = f"setParameterValue({self._modelName}, {pk_structure}, \"{pk_value}\")"
1820+
expression = f"setParameterValue({self._model_name}, {pk_structure}, \"{pk_value}\")"
18211821
elif isinstance(pk_value, bool):
18221822
pk_value_bool_str = "true" if pk_value else "false"
1823-
expression = f"setParameterValue({self._modelName}, {pk_structure}, {pk_value_bool_str});"
1823+
expression = f"setParameterValue({self._model_name}, {pk_structure}, {pk_value_bool_str});"
18241824
else:
1825-
expression = f"setParameterValue({self._modelName}, {pk_structure}, {pk_value})"
1826-
res = mod_structure.sendExpression(expression)
1825+
expression = f"setParameterValue({self._model_name}, {pk_structure}, {pk_value})"
1826+
res = self._mod.sendExpression(expression)
18271827
if not res:
1828-
raise ModelicaSystemError(f"Cannot set structural parameter {self._modelName}.{pk_structure} "
1828+
raise ModelicaSystemError(f"Cannot set structural parameter {self._model_name}.{pk_structure} "
18291829
f"to {pk_value} using {repr(expression)}")
18301830

18311831
self._mod.buildModel()

0 commit comments

Comments
 (0)