dune-grid  2.7.0
uggridfactory.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 
4 #ifndef DUNE_UGGRID_FACTORY_HH
5 #define DUNE_UGGRID_FACTORY_HH
6 
12 #include <array>
13 #include <memory>
14 #include <vector>
15 
16 #include <dune/common/fvector.hh>
17 #include <dune/common/to_unique_ptr.hh>
18 
21 #include <dune/grid/uggrid.hh>
22 
23 namespace Dune {
24 
25 
161  template <int dimworld>
162  class GridFactory<UGGrid<dimworld> > : public GridFactoryInterface<UGGrid<dimworld> > {
163 
165  typedef typename UGGrid<dimworld>::ctype ctype;
166 
167  // UGGrid only in 2d and 3d
168  static_assert(dimworld==2 || dimworld == 3, "UGGrid only in 2d and 3d");
169 
170  public:
171 
173  GridFactory();
174 
186 
188  ~GridFactory();
189 
191  virtual void insertVertex(const FieldVector<ctype,dimworld>& pos);
192 
197  virtual void insertElement(const GeometryType& type,
198  const std::vector<unsigned int>& vertices);
199 
206  void insertBoundarySegment(const std::vector<unsigned int>& vertices);
207 
212  void insertBoundarySegment(const std::vector<unsigned int>& vertices,
213  const std::shared_ptr<BoundarySegment<dimworld> > &boundarySegment);
214 
215 
220  virtual ToUniquePtr<UGGrid<dimworld>> createGrid();
221 
223 
224  template< int codim >
225  struct Codim
226  {
228  };
229 
234  virtual unsigned int
235  insertionIndex ( const typename Codim< 0 >::Entity &entity ) const
236  {
237  return UG_NS<dimension>::levelIndex(entity.impl().target_);
238  }
239 
244  virtual unsigned int
245  insertionIndex ( const typename Codim< dimension >::Entity &entity ) const
246  {
247  return UG_NS<dimension>::levelIndex(entity.impl().target_);
248  }
249 
254  virtual unsigned int
255  insertionIndex ( const typename UGGrid<dimworld>::LeafIntersection &intersection ) const
256  {
257  return intersection.boundarySegmentIndex();
258  }
259 
261  virtual bool
262  wasInserted ( const typename UGGrid<dimworld>::LeafIntersection &intersection ) const
263  {
264  return (insertionIndex( intersection ) < boundarySegmentVertices_.size());
265  }
266 
268 
274  {
275  return grid_->comm();
276  }
277 
278  private:
279 
280  // Initialize the grid structure in UG
281  void createBegin();
282 
283  // Pointer to the grid being built
284  UGGrid<dimworld>* grid_;
285 
286  // True if the factory allocated the grid itself, false if the
287  // grid was handed over from the outside
288  bool factoryOwnsGrid_;
289 
291  std::vector<std::array<int, dimworld*2-2> > boundarySegmentVertices_;
292 
295  std::vector<unsigned char> elementTypes_;
296 
299  std::vector<unsigned int> elementVertices_;
300 
302  std::vector<FieldVector<double, dimworld> > vertexPositions_;
303 
304  };
305 
306 }
307 
308 #endif
Dune::GridFactory< UGGrid< dimworld > >::Communication
typename UGGrid< dimworld >::CollectiveCommunication Communication
Definition: uggridfactory.hh:267
Dune::BoundarySegment
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:35
Dune::UGGrid
Front-end for the grid manager of the finite element toolbox UG.
Definition: uggrid.hh:226
uggrid.hh
The UGGrid class.
Dune::GridFactory
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:269
Dune::GridFactory< UGGrid< dimworld > >::Codim::Entity
UGGrid< dimworld >::template Codim< codim >::Entity Entity
Definition: uggridfactory.hh:227
Dune::GridFactory< UGGrid< dimworld > >::insertionIndex
virtual unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
Return the number of the element in the order of insertion into the factory.
Definition: uggridfactory.hh:235
Dune::GridFactoryInterface::insertionIndex
virtual unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
obtain an element's insertion index
Definition: common/gridfactory.hh:175
gridfactory.hh
Provide a generic factory class for unstructured grids.
Dune::GridFactory< UGGrid< dimworld > >::insertionIndex
virtual unsigned int insertionIndex(const typename UGGrid< dimworld >::LeafIntersection &intersection) const
Return the number of the intersection in the order of insertion into the factory.
Definition: uggridfactory.hh:255
Dune::GridFactory::insertElement
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
Definition: common/gridfactory.hh:301
Dune::GridFactory< UGGrid< dimworld > >::wasInserted
virtual bool wasInserted(const typename UGGrid< dimworld >::LeafIntersection &intersection) const
Return true if the intersection has been explictily insterted into the factory.
Definition: uggridfactory.hh:262
Dune::GridFactoryInterface::dimension
static const int dimension
dimension of the grid
Definition: common/gridfactory.hh:74
Dune::GridFactory< UGGrid< dimworld > >::insertionIndex
virtual unsigned int insertionIndex(const typename Codim< dimension >::Entity &entity) const
Return the number of the vertex in the order of insertion into the factory.
Definition: uggridfactory.hh:245
Dune::GridFactory::createGrid
virtual ToUniquePtr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition: common/gridfactory.hh:327
Dune::GridFactory::GridFactory
GridFactory()
Default constructor.
Definition: common/gridfactory.hh:285
Dune::GridFactory< UGGrid< dimworld > >::comm
Communication comm() const
Return the Communication used by the grid factory.
Definition: uggridfactory.hh:273
Dune::GridFactoryInterface
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:69
Dune::GridFactory::insertBoundarySegment
virtual void insertBoundarySegment(const std::vector< unsigned int > &vertices)
insert a boundary segment
Definition: common/gridfactory.hh:319
boundarysegment.hh
Base class for grid boundary segments of arbitrary geometry.
Dune
Include standard header files.
Definition: agrid.hh:58
Dune::GridFactory::insertVertex
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: common/gridfactory.hh:290
Dune::VTK::GeometryType
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:180