dune-grid
2.2.0
|
00001 #ifndef DUNE_ALU2DGRID_INCLUDE_HH 00002 #define DUNE_ALU2DGRID_INCLUDE_HH 00003 00004 #define ALU2DGRID_COMPATIBILITY_LEVEL 2 00005 00006 #include <alugrid_2d.h> 00007 00009 // compile imp.cc into lib (1 yes, 0 no) 00010 // if you change this, you'll get what you deserve 00012 #define COMPILE_ALU2DGRID_LIB 0 00013 00014 #if COMPILE_ALU2DGRID_LIB 00015 #define COMPILE_ALU2DGRID_INLINE 0 00016 #else 00017 #define COMPILE_ALU2DGRID_INLINE 1 00018 #endif 00019 00020 #if COMPILE_ALU2DGRID_INLINE 00021 #define alu2d_inline inline 00022 #else 00023 #define alu2d_inline 00024 #endif 00025 00026 00027 // fix for ALUGrid 1.22, where ALUGRID_VERTEX_PROJECTION is defined only in alugrid_serial.h 00028 #ifndef ALUGRID_VERTEX_PROJECTION 00029 #include <alugrid_serial.h> 00030 #endif 00031 00032 #define ALU2DSPACE ALU2DSPACENAME :: 00033 00034 #define ALU2DSPACENAME ALU2DGrid 00035 #define ALU2DDIMWORLD(dimw,eltype) < dimw,(eltype == ALU2DSPACE triangle ? 3 : 4) > 00036 00037 // use the ALU3dGrid Parallel detection 00038 #include <dune/grid/alugrid/common/checkparallel.hh> 00039 //#define ALU2DGRID_PARALLEL ALU3DGRID_PARALLEL 00040 #define ALU2DGRID_PARALLEL 0 00041 00042 #include <dune/common/collectivecommunication.hh> 00043 00044 #if ALU2DGRID_PARALLEL 00045 //#include "communicator.hh" 00046 #warning "Using ALU2dGrid in parallel" 00047 #endif 00048 00049 00050 namespace ALU2DSPACENAME 00051 { 00052 00053 enum ElementType { triangle, quadrilateral, mixed }; 00054 00055 } 00056 00057 00058 namespace Dune 00059 { 00060 00061 typedef double alu2d_ctype; 00062 00063 00064 #ifndef DOXYGEN 00065 // ALU2dImplInterface 00066 // ------------------ 00067 00068 template< int dim, int dimw, ALU2DSPACE ElementType eltype > 00069 struct ALU2dImplInterface; 00070 00071 template< int dimw, ALU2DSPACE ElementType eltype > 00072 struct ALU2dImplInterface< 0, dimw, eltype > 00073 { 00074 typedef typename ALU2DSPACE Hmesh_basic ALU2DDIMWORLD(dimw,eltype) ::vertex_t Type; 00075 }; 00076 00077 template< int dimw, ALU2DSPACE ElementType eltype > 00078 struct ALU2dImplInterface< 1, dimw, eltype > 00079 { 00080 typedef typename ALU2DSPACE Hmesh_basic ALU2DDIMWORLD(dimw,eltype) ::helement_t Type; 00081 }; 00082 00083 template< int dimw, ALU2DSPACE ElementType eltype > 00084 struct ALU2dImplInterface< 2, dimw, eltype > 00085 { 00086 typedef typename ALU2DSPACE Hmesh_basic ALU2DDIMWORLD(dimw,eltype) ::helement_t Type; 00087 }; 00088 #endif 00089 00090 00091 // ALU2dImplTraits 00092 // --------------- 00093 00094 template< int dimw, ALU2DSPACE ElementType eltype > 00095 struct ALU2dImplTraits 00096 { 00097 template< int cdim > 00098 struct Codim 00099 { 00100 typedef typename ALU2dImplInterface< 2-cdim, dimw, eltype >::Type InterfaceType; 00101 }; 00102 00103 typedef ALU2DSPACE Hmesh ALU2DDIMWORLD(dimw,eltype) HmeshType; 00104 typedef ALU2DSPACE Thinelement ALU2DDIMWORLD(dimw,eltype) ThinelementType; 00105 typedef ALU2DSPACE Element ALU2DDIMWORLD(dimw,eltype) ElementType; 00106 typedef typename HmeshType::helement_t HElementType; 00107 typedef typename HmeshType::hbndel_t HBndElType; 00108 typedef ALU2DSPACE Bndel_periodic ALU2DDIMWORLD(dimw,eltype) PeriodicBndElType; 00109 }; 00110 00111 00112 00113 // ALU2dGridMarkerVector 00114 // --------------------- 00115 00116 class ALU2dGridMarkerVector 00117 { 00118 typedef std::vector< int > VectorType; 00119 public: 00120 ALU2dGridMarkerVector() : valid_(false) {} 00121 00122 bool valid() const { return valid_; } 00123 00124 void invalidate() { valid_ = false; } 00125 00126 bool isOnElement(int elementIndex, int idx, int codim) const 00127 { 00128 return marker_[codim-1][idx] == elementIndex; 00129 } 00130 00131 template <class GridType> 00132 void update (const GridType & grid, int level ) 00133 { 00134 enum { dim = GridType::dimension }; 00135 static const int dimworld = GridType::dimensionworld; 00136 static const ALU2DSPACE ElementType eltype = GridType::elementType; 00137 00138 typedef typename ALU2dImplTraits< dimworld, eltype >::template Codim<0>::InterfaceType ElementType; 00139 typedef typename ALU2dImplTraits< dimworld, eltype >::template Codim<2>::InterfaceType VertexType; 00140 typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType; 00141 00142 // resize 00143 for(int i=0; i<2; ++i) 00144 { 00145 int s = grid.hierSetSize(i+1); 00146 if((int) marker_[i].size() < s ) marker_[i].resize(s); 00147 00148 size_t markerSize = marker_[i].size(); 00149 // reset marker vector to default value 00150 for(size_t k=0; k<markerSize; ++k) marker_[i][k] = -1; 00151 } 00152 00153 IteratorType iter(grid.myGrid(), level); 00154 00155 for(iter->first(); !iter->done(); iter->next()) 00156 { 00157 ElementType & elem = iter->getitem(); 00158 int elIdx = elem.getIndex(); 00159 00160 // if element is not valid, go to next 00161 #if ALU2DGRID_PARALLEL 00162 if( ! grid.rankManager().isValid( elIdx , All_Partition ) ) continue; 00163 #endif 00164 for(int i=0; i<elem.numvertices(); ++i) 00165 { 00166 enum { vxCodim = 1 }; 00167 int vxIdx = elem.getVertex(i)->getIndex(); 00168 if( marker_[vxCodim][vxIdx] < 0) marker_[vxCodim][vxIdx] = elIdx; 00169 00170 enum { edgeCodim = 0 }; 00171 int edgeIdx = elem.edge_idx(i); 00172 if( marker_[edgeCodim][edgeIdx] < 0) marker_[edgeCodim][edgeIdx] = elIdx; 00173 } 00174 } 00175 valid_ = true; 00176 } 00177 00178 private: 00179 VectorType marker_[2]; 00180 00181 bool valid_; 00182 }; 00183 00184 class ALU2dGridLeafMarkerVector 00185 { 00186 typedef std::vector< int > VectorType; 00187 public: 00188 ALU2dGridLeafMarkerVector() : valid_(false) {} 00189 00190 bool valid() const { return valid_; } 00191 00192 void invalidate() { valid_ = false; } 00193 00194 // return true, if edge is visited on given element 00195 bool isOnElement(int elementIndex, int idx, int codim) const 00196 { 00197 assert( valid_ ); 00198 // this marker only works for codim 1, i.e. edges 00199 assert( codim == 1 ); 00200 return marker_[idx] == elementIndex; 00201 } 00202 00203 // this is for the LeafIterator 00204 template <class GridType> 00205 void update (const GridType & grid) 00206 { 00207 static const int dimworld = GridType::dimensionworld; 00208 static const ALU2DSPACE ElementType eltype = GridType::elementType; 00209 00210 typedef typename ALU2dImplTraits< dimworld, eltype >::template Codim<0>::InterfaceType ElementType; 00211 typedef typename ALU2dImplTraits< dimworld, eltype >::template Codim<2>::InterfaceType VertexType; 00212 typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType; 00213 00214 // resize edge marker 00215 { 00216 int s = grid.hierSetSize(1); 00217 if((int) marker_.size() < s ) marker_.resize(s); 00218 00219 size_t markerSize = marker_.size(); 00220 // reset marker vector to default value 00221 for(size_t k=0; k<markerSize; ++k) marker_[k] = -1; 00222 } 00223 00224 // resize vertex levels 00225 { 00226 int s = grid.hierSetSize(2); 00227 if((int) vertexLevels_.size() < s ) vertexLevels_.resize(s); 00228 00229 // initialize with -1 00230 size_t vxSize = vertexLevels_.size(); 00231 for(size_t k=0; k<vxSize; ++k) vertexLevels_[k] = -1; 00232 } 00233 00234 enum { dim = GridType::dimension }; 00235 IteratorType iter(grid.myGrid()); 00236 00237 for(iter->first(); !iter->done(); iter->next()) 00238 { 00239 ElementType & elem = iter->getitem(); 00240 int elIdx = elem.getIndex(); 00241 00242 #if ALU2DGRID_PARALLEL 00243 // is element is not valid, go to next 00244 if( ! grid.rankManager().isValid( elIdx , All_Partition ) ) continue; 00245 #endif 00246 int level = elem.level(); 00247 00248 for(int i=0; i<elem.numvertices(); ++i) 00249 { 00250 int vxIdx = elem.getVertex(i)->getIndex(); 00251 00252 // set max level to vertices, see Grid docu paper 00253 if(level > vertexLevels_[vxIdx]) vertexLevels_[vxIdx] = level; 00254 00255 int edgeIdx = elem.edge_idx(i); 00256 if( marker_[edgeIdx] < 0) marker_[edgeIdx] = elIdx; 00257 } 00258 } 00259 valid_ = true; 00260 } 00261 00263 int levelOfVertex(const int vxIdx) const 00264 { 00265 assert( valid_ ); 00266 assert( vxIdx >= 0 && vxIdx < (int) vertexLevels_.size()); 00267 // if this assertion is thrown, the level has not been initialized 00268 assert( vertexLevels_[vxIdx] >= 0 ); 00269 return vertexLevels_[vxIdx]; 00270 } 00271 00273 bool isValidVertex(const int vxIdx) const 00274 { 00275 assert( valid_ ); 00276 assert( vxIdx >= 0 && vxIdx < (int) vertexLevels_.size()); 00277 return (vertexLevels_[vxIdx] >= 0); 00278 } 00279 00280 private: 00281 VectorType marker_; 00282 VectorType vertexLevels_; 00283 00284 bool valid_; 00285 }; 00286 00287 // dummy object stream class 00288 class ALU2dGridObjectStream 00289 { 00290 public: 00291 class EOFException {} ; 00292 template <class T> 00293 void readObject (T &) {} 00294 void readObject (int) {} 00295 void readObject (double) {} 00296 template <class T> 00297 void writeObject (T &) {} 00298 void writeObject (int) {} 00299 void writeObject (double) {} 00300 00301 template <class T> 00302 void read (T &) const {} 00303 template <class T> 00304 void write (const T &) {} 00305 }; 00306 00307 } //end namespace Dune 00308 #endif