dune-geometry 2.8.0
Loading...
Searching...
No Matches
pyramidtriangulation.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_PYRAMIDTRIANGULATION_CC
4#define DUNE_GEOMETRY_REFINEMENT_PYRAMIDTRIANGULATION_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 PyramidTriangulation
25 {
26 // ////////////
27 //
28 // Utilities
29 //
30
33
34 // ////////////////////////////////////
35 //
36 // Refine a pyramid with simplices
37 //
38
39 // forward declaration of the iterator base
40 template<int dimension, class CoordType, int codimension>
42
43 /*
44 * The permutations 0 and 1 of the Kuhn-decomposition of a cube into simplices form a pyramid.
45 * The resulting pyramid is not oriented the same as the reference pyramid and so the Kuhn-coordinates
46 * have to be transformed using the method below.
47 */
48 template<int dimension, class CoordType> FieldVector<CoordType, dimension>
50 {
52 transform[0]=1-point[0];
53 transform[1]=1-point[1];
54 transform[2]=point[2];
55 return transform;
56 }
57
64 template<int dimension_, class CoordType>
66 {
67 public:
69
70 typedef CoordType ctype;
71
72 template<int codimension>
73 struct Codim;
78
79 static int nVertices(int nIntervals);
81 static VertexIterator vEnd(int nIntervals);
82
83 static int nElements(int nIntervals);
86
87 private:
88 friend class RefinementIteratorSpecial<dimension, CoordType, 0>;
89 friend class RefinementIteratorSpecial<dimension, CoordType, dimension>;
90
92
93 enum { nKuhnSimplices = 2 };
94 };
95
96 template<int dimension, class CoordType>
97 template<int codimension>
98 struct RefinementImp<dimension, CoordType>::Codim
99 {
100 class SubEntityIterator;
102 };
103
104 template<int dimension, class CoordType>
105 int
108 {
109 return BackendRefinement::nVertices(nIntervals) * nKuhnSimplices;
110 }
111
112 template<int dimension, class CoordType>
119
120 template<int dimension, class CoordType>
127
128 template<int dimension, class CoordType>
129 int
132 {
133 return BackendRefinement::nElements(nIntervals) * nKuhnSimplices;
134 }
135
136 template<int dimension, class CoordType>
143
144 template<int dimension, class CoordType>
151
152 // //////////////
153 //
154 // The iterator
155 //
156
157 // vertices
158 template<int dimension, class CoordType>
159 class RefinementIteratorSpecial<dimension, CoordType, dimension>
160 {
161 public:
163 typedef typename Refinement::CoordVector CoordVector;
164 typedef typename Refinement::template Codim<dimension>::Geometry Geometry;
165
166 RefinementIteratorSpecial(int nIntervals, bool end = false);
167
168 void increment();
169
170 CoordVector coords() const;
171
172 Geometry geometry() const;
173
174 int index() const;
175 protected:
176 typedef typename Refinement::BackendRefinement BackendRefinement;
177 typedef typename BackendRefinement::template Codim<dimension>::SubEntityIterator BackendIterator;
178 enum { nKuhnSimplices = 2 };
179
181
185 };
186
187 template<int dimension, class CoordType>
190 : nIntervals_(nIntervals), kuhnIndex(0),
191 backend(BackendRefinement::vBegin(nIntervals_)),
192 backendEnd(BackendRefinement::vEnd(nIntervals_))
193 {
194 if (end)
195 kuhnIndex = nKuhnSimplices;
196 }
197
198 template<int dimension, class CoordType>
199 void
202 {
203 ++backend;
204 if(backend == backendEnd)
205 {
206 backend = BackendRefinement::vBegin(nIntervals_);
207 ++kuhnIndex;
208 }
209 }
210
211 template<int dimension, class CoordType>
214 coords() const
215 {
216 return transformCoordinate(referenceToKuhn(backend.coords(),
217 getPermutation<dimension>(kuhnIndex)));
218 }
219
220 template<int dimension, class CoordType>
223 {
224 std::vector<CoordVector> corners(1);
225 corners[0] = referenceToKuhn(backend.coords(), getPermutation<dimension>(kuhnIndex));
226 return Geometry(GeometryTypes::vertex, corners);
227 }
228
229 template<int dimension, class CoordType>
230 int
232 index() const
233 {
234 return kuhnIndex*BackendRefinement::nVertices(nIntervals_) + backend.index();
235 }
236
237 // elements
238 template<int dimension, class CoordType>
239 class RefinementIteratorSpecial<dimension, CoordType, 0>
240 {
241 public:
245 typedef typename Refinement::template Codim<0>::Geometry Geometry;
246
247 RefinementIteratorSpecial(int nIntervals, bool end = false);
248
249 void increment();
250
251 IndexVector vertexIndices() const;
252 int index() const;
253 CoordVector coords() const;
254
255 Geometry geometry() const;
256
257 private:
258 CoordVector global(const CoordVector &local) const;
259
260 protected:
262 typedef typename BackendRefinement::template Codim<0>::SubEntityIterator BackendIterator;
263 enum { nKuhnSimplices = 2};
264
266
270 };
271
272 template<int dimension, class CoordType>
275 : nIntervals_(nIntervals), kuhnIndex(0),
276 backend(BackendRefinement::eBegin(nIntervals_)),
277 backendEnd(BackendRefinement::eEnd(nIntervals_))
278 {
279 if (end)
280 kuhnIndex = nKuhnSimplices;
281 }
282
283 template<int dimension, class CoordType>
284 void
287 {
288 ++backend;
289 if (backend == backendEnd)
290 {
291 backend = BackendRefinement::eBegin(nIntervals_);
292 ++kuhnIndex;
293 }
294 }
295
296 template<int dimension, class CoordType>
299 vertexIndices() const
300 {
301 IndexVector indices = backend.vertexIndices();
302
303 int base = kuhnIndex * BackendRefinement::nVertices(nIntervals_);
304 indices += base;
305
306 return indices;
307 }
308
309 template<int dimension, class CoordType>
310 int
312 index() const
313 {
314 return kuhnIndex*BackendRefinement::nElements(nIntervals_) + backend.index();
315 }
316
317 template<int dimension, class CoordType>
320 coords() const
321 {
322 return global(backend.coords());
323 }
324
325 template<int dimension, class CoordType>
328 geometry() const
329 {
330 const typename BackendIterator::Geometry &
331 bgeo = backend.geometry();
332 std::vector<CoordVector> corners(dimension+1);
333 for(int i = 0; i <= dimension; ++i)
334 corners[i] = global(bgeo.corner(i));
335
336 return Geometry(bgeo.type(), corners);
337 }
338
339 template<int dimension, class CoordType>
341 CoordVector
343 global(const CoordVector &local) const
344 {
345 return transformCoordinate(referenceToKuhn(local,
346 getPermutation<dimension>(kuhnIndex)));
347 }
348
349 // common
350 template<int dimension, class CoordType>
351 template<int codimension>
352 class RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator
353 : public ForwardIteratorFacade<typename RefinementImp<dimension, CoordType>::template Codim<codimension>::SubEntityIterator, int>,
354 public RefinementIteratorSpecial<dimension, CoordType, codimension>
355 {
356 public:
358 typedef SubEntityIterator This;
359
360 SubEntityIterator(int nIntervals, bool end = false);
361
362 bool equals(const This &other) const;
363 protected:
364 using RefinementIteratorSpecial<dimension, CoordType, codimension>::kuhnIndex;
365 using RefinementIteratorSpecial<dimension, CoordType, codimension>::backend;
366 };
367
368#ifndef DOXYGEN
369 template<int dimension, class CoordType>
370 template<int codimension>
373 : RefinementIteratorSpecial<dimension, CoordType, codimension>(nIntervals, end)
374 {}
375
376 template<int dimension, class CoordType>
377 template<int codimension>
378 bool
380 equals(const This &other) const
381 {
382 return kuhnIndex == other.kuhnIndex && backend == other.backend;
383 }
384#endif
385
386 } // namespace PyramidTriangulation
387 } // namespace RefinementImp
388
389 namespace RefinementImp
390 {
391 // ///////////////////////
392 //
393 // The refinement traits
394 //
395#ifndef DOXYGEN
396 template<unsigned topologyId, class CoordType, unsigned coerceToId>
397 struct Traits<
398 topologyId, CoordType, coerceToId, 3,
399 typename std::enable_if<
400 (GeometryTypes::pyramid.id() >> 1) ==
401 (topologyId >> 1) &&
402 (GeometryTypes::simplex(3).id() >> 1) ==
403 (coerceToId >> 1)
404 >::type>
405 {
406 typedef PyramidTriangulation::RefinementImp<3, CoordType> Imp;
407 };
408#endif
409
410 } // namespace RefinementImp
411} // namespace Dune
412
413#endif // DUNE_GEOMETRY_REFINEMENT_PYRAMIDTRIANGULATION_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 pyramidtriangulation.cc:49
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 pyramid into simplices.
Definition pyramidtriangulation.cc:66
FieldVector< CoordType, dimension > CoordVector
Definition pyramidtriangulation.cc:75
static int nVertices(int nIntervals)
Definition pyramidtriangulation.cc:107
static int nElements(int nIntervals)
Definition pyramidtriangulation.cc:131
CoordType ctype
Definition pyramidtriangulation.cc:70
Codim< dimension >::SubEntityIterator VertexIterator
Definition pyramidtriangulation.cc:74
Codim< 0 >::SubEntityIterator ElementIterator
Definition pyramidtriangulation.cc:76
static ElementIterator eBegin(int nIntervals)
Definition pyramidtriangulation.cc:139
static ElementIterator eEnd(int nIntervals)
Definition pyramidtriangulation.cc:147
@ dimension
Definition pyramidtriangulation.cc:68
FieldVector< int, dimension+1 > IndexVector
Definition pyramidtriangulation.cc:77
static VertexIterator vBegin(int nIntervals)
Definition pyramidtriangulation.cc:115
static VertexIterator vEnd(int nIntervals)
Definition pyramidtriangulation.cc:123
Dune::MultiLinearGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition pyramidtriangulation.cc:101
RefinementImp< dimension, CoordType > Refinement
Definition pyramidtriangulation.cc:162
Refinement::template Codim< dimension >::Geometry Geometry
Definition pyramidtriangulation.cc:164
Refinement::BackendRefinement BackendRefinement
Definition pyramidtriangulation.cc:176
BackendRefinement::template Codim< dimension >::SubEntityIterator BackendIterator
Definition pyramidtriangulation.cc:177
Refinement::CoordVector CoordVector
Definition pyramidtriangulation.cc:244
Refinement::template Codim< 0 >::Geometry Geometry
Definition pyramidtriangulation.cc:245
Refinement::IndexVector IndexVector
Definition pyramidtriangulation.cc:243
BackendRefinement::template Codim< 0 >::SubEntityIterator BackendIterator
Definition pyramidtriangulation.cc:262
RefinementImp< dimension, CoordType > Refinement
Definition pyramidtriangulation.cc:242
Refinement::BackendRefinement BackendRefinement
Definition pyramidtriangulation.cc:261
SubEntityIterator This
Definition pyramidtriangulation.cc:358
RefinementImp< dimension, CoordType > Refinement
Definition pyramidtriangulation.cc:357