dune-grid  2.8.0
common/gridfactory.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GRID_COMMON_GRIDFACTORY_HH
4 #define DUNE_GRID_COMMON_GRIDFACTORY_HH
5 
10 #include <memory>
11 #include <vector>
12 
13 #include <dune/common/deprecated.hh>
14 #define DUNE_FUNCTION_HH_SILENCE_DEPRECATION
15 #include <dune/common/function.hh>
16 #include <dune/common/fvector.hh>
17 #include <dune/common/parallel/mpihelper.hh>
18 
19 #include <dune/geometry/type.hh>
20 
22 #include <dune/grid/common/grid.hh>
23 
24 namespace Dune
25 {
26 
69  template <class GridType>
71  {
72 
73  protected:
75  static const int dimension = GridType::dimension;
76 
78  enum {dimworld = GridType::dimensionworld};
79 
81  typedef typename GridType::ctype ctype;
82 
83  public:
84  template< int codim >
85  struct Codim
86  {
87  typedef typename GridType::template Codim< codim >::Entity Entity;
88  };
89 
92  {}
93 
96  {}
97 
99  virtual void insertVertex(const FieldVector<ctype,dimworld>& pos) = 0;
100 
108  virtual void insertElement(const GeometryType& type,
109  const std::vector<unsigned int>& vertices) = 0;
110 
111  DUNE_NO_DEPRECATED_BEGIN
123  [[deprecated("[After Dune 2.7]: VirtualFunction is deprecated, use the "
124  "overload taking a std::function instead")]]
125  virtual void
126  insertElement([[maybe_unused]] const GeometryType& type,
127  [[maybe_unused]] const std::vector<unsigned int>& vertices,
128  [[maybe_unused]] const std::shared_ptr<VirtualFunction<
129  FieldVector<ctype,dimension>,
130  FieldVector<ctype,dimworld>
131  > >& elementParametrization)
132  {
133  DUNE_THROW(GridError, "This grid does not support parametrized elements!");
134  }
135  DUNE_NO_DEPRECATED_END
136 
148  virtual void
150  const std::vector<unsigned int>& vertices,
151  std::function<FieldVector<ctype,dimworld>
152  (FieldVector<ctype,dimension>)>
153  elementParametrization)
154  {
155  // note: this forward to the overload taking a Virtual function during
156  // the deprecation period, once that is over it should the throwing of
157  // the exception should be moved here directly
158  using Domain = FieldVector<ctype,dimension>;
159  using Range = FieldVector<ctype,dimworld>;
160  DUNE_NO_DEPRECATED_BEGIN
161  auto f =
162  makeVirtualFunction<Domain, Range>(std::move(elementParametrization));
163  insertElement(type, vertices,
164  std::make_unique<decltype(f)>(std::move(f)));
165  DUNE_NO_DEPRECATED_END
166  }
167 
181  virtual void insertBoundarySegment(const std::vector<unsigned int>& vertices) = 0;
182 
190  virtual void insertBoundarySegment([[maybe_unused]] const std::vector<unsigned int>& vertices,
191  [[maybe_unused]] const std::shared_ptr<BoundarySegment<dimension,dimworld> >& boundarySegment)
192  {
193  DUNE_THROW(GridError, "This grid does not support parametrized boundary segments!");
194  }
195 
200  virtual std::unique_ptr<GridType> createGrid() = 0;
201 
217  virtual unsigned int
218  insertionIndex ( [[maybe_unused]] const typename Codim< 0 >::Entity &entity ) const
219  {
220  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
221  }
222 
238  virtual unsigned int
239  insertionIndex ( [[maybe_unused]] const typename Codim< dimension >::Entity &entity ) const
240  {
241  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
242  }
243 
263  virtual unsigned int
264  insertionIndex ( [[maybe_unused]] const typename GridType::LeafIntersection &intersection ) const
265  {
266  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
267  }
268 
269 
283  virtual bool
284  wasInserted ( [[maybe_unused]] const typename GridType::LeafIntersection &intersection ) const
285  {
286  DUNE_THROW( NotImplemented, "insertion indices have not yet been implemented." );
287  }
288 
289  using Communication = Dune::CollectiveCommunication<typename MPIHelper::MPICommunicator>;
290 
296  {
297  return Communication(MPIHelper::getLocalCommunicator());
298  }
299  };
300 
301 
311  template <class GridType>
312  class GridFactory : public GridFactoryInterface<GridType> {
313 
315 
317  enum {dimworld = GridType::dimensionworld};
318 
320  typedef typename GridType::ctype ctype;
321 
322  public:
323 
324  // use default implementation from base class
326 
329  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
330  }
331 
333  virtual void insertVertex([[maybe_unused]] const FieldVector<ctype,dimworld>& pos) {
334  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
335  }
336 
344  virtual void insertElement([[maybe_unused]] const GeometryType& type,
345  [[maybe_unused]] const std::vector<unsigned int>& vertices) {
346  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
347  }
348 
362  virtual void insertBoundarySegment([[maybe_unused]] const std::vector<unsigned int>& vertices) {
363  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
364  }
365 
370  virtual std::unique_ptr<GridType> createGrid() {
371  DUNE_THROW(GridError, "There is no grid factory for this grid type!");
372  }
373 
374  };
375 
376 }
377 
378 #endif
Base class for grid boundary segments of arbitrary geometry.
Include standard header files.
Definition: agrid.hh:58
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:92
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:71
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:218
@ dimworld
Definition: common/gridfactory.hh:78
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:284
virtual ~GridFactoryInterface()
virtual destructor
Definition: common/gridfactory.hh:95
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:239
static const int dimension
dimension of the grid
Definition: common/gridfactory.hh:75
GridType::ctype ctype
Type used by the grid for coordinates.
Definition: common/gridfactory.hh:81
GridFactoryInterface()
Default constructor.
Definition: common/gridfactory.hh:91
Communication comm() const
Return the Communication used by the grid factory.
Definition: common/gridfactory.hh:295
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:190
virtual unsigned int insertionIndex([[maybe_unused]] const typename GridType::LeafIntersection &intersection) const
obtain a boundary's insertion index
Definition: common/gridfactory.hh:264
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:149
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:126
Dune::CollectiveCommunication< typename MPIHelper::MPICommunicator > Communication
Definition: common/gridfactory.hh:289
Definition: common/gridfactory.hh:86
GridType::template Codim< codim >::Entity Entity
Definition: common/gridfactory.hh:87
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:312
virtual void insertVertex([[maybe_unused]] const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: common/gridfactory.hh:333
GridFactory()
Default constructor.
Definition: common/gridfactory.hh:328
virtual void insertBoundarySegment([[maybe_unused]] const std::vector< unsigned int > &vertices)
insert a boundary segment
Definition: common/gridfactory.hh:362
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:344
virtual std::unique_ptr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition: common/gridfactory.hh:370
Different resources needed by all grid implementations.