Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize model with previous simulation solution?

Having run out of ideas again I turn to you.

I'm sure this has to have been answered before though for the life of me I can't find a clear description of it.

Scenario:

You work hard to get a model all set up with initial guesses, etc., and then solve for the 'real' steady state (SS) condition of all parameters in the model. From this solution I want to investigate events effects on the system.

To perform this deviation from SS analysis, it would be expedient to be able to simply load the SS solution .mat file with all the model parameters that is already generated by Dymola. Loading this solution removes any need to first simulate the model to achieve the SS solution before performing the deviations from the SS investigations. I can conceive that a possible step at which this takes place is during the 'Initialization' phase of the simulation.

Given that this would seem to be an important concept, I imagine that this idea would have been considered from a very early stage of Modelica/Dymola development. Manual extraction of each individual parameter does not seem proper given that the size of these models quickly become very large.

Question:

  1. Is it possible to solve for the state of your model (.mat file) and then load that simulation as the 'initial' values of all variables? (this would override/replace the previous initial guesses in the system)
  2. If it is possible, how is this achieved? (run some script, some hidden menu option, add some sort of import command in model/simulation?)

I very much appreciate your help. I am using Dymola 2016.

like image 438
Scott G Avatar asked Jan 07 '16 17:01

Scott G


1 Answers

I have found the following answers to my own questions posted above.

Edit: matth also pointed to the following helpful reference on the subject: http://claytex.com/blog/how-to-restart-a-simulation

These are instructions for Dymola. I cannot verify if they are applicable to other Modelica based programs. I also found some documentation in the Dymola User Manual Volume 1 Section 5.3.3 Simulation > Continue > Import Initial/Continue.

1) Yes it is possible to start your model from the generated .mat file. You can also continue it from the dsfinal.txt file.

2) Below are the steps using the GUI:

  • Backup the 'YOUR_MODEL.mat' file (e.g. YOUR_MODEL_orig.txt). Once you have run the simulation a new .mat file will be created and you probably don't want to overwrite it by accident.
  • Translate your model.
  • In the ribbon, go to Simulation > Continue > Import Initial. Select the .mat file from which you want to continue the simulation.
  • A prompt will be generated requested a time input with a specified range given. This allows you to continue the simulation at any point in time within the .mat simulation results.
  • Go to Simulation Setup and select the new simulation parameters. If you want the solution to register a start time of 0 rather than some large number associated with the Initial SS simulation than update the 'Start time' to 0. This does not affect the initial time used for parameter data from the Model_Sim.mat file.
  • Now simulate the model. A new .mat file will be generated starting off from the point you specified.

Alternative method: (an odd thing though with this method no .mat file seems to be generated or updated.)

  • Backup the 'dsfinal.txt' file (e.g. dsfinal_orig.txt). Once you have run the simulation a new dsfinal.txt file will be created and you probably don't want to overwrite it by accident.
  • Translate your model.
  • In the ribbon, go to Simulation > Continue > Continue. Simulation will start using whatever dsfinal.txt file is on the path once this option is pressed.
  • The simulation will now continue from where the final conditions of the simulation that generated the dsfinal.txt file.
  • If it is desired to start at time 0 then the dsfinal.txt file can be modified (line 9, 10, and 12 for me) which corresponds to simulation start (9), stop (10) , and number of timesteps (12). This appears to do the trick.
like image 132
Scott G Avatar answered Sep 26 '22 02:09

Scott G