dune-geometry 2.9.1
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// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_GEOMETRY_REFINEMENT_PYRAMIDTRIANGULATION_CC
6#define DUNE_GEOMETRY_REFINEMENT_PYRAMIDTRIANGULATION_CC
7
8#include <dune/common/fvector.hh>
9#include <dune/common/typetraits.hh>
10
12#include <dune/geometry/type.hh>
13
14#include "base.cc"
15#include "simplex.cc"
16
17namespace Dune
18{
19 namespace RefinementImp
20 {
26 namespace PyramidTriangulation
27 {
28 // ////////////
29 //
30 // Utilities
31 //
32
35
36 // ////////////////////////////////////
37 //
38 // Refine a pyramid with simplices
39 //
40
41 // forward declaration of the iterator base
42 template<int dimension, class CoordType, int codimension>
44
45 /*
46 * The permutations 0 and 1 of the Kuhn-decomposition of a cube into simplices form a pyramid.
47 * The resulting pyramid is not oriented the same as the reference pyramid and so the Kuhn-coordinates
48 * have to be transformed using the method below.
49 */
50 template<int dimension, class CoordType> FieldVector<CoordType, dimension>
51 transformCoordinate( FieldVector<CoordType, dimension> point)
52 {
53 FieldVector<CoordType, dimension> transform;
54 transform[0]=1-point[0];
55 transform[1]=1-point[1];
56 transform[2]=point[2];
57 return transform;
58 }
59
66 template<int dimension_, class CoordType>
68 {
69 public:
70 constexpr static int dimension = dimension_;
71
72 typedef CoordType ctype;
73
74 template<int codimension>
75 struct Codim;
77 typedef FieldVector<CoordType, dimension> CoordVector;
79 typedef FieldVector<int, dimension+1> IndexVector;
80
81 static int nVertices(int nIntervals);
82 static VertexIterator vBegin(int nIntervals);
83 static VertexIterator vEnd(int nIntervals);
84
85 static int nElements(int nIntervals);
86 static ElementIterator eBegin(int nIntervals);
87 static ElementIterator eEnd(int nIntervals);
88
89 private:
90 friend class RefinementIteratorSpecial<dimension, CoordType, 0>;
91 friend class RefinementIteratorSpecial<dimension, CoordType, dimension>;
92
94
95 constexpr static int nKuhnSimplices = 2;
96 };
97
98 template<int dimension, class CoordType>
99 template<int codimension>
100 struct RefinementImp<dimension, CoordType>::Codim
101 {
102 class SubEntityIterator;
104 };
105
106 template<int dimension, class CoordType>
107 int
109 nVertices(int nIntervals)
110 {
111 return BackendRefinement::nVertices(nIntervals) * nKuhnSimplices;
112 }
113
114 template<int dimension, class CoordType>
117 vBegin(int nIntervals)
118 {
119 return VertexIterator(nIntervals);
120 }
121
122 template<int dimension, class CoordType>
125 vEnd(int nIntervals)
126 {
127 return VertexIterator(nIntervals, true);
128 }
129
130 template<int dimension, class CoordType>
131 int
133 nElements(int nIntervals)
134 {
135 return BackendRefinement::nElements(nIntervals) * nKuhnSimplices;
136 }
137
138 template<int dimension, class CoordType>
141 eBegin(int nIntervals)
142 {
143 return ElementIterator(nIntervals);
144 }
145
146 template<int dimension, class CoordType>
149 eEnd(int nIntervals)
150 {
151 return ElementIterator(nIntervals, true);
152 }
153
154 // //////////////
155 //
156 // The iterator
157 //
158
159 // vertices
160 template<int dimension, class CoordType>
161 class RefinementIteratorSpecial<dimension, CoordType, dimension>
162 {
163 public:
166 typedef typename Refinement::template Codim<dimension>::Geometry Geometry;
167
168 RefinementIteratorSpecial(int nIntervals, bool end = false);
169
170 void increment();
171
172 CoordVector coords() const;
173
174 Geometry geometry() const;
175
176 int index() const;
177 protected:
179 typedef typename BackendRefinement::template Codim<dimension>::SubEntityIterator BackendIterator;
180 constexpr static int nKuhnSimplices = 2;
181
183
187 };
188
189 template<int dimension, class CoordType>
191 RefinementIteratorSpecial(int nIntervals, bool end)
192 : nIntervals_(nIntervals), kuhnIndex(0),
193 backend(BackendRefinement::vBegin(nIntervals_)),
194 backendEnd(BackendRefinement::vEnd(nIntervals_))
195 {
196 if (end)
197 kuhnIndex = nKuhnSimplices;
198 }
199
200 template<int dimension, class CoordType>
201 void
204 {
205 ++backend;
206 if(backend == backendEnd)
207 {
208 backend = BackendRefinement::vBegin(nIntervals_);
209 ++kuhnIndex;
210 }
211 }
212
213 template<int dimension, class CoordType>
216 coords() const
217 {
218 return transformCoordinate(referenceToKuhn(backend.coords(),
219 getPermutation<dimension>(kuhnIndex)));
220 }
221
222 template<int dimension, class CoordType>
225 {
226 std::vector<CoordVector> corners(1);
227 corners[0] = referenceToKuhn(backend.coords(), getPermutation<dimension>(kuhnIndex));
228 return Geometry(GeometryTypes::vertex, corners);
229 }
230
231 template<int dimension, class CoordType>
232 int
234 index() const
235 {
236 return kuhnIndex*BackendRefinement::nVertices(nIntervals_) + backend.index();
237 }
238
239 // elements
240 template<int dimension, class CoordType>
241 class RefinementIteratorSpecial<dimension, CoordType, 0>
242 {
243 public:
247 typedef typename Refinement::template Codim<0>::Geometry Geometry;
248
249 RefinementIteratorSpecial(int nIntervals, bool end = false);
250
251 void increment();
252
253 IndexVector vertexIndices() const;
254 int index() const;
255 CoordVector coords() const;
256
257 Geometry geometry() const;
258
259 private:
260 CoordVector global(const CoordVector &local) const;
261
262 protected:
264 typedef typename BackendRefinement::template Codim<0>::SubEntityIterator BackendIterator;
265 constexpr static int nKuhnSimplices = 2;
266
268
272 };
273
274 template<int dimension, class CoordType>
276 RefinementIteratorSpecial(int nIntervals, bool end)
277 : nIntervals_(nIntervals), kuhnIndex(0),
278 backend(BackendRefinement::eBegin(nIntervals_)),
279 backendEnd(BackendRefinement::eEnd(nIntervals_))
280 {
281 if (end)
282 kuhnIndex = nKuhnSimplices;
283 }
284
285 template<int dimension, class CoordType>
286 void
289 {
290 ++backend;
291 if (backend == backendEnd)
292 {
293 backend = BackendRefinement::eBegin(nIntervals_);
294 ++kuhnIndex;
295 }
296 }
297
298 template<int dimension, class CoordType>
301 vertexIndices() const
302 {
303 IndexVector indices = backend.vertexIndices();
304
305 int base = kuhnIndex * BackendRefinement::nVertices(nIntervals_);
306 indices += base;
307
308 return indices;
309 }
310
311 template<int dimension, class CoordType>
312 int
314 index() const
315 {
316 return kuhnIndex*BackendRefinement::nElements(nIntervals_) + backend.index();
317 }
318
319 template<int dimension, class CoordType>
322 coords() const
323 {
324 return global(backend.coords());
325 }
326
327 template<int dimension, class CoordType>
330 geometry() const
331 {
332 const typename BackendIterator::Geometry &
333 bgeo = backend.geometry();
334 std::vector<CoordVector> corners(dimension+1);
335 for(int i = 0; i <= dimension; ++i)
336 corners[i] = global(bgeo.corner(i));
337
338 return Geometry(bgeo.type(), corners);
339 }
340
341 template<int dimension, class CoordType>
343 CoordVector
345 global(const CoordVector &local) const
346 {
347 return transformCoordinate(referenceToKuhn(local,
348 getPermutation<dimension>(kuhnIndex)));
349 }
350
351 // common
352 template<int dimension, class CoordType>
353 template<int codimension>
354 class RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator
355 : public ForwardIteratorFacade<typename RefinementImp<dimension, CoordType>::template Codim<codimension>::SubEntityIterator, int>,
356 public RefinementIteratorSpecial<dimension, CoordType, codimension>
357 {
358 public:
360 typedef SubEntityIterator This;
361
362 SubEntityIterator(int nIntervals, bool end = false);
363
364 bool equals(const This &other) const;
365 protected:
366 using RefinementIteratorSpecial<dimension, CoordType, codimension>::kuhnIndex;
367 using RefinementIteratorSpecial<dimension, CoordType, codimension>::backend;
368 };
369
370#ifndef DOXYGEN
371 template<int dimension, class CoordType>
372 template<int codimension>
374 SubEntityIterator(int nIntervals, bool end)
375 : RefinementIteratorSpecial<dimension, CoordType, codimension>(nIntervals, end)
376 {}
377
378 template<int dimension, class CoordType>
379 template<int codimension>
380 bool
382 equals(const This &other) const
383 {
384 return kuhnIndex == other.kuhnIndex && backend == other.backend;
385 }
386#endif
387
388 } // namespace PyramidTriangulation
389 } // namespace RefinementImp
390
391 namespace RefinementImp
392 {
393 // ///////////////////////
394 //
395 // The refinement traits
396 //
397#ifndef DOXYGEN
398 template<unsigned topologyId, class CoordType, unsigned coerceToId>
399 struct Traits<
400 topologyId, CoordType, coerceToId, 3,
401 typename std::enable_if<
402 (GeometryTypes::pyramid.id() >> 1) ==
403 (topologyId >> 1) &&
404 (GeometryTypes::simplex(3).id() >> 1) ==
405 (coerceToId >> 1)
406 >::type>
407 {
408 typedef PyramidTriangulation::RefinementImp<3, CoordType> Imp;
409 };
410#endif
411
412 } // namespace RefinementImp
413} // namespace Dune
414
415#endif // DUNE_GEOMETRY_REFINEMENT_PYRAMIDTRIANGULATION_CC
This file contains the Refinement implementation for simplices (triangles, tetrahedrons....
This file contains the parts independent of a particular Refinement implementation.
A unique label for each type of element that can occur in a grid.
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition type.hh:507
Definition affinegeometry.hh:21
FieldVector< CoordType, dimension > transformCoordinate(FieldVector< CoordType, dimension > point)
Definition pyramidtriangulation.cc:51
FieldVector< int, n > getPermutation(int m)
Calculate permutation from it's index.
Definition simplex.cc:336
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:394
Static tag representing a codimension.
Definition dimension.hh:24
generic geometry implementation based on corner coordinates
Definition multilineargeometry.hh:181
Implementation of the refinement of a pyramid into simplices.
Definition pyramidtriangulation.cc:68
FieldVector< CoordType, dimension > CoordVector
Definition pyramidtriangulation.cc:77
static int nVertices(int nIntervals)
Definition pyramidtriangulation.cc:109
static int nElements(int nIntervals)
Definition pyramidtriangulation.cc:133
CoordType ctype
Definition pyramidtriangulation.cc:72
Codim< dimension >::SubEntityIterator VertexIterator
Definition pyramidtriangulation.cc:76
Codim< 0 >::SubEntityIterator ElementIterator
Definition pyramidtriangulation.cc:78
static constexpr int dimension
Definition pyramidtriangulation.cc:70
static ElementIterator eBegin(int nIntervals)
Definition pyramidtriangulation.cc:141
static ElementIterator eEnd(int nIntervals)
Definition pyramidtriangulation.cc:149
FieldVector< int, dimension+1 > IndexVector
Definition pyramidtriangulation.cc:79
static VertexIterator vBegin(int nIntervals)
Definition pyramidtriangulation.cc:117
static VertexIterator vEnd(int nIntervals)
Definition pyramidtriangulation.cc:125
Dune::MultiLinearGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition pyramidtriangulation.cc:103
RefinementImp< dimension, CoordType > Refinement
Definition pyramidtriangulation.cc:164
Refinement::template Codim< dimension >::Geometry Geometry
Definition pyramidtriangulation.cc:166
Refinement::BackendRefinement BackendRefinement
Definition pyramidtriangulation.cc:178
BackendRefinement::template Codim< dimension >::SubEntityIterator BackendIterator
Definition pyramidtriangulation.cc:179
Refinement::CoordVector CoordVector
Definition pyramidtriangulation.cc:246
Refinement::template Codim< 0 >::Geometry Geometry
Definition pyramidtriangulation.cc:247
Refinement::IndexVector IndexVector
Definition pyramidtriangulation.cc:245
BackendRefinement::template Codim< 0 >::SubEntityIterator BackendIterator
Definition pyramidtriangulation.cc:264
RefinementImp< dimension, CoordType > Refinement
Definition pyramidtriangulation.cc:244
Refinement::BackendRefinement BackendRefinement
Definition pyramidtriangulation.cc:263
SubEntityIterator This
Definition pyramidtriangulation.cc:360
RefinementImp< dimension, CoordType > Refinement
Definition pyramidtriangulation.cc:359