dune-grid  2.2.0
alu2dinclude.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU2DGRID_INCLUDE_HH
2 #define DUNE_ALU2DGRID_INCLUDE_HH
3 
4 #define ALU2DGRID_COMPATIBILITY_LEVEL 2
5 
6 #include <alugrid_2d.h>
7 
9 // compile imp.cc into lib (1 yes, 0 no)
10 // if you change this, you'll get what you deserve
12 #define COMPILE_ALU2DGRID_LIB 0
13 
14 #if COMPILE_ALU2DGRID_LIB
15  #define COMPILE_ALU2DGRID_INLINE 0
16 #else
17  #define COMPILE_ALU2DGRID_INLINE 1
18 #endif
19 
20 #if COMPILE_ALU2DGRID_INLINE
21 #define alu2d_inline inline
22 #else
23 #define alu2d_inline
24 #endif
25 
26 
27 // fix for ALUGrid 1.22, where ALUGRID_VERTEX_PROJECTION is defined only in alugrid_serial.h
28 #ifndef ALUGRID_VERTEX_PROJECTION
29 #include <alugrid_serial.h>
30 #endif
31 
32 #define ALU2DSPACE ALU2DSPACENAME ::
33 
34 #define ALU2DSPACENAME ALU2DGrid
35 #define ALU2DDIMWORLD(dimw,eltype) < dimw,(eltype == ALU2DSPACE triangle ? 3 : 4) >
36 
37 // use the ALU3dGrid Parallel detection
39 //#define ALU2DGRID_PARALLEL ALU3DGRID_PARALLEL
40 #define ALU2DGRID_PARALLEL 0
41 
42 #include <dune/common/collectivecommunication.hh>
43 
44 #if ALU2DGRID_PARALLEL
45 //#include "communicator.hh"
46 #warning "Using ALU2dGrid in parallel"
47 #endif
48 
49 
50 namespace ALU2DSPACENAME
51 {
52 
54 
55 }
56 
57 
58 namespace Dune
59 {
60 
61  typedef double alu2d_ctype;
62 
63 
64 #ifndef DOXYGEN
65  // ALU2dImplInterface
66  // ------------------
67 
68  template< int dim, int dimw, ALU2DSPACE ElementType eltype >
69  struct ALU2dImplInterface;
70 
71  template< int dimw, ALU2DSPACE ElementType eltype >
72  struct ALU2dImplInterface< 0, dimw, eltype >
73  {
74  typedef typename ALU2DSPACE Hmesh_basic ALU2DDIMWORLD(dimw,eltype) ::vertex_t Type;
75  };
76 
77  template< int dimw, ALU2DSPACE ElementType eltype >
78  struct ALU2dImplInterface< 1, dimw, eltype >
79  {
80  typedef typename ALU2DSPACE Hmesh_basic ALU2DDIMWORLD(dimw,eltype) ::helement_t Type;
81  };
82 
83  template< int dimw, ALU2DSPACE ElementType eltype >
84  struct ALU2dImplInterface< 2, dimw, eltype >
85  {
86  typedef typename ALU2DSPACE Hmesh_basic ALU2DDIMWORLD(dimw,eltype) ::helement_t Type;
87  };
88 #endif
89 
90 
91  // ALU2dImplTraits
92  // ---------------
93 
94  template< int dimw, ALU2DSPACE ElementType eltype >
96  {
97  template< int cdim >
98  struct Codim
99  {
100  typedef typename ALU2dImplInterface< 2-cdim, dimw, eltype >::Type InterfaceType;
101  };
102 
103  typedef ALU2DSPACE Hmesh ALU2DDIMWORLD(dimw,eltype) HmeshType;
104  typedef ALU2DSPACE Thinelement ALU2DDIMWORLD(dimw,eltype) ThinelementType;
106  typedef typename HmeshType::helement_t HElementType;
107  typedef typename HmeshType::hbndel_t HBndElType;
108  typedef ALU2DSPACE Bndel_periodic ALU2DDIMWORLD(dimw,eltype) PeriodicBndElType;
109  };
110 
111 
112 
113  // ALU2dGridMarkerVector
114  // ---------------------
115 
117  {
118  typedef std::vector< int > VectorType;
119  public:
120  ALU2dGridMarkerVector() : valid_(false) {}
121 
122  bool valid() const { return valid_; }
123 
124  void invalidate() { valid_ = false; }
125 
126  bool isOnElement(int elementIndex, int idx, int codim) const
127  {
128  return marker_[codim-1][idx] == elementIndex;
129  }
130 
131  template <class GridType>
132  void update (const GridType & grid, int level )
133  {
134  enum { dim = GridType::dimension };
135  static const int dimworld = GridType::dimensionworld;
136  static const ALU2DSPACE ElementType eltype = GridType::elementType;
137 
140  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
141 
142  // resize
143  for(int i=0; i<2; ++i)
144  {
145  int s = grid.hierSetSize(i+1);
146  if((int) marker_[i].size() < s ) marker_[i].resize(s);
147 
148  size_t markerSize = marker_[i].size();
149  // reset marker vector to default value
150  for(size_t k=0; k<markerSize; ++k) marker_[i][k] = -1;
151  }
152 
153  IteratorType iter(grid.myGrid(), level);
154 
155  for(iter->first(); !iter->done(); iter->next())
156  {
157  ElementType & elem = iter->getitem();
158  int elIdx = elem.getIndex();
159 
160  // if element is not valid, go to next
161 #if ALU2DGRID_PARALLEL
162  if( ! grid.rankManager().isValid( elIdx , All_Partition ) ) continue;
163 #endif
164  for(int i=0; i<elem.numvertices(); ++i)
165  {
166  enum { vxCodim = 1 };
167  int vxIdx = elem.getVertex(i)->getIndex();
168  if( marker_[vxCodim][vxIdx] < 0) marker_[vxCodim][vxIdx] = elIdx;
169 
170  enum { edgeCodim = 0 };
171  int edgeIdx = elem.edge_idx(i);
172  if( marker_[edgeCodim][edgeIdx] < 0) marker_[edgeCodim][edgeIdx] = elIdx;
173  }
174  }
175  valid_ = true;
176  }
177 
178  private:
179  VectorType marker_[2];
180 
181  bool valid_;
182  };
183 
185  {
186  typedef std::vector< int > VectorType;
187  public:
188  ALU2dGridLeafMarkerVector() : valid_(false) {}
189 
190  bool valid() const { return valid_; }
191 
192  void invalidate() { valid_ = false; }
193 
194  // return true, if edge is visited on given element
195  bool isOnElement(int elementIndex, int idx, int codim) const
196  {
197  assert( valid_ );
198  // this marker only works for codim 1, i.e. edges
199  assert( codim == 1 );
200  return marker_[idx] == elementIndex;
201  }
202 
203  // this is for the LeafIterator
204  template <class GridType>
205  void update (const GridType & grid)
206  {
207  static const int dimworld = GridType::dimensionworld;
208  static const ALU2DSPACE ElementType eltype = GridType::elementType;
209 
212  typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
213 
214  // resize edge marker
215  {
216  int s = grid.hierSetSize(1);
217  if((int) marker_.size() < s ) marker_.resize(s);
218 
219  size_t markerSize = marker_.size();
220  // reset marker vector to default value
221  for(size_t k=0; k<markerSize; ++k) marker_[k] = -1;
222  }
223 
224  // resize vertex levels
225  {
226  int s = grid.hierSetSize(2);
227  if((int) vertexLevels_.size() < s ) vertexLevels_.resize(s);
228 
229  // initialize with -1
230  size_t vxSize = vertexLevels_.size();
231  for(size_t k=0; k<vxSize; ++k) vertexLevels_[k] = -1;
232  }
233 
234  enum { dim = GridType::dimension };
235  IteratorType iter(grid.myGrid());
236 
237  for(iter->first(); !iter->done(); iter->next())
238  {
239  ElementType & elem = iter->getitem();
240  int elIdx = elem.getIndex();
241 
242 #if ALU2DGRID_PARALLEL
243  // is element is not valid, go to next
244  if( ! grid.rankManager().isValid( elIdx , All_Partition ) ) continue;
245 #endif
246  int level = elem.level();
247 
248  for(int i=0; i<elem.numvertices(); ++i)
249  {
250  int vxIdx = elem.getVertex(i)->getIndex();
251 
252  // set max level to vertices, see Grid docu paper
253  if(level > vertexLevels_[vxIdx]) vertexLevels_[vxIdx] = level;
254 
255  int edgeIdx = elem.edge_idx(i);
256  if( marker_[edgeIdx] < 0) marker_[edgeIdx] = elIdx;
257  }
258  }
259  valid_ = true;
260  }
261 
263  int levelOfVertex(const int vxIdx) const
264  {
265  assert( valid_ );
266  assert( vxIdx >= 0 && vxIdx < (int) vertexLevels_.size());
267  // if this assertion is thrown, the level has not been initialized
268  assert( vertexLevels_[vxIdx] >= 0 );
269  return vertexLevels_[vxIdx];
270  }
271 
273  bool isValidVertex(const int vxIdx) const
274  {
275  assert( valid_ );
276  assert( vxIdx >= 0 && vxIdx < (int) vertexLevels_.size());
277  return (vertexLevels_[vxIdx] >= 0);
278  }
279 
280  private:
281  VectorType marker_;
282  VectorType vertexLevels_;
283 
284  bool valid_;
285  };
286 
287  // dummy object stream class
289  {
290  public:
291  class EOFException {} ;
292  template <class T>
293  void readObject (T &) {}
294  void readObject (int) {}
295  void readObject (double) {}
296  template <class T>
297  void writeObject (T &) {}
298  void writeObject (int) {}
299  void writeObject (double) {}
300 
301  template <class T>
302  void read (T &) const {}
303  template <class T>
304  void write (const T &) {}
305  };
306 
307 } //end namespace Dune
308 #endif