Changes between Initial Version and Version 1 of Ticket #5824, comment 3


Ignore:
Timestamp:
2020-06-27T17:04:27Z (4 years ago)
Author:
Francesco Casella

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #5824, comment 3

    initial v1  
    11@daniel, I made some analysis, and I think a solution for you should already be available in 1.16.0. In fact, there are two options.
    22
    3 The first option is that the simulation starts by '''solving the initial equations''', that determine the values of all variables and derivatives, as well as of all parameters with {{{fixed = false}}}, but yet '''using start values imported from a previous simulation'''. Parameters with {{{fixed = true}}} will also get the imported values.
     3The first option is that the simulation starts by '''solving the initial equations''', that determine the values of all variables and derivatives, as well as of all parameters with {{{fixed = false}}}, but yet '''using start values imported from a previous simulation'''. Parameters with {{{fixed = true}}} will also get their values from the external file.
    44
    5 This ensures that any implicit nonlinear equation in the initialization problem, e.g. nonlinear steady-state equation, is solved using the imported start values to provide initial guesses to the iteration variables. This is very handy if OpenModelica selects different iteration variables than, say, Dymola, because then the right values obtained by the simulation result in Dymola will be picked and the convergence will be successful.
     5This ensures that any implicit nonlinear equation in the initialization problem, e.g. nonlinear steady-state equations, is solved using the imported start values to provide initial guesses to the iteration variables. This is very handy if OpenModelica selects different iteration variables than, say, Dymola, because then the right values obtained by the simulation result in Dymola will be picked and the convergence will be successful.
    66
    77This first option is achieved by setting the [https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/simulationflags.html#simflag-iif -iif=<resultfile.mat>] simulation flag. The flag can be embedded in an [https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/omedit.html#openmodelica-simulationflags-annotation __OpenModelica_simulationFlags(iif="filename.mat")] annotation in the model, or set in OMEdit by means of the ''Simulation Setup | Simulation Flags | Equation System Initialization File'' input field. You can also specify at which time in that file the values should be picked via [https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/simulationflags.html#simflag-iit -iit=initialTimeValue], or set it in OMEdit by means of the ''Simulation Setup | Simulation Flags | Equation System Initialization Time''
    88
    9 The second option is to '''skip the solution of the initial equations entirely''', and to directly '''start the simulation using the imported start values'''. In this case, the values of all parameters and the initial values of states are exactly the same as the ones in the import file, irrespective of the initial equations, while the values of algebraic variables will be used to initialize iteration variables in nonlinear implicit equations, or otherwise ignored. This requires, in addition to what explained for the first option, to also set [https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/simulationflags.html#simflag-iim -iim=none], or to set 'none' in ''Simulation Setup | Simulation Flags | Initialization Method''
     9The second option is to '''skip the solution of the initial equations entirely''', and to directly '''start the simulation using the imported start values'''. In this case, the values of all parameters and the initial values of states are exactly the same as the ones in the import file, irrespective of the initial equations, while the values of algebraic variables in the imported file will be used to initialize iteration variables in nonlinear implicit equations of the simulation model, or otherwise ignored. This requires, in addition to what explained for the first option, to also set [https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/simulationflags.html#simflag-iim -iim=none], or to set 'none' in ''Simulation Setup | Simulation Flags | Initialization Method''
    1010
    1111These two options are demonstrated in the attached test package.
     
    1313The model {{{ResultGenerator}}} can be run to generate an {{{initial.mat}}} file containg the following initial values: {{{v1 = 2.8}}}, {{{v = 3.9}}}, {{{x = 4}}}, {{{p1 = 7}}}, {{{p2 = 10}}}.
    1414
    15 Consider now {{{ImportModel}}}. If you run it with the embedded start values and initial equations, {{{v1}}} converges to 15, which is the closest solution of the implicit nonlinear equation to the start value of 14. The state {{{x}}} is initialized to 6 by the initial equation. The closes solution {{{v2}}} to the start value 14 is {{{v2 = 15}}}, which is the obtained result. The values of parameters are {{{p1 = 1}}}, {{{p2 = 1}}}, and {{{p3 = 3*p1 = 3}}}.
     15Consider now {{{ImportModel}}}. If you run it with the embedded start values and initial equations, {{{v1}}} converges to 15, which is the closest solution of the implicit nonlinear equation to the start value of 14. The state {{{x}}} is initialized to 6 by the initial equation. The solution for {{{v2}}} to the start value 14 is {{{v2 = 15}}}, which is the obtained result. The values of the three parameters, which have all {{{fixed = true}}} by default, are given by the binding equations {{{p1 = 1}}}, {{{p2 = 1}}}, and {{{p3 = 3*p1 = 3}}}.
    1616
    17 If you now choose the first option, i.e. only import {{{initial.mat}}} to provide the start values, but still solve the initial equations, the initial state value will remain the same as before {{{x = 6}}} because of the initial equation; the two fixed non-final parameters will now be imported from the file, {{{p1 = 7}}}, {{{p2 = 10}}}, while the final parameter will be computed by the binding equation as {{{p3 = 3*p1 = 21}}}. The implicit algebraic equations will now be solved using the imported start values {{{v1 = 2.8}}}, {{{v = 3.9}}} as initial guesses, thus the solver initially converges to the closest solutions {{{v1 = 3}}} and {{{v2 = x = 6}}}. The start value of {{{v3}}} is ignored, because {{{v3}}} is directly determined by an equation that can be solved explicitly, so it doesn't depend on start values.
     17If you now choose the first option, i.e. only import {{{initial.mat}}} to provide the start values, but still solve the initial equations, the initial state value will remain the same as before {{{x = 6}}}, because of the initial equation. The two fixed non-final parameters will now be imported from the file, {{{p1 = 7}}}, {{{p2 = 10}}}, while the final parameter will be computed by the binding equation as {{{p3 = 3*p1 = 21}}}; final binding equations cannot be undone, so the imported value of {{{p3}}} is ignored. The implicit algebraic equations will now be solved using the imported start values {{{v1 = 2.8}}}, {{{v = 3.9}}} as initial guesses, thus the solver initially converges to the closest solutions {{{v1 = 3}}} and {{{v2 = x = 6}}}. The start value of {{{v3}}} is ignored, because {{{v3}}} is directly determined by an equation that can be solved explicitly, so it doesn't depend on start values.
    1818
    19 By choosing the second option, instead, besides the two fixed non-final parameters {{{p1 = 7}}} and {{{p2 = 10}}}, also the initial state {{{x = 4}}} is imported from the file. When the simulation starts, the start value of 2.8 causes {{{v1}}} to converge to the nearest solution {{{v1 = 3}}}, while the start value of 3.9 will cause {{{v2}}} to converge to the nearest solution, which is {{{v2 = x = 4}}}
     19By choosing the second option, instead, besides the two fixed non-final parameters {{{p1 = 7}}} and {{{p2 = 10}}}, also the initial state {{{x = 4}}} is imported from the file. When the simulation starts, the start value of 2.8 causes {{{v1}}} to converge to the nearest solution {{{v1 = 3}}}, while the start value of 3.9 will cause {{{v2}}} to converge to the nearest solution, which is now {{{v2 = x = 4}}}
    2020
    2121The last two models {{{ImportModelAnnotationInitialEqs}}} and {{{ImportModelAnnotationNoInitialEqs}}} demonstrate how to get the same results via annotations.