dune-geometry 2.9.1
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// 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_PRISMTRIANGULATION_CC
6#define DUNE_GEOMETRY_REFINEMENT_PRISMTRIANGULATION_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 PrismTriangulation
27 {
28 // ////////////
29 //
30 // Utilities
31 //
32
35
36 // ////////////////////////////////////
37 //
38 // Refine a prism with simplices
39 //
40
41 // forward declaration of the iterator base
42 template<int dimension, class CoordType, int codimension>
44 /*
45 * The permutations 0,2 and 3 of the Kuhn-decomposition of a cube into simplices form a prism.
46 * The resulting prism is not oriented the same as the reference prism and so the Kuhn-coordinates
47 * have to be transformed using the method below.
48 */
49 template<int dimension, class CoordType> FieldVector<CoordType, dimension>
50 transformCoordinate(FieldVector<CoordType, dimension> point)
51 {
52 FieldVector<CoordType, dimension> transform;
53 transform[0] = point[1];
54 transform[1] = 1 - point[0];
55 transform[2] = point[2];
56 return transform;
57 }
58
65 template<int dimension_, class CoordType>
67 {
68 public:
69 constexpr static int dimension = dimension_;
70
71 typedef CoordType ctype;
72
73 template<int codimension>
74 struct Codim;
76 typedef FieldVector<CoordType, dimension> CoordVector;
78 typedef FieldVector<int, dimension+1> IndexVector;
79
80 static int nVertices(int nIntervals);
81 static VertexIterator vBegin(int nIntervals);
82 static VertexIterator vEnd(int nIntervals);
83
84 static int nElements(int nIntervals);
85 static ElementIterator eBegin(int nIntervals);
86 static ElementIterator eEnd(int nIntervals);
87
88 private:
89 friend class RefinementIteratorSpecial<dimension, CoordType, 0>;
90 friend class RefinementIteratorSpecial<dimension, CoordType, dimension>;
91
93 };
94
95 template<int dimension, class CoordType>
96 template<int codimension>
97 struct RefinementImp<dimension, CoordType>::Codim
98 {
99 class SubEntityIterator;
101 };
102
103 template<int dimension, class CoordType>
104 int
106 nVertices(int nIntervals)
107 {
108 return BackendRefinement::nVertices(nIntervals) * 3;
109 }
110
111 template<int dimension, class CoordType>
114 vBegin(int nIntervals)
115 {
116 return VertexIterator(nIntervals);
117 }
118
119 template<int dimension, class CoordType>
122 vEnd(int nIntervals)
123 {
124 return VertexIterator(nIntervals, true);
125 }
126
127 template<int dimension, class CoordType>
128 int
130 nElements(int nIntervals)
131 {
132 return BackendRefinement::nElements(nIntervals) * 3;
133 }
134
135 template<int dimension, class CoordType>
138 eBegin(int nIntervals)
139 {
140 return ElementIterator(nIntervals);
141 }
142
143 template<int dimension, class CoordType>
146 eEnd(int nIntervals)
147 {
148 return ElementIterator(nIntervals, true);
149 }
150
151 // //////////////
152 //
153 // The iterator
154 //
155
156 // vertices
157 template<int dimension, class CoordType>
158 class RefinementIteratorSpecial<dimension, CoordType, dimension>
159 {
160 public:
163 typedef typename Refinement::template Codim<dimension>::Geometry Geometry;
164
165 RefinementIteratorSpecial(int nIntervals, bool end = false);
166
167 void increment();
168
169 CoordVector coords() const;
170 Geometry geometry () const;
171
172 int index() const;
173 protected:
175 typedef typename BackendRefinement::template Codim<dimension>::SubEntityIterator BackendIterator;
176 constexpr static int nKuhnSimplices = 3;
177
179
183 };
184
185 template<int dimension, class CoordType>
187 RefinementIteratorSpecial(int nIntervals, bool end)
188 : nIntervals_(nIntervals), kuhnIndex(0),
189 backend(BackendRefinement::vBegin(nIntervals_)),
190 backendEnd(BackendRefinement::vEnd(nIntervals_))
191 {
192 if (end)
193 kuhnIndex = nKuhnSimplices;
194 }
195
196 template<int dimension, class CoordType>
197 void
200 {
201 ++backend;
202 if (backend == backendEnd)
203 {
204 backend = BackendRefinement::vBegin(nIntervals_);
205 ++kuhnIndex;
206 }
207 }
208
209 template<int dimension, class CoordType>
212 coords() const
213 {
214 // while the kuhnIndex runs from 0,1,2 the actual permutations we need are 0,2,3
215 return transformCoordinate(referenceToKuhn(backend.coords(),
216 getPermutation<dimension>((kuhnIndex + 2) % 4)));
217 }
218
219 template<int dimension, class CoordType>
222 {
223 std::vector<CoordVector> corners(1);
224 corners[0] = transformCoordinate(referenceToKuhn(backend.coords(),
225 getPermutation<dimension>((kuhnIndex + 2) % 4)));
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 constexpr static int nKuhnSimplices = 3;
264
266
270 };
271
272 template<int dimension, class CoordType>
274 RefinementIteratorSpecial(int nIntervals, bool end)
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 {
329 const typename BackendIterator::Geometry &bgeo =
330 backend.geometry();
331 std::vector<CoordVector> corners(dimension+1);
332 for(int i = 0; i <= dimension; ++i)
333 corners[i] = global(bgeo.corner(i));
334
335 return Geometry(bgeo.type(), corners);
336 }
337
338 template<int dimension, class CoordType>
341 global(const CoordVector &local) const
342 {
343 // while the kuhnIndex runs from 0,1,2 the actual permutations we need are 0,2,3
344 return transformCoordinate(referenceToKuhn(local, getPermutation<dimension>((kuhnIndex+2)%4)));
345 }
346
347 // common
348 template<int dimension, class CoordType>
349 template<int codimension>
350 class RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator
351 : public ForwardIteratorFacade<typename RefinementImp<dimension, CoordType>::template Codim<codimension>::SubEntityIterator, int>,
352 public RefinementIteratorSpecial<dimension, CoordType, codimension>
353 {
354 public:
356 typedef SubEntityIterator This;
357
358 SubEntityIterator(int nIntervals, bool end = false);
359
360 bool equals(const This &other) const;
361 protected:
362 using RefinementIteratorSpecial<dimension, CoordType, codimension>::kuhnIndex;
363 using RefinementIteratorSpecial<dimension, CoordType, codimension>::backend;
364 };
365
366#ifndef DOXYGEN
367 template<int dimension, class CoordType>
368 template<int codimension>
370 SubEntityIterator(int nIntervals, bool end)
371 : RefinementIteratorSpecial<dimension, CoordType, codimension>(nIntervals, end)
372 {}
373
374 template<int dimension, class CoordType>
375 template<int codimension>
376 bool
378 equals(const This &other) const
379 {
380 return ((kuhnIndex == other.kuhnIndex) && (backend == other.backend));
381 }
382#endif
383
384 } // namespace PrismTriangulation
385 } // namespace RefinementImp
386
387 namespace RefinementImp
388 {
389 // ///////////////////////
390 //
391 // The refinement traits
392 //
393
394#ifndef DOXYGEN
395 template<unsigned topologyId, class CoordType, unsigned coerceToId>
396 struct Traits<
397 topologyId, CoordType, coerceToId, 3,
398 typename std::enable_if<
399 (GeometryTypes::prism.id() >> 1) ==
400 (topologyId >> 1) &&
401 (GeometryTypes::simplex(3).id() >> 1) ==
402 (coerceToId >> 1)
403 >::type>
404 {
405 typedef PrismTriangulation::RefinementImp<3, CoordType> Imp;
406 };
407#endif
408
409 } // namespace RefinementImp
410} // namespace Dune
411
412#endif // DUNE_GEOMETRY_REFINEMENT_PRISMTRIANGULATION_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 prismtriangulation.cc:50
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 prism into simplices.
Definition prismtriangulation.cc:67
static constexpr int dimension
Definition prismtriangulation.cc:69
CoordType ctype
Definition prismtriangulation.cc:71
static VertexIterator vEnd(int nIntervals)
Definition prismtriangulation.cc:122
FieldVector< int, dimension+1 > IndexVector
Definition prismtriangulation.cc:78
static ElementIterator eEnd(int nIntervals)
Definition prismtriangulation.cc:146
static int nVertices(int nIntervals)
Definition prismtriangulation.cc:106
FieldVector< CoordType, dimension > CoordVector
Definition prismtriangulation.cc:76
static int nElements(int nIntervals)
Definition prismtriangulation.cc:130
Codim< 0 >::SubEntityIterator ElementIterator
Definition prismtriangulation.cc:77
Codim< dimension >::SubEntityIterator VertexIterator
Definition prismtriangulation.cc:75
static ElementIterator eBegin(int nIntervals)
Definition prismtriangulation.cc:138
static VertexIterator vBegin(int nIntervals)
Definition prismtriangulation.cc:114
Dune::MultiLinearGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition prismtriangulation.cc:100
Refinement::template Codim< dimension >::Geometry Geometry
Definition prismtriangulation.cc:163
Refinement::BackendRefinement BackendRefinement
Definition prismtriangulation.cc:174
BackendRefinement::template Codim< dimension >::SubEntityIterator BackendIterator
Definition prismtriangulation.cc:175
RefinementImp< dimension, CoordType > Refinement
Definition prismtriangulation.cc:161
Refinement::template Codim< 0 >::Geometry Geometry
Definition prismtriangulation.cc:245
Refinement::IndexVector IndexVector
Definition prismtriangulation.cc:243
BackendRefinement::template Codim< 0 >::SubEntityIterator BackendIterator
Definition prismtriangulation.cc:262
Refinement::CoordVector CoordVector
Definition prismtriangulation.cc:244
RefinementImp< dimension, CoordType > Refinement
Definition prismtriangulation.cc:242
Refinement::BackendRefinement BackendRefinement
Definition prismtriangulation.cc:261
SubEntityIterator This
Definition prismtriangulation.cc:356
RefinementImp< dimension, CoordType > Refinement
Definition prismtriangulation.cc:355