Opened 12 years ago

Closed 11 years ago

#2207 closed defect (fixed)

nominal values get not evaluated if they depend on parameters

Reported by: Lennart Ochel Owned by: Lennart Ochel
Priority: critical Milestone: 1.9.1
Component: Run-time Version: trunk
Keywords: Cc: Lennart Ochel, Vitalij Ruge, Willi Braun

Description

Not all nominal values (same for other attributes, except start values) get not evaluated if they depend on parameter expressions.

mos-script

loadString("
model m1
  parameter Real a=100;
  constant Real b=100;
  Real x(nominal=10*a);
  Real y(nominal=10*b);
equation
  der(x) = 0;
  der(y) = 0;
end m1;
"); getErrorString();

simulate(m1, simflags="-lv=LOG_DEBUG"); getErrorString();

It works for y but not for x:

LOG_DEBUG         | info    | read xml file for states
|                 | |       | | Real y({start=0}, fixed=false, nominal=1000, min=-1.79769e+308, max=1.79769e+308)
|                 | |       | | Real x({start=0}, fixed=false, {nominal=1}, min=-1.79769e+308, max=1.79769e+308)
LOG_DEBUG         | info    | read xml file for stateDerivatives
|                 | |       | | Real der(y)({start=0}, fixed=false, nominal=1000, min=-1.79769e+308, max=1.79769e+308)
|                 | |       | | Real der(x)({start=0}, fixed=false, {nominal=1}, min=-1.79769e+308, max=1.79769e+308)
[...]

Change History (15)

comment:1 by anonymous, 12 years ago

Component: Run-timeFrontend

comment:2 by anonymous, 12 years ago

Component: FrontendBackend
Owner: changed from somebody to probably noone

comment:3 by Adrian Pop, 12 years ago

Hi,

I think we should talk about this in the next OSMC dev. meeting as is not 100% clear
where these should be evaluated. We can evaluate them in the Front-End but you can
also evaluate them in the Back-End (similar to what EvaluateParameter does).

Cheers,
Adrian Pop/

comment:4 by Adrian Pop, 12 years ago

Flattening this model:

model m1
  parameter Real a=100;
  constant Real b=100;
  Real x(start=10*a, nominal=10*a);
  Real y(nominal=10*b);
equation
  der(x) = 0;
  der(y) = 0;
end m1;

gets you:

adrpo@ida-liu050 ~/dev/OpenModelica/build/bin
$ ./omc m1.mo 
class m1
  parameter Real a = 100.0;
  constant Real b = 100.0;
  Real y(nominal = 1000.0);
  Real x(start = 10.0 * a, nominal = 10.0 * a);
equation
  der(x) = 0.0;
  der(y) = 0.0;
end m1;

so start values are not evaluated in the Front-End either.
They might be evaluated somewhere in the Back-End I guess
if they reach the code generation as values.

comment:5 by Martin Sjölund, 12 years ago

They should be evaluated in the backend for sure, I think. But this is probably dependent on if they are structural parameters or not.

comment:6 by Lennart Ochel, 12 years ago

Well, we calculate start values that depend on parameter expressions during simulation. This has the advantage that we can run a simulation without recompilation with several parameter sets.
I guess we should do it the same way for the other attributes, like min, max and nominal.

The following example shows that start values are supported in a proper way:

loadString("
model bug_2207
  parameter Real a=100;
  constant Real b=100;
  Real x(start=9*a, nominal=10*a);
  Real y(start=9*b, nominal=10*b);
equation
  der(x) = 0;
  der(y) = 0;
end bug_2207;
"); getErrorString();

simulate(bug_2207, simflags="-lv=LOG_DEBUG,LOG_INIT"); getErrorString();

Simulation output

LOG_DEBUG         | info    | read xml file for states
|                 | |       | | Real y(start=900, fixed=false, nominal=1000, min=-1.79769e+308, max=1.79769e+308)
|                 | |       | | Real x({start=0}, fixed=false, {nominal=1}, min=-1.79769e+308, max=1.79769e+308)
LOG_DEBUG         | info    | read xml file for stateDerivatives
|                 | |       | | Real der(y)({start=0}, fixed=false, nominal=1000, min=-1.79769e+308, max=1.79769e+308)
|                 | |       | | Real der(x)({start=0}, fixed=false, {nominal=1}, min=-1.79769e+308, max=1.79769e+308)
[…]
LOG_INIT          | info    | updating start-values
|                 | |       | | x(start=900)
[…]
|                 | |       | | states variables
|                 | |       | | | [1] Real y(start=900, nominal=1000) = 900 (pre: 900)
|                 | |       | | | [2] Real x(start=900, nominal=1) = 900 (pre: 900)
[…]

comment:7 by Lennart Ochel, 12 years ago

Component: BackendRun-time
Owner: changed from probably noone to somebody

I think it's not a question of how to do it. The only question is who has the time to do it. The implementation should be quite easy and straight forward.
I guess Adrian is right and we can discuss it in the next OMDev meeting.

comment:8 by Martin Sjölund, 11 years ago

Milestone: 1.9.01.9.1

Postponed until 1.9.1

comment:9 by Francesco Casella, 11 years ago

Priority: highcritical

I understand this problem also affects the experimental optimal control problem solver Vitalij is working on; if one sets min and max attributes on variables, these should be considered as hard constraints, so they are an essential part of the problem and cannot be ignored at all. Most of the time they will be parameter depending, so this needs to be taken care of.

comment:10 by Lennart Ochel, 11 years ago

Owner: changed from somebody to vruge
Status: newassigned

comment:11 by Lennart Ochel, 11 years ago

Cc: Vitalij Ruge added; vruge removed
Owner: changed from vruge to Vitalij Ruge

comment:12 by Vitalij Ruge, 11 years ago

Owner: changed from Vitalij Ruge to Lennart Ochel

comment:13 by Lennart Ochel, 11 years ago

Status: assignedaccepted

comment:14 by Lennart Ochel, 11 years ago

I fixed it and will commit it soon. Before, I would like to clean up my changes a bit.

comment:15 by Lennart Ochel, 11 years ago

Resolution: fixed
Status: acceptedclosed

fixed in r19076

Note: See TracTickets for help on using tickets.