Opened 5 years ago

Closed 5 years ago

#5807 closed defect (fixed)

Start value for final parameters with fixed=false is ignored

Reported by: Francesco Casella Owned by: Andreas Heuermann
Priority: blocker Milestone: 1.16.0
Component: Run-time Version:
Keywords: Cc: Karim Adbdelhak

Description (last modified by Karim Adbdelhak)

Consider the following model (also attached)

model TestInitStart
  final parameter Real p(start = p_start, fixed = false);
  parameter Real p_start = -2;
initial equation
 (p - 1)*p*(p+2) = 0;
annotation(__OpenModelica_simulationFlags(lv=LOG_NLS_V));
end TestInitStart;

The Newton solver log clearly shows that the iterations start at p = 0, not at p = -2 as expected, leading the convergence to the wrong solution.

This issue is preventing me to initialize in steady-state the big power plant model that I will present at the OpenModelica Workshop next week, so fixing this issue is currently top priority to show that OpenModelica can handle such real-life, complex models effectively.

Attachments (2)

TestInitStart.mo (234 bytes ) - added by Francesco Casella 5 years ago.
TestInitStartEvaluate.mo (324 bytes ) - added by Francesco Casella 5 years ago.

Download all attachments as: .zip

Change History (22)

by Francesco Casella, 5 years ago

Attachment: TestInitStart.mo added

comment:1 by Francesco Casella, 5 years ago

Update: I just found a workaround: if I add -d=evaluateAllParameters, then the model works as expected.

Maybe gives you some clues so as to how to fix the issue.

Unfortunately I cannot use this workaround of the big model because it causes a new frontend failure related to homotopy. Life's hard.

Last edited 5 years ago by Francesco Casella (previous) (diff)

by Francesco Casella, 5 years ago

Attachment: TestInitStartEvaluate.mo added

comment:2 by Karim Adbdelhak, 5 years ago

It seems like the compiler drops all fixed=false start values. That is correct for general initialization (in the sense that no initial equation is generated) but not for solving loops in the initialization problem.

I have a pretty good idea where to look!

comment:3 by Lennart Ochel, 5 years ago

This might be synchronized with the OpenModelica FMI 2.0 export. There are strict rules for start values defined. Sounds bad to implement it twice.

comment:4 by Karim Adbdelhak, 5 years ago

Description: modified (diff)

comment:5 by Karim Adbdelhak, 5 years ago

I prepared a fix that is not the best solution but better than what we got now. PR700 Hopefully Jenkins does not reject these changes.

Start values for calculated parameters will be evaluated. They won't have any influence unless the parameter will be evaluated in a nonlinear loop. Unfortunately changing p_start after compilation will not change the start value of p because they have been decoupled. To keep this coupling we would need to change how the _init.xml is accessed. Possible but quite a lot of work.

Long story short: It should work always if the model is compiled from scratch. Influencing the values of parameters that influence start values after compilation might not always work out as expected.

Maybe i will add a warning for now.

Last edited 5 years ago by Karim Adbdelhak (previous) (diff)

in reply to:  3 comment:6 by Karim Adbdelhak, 5 years ago

Replying to lochel:

This might be synchronized with the OpenModelica FMI 2.0 export. There are strict rules for start values defined. Sounds bad to implement it twice.

I actually slightly modified your code for my changes, maybe you want to have a look.

in reply to:  5 comment:7 by Vitalij Ruge, 5 years ago

Replying to Karim.Abdelhak:

Start values for calculated parameters will be evaluated. They won't have any influence unless the parameter will be evaluated in a nonlinear loop. Unfortunately changing p_start after compilation will not change the start value of p because they have been decoupled. To keep this coupling we would need to change how the _init.xml is accessed. Possible but quite a lot of work.

Maybe #2207 is interesting.

comment:8 by Francesco Casella, 5 years ago

Local workaround:

model TestInitStart
  final parameter Real p(start = p_start, fixed = false);
  parameter Real p_start = -2 annotation(Evaluate=true);
initial equation
 (p - 1)*p*(p+2) = 0;
annotation(__OpenModelica_simulationFlags(lv=LOG_NLS_V));
end TestInitStart;

comment:9 by Francesco Casella, 5 years ago

Unfortunately this doesn't work on the big test case. If I switch on -d=evaluateAllParameters, the front end gives me

final parameter Real Plant.u_Tin_RHA(unit = "1", start = -0.24, fixed = false);

so the start value parameter has been evaluated to the literal value -0.24, but then the nonlinear solver still fails and the run-time diagnostic message still gives

proper start-values for some of the following iteration variables might help
...
[329] Real Plant.u_Tin_RHA(start=?, nominal=?)
...

as it did before when i did not evaluate the parameter containing the start value.
No idea where these question marks come from and what they mean. The LOG_NLS_V output shows an initial guess of zero, which badly breaks the convergence.

comment:10 by Francesco Casella, 5 years ago

See comment in PR 700 on how to fix this.

comment:11 by Karim Adbdelhak, 5 years ago

Possible fix in PR744. Works for the minimal model and does not seem to break anything i tried.

comment:12 by Karim Adbdelhak, 5 years ago

One test fails with an assertion at initialization: ThermoPower.Test.DistributedParameterComponents.TestWaterFlow1DFV2ph

If have to look deeper into it to know what is happening.

comment:13 by Karim Adbdelhak, 5 years ago

The test is fixed. To shortly summarize what i did in pseudo code:

Usually each iteration variable of a nonlinear loop is initialized with the corresponding value:

 iter_var[0] = realParam[3] /* p */
 iter_var[1] = realParam[0] /* tank.y */
  ...

These values have been set before by the init_xml file for initialization and in all other cases they grab the previous value of the variable to initialize the solver. If the start value could not be evaluated to a constant, there is no value in the init_xml and therefore it will be initialized with 0.

I changed it such that for the very first call during initialization, the generated loop grabs the start expression, if it could not be evaluated to be constant. E.g. the start value of p could be p_start.

 iter_var[0] = realParam[4] /* p_start */ 
 iter_var[1] = realParam[0] /* tank.y */
  ...

Note that only the very first call should be like this, so if there is a lambda_0 system for homotopy it has to be done there and the regular initial system has to grab the regular variable as described (this was the error for ThermoPower.Test.DistributedParameterComponents.TestWaterFlow1DFV2ph).

I am just tackling one last problem which is just an OS problem to push everything. Should be done by tomorrow.

comment:14 by Francesco Casella, 5 years ago

Excellent, I'm looking forward to this. BTW, we still have many initialization failures in our testsuite, maybe this helps fixing other issues.

comment:15 by Karim Adbdelhak, 5 years ago

It introduced some problems with the Chemical library. Hopefully fixed with PR746

comment:16 by Francesco Casella, 5 years ago

OK, thanks! Just started the ripper newInst job. If everything works fine I'll make a windows nightly build and check with the FlexiCaL model

Last edited 5 years ago by Francesco Casella (previous) (diff)

in reply to:  16 comment:17 by Karim Adbdelhak, 5 years ago

Replying to casella:

OK, thanks! Just started the ripper newInst job. If everything works fine I'll make a windows nightly build and check with the FlexiCaL model

Did the build crash?

comment:18 by Francesco Casella, 5 years ago

Yes, unfortunately @sjoelund.se's attempted fix to the problem of no longer operational daeMode tests didn't work properly, see https://github.com/OpenModelica/OpenModelicaLibraryTesting/commit/02329a8cfe974319003e011b1df5c01455c00973#commitcomment-37507759.

comment:19 by Karim Adbdelhak, 5 years ago

How did the tests go? Are there still regressions? I lost the trace, original problem should be solved!

comment:20 by Francesco Casella, 5 years ago

Resolution: fixed
Status: newclosed

The original problem was solved, now I can get this to run correctly without setting evaluateParameters = true.

I am currently unable to test the FlexiCaL model due to lack of time, I will reopen this ticket if necessary.

Thanks!

Note: See TracTickets for help on using tickets.