Open AndreaBartolini opened 6 months ago
@AntoineGautier : Can you please look into this issue that is used in the Templates
package.
We use this implementation pattern systematically in the Buildings library for parameters that are used in conditional or replaceable components. All these parameter declarations have
From the language specification:
If enable = false, the input field may be disabled and no input can be given.
If the enable attribute evaluates to false, you'll notice that these parameters are actually not used in the flat equation system – after removing the conditional components with false condition and taking into account all redeclarations. We use the start attribute to provide a "placeholder" value that has no impact whatsoever on the simulation results.
All this is due to the fact that conditional components cannot be used outside of connect equations in Modelica.
You will find more insight on this in section 6 of the paper HVAC and Control Templates for the Modelica Buildings Library, as well as the alternative approaches that were tested and the reason why they were rejected.
The same feature is used for example in the model Modelica.Electrical.Machines.BasicMachines.SynchronousMachines.SM_ElectricalExcited
.
parameter SI.Temperature TrRef(start=293.15)
"Reference temperature of damper resistances in d- and q-axis"
annotation (Dialog(
tab="Nominal resistances and inductances",
group="Damper cage",
enable=useDamperCage));
...
Machines.BasicMachines.Components.DamperCage damperCage(
final Lrsigmad=Lrsigmad,
final Lrsigmaq=Lrsigmaq,
final Rrd=Rrd,
final Rrq=Rrq,
final T_ref=TrRef,
final alpha=Machines.Thermal.convertAlpha(alpha20r, TrRef),
final useHeatPort=true) if useDamperCage
In any instance of this model, if useDamperCage=false
, the parameter TrRef
may be left unassigned.
This feature is fully supported by Dymola.
For example, translating Buildings.Templates.Plants.HeatPumps.Components.Validation.ValvesIsolation
yields the following info message – but not a warning as in the case where a parameter assignment relies on the start attribute and no enable attribute is used.
The following parameters have enable=false and don't have any value, only a start value:
Modelon is working on supporting this feature as well in Optimica (ticket #2022110739000228).
We believe that the lack of conditional declarations of parameters is the biggest obstacle to the development of complex system templates and makes the parametric polymorphism of the Modelica language cumbersome in practice. We plan to raise the issue to the Modelica Association and motivate an evolution of the language specification to support the use of conditional components outside of connect statements (at least for parameters). In the meantime, and as described in the paper on HVAC templates, we see no satisfying alternative other than using the start attribute together with enable.
Can this be supported by OMC in the near future?
Can this be supported by OMC in the near future?
@casella can you please answer about this point?
@AntoineGautier, thanks for the in-depth analysis.
@casella It would be great if you could open a ticket to improve the MLS concerning parameters with annotation(Dialog(enable = false))
and no binding.
On my end I will open a ticket for supporting the use of conditional parameters in binding equations, which is more of a long-term feature enhancement. I talked about this with Hans Olsson at the Modelica conference last year and now I really need to follow up on that.
We also support further MLS amendments to better support models with conditional components and are open to discussion and test implementation of that.
Great! I'll keep you in the loop.
Some models in the Buildings library fails to simulate under OpenModelica because some parameters are assigned by using theirs start attribute instead of a binding (an example is given in https://github.com/OpenModelica/OpenModelica/issues/12305).
This modus-operandi is allowed by the Modelica Specification and the issue is under fixing in OpenModelica (see https://github.com/OpenModelica/OpenModelica/issues/12304) but in general it is better to use modifiers to assign the values to the parameters.
Please consider the possibility to update the Models listed in the https://github.com/OpenModelica/OpenModelica/issues/12305 by adding proper modifiers to assign the parameters that currently have only the start attribute.
keeping @casella in the loop