Opened 15 years ago

Closed 6 years ago

#1227 closed defect (fixed)

Perform constant evaluation only for bindings of structural parameters

Reported by: Adrian Pop Owned by: Per Östlund
Priority: critical Milestone: 2.0.0
Component: Instantiation Version:
Keywords: Cc: Adrian Pop, Per Östlund

Description

Right now constant evaluation is performed always if the expression given to Ceval.ceval is constant.
This takes a lot of time and is not needed during instantiation.

Constant evaluation should only be performed for bindings of structural parameters.
A parameter is structural if:

  • is used in an array dimension: Real x[structParam];
  • is used in a condition of a conditional component: Real x if structParam;
  • is used in a condition of an if equation: equation if structParam then ... ;
  • has a binding that is a structural parameter (from an outside modification): Type x(structParamam=structParamOutside);


A possible implementation would extend Env.VAR with a new boolean component: isStructuralParameter.
Lookup.lookupVar would return this boolean too.
Static.elabExp will only perform constant evaluation if the given expression is a component reference that
is a structural parameter.
During instantiation when Static.elabExp is called on expressions that appear in arrays dimensions, if, etc. (see above) you first update the component reference in the environment and set isStructuralParameter to true.

Cheers,
Adrian Pop/

Change History (8)

comment:1 by Martin Sjölund, 14 years ago

Note: Also mark the parameter "final"; it must not be modified in the init-file if it is structural :)

comment:2 by Peter Aronsson, 12 years ago

The following parameter is also structural (since it affects which variables are unknown during initialization)

model paraminit
  Real p1,p2;
  parameter Real L(fixed=not computeL); 
  parameter Boolean computeL=true; // a structural parameter
initial equation
 p1 -p2 = 10;
equation
der(p1) = -time;
p1+L = p2;
end paraminit;

comment:3 by Dietmar Winkler, 9 years ago

Milestone: Future

comment:4 by Francesco Casella, 8 years ago

Is this enhancement covered by the the new front-end envisioned for version 2.0.0?

comment:5 by Adrian Pop, 8 years ago

Milestone: Future2.0.0

Yes.

comment:6 by Francesco Casella, 6 years ago

Parameter should also be constant evaluated if they have an Evaluate=true annotation and have a binding to a constant expression, or if they are final and the binding expression only depends on constants and parameters which have Evaluate=true, see the discussion in #1283

comment:7 by Francesco Casella, 6 years ago

Owner: changed from Adrian Pop to Per Östlund

@perost, is the current frontend satisfying these requirements? If so, please close the ticket

in reply to:  7 comment:8 by Per Östlund, 6 years ago

Resolution: fixed
Status: assignedclosed

Replying to casella:

@perost, is the current frontend satisfying these requirements? If so, please close the ticket

Not the current frontend. It does keep a list of "structural" parameters, but it's really just a list of parameters it has evaluated. The new frontend marks parameters as structural approximately according to these rules though, but also has to evaluate some extra things to satisfy the backend.

But the current instantiation won't be improved in this regard, and the new satisfy the requirements well enough that this ticket doesn't really serve any purpose. So I think we can close it, and if there are any issues regarding structural parameters we can open more specific tickets.

Note: See TracTickets for help on using tickets.