VtkAnim

From OpenFOAMWiki

Saving selected field variables in selected surfaces in your computational domain into time-directories is a functionality provided in the official release of OpenFOAM. This is a small contribution that will help you use that functionality to generate animations. By using the Python script below, the files in the saved time-directories will be copied and renamed in a fashion that will allow ParaView to interpret the save-outs as a time series.

This was tested to work in OF1.5, using ParaView 3.3 and Python 2.4.3 in a Linux environment.

Usage

1. Modify the following to suite your case and add to your $FOAM_CASE/system/controlDict-file:

 
functions
(
    planes
    {
        type surfaces;
        functionObjectLibs ("libsampling.so");
        interval 100;
        surfaceFormat vtk;
        fields
        (
            U
            p
        );
        surfaces
        (
            xz
            {
                type            plane;
                basePoint	(1e-5 1e-5 1e-5);
                normalVector	(0 1 0);
                triangulate     false;
            }
            yz
            {
                type            plane;
                basePoint	(1e-5 1e-5 1e-5);
                normalVector	(1 0 0);
                triangulate     false;
            }
        );
    }
);

Upon runtime, the selected surfaces with sampled field variables will be saved in time-directories in the directory $FOAM_CASE/planes/ in vtk format.

2. Download this tar file and unpack it to your $FOAM_USER_APPBIN directory. Executing 'vtkAnim.py' in the $FOAM_CASE/planes/ directory will then conveniently copy the vtk-files in the time-directories to the $FOAM_CASE/planes/ directory and add a count-number to each file.

3. Start ParaView and go to the $FOAM_CASE/planes/ directory. Now you can open each saved variable as a time series.

Hints: To save disk space and your precious time, you can change 'shutil.copy2' to 'os.rename' near the end of the script. Then, the vtk-files will be moved instead of copied. This would be particular useful if you download the time-directories from a cluster. But if you do this in your running simulation directory, you will have trouble to make longer animations at a later time.

ParaView will open the data as cell data. If you prefer point data, just apply the filter "Cell data to point data" provided in ParaView.