CFD Online Discussion Forums

CFD Online Discussion Forums (
-   ParaView (
-   -   Paraview Vector Field (

simone Marras February 10, 2007 12:38

Paraview Vector Field
Hello, I need help: with my code I generate 2 output files with the values of the U and V component of a vector field on my computational grid. How do I view the vector field given by the twe velocity components written in the output files? What type of file do I need to write for paraview to see it? do I need 2 scalar field? one scalar file with the 2 matrix components of U and V? I tried to understand it from the User guide, but it is not clear for this purpose. Also, once I figured out how to view one vector field at time step t(n), how can I tell Paraview to subsequently open all of the files to generate a movie?

Thank you very much,

best regards

simone marras

simone Marras February 11, 2007 09:15

Re: Paraview Vector Field: SOLVED
I solved it already, and here the C function to write the correct format file for those who need it.


void PRINT_VECT_VTK(int imax, int jmax, char *vector_field_name, float **U, float **V, float *x, float *y) {

int i,j,k;

int nx,ny,nz;

float z = 0.0;

FILE *vect_field;

nx = imax;

ny = jmax;

nz = 1;

/* File grid.vtk*/

if((vect_field = fopen(vector_field_name, "w")) == NULL)

printf("The grid file could not be open\n");


fprintf(vect_field, "# vtk DataFile Version 2.0\n");

fprintf(vect_field, "Sample rectilinear grid\n");

fprintf(vect_field, "ASCII\n");

fprintf(vect_field, "DATASET RECTILINEAR_GRID\n");

fprintf(vect_field, "DIMENSIONS %d %d %d\n", nx, ny, nz);

fprintf(vect_field, "X_COORDINATES %d float\n", nx);

for(i=0; i<=nx-1; i++)

fprintf(vect_field, "%f\n", x[i]);

fprintf(vect_field, "Y_COORDINATES %d float\n", ny);

for(j=0; j<=ny-1; j++)

fprintf(vect_field, "%f\n", y[j]);

fprintf(vect_field, "Z_COORDINATES %d float\n", nz);

fprintf(vect_field, "%f\n", z);

fprintf(vect_field, "POINT_DATA %d\n", (nx)*(ny)*(nz));

fprintf(vect_field, "VECTORS vectors float\n");

for(i=0; i<=nx-1; i++)

for(j=0; j<=ny-1; j++){

fprintf(vect_field, "%f\t %f\t %f\n", U[j][i], V[j][i], 0.0);




return; }

andyru April 3, 2013 06:34

Vector plotting via vtk-file without a "Sample rectilinear grid" data set

I found this thread here, because I faced the same problem. This helped a lot. But since the code example above uses a rectilinear grid, here comes my way, if you know coordinates and vector data, but the data set consists of a unstructured grid.
This is a short example using three points, 3 scalar values and 3 different vector data sets for each point.


# vtk DataFile Version 2.0
Unstructured Grid Example
POINTS 3 float
507026.25 6558690 1000
507348.5312 6558335 1000
507662.9062 6558345.5 1000
1 0
1 1
1 2
SCALARS scalarvalue float 1
VECTORS firstDirection float
0.419849547889549 -0.9075937181013 0
0.413814690673992 -0.910361138110798 0
0.412805482528595 -0.910819210158819 0
VECTORS secondDirection float
-0.424308102831314 0.905517881585831 0
-0.470514354339469 0.882392340379557 0
-0.53338593729323 0.84587200089483 0
VECTORS thirdDirection float
0.42459451128102 -0.905383620897811 0
0.428540938206614 -0.903522365124956 0
0.459812358448163 -0.88801610065265 0

Hope this helps!

First you define the coordinates.
Second the cells are related to the coordinates.
Then you define each cell type. 1 stands for cell type only consist of one point. This is trivial.
Then comes the point data with scalar values, followed by the vector data.

Then the import in paraview is possible and all features can be used.

(Detailed information for vtk is given in )

Best regards,


All times are GMT -4. The time now is 10:29.