Skip to content

Commit 0bd7df7

Browse files
committed
[ModelicaSystemDoE] update variable handling / remove variables not needed
1 parent 67713a5 commit 0bd7df7

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
@@ -1801,52 +1801,52 @@ def run_doe():
18011801

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

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

1838+
self._model_name = modelName
1839+
18431840
self._simargs = simargs
18441841
self._timeout = timeout
18451842

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

18511851
if isinstance(parameters, dict):
18521852
self._parameters = parameters
@@ -1893,15 +1893,15 @@ def prepare(self) -> int:
18931893

18941894
pk_value = pc_structure[idx_structure]
18951895
if isinstance(pk_value, str):
1896-
expression = f"setParameterValue({self._modelName}, {pk_structure}, \"{pk_value}\")"
1896+
expression = f"setParameterValue({self._model_name}, {pk_structure}, \"{pk_value}\")"
18971897
elif isinstance(pk_value, bool):
18981898
pk_value_bool_str = "true" if pk_value else "false"
1899-
expression = f"setParameterValue({self._modelName}, {pk_structure}, {pk_value_bool_str});"
1899+
expression = f"setParameterValue({self._model_name}, {pk_structure}, {pk_value_bool_str});"
19001900
else:
1901-
expression = f"setParameterValue({self._modelName}, {pk_structure}, {pk_value})"
1902-
res = mod_structure.sendExpression(expression)
1901+
expression = f"setParameterValue({self._model_name}, {pk_structure}, {pk_value})"
1902+
res = self._mod.sendExpression(expression)
19031903
if not res:
1904-
raise ModelicaSystemError(f"Cannot set structural parameter {self._modelName}.{pk_structure} "
1904+
raise ModelicaSystemError(f"Cannot set structural parameter {self._model_name}.{pk_structure} "
19051905
f"to {pk_value} using {repr(expression)}")
19061906

19071907
self._mod.buildModel()

0 commit comments

Comments
 (0)