Skip to content

Commit 9d94c49

Browse files
committed
[ModelicaSystemDoE] cleanup prepare() / rename variables
1 parent ac9c44c commit 9d94c49

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
@@ -1610,9 +1610,9 @@ def prepare(self) -> int:
16101610
build=False,
16111611
)
16121612

1613-
sim_args_structure = {}
1613+
sim_param_structure = {}
16141614
for idx_structure, pk_structure in enumerate(param_structure.keys()):
1615-
sim_args_structure[pk_structure] = pc_structure[idx_structure]
1615+
sim_param_structure[pk_structure] = pc_structure[idx_structure]
16161616

16171617
pk_value = pc_structure[idx_structure]
16181618
if isinstance(pk_value, str):
@@ -1622,19 +1622,22 @@ def prepare(self) -> int:
16221622
expression = f"setParameterValue({self._modelName}, {pk_structure}, $Code(={pk_value_bool_str}));"
16231623
else:
16241624
expression = f"setParameterValue({self._modelName}, {pk_structure}, {pk_value})"
1625-
mod_structure.sendExpression(expression)
1625+
res = mod_structure.sendExpression(expression)
1626+
if not res:
1627+
raise ModelicaSystemError(f"Cannot set structural parameter {self._modelName}.{pk_structure} "
1628+
f"to {pk_value} using {repr(expression)}")
16261629

16271630
mod_structure.buildModel(variableFilter=self._variableFilter)
16281631

16291632
for idx_pc_simple, pc_simple in enumerate(param_simple_combinations):
1630-
sim_args_simple = {}
1633+
sim_param_simple = {}
16311634
for idx_simple, pk_simple in enumerate(param_simple.keys()):
1632-
sim_args_simple[pk_simple] = str(pc_simple[idx_simple])
1635+
sim_param_simple[pk_simple] = str(pc_simple[idx_simple])
16331636

16341637
resfilename = f"DOE_{idx_pc_structure:09d}_{idx_pc_simple:09d}.mat"
16351638
logger.info(f"use result file {repr(resfilename)} "
1636-
f"for structural parameters: {sim_args_structure} "
1637-
f"and simple parameters: {sim_args_simple}")
1639+
f"for structural parameters: {sim_param_structure} "
1640+
f"and simple parameters: {sim_param_simple}")
16381641
resultfile = self._resultpath / resfilename
16391642

16401643
df_data = (
@@ -1644,24 +1647,27 @@ def prepare(self) -> int:
16441647
self.DF_COLUMNS_RESULTFILENAME: resfilename,
16451648
'structural parameters ID': idx_pc_structure,
16461649
}
1647-
| sim_args_structure
1650+
| sim_param_structure
16481651
| {
16491652
'non-structural parameters ID': idx_pc_simple,
16501653
}
1651-
| sim_args_simple
1654+
| sim_param_simple
16521655
| {
16531656
self.DF_COLUMNS_RESULTS_AVAILABLE: False,
16541657
}
16551658
)
16561659

1657-
df_entries.append(pd.DataFrame.from_dict(df_data))
1660+
df_entries.append(pd.DataFrame(data=df_data, index=[0]))
16581661

1659-
cmd = mod_structure.simulate_cmd(
1662+
mscmd = mod_structure.simulate_cmd(
16601663
resultfile=resultfile.absolute().resolve(),
1661-
simargs={"override": sim_args_simple},
1664+
timeout=self._timeout,
16621665
)
1666+
if self._simargs is not None:
1667+
mscmd.args_set(args=self._simargs)
1668+
mscmd.args_set(args={"override": sim_param_simple})
16631669

1664-
self._sim_task_query.put(cmd)
1670+
self._sim_task_query.put(mscmd)
16651671

16661672
self._sim_df = pd.concat(df_entries, ignore_index=True)
16671673

0 commit comments

Comments
 (0)