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