Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#2990 closed defect (fixed)

max/min attributes overwrite start at initialization

Reported by: crupp@… Owned by: Lennart Ochel
Priority: critical Milestone: 1.9.4
Component: Run-time Version: trunk
Keywords: Cc: Lennart Ochel

Description

When max and min equations exist for a variable, the start value gets improperly overwritten with the max attribute value.

Here is some example code:

loadString("
model maxminbug
parameter Real L = 2.5;
parameter Real a = 0.24;
Real x(start = 1.0, min=-L^2.0, max=L^2.0);
Real y;
equation
der(x)=y;
der(y)=-a*x;
end maxminbug;
");

// Notice that pre(x) for initialization is 6.25, this should not be x.max
simulate(maxminbug, simflags="-lv=LOG_INIT");

// With -iim=none, x.start is set to 6.25, this should definitely not be x.max
simulate(maxminbug, simflags="-lv=LOG_INIT -iim=none");

The output:

"true
record SimulationResult
    resultFile = \"S:/Scratch/OMBugs/maxminbug_res.mat\",
    simulationOptions = \"startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'maxminbug', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv=LOG_INIT'\",
    messages = \"LOG_INIT          | info    | ### START INITIALIZATION ###
LOG_INIT          | info    | updating min-values
|                 | |       | | x(min=-6.25)
LOG_INIT          | info    | updating max-values
|                 | |       | | x(max=6.25)
LOG_INIT          | info    | updating nominal-values
LOG_INIT          | info    | updating start-values
LOG_INIT          | info    | initialization method: symbolic        [solves the initialization problem symbolically - default]
LOG_INIT          | info    | parameter values
|                 | |       | | real parameters
|                 | |       | | | [1] parameter Real L(start=2.5, fixed=true) = 2.5
|                 | |       | | | [2] parameter Real a(start=0.24, fixed=true) = 0.24
LOG_SOTI          | info    | ### SOLUTION OF THE INITIALIZATION ###
|                 | |       | | states variables
|                 | |       | | | [1] Real x(start=1, nominal=1) = 1 (pre: 6.25)
|                 | |       | | | [2] Real y(start=0, nominal=1) = 0 (pre: 0)
|                 | |       | | derivatives variables
|                 | |       | | | [3] Real der(x) = 0 (pre: 0)
|                 | |       | | | [4] Real der(y) = -0.24 (pre: 0)
LOG_INIT          | info    | ### END INITIALIZATION ###
\",
    timeFrontend = 0.01207791378747863,
    timeBackend = 0.001214175020201499,
    timeSimCode = 0.0009431108479240174,
    timeTemplates = 0.03195060665444899,
    timeCompile = 1.29165318028847,
    timeSimulation = 0.09866671713699776,
    timeTotal = 1.436676041102952
end SimulationResult;
record SimulationResult
    resultFile = \"S:/Scratch/OMBugs/maxminbug_res.mat\",
    simulationOptions = \"startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'maxminbug', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-lv=LOG_INIT -iim=none'\",
    messages = \"LOG_INIT          | info    | ### START INITIALIZATION ###
LOG_INIT          | info    | updating min-values
|                 | |       | | x(min=-6.25)
LOG_INIT          | info    | updating max-values
|                 | |       | | x(max=6.25)
LOG_INIT          | info    | updating nominal-values
LOG_INIT          | info    | updating start-values
LOG_INIT          | info    | initialization method: none            [sets all variables to their start values and skips the initialization process]
LOG_INIT          | info    | parameter values
|                 | |       | | real parameters
|                 | |       | | | [1] parameter Real L(start=2.5, fixed=true) = 2.5
|                 | |       | | | [2] parameter Real a(start=0.24, fixed=true) = 0.24
LOG_SOTI          | info    | ### SOLUTION OF THE INITIALIZATION ###
|                 | |       | | states variables
|                 | |       | | | [1] Real x(start=1, nominal=1) = 6.25 (pre: 1)
|                 | |       | | | [2] Real y(start=0, nominal=1) = 0 (pre: 0)
|                 | |       | | derivatives variables
|                 | |       | | | [3] Real der(x) = 0 (pre: 0)
|                 | |       | | | [4] Real der(y) = 0 (pre: 0)
LOG_INIT          | info    | ### END INITIALIZATION ###
\",
    timeFrontend = 0.00790769575244046,
    timeBackend = 0.0009164856097003121,
    timeSimCode = 0.0007208061480562133,
    timeTemplates = 0.02231804456551621,
    timeCompile = 1.278270309042027,
    timeSimulation = 0.08834574828628097,
    timeTotal = 1.398650068343458
end SimulationResult;
"
Warning: The initial conditions are not fully specified. Use +d=initialization for more information.

This bug also shows up in testsuite/simulation/modelica/initialization/bug_2207.mos if the nominal attribute is not set.

Produced using r23393 and somewhat earlier.

Change History (10)

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

Component: UnknownRun-time

The init-file seems to have start=1.0, so this should be a run-time issue since the generated initial equation is x=$_start(x).

comment:2 by Martin Sjölund, 10 years ago

Cc: Lennart Ochel added
Owner: changed from somebody to Willi Braun
Status: newassigned

comment:3 by Lennart Ochel, 10 years ago

Owner: changed from Willi Braun to Lennart Ochel
Status: assignedaccepted

comment:4 by Lennart Ochel, 10 years ago

Resolution: fixed
Status: acceptedclosed

Thank you for this very helpful bug report. I added your test to the test suite and fixed the issue with r23423.

comment:5 by crupp@…, 10 years ago

You guys are awesome! Thank you for the quick fix and for the great work in general.

comment:6 by anonymous, 10 years ago

Resolution: fixed
Status: closedreopened

comment:7 by Lennart Ochel, 10 years ago

Status: reopenedaccepted

The issue is that the symbolic jacobian for a state set is calculated before all required parameters are initialized properly, which leads to the division by zero.

in reply to:  6 comment:8 by Lennart Ochel, 10 years ago

Resolution: fixed
Status: acceptedclosed

Replying to anonymous:

r23423 breaks PlanarMechanics examples (see https://test.openmodelica.org/hudson/job/PlanarMechanics_Simulation/302/).

I opened a new ticket (#3064) for this, since it is not connected to the original problem.

comment:9 by Dietmar Winkler, 9 years ago

Milestone: Futurepre1.9.4

It doesn't make sense to keep closed ticket in the "Future" milestone that were simply forgotten to assign to the correct milestone in the past.

comment:10 by Martin Sjölund, 7 years ago

Milestone: pre1.9.41.9.4

Removing the pre1.9.4 milestone in favor of 1.9.4.

Note: See TracTickets for help on using tickets.