| | 543 | class ParameterDefaults "Parameter defaults" |
| | 544 | |
| | 545 | annotation (Documentation(info="<html> |
| | 546 | |
| | 547 | <p> |
| | 548 | In this section the convention is summarized how default parameters are |
| | 549 | handled in the Modelica Standard Library (since version 3.0). |
| | 550 | </p> |
| | 551 | |
| | 552 | <p> |
| | 553 | Many models in this library have parameter declarations to define |
| | 554 | constants of a model that might be changed before simulation starts. |
| | 555 | Example: |
| | 556 | </p> |
| | 557 | |
| | 558 | <blockquote> |
| | 559 | <pre> |
| | 560 | <b>model</b> SpringDamper |
| | 561 | <b>parameter</b> Real c(final unit=\"N.m/rad\") = 1e5 \"Spring constant\"; |
| | 562 | <b>parameter</b> Real d(final unit=\"N.m.s/rad\") = 0 \"Damping constant\"; |
| | 563 | <b>parameter</b> Modelica.SIunits.Angle phi_rel0 = 0 \"Unstretched spring angle\"; |
| | 564 | ... |
| | 565 | <b>end</b> SpringDamper; |
| | 566 | </pre> |
| | 567 | </blockquote> |
| | 568 | |
| | 569 | <p> |
| | 570 | In Modelica it is possible to define a default value of a parameter in |
| | 571 | the parameter declaration. In the example above, this is performed for |
| | 572 | all parameters. Providing default values for all parameters can lead to |
| | 573 | errors that are difficult to detect, since a modeler may have forgotten |
| | 574 | to provide a meaningful value (the model simulates but gives wrong |
| | 575 | results due to wrong parameter values). In general the following basic |
| | 576 | situations are present: |
| | 577 | </p> |
| | 578 | |
| | 579 | <ol> |
| | 580 | <li> The parameter value could be anything (e.g., a spring constant or |
| | 581 | a resistance value) and therefore the user should provide a value in |
| | 582 | all cases. A Modelica translator should warn, if no value is provided. |
| | 583 | <br><br></li> |
| | 584 | |
| | 585 | <li> The parameter value is not changed in > 95 % of the cases |
| | 586 | (e.g. initialization or visualization parameters, or parameter phi_rel0 |
| | 587 | in the example above). In this case a default parameter value should be |
| | 588 | provided, in order that the model or function can be conveniently |
| | 589 | used by a modeler. |
| | 590 | <br><br></li> |
| | 591 | |
| | 592 | <li> A modeler would like to quickly utilize a model, e.g., |
| | 593 | <ul> |
| | 594 | <li> to automatically check that the model still translates and/or simulates |
| | 595 | (after some changes in the library),</li> |
| | 596 | <li> to make a quick demo of a library by drag-and-drop of components,</li> |
| | 597 | <li> to implement a simple test model in order to get a better understanding |
| | 598 | of the desired component.</li> |
| | 599 | </ul> |
| | 600 | In all these cases, it would be not practical, if the modeler would |
| | 601 | have to provide explicit values for all parameters first. |
| | 602 | </li> |
| | 603 | </ol> |
| | 604 | |
| | 605 | <p> |
| | 606 | To handle the conflicting goals of (1) and (3), the Modelica Standard Library |
| | 607 | uses two approaches to define default parameters, as demonstrated with the |
| | 608 | following example: |
| | 609 | </p> |
| | 610 | |
| | 611 | <blockquote> |
| | 612 | <pre> |
| | 613 | <b>model</b> SpringDamper |
| | 614 | <b>parameter</b> Real c(final unit=\"N.m/rad\" , start=1e5) \"Spring constant\"; |
| | 615 | <b>parameter</b> Real d(final unit=\"N.m.s/rad\", start= 0) \"Damping constant\"; |
| | 616 | <b>parameter</b> Modelica.SIunits.Angle phi_rel0 = 0 \"Unstretched spring angle\"; |
| | 617 | ... |
| | 618 | <b>end</b> SpringDamper; |
| | 619 | |
| | 620 | SpringDamper sp1; // warning for \"c\" and \"d\" |
| | 621 | SpringDamper sp2(c=1e4, d=0); // fine, no warning |
| | 622 | </pre> |
| | 623 | </blockquote> |
| | 624 | |
| | 625 | <p> |
| | 626 | Both definition forms, using a \"start\" value (for \"c\" and \"d\") and providing |
| | 627 | a declaration equation (for \"phi_rel0\"), are valid Modelica and define the value |
| | 628 | of the parameter. By convention, it is expected that Modelica translators will |
| | 629 | trigger a warning message for parameters that are <b>not</b> defined by a declaration |
| | 630 | equation, by a modifier equation or in an initial equation/algorithm section. |
| | 631 | A Modelica translator might have options to change this behavior, especially, |
| | 632 | that no messages are printed in such cases and/or that an error is triggered |
| | 633 | instead of a warning. |
| | 634 | </p> |
| | 635 | |
| | 636 | </html> |
| | 637 | ")); |
| | 638 | end ParameterDefaults; |
| | 639 | |