Skip to content

Commit 7a55a00

Browse files
committed
[ModelicaSystemDoE] cleanup prepare() / rename variables
1 parent 171bfdc commit 7a55a00

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,9 +1881,9 @@ def prepare(self) -> int:
18811881
build=False,
18821882
)
18831883

1884-
sim_args_structure = {}
1884+
sim_param_structure = {}
18851885
for idx_structure, pk_structure in enumerate(param_structure.keys()):
1886-
sim_args_structure[pk_structure] = pc_structure[idx_structure]
1886+
sim_param_structure[pk_structure] = pc_structure[idx_structure]
18871887

18881888
pk_value = pc_structure[idx_structure]
18891889
if isinstance(pk_value, str):
@@ -1893,19 +1893,22 @@ def prepare(self) -> int:
18931893
expression = f"setParameterValue({self._modelName}, {pk_structure}, $Code(={pk_value_bool_str}));"
18941894
else:
18951895
expression = f"setParameterValue({self._modelName}, {pk_structure}, {pk_value})"
1896-
mod_structure.sendExpression(expression)
1896+
res = mod_structure.sendExpression(expression)
1897+
if not res:
1898+
raise ModelicaSystemError(f"Cannot set structural parameter {self._modelName}.{pk_structure} "
1899+
f"to {pk_value} using {repr(expression)}")
18971900

18981901
mod_structure.buildModel(variableFilter=self._variableFilter)
18991902

19001903
for idx_pc_simple, pc_simple in enumerate(param_simple_combinations):
1901-
sim_args_simple = {}
1904+
sim_param_simple = {}
19021905
for idx_simple, pk_simple in enumerate(param_simple.keys()):
1903-
sim_args_simple[pk_simple] = str(pc_simple[idx_simple])
1906+
sim_param_simple[pk_simple] = str(pc_simple[idx_simple])
19041907

19051908
resfilename = f"DOE_{idx_pc_structure:09d}_{idx_pc_simple:09d}.mat"
19061909
logger.info(f"use result file {repr(resfilename)} "
1907-
f"for structural parameters: {sim_args_structure} "
1908-
f"and simple parameters: {sim_args_simple}")
1910+
f"for structural parameters: {sim_param_structure} "
1911+
f"and simple parameters: {sim_param_simple}")
19091912
resultfile = self._resultpath / resfilename
19101913

19111914
df_data = (
@@ -1915,24 +1918,27 @@ def prepare(self) -> int:
19151918
self.DF_COLUMNS_RESULTFILENAME: resfilename,
19161919
'structural parameters ID': idx_pc_structure,
19171920
}
1918-
| sim_args_structure
1921+
| sim_param_structure
19191922
| {
19201923
'non-structural parameters ID': idx_pc_simple,
19211924
}
1922-
| sim_args_simple
1925+
| sim_param_simple
19231926
| {
19241927
self.DF_COLUMNS_RESULTS_AVAILABLE: False,
19251928
}
19261929
)
19271930

1928-
df_entries.append(pd.DataFrame.from_dict(df_data))
1931+
df_entries.append(pd.DataFrame(data=df_data, index=[0]))
19291932

1930-
cmd = mod_structure.simulate_cmd(
1933+
mscmd = mod_structure.simulate_cmd(
19311934
resultfile=resultfile.absolute().resolve(),
1932-
simargs={"override": sim_args_simple},
1935+
timeout=self._timeout,
19331936
)
1937+
if self._simargs is not None:
1938+
mscmd.args_set(args=self._simargs)
1939+
mscmd.args_set(args={"override": sim_param_simple})
19341940

1935-
self._sim_task_query.put(cmd)
1941+
self._sim_task_query.put(mscmd)
19361942

19371943
self._sim_df = pd.concat(df_entries, ignore_index=True)
19381944

0 commit comments

Comments
 (0)