timeserieswriter.cc 1.82 KB
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
// -*- 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/gridfunctions/analyticgridviewfunction.hh>
#include <dune/grid/yaspgrid.hh>

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

using namespace Dune;
using namespace Dune::Functions;

template <class GridView>
void write (std::string prefix, GridView const& gridView)
{
Praetorius, Simon's avatar
Praetorius, Simon committed
27
  FieldVector<double,GridView::dimensionworld> c{11.0, 7.0, 3.0};
28
29
  double shift = 0.0;
  auto p1Analytic = makeAnalyticGridViewFunction([&c,&shift](auto const& x) -> float { return c.dot(x) + shift; }, gridView);
30
31

  using Writer = VtkUnstructuredGridWriter<GridView>;
32
33
34
  VtkTimeseriesWriter<Writer> seriesWriter(gridView, Vtk::BINARY, Vtk::FLOAT32);
  seriesWriter.addPointData(p1Analytic, "q1");
  seriesWriter.addCellData(p1Analytic, "q0");
Praetorius, Simon's avatar
Praetorius, Simon committed
35
  std::string filename = prefix + "_" + std::to_string(GridView::dimensionworld) + "d_binary32.vtu";
36
  for (double t = 0.0; t < 5; t += 0.5) {
37
38
    seriesWriter.writeTimestep(t, filename, false);
    shift += 0.25;
39
  }
40
41
42
43
44
45
  seriesWriter.write(filename);

  Writer vtkWriter(gridView, Vtk::BINARY, Vtk::FLOAT32);
  vtkWriter.addPointData(p1Analytic, "q1");
  vtkWriter.addCellData(p1Analytic, "q0");
  vtkWriter.write(filename);
46
47
48
49
50
51
52
53
}

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

  using GridType = YaspGrid<3>;
  FieldVector<double,3> upperRight; upperRight = 1.0;
54
  auto numElements = filledArray<3,int>(8);
Praetorius, Simon's avatar
Praetorius, Simon committed
55
  GridType grid(upperRight, numElements, 0, 0);
56
57
  write("yasp", grid.leafGridView());
}