datacollector.cc 4.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
// -*- 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>
14
#include <dune/common/version.hh>
15
16
17
18
19
20

#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <dune/functions/functionspacebases/interpolate.hh>
#include <dune/functions/gridfunctions/analyticgridviewfunction.hh>
#include <dune/functions/gridfunctions/discreteglobalbasisfunction.hh>
21

Praetorius, Simon's avatar
Praetorius, Simon committed
22
#if HAVE_DUNE_UGGRID
Praetorius, Simon's avatar
Praetorius, Simon committed
23
#include <dune/grid/uggrid.hh>
Stenger, Florian's avatar
Stenger, Florian committed
24
#endif
Praetorius, Simon's avatar
Praetorius, Simon committed
25

26
#include <dune/grid/yaspgrid.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
27
#include <dune/grid/utility/structuredgridfactory.hh>
28

29
#include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
30
31

#include <dune/vtk/datacollectors/continuousdatacollector.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
32
#include <dune/vtk/datacollectors/discontinuousdatacollector.hh>
33
#include <dune/vtk/datacollectors/quadraticdatacollector.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
34
#include <dune/vtk/datacollectors/lagrangedatacollector.hh>
35
36
37
38

using namespace Dune;
using namespace Dune::Functions;

39
40
template <class DataCollector, class GridView, class Fct1, class Fct2>
void write_dc (std::string prefix, GridView const& gridView, Fct1 const& fct1, Fct2 const& fct2)
41
{
42
  VtkUnstructuredGridWriter<GridView, DataCollector> vtkWriter(gridView, Vtk::ASCII, Vtk::FLOAT32);
43
44
45
46
47
  vtkWriter.addPointData(fct1, "p1");
  vtkWriter.addCellData(fct1, "p0");
  vtkWriter.addPointData(fct2, "q1");
  vtkWriter.addCellData(fct2, "q0");

Praetorius, Simon's avatar
Praetorius, Simon committed
48
  vtkWriter.write(prefix + "_" + std::to_string(GridView::dimensionworld) + "d_ascii.vtu");
49
}
50

51
52
53
template <class GridView>
void write (std::string prefix, GridView const& gridView)
{
Praetorius, Simon's avatar
Praetorius, Simon committed
54
  std::cout << prefix << "..." << std::endl;
55
56
57
#if ! DUNE_VERSION_NEWER(DUNE_FUNCTIONS, 2, 6)
  using namespace BasisBuilder;
#else
58
  using namespace BasisFactory;
59
#endif
60
61
  auto basis = makeBasis(gridView, lagrange<1>());

Praetorius, Simon's avatar
Praetorius, Simon committed
62
63
64
65
  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;
66

67
68
  std::vector<double> vec(basis.dimension());
  interpolate(basis, vec, [&c](auto const& x) { return c.dot(x); });
69
70

  // write discrete global-basis function
71
72
  auto p1Interpol = makeDiscreteGlobalBasisFunction<double>(basis, vec);

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

Stenger, Florian's avatar
Stenger, Florian committed
76
77
78
  write_dc<Vtk::ContinuousDataCollector<GridView>>(prefix + "_continuous", gridView, p1Interpol, p1Analytic);
  write_dc<Vtk::DiscontinuousDataCollector<GridView>>(prefix + "_discontinuous", gridView, p1Interpol, p1Analytic);
  write_dc<Vtk::QuadraticDataCollector<GridView>>(prefix + "_quadratic", gridView, p1Interpol, p1Analytic);
Praetorius, Simon's avatar
Praetorius, Simon committed
79
80

  Hybrid::forEach(StaticIntegralRange<int,7,1>{}, [&](auto p) {
Stenger, Florian's avatar
Stenger, Florian committed
81
    write_dc<Vtk::LagrangeDataCollector<GridView,p>>(prefix + "_lagrange_p" + std::to_string(p), gridView, p1Interpol, p1Analytic);
Praetorius, Simon's avatar
Praetorius, Simon committed
82
  });
83
84
}

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

88
89
90
91
int main(int argc, char** argv)
{
  Dune::MPIHelper::instance(argc, argv);

Praetorius, Simon's avatar
Praetorius, Simon committed
92
  Hybrid::forEach(StaticIntegralRange<int,4,1>{}, [](auto dim)
93
  {
94
95
    using GridType = YaspGrid<dim.value>;
    FieldVector<double,dim.value> upperRight; upperRight = 1.0;
Praetorius, Simon's avatar
Praetorius, Simon committed
96
    auto numElements = filledArray<dim.value,int>(2);
Praetorius, Simon's avatar
Praetorius, Simon committed
97
    GridType grid(upperRight, numElements, 0, 0);
Praetorius, Simon's avatar
Praetorius, Simon committed
98
    write("datacollector_yasp", grid.leafGridView());
99
  });
Praetorius, Simon's avatar
Praetorius, Simon committed
100

Praetorius, Simon's avatar
Praetorius, Simon committed
101
#if HAVE_DUNE_UGGRID
Praetorius, Simon's avatar
Praetorius, Simon committed
102
103
104
105
106
107
108
109
110
111
  Hybrid::forEach(StaticIntegralRange<int,4,2>{}, [](auto dim)
  {
    using GridType = UGGrid<dim.value>;
    FieldVector<double,dim.value> lowerLeft; lowerLeft = 0.0;
    FieldVector<double,dim.value> upperRight; upperRight = 1.0;
    auto numElements = filledArray<dim.value,unsigned int>(4);
    auto grid = StructuredGridFactory<GridType>::createSimplexGrid(lowerLeft, upperRight, numElements);
    write("datacollector_ug", grid->leafGridView());
  });
#endif
112
}