example.c 995 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include "visit_writer.h"
#include <math.h>

int
main(int argc, char **argv)
{
    // Set up storage
    int nCellsX = 10;
    int nCellsY = 10;
    float cellCentered[nCellsX][nCellsY];
    float nodeCentered[nCellsX+1][nCellsY+1];

    // Put data in the arrays.
    int x, y;
    for(x=0;x<nCellsX;x++)
        for(y=0;y<nCellsY;y++)
            cellCentered[x][y] = sin(x/2.)*cos(y/2.);

    for(x=0;x<nCellsX+1;x++)
        for(y=0;y<nCellsY+1;y++)
            nodeCentered[x][y] = 1/(x*y+0.1);

    // Write out the mesh and the arrays.
    int dims[] = { nCellsX+1, nCellsY+1, 1 };    // The number of nodes in the mesh.
    int vardims[] = { 1, 1 };   // Two scalars
    int centering[] = { 1, 0 }; // node centered, cell centered
    const char * const varnames[] = { "nodeCentered", "cellCentered" };
    float *arrays[] = { (float*)nodeCentered, (float*)cellCentered };
    write_regular_mesh("example.vtk", 0, dims, 2, vardims, centering,
                       varnames, arrays);
}