How to create a restart (python) file

From KratosWiki
Jump to: navigation, search

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.

Warn_icon.gif Warning. Please, note that:

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 file which is the main for our GiD example. We will now modify it in order to obtain a and a The first one is run instead of the normal 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.


How to create a

The 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,, 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

The 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 file from the file basically because when running the we want to continue writing the restart files.

So, first of all take your, change its name in and follow the following steps

Read the model fom a .rest

Let's suppose the restart file we want to read from is called 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 is read as initialization file.

In case of using the DEBUG mode in the file BE SURE TO USE THE SAME IN THE, 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

the save and load cases of the edgebased application ( and respectively). You can also compare the differences with the default script generated by the problem type

Personal tools