Skip to content

Commit 5bb7799

Browse files
committed
[ModelicaSystemDoE] update variable handling / remove variables not needed
1 parent b9b4189 commit 5bb7799

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

OMPython/ModelicaSystem.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,52 +1802,52 @@ def run_doe():
18021802

18031803
def __init__(
18041804
self,
1805-
fileName: Optional[str | os.PathLike | pathlib.Path] = None,
1805+
# data to be used for ModelicaSystem
1806+
fileName: Optional[str | os.PathLike] = None,
18061807
modelName: Optional[str] = None,
18071808
lmodel: Optional[list[str | tuple[str, str]]] = None,
18081809
commandLineOptions: Optional[list[str]] = None,
18091810
variableFilter: Optional[str] = None,
1810-
customBuildDirectory: Optional[str | os.PathLike | pathlib.Path] = None,
1811+
customBuildDirectory: Optional[str | os.PathLike] = None,
18111812
omhome: Optional[str] = None,
1812-
1813+
omc_process: Optional[OMCProcess] = None, # TODO: use omc session
1814+
# simulation specific input
1815+
# TODO: add more settings (simulation options, input options, ...)
18131816
simargs: Optional[dict[str, Optional[str | dict[str, str] | numbers.Number]]] = None,
18141817
timeout: Optional[int] = None,
1815-
1816-
resultpath: Optional[pathlib.Path] = None,
1818+
# DoE specific inputs
1819+
resultpath: Optional[str | os.PathLike] = None,
18171820
parameters: Optional[dict[str, list[str] | list[int] | list[float]]] = None,
18181821
) -> None:
18191822
"""
18201823
Initialisation of ModelicaSystemDoE. The parameters are based on: ModelicaSystem.__init__() and
18211824
ModelicaSystem.simulate(). Additionally, the path to store the result files is needed (= resultpath) as well as
18221825
a list of parameters to vary for the Doe (= parameters). All possible combinations are considered.
18231826
"""
1824-
self._lmodel = lmodel
1825-
self._modelName = modelName
1826-
self._fileName = fileName
1827-
1828-
self._CommandLineOptions = commandLineOptions
1829-
self._variableFilter = variableFilter
1830-
self._customBuildDirectory = customBuildDirectory
1831-
self._omhome = omhome
18321827

1833-
# reference for the model; not used for any simulations but to evaluate parameters, etc.
18341828
self._mod = ModelicaSystem(
1835-
fileName=self._fileName,
1836-
modelName=self._modelName,
1837-
lmodel=self._lmodel,
1838-
commandLineOptions=self._CommandLineOptions,
1839-
variableFilter=self._variableFilter,
1840-
customBuildDirectory=self._customBuildDirectory,
1841-
omhome=self._omhome,
1829+
fileName=fileName,
1830+
modelName=modelName,
1831+
lmodel=lmodel,
1832+
commandLineOptions=commandLineOptions,
1833+
variableFilter=variableFilter,
1834+
customBuildDirectory=customBuildDirectory,
1835+
omhome=omhome,
1836+
omc_process=omc_process,
18421837
)
18431838

1839+
self._model_name = modelName
1840+
18441841
self._simargs = simargs
18451842
self._timeout = timeout
18461843

1847-
if isinstance(resultpath, pathlib.Path):
1848-
self._resultpath = resultpath
1844+
if resultpath is None:
1845+
self._resultpath = self._mod._getconn.omcpath_tempdir()
18491846
else:
1850-
self._resultpath = pathlib.Path('.')
1847+
self._resultpath = self._mod._getconn.omcpath(resultpath)
1848+
if not self._resultpath.is_dir():
1849+
raise ModelicaSystemError("Argument resultpath must be set to a valid path within the environment used "
1850+
f"for the OpenModelica session: {resultpath}!")
18511851

18521852
if isinstance(parameters, dict):
18531853
self._parameters = parameters
@@ -1894,15 +1894,15 @@ def prepare(self) -> int:
18941894

18951895
pk_value = pc_structure[idx_structure]
18961896
if isinstance(pk_value, str):
1897-
expression = f"setParameterValue({self._modelName}, {pk_structure}, \"{pk_value}\")"
1897+
expression = f"setParameterValue({self._model_name}, {pk_structure}, \"{pk_value}\")"
18981898
elif isinstance(pk_value, bool):
18991899
pk_value_bool_str = "true" if pk_value else "false"
1900-
expression = f"setParameterValue({self._modelName}, {pk_structure}, {pk_value_bool_str});"
1900+
expression = f"setParameterValue({self._model_name}, {pk_structure}, {pk_value_bool_str});"
19011901
else:
1902-
expression = f"setParameterValue({self._modelName}, {pk_structure}, {pk_value})"
1903-
res = mod_structure.sendExpression(expression)
1902+
expression = f"setParameterValue({self._model_name}, {pk_structure}, {pk_value})"
1903+
res = self._mod.sendExpression(expression)
19041904
if not res:
1905-
raise ModelicaSystemError(f"Cannot set structural parameter {self._modelName}.{pk_structure} "
1905+
raise ModelicaSystemError(f"Cannot set structural parameter {self._model_name}.{pk_structure} "
19061906
f"to {pk_value} using {repr(expression)}")
19071907

19081908
self._mod.buildModel()

0 commit comments

Comments
 (0)