Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#5824 closed defect (fixed)

Import start values from existing simulations run with other tools

Reported by: casella Owned by: 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)

ImportInitialValues.mo (1.7 KB) - added by casella 4 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by casella

  • Milestone changed from 1.16.0 to 1.17.0

1.16.0 feature freeze is imminent, new developments postponed to 1.17.0

comment:2 Changed 4 years ago by casella

Check the forum about this topic

comment:3 Changed 4 years ago by casella

@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 their values from the external file.

This 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.

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 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 -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 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.

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; 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.

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 now v2 = x = 4

The last two models ImportModelAnnotationInitialEqs and ImportModelAnnotationNoInitialEqs demonstrate how to get the same results via annotations.

Last edited 4 years ago by casella (previous) (diff)

Changed 4 years ago by casella

comment:4 Changed 4 years ago by casella

  • Owner changed from lochel to casella
  • Status changed from new to assigned

comment:5 Changed 4 years ago by casella

  • Resolution set to fixed
  • Status changed from assigned to closed

comment:6 Changed 4 years ago by casella

See also #6039

comment:7 Changed 4 years ago by casella

See #6097 for a proposal on how to store the required values in a vendor annotation

Note: See TracTickets for help on using tickets.