dune-grid  2.7.1
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 
174 
186 
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
Base class for grid boundary segments of arbitrary geometry.
The UGGrid class.
Include standard header files.
Definition: agrid.hh:59
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:180
Base class for classes implementing geometries of boundary segments.
Definition: boundarysegment.hh:92
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:70
virtual unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
obtain an element's insertion index
Definition: common/gridfactory.hh:175
static const int dimension
dimension of the grid
Definition: common/gridfactory.hh:74
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:269
Front-end for the grid manager of the finite element toolbox UG.
Definition: uggrid.hh:227
void insertBoundarySegment(const std::vector< unsigned int > &vertices, const std::shared_ptr< BoundarySegment< dimworld > > &boundarySegment)
Method to insert an arbitrarily shaped boundary segment into a coarse grid.
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
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
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
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
typename UGGrid< dimworld >::CollectiveCommunication Communication
Definition: uggridfactory.hh:267
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
Communication comm() const
Return the Communication used by the grid factory.
Definition: uggridfactory.hh:273
GridFactory(UGGrid< dimworld > *grid)
Constructor for a given grid object.
virtual ToUniquePtr< UGGrid< dimworld > > createGrid()
Finalize grid creation and hand over the grid.
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
void insertBoundarySegment(const std::vector< unsigned int > &vertices)
Method to insert a boundary segment into a coarse grid.
UGGrid< dimworld >::template Codim< codim >::Entity Entity
Definition: uggridfactory.hh:227
Provide a generic factory class for unstructured grids.