dune-grid  2.2.0
alugrid/2d/grid.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU2DGRIDGRID_HH
2 #define DUNE_ALU2DGRIDGRID_HH
3 
4 //- System includes
5 #include "alu2dinclude.hh"
6 #include <iostream>
7 #include <vector>
8 
9 //- Dune includes
13 #include <dune/common/deprecated.hh>
14 #include <dune/common/static_assert.hh>
15 
16 #include <dune/grid/common/grid.hh>
21 #include <dune/common/mpihelper.hh>
22 
24 
25 // bnd projection stuff
28 
29 //- Local includes
30 #include "indexsets.hh"
32 #include "datahandle.hh"
33 
34 namespace Dune {
35 
36  // Forward declarations
37  template<int cd, int dim, class GridImp>
38  class ALU2dGridEntity;
39  template<int cd, PartitionIteratorType pitype, class GridImp >
40  class ALU2dGridLevelIterator;
41  template<int cd, class GridImp >
42  class ALU2dGridEntityPointer;
43  template<int cd, class GridImp >
44  class ALU2dGridEntitySeed;
45  template<int mydim, int coorddim, class GridImp>
46  class ALU2dGridMakeableGeometry;
47  template<int mydim, int cdim, class GridImp>
48  class ALU2dGridGeometry;
49  template<class GridImp>
50  class ALU2dGridHierarchicIterator;
51  template<class GridImp>
52  class ALU2dGridIntersectionBase;
53  template<class GridImp>
54  class ALU2dGridLevelIntersectionIterator;
55  template<class GridImp>
56  class ALU2dGridLeafIntersectionIterator;
57  template<int codim, PartitionIteratorType pitype, class GridImp>
58  class ALU2dGridLeafIterator;
59  template <int mydim, int coorddim, class GridImp>
60  class ALU2dGridMakeableEntity;
61  template <class GridImp>
62  class ALU2dGridFaceGeometryInfo;
63  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
64  class ALU2dGridLocalIdSet;
65  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
66  class ALU2dGridHierarchicIndexSet;
67  template <class EntityImp>
68  class ALUMemoryProvider;
69  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
70  class ALU2dGrid;
71  template <class GridImp, class GeometryImp, int nChild>
72  class ALULocalGeometryStorage;
73 
74  class ALU2dObjectStream;
75 
76  // Internal Forward Declarations
77  // -----------------------------
78 
79  template < int dimw, class Comm >
80  struct ALUGridBaseGrid< 2, dimw, cube, Comm >
81  {
83  };
84 
85  template < int dimw, class Comm >
86  struct ALUGridBaseGrid< 2, dimw, simplex, Comm >
87  {
89  };
90 
91 
92  //
93  // --ALU2dGrid
94  // --Grid
95  //
96  //**********************************************************************
97  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
99  {
101 
104 
107 
108  typedef int GlobalIdType;
109  typedef int LocalIdType;
110 
111  struct Traits
112  {
113  typedef GridImp Grid;
114 
117 
121 
123 
125  typedef std::vector< const DuneBoundaryProjectionType *> DuneBoundaryProjectionVector;
126 
127  template <int cd>
128  struct Codim
129  {
130  // IMPORTANT: Codim<codim>::Geometry == Geometry<dim-codim,dimw>
131  typedef ALU2dGridGeometry< dim-cd, dimworld, const GridImp > GeometryImpl;
132  typedef ALU2dGridGeometry< dim-cd, dim, const GridImp > LocalGeometryImpl;
133  typedef Dune::Geometry< dim-cd, dimworld, const GridImp, ALU2dGridGeometry > Geometry;
134  typedef Dune::Geometry< dim-cd, dim, const GridImp, ALU2dGridGeometry > LocalGeometry;
135 
136  // we could - if needed - introduce an other struct for dimglobal of Geometry
138 
141 
142  // minimal information to generate entities
144 
145  template <PartitionIteratorType pitype>
146  struct Partition
147  {
150  };
151 
154 
155  };
156 
157  template <PartitionIteratorType pitype>
158  struct Partition
159  {
164  };
165 
170 
175 
176 #if ALU2DGRID_PARALLEL
177  typedef Dune :: CollectiveCommunication< MPI_Comm >
179 #else
180  typedef Dune :: CollectiveCommunication< GridImp >
182 #endif
183  };
184 
187 
190  }; // end of ALU2dGridFamily
191 
192 
207  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
208  class ALU2dGrid
209  : public GridDefaultImplementation< dim, dimworld, alu2d_ctype, ALU2dGridFamily< dim, dimworld, eltype > >,
210  public HasObjectStream,
211  public HasHierarchicIndexSet
212  {
215 
216  dune_static_assert( dim == 2, "ALU2dGrid only implemented for grid dim 2." );
217  dune_static_assert( dimworld == 2 || dimworld == 3, "ALU2dGrid only implemented for world dim 2 or 3." );
218 
219  public:
220  static const ALU2DSPACE ElementType elementType = eltype;
221 
223 
224  // new intersection iterator is a wrapper which get itersectioniteratoimp as pointers
227 
229 
230  private:
231 
232  typedef typename ALU2dImplTraits<dimworld, elementType >::HmeshType HmeshType ;
233  typedef typename ALU2dImplTraits<dimworld, elementType >::HElementType HElementType ;
234  typedef typename ALU2dImplTraits<dimworld, elementType >::ElementType ElementType ;
235 
236  template< class > friend class DGFBaseFactory;
237 
238  template< int, int, class > friend class ALU2dGridEntity;
239 
240  friend class ALU2dGridGeometry<0,dimworld,const ThisType>;
241  friend class ALU2dGridGeometry<1,dimworld,const ThisType>;
242  friend class ALU2dGridGeometry<dim,dimworld,const ThisType>;
243  template< class, class, int > friend class ALULocalGeometryStorage;
244 
245  friend class ALU2dGridEntityPointer<0,const ThisType>;
246  friend class ALU2dGridEntityPointer<1,const ThisType>;
247  friend class ALU2dGridEntityPointer<dim,const ThisType>;
248 
249  friend class ALU2dGridHierarchicIndexSet<dim,dimworld,elementType>;
250 
251  friend class ALU2dGridIntersectionBase < const ThisType > ;
254 
255  //**********************************************************
256  // The Interface Methods
257  //**********************************************************
258  protected:
259  typedef MakeableInterfaceObject<typename Traits::template
263 
264  public:
265 
270 
273 
276 
280 
283 
286 
287 
292 
295  typedef typename Traits::template Codim<0>::LeafIterator LeafIteratorType;
296  typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
297 
299  typedef ALU2dGridLevelIterator<0, All_Partition, const ThisType> LevelIteratorImp;
300  typedef typename Traits::template Codim<0>::LevelIterator LevelIteratorType;
301  typedef typename Traits::template Codim<0>::LevelIterator LevelIterator;
302 
304 
306 
307 
309  enum {
311  MAXL = 64 };
312 
314  enum {
317 
319  enum {
324 
329 
330 #ifdef ALUGRID_VERTEX_PROJECTION
331 
332  typedef ALUGridSpace :: VertexProjection< dimworld > ALUGridVertexProjectionType;
333 #endif
334 
335 
336  protected:
337 
340  // type of ALUGrid boundary projection wrapper
342 
345  //- --constructor
346  ALU2dGrid(const std::string macroTriangFilename,
347  const int nrOfHangingNodes,
350  std::istream* macroFile = 0);
351 
352  // method creating mesh object
353  HmeshType* createGrid(const std::string&,
354  const int,
355  std::istream* );
356 
358  explicit ALU2dGrid( int );
359 
360  public:
362  ~ALU2dGrid();
363 
366  int maxLevel() const;
367 
370  template<int cd, PartitionIteratorType pitype>
371  typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
372  lbegin (int level) const;
373 
375  template<int cd, PartitionIteratorType pitype>
376  typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
377  lend (int level) const;
378 
380  template<int cd>
381  typename Traits::template Codim<cd>::
383  lbegin (int level) const;
384 
386  template<int cd>
387  typename Traits::template Codim<cd>::
389  lend (int level) const;
390 
392  LevelIteratorType lbegin (int level) const;
393 
395  LevelIteratorType lend (int level) const;
396 
398  template <int codim, PartitionIteratorType pitype>
400  leafbegin() const;
401 
403  template <int codim, PartitionIteratorType pitype>
405  leafend() const;
406 
408  template <int codim>
409  typename Traits::template Codim<codim>::LeafIterator
410  leafbegin() const;
411 
413  template <int codim>
414  typename Traits::template Codim<codim>::LeafIterator
415  leafend() const;
416 
417  private:
419  LeafIteratorType leafbegin () const;
420 
422  LeafIteratorType leafend () const;
423 
424  public:
426  int size (int level, int cd) const;
427 
429  int size (int codim) const;
430 
432  int size (int level, GeometryType type) const;
433 
435  int size (GeometryType type) const;
436 
438  const std::vector<GeometryType>& geomTypes (int codim) const { return geomTypes_[codim]; }
439 
440  //****************************************************************
441  // index and id sets
442  //****************************************************************
443 
445  const GlobalIdSet & globalIdSet () const;
446 
448  const LocalIdSet & localIdSet () const;
449 
451  int hierSetSize (int cd) const;
452 
454  const HierarchicIndexSet & hierarchicIndexSet () const ;
455 
457  const typename Traits :: LeafIndexSet & leafIndexSet () const;
458 
460  const typename Traits :: LevelIndexSet & levelIndexSet (int level) const;
461 
462 
463  //**********************************************************
464  // End of Interface Methods
465  //**********************************************************
466 
467  // return reference to org ALU2dGrid
468  // private method, but otherwise we have to friend class all possible
469  // types of LevelIterator ==> later
470  HmeshType & myGrid();
471  HmeshType & myGrid() const;
472 
474  void globalRefine ( int refCount );
475 
476  template< class GridImp, class DataHandle >
477  void globalRefine ( int refCount, AdaptDataHandleInterface< GridImp, DataHandle > &hamdle );
478 
480  bool preAdapt ( );
481 
483  void postAdapt ( );
484 
488  bool adapt ();
489 
490  template< class GridImp, class DataHandle >
492 
493  // refine grid
494  bool refineGrid();
495 
497  int getMark(const typename Traits::template Codim<0>::Entity & e) const;
498 
500  bool mark( int refCount , const typename Traits::template Codim<0>::Entity & e);
501 
503  const CollectiveCommunicationType & comm() const;
504  private:
506 
507  void updateStatus();
508 
509  void calcMaxlevel();
510 
511  void calcExtras();
512 
513  // clear refinement marker of element and all children
514  void hierarchicClear( HElementType *el );
515  public:
519 
520  protected:
521  // create GeomTypes
522  void makeGeomTypes ();
523 
524  friend class Conversion<ALU2dGrid<dim, dimworld,eltype>, HasObjectStream>;
525  friend class Conversion<const ALU2dGrid<dim, dimworld,eltype>, HasObjectStream>;
526 
527  friend class Conversion<ALU2dGrid<dim, dimworld,eltype>, HasHierarchicIndexSet>;
528  friend class Conversion<const ALU2dGrid<dim, dimworld,eltype>, HasHierarchicIndexSet>;
529 
530  private:
532  ALU2dGrid( const ThisType & g );
533 
535  ThisType & operator = (const ThisType & g);
536 
537  protected:
538  // check macro file and return const char * to filename
539  const char * checkMacroGridFile(const std::string & filename);
540 
542  mutable HmeshType* mygrid_;
543 
544  // return reference to grid
545  HmeshType& mesh() const {
546  assert(mygrid_);
547  return *mygrid_;
548  }
549 
550 #ifdef USE_SMP_PARALLEL
551  std::vector< GridObjectFactoryType > factoryVec_;
552 #else
554 #endif
555 
558 
561 
563  mutable std::vector < LevelIndexSetImp * > levelIndexVec_;
564 
565  // at the moment the number of different geom types is 1
566  enum { numberOfGeomTypes = 1 };
567  std::vector< std::vector<GeometryType> > geomTypes_;
568 
571 
574  const int nrOfHangingNodes_;
575 
579 
580  // flag to make sure postAdapt is called after adapt
582 
583  // pointer to Dune boundary projection
585 
586  // pointer to Dune boundary projection
588 
589  // boundary projection for vertices
591 
593  {
594  return bndPrj_;
595  }
596 
598  const DuneBoundaryProjectionType* boundaryProjection(const int segmentIndex) const
599  {
600  if( bndPrj_ )
601  {
602  return bndPrj_;
603  }
604  else
605  {
606  // note pointer can be zero (identity mapping)
607  assert( bndVec_ );
608  assert( segmentIndex < (int) bndVec_->size() );
609  return (*bndVec_)[ segmentIndex ];
610  }
611  }
612 
613  public:
615  size_t numBoundarySegments () const
616  {
617 #ifdef ALUGRID_VERTEX_PROJECTION
618  return myGrid().numMacroBndSegments();
619 #else
620  derr << "Method available in any version of ALUGrid > 1.14 \n";
621  return 0;
622 #endif
623  }
624 
627  {
628  return (vertexProjection_ != 0);
629  }
630 
632 
633  public:
634  template< class IntersectionType >
635  const typename BaseType
636  :: template ReturnImplementationType< IntersectionType>
637  :: ImplementationType &
638  getRealIntersection ( const IntersectionType &intersection ) const
639  {
640  return this->getRealImplementation( intersection );
641  }
642 
644 #ifdef USE_SMP_PARALLEL
645  assert( (int) factoryVec_.size() > GridObjectFactoryType :: threadNumber() );
646  return factoryVec_[ GridObjectFactoryType :: threadNumber() ];
647 #else
648  return factory_;
649 #endif
650  }
651 
652  protected:
653  // max level of grid
657  friend class LeafIntersectionIteratorWrapper < const ThisType > ;
659 
661  public:
663  private:
664  // always update this marker!!!
665  mutable ALU2dGridLeafMarkerVectorType leafMarker_;
666 
667  public:
668  template < class EntitySeed >
669  typename Traits :: template Codim< EntitySeed :: codimension > :: EntityPointer
670  entityPointer( const EntitySeed& seed ) const
671  {
672  enum { codim = EntitySeed :: codimension };
673  typedef typename Traits :: template Codim< codim > :: EntityPointer EntityPointer;
675  return ALUPointer( factory(), seed ) ;
676  }
677 
681  {
682  assert( level >= 0);
683  assert( level <= MAXL);
684  return marker_[level];
685  }
686 
690  {
691  return leafMarker_;
692  }
693 
696  template <GrapeIOFileFormatType ftype>
697  bool writeGrid( const std::string filename, alu2d_ctype time ) const ;
698 
699  bool writeGrid_Xdr( const std::string filename, alu2d_ctype time ) const ;
700  bool writeGrid_Ascii( const std::string filename, alu2d_ctype time ) const ;
701 
704  template <GrapeIOFileFormatType ftype>
705  bool readGrid( const std::string filename, alu2d_ctype & time );
706 
707  protected:
710  bool nonConform () const
711  {
712  return (nrOfHangingNodes_ > 0);
713  }
714 
715 #if ALU2DGRID_PARALLEL
716  typedef RankManager<ThisType> RankManagerType;
717  RankManagerType rankManager_;
718  public:
719  const RankManagerType& rankManager() const
720  {
721  return rankManager_;
722  }
723 #endif
724 
725  public:
727  template<class DataHandleImp,class DataTypeImp>
728  void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
729  InterfaceType iftype, CommunicationDirection dir, int level) const;
730 
734  template<class DataHandleImp,class DataTypeImp>
735  void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
736  InterfaceType iftype, CommunicationDirection dir) const;
737 
738  int ghostSize ( int level, int codim ) const
739  {
740  return ghostSize( codim );
741  }
742 
743  int ghostSize ( int codim ) const
744  {
745 #if ALU2DGRID_PARALLEL
746  return 1;
747 #else
748  return 0;
749 #endif
750  }
751 
753  bool loadBalance() ;
754 
756  template<class DataHandle>
757  bool loadBalance(DataHandle& data) ;
758 
759  void checkManager() {
760 #if ALU2DGRID_PARALLEL
761  rankManager_.notifyMarking () ;
762 #endif
763  }
764 
765  }; // end class ALU2dGrid
766 
767  namespace Capabilities
768  {
769  template<int dim, int dimw, ALU2DSPACE ElementType eltype, int cdim>
770  struct hasEntity<ALU2dGrid<dim,dimw,eltype>, cdim >
771  {
772  static const bool v = true;
773  };
774 
775  template<int dim, int dimw, ALU2DSPACE ElementType eltype>
776  struct isLevelwiseConforming< ALU2dGrid<dim,dimw,eltype> >
777  {
778  static const bool v = false;
779  };
780 
781  } // end namespace Capabilities
782 
783 } // end namespace Dune
784 
785 #include "entity.hh"
786 #include "geometry.hh"
789 
790 #include "grid_imp.cc"
791 
792 #endif