gridcreatorinterface.hh 2.18 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once

#include <cstdint>
#include <string>
#include <vector>

#include <dune/common/version.hh>
#include <dune/grid/common/gridfactory.hh>

#include <dune/vtk/forward.hh>

namespace Dune {

template <class G, class Derived>
class GridCreatorInterface
{
public:
  using Grid = G;
  using GlobalCoordinate = typename Grid::template Codim<0>::Entity::Geometry::GlobalCoordinate;

public:
  GridCreatorInterface (GridFactory<Grid>& factory)
    : factory_(&factory)
24
  {}
Praetorius, Simon's avatar
Praetorius, Simon committed
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

  /// Insert all points as vertices into the factory
  void insertVertices (std::vector<GlobalCoordinate> const& points,
                       std::vector<std::uint64_t> const& point_ids)
  {
    asDerived().insertVerticesImpl(points, point_ids);
  }

  /// Create elements based on type and connectivity description
  void insertElements (std::vector<std::uint8_t> const& types,
                       std::vector<std::int64_t> const& offsets,
                       std::vector<std::int64_t> const& connectivity)
  {
    asDerived().insertElementsImpl(types, offsets, connectivity);
  }

  /// Insert part of a grid stored in file into factory
  void insertPieces (std::vector<std::string> const& pieces)
  {
    asDerived().insertPiecesImpl(pieces);
  }

  /// Return the associated GridFactory
  GridFactory<Grid>& factory ()
  {
    return *factory_;
  }

53
54
  /// Return the mpi collective communicator
  auto comm () const
Praetorius, Simon's avatar
Praetorius, Simon committed
55
  {
56
    return MPIHelper::getCollectiveCommunication();
Praetorius, Simon's avatar
Praetorius, Simon committed
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
  }

protected: // cast to derived type

  Derived& asDerived ()
  {
    return static_cast<Derived&>(*this);
  }

  const Derived& asDerived () const
  {
    return static_cast<const Derived&>(*this);
  }

public: // default implementations

  void insertVerticesImpl (std::vector<GlobalCoordinate> const&,
                           std::vector<std::uint64_t> const&)
  {
    /* do nothing */
  }

  void insertElementsImpl (std::vector<std::uint8_t> const&,
                           std::vector<std::int64_t> const&,
                           std::vector<std::int64_t> const&)
  {
    /* do nothing */
  }

  void insertPiecesImpl (std::vector<std::string> const&)
  {
    /* do nothing */;
  }

protected:
  GridFactory<Grid>* factory_;
};

} // end namespace Dune