dune-grid  2.11
gridcreatorinterface.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3 
4 #ifndef DUNE_GRID_IO_FILE_GMSH_GRIDCREATORINTERFACE_HH
5 #define DUNE_GRID_IO_FILE_GMSH_GRIDCREATORINTERFACE_HH
6 
7 #include <cstdint>
8 #include <string>
9 #include <tuple>
10 #include <vector>
11 
13 
14 namespace Dune::Impl::Gmsh
15 {
17 
23  template <class G, class Derived>
24  class GridCreatorInterface
25  {
26  public:
27  using Grid = G;
28  using GlobalCoordinate = typename Grid::template Codim<0>::Entity::Geometry::GlobalCoordinate;
29 
30  public:
32  GridCreatorInterface (GridFactory<Grid>& factory)
33  : factory_(&factory)
34  {}
35 
37  template <class NodeAttributes>
38  void insertVertices (std::size_t numNodes,
39  std::pair<std::size_t,std::size_t> nodeTagRange,
40  std::vector<NodeAttributes> const& entityBlocks)
41  {
42  asDerived().insertVerticesImpl(numNodes, nodeTagRange, entityBlocks);
43  }
44 
46  template <class ElementAttributes, class BoundaryEntities>
47  void insertElements (std::size_t numElements,
48  std::pair<std::size_t,std::size_t> elementTagRange,
49  std::vector<ElementAttributes> const& entityBlocks,
50  BoundaryEntities const& boundaryEntities)
51  {
52  asDerived().insertElementsImpl(numElements, elementTagRange, entityBlocks, boundaryEntities);
53  }
54 
56  void insertPieces (std::vector<std::string> const& pieces)
57  {
58  asDerived().insertPiecesImpl(pieces);
59  }
60 
62  GridFactory<Grid>& factory ()
63  {
64  return *factory_;
65  }
66 
68  GridFactory<Grid> const& factory () const
69  {
70  return *factory_;
71  }
72 
74  auto comm () const
75  {
76  return MPIHelper::getCommunication();
77  }
78 
79  protected: // cast to derived type
80 
81  Derived& asDerived ()
82  {
83  return static_cast<Derived&>(*this);
84  }
85 
86  const Derived& asDerived () const
87  {
88  return static_cast<const Derived&>(*this);
89  }
90 
91  public: // default implementations
92 
93  template <class NodeAttributes>
94  void insertVerticesImpl (std::size_t numNodes,
95  std::pair<std::size_t,std::size_t> nodeTagRange,
96  std::vector<NodeAttributes> const& entityBlocks)
97  {
98  /* do nothing */
99  }
100 
101  template <class ElementAttributes, class BoundaryEntities>
102  void insertElementsImpl (std::size_t numElements,
103  std::pair<std::size_t,std::size_t> elementTagRange,
104  std::vector<ElementAttributes> const& entityBlocks,
105  BoundaryEntities const& boundaryEntities)
106  {
107  /* do nothing */
108  }
109 
110  void insertPiecesImpl (std::vector<std::string> const&)
111  {
112  /* do nothing */;
113  }
114 
115  protected:
116  GridFactory<Grid>* factory_;
117  };
118 
119 } // end namespace Dune::Impl::Gmsh
120 
121 #endif
Provide a generic factory class for unstructured grids.
concept Grid
Requirements for implementations of the Dune::Grid interface.The Grid concept defines interface requi...
Definition: concepts/grid.hh:109
Definition: filereader.hh:14