Dune Core Modules (2.4.1)

alu2dinclude.hh
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_ALU2DGRID_INCLUDE_HH
4#define DUNE_ALU2DGRID_INCLUDE_HH
5
6#define ALU2DGRID_COMPATIBILITY_LEVEL 2
7
8#include <alugrid_2d.h>
9
11// compile imp.cc into lib (1 yes, 0 no)
12// if you change this, you'll get what you deserve
14#define COMPILE_ALU2DGRID_LIB 0
15
16#if COMPILE_ALU2DGRID_LIB
17 #define COMPILE_ALU2DGRID_INLINE 0
18#else
19 #define COMPILE_ALU2DGRID_INLINE 1
20#endif
21
22#if COMPILE_ALU2DGRID_INLINE
23#define alu2d_inline inline
24#else
25#define alu2d_inline
26#endif
28
29// fix for ALUGrid 1.22, where ALUGRID_VERTEX_PROJECTION is defined only in alugrid_serial.h
30#ifndef ALUGRID_VERTEX_PROJECTION
31#include <alugrid_serial.h>
32#endif
33
34#define ALU2DSPACE ALU2DSPACENAME ::
35
36#define ALU2DSPACENAME ALU2DGrid
37#define ALU2DDIMWORLD(dimw,eltype) < dimw,(eltype == ALU2DSPACE triangle ? 3 : 4) >
38
39// use the ALU3dGrid Parallel detection
40#include <dune/grid/alugrid/common/checkparallel.hh>
41//#define ALU2DGRID_PARALLEL ALU3DGRID_PARALLEL
42#define ALU2DGRID_PARALLEL 0
43
45
46#if ALU2DGRID_PARALLEL
47//#include "communicator.hh"
48#warning "Using ALU2dGrid in parallel"
49#endif
50
51
52namespace ALU2DSPACENAME
53{
54
55 enum ElementType { triangle, quadrilateral, mixed };
56
57}
58
59
60namespace Dune
61{
62
63 typedef double alu2d_ctype;
64
65
66#ifndef DOXYGEN
67 // ALU2dImplInterface
68 // ------------------
69
70 template< int dim, int dimw, ALU2DSPACE ElementType eltype >
71 struct ALU2dImplInterface;
72
73 template< int dimw, ALU2DSPACE ElementType eltype >
74 struct ALU2dImplInterface< 0, dimw, eltype >
75 {
76 typedef typename ALU2DSPACE Hmesh_basic ALU2DDIMWORLD (dimw,eltype) ::vertex_t Type;
77 };
78
79 template< int dimw, ALU2DSPACE ElementType eltype >
80 struct ALU2dImplInterface< 1, dimw, eltype >
81 {
82 typedef typename ALU2DSPACE Hmesh_basic ALU2DDIMWORLD (dimw,eltype) ::helement_t Type;
83 };
84
85 template< int dimw, ALU2DSPACE ElementType eltype >
86 struct ALU2dImplInterface< 2, dimw, eltype >
87 {
88 typedef typename ALU2DSPACE Hmesh_basic ALU2DDIMWORLD (dimw,eltype) ::helement_t Type;
89 };
90#endif
91
92
93 // ALU2dImplTraits
94 // ---------------
95
96 template< int dimw, ALU2DSPACE ElementType eltype >
97 struct ALU2dImplTraits
98 {
99 template< int cdim >
100 struct Codim
101 {
102 typedef typename ALU2dImplInterface< 2-cdim, dimw, eltype >::Type InterfaceType;
103 };
104
105 typedef ALU2DSPACE Hmesh ALU2DDIMWORLD (dimw,eltype) HmeshType;
106 typedef ALU2DSPACE Thinelement ALU2DDIMWORLD (dimw,eltype) ThinelementType;
107 typedef ALU2DSPACE Element ALU2DDIMWORLD (dimw,eltype) ElementType;
108 typedef typename HmeshType::helement_t HElementType;
109 typedef typename HmeshType::hbndel_t HBndElType;
110 typedef ALU2DSPACE Bndel_periodic ALU2DDIMWORLD (dimw,eltype) PeriodicBndElType;
111 };
112
113
114
115 // ALU2dGridMarkerVector
116 // ---------------------
117
118 class ALU2dGridMarkerVector
119 {
120 typedef std::vector< int > VectorType;
121 public:
122 ALU2dGridMarkerVector() : valid_(false) {}
123
124 bool valid() const { return valid_; }
125
126 void invalidate() { valid_ = false; }
127
128 bool isOnElement(int elementIndex, int idx, int codim) const
129 {
130 return marker_[codim-1][idx] == elementIndex;
131 }
132
133 template <class GridType>
134 void update (const GridType & grid, int level )
135 {
136 enum { dim = GridType::dimension };
137 static const int dimworld = GridType::dimensionworld;
138 static const ALU2DSPACE ElementType eltype = GridType::elementType;
139
140 typedef typename ALU2dImplTraits< dimworld, eltype >::template Codim<0>::InterfaceType ElementType;
141 typedef ALU2DSPACE Listwalkptr< ElementType > IteratorType;
142
143 // resize
144 for(int i=0; i<2; ++i)
145 {
146 int s = grid.hierSetSize(i+1);
147 if((int) marker_[i].size() < s ) marker_[i].resize(s);
148
149 size_t markerSize = marker_[i].size();
150 // reset marker vector to default value
151 for(size_t k=0; k<markerSize; ++k) marker_[i][k] = -1;
152 }
153
154 IteratorType iter(grid.myGrid(), level);
155
156 for(iter->first(); !iter->done(); iter->next())
157 {
158 ElementType & elem = iter->getitem();
159 int elIdx = elem.getIndex();
160
161 // if element is not valid, go to next
162#if ALU2DGRID_PARALLEL
163 if( ! grid.rankManager().isValid( elIdx , All_Partition ) ) continue;
164#endif
165 for(int i=0; i<elem.numvertices(); ++i)
166 {
167 enum { vxCodim = 1 };
168 int vxIdx = elem.getVertex(i)->getIndex();
169 if( marker_[vxCodim][vxIdx] < 0) marker_[vxCodim][vxIdx] = elIdx;
170
171 enum { edgeCodim = 0 };
172 int edgeIdx = elem.edge_idx(i);
173 if( marker_[edgeCodim][edgeIdx] < 0) marker_[edgeCodim][edgeIdx] = elIdx;
174 }
175 }
176 valid_ = true;
177 }
178
179 private:
180 VectorType marker_[2];
181
182 bool valid_;
183 };
184
185 class ALU2dGridLeafMarkerVector
186 {
187 typedef std::vector< int > VectorType;
188 public:
189 ALU2dGridLeafMarkerVector() : valid_(false) {}
190
191 bool valid() const { return valid_; }
192
193 void invalidate() { valid_ = false; }
194
195 // return true, if edge is visited on given element
196 bool isOnElement(int elementIndex, int idx, int codim) const
197 {
198 assert( valid_ );
199 // this marker only works for codim 1, i.e. edges
200 assert( codim == 1 );
201 return marker_[idx] == elementIndex;
202 }
203
204 // this is for the LeafIterator
205 template <class GridType>
206 void update (const GridType & grid)
207 {
208 static const int dimworld = GridType::dimensionworld;
209 static const ALU2DSPACE ElementType eltype = GridType::elementType;
210
211 typedef typename ALU2dImplTraits< dimworld, eltype >::template Codim<0>::InterfaceType ElementType;
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
288 class ALU2dGridObjectStream
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
Implements an utility class that provides collective communication methods for sequential programs.
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:84
@ All_Partition
all entities
Definition: gridenums.hh:139
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 22, 23:33, 2024)