Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...