vtkout.hh 885 Bytes
Newer Older
1 2
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
3 4 5
#ifndef __DUNE_GRID_HOWTO_VTKOUT_HH__
#define __DUNE_GRID_HOWTO_VTKOUT_HH__

6
#include <dune/grid/io/file/vtk/vtkwriter.hh>
Peter Bastian's avatar
Peter Bastian committed
7
#include <stdio.h>
8 9

template<class G, class V>
10
void vtkout (const G& grid, const V& c, const char* name, int k, double time=0.0, int rank=0)
11
{
12
  Dune::VTKWriter<typename G::LeafGridView> vtkwriter(grid.leafGridView());
Peter Bastian's avatar
Peter Bastian committed
13
  char fname[128];
14
  char sername[128];
Peter Bastian's avatar
Peter Bastian committed
15
  sprintf(fname,"%s-%05d",name,k);
16
  sprintf(sername,"%s.series",name);
17
  vtkwriter.addCellData(c,"celldata");
18
  vtkwriter.write( fname, Dune::VTK::ascii );
19 20 21 22 23 24 25

  if ( rank == 0)
  {
    std::ofstream serstream(sername, (k==0 ? std::ios_base::out : std::ios_base::app));
    serstream << k << " " << fname << ".vtu " << time << std::endl;
    serstream.close();
  }
26
}
27 28

#endif // __DUNE_GRID_HOWTO_VTKOUT_HH__