Skip to content

Commit 0a89151

Browse files
committed
[ModelicaSystem._set_method_helper] fail if parameter is *NOT* changeable
* if this happens, the result would be unexpected * fail early, fail hard to indicate this to the user * simplify code
1 parent 30cb70e commit 0a89151

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

OMPython/ModelicaSystem.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,29 +1195,25 @@ def _set_method_helper(
11951195
dict() which stores the new override variables list,
11961196
"""
11971197

1198-
inputdata_status: dict[str, bool] = {}
11991198
for key, val in inputdata.items():
12001199
if key not in classdata:
12011200
raise ModelicaSystemError("Unhandled case in setMethodHelper.apply_single() - "
12021201
f"{repr(key)} is not a {repr(datatype)} variable")
12031202

1204-
status = False
12051203
if datatype == "parameter" and not self.isParameterChangeable(key):
1206-
logger.debug(f"It is not possible to set the parameter {repr(key)}. It seems to be "
1207-
"structural, final, protected, evaluated or has a non-constant binding. "
1208-
"Use sendExpression(...) and rebuild the model using buildModel() API; example: "
1209-
"sendExpression(\"setParameterValue("
1210-
f"{self._model_name}, {key}, {val if val is not None else '<?value?>'}"
1211-
")\") ")
1212-
else:
1213-
classdata[key] = val
1214-
if overwritedata is not None:
1215-
overwritedata[key] = val
1216-
status = True
1217-
1218-
inputdata_status[key] = status
1204+
raise ModelicaSystemError(f"It is not possible to set the parameter {repr(key)}. It seems to be "
1205+
"structural, final, protected, evaluated or has a non-constant binding. "
1206+
"Use sendExpression(...) and rebuild the model using buildModel() API; "
1207+
"command to set the parameter before rebuilding the model: "
1208+
"sendExpression(\"setParameterValue("
1209+
f"{self._model_name}, {key}, {val if val is not None else '<?value?>'}"
1210+
")\").")
1211+
1212+
classdata[key] = val
1213+
if overwritedata is not None:
1214+
overwritedata[key] = val
12191215

1220-
return all(inputdata_status.values())
1216+
return True
12211217

12221218
def isParameterChangeable(
12231219
self,

0 commit comments

Comments
 (0)