PLUTO  4.4-patch2
Functions
write_vtk.c File Reference

Write data in VTK format. More...

#include "pluto.h"

Functions

void WriteVTK_Header (FILE *fvtk, Grid *grid)
 
void WriteVTK_Vector (FILE *fvtk, Data_Arr V, double unit, char *var_name, Grid *grid)
 
void WriteVTK_Scalar (FILE *fvtk, double ***V, double unit, char *var_name, Grid *grid)
 

Detailed Description

Collection of basic functions to write legacy VTK binary files. Files can be written in serial or parallel mode and consists of the basic five parts :

  1. File version and identifier
  2. Header, consisting of a string
  3. File format
  4. Dataset structure: describes the geometry and topology of the dataset
  5. Dataset attributes. This section is used to write the actual binary data as a vector or scalar data

The mesh topology and the variable datasets are written using single precision (4 bytes) binary format. VTK file are written following big endian order. Therefore, we swap endianity only if local architecture has little endian ordering.

The WriteVTK_Header() function provides the basic functionality for steps 1, 2, 3 and 4. Only processor 0 does the actual writing. For cartesian/cylindrical geometries the default grid topology is rectilinear grid (VTK_RECTILINEAR_GRIDS) whereas for polar/spherical we employ structured grid (VTK_STRUCTURED_GRID) to provide a convenient mapping to a cartesian mesh.

Note for 2D datasets: in order to produce a strictly 2D dataset we always set the third coordinate (x3) to zero. For this reason, in 2D spherical cordinates we swap the role of the "y" and "z" coordinates.

The WriteVTK_Vector() is fully parallel and is used to write data with the vector attribute (by default these include velocity and magnetic fields).

The WriteVTK_Scalar() is fully parallel and is used to write data with the scalar attribute (by default these include density, pressure, tracer and user-defined variables).

Reference

http://www.vtk.org/VTK/img/file-formats.pdf

Author
A. Mignone (migno.nosp@m.ne@t.nosp@m.o.inf.nosp@m.n.it)
Date
Jun n11, 2021

Function Documentation

◆ WriteVTK_Header()

void WriteVTK_Header ( FILE *  fvtk,
Grid grid 
)

Write VTK header in parallel or serial mode. In parallel mode only processor 0 does the actual writing (see al_io.c/AL_Write_header).

Parameters
[in]fvtkpointer to file
[in]gridpointer to an array of Grid structures
Todo:
Write the grid using several processors.

◆ WriteVTK_Scalar()

void WriteVTK_Scalar ( FILE *  fvtk,
double ***  V,
double  unit,
char *  var_name,
Grid grid 
)

Write VTK scalar field.

Parameters
[in]fvtkpointer to file (handle)
[in]Vpointer to 3D data array
[in]unitthe corresponding cgs unit (if specified, 1 otherwise)
[in]var_namethe variable name appearing in the VTK file
[in]gridpointer to an array of Grid structures

◆ WriteVTK_Vector()

void WriteVTK_Vector ( FILE *  fvtk,
Data_Arr  V,
double  unit,
char *  var_name,
Grid grid 
)

Write VTK vector field data. This is enabled only when VTK_VECTOR_DUMP is set to YES. For generality purposes, vectors are written always with 3 components, even when there're only 2 being used.

The following Maple script has been used to find vector components from cyl/sph to cartesian:

restart;
with(linalg);
Acyl := matrix (3,3,[ cos(phi), sin(phi), 0,
-sin(phi), cos(phi), 0,
0 , 0 , 1]);
Asph := matrix (3,3,[ sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta),
cos(theta)*cos(phi), cos(theta)*sin(phi), -sin(theta),
-sin(phi) , cos(phi) , 0]);
Bcyl := simplify(inverse(Acyl));
Bsph := simplify(inverse(Asph));
Parameters
[in]fvtkpointer to file
[in]Va 4D array [nv][k][j][i] containing the vector components (nv) defined at cell centers (k,j,i). The index nv = 0 marks the vector first component.
[in]unitthe corresponding cgs unit (if specified, 1 otherwise)
[in]var_namethe variable name appearing in the VTK file
[in]gridpointer to an array of Grid structures