Reputation: 794
I use a lot of parameter annotations when developping components, in order to make them user-friendly, especially the Dialog(enable=...)
. However, when a parameter is disabled, it just prevents the user from modifying it afterwards, but it does not affect the value that may have been set beforehand. Here's an example:
model toto
parameter Boolean isComplexModel=true;
parameter Boolean isDynamicModel=false annotation (Dialog(enable=isComplexModel));
equation
// Mass and energy balance equations
if isDynamicModel and isComplexModel then
[...]
else
[...]
end if;
// Other part of the code
if isComplexModel then
[...]
end if;
end toto;
In this example, the dynamic equations are used only if isDynamicModel=true
, which should be available only if isComplexModel=true
. However, I could set isDynamicModel=true
and then isComplexModel=false
in the instance. That's why I need to specify if isDynamicModel and isComplexModel
.
Therefore, is there a way to modify (or at least reset) the value of a parameter when it is disabled?
Upvotes: 0
Views: 72
Reputation: 101
I don't think that it is possible to change the parameter value when it is disabled.
You have three cases (simple, complex with dynamics, complex without dynamics). As tbeu mentioned, a better design would be to implement this as an enumeration.
If you want to use booleans, you could also implement an additional protected parameter
parameter Boolean isComplexModel = true;
protected
parameter Boolean hasDynamicBalance = isDynamicModel and isComplexModel;
[...]
// Mass and energy balance equations
if hasDynamicBalance then
[...]
else
[...]
end if;
If you implement the simple/complex sub-models replaceable, you might implement the dynamics parameter inside the complex sub-model. However, interfacing the sub-model is more complex.
model ComplexModel
extends BaseModel;
parameter Boolean isDynamicModel=false
[...]
// Mass and energy balance equations
if hasDynamicBalance then
[...]
else
[...]
end if;
end ComplexModel;
model SimpleModel
extends BaseModel;
[...]
end SimpleModel;
replaceable SimpleModel model constrainedby BaseModel;
...
Upvotes: 2