dune-grid  2.9.0
common/gridfactory.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 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/deprecated.hh>
16 #define DUNE_FUNCTION_HH_SILENCE_DEPRECATION
17 #include <dune/common/function.hh>
18 #include <dune/common/fvector.hh>
19 #include <dune/common/parallel/mpihelper.hh>
20 
21 #include <dune/geometry/type.hh>
22 
24 #include <dune/grid/common/grid.hh>
25 
26 namespace Dune
27 {
28 
71  template <class GridType>
73  {
74 
75  protected:
77  static const int dimension = GridType::dimension;
78 
80  constexpr static int dimworld = GridType::dimensionworld;
81 
83  typedef typename GridType::ctype ctype;
84 
85  public:
86  template< int codim >
87  struct Codim
88  {
89  typedef typename GridType::template Codim< codim >::Entity Entity;
90  };
91 
94  {}
95 
98  {}
99 
101  virtual void insertVertex(const FieldVector<ctype,dimworld>& pos) = 0;
102 
110  virtual void insertElement(const GeometryType& type,
111  const std::vector<unsigned int>& vertices) = 0;
112 
113  DUNE_NO_DEPRECATED_BEGIN
125  [[deprecated("[After Dune 2.7]: VirtualFunction is deprecated, use the "
126  "overload taking a std::function instead")]]
127  virtual void
128  insertElement([[maybe_unused]] const GeometryType& type,
129  [[maybe_unused]] const std::vector<unsigned int>& vertices,
130  [[maybe_unused]] const std::shared_ptr<VirtualFunction<
131  FieldVector<ctype,dimension>,
132  FieldVector<ctype,dimworld>
133  > >& elementParametrization)
134  {
135  DUNE_THROW(GridError, "This grid does not support parametrized elements!");
136  }
137  DUNE_NO_DEPRECATED_END
138 
150  virtual void
152  const std::vector<unsigned int>& vertices,
153  std::function<FieldVector<ctype,dimworld>
154  (FieldVector<ctype,dimension>)>
155  elementParametrization)
156  {
157  // note: this forward to the overload taking a Virtual function during
158  // the deprecation period, once that is over it should the throwing of
159  // the exception should be moved here directly
160  using Domain = FieldVector<ctype,dimension>;
161  using Range = FieldVector<ctype,dimworld>;
162  DUNE_NO_DEPRECATED_BEGIN
163  auto f =
164  makeVirtualFunction<Domain, Range>(std::move(elementParametrization));
165  insertElement(type, vertices,
166  std::make_unique<decltype(f)>(std::move(f)));
167  DUNE_NO_DEPRECATED_END
168  }
169 
183  virtual void insertBoundarySegment(const std::vector<unsigned int>& vertices) = 0;
184 
192  virtual void insertBoundarySegment([[maybe_unused]] const std::vector<unsigned int>& vertices,
193  [[maybe_unused]] const std::shared_ptr<BoundarySegment<dimension,dimworld> >& boundarySegment)
194  {
195  DUNE_THROW(GridError, "This grid does not support parametrized boundary segments!");
196  }
197 
202  virtual std::unique_ptr<GridType> createGrid() = 0;
203 
219  virtual unsigned int
220  insertionIndex ( [[maybe_unused]] const typename Codim< 0 >::Entity &entity ) const
221  {
222  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
223  }
224 
240  virtual unsigned int
241  insertionIndex ( [[maybe_unused]] const typename Codim< dimension >::Entity &entity ) const
242  {
243  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
244  }
245 
265  virtual unsigned int
266  insertionIndex ( [[maybe_unused]] const typename GridType::LeafIntersection &intersection ) const
267  {
268  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
269  }
270 
271 
285  virtual bool
286  wasInserted ( [[maybe_unused]] const typename GridType::LeafIntersection &intersection ) const
287  {
288  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
289  }
290 
291  using Communication = Dune::Communication<typename MPIHelper::MPICommunicator>;
292 
298  {
299  return Communication(MPIHelper::getLocalCommunicator());
300  }
301  };
302 
303 
313  template <class GridType>
314  class GridFactory : public GridFactoryInterface<GridType> {
315 
317 
319  constexpr static int dimworld = GridType::dimensionworld;
320 
322  typedef typename GridType::ctype ctype;
323 
324  public:
325 
326  // use default implementation from base class
328 
331  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
332  }
333 
335  virtual void insertVertex([[maybe_unused]] const FieldVector<ctype,dimworld>& pos) {
336  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
337  }
338 
346  virtual void insertElement([[maybe_unused]] const GeometryType& type,
347  [[maybe_unused]] const std::vector<unsigned int>& vertices) {
348  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
349  }
350 
364  virtual void insertBoundarySegment([[maybe_unused]] const std::vector<unsigned int>& vertices) {
365  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
366  }
367 
372  virtual std::unique_ptr<GridType> createGrid() {
373  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
374  }
375 
376  };
377 
378 }
379 
380 #endif
Base class for grid boundary segments of arbitrary geometry.
Include standard header files.
Definition: agrid.hh:60
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:94
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:20
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:73
virtual std::unique_ptr< GridType > createGrid()=0
Finalize grid creation and hand over the grid.
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)=0
Insert an element into the coarse grid.
virtual unsigned int insertionIndex([[maybe_unused]] const typename Codim< 0 >::Entity &entity) const
obtain an element's insertion index
Definition: common/gridfactory.hh:220
virtual void insertBoundarySegment(const std::vector< unsigned int > &vertices)=0
insert a boundary segment
virtual bool wasInserted([[maybe_unused]] const typename GridType::LeafIntersection &intersection) const
determine whether an intersection was inserted
Definition: common/gridfactory.hh:286
virtual ~GridFactoryInterface()
virtual destructor
Definition: common/gridfactory.hh:97
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)=0
Insert a vertex into the coarse grid.
virtual unsigned int insertionIndex([[maybe_unused]] const typename Codim< dimension >::Entity &entity) const
obtain a vertex' insertion index
Definition: common/gridfactory.hh:241
static const int dimension
dimension of the grid
Definition: common/gridfactory.hh:77
GridType::ctype ctype
Type used by the grid for coordinates.
Definition: common/gridfactory.hh:83
Dune::Communication< typename MPIHelper::MPICommunicator > Communication
Definition: common/gridfactory.hh:291
GridFactoryInterface()
Default constructor.
Definition: common/gridfactory.hh:93
Communication comm() const
Return the Communication used by the grid factory.
Definition: common/gridfactory.hh:297
virtual void insertBoundarySegment([[maybe_unused]] const std::vector< unsigned int > &vertices, [[maybe_unused]] const std::shared_ptr< BoundarySegment< dimension, dimworld > > &boundarySegment)
insert an arbitrarily shaped boundary segment
Definition: common/gridfactory.hh:192
constexpr static int dimworld
The grid world dimension.
Definition: common/gridfactory.hh:80
virtual unsigned int insertionIndex([[maybe_unused]] const typename GridType::LeafIntersection &intersection) const
obtain a boundary's insertion index
Definition: common/gridfactory.hh:266
virtual DUNE_NO_DEPRECATED_END void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices, std::function< FieldVector< ctype, dimworld >(FieldVector< ctype, dimension >)> elementParametrization)
Insert a parametrized element into the coarse grid.
Definition: common/gridfactory.hh:151
virtual DUNE_NO_DEPRECATED_BEGIN void insertElement([[maybe_unused]] const GeometryType &type, [[maybe_unused]] const std::vector< unsigned int > &vertices, [[maybe_unused]] const std::shared_ptr< VirtualFunction< FieldVector< ctype, dimension >, FieldVector< ctype, dimworld > > > &elementParametrization)
Insert a parametrized element into the coarse grid.
Definition: common/gridfactory.hh:128
Definition: common/gridfactory.hh:88
GridType::template Codim< codim >::Entity Entity
Definition: common/gridfactory.hh:89
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:314
virtual void insertVertex([[maybe_unused]] const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: common/gridfactory.hh:335
GridFactory()
Default constructor.
Definition: common/gridfactory.hh:330
virtual void insertBoundarySegment([[maybe_unused]] const std::vector< unsigned int > &vertices)
insert a boundary segment
Definition: common/gridfactory.hh:364
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:346
virtual std::unique_ptr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition: common/gridfactory.hh:372
Different resources needed by all grid implementations.