#5824 closed defect (fixed)
Import start values from existing simulations run with other tools
Reported by: | Francesco Casella | Owned by: | Francesco Casella |
---|---|---|---|
Priority: | blocker | Milestone: | 1.17.0 |
Component: | Run-time | Version: | |
Keywords: | Cc: | daniel.bouskela@… |
Description
When migrating models from other Modelica tools to OMC, issues can arise at initialization because different iteration variables (hence start values) are picked.
We should have some easy means to import the results of the previous simulations into OMC for this purpose.
@lohel, I understand a functionality to import .mat files for this purpose is already available, but it's not widely advertised. Could you please comment on it here.
It should be more clearly addressed in the User's Guide, and possibly also directly supported in the OMEdit GUI.
Attachments (1)
Change History (8)
comment:1 by , 4 years ago
Milestone: | 1.16.0 → 1.17.0 |
---|
comment:3 by , 4 years ago
@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.
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.
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.
This first option is achieved by setting the -iif=<resultfile.mat> simulation flag. The flag can be embedded in an __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 -iit=initialTimeValue, or set it in OMEdit by means of the Simulation Setup | Simulation Flags | Equation System Initialization Time
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 -iim=none, or to set 'none' in Simulation Setup | Simulation Flags | Initialization Method
These two options are demonstrated in the attached test package.
The 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
.
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
.
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.
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
The last two models ImportModelAnnotationInitialEqs
and ImportModelAnnotationNoInitialEqs
demonstrate how to get the same results via annotations.
by , 4 years ago
Attachment: | ImportInitialValues.mo added |
---|
comment:4 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:7 by , 4 years ago
See #6097 for a proposal on how to store the required values in a vendor annotation
1.16.0 feature freeze is imminent, new developments postponed to 1.17.0