spdatacollector.hh 2.48 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
#pragma once

#ifdef HAVE_DUNE_SPGRID
#include <dune/grid/spgrid.hh>
#endif
#include <dune/vtk/datacollectors/structureddatacollector.hh>

namespace Dune { namespace experimental
{
#ifdef HAVE_DUNE_SPGRID

// Specialization for SPGrid
template <class GridView>
class SPDataCollector
    : public StructuredDataCollectorInterface<GridView, SPDataCollector<GridView>>
{
  enum { dim = GridView::dimension };

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

public:
  SPDataCollector (GridView const& gridView)
    : Super(gridView)
    , wholeExtent_(filledArray<6,int>(0))
    , origin_(0.0)
    , spacing_(0.0)
  {}

  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();

    auto const& begin = gridView_.impl().gridLevel().globalMesh().begin();
    auto const& end = gridView_.impl().gridLevel().globalMesh().end();
    auto const& cube = gridView_.grid().domain().cube();

    for (int i = 0; i < dim; ++i) {
      wholeExtent_[2*i] = begin[i];
      wholeExtent_[2*i+1] = end[i];
      spacing_[i] = cube.width()[i] / (end[i] - begin[i]);
      origin_[i] = cube.origin()[i];
    }
  }

  template <class Writer>
  void writeLocalPieceImpl (Writer const& writer) const
  {
    auto extent = filledArray<6,int>(0);
    auto const& localMesh = gridView_.impl().gridLevel().localMesh();
    for (int i = 0; i < dim; ++i) {
      extent[2*i] = localMesh.begin()[i];
      extent[2*i+1] = localMesh.end()[i];
    }
    writer(extent);
  }

  template <class Writer>
  void writePiecesImpl (Writer const& writer) const
  {
    auto extent = filledArray<6,int>(0);
    auto const& partitionList = gridView_.impl().gridLevel().decomposition_;
    // for (auto const& part : partitionList)
    for (std::size_t p = 0; p < partitionList.size(); ++p)
    {
      auto const& part = partitionList[p];
      for (int i = 0; i < dim; ++i) {
        extent[2*i] = part.begin()[i];
        extent[2*i+1] = part.begin()[i] + part.width(i);
      }
      writer(p, extent, true);
    }
  }

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

#endif

}} // end namespace Dune::experimental