dune-geometry 2.9.1
Loading...
Searching...
No Matches
hcubetriangulation.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_HCUBETRIANGULATION_CC
6#define DUNE_GEOMETRY_REFINEMENT_HCUBETRIANGULATION_CC
7
30#include <dune/geometry/type.hh>
31
32#include "base.cc"
33#include "simplex.cc"
34
35namespace Dune
36{
37 namespace RefinementImp
38 {
46 namespace HCubeTriangulation {
47
48 // ////////////
49 //
50 // Utilities
51 //
52
55
56 // ////////////////////////////////////
57 //
58 // Refine a hypercube with simplices
59 //
60
61 // forward declaration of the iterator base
62 template<int dimension, class CoordType, int codimension>
64
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 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 nIntervals)
106 {
107 return BackendRefinement::nVertices(nIntervals) * factorial(int(dimension));
108 }
109
110 template<int dimension, class CoordType>
113 vBegin(int nIntervals)
114 {
115 return VertexIterator(nIntervals);
116 }
117
118 template<int dimension, class CoordType>
121 vEnd(int nIntervals)
122 {
123 return VertexIterator(nIntervals, true);
124 }
125
126 template<int dimension, class CoordType>
127 int
129 nElements(int nIntervals)
130 {
131 return BackendRefinement::nElements(nIntervals) * factorial(int(dimension));
132 }
133
134 template<int dimension, class CoordType>
137 eBegin(int nIntervals)
138 {
139 return ElementIterator(nIntervals);
140 }
141
142 template<int dimension, class CoordType>
145 eEnd(int nIntervals)
146 {
147 return ElementIterator(nIntervals, 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:
162 typedef typename Refinement::template Codim<dimension>::Geometry Geometry;
163
164 RefinementIteratorSpecial(int nIntervals, bool end = false);
165
166 void increment();
167
168 CoordVector coords() const;
169
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 = factorial(int(dimension));
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 return referenceToKuhn(backend.coords(), getPermutation<dimension>(kuhnIndex));
215 }
216
217 template<int dimension, class CoordType>
220 {
221 std::vector<CoordVector> corners(1);
222 corners[0] = referenceToKuhn(backend.coords(), getPermutation<dimension>(kuhnIndex));
223 return Geometry(GeometryTypes::vertex, corners);
224 }
225
226 template<int dimension, class CoordType>
227 int
229 index() const
230 {
231 return kuhnIndex*BackendRefinement::nVertices(nIntervals_) + backend.index();
232 }
233
234 // elements
235 template<int dimension, class CoordType>
236 class RefinementIteratorSpecial<dimension, CoordType, 0>
237 {
238 public:
242 typedef typename Refinement::template Codim<0>::Geometry Geometry;
243
244 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 constexpr static int nKuhnSimplices = factorial(dimension);
262
264
268 };
269
270 template<int dimension, class CoordType>
272 RefinementIteratorSpecial(int nIntervals, bool end)
273 : nIntervals_(nIntervals), kuhnIndex(0),
274 backend(BackendRefinement::eBegin(nIntervals_)),
275 backendEnd(BackendRefinement::eEnd(nIntervals_))
276 {
277 if (end)
278 kuhnIndex = nKuhnSimplices;
279 }
280 template<int dimension, class CoordType>
283 : nIntervals_(other.nIntervals_), kuhnIndex(other.kuhnIndex),
284 backend(other.backend),
285 backendEnd(other.backendEnd)
286 {}
287
288 template<int dimension, class CoordType>
289 void
292 {
293 ++backend;
294 if (backend == backendEnd)
295 {
296 backend = BackendRefinement::eBegin(nIntervals_);
297 ++kuhnIndex;
298 }
299 }
300
301 template<int dimension, class CoordType>
304 vertexIndices() const
305 {
306 IndexVector indices = backend.vertexIndices();
307
308 int base = kuhnIndex * BackendRefinement::nVertices(nIntervals_);
309 indices += base;
310
311 return indices;
312 }
313
314 template<int dimension, class CoordType>
315 int
317 index() const
318 {
319 return kuhnIndex*BackendRefinement::nElements(nIntervals_) + backend.index();
320 }
321
322 template<int dimension, class CoordType>
325 coords() const
326 {
327 return global(backend.coords());
328 }
329
330 template<int dimension, class CoordType>
333 {
334 const typename BackendIterator::Geometry &bgeo =
335 backend.geometry();
336 std::vector<CoordVector> corners(dimension+1);
337 for(int i = 0; i <= dimension; ++i)
338 corners[i] = global(bgeo.corner(i));
339
340 return Geometry(bgeo.type(), corners);
341 }
342
343 template<int dimension, class CoordType>
346 global(const CoordVector &local) const
347 {
348 return referenceToKuhn(local, 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 { return kuhnIndex == other.kuhnIndex && backend == other.backend; }
384
385#endif // DOXYGEN
386
387 } // namespace HCubeTriangulation
388 } // namespace RefinementImp
389
390 namespace RefinementImp
391 {
392 // ///////////////////////
393 //
394 // The refinement traits
395 //
396
397#ifndef DOXYGEN
398 template<unsigned topologyId, class CoordType, unsigned coerceToId,
399 int dim>
400 struct Traits<
401 topologyId, CoordType, coerceToId, dim,
402 typename std::enable_if<
403 (dim >= 2 &&
404 (GeometryTypes::cube(dim).id() >> 1) ==
405 (topologyId >> 1) &&
406 (GeometryTypes::simplex(dim).id() >> 1) ==
407 (coerceToId >> 1)
408 )>::type
409 >
410 {
411 typedef HCubeTriangulation::RefinementImp<dim, CoordType> Imp;
412 };
413#endif
414
415 } // namespace RefinementImp
416} // namespace Dune
417
418#endif // DUNE_GEOMETRY_REFINEMENT_HCUBETRIANGULATION_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< 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
static VertexIterator vEnd(int nIntervals)
Definition hcubetriangulation.cc:121
static VertexIterator vBegin(int nIntervals)
Definition hcubetriangulation.cc:113
static int nElements(int nIntervals)
Definition hcubetriangulation.cc:129
FieldVector< CoordType, dimension > CoordVector
Definition hcubetriangulation.cc:76
CoordType ctype
Definition hcubetriangulation.cc:71
Codim< 0 >::SubEntityIterator ElementIterator
Definition hcubetriangulation.cc:77
FieldVector< int, dimension+1 > IndexVector
Definition hcubetriangulation.cc:78
static ElementIterator eBegin(int nIntervals)
Definition hcubetriangulation.cc:137
static ElementIterator eEnd(int nIntervals)
Definition hcubetriangulation.cc:145
static constexpr int dimension
Definition hcubetriangulation.cc:69
Codim< dimension >::SubEntityIterator VertexIterator
Definition hcubetriangulation.cc:75
static int nVertices(int nIntervals)
Definition hcubetriangulation.cc:105
Dune::MultiLinearGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition hcubetriangulation.cc:99
Refinement::template Codim< dimension >::Geometry Geometry
Definition hcubetriangulation.cc:162
BackendRefinement::template Codim< dimension >::SubEntityIterator BackendIterator
Definition hcubetriangulation.cc:175
Refinement::BackendRefinement BackendRefinement
Definition hcubetriangulation.cc:174
RefinementImp< dimension, CoordType > Refinement
Definition hcubetriangulation.cc:160
BackendRefinement::template Codim< 0 >::SubEntityIterator BackendIterator
Definition hcubetriangulation.cc:260
Refinement::CoordVector CoordVector
Definition hcubetriangulation.cc:241
Refinement::BackendRefinement BackendRefinement
Definition hcubetriangulation.cc:259
Refinement::IndexVector IndexVector
Definition hcubetriangulation.cc:240
RefinementImp< dimension, CoordType > Refinement
Definition hcubetriangulation.cc:239
Refinement::template Codim< 0 >::Geometry Geometry
Definition hcubetriangulation.cc:242
RefinementImp< dimension, CoordType > Refinement
Definition hcubetriangulation.cc:359
SubEntityIterator This
Definition hcubetriangulation.cc:360