dune-grid  2.2.1
alugrid/2d/alugrid.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU2D_ALUGRID_HH
2 #define DUNE_ALU2D_ALUGRID_HH
3 
4 // only include this code, if ENABLE_ALUGRID is defined
5 #if HAVE_ALUGRID
6 
11 
12 namespace Dune
13 {
14 
20 template<int dimw>
21 class ALUCubeGrid< 2, dimw >
22 : public Dune::ALU2dGrid< 2, dimw, ALU2DSPACE quadrilateral >
23 {
24  typedef ALUCubeGrid< 2, dimw > This;
25 
27  enum { dim = 2 };
28  enum { dimworld = dimw };
29 
30 public:
32  typedef typename BaseType :: DuneBoundaryProjectionType DuneBoundaryProjectionType;
33 
35  typedef typename BaseType :: DuneBoundaryProjectionVector DuneBoundaryProjectionVector;
36 
45  ALUCubeGrid(const std::string macroName,
46  const DuneBoundaryProjectionType* bndProject = 0,
47  const DuneBoundaryProjectionVector* bndVector = 0,
48  const bool verbose = true )
49  : BaseType(macroName,1, bndProject, bndVector)
50  {
51  if( verbose )
52  {
53  std::cout << "\nCreated serial ALUCubeGrid<"<<dim<<","<<dimworld;
54  std::cout <<"> from macro grid file '" << macroName << "'. \n\n";
55  }
56  }
57 
67  ALUCubeGrid(const std::string macroName,
68  std::istream& macroFile,
69  const DuneBoundaryProjectionType* bndProject = 0,
70  const DuneBoundaryProjectionVector* bndVector = 0,
71  const bool verbose = true )
72  : BaseType("",1, bndProject, bndVector, &macroFile)
73  {
74  if( verbose )
75  {
76  std::cout << "\nCreated serial ALUCubeGrid<"<<dim<<","<<dimworld;
77  if( macroName == "" )
78  std::cout <<">. \n\n";
79  else
80  std::cout <<"> from macro grid file '" << macroName << "'. \n\n";
81  }
82  }
83 
85  ALUCubeGrid( ) : BaseType(1)
86  {
87  std::cout << "\nCreated empty ALUCubeGrid<"<<dim<<","<<dimworld <<">. \n\n";
88  }
89 
90  enum {dimension=BaseType::dimension,dimensionworld=BaseType::dimensionworld};
91  enum { refineStepsForHalf = 1 };
92  typedef typename BaseType::ctype ctype;
93  typedef typename BaseType::GridFamily GridFamily;
94  typedef typename GridFamily::Traits Traits;
95  typedef typename BaseType::LocalIdSetImp LocalIdSetImp;
96  typedef typename Traits :: GlobalIdSet GlobalIdSet;
97  typedef typename Traits :: LocalIdSet LocalIdSet;
98  typedef typename GridFamily :: LevelIndexSetImp LevelIndexSetImp;
99  typedef typename GridFamily :: LeafIndexSetImp LeafIndexSetImp;
100  typedef typename BaseType::LeafIteratorImp LeafIteratorImp;
101  typedef typename Traits::template Codim<0>::LeafIterator LeafIteratorType;
102  typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
103  typedef typename BaseType::HierarchicIteratorImp HierarchicIteratorImp;
104 
105  template< PartitionIteratorType pitype >
106  struct Partition
107  {
109  LevelGridView;
111  LeafGridView;
112  };
113 
114  typedef typename Partition< All_Partition > :: LevelGridView LevelGridView;
115  typedef typename Partition< All_Partition > :: LeafGridView LeafGridView;
116 
117  template< PartitionIteratorType pitype >
118  typename Partition< pitype >::LevelGridView levelView ( int level ) const
119  {
120  typedef typename Partition< pitype >::LevelGridView LevelGridView;
121  typedef typename LevelGridView::GridViewImp LevelGridViewImp;
122  return LevelGridView( LevelGridViewImp( *this, level ) );
123  }
124 
125  template< PartitionIteratorType pitype >
126  typename Partition< pitype >::LeafGridView leafView () const
127  {
128  typedef typename Partition< pitype >::LeafGridView LeafGridView;
129  typedef typename LeafGridView::GridViewImp LeafGridViewImp;
130  return LeafGridView( LeafGridViewImp( *this ) );
131  }
132 
133  LevelGridView levelView ( int level ) const
134  {
135  typedef typename LevelGridView::GridViewImp LevelGridViewImp;
136  return LevelGridView( LevelGridViewImp( *this, level ) );
137  }
138 
139  LeafGridView leafView () const
140  {
141  typedef typename LeafGridView::GridViewImp LeafGridViewImp;
142  return LeafGridView( LeafGridViewImp( *this ) );
143  }
144 
145 private:
146  friend class Conversion< ALUCubeGrid<dimension,dimensionworld> , HasObjectStream > ;
147  friend class Conversion< const ALUCubeGrid<dimension,dimensionworld> , HasObjectStream > ;
148 
149  friend class Conversion< ALUCubeGrid<dimension,dimensionworld> , HasHierarchicIndexSet > ;
150  friend class Conversion< const ALUCubeGrid<dimension,dimensionworld> , HasHierarchicIndexSet > ;
151 
152  template< class >
153  friend class ALU2dGridFactory;
154 
156  ALUCubeGrid( const ALUCubeGrid & g ) ; // : BaseType(g) {}
157 
159  ALUCubeGrid<dim,dimworld>&
160  operator = (const ALUCubeGrid& g);
161 };
162 
168 template<int dimw>
169 class ALUSimplexGrid< 2, dimw >
170 : public Dune::ALU2dGrid< 2, dimw, ALU2DSPACE triangle >
171 {
172  typedef ALUSimplexGrid< 2, dimw > This;
173 
175  enum { dim = 2 };
176  enum { dimworld = dimw };
177 
178 public:
180  typedef typename BaseType :: DuneBoundaryProjectionType DuneBoundaryProjectionType;
181 
183  typedef typename BaseType :: DuneBoundaryProjectionVector DuneBoundaryProjectionVector;
184 
193  ALUSimplexGrid(const std::string macroName,
194  const DuneBoundaryProjectionType* bndProject = 0,
195  const DuneBoundaryProjectionVector* bndVector = 0,
196  const bool verbose = true )
197  : BaseType(macroName,1, bndProject, bndVector)
198  {
199  if( verbose )
200  {
201  std::cout << "\nCreated serial ALUSimplexGrid<"<<dim<<","<<dimworld;
202  std::cout <<"> from macro grid file '" << macroName << "'. \n\n";
203  }
204  }
205 
215  ALUSimplexGrid(const std::string macroName,
216  std::istream& macroFile,
217  const DuneBoundaryProjectionType* bndProject = 0,
218  const DuneBoundaryProjectionVector* bndVector = 0,
219  const bool verbose = true )
220  : BaseType("",1, bndProject, bndVector, &macroFile)
221  {
222  if( verbose )
223  {
224  std::cout << "\nCreated serial ALUSimplexGrid<"<<dim<<","<<dimworld;
225  if( macroName == "" )
226  std::cout <<">. \n\n";
227  else
228  std::cout <<"> from macro grid file '" << macroName << "'. \n\n";
229  }
230  }
231 
233  ALUSimplexGrid( ) : BaseType(1)
234  {
235  std::cout << "\nCreated empty ALUSimplexGrid<"<<dim<<","<<dimworld <<">. \n\n";
236  }
237 
238  enum {dimension=BaseType::dimension,dimensionworld=BaseType::dimensionworld};
239  enum { refineStepsForHalf = 1 };
240  typedef typename BaseType::ctype ctype;
241  typedef typename BaseType::GridFamily GridFamily;
242  typedef typename GridFamily::Traits Traits;
243  typedef typename BaseType::LocalIdSetImp LocalIdSetImp;
244  typedef typename Traits :: GlobalIdSet GlobalIdSet;
245  typedef typename Traits :: LocalIdSet LocalIdSet;
246  typedef typename GridFamily :: LevelIndexSetImp LevelIndexSetImp;
247  typedef typename GridFamily :: LeafIndexSetImp LeafIndexSetImp;
248  typedef typename BaseType::LeafIteratorImp LeafIteratorImp;
249  typedef typename Traits::template Codim<0>::LeafIterator LeafIteratorType;
250  typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
251  typedef typename BaseType::HierarchicIteratorImp HierarchicIteratorImp;
252 
253  template< PartitionIteratorType pitype >
254  struct Partition
255  {
257  LevelGridView;
259  LeafGridView;
260  };
261 
262  typedef typename Partition< All_Partition > :: LevelGridView LevelGridView;
263  typedef typename Partition< All_Partition > :: LeafGridView LeafGridView;
264 
265  template< PartitionIteratorType pitype >
266  typename Partition< pitype >::LevelGridView levelView ( int level ) const
267  {
268  typedef typename Partition< pitype >::LevelGridView LevelGridView;
269  typedef typename LevelGridView::GridViewImp LevelGridViewImp;
270  return LevelGridView( LevelGridViewImp( *this, level ) );
271  }
272 
273  template< PartitionIteratorType pitype >
274  typename Partition< pitype >::LeafGridView leafView () const
275  {
276  typedef typename Partition< pitype >::LeafGridView LeafGridView;
277  typedef typename LeafGridView::GridViewImp LeafGridViewImp;
278  return LeafGridView( LeafGridViewImp( *this ) );
279  }
280 
281  LevelGridView levelView ( int level ) const
282  {
283  typedef typename LevelGridView::GridViewImp LevelGridViewImp;
284  return LevelGridView( LevelGridViewImp( *this, level ) );
285  }
286 
287  LeafGridView leafView () const
288  {
289  typedef typename LeafGridView::GridViewImp LeafGridViewImp;
290  return LeafGridView( LeafGridViewImp( *this ) );
291  }
292 
293 private:
294  friend class Conversion< ALUSimplexGrid<dimension,dimensionworld> , HasObjectStream > ;
295  friend class Conversion< const ALUSimplexGrid<dimension,dimensionworld> , HasObjectStream > ;
296 
297  friend class Conversion< ALUSimplexGrid<dimension,dimensionworld> , HasHierarchicIndexSet > ;
298  friend class Conversion< const ALUSimplexGrid<dimension,dimensionworld> , HasHierarchicIndexSet > ;
299 
300  template< class >
301  friend class ALU2dGridFactory;
302 
304  ALUSimplexGrid( const ALUSimplexGrid & g ) ; // : BaseType(g) {}
305 
307  ALUSimplexGrid<dim,dimworld>&
308  operator = (const ALUSimplexGrid& g);
309 };
310 
338 template <int dim, int dimworld>
339 class ALUConformGrid {
340  dune_static_assert((AlwaysFalse<integral_constant<int,dim> >::value),
341  "The unspecialized version of ALUConformGrid is defined "
342  "for documentation purposes only, only the "
343  "specializations can actually be used.");
344 };
345 
346 namespace Capabilities {
358  template<int dim,int dimw, int cdim >
359  struct hasEntity<Dune::ALUConformGrid<dim, dimw>, cdim >
360  {
361  static const bool v = true;
362  };
363 
367  template<int dim,int dimw>
368  struct isParallel<const ALUConformGrid<dim, dimw> > {
369  static const bool v = false;
370  };
371 
375  template<int dim,int dimw>
376  struct isLevelwiseConforming< ALUConformGrid<dim,dimw> >
377  {
378  static const bool v = false;
379  };
380 
384  template<int dim,int dimw>
385  struct isLeafwiseConforming< ALUConformGrid<dim,dimw> >
386  {
387  static const bool v = true;
388  };
389 
393  template<int dim,int dimw>
394  struct hasBackupRestoreFacilities< ALUConformGrid<dim,dimw> >
395  {
396  static const bool v = true;
397  };
398 
399 } // end namespace Capabilities
400 
401 
402 
408 template<int dimw>
409 class ALUConformGrid< 2, dimw >
410 : public Dune::ALU2dGrid< 2, dimw, ALU2DSPACE triangle >
411 {
412  typedef ALUConformGrid< 2, dimw > This;
413 
415  enum { dim = 2 };
416  enum { dimworld = dimw };
417  public:
419  typedef typename BaseType :: DuneBoundaryProjectionType DuneBoundaryProjectionType;
420 
422  typedef typename BaseType :: DuneBoundaryProjectionVector DuneBoundaryProjectionVector;
423 
432  ALUConformGrid(const std::string macroName,
433  const DuneBoundaryProjectionType* bndProject = 0,
434  const DuneBoundaryProjectionVector* bndVector = 0,
435  const bool verbose = true)
436  : BaseType(macroName, 0, bndProject, bndVector)
437  {
438  if( verbose )
439  {
440  std::cout << "\nCreated serial ALUConformGrid<"<<dim<<","<<dimworld;
441  std::cout <<"> from macro grid file '" << macroName << "'. \n\n";
442  }
443  }
444 
454  ALUConformGrid(const std::string macroName,
455  std::istream& macroFile,
456  const DuneBoundaryProjectionType* bndProject = 0,
457  const DuneBoundaryProjectionVector* bndVector = 0,
458  const bool verbose = true )
459  : BaseType("", 0, bndProject, bndVector, &macroFile)
460  {
461  if( verbose )
462  {
463  std::cout << "\nCreated serial ALUConformGrid<"<<dim<<","<<dimworld;
464  if( macroName == "" )
465  std::cout <<">. \n\n";
466  else
467  std::cout <<"> from macro grid file '" << macroName << "'. \n\n";
468  }
469  }
470 
472  ALUConformGrid( ) : BaseType(0)
473  {
474  std::cout << "\nCreated empty ALUConformGrid<"<<dim<<","<<dimworld <<">. \n\n";
475  }
476 
478  static inline std::string name () { return "ALUConformGrid"; }
479 
480  enum {dimension=BaseType::dimension,dimensionworld=BaseType::dimensionworld};
481  enum { refineStepsForHalf = 2 };
482  typedef typename BaseType::ctype ctype;
483  typedef typename BaseType::GridFamily GridFamily;
484  typedef typename GridFamily::Traits Traits;
485  typedef typename BaseType::LocalIdSetImp LocalIdSetImp;
486  typedef typename Traits :: GlobalIdSet GlobalIdSet;
487  typedef typename Traits :: LocalIdSet LocalIdSet;
488  typedef typename GridFamily :: LevelIndexSetImp LevelIndexSetImp;
489  typedef typename GridFamily :: LeafIndexSetImp LeafIndexSetImp;
490  typedef typename BaseType::LeafIteratorImp LeafIteratorImp;
491  typedef typename Traits::template Codim<0>::LeafIterator LeafIteratorType;
492  typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
493  typedef typename BaseType::HierarchicIteratorImp HierarchicIteratorImp;
494 
495  template< PartitionIteratorType pitype >
496  struct Partition
497  {
499  LevelGridView;
501  LeafGridView;
502  };
503 
504  typedef typename Partition< All_Partition > :: LevelGridView LevelGridView;
505  typedef typename Partition< All_Partition > :: LeafGridView LeafGridView;
506 
507  template< PartitionIteratorType pitype >
508  typename Partition< pitype >::LevelGridView levelView ( int level ) const
509  {
510  typedef typename Partition< pitype >::LevelGridView LevelGridView;
511  typedef typename LevelGridView::GridViewImp LevelGridViewImp;
512  return LevelGridView( LevelGridViewImp( *this, level ) );
513  }
514 
515  template< PartitionIteratorType pitype >
516  typename Partition< pitype >::LeafGridView leafView () const
517  {
518  typedef typename Partition< pitype >::LeafGridView LeafGridView;
519  typedef typename LeafGridView::GridViewImp LeafGridViewImp;
520  return LeafGridView( LeafGridViewImp( *this ) );
521  }
522 
523  LevelGridView levelView ( int level ) const
524  {
525  typedef typename LevelGridView::GridViewImp LevelGridViewImp;
526  return LevelGridView( LevelGridViewImp( *this, level ) );
527  }
528 
529  LeafGridView leafView () const
530  {
531  typedef typename LeafGridView::GridViewImp LeafGridViewImp;
532  return LeafGridView( LeafGridViewImp( *this ) );
533  }
534 
535 private:
536  friend class Conversion< ALUConformGrid<dimension,dimensionworld> , HasObjectStream > ;
537  friend class Conversion< const ALUConformGrid<dimension,dimensionworld> , HasObjectStream > ;
538 
539  friend class Conversion< ALUConformGrid<dimension,dimensionworld> , HasHierarchicIndexSet > ;
540  friend class Conversion< const ALUConformGrid<dimension,dimensionworld> , HasHierarchicIndexSet > ;
541 
542  template< class >
543  friend class ALU2dGridFactory;
544 
546  ALUConformGrid( const ALUConformGrid & g ) ; // : BaseType(g) {}
547 
549  ALUConformGrid<dim,dimworld>&
550  operator = (const ALUConformGrid& g);
551 };
552 
553 /*-
554  (see ALUGrid homepage: http://www.mathematik.uni-freiburg.de/IAM/Research/alugrid/)
555 
556  \li Available Implementations
557  - quadrilateral and hexahedral elements only nonconforming refinement
558  - Dune::ALUGrid< 2, 2, cube, nonconforming >
559  - Dune::ALUGrid< 2, 3, cube, nonconforming >
560  - Dune::ALUGrid< 3, 3, cube, nonconforming >
561  - simplicial elements and nonconforming refinement
562  - Dune::ALUGrid< 2, 2, simplex, nonconforming >
563  - Dune::ALUGrid< 2, 3, simplex, nonconforming >
564  - Dune::ALUGrid< 3, 3, simplex, nonconforming >
565  - simplicial elements and bisection refinement
566  - Dune::ALUGrid< 2, 2, simplex, conforming >
567  - Dune::ALUGrid< 2, 3, simplex, conforming >
568  - Dune::ALUGrid< 3, 3, simplex, conforming > (work in progress)
569 
570  \note template parameter Comm defaults to MPI_Comm, if MPI is available, No_Comm otherwise.
571 */
572 template<int dimw, ALUGridElementType elType, ALUGridRefinementType refinementType, class Comm >
573 class ALUGrid< 2, dimw, elType, refinementType, Comm >
574  : public ALUGridBaseGrid < 2, dimw, elType, Comm > :: BaseGrid
575 {
576  typedef ALUGrid< 2, dimw, elType, refinementType, Comm > This;
577  typedef typename ALUGridBaseGrid < 2, dimw, elType, Comm > :: BaseGrid BaseType;
578 
579  enum { dim = 2 };
580  enum { dimworld = dimw };
581 
582 public:
584  typedef typename BaseType :: DuneBoundaryProjectionType DuneBoundaryProjectionType;
585 
587  typedef typename BaseType :: DuneBoundaryProjectionVector DuneBoundaryProjectionVector;
588 
597  ALUGrid(const std::string macroName,
598  const DuneBoundaryProjectionType* bndProject = 0,
599  const DuneBoundaryProjectionVector* bndVector = 0,
600  const bool verbose = true )
601  : BaseType(macroName, hangingNodes(), bndProject, bndVector)
602  {
603  if( verbose )
604  {
605  std::cout << "\nCreated serial " << name() << nameSuffix()
606  << " from macro grid file '" << macroName << "'." << std::endl << std::endl;
607  }
608  }
609 
619  ALUGrid(const std::string macroName,
620  std::istream& macroFile,
621  const DuneBoundaryProjectionType* bndProject = 0,
622  const DuneBoundaryProjectionVector* bndVector = 0,
623  const bool verbose = true )
624  : BaseType("", hangingNodes(), bndProject, bndVector, &macroFile)
625  {
626  if( verbose )
627  {
628  std::cout << "\nCreated serial " << name() << nameSuffix();
629  if( macroName != "" )
630  std::cout <<" from macro grid file '" << macroName;
631  std::cout << "." << std::endl << std::endl;
632  }
633  }
634 
635  static std::string name () { return std::string("ALUGrid"); }
636 
638  ALUGrid( ) : BaseType( hangingNodes() )
639  {
640  std::cout << "\nCreated serial " << name() << nameSuffix() << "." << std::endl << std::endl;
641  }
642 
643  enum {dimension=BaseType::dimension,dimensionworld=BaseType::dimensionworld};
644  enum { refineStepsForHalf = 1 };
645  typedef typename BaseType::ctype ctype;
646  typedef typename BaseType::GridFamily GridFamily;
647  typedef typename GridFamily::Traits Traits;
648  typedef typename BaseType::LocalIdSetImp LocalIdSetImp;
649  typedef typename Traits :: GlobalIdSet GlobalIdSet;
650  typedef typename Traits :: LocalIdSet LocalIdSet;
651  typedef typename GridFamily :: LevelIndexSetImp LevelIndexSetImp;
652  typedef typename GridFamily :: LeafIndexSetImp LeafIndexSetImp;
653  typedef typename BaseType::LeafIteratorImp LeafIteratorImp;
654  typedef typename Traits::template Codim<0>::LeafIterator LeafIteratorType;
655  typedef typename Traits::template Codim<0>::LeafIterator LeafIterator;
656  typedef typename BaseType::HierarchicIteratorImp HierarchicIteratorImp;
657 
658  template< PartitionIteratorType pitype >
659  struct Partition
660  {
662  LevelGridView;
664  LeafGridView;
665  };
666 
667  typedef typename Partition< All_Partition > :: LevelGridView LevelGridView;
668  typedef typename Partition< All_Partition > :: LeafGridView LeafGridView;
669 
670  template< PartitionIteratorType pitype >
671  typename Partition< pitype >::LevelGridView levelView ( int level ) const
672  {
673  typedef typename Partition< pitype >::LevelGridView LevelGridView;
674  typedef typename LevelGridView::GridViewImp LevelGridViewImp;
675  return LevelGridView( LevelGridViewImp( *this, level ) );
676  }
677 
678  template< PartitionIteratorType pitype >
679  typename Partition< pitype >::LeafGridView leafView () const
680  {
681  typedef typename Partition< pitype >::LeafGridView LeafGridView;
682  typedef typename LeafGridView::GridViewImp LeafGridViewImp;
683  return LeafGridView( LeafGridViewImp( *this ) );
684  }
685 
686  LevelGridView levelView ( int level ) const
687  {
688  typedef typename LevelGridView::GridViewImp LevelGridViewImp;
689  return LevelGridView( LevelGridViewImp( *this, level ) );
690  }
691 
692  LeafGridView leafView () const
693  {
694  typedef typename LeafGridView::GridViewImp LeafGridViewImp;
695  return LeafGridView( LeafGridViewImp( *this ) );
696  }
697 
698 private:
699  static std::string nameSuffix()
700  {
701  std::string elt ( elType == cube ? "cube," : "simplex," );
702  std::string ref ( refinementType == nonconforming ? "nonconforming>" : "conforming>" );
703  std::stringstream suffix;
704  suffix << "<"<<dim<<","<<dimworld<<"," << elt << ref;
705  return suffix.str();
706  }
707 
708  // returns number of hanging nodes allowed (0 or 1)
709  int hangingNodes() const
710  {
711  return ((elType == simplex) && (refinementType == conforming)) ? 0 : 1;
712  }
713 
714  friend class Conversion< This, HasObjectStream > ;
715  friend class Conversion< const This, HasObjectStream > ;
716 
717  friend class Conversion< This, HasHierarchicIndexSet > ;
718  friend class Conversion< const This, HasHierarchicIndexSet > ;
719 
720  template< class >
721  friend class ALU2dGridFactory;
722 
724  ALUGrid( const ALUGrid & g ) ; // : BaseType(g) {}
725 
727  This& operator = (const ALUGrid& g);
728 };
729 
730 } //end namespace Dune
731 
732 #else
733 #error "Trying to use <dune/grid/alugrid.hh> without ALUGRID_CPPFLAGS."
734 #endif // #if HAVE_ALUGRID
735 
736 #endif