dune-geometry 2.8.0
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#ifndef DUNE_GEOMETRY_REFINEMENT_HCUBETRIANGULATION_CC
4#define DUNE_GEOMETRY_REFINEMENT_HCUBETRIANGULATION_CC
5
28#include <dune/geometry/type.hh>
29
30#include "base.cc"
31#include "simplex.cc"
32
33namespace Dune
34{
35 namespace RefinementImp
36 {
44 namespace HCubeTriangulation {
45
46 // ////////////
47 //
48 // Utilities
49 //
50
53
54 // ////////////////////////////////////
55 //
56 // Refine a hypercube with simplices
57 //
58
59 // forward declaration of the iterator base
60 template<int dimension, class CoordType, int codimension>
62
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 private:
86 friend class RefinementIteratorSpecial<dimension, CoordType, 0>;
87 friend class RefinementIteratorSpecial<dimension, CoordType, dimension>;
88
90 };
91
92 template<int dimension, class CoordType>
93 template<int codimension>
94 struct RefinementImp<dimension, CoordType>::Codim
95 {
96 class SubEntityIterator;
98 };
99
100 template<int dimension, class CoordType>
101 int
104 {
105 return BackendRefinement::nVertices(nIntervals) * Factorial<dimension>::factorial;
106 }
107
108 template<int dimension, class CoordType>
115
116 template<int dimension, class CoordType>
123
124 template<int dimension, class CoordType>
125 int
128 {
129 return BackendRefinement::nElements(nIntervals) * Factorial<dimension>::factorial;
130 }
131
132 template<int dimension, class CoordType>
139
140 template<int dimension, class CoordType>
147
148 // //////////////
149 //
150 // The iterator
151 //
152
153 // vertices
154 template<int dimension, class CoordType>
155 class RefinementIteratorSpecial<dimension, CoordType, dimension>
156 {
157 public:
159 typedef typename Refinement::CoordVector CoordVector;
160 typedef typename Refinement::template Codim<dimension>::Geometry Geometry;
161
162 RefinementIteratorSpecial(int nIntervals, bool end = false);
163
164 void increment();
165
166 CoordVector coords() const;
167
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 = Factorial<dimension>::factorial };
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 return referenceToKuhn(backend.coords(), getPermutation<dimension>(kuhnIndex));
213 }
214
215 template<int dimension, class CoordType>
218 {
219 std::vector<CoordVector> corners(1);
220 corners[0] = referenceToKuhn(backend.coords(), getPermutation<dimension>(kuhnIndex));
221 return Geometry(GeometryTypes::vertex, corners);
222 }
223
224 template<int dimension, class CoordType>
225 int
227 index() const
228 {
229 return kuhnIndex*BackendRefinement::nVertices(nIntervals_) + backend.index();
230 }
231
232 // elements
233 template<int dimension, class CoordType>
234 class RefinementIteratorSpecial<dimension, CoordType, 0>
235 {
236 public:
240 typedef typename Refinement::template Codim<0>::Geometry Geometry;
241
242 RefinementIteratorSpecial(int nIntervals_, bool end = false);
244
245 void increment();
246
247 IndexVector vertexIndices() const;
248 int index() const;
249 CoordVector coords() const;
250
251 Geometry geometry() const;
252
253 private:
254 CoordVector global(const CoordVector &local) const;
255
256 protected:
258 typedef typename BackendRefinement::template Codim<0>::SubEntityIterator BackendIterator;
259 enum { nKuhnSimplices = Factorial<dimension>::factorial };
260
262
266 };
267
268 template<int dimension, class CoordType>
271 : nIntervals_(nIntervals), kuhnIndex(0),
272 backend(BackendRefinement::eBegin(nIntervals_)),
273 backendEnd(BackendRefinement::eEnd(nIntervals_))
274 {
275 if (end)
276 kuhnIndex = nKuhnSimplices;
277 }
278 template<int dimension, class CoordType>
281 : nIntervals_(other.nIntervals_), kuhnIndex(other.kuhnIndex),
282 backend(other.backend),
283 backendEnd(other.backendEnd)
284 {}
285
286 template<int dimension, class CoordType>
287 void
290 {
291 ++backend;
292 if (backend == backendEnd)
293 {
294 backend = BackendRefinement::eBegin(nIntervals_);
295 ++kuhnIndex;
296 }
297 }
298
299 template<int dimension, class CoordType>
302 vertexIndices() const
303 {
304 IndexVector indices = backend.vertexIndices();
305
306 int base = kuhnIndex * BackendRefinement::nVertices(nIntervals_);
307 indices += base;
308
309 return indices;
310 }
311
312 template<int dimension, class CoordType>
313 int
315 index() const
316 {
317 return kuhnIndex*BackendRefinement::nElements(nIntervals_) + backend.index();
318 }
319
320 template<int dimension, class CoordType>
323 coords() const
324 {
325 return global(backend.coords());
326 }
327
328 template<int dimension, class CoordType>
331 {
332 const typename BackendIterator::Geometry &bgeo =
333 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>
344 global(const CoordVector &local) const
345 {
346 return referenceToKuhn(local, 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 { return kuhnIndex == other.kuhnIndex && backend == other.backend; }
382
383#endif // DOXYGEN
384
385 } // namespace HCubeTriangulation
386 } // namespace RefinementImp
387
388 namespace RefinementImp
389 {
390 // ///////////////////////
391 //
392 // The refinement traits
393 //
394
395#ifndef DOXYGEN
396 template<unsigned topologyId, class CoordType, unsigned coerceToId,
397 int dim>
398 struct Traits<
399 topologyId, CoordType, coerceToId, dim,
400 typename std::enable_if<
401 (dim >= 2 &&
402 (GeometryTypes::cube(dim).id() >> 1) ==
403 (topologyId >> 1) &&
404 (GeometryTypes::simplex(dim).id() >> 1) ==
405 (coerceToId >> 1)
406 )>::type
407 >
408 {
409 typedef HCubeTriangulation::RefinementImp<dim, CoordType> Imp;
410 };
411#endif
412
413 } // namespace RefinementImp
414} // namespace Dune
415
416#endif // DUNE_GEOMETRY_REFINEMENT_HCUBETRIANGULATION_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< 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()
size_type dim() const
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
static VertexIterator vEnd(int nIntervals)
Definition hcubetriangulation.cc:119
static VertexIterator vBegin(int nIntervals)
Definition hcubetriangulation.cc:111
static int nElements(int nIntervals)
Definition hcubetriangulation.cc:127
@ dimension
Definition hcubetriangulation.cc:67
FieldVector< CoordType, dimension > CoordVector
Definition hcubetriangulation.cc:74
CoordType ctype
Definition hcubetriangulation.cc:69
Codim< 0 >::SubEntityIterator ElementIterator
Definition hcubetriangulation.cc:75
FieldVector< int, dimension+1 > IndexVector
Definition hcubetriangulation.cc:76
static ElementIterator eBegin(int nIntervals)
Definition hcubetriangulation.cc:135
static ElementIterator eEnd(int nIntervals)
Definition hcubetriangulation.cc:143
Codim< dimension >::SubEntityIterator VertexIterator
Definition hcubetriangulation.cc:73
static int nVertices(int nIntervals)
Definition hcubetriangulation.cc:103
Dune::MultiLinearGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition hcubetriangulation.cc:97
Refinement::template Codim< dimension >::Geometry Geometry
Definition hcubetriangulation.cc:160
BackendRefinement::template Codim< dimension >::SubEntityIterator BackendIterator
Definition hcubetriangulation.cc:173
Refinement::BackendRefinement BackendRefinement
Definition hcubetriangulation.cc:172
RefinementImp< dimension, CoordType > Refinement
Definition hcubetriangulation.cc:158
BackendRefinement::template Codim< 0 >::SubEntityIterator BackendIterator
Definition hcubetriangulation.cc:258
Refinement::CoordVector CoordVector
Definition hcubetriangulation.cc:239
Refinement::BackendRefinement BackendRefinement
Definition hcubetriangulation.cc:257
Refinement::IndexVector IndexVector
Definition hcubetriangulation.cc:238
RefinementImp< dimension, CoordType > Refinement
Definition hcubetriangulation.cc:237
Refinement::template Codim< 0 >::Geometry Geometry
Definition hcubetriangulation.cc:240
RefinementImp< dimension, CoordType > Refinement
Definition hcubetriangulation.cc:357
SubEntityIterator This
Definition hcubetriangulation.cc:358