ParameterDefaults
Parameter defaults
Library
Modelica/UsersGuide
Description
In this section the convention is summarized how default parameters arehandled in the Modelica Standard Library (since version 3.0).
Many models in this library have parameter declarations to defineconstants of a model that might be changed before simulation starts.Example:
model SpringDamperparameter Real c(final unit="N.m/rad") = 1e5 "Spring constant";parameter Real d(final unit="N.m.s/rad") = 0 "Damping constant";parameter Modelica.SIunits.Angle phi_rel0 = 0 "Unstretched spring angle";...end SpringDamper;
In Modelica it is possible to define a default value of a parameter inthe parameter declaration. In the example above, this is performed forall parameters. Providing default values for all parameters can lead toerrors that are difficult to detect, since a modeler may have forgottento provide a meaningful value (the model simulates but gives wrongresults due to wrong parameter values). In general the following basicsituations are present:
- The parameter value could be anything (e.g., a spring constant or a resistance value) and therefore the user should provide a value in all cases. A Modelica translator should warn, if no value is provided.
- The parameter value is not changed in > 95 % of the cases (e.g., initialization or visualization parameters, or parameter phi_rel0 in the example above). In this case a default parameter value should be provided, in order that the model or function can be conveniently used by a modeler.
- A modeler would like to quickly utilize a model, e.g.,
- to automatically check that the model still translates and/or simulates (after some changes in the library),
- to make a quick demo of a library by drag-and-drop of components,
- to implement a simple test model in order to get a better understanding of the desired component.
To handle the conflicting goals of (1) and (3), the Modelica Standard Libraryuses two approaches to define default parameters, as demonstrated with thefollowing example:
model SpringDamperparameter Real c(final unit="N.m/rad" , start=1e5) "Spring constant";parameter Real d(final unit="N.m.s/rad", start= 0) "Damping constant";parameter Modelica.SIunits.Angle phi_rel0 = 0 "Unstretched spring angle";...end SpringDamper;SpringDamper sp1; // warning for "c" and "d"SpringDamper sp2(c=1e4, d=0); // fine, no warning
Both definition forms, using a "start" value (for "c" and "d") and providinga declaration equation (for "phi_rel0"), are valid Modelica and define the valueof the parameter. By convention, it is expected that Modelica translators willtrigger a warning message for parameters that are not defined by a declarationequation, by a modifier equation or in an initial equation/algorithm section.A Modelica translator might have options to change this behavior, especially,that no messages are printed in such cases and/or that an error is triggeredinstead of a warning.