Skip to content

Commit a4e2a79

Browse files
committed
[ModelicaSystemDoE] cleanup prepare() / rename variables
1 parent eb1ce4d commit a4e2a79

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
@@ -1524,9 +1524,9 @@ def prepare(self) -> int:
15241524
build=False,
15251525
)
15261526

1527-
sim_args_structure = {}
1527+
sim_param_structure = {}
15281528
for idx_structure, pk_structure in enumerate(param_structure.keys()):
1529-
sim_args_structure[pk_structure] = pc_structure[idx_structure]
1529+
sim_param_structure[pk_structure] = pc_structure[idx_structure]
15301530

15311531
pk_value = pc_structure[idx_structure]
15321532
if isinstance(pk_value, str):
@@ -1536,19 +1536,22 @@ def prepare(self) -> int:
15361536
expression = f"setParameterValue({self._modelName}, {pk_structure}, $Code(={pk_value_bool_str}));"
15371537
else:
15381538
expression = f"setParameterValue({self._modelName}, {pk_structure}, {pk_value})"
1539-
mod_structure.sendExpression(expression)
1539+
res = mod_structure.sendExpression(expression)
1540+
if not res:
1541+
raise ModelicaSystemError(f"Cannot set structural parameter {self._modelName}.{pk_structure} "
1542+
f"to {pk_value} using {repr(expression)}")
15401543

15411544
mod_structure.buildModel(variableFilter=self._variableFilter)
15421545

15431546
for idx_pc_simple, pc_simple in enumerate(param_simple_combinations):
1544-
sim_args_simple = {}
1547+
sim_param_simple = {}
15451548
for idx_simple, pk_simple in enumerate(param_simple.keys()):
1546-
sim_args_simple[pk_simple] = str(pc_simple[idx_simple])
1549+
sim_param_simple[pk_simple] = str(pc_simple[idx_simple])
15471550

15481551
resfilename = f"DOE_{idx_pc_structure:09d}_{idx_pc_simple:09d}.mat"
15491552
logger.info(f"use result file {repr(resfilename)} "
1550-
f"for structural parameters: {sim_args_structure} "
1551-
f"and simple parameters: {sim_args_simple}")
1553+
f"for structural parameters: {sim_param_structure} "
1554+
f"and simple parameters: {sim_param_simple}")
15521555
resultfile = self._resultpath / resfilename
15531556

15541557
df_data = (
@@ -1558,24 +1561,27 @@ def prepare(self) -> int:
15581561
self.DF_COLUMNS_RESULTFILENAME: resfilename,
15591562
'structural parameters ID': idx_pc_structure,
15601563
}
1561-
| sim_args_structure
1564+
| sim_param_structure
15621565
| {
15631566
'non-structural parameters ID': idx_pc_simple,
15641567
}
1565-
| sim_args_simple
1568+
| sim_param_simple
15661569
| {
15671570
self.DF_COLUMNS_RESULTS_AVAILABLE: False,
15681571
}
15691572
)
15701573

1571-
df_entries.append(pd.DataFrame.from_dict(df_data))
1574+
df_entries.append(pd.DataFrame(data=df_data, index=[0]))
15721575

1573-
cmd = mod_structure.simulate_cmd(
1576+
mscmd = mod_structure.simulate_cmd(
15741577
resultfile=resultfile.absolute().resolve(),
1575-
simargs={"override": sim_args_simple},
1578+
timeout=self._timeout,
15761579
)
1580+
if self._simargs is not None:
1581+
mscmd.args_set(args=self._simargs)
1582+
mscmd.args_set(args={"override": sim_param_simple})
15771583

1578-
self._sim_task_query.put(cmd)
1584+
self._sim_task_query.put(mscmd)
15791585

15801586
self._sim_df = pd.concat(df_entries, ignore_index=True)
15811587

0 commit comments

Comments
 (0)