modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
102 stars 41 forks source link

Are parameter dependent annotations for code generation legal? #1672

Open modelica-trac-importer opened 6 years ago

modelica-trac-importer commented 6 years ago

Reported by beutlich on 4 Mar 2015 11:52 UTC Is it legal to have parameter dependent annotations for code generation, such as HideResults, Evaluate, Inline etc.?

model Model8
  parameter Boolean useNormalizedVolume = true "Normalized volume of solution is 1 liter" annotation(Evaluate=true,HideResult=true,choices(__Dymola_checkBox=true),Dialog(group="External inputs/outputs"));
  Real volume=0 "Solution volume" annotation(HideResult=useNormalizedVolume);
end Model8;

Or should DynamicSelect be used instead

model Model8
  parameter Boolean useNormalizedVolume = true "Normalized volume of solution is 1 liter" annotation(Evaluate=true,HideResult=true,choices(__Dymola_checkBox=true),Dialog(group="External inputs/outputs"));
  Real volume=0 "Solution volume" annotation(HideResult=DynamicSelect(true, useNormalizedVolume));
end Model8;

Migrated-From: https://trac.modelica.org/Modelica/ticket/1672

modelica-trac-importer commented 6 years ago

Modified by beutlich on 18 Sep 2015 09:07 UTC

modelica-trac-importer commented 6 years ago

Comment by hansolsson on 18 Sep 2015 09:24 UTC To be clear we have three possibilities:

  1. You can directly use parameter expressions for those annotations: Real volume=0 annotation(HideResult=useNormalizedVolume);
  2. You have to use DynamicSelect for the parameter expression: Real volume=0 annotation(HideResult=DynamicSelect(true, useNormalizedVolume));
  3. Only literal values can be used for those annotations: Real volume=0 annotation(HideResult=true);

The start of "18.3 Annotations for Code Generation" code_annotation: annotation"(" codeGenerationFlag "=" ( false | true ) ")" would indicate that option 3 is specified.

Obviously we can decide to extend it to non-literals; assuming there are relevant use cases etc.

(A separate topic is that there are cases where HideResult is overused.)

modelica-trac-importer commented 6 years ago

Comment by beutlich on 18 Sep 2015 09:45 UTC Thanks, Hans. For your convenience I add the origin of this discussion: Physiolibrary#9.

modelica-trac-importer commented 6 years ago

Comment by dietmarw on 2 Oct 2015 20:51 UTC Ticket retargeted after milestone closed

modelica-trac-importer commented 6 years ago

Comment by hansolsson on 1 Apr 2016 12:26 UTC Replying to [comment:3 beutlich]:

Thanks, Hans. For your convenience I add the origin of this discussion: Physiolibrary#9.

Based on that discussion it seems that only literals (as indicated by section 18.3) is an acceptable solution - and that should be clarified.

HansOlsson commented 4 years ago

Note: A contrary view is that there has been a push from customers to allow Evaluate to depend on a parameter, which was implemented in Dymola 2019 I think (as variant 1).

beutlich commented 3 years ago

Note: A contrary view is that there has been a push from customers to allow Evaluate to depend on a parameter, which was implemented in Dymola 2019 I think (as variant 1).

So, maybe there should be another discussion and poll then.

thorade commented 3 years ago

I would be interested in a solution as described in the comment by Hans Olsson, especially to use Boolean parameters for Evaluate=true/false, similar to the below:

model evalparam
  parameter Boolean beFlexible = true;
  final parameter Boolean beFast = not beFlexible annotation (Evaluate=true);
  parameter Real myCoefficient = 4.0 annotation (Evaluate=beFast);
  Real y;

equation 
  y = sin(myCoefficient*time);
end evalparam;

This would already cover most of the customer needs I have seen, but the final parameter Boolean beFast could possibly use a more complex equation, or depend on parameters that are propagated from an extending model.