gridcreatorinterface.hh 2.6 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
#pragma once

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

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

#include <dune/vtk/forward.hh>

12
namespace Dune
Praetorius, Simon's avatar
Praetorius, Simon committed
13
14
{

15
16
17
18
19
20
21
22
23
  /// Base class for grid creators in a CRTP style.
  /**
   * Construct a grid from data read from VTK files.
   *
   * \tparam GridView   Model of Dune::GridView
   * \tparam Derived    Implementation of a concrete GridCreator.
   **/
  template <class G, class Derived>
  class GridCreatorInterface
Praetorius, Simon's avatar
Praetorius, Simon committed
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
  public:
    using Grid = G;
    using GlobalCoordinate = typename Grid::template Codim<0>::Entity::Geometry::GlobalCoordinate;

  public:
    /// Constructor. Stores a reference to the passed GridFactory
    GridCreatorInterface (GridFactory<Grid>& factory)
      : factory_(&factory)
    {}

    /// 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_;
    }

    /// Return the mpi collective communicator
    auto comm () const
    {
      return MPIHelper::getCollectiveCommunication();
    }

  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_;
  };
Praetorius, Simon's avatar
Praetorius, Simon committed
103
104

} // end namespace Dune