dune-grid  2.11
common/gridfactory.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_GRID_COMMON_GRIDFACTORY_HH
6 #define DUNE_GRID_COMMON_GRIDFACTORY_HH
7 
12 #include <memory>
13 #include <vector>
14 
15 #include <dune/common/fvector.hh>
16 #include <dune/common/parallel/mpihelper.hh>
17 
18 #include <dune/geometry/type.hh>
19 
21 #include <dune/grid/common/grid.hh>
22 
23 namespace Dune
24 {
25 
68  template <class GridType>
70  {
71 
72  protected:
74  static const int dimension = GridType::dimension;
75 
77  constexpr static int dimworld = GridType::dimensionworld;
78 
80  typedef typename GridType::ctype ctype;
81 
82  public:
83  template< int codim >
84  struct Codim
85  {
86  typedef typename GridType::template Codim< codim >::Entity Entity;
87  };
88 
91  {}
92 
95  {}
96 
98  virtual void insertVertex(const FieldVector<ctype,dimworld>& pos) = 0;
99 
107  virtual void insertElement(const GeometryType& type,
108  const std::vector<unsigned int>& vertices) = 0;
109 
121  virtual void
122  insertElement(const GeometryType& /*type*/,
123  const std::vector<unsigned int>& /*vertices*/,
124  std::function<FieldVector<ctype,dimworld>
125  (FieldVector<ctype,dimension>)>
126  /*elementParametrization*/)
127  {
128  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
129  }
130 
144  virtual void insertBoundarySegment(const std::vector<unsigned int>& vertices) = 0;
145 
153  virtual void insertBoundarySegment([[maybe_unused]] const std::vector<unsigned int>& vertices,
154  [[maybe_unused]] const std::shared_ptr<BoundarySegment<dimension,dimworld> >& boundarySegment)
155  {
156  DUNE_THROW(GridError, "This grid does not support parametrized boundary segments!");
157  }
158 
163  virtual std::unique_ptr<GridType> createGrid() = 0;
164 
180  virtual unsigned int
181  insertionIndex ( [[maybe_unused]] const typename Codim< 0 >::Entity &entity ) const
182  {
183  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
184  }
185 
201  virtual unsigned int
202  insertionIndex ( [[maybe_unused]] const typename Codim< dimension >::Entity &entity ) const
203  {
204  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
205  }
206 
226  virtual unsigned int
227  insertionIndex ( [[maybe_unused]] const typename GridType::LeafIntersection &intersection ) const
228  {
229  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
230  }
231 
232 
246  virtual bool
247  wasInserted ( [[maybe_unused]] const typename GridType::LeafIntersection &intersection ) const
248  {
249  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
250  }
251 
252  using Communication = Dune::Communication<typename MPIHelper::MPICommunicator>;
253 
259  {
260  return Communication(MPIHelper::getLocalCommunicator());
261  }
262  };
263 
264 
274  template <class GridType>
275  class GridFactory : public GridFactoryInterface<GridType> {
276 
278 
280  constexpr static int dimworld = GridType::dimensionworld;
281 
283  typedef typename GridType::ctype ctype;
284 
285  public:
286 
287  // use default implementation from base class
289 
292  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
293  }
294 
296  virtual void insertVertex([[maybe_unused]] const FieldVector<ctype,dimworld>& pos) {
297  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
298  }
299 
307  virtual void insertElement([[maybe_unused]] const GeometryType& type,
308  [[maybe_unused]] const std::vector<unsigned int>& vertices) {
309  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
310  }
311 
325  virtual void insertBoundarySegment([[maybe_unused]] const std::vector<unsigned int>& vertices) {
326  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
327  }
328 
333  virtual std::unique_ptr<GridType> createGrid() {
334  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
335  }
336 
337  };
338 
339 }
340 
341 #endif
virtual void insertElement(const GeometryType &, const std::vector< unsigned int > &, std::function< FieldVector< ctype, dimworld >(FieldVector< ctype, dimension >)>)
Insert a parametrized element into the coarse grid.
Definition: common/gridfactory.hh:122
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:37
Base class for grid boundary segments of arbitrary geometry.
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)=0
Insert an element into the coarse grid.
virtual bool wasInserted([[maybe_unused]] const typename GridType::LeafIntersection &intersection) const
determine whether an intersection was inserted
Definition: common/gridfactory.hh:247
Dune::Communication< typename MPIHelper::MPICommunicator > Communication
Definition: common/gridfactory.hh:252
static constexpr int dimworld
The grid world dimension.
Definition: common/gridfactory.hh:77
virtual ~GridFactoryInterface()
virtual destructor
Definition: common/gridfactory.hh:94
Different resources needed by all grid implementations.
virtual std::unique_ptr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition: common/gridfactory.hh:333
GridFactory()
Default constructor.
Definition: common/gridfactory.hh:291
GridType::ctype ctype
Type used by the grid for coordinates.
Definition: common/gridfactory.hh:80
virtual unsigned int insertionIndex([[maybe_unused]] const typename Codim< 0 >::Entity &entity) const
obtain an element&#39;s insertion index
Definition: common/gridfactory.hh:181
Communication comm() const
Return the Communication used by the grid factory.
Definition: common/gridfactory.hh:258
Include standard header files.
Definition: agrid.hh:59
virtual void insertBoundarySegment(const std::vector< unsigned int > &vertices)=0
insert a boundary segment
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:69
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)=0
Insert a vertex into the coarse grid.
virtual void insertBoundarySegment([[maybe_unused]] const std::vector< unsigned int > &vertices)
insert a boundary segment
Definition: common/gridfactory.hh:325
GridFactoryInterface()
Default constructor.
Definition: common/gridfactory.hh:90
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:275
virtual unsigned int insertionIndex([[maybe_unused]] const typename Codim< dimension >::Entity &entity) const
obtain a vertex&#39; insertion index
Definition: common/gridfactory.hh:202
GridType::template Codim< codim >::Entity Entity
Definition: common/gridfactory.hh:86
virtual std::unique_ptr< GridType > createGrid()=0
Finalize grid creation and hand over the grid.
GeometryType
Type representing VTK&#39;s entity geometry types.
Definition: common.hh:132
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
virtual void insertElement([[maybe_unused]] const GeometryType &type, [[maybe_unused]] const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
Definition: common/gridfactory.hh:307
Definition: common/gridfactory.hh:84
static const int dimension
dimension of the grid
Definition: common/gridfactory.hh:74
virtual unsigned int insertionIndex([[maybe_unused]] const typename GridType::LeafIntersection &intersection) const
obtain a boundary&#39;s insertion index
Definition: common/gridfactory.hh:227
virtual void insertVertex([[maybe_unused]] const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: common/gridfactory.hh:296