pvdwriter.cc 1.97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// -*- 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/functions/functionspacebases/defaultglobalbasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <dune/functions/gridfunctions/analyticgridviewfunction.hh>

#include <dune/grid/yaspgrid.hh>

#include <dune/vtk/pvdwriter.hh>
22
#include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
23
24
25
26
27
28
29
30
31
32

using namespace Dune;
using namespace Dune::Functions;

template <class GridView>
void write (std::string prefix, GridView const& gridView)
{
  using namespace BasisFactory;
  auto basis = makeBasis(gridView, lagrange<1>());

Praetorius, Simon's avatar
Praetorius, Simon committed
33
34
35
36
  FieldVector<double,GridView::dimensionworld> c;
  if (GridView::dimensionworld > 0) c[0] = 11.0;
  if (GridView::dimensionworld > 1) c[1] = 7.0;
  if (GridView::dimensionworld > 2) c[2] = 3.0;
37
38
39
40
41

  // write analytic function
  auto p1Analytic = makeAnalyticGridViewFunction([&c](auto const& x) { return c.dot(x); }, gridView);

  using Writer = VtkUnstructuredGridWriter<GridView>;
42
  PvdWriter<Writer> pvdWriter(gridView, Vtk::ASCII, Vtk::FLOAT32);
43

44
45
  std::string filename = prefix + "_" + std::to_string(GridView::dimensionworld) + "d_ascii.vtu";

46
47
48
  pvdWriter.addPointData(p1Analytic, "p1");
  pvdWriter.addCellData(p1Analytic, "p0");
  for (double t = 0.0; t < 10.0; t += 1.0) {
49
    pvdWriter.writeTimestep(t, filename);
50
51
52
53
54
55
56
57
58
59
60
61
62
  }
}

template <int I>
using int_ = std::integral_constant<int,I>;

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

  // Test PvdWriter for YaspGrid
  using GridType = YaspGrid<2>;
  FieldVector<double,2> upperRight; upperRight = 1.0;
Praetorius, Simon's avatar
Praetorius, Simon committed
63
64
  auto numElements = filledArray<2,int>(8);
  GridType grid(upperRight, numElements, 0, 0);
65
66
  write("yasp", grid.leafGridView());
}