dune-geometry 3.0-git
prismtriangulation.cc
Go to the documentation of this file.
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_GEOMETRY_REFINEMENT_PRISMTRIANGULATION_CC
4#define DUNE_GEOMETRY_REFINEMENT_PRISMTRIANGULATION_CC
5
6#include <dune/common/fvector.hh>
7#include <dune/common/typetraits.hh>
8
12
13#include "base.cc"
14#include "simplex.cc"
15
16namespace Dune
17{
18 namespace RefinementImp
19 {
25 namespace PrismTriangulation
26 {
27 // ////////////
28 //
29 // Utilities
30 //
31
34
35 // ////////////////////////////////////
36 //
37 // Refine a prism with simplices
38 //
39
40 // forward declaration of the iterator base
41 template<int dimension, class CoordType, int codimension>
43 /*
44 * The permutations 0,2 and 3 of the Kuhn-decomposition of a cube into simplices form a prism.
45 * The resulting prism is not oriented the same as the reference prism and so the Kuhn-coordinates
46 * have to be transformed using the method below.
47 */
48 template<int dimension, class CoordType> FieldVector<CoordType, dimension>
49 transformCoordinate(FieldVector<CoordType, dimension> point)
50 {
51 FieldVector<CoordType, dimension> transform;
52 transform[0] = point[1];
53 transform[1] = 1 - point[0];
54 transform[2] = point[2];
55 return transform;
56 }
57
64 template<int dimension_, class CoordType>
66 {
67 public:
68 enum {dimension = dimension_};
69
70 typedef CoordType ctype;
71
72 template<int codimension>
73 struct Codim;
75 typedef FieldVector<CoordType, dimension> CoordVector;
77 typedef FieldVector<int, dimension+1> IndexVector;
78
79 static int nVertices(int level);
80 static VertexIterator vBegin(int level);
81 static VertexIterator vEnd(int level);
82
83 static int nElements(int level);
84 static ElementIterator eBegin(int level);
85 static ElementIterator eEnd(int level);
86
87 private:
88 friend class RefinementIteratorSpecial<dimension, CoordType, 0>;
89 friend class RefinementIteratorSpecial<dimension, CoordType, dimension>;
90
92 };
93
94 template<int dimension, class CoordType>
95 template<int codimension>
96 struct RefinementImp<dimension, CoordType>::Codim
97 {
98 class SubEntityIterator;
99 typedef Dune::MultiLinearGeometry<CoordType,dimension-codimension,dimension> Geometry;
100 };
101
102 template<int dimension, class CoordType>
103 int
105 nVertices(int level)
106 {
107 return BackendRefinement::nVertices(level) * 3;
108 }
109
110 template<int dimension, class CoordType>
113 vBegin(int level)
114 {
115 return VertexIterator(level);
116 }
117
118 template<int dimension, class CoordType>
121 vEnd(int level)
122 {
123 return VertexIterator(level, true);
124 }
125
126 template<int dimension, class CoordType>
127 int
129 nElements(int level)
130 {
131 return BackendRefinement::nElements(level) * 3;
132 }
133
134 template<int dimension, class CoordType>
137 eBegin(int level)
138 {
139 return ElementIterator(level);
140 }
141
142 template<int dimension, class CoordType>
145 eEnd(int level)
146 {
147 return ElementIterator(level, true);
148 }
149
150 // //////////////
151 //
152 // The iterator
153 //
154
155 // vertices
156 template<int dimension, class CoordType>
157 class RefinementIteratorSpecial<dimension, CoordType, dimension>
158 {
159 public:
161 typedef typename Refinement::CoordVector CoordVector;
162 typedef typename Refinement::template Codim<dimension>::Geometry Geometry;
163
164 RefinementIteratorSpecial(int level, bool end = false);
165
166 void increment();
167
168 CoordVector coords() const;
169 Geometry geometry () const;
170
171 int index() const;
172 protected:
173 typedef typename Refinement::BackendRefinement BackendRefinement;
174 typedef typename BackendRefinement::template Codim<dimension>::SubEntityIterator BackendIterator;
175 enum { nKuhnSimplices = 3 };
176
178
182 };
183
184 template<int dimension, class CoordType>
186 RefinementIteratorSpecial(int level, bool end)
187 : level_(level), kuhnIndex(0),
188 backend(BackendRefinement::vBegin(level_)),
189 backendEnd(BackendRefinement::vEnd(level_))
190 {
191 if (end)
192 kuhnIndex = nKuhnSimplices;
193 }
194
195 template<int dimension, class CoordType>
196 void
199 {
200 ++backend;
201 if (backend == backendEnd)
202 {
203 backend = BackendRefinement::vBegin(level_);
204 ++kuhnIndex;
205 }
206 }
207
208 template<int dimension, class CoordType>
211 coords() const
212 {
213 // while the kuhnIndex runs from 0,1,2 the actual permutations we need are 0,2,3
214 return transformCoordinate(referenceToKuhn(backend.coords(),
215 getPermutation<dimension>((kuhnIndex + 2) % 4)));
216 }
217
218 template<int dimension, class CoordType>
221 {
222 std::vector<CoordVector> corners(1);
223 corners[0] = transformCoordinate(referenceToKuhn(backend.coords(),
224 getPermutation<dimension>((kuhnIndex + 2) % 4)));
225 return Geometry(GeometryType(0), corners);
226 }
227
228 template<int dimension, class CoordType>
229 int
231 index() const
232 {
233 return kuhnIndex*BackendRefinement::nVertices(level_) + backend.index();
234 }
235
236 // elements
237 template<int dimension, class CoordType>
238 class RefinementIteratorSpecial<dimension, CoordType, 0>
239 {
240 public:
244 typedef typename Refinement::template Codim<0>::Geometry Geometry;
245
246 RefinementIteratorSpecial(int level, bool end = false);
247
248 void increment();
249
250 IndexVector vertexIndices() const;
251 int index() const;
252 CoordVector coords() const;
253
254 Geometry geometry () const;
255
256 private:
257 CoordVector global(const CoordVector &local) const;
258
259 protected:
261 typedef typename BackendRefinement::template Codim<0>::SubEntityIterator BackendIterator;
262 enum { nKuhnSimplices = 3};
263
265
269 };
270
271 template<int dimension, class CoordType>
273 RefinementIteratorSpecial(int level, bool end)
274 : level_(level), kuhnIndex(0),
275 backend(BackendRefinement::eBegin(level_)),
276 backendEnd(BackendRefinement::eEnd(level_))
277 {
278 if (end)
279 kuhnIndex = nKuhnSimplices;
280 }
281
282 template<int dimension, class CoordType>
283 void
286 {
287 ++backend;
288 if (backend == backendEnd)
289 {
290 backend = BackendRefinement::eBegin(level_);
291 ++kuhnIndex;
292 }
293 }
294
295 template<int dimension, class CoordType>
298 vertexIndices() const
299 {
300 IndexVector indices = backend.vertexIndices();
301
302 int base = kuhnIndex * BackendRefinement::nVertices(level_);
303 indices += base;
304
305 return indices;
306 }
307
308 template<int dimension, class CoordType>
309 int
311 index() const
312 {
313 return kuhnIndex*BackendRefinement::nElements(level_) + backend.index();
314 }
315
316 template<int dimension, class CoordType>
319 coords() const
320 {
321 return global(backend.coords());
322 }
323
324 template<int dimension, class CoordType>
327 {
328 const typename BackendIterator::Geometry &bgeo =
329 backend.geometry();
330 std::vector<CoordVector> corners(dimension+1);
331 for(int i = 0; i <= dimension; ++i)
332 corners[i] = global(bgeo.corner(i));
333
334 return Geometry(bgeo.type(), corners);
335 }
336
337 template<int dimension, class CoordType>
340 global(const CoordVector &local) const
341 {
342 // while the kuhnIndex runs from 0,1,2 the actual permutations we need are 0,2,3
343 return transformCoordinate(referenceToKuhn(local, getPermutation<dimension>((kuhnIndex+2)%4)));
344 }
345
346 // common
347 template<int dimension, class CoordType>
348 template<int codimension>
349 class RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator
350 : public ForwardIteratorFacade<typename RefinementImp<dimension, CoordType>::template Codim<codimension>::SubEntityIterator, int>,
351 public RefinementIteratorSpecial<dimension, CoordType, codimension>
352 {
353 public:
355 typedef SubEntityIterator This;
356
357 SubEntityIterator(int level, bool end = false);
358
359 bool equals(const This &other) const;
360 protected:
361 using RefinementIteratorSpecial<dimension, CoordType, codimension>::kuhnIndex;
362 using RefinementIteratorSpecial<dimension, CoordType, codimension>::backend;
363 };
364
365#ifndef DOXYGEN
366 template<int dimension, class CoordType>
367 template<int codimension>
369 SubEntityIterator(int level, bool end)
370 : RefinementIteratorSpecial<dimension, CoordType, codimension>(level, end)
371 {}
372
373 template<int dimension, class CoordType>
374 template<int codimension>
375 bool
377 equals(const This &other) const
378 {
379 return ((kuhnIndex == other.kuhnIndex) && (backend == other.backend));
380 }
381#endif
382
383 } // namespace PrismTriangulation
384 } // namespace RefinementImp
385
386 namespace RefinementImp
387 {
388 // ///////////////////////
389 //
390 // The refinement traits
391 //
392
393#ifndef DOXYGEN
394 template<unsigned topologyId, class CoordType, unsigned coerceToId>
395 struct Traits<
396 topologyId, CoordType, coerceToId, 3,
397 typename std::enable_if<
398 (GenericGeometry::PrismTopology<3>::type::id >> 1) ==
399 (topologyId >> 1) &&
400 (GenericGeometry::SimplexTopology<3>::type::id >> 1) ==
401 (coerceToId >> 1)
402 >::type>
403 {
404 typedef PrismTriangulation::RefinementImp<3, CoordType> Imp;
405 };
406#endif
407
408 } // namespace RefinementImp
409} // namespace Dune
410
411#endif // DUNE_GEOMETRY_REFINEMENT_PRISMTRIANGULATION_CC
This file contains the parts independent of a particular Refinement implementation.
This file contains the Refinement implementation for simplices (triangles, tetrahedrons....
Definition affinegeometry.hh:19
FieldVector< CoordType, dimension > transformCoordinate(FieldVector< CoordType, dimension > point)
Definition prismtriangulation.cc:49
FieldVector< int, n > getPermutation(int m)
Calculate permutation from it's index.
Definition simplex.cc:325
FieldVector< CoordType, dimension > referenceToKuhn(FieldVector< CoordType, dimension > point, const FieldVector< int, dimension > &kuhn)
Map from the reference simplex to some Kuhn simplex.
Definition simplex.cc:383
Static tag representing a codimension.
Definition dimension.hh:22
generic geometry implementation based on corner coordinates
Definition multilineargeometry.hh:191
Implementation of the refinement of a prism into simplices.
Definition prismtriangulation.cc:66
static ElementIterator eBegin(int level)
Definition prismtriangulation.cc:137
CoordType ctype
Definition prismtriangulation.cc:70
FieldVector< int, dimension+1 > IndexVector
Definition prismtriangulation.cc:77
FieldVector< CoordType, dimension > CoordVector
Definition prismtriangulation.cc:75
static ElementIterator eEnd(int level)
Definition prismtriangulation.cc:145
Codim< 0 >::SubEntityIterator ElementIterator
Definition prismtriangulation.cc:76
static VertexIterator vBegin(int level)
Definition prismtriangulation.cc:113
Codim< dimension >::SubEntityIterator VertexIterator
Definition prismtriangulation.cc:74
@ dimension
Definition prismtriangulation.cc:68
static int nElements(int level)
Definition prismtriangulation.cc:129
static int nVertices(int level)
Definition prismtriangulation.cc:105
static VertexIterator vEnd(int level)
Definition prismtriangulation.cc:121
Dune::MultiLinearGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition prismtriangulation.cc:99
Refinement::template Codim< dimension >::Geometry Geometry
Definition prismtriangulation.cc:162
Refinement::BackendRefinement BackendRefinement
Definition prismtriangulation.cc:173
BackendRefinement::template Codim< dimension >::SubEntityIterator BackendIterator
Definition prismtriangulation.cc:174
RefinementImp< dimension, CoordType > Refinement
Definition prismtriangulation.cc:160
Refinement::template Codim< 0 >::Geometry Geometry
Definition prismtriangulation.cc:244
Refinement::IndexVector IndexVector
Definition prismtriangulation.cc:242
BackendRefinement::template Codim< 0 >::SubEntityIterator BackendIterator
Definition prismtriangulation.cc:261
Refinement::CoordVector CoordVector
Definition prismtriangulation.cc:243
RefinementImp< dimension, CoordType > Refinement
Definition prismtriangulation.cc:241
Refinement::BackendRefinement BackendRefinement
Definition prismtriangulation.cc:260
SubEntityIterator This
Definition prismtriangulation.cc:355
RefinementImp< dimension, CoordType > Refinement
Definition prismtriangulation.cc:354
Unique label for each type of entities that can occur in DUNE grids.
Definition type.hh:25