How to create a restart (python) file
(→Sample files) |
|||
Line 1: | Line 1: | ||
− | |||
In this section how create a restart file for your gid example is explained. In other words it is shown how to adapt the script file of your problemtype to obtain a save and load files. At the end of the page there exists the possibility to download the restart files in the case of the edgebased application and to compare it with the default script generated by the problem type. | In this section how create a restart file for your gid example is explained. In other words it is shown how to adapt the script file of your problemtype to obtain a save and load files. At the end of the page there exists the possibility to download the restart files in the case of the edgebased application and to compare it with the default script generated by the problem type. | ||
Line 54: | Line 53: | ||
== How to create a '''script_load.py''' == | == How to create a '''script_load.py''' == | ||
− | The | + | The script_load.py is the file you will run when you want to initialize your GiD example with one of the .rest files, or in other words when you want to restart your problem. |
It is very recommended to derive the script_load.py file from the script_save.py file basically because when running the script_load.py we want to continue writing the restart files. | It is very recommended to derive the script_load.py file from the script_save.py file basically because when running the script_load.py we want to continue writing the restart files. |
Latest revision as of 14:33, 11 April 2012
In this section how create a restart file for your gid example is explained. In other words it is shown how to adapt the script file of your problemtype to obtain a save and load files. At the end of the page there exists the possibility to download the restart files in the case of the edgebased application and to compare it with the default script generated by the problem type.
Please provide that all the elements and conditions you are using have been already prepared to use the SERIALIZER. If not, please refer to How to use Serialization before proceeding. |
Let's suppose to have a script.py file which is the main for our GiD example. We will now modify it in order to obtain a script_save.py and a script_load.py.
The first one is run instead of the normal script.py in order to write the restart file or files. The second one is run when we want to re-initialize our example reading from one of the restart files already generated.
Contents |
How to create a script_save.py
The script_save.py will be use only in the case of an example run from zero. The modification that should be introduced are the following:
Before starting the loop over time two parameters should be defined:
time_to_restart = 0.0 restart_interval = 2.0
The first is a counter that is always set to zero, the second one indicates the time interval at which the code will write a restart file.
Consider that writing a restart file is a VERY time consuming procedure!!!
Every time the time variable is updated, also the time_to_restart variable is
time = time + Dt time_to_restart = time_to_restart + Dt
Last thing to do is to write the restart file when time_to_restart restart_interval
if(time_to_restart > restart_interval): serializer = Serializer(input_file_name + str(time)) serializer.Save("ModelPart", model_part); serializer = 0 time_to_restart = 0.0
It is important to set to zero the time_to_restart variable.
By using the form Serializer(input_file_name + str(time)) the restarts files will be named as the example name (input file name) plus the simulation time of the restart. The extension will be .rest.
Just as an example if I run the case1.gid and I set to write a restart every 1 second of simulation and the problem crashes at 3.5 seconds of simulation, I will get the case1_1.rest, case1_2.rest, case1_3.rest restarts files to use.
There is a second choice, useful at the beginning, when trying to DEBUG your restart file. You can use the SERIALIZER_TRACE_ALL and write the following
if(time_to_restart > restart_interval): serializer = Serializer(input_file_name,SERIALIZER_TRACE_ALL) serializer.Save("ModelPart", model_part); serializer = 0 time_to_restart = 0.0
This form is much slower than the first one but help debugging tracing all the errors found by the serializer.
How to create a script_load.py
The script_load.py is the file you will run when you want to initialize your GiD example with one of the .rest files, or in other words when you want to restart your problem.
It is very recommended to derive the script_load.py file from the script_save.py file basically because when running the script_load.py we want to continue writing the restart files.
So, first of all take your script_save.py, change its name in script_load.py and follow the following steps
Read the model fom a .rest
Let's suppose the restart file we want to read from is called case1_3.rest. First of all we have to comment out the line where reading the original model:
COMMENTED OUT: ReadModelPart(model_part)
and substitute it with
serializer = Serializer("case1_3") serializer.Load("ModelPart", model_part);
where in the first line the serializer is called and the case1_3.rest is read as initialization file.
In case of using the DEBUG mode in the script_save.py file BE SURE TO USE THE SAME IN THE script_load.py, that means to write
serializer = Serializer(input_file_name,SERIALIZER_TRACE_ERROR) serializer.Load("ModelPart", model_part);
Comment out the AddVariable function
Be sure to comment out the AddVariable function. The restart file already knows all the variables used.
COMMENTED OUT: solver.AddVariables(model_part)
Comment out all the variables initialization
Being a restart file all the initializations should be commented out.
COMMENTED OUT: all the VARIABLES initializations
All the forms like "if step < 3 do not consider the results"
Check the counters initialization (if connected with time)
Pay particular attention to the initialization of all the variables connected with the simulation time, such as, for instance time, step, output_dt and so on.
Time should not be initialized by 0 but should be read directly from the ProcessInfo
time = fluid_model_part.ProcessInfo[TIME]
If usually you write your results at time = 0.0 and then every output_dt custom value, you should change the counter
output_dt = VALUE next_output_time = 0.0
to the following form
output_dt = VALUE next_output_time = time
Sample files
You can download here
media:Edgebased_RestartFiles.zip
the save and load cases of the edgebased application (edgebased_serializer_save.py and edgebased_serializer_load.py respectively). You can also compare the differences with the default script generated by the problem type edgebased_original_script.py.