yaspdatacollector.hh 3.06 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#pragma once

#include <dune/grid/yaspgrid.hh>
#include <dune/vtk/datacollectors/structureddatacollector.hh>

namespace Dune { namespace experimental
{
// Specialization for YaspGrid
template <class GridView>
class YaspDataCollector
    : public StructuredDataCollectorInterface<GridView, YaspDataCollector<GridView>>
{
  enum { dim = GridView::dimension };

  using Self = YaspDataCollector;
  using Super = StructuredDataCollectorInterface<GridView, Self>;
  using Super::gridView_;
  using ctype = typename GridView::ctype;

public:
  YaspDataCollector (GridView const& gridView)
    : Super(gridView)
    , wholeExtent_(filledArray<6,int>(0))
    , origin_(0.0)
    , spacing_(0.0)
    , level_(gridView.template begin<0,Interior_Partition>()->level())
  {}

  std::array<int, 6> const& wholeExtentImpl () const
  {
    return wholeExtent_;
  }

  auto const& originImpl () const
  {
    return origin_;
  }

  auto const& spacingImpl () const
  {
    return spacing_;
  }

  void updateImpl ()
  {
    Super::updateImpl();

    for (int i = 0; i < dim; ++i) {
      wholeExtent_[2*i] = 0;
      wholeExtent_[2*i+1] = gridView_.grid().levelSize(level_,i);
    }

    auto it = gridView_.grid().begin(level_);
    initGeometry(it->coords);
  }

  template <class Coords>
  void initGeometry (Coords const& coords) { DUNE_THROW(NotImplemented, "Coordinate-Type not implemented!"); }

  void initGeometry (EquidistantCoordinates<ctype,dim> const& coords)
  {
    for (int i = 0; i < dim; ++i) {
      spacing_[i] = coords.meshsize(i,0);
      origin_[i] = 0;
    }
  }

  void initGeometry (EquidistantOffsetCoordinates<ctype,dim> const& coords)
  {
    for (int i = 0; i < dim; ++i) {
      spacing_[i] = coords.meshsize(i,0);
      origin_[i] = coords.origin(i);
    }
  }

  void initGeometry (TensorProductCoordinates<ctype,dim> const& coords)
  {
    for (int i = 0; i < dim; ++i) {
      spacing_[i] = coords.meshsize(i,0); // is not constant, but also not used.
      origin_[i] = coords.coordinate(i,0);
    }
  }

  template <class Writer>
  void writeLocalPieceImpl (Writer const& writer) const
  {
    auto const& gl = *gridView_.grid().begin(level_);
    auto const& g = gl.interior[0];
    auto extent = filledArray<6,int>(0);
    auto const& gc = *g.dataBegin();
    for (int i = 0; i < dim; ++i) {
      extent[2*i] = gc.min(i);
      extent[2*i+1] = gc.max(i)+1;
    }
    writer(extent);
  }

  template <class Writer>
  void writePiecesImpl (Writer const& writer) const
  {
    auto extent = filledArray<6,int>(0);
    // for (auto const& part : gridView_.gridLevel().template partition<InteriorEntity>())
    // {
    //   for (int i = 0; i < dim; ++i) {
    //     extent[2*i] = part.begin()[i];
    //     extent[2*i+1] = part.end()[i]-1;
    //   }

    int num_ranks = -1;
    MPI_Comm_size(MPI_COMM_WORLD, &num_ranks);
    for (int p = 0; p < num_ranks; ++p) {
      writer(p, extent, false);
    }
  }

private:
  std::array<int, 6> wholeExtent_;
  FieldVector<ctype,3> spacing_;
  FieldVector<ctype,3> origin_;
  std::vector<std::size_t> indexMap_;
  int level_;
};

}} // end namespace Dune::experimental