dune-grid  2.3.1
alugrid/2d/grid.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_ALU2DGRIDGRID_HH
4 #define DUNE_ALU2DGRIDGRID_HH
5 
6 //- System includes
7 #include "alu2dinclude.hh"
8 #include <iostream>
9 #include <vector>
10 
11 //- Dune includes
15 #include <dune/common/static_assert.hh>
16 
17 #include <dune/grid/common/grid.hh>
22 #include <dune/common/parallel/mpihelper.hh>
23 
25 
26 // bnd projection stuff
29 
30 //- Local includes
31 #include "indexsets.hh"
33 #include "datahandle.hh"
34 
35 namespace Dune {
36 
37  // Forward declarations
38  template<int cd, int dim, class GridImp>
39  class ALU2dGridEntity;
40  template<int cd, PartitionIteratorType pitype, class GridImp >
41  class ALU2dGridLevelIterator;
42  template<int cd, class GridImp >
43  class ALU2dGridEntityPointer;
44  template<int cd, class GridImp >
45  class ALU2dGridEntitySeed;
46  template<int mydim, int coorddim, class GridImp>
47  class ALU2dGridMakeableGeometry;
48  template<int mydim, int cdim, class GridImp>
49  class ALU2dGridGeometry;
50  template<class GridImp>
51  class ALU2dGridHierarchicIterator;
52  template<class GridImp>
53  class ALU2dGridIntersectionBase;
54  template<class GridImp>
55  class ALU2dGridLevelIntersectionIterator;
56  template<class GridImp>
57  class ALU2dGridLeafIntersectionIterator;
58  template<int codim, PartitionIteratorType pitype, class GridImp>
59  class ALU2dGridLeafIterator;
60  template <int mydim, int coorddim, class GridImp>
61  class ALU2dGridMakeableEntity;
62  template <class GridImp>
63  class ALU2dGridFaceGeometryInfo;
64  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
65  class ALU2dGridLocalIdSet;
66  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
67  class ALU2dGridHierarchicIndexSet;
68  template <class EntityImp>
69  class ALUMemoryProvider;
70  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
71  class ALU2dGrid;
72  template <class GridImp, class GeometryImp, int nChild>
73  class ALULocalGeometryStorage;
74 
75  class ALU2dObjectStream;
76 
77  // Internal Forward Declarations
78  // -----------------------------
79 
80  template < int dimw, class Comm >
81  struct ALUGridBaseGrid< 2, dimw, cube, Comm >
82  {
84  };
85 
86  template < int dimw, class Comm >
87  struct ALUGridBaseGrid< 2, dimw, simplex, Comm >
88  {
90  };
91 
92 
93  //
94  // --ALU2dGrid
95  // --Grid
96  //
97  //**********************************************************************
98  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
100  {
102 
105 
108 
109  typedef int GlobalIdType;
110  typedef int LocalIdType;
111 
112  struct Traits
113  {
114  typedef GridImp Grid;
115 
118 
122 
124 
126  typedef std::vector< const DuneBoundaryProjectionType *> DuneBoundaryProjectionVector;
127 
128  template <int cd>
129  struct Codim
130  {
131  // IMPORTANT: Codim<codim>::Geometry == Geometry<dim-codim,dimw>
132  typedef ALU2dGridGeometry< dim-cd, dimworld, const GridImp > GeometryImpl;
133  typedef ALU2dGridGeometry< dim-cd, dim, const GridImp > LocalGeometryImpl;
134  typedef Dune::Geometry< dim-cd, dimworld, const GridImp, ALU2dGridGeometry > Geometry;
135  typedef Dune::Geometry< dim-cd, dim, const GridImp, ALU2dGridGeometry > LocalGeometry;
136 
137  // we could - if needed - introduce an other struct for dimglobal of Geometry
139 
142 
143  // minimal information to generate entities
145 
146  template <PartitionIteratorType pitype>
147  struct Partition
148  {
151  };
152 
155 
156  };
157 
158  template <PartitionIteratorType pitype>
159  struct Partition
160  {
165  };
166 
171 
176 
177 #if ALU2DGRID_PARALLEL
178  typedef Dune :: CollectiveCommunication< MPI_Comm >
180 #else
181  typedef Dune :: CollectiveCommunication< GridImp >
183 #endif
184  };
185 
188 
191  }; // end of ALU2dGridFamily
192 
193 
208  template< int dim, int dimworld, ALU2DSPACE ElementType eltype >
209  class ALU2dGrid
210  : public GridDefaultImplementation< dim, dimworld, alu2d_ctype, ALU2dGridFamily< dim, dimworld, eltype > >,
211  public HasObjectStream,
212  public HasHierarchicIndexSet
213  {
216 
217  dune_static_assert( dim == 2, "ALU2dGrid only implemented for grid dim 2." );
218  dune_static_assert( dimworld == 2 || dimworld == 3, "ALU2dGrid only implemented for world dim 2 or 3." );
219 
220  public:
221  static const ALU2DSPACE ElementType elementType = eltype;
222 
224 
225  // new intersection iterator is a wrapper which get itersectioniteratoimp as pointers
228 
230 
231  private:
232 
233  typedef typename ALU2dImplTraits<dimworld, elementType >::HmeshType HmeshType ;
234  typedef typename ALU2dImplTraits<dimworld, elementType >::HElementType HElementType ;
235  typedef typename ALU2dImplTraits<dimworld, elementType >::ElementType ElementType ;
236 
237  template< class > friend struct DGFBaseFactory;
238 
239  template< int, int, class > friend class ALU2dGridEntity;
240 
241  friend class ALU2dGridGeometry<0,dimworld,const ThisType>;
242  friend class ALU2dGridGeometry<1,dimworld,const ThisType>;
243  friend class ALU2dGridGeometry<dim,dimworld,const ThisType>;
244  template< class, class, int > friend class ALULocalGeometryStorage;
245 
246  friend class ALU2dGridEntityPointer<0,const ThisType>;
247  friend class ALU2dGridEntityPointer<1,const ThisType>;
248  friend class ALU2dGridEntityPointer<dim,const ThisType>;
249 
250  friend class ALU2dGridHierarchicIndexSet<dim,dimworld,elementType>;
251 
252  friend class ALU2dGridIntersectionBase < const ThisType > ;
255 
256  //**********************************************************
257  // The Interface Methods
258  //**********************************************************
259  protected:
260  typedef MakeableInterfaceObject<typename Traits::template
264 
265  public:
266 
271 
274 
277 
281 
284 
287 
288 
293 
296  typedef typename Traits::template Codim<0>::LeafIterator LeafIteratorType;
297  typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
298 
300  typedef ALU2dGridLevelIterator<0, All_Partition, const ThisType> LevelIteratorImp;
301  typedef typename Traits::template Codim<0>::LevelIterator LevelIteratorType;
302  typedef typename Traits::template Codim<0>::LevelIterator LevelIterator;
303 
305 
307 
308 
310  enum {
312  MAXL = 64
313  };
314 
316  enum {
319  };
320 
322  enum {
327  };
328 
333 
334 #ifdef ALUGRID_VERTEX_PROJECTION
335 
336  typedef ALUGridSpace :: VertexProjection< dimworld > ALUGridVertexProjectionType;
337 #endif
338 
339 
340  protected:
341 
344  // type of ALUGrid boundary projection wrapper
346 
349  //- --constructor
350  ALU2dGrid(const std::string macroTriangFilename,
351  const int nrOfHangingNodes,
354  std::istream* macroFile = 0);
355 
356  // method creating mesh object
357  HmeshType* createGrid(const std::string&,
358  const int,
359  std::istream* );
360 
362  explicit ALU2dGrid( int );
363 
364  public:
366  ~ALU2dGrid();
367 
370  int maxLevel() const;
371 
374  template<int cd, PartitionIteratorType pitype>
375  typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
376  lbegin (int level) const;
377 
379  template<int cd, PartitionIteratorType pitype>
380  typename Traits::template Codim<cd>::template Partition<pitype>::LevelIterator
381  lend (int level) const;
382 
384  template<int cd>
385  typename Traits::template Codim<cd>::
387  lbegin (int level) const;
388 
390  template<int cd>
391  typename Traits::template Codim<cd>::
393  lend (int level) const;
394 
396  LevelIteratorType lbegin (int level) const;
397 
399  LevelIteratorType lend (int level) const;
400 
402  template <int codim, PartitionIteratorType pitype>
404  leafbegin() const;
405 
407  template <int codim, PartitionIteratorType pitype>
409  leafend() const;
410 
412  template <int codim>
413  typename Traits::template Codim<codim>::LeafIterator
414  leafbegin() const;
415 
417  template <int codim>
418  typename Traits::template Codim<codim>::LeafIterator
419  leafend() const;
420 
421  private:
423  LeafIteratorType leafbegin () const;
424 
426  LeafIteratorType leafend () const;
427 
428  public:
430  int size (int level, int cd) const;
431 
433  int size (int codim) const;
434 
436  int size (int level, GeometryType type) const;
437 
439  int size (GeometryType type) const;
440 
442  const std::vector<GeometryType>& geomTypes (int codim) const { return geomTypes_[codim]; }
443 
444  //****************************************************************
445  // index and id sets
446  //****************************************************************
447 
449  const GlobalIdSet & globalIdSet () const;
450 
452  const LocalIdSet & localIdSet () const;
453 
455  int hierSetSize (int cd) const;
456 
458  const HierarchicIndexSet & hierarchicIndexSet () const ;
459 
461  const typename Traits :: LeafIndexSet & leafIndexSet () const;
462 
464  const typename Traits :: LevelIndexSet & levelIndexSet (int level) const;
465 
466 
467  //**********************************************************
468  // End of Interface Methods
469  //**********************************************************
470 
471  // return reference to org ALU2dGrid
472  // private method, but otherwise we have to friend class all possible
473  // types of LevelIterator ==> later
474  HmeshType & myGrid();
475  HmeshType & myGrid() const;
476 
478  void globalRefine ( int refCount );
479 
480  template< class GridImp, class DataHandle >
481  void globalRefine ( int refCount, AdaptDataHandleInterface< GridImp, DataHandle > &hamdle );
482 
484  bool preAdapt ( );
485 
487  void postAdapt ( );
488 
492  bool adapt ();
493 
494  template< class GridImp, class DataHandle >
496 
497  // refine grid
498  bool refineGrid();
499 
501  int getMark(const typename Traits::template Codim<0>::Entity & e) const;
502 
504  bool mark( int refCount , const typename Traits::template Codim<0>::Entity & e);
505 
507  const CollectiveCommunicationType & comm() const;
508  private:
510 
511  void updateStatus();
512 
513  void calcMaxlevel();
514 
515  void calcExtras();
516 
517  // clear refinement marker of element and all children
518  void hierarchicClear( HElementType *el );
519  public:
523 
524  protected:
525  // create GeomTypes
526  void makeGeomTypes ();
527 
528  friend class Conversion<ALU2dGrid<dim, dimworld,eltype>, HasObjectStream>;
529  friend class Conversion<const ALU2dGrid<dim, dimworld,eltype>, HasObjectStream>;
530 
531  friend class Conversion<ALU2dGrid<dim, dimworld,eltype>, HasHierarchicIndexSet>;
532  friend class Conversion<const ALU2dGrid<dim, dimworld,eltype>, HasHierarchicIndexSet>;
533 
534  private:
536  ALU2dGrid( const ThisType & g );
537 
539  ThisType & operator = (const ThisType & g);
540 
541  protected:
542  // check macro file and return const char * to filename
543  const char * checkMacroGridFile(const std::string & filename);
544 
546  mutable HmeshType* mygrid_;
547 
548  // return reference to grid
549  HmeshType& mesh() const {
550  assert(mygrid_);
551  return *mygrid_;
552  }
553 
554 #ifdef USE_SMP_PARALLEL
555  std::vector< GridObjectFactoryType > factoryVec_;
556 #else
558 #endif
559 
562 
565 
567  mutable std::vector < LevelIndexSetImp * > levelIndexVec_;
568 
569  // at the moment the number of different geom types is 1
570  enum { numberOfGeomTypes = 1 };
571  std::vector< std::vector<GeometryType> > geomTypes_;
572 
575 
578  const int nrOfHangingNodes_;
579 
583 
584  // flag to make sure postAdapt is called after adapt
586 
587  // pointer to Dune boundary projection
589 
590  // pointer to Dune boundary projection
592 
593  // boundary projection for vertices
595 
597  {
598  return bndPrj_;
599  }
600 
602  const DuneBoundaryProjectionType* boundaryProjection(const int segmentIndex) const
603  {
604  if( bndPrj_ )
605  {
606  return bndPrj_;
607  }
608  else
609  {
610  // note pointer can be zero (identity mapping)
611  assert( bndVec_ );
612  assert( segmentIndex < (int) bndVec_->size() );
613  return (*bndVec_)[ segmentIndex ];
614  }
615  }
616 
617  public:
619  size_t numBoundarySegments () const
620  {
621 #ifdef ALUGRID_VERTEX_PROJECTION
622  return myGrid().numMacroBndSegments();
623 #else
624  derr << "Method available in any version of ALUGrid > 1.14 \n";
625  return 0;
626 #endif
627  }
628 
631  {
632  return (vertexProjection_ != 0);
633  }
634 
636 
637  public:
638  template< class IntersectionType >
639  const typename BaseType
640  :: template ReturnImplementationType< IntersectionType>
641  :: ImplementationType &
642  getRealIntersection ( const IntersectionType &intersection ) const
643  {
644  return this->getRealImplementation( intersection );
645  }
646 
648 #ifdef USE_SMP_PARALLEL
649  assert( (int) factoryVec_.size() > GridObjectFactoryType :: threadNumber() );
650  return factoryVec_[ GridObjectFactoryType :: threadNumber() ];
651 #else
652  return factory_;
653 #endif
654  }
655 
656  protected:
657  // max level of grid
661  friend class LeafIntersectionIteratorWrapper < const ThisType > ;
663 
665  public:
667  private:
668  // always update this marker!!!
669  mutable ALU2dGridLeafMarkerVectorType leafMarker_;
670 
671  public:
672  template < class EntitySeed >
673  typename Traits :: template Codim< EntitySeed :: codimension > :: EntityPointer
674  entityPointer( const EntitySeed& seed ) const
675  {
676  enum { codim = EntitySeed :: codimension };
678  return ALUPointer( factory(), seed ) ;
679  }
680 
684  {
685  assert( level >= 0);
686  assert( level <= MAXL);
687  return marker_[level];
688  }
689 
693  {
694  return leafMarker_;
695  }
696 
699  template <GrapeIOFileFormatType ftype>
700  bool writeGrid( const std::string filename, alu2d_ctype time ) const ;
701 
702  bool writeGrid_Xdr( const std::string filename, alu2d_ctype time ) const ;
703  bool writeGrid_Ascii( const std::string filename, alu2d_ctype time ) const ;
704 
707  template <GrapeIOFileFormatType ftype>
708  bool readGrid( const std::string filename, alu2d_ctype & time );
709 
711  void backup( std::ostream& ) const ;
712 
714  void restore( std::istream& ) ;
715 
717  bool conformingRefinement () const
718  {
719  return ! nonConform ();
720  }
721 
722  protected:
725  bool nonConform () const
726  {
727  return (nrOfHangingNodes_ > 0);
728  }
729 
730 #if ALU2DGRID_PARALLEL
731  typedef RankManager<ThisType> RankManagerType;
732  RankManagerType rankManager_;
733  public:
734  const RankManagerType& rankManager() const
735  {
736  return rankManager_;
737  }
738 #endif
739 
740  public:
742  template<class DataHandleImp,class DataTypeImp>
743  void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
744  InterfaceType iftype, CommunicationDirection dir, int level) const;
745 
749  template<class DataHandleImp,class DataTypeImp>
750  void communicate (CommDataHandleIF<DataHandleImp,DataTypeImp> & data,
751  InterfaceType iftype, CommunicationDirection dir) const;
752 
753  int ghostSize ( int level, int codim ) const
754  {
755  return ghostSize( codim );
756  }
757 
758  int ghostSize ( int codim ) const
759  {
760 #if ALU2DGRID_PARALLEL
761  return 1;
762 #else
763  return 0;
764 #endif
765  }
766 
768  bool loadBalance() ;
769 
771  template<class DataHandle>
772  bool loadBalance(DataHandle& data) ;
773 
774  void checkManager() {
775 #if ALU2DGRID_PARALLEL
776  rankManager_.notifyMarking () ;
777 #endif
778  }
779 
780  }; // end class ALU2dGrid
781 
782  namespace Capabilities
783  {
784  template<int dim, int dimw, ALU2DSPACE ElementType eltype, int cdim>
785  struct hasEntity<ALU2dGrid<dim,dimw,eltype>, cdim >
786  {
787  static const bool v = true;
788  };
789 
790  template<int dim, int dimw, ALU2DSPACE ElementType eltype>
791  struct isLevelwiseConforming< ALU2dGrid<dim,dimw,eltype> >
792  {
793  static const bool v = false;
794  };
795 
796  } // end namespace Capabilities
797 
798 } // end namespace Dune
799 
800 #include "entity.hh"
801 #include "geometry.hh"
804 
805 #include "grid_imp.cc"
806 
807 #endif