ModelicaSpecification icon indicating copy to clipboard operation
ModelicaSpecification copied to clipboard

Are parameter dependent annotations for code generation legal?

Open modelica-trac-importer opened this issue 6 years ago • 8 comments

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 avatar Nov 04 '18 12:11 modelica-trac-importer

Modified by beutlich on 18 Sep 2015 09:07 UTC

modelica-trac-importer avatar Nov 04 '18 12:11 modelica-trac-importer

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 avatar Nov 04 '18 12:11 modelica-trac-importer

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 avatar Nov 04 '18 12:11 modelica-trac-importer

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

modelica-trac-importer avatar Nov 04 '18 12:11 modelica-trac-importer

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.

modelica-trac-importer avatar Nov 04 '18 12:11 modelica-trac-importer

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).

HansOlsson avatar Feb 13 '20 15:02 HansOlsson

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.

beutlich avatar Feb 03 '21 19:02 beutlich

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.

thorade avatar Feb 17 '21 08:02 thorade