legacyvtkwriter.cc 1.29 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
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
32
33
34
35
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <iostream>
#include <vector>

#include <dune/common/parallel/mpihelper.hh> // An initializer of MPI
#include <dune/common/exceptions.hh> // We use exceptions
#include <dune/common/filledarray.hh>

#include <dune/grid/uggrid.hh>
#include <dune/grid/yaspgrid.hh>

#include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
#include <dune/vtk/legacyvtkfunction.hh>

using namespace Dune;

int main(int argc, char** argv)
{
  Dune::MPIHelper::instance(argc, argv);

  const int dim = 3;
  using GridType = YaspGrid<dim>;
  FieldVector<double,dim> upperRight; upperRight = 1.0;
  auto numElements = filledArray<dim,int>(8);
  GridType grid(upperRight,numElements);

  using GridView = typename GridType::LeafGridView;
  GridView gridView = grid.leafGridView();

36
  std::vector<double> p1function(gridView.size(dim), 1.0);
Praetorius, Simon's avatar
Praetorius, Simon committed
37
38
39
40
41
42
43
44
  using P1Function = P1VTKFunction<GridView,std::vector<double>>;
  std::shared_ptr<VTKFunction<GridView> const> p1FctWrapped(new P1Function(gridView, p1function, "p1"));

  using Writer = VtkUnstructuredGridWriter<GridView>;
  Writer vtkWriter(gridView);
  vtkWriter.addPointData(p1FctWrapped);
  vtkWriter.write("test_ascii_float32.vtu", Vtk::ASCII);
}