Difference between revisions of "VtkAnim"

From OpenFOAMWiki
(Created page with '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…')
 
m
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
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 to 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.
+
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'''
 
'''Usage'''
  
1. Modify the following to suite your case and add to your system/controlDict-file:
+
1. Modify the following to suite your case and add to your $FOAM_CASE/system/controlDict-file:
  
 
<bash>
 
<bash>
Line 12: Line 13:
 
     {
 
     {
 
         type surfaces;
 
         type surfaces;
 +
        functionObjectLibs ("libsampling.so");
 
         interval 100;
 
         interval 100;
 
         surfaceFormat vtk;
 
         surfaceFormat vtk;
Line 40: Line 42:
 
</bash>
 
</bash>
  
This will create a directory named planes/ in your case directory. When the case is running, the selected cross section surfaces with sampled field variables will be saved as time directories in planes/ in vtk format.
+
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. Executing this Python script will conveniently copy the vtk-files in the time directories to the planes/ directory and add a count-number to each file. By doing this, ParaView will recognize these data fields as time series.
+
2. Download [[Media:vtkAnim.tar|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 planes/ directory. There you can open each saved variable as a time series.
+
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' in the last line of the script. Then, the vtk-files will be renamed 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, you will have trouble to make a longer animation later.
+
''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, which is troublesome for vectors. By using the filter "Cell data to point data" provided in ParaView, this is easily solved
+
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.

Latest revision as of 05:57, 12 April 2010

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.