1 #ifndef DUNE_ALU3DGRID_ALUGRID_HH 2 #define DUNE_ALU3DGRID_ALUGRID_HH 3 4 #include <type_traits> 5 6 // 3d version 7 #include <dune/alugrid/common/capabilities.hh> 8 #include <dune/alugrid/3d/indexsets.hh> 9 #include <dune/alugrid/3d/iterator.hh> 10 #include <dune/alugrid/3d/entity.hh> 11 #include <dune/alugrid/3d/geometry.hh> 12 #include <dune/alugrid/3d/grid.hh> 13 14 /** @file 15 @author Robert Kloefkorn 16 @brief Provides base classes for ALUGrid 17 **/ 18 19 namespace Dune 20 { 21 22 template <class Comm> ALUGridParallelSerial()23 static const char* ALUGridParallelSerial() 24 { 25 return ( std::is_same< Comm, ALUGridNoComm >::value ) ? "serial" : "parallel"; 26 } 27 28 template< int dim, int dimworld, ALUGridElementType elType, ALUGridRefinementType refineType, class Comm > 29 class ALUGrid 30 : public ALUGridBaseGrid< dim, dimworld, elType, Comm > :: BaseGrid 31 { 32 // the cube version of ALUGrid only works with nonconforming refinement 33 static_assert( elType == cube ? refineType == nonconforming : true, "cube only works with nonconforming refinement"); 34 35 typedef ALUGrid< dim, dimworld, elType, refineType, Comm > This; 36 typedef typename ALUGridBaseGrid< dim, dimworld, elType, Comm > :: BaseGrid BaseType; 37 38 public: 39 typedef typename BaseType::MPICommunicatorType MPICommunicatorType; 40 41 //! type of boundary projection 42 typedef typename BaseType :: ALUGridVertexProjectionPairType ALUGridVertexProjectionPairType; 43 44 enum { dimension=BaseType::dimension, dimensionworld=BaseType::dimensionworld}; 45 static const ALUGridRefinementType refinementType = refineType; 46 typedef typename BaseType::ctype ctype; 47 typedef typename BaseType::GridFamily GridFamily; 48 typedef typename GridFamily::Traits Traits; 49 typedef typename BaseType::LocalIdSetImp LocalIdSetImp; 50 typedef typename Traits :: GlobalIdSet GlobalIdSet; 51 typedef typename Traits :: LocalIdSet LocalIdSet; 52 typedef typename GridFamily :: LevelIndexSetImp LevelIndexSetImp; 53 typedef typename GridFamily :: LeafIndexSetImp LeafIndexSetImp; 54 typedef typename BaseType::LeafIteratorImp LeafIteratorImp; 55 typedef typename Traits:: template Codim<0>::LeafIterator LeafIteratorType; 56 typedef typename Traits:: template Codim<0>::LeafIterator LeafIterator; 57 58 //! \brief constructor for creating ALUGrid from given macro grid file 59 //! \param macroName filename for macro grid in ALUGrid tetra format 60 //! \param mpiComm MPI Communicator (when HAVE_MPI == 1 then mpiComm is of 61 //! type MPI_Comm and the default value is MPI_COMM_WORLD) 62 //! \param bndProject global boundary projection pointer 63 //! \param bndVector pointer to vector holding boundary projection for 64 //! each boundary segment. ALUGrid takes ownership of 65 //! this pointer and will delete it in the desctructor 66 //! \param verb Whether to write a notice about grid creation to 67 //! stdout. ALUGrid(const std::string macroName,const MPICommunicatorType mpiComm=BaseType::defaultCommunicator (),const ALUGridVertexProjectionPairType & bndPrj=ALUGridVertexProjectionPairType (),const bool verb=true)68 ALUGrid(const std::string macroName, 69 const MPICommunicatorType mpiComm = BaseType::defaultCommunicator(), 70 const ALUGridVertexProjectionPairType& bndPrj = ALUGridVertexProjectionPairType(), 71 const bool verb = true ) : 72 BaseType(macroName, mpiComm, bndPrj, refineType ) 73 { 74 const bool verbose = verb && this->comm().rank() == 0; 75 if( verbose ) 76 { 77 std::cout << "\nCreated " << ALUGridParallelSerial< Comm >() << " " << name() << nameSuffix() 78 << " from macro grid file '" << macroName << "'. \n\n"; 79 } 80 } 81 name()82 static std::string name () { return std::string("ALUGrid"); } 83 nameSuffix()84 static std::string nameSuffix() 85 { 86 std::string elt ( elType == cube ? "cube," : "simplex," ); 87 std::string ref ( refineType == nonconforming ? "nonconforming>" : "conforming>" ); 88 std::stringstream suffix; 89 suffix << "<"<< dimension <<","<< dimensionworld <<"," << elt << ref; 90 return suffix.str(); 91 } 92 93 94 //! \brief constructor called from ALUGridFactory 95 //! for creating ALUConformGrid from given macro grid file 96 //! \param mpiComm MPI Communicator (when HAVE_MPI == 1 then mpiComm is of type MPI_Comm) 97 //! \param bndProject global boundary projection pointer 98 //! \param bndVector pointer to vector holding boundary projection for each boundary segment 99 //! \note ALUGrid takes ownership of this pointer and will delete it in the desctructor 100 //! \param macroName filename from which ALUGrid is being generated 101 //! \param verb Whether to write a notice about grid creation to 102 //! stdout. ALUGrid(const MPICommunicatorType mpiComm,const ALUGridVertexProjectionPairType & bndPrj,const std::string macroName,const bool verb=true)103 ALUGrid(const MPICommunicatorType mpiComm, 104 const ALUGridVertexProjectionPairType& bndPrj, 105 const std::string macroName, 106 const bool verb = true ) : 107 BaseType("", mpiComm, bndPrj, refineType ) 108 { 109 const bool verbose = verb && this->comm().rank() == 0; 110 if( verbose ) 111 { 112 std::cout << "\nCreated " << ALUGridParallelSerial< Comm >() << " " << name() << nameSuffix(); 113 if( macroName.empty() ) 114 std::cout << " from input stream. \n"; 115 else 116 std::cout << " from macro grid file '" << macroName << "'. \n"; 117 std::cout << std::endl; 118 } 119 } 120 121 //! constructor creating empty grid, empty string creates empty grid ALUGrid(const MPICommunicatorType mpiComm=BaseType::defaultCommunicator ())122 ALUGrid(const MPICommunicatorType mpiComm = BaseType::defaultCommunicator()) : 123 BaseType("", mpiComm, ALUGridVertexProjectionPairType(), refineType ) 124 { 125 if(this->comm().rank() == 0) 126 { 127 std::cout << "\nCreated empty " << ALUGridParallelSerial< Comm >() << " " << name() << nameSuffix() << "." << std::endl << std::endl; 128 } 129 } 130 131 // ALUGrid only typedefs 132 typedef typename BaseType::HierarchicIteratorImp HierarchicIteratorImp; 133 typedef typename BaseType::ObjectStreamType ObjectStreamType; 134 135 template< PartitionIteratorType pitype > 136 struct Partition 137 { 138 typedef Dune::GridView< ALU3dLevelGridViewTraits< const This, pitype > > LevelGridView; 139 typedef Dune::GridView< ALU3dLeafGridViewTraits< const This, pitype > > LeafGridView; 140 }; 141 142 typedef typename Partition< All_Partition > :: LevelGridView LevelGridView; 143 typedef typename Partition< All_Partition > :: LeafGridView LeafGridView; 144 145 // old grid view methods 146 template< PartitionIteratorType pitype > levelView(int level) const147 typename Partition< pitype >::LevelGridView levelView ( int level ) const { return levelGridView< pitype >( level ); } 148 149 template< PartitionIteratorType pitype > leafView() const150 typename Partition< pitype >::LeafGridView leafView () const { return leafGridView< pitype >(); } 151 levelView(int level) const152 LevelGridView levelView ( int level ) const { return levelGridView( level ); } 153 leafView() const154 LeafGridView leafView () const { return leafGridView(); } 155 156 // new grid view methods 157 template< PartitionIteratorType pitype > levelGridView(int level) const158 typename Partition< pitype >::LevelGridView levelGridView ( int level ) const 159 { 160 typedef typename Partition< pitype >::LevelGridView LevelGridView; 161 typedef typename LevelGridView::GridViewImp LevelGridViewImp; 162 return LevelGridView( LevelGridViewImp( *this, level ) ); 163 } 164 165 template< PartitionIteratorType pitype > leafGridView() const166 typename Partition< pitype >::LeafGridView leafGridView () const 167 { 168 typedef typename Partition< pitype >::LeafGridView LeafGridView; 169 typedef typename LeafGridView::GridViewImp LeafGridViewImp; 170 return LeafGridView( LeafGridViewImp( *this ) ); 171 } 172 levelGridView(int level) const173 LevelGridView levelGridView ( int level ) const 174 { 175 typedef typename LevelGridView::GridViewImp LevelGridViewImp; 176 return LevelGridView( LevelGridViewImp( *this, level ) ); 177 } 178 leafGridView() const179 LeafGridView leafGridView () const 180 { 181 typedef typename LeafGridView::GridViewImp LeafGridViewImp; 182 return LeafGridView( LeafGridViewImp( *this ) ); 183 } 184 185 private: 186 template< class > friend class ALU3dGridFactory; 187 188 //! Copy constructor should not be used 189 ALUGrid( const ALUGrid & g ); // : BaseType(g) {} 190 191 //! assignment operator should not be used 192 This& operator = (const ALUGrid& g); 193 }; 194 195 } //end namespace Dune 196 197 //#undef alu_inline 198 #endif // #ifndef DUNE_ALU3DGRID_ALUGRID_HH 199