3#ifndef DUNE_GEOMETRY_GENERICGEOMETRY_CORNERMAPPING_HH
4#define DUNE_GEOMETRY_GENERICGEOMETRY_CORNERMAPPING_HH
6#include <dune/geometry/genericgeometry/topologytypes.hh>
8#include <dune/geometry/genericgeometry/matrixhelper.hh>
14 namespace GenericGeometry
20 template<
class CT,
unsigned int dim,
unsigned int dimW >
28 template<
class Topology,
class Traits,
bool affine,
unsigned int offset = 0 >
29 class GenericCornerMapping;
31 template<
class Traits,
bool affine,
unsigned int offset >
32 class GenericCornerMapping < Point, Traits, affine, offset >
34 typedef Point Topology;
37 static const unsigned int dim = Topology::dimension;
38 static const unsigned int dimW = Traits::dimWorld;
40 typedef typename Traits::FieldType FieldType;
41 typedef typename Traits::LocalCoordinate LocalCoordinate;
42 typedef typename Traits::GlobalCoordinate GlobalCoordinate;
43 typedef typename Traits::JacobianTransposedType JacobianTransposedType;
45 static const bool alwaysAffine =
true;
47 template<
class CoordStorage >
48 static const GlobalCoordinate &origin (
const CoordStorage &coords )
51 return coords[ offset ];
54 template<
class CoordStorage >
55 static void phi_set (
const CoordStorage &coords,
56 const LocalCoordinate &x,
57 const FieldType &factor,
61 const GlobalCoordinate &y = origin( coords );
62 for(
unsigned int i = 0; i < dimW; ++i )
63 p[ i ] = factor * y[ i ];
66 template<
class CoordStorage >
67 static void phi_add (
const CoordStorage &coords,
68 const LocalCoordinate &x,
69 const FieldType &factor,
72 const GlobalCoordinate &y = origin( coords );
73 for(
unsigned int i = 0; i < dimW; ++i )
74 p[ i ] += factor * y[ i ];
77 template<
class CoordStorage >
78 static bool Dphi_set (
const CoordStorage &coords,
79 const LocalCoordinate &x,
80 const FieldType &factor,
81 JacobianTransposedType &J )
90 template<
class CoordStorage >
91 static bool Dphi_add (
const CoordStorage &coords,
92 const LocalCoordinate &x,
93 const FieldType &factor,
94 JacobianTransposedType &J )
105 template<
class BaseTopology,
class Traits,
bool affine,
unsigned int offset >
106 class GenericCornerMapping< Prism< BaseTopology >, Traits, affine, offset >
108 typedef Prism< BaseTopology > Topology;
110 typedef GenericCornerMapping< BaseTopology, Traits, affine, offset >
112 typedef GenericCornerMapping
113 < BaseTopology, Traits, affine, offset + BaseTopology::numCorners >
117 static const unsigned int dim = Topology::dimension;
118 static const unsigned int dimW = Traits::dimWorld;
120 typedef typename Traits::FieldType FieldType;
121 typedef typename Traits::LocalCoordinate LocalCoordinate;
122 typedef typename Traits::GlobalCoordinate GlobalCoordinate;
123 typedef typename Traits::JacobianTransposedType JacobianTransposedType;
125 static const bool alwaysAffine = ((dim < 2) || affine);
127 template<
class CoordStorage >
128 static const GlobalCoordinate &origin (
const CoordStorage &coords )
130 return BottomMapping::origin( coords );
133 template<
class CoordStorage >
134 static void phi_set (
const CoordStorage &coords,
135 const LocalCoordinate &x,
136 const FieldType &factor,
137 GlobalCoordinate &p )
139 const FieldType xn = x[ dim-1 ];
140 const FieldType cxn = FieldType( 1 ) - xn;
141 BottomMapping::phi_set( coords, x, factor * cxn, p );
142 TopMapping::phi_add( coords, x, factor * xn, p );
145 template<
class CoordStorage >
146 static void phi_add (
const CoordStorage &coords,
147 const LocalCoordinate &x,
148 const FieldType &factor,
149 GlobalCoordinate &p )
151 const FieldType xn = x[ dim-1 ];
152 const FieldType cxn = FieldType( 1 ) - xn;
153 BottomMapping::phi_add( coords, x, factor * cxn, p );
154 TopMapping::phi_add( coords, x, factor * xn, p );
157 template<
class CoordStorage >
158 static bool Dphi_set (
const CoordStorage &coords,
159 const LocalCoordinate &x,
160 const FieldType &factor,
161 JacobianTransposedType &J )
163 const FieldType xn = x[ dim-1 ];
164 bool isAffine =
true;
167 const FieldType cxn = FieldType( 1 ) - xn;
168 BottomMapping::Dphi_set( coords, x, factor * cxn, J );
169 TopMapping::Dphi_add( coords, x, factor * xn, J );
173 JacobianTransposedType Jtop;
174 isAffine &= BottomMapping::Dphi_set( coords, x, factor, J );
175 isAffine &= TopMapping::Dphi_set( coords, x, factor, Jtop );
177 FieldType norm = FieldType( 0 );
178 for(
unsigned int i = 0; i < dim-1; ++i )
181 norm += Jtop[ i ].two_norm2();
182 J[ i ].axpy( xn, Jtop[ i ] );
184 isAffine &= (norm < 1e-12);
186 BottomMapping::phi_set( coords, x, -factor, J[ dim-1 ] );
187 TopMapping::phi_add( coords, x, factor, J[ dim-1 ] );
191 template<
class CoordStorage >
192 static bool Dphi_add (
const CoordStorage &coords,
193 const LocalCoordinate &x,
194 const FieldType &factor,
195 JacobianTransposedType &J )
197 const FieldType xn = x[ dim-1 ];
198 bool isAffine =
true;
201 const FieldType cxn = FieldType( 1 ) - xn;
202 BottomMapping::Dphi_add( coords, x, factor * cxn, J );
203 TopMapping::Dphi_add( coords, x, factor * xn, J );
207 JacobianTransposedType Jbottom, Jtop;
208 isAffine &= BottomMapping::Dphi_set( coords, x, FieldType( 1 ), Jbottom );
209 isAffine &= TopMapping::Dphi_set( coords, x, FieldType( 1 ), Jtop );
211 FieldType norm = FieldType( 0 );
212 for(
unsigned int i = 0; i < dim-1; ++i )
214 Jtop[ i ] -= Jbottom[ i ];
215 norm += Jtop[ i ].two_norm2();
216 J[ i ].axpy( factor, Jbottom[ i ] );
217 J[ i ].axpy( factor*xn, Jtop[ i ] );
219 isAffine &= (norm < 1e-12);
221 BottomMapping::phi_add( coords, x, -factor, J[ dim-1 ] );
222 TopMapping::phi_add( coords, x, factor, J[ dim-1 ] );
228 template<
class BaseTopology,
class Traits,
bool affine,
unsigned int offset >
229 class GenericCornerMapping < Pyramid< BaseTopology >, Traits, affine, offset >
231 typedef Pyramid< BaseTopology > Topology;
233 typedef GenericCornerMapping< BaseTopology, Traits, affine, offset >
235 typedef GenericCornerMapping
236 < Point, Traits, affine, offset + BaseTopology::numCorners >
240 static const unsigned int dim = Topology::dimension;
241 static const unsigned int dimW = Traits::dimWorld;
243 typedef typename Traits::FieldType FieldType;
244 typedef typename Traits::LocalCoordinate LocalCoordinate;
245 typedef typename Traits::GlobalCoordinate GlobalCoordinate;
246 typedef typename Traits::JacobianTransposedType JacobianTransposedType;
248 static const bool alwaysAffine = (BottomMapping::alwaysAffine || affine);
250 template<
class CoordStorage >
251 static const GlobalCoordinate &origin (
const CoordStorage &coords )
253 return BottomMapping::origin( coords );
256 template<
class CoordStorage >
257 static void phi_set (
const CoordStorage &coords,
258 const LocalCoordinate &x,
259 const FieldType &factor,
260 GlobalCoordinate &p )
262 const FieldType xn = x[ dim-1 ];
265 const GlobalCoordinate &top = TopMapping::origin( coords );
266 const GlobalCoordinate &bottom = BottomMapping::origin( coords );
268 BottomMapping::phi_set( coords, x, factor, p );
269 for(
unsigned int i = 0; i < dimW; ++i )
270 p[ i ] += (factor * xn) * (top[ i ] - bottom[ i ]);
274 TopMapping::phi_set( coords, x, factor * xn, p );
275 const FieldType cxn = FieldType( 1 ) - xn;
278 const FieldType icxn = FieldType( 1 ) / cxn;
280 for(
unsigned int i = 0; i < dim-1; ++i )
281 xb[ i ] = icxn * x[ i ];
283 BottomMapping::phi_add( coords, xb, factor * cxn, p );
288 template<
class CoordStorage >
289 static void phi_add (
const CoordStorage &coords,
290 const LocalCoordinate &x,
291 const FieldType &factor,
292 GlobalCoordinate &p )
294 const FieldType xn = x[ dim-1 ];
297 const GlobalCoordinate &top = TopMapping::origin( coords );
298 const GlobalCoordinate &bottom = BottomMapping::origin( coords );
300 BottomMapping::phi_add( coords, x, factor, p );
301 for(
unsigned int i = 0; i < dimW; ++i )
302 p[ i ] += (factor * xn) * (top[ i ] - bottom[ i ]);
306 TopMapping::phi_add( coords, x, factor * xn, p );
307 const FieldType cxn = FieldType( 1 ) - xn;
310 const FieldType icxn = FieldType( 1 ) / cxn;
312 for(
unsigned int i = 0; i < dim-1; ++i )
313 xb[ i ] = icxn * x[ i ];
315 BottomMapping::phi_add( coords, xb, factor * cxn, p );
320 template<
class CoordStorage >
321 static bool Dphi_set (
const CoordStorage &coords,
322 const LocalCoordinate &x,
323 const FieldType &factor,
324 JacobianTransposedType &J )
326 GlobalCoordinate &q = J[ dim-1 ];
330 const GlobalCoordinate &top = TopMapping::origin( coords );
331 const GlobalCoordinate &bottom = BottomMapping::origin( coords );
333 isAffine = BottomMapping::Dphi_set( coords, x, factor, J );
334 for(
unsigned int i = 0; i < dimW; ++i )
335 q[ i ] = factor * (top[ i ] - bottom[ i ]);
339 const FieldType xn = x[ dim-1 ];
340 const FieldType cxn = FieldType( 1 ) - xn;
341 const FieldType icxn = FieldType( 1 ) / cxn;
343 for(
unsigned int i = 0; i < dim-1; ++i )
344 xb[ i ] = icxn * x[ i ];
345 isAffine = BottomMapping::Dphi_set( coords, xb, factor, J );
347 TopMapping::phi_set( coords, x, factor, q );
348 BottomMapping::phi_add( coords, xb, -factor, q );
350 for(
unsigned int j = 0; j < dim-1; ++j )
352 for(
unsigned int i = 0; i < dimW; ++i )
353 q[ i ] += J[ j ][ i ] * xb[ j ];
359 template<
class CoordStorage >
360 static bool Dphi_add (
const CoordStorage &coords,
361 const LocalCoordinate &x,
362 const FieldType &factor,
363 JacobianTransposedType &J )
365 GlobalCoordinate &q = J[ dim-1 ];
369 const GlobalCoordinate &top = TopMapping::origin( coords );
370 const GlobalCoordinate &bottom = BottomMapping::origin( coords );
372 isAffine = BottomMapping::Dphi_add( coords, x, factor, J );
373 for(
unsigned int i = 0; i < dimW; ++i )
374 q[ i ] += factor * (top[ i ] - bottom[ i ]);
378 const FieldType xn = x[ dim-1 ];
379 const FieldType cxn = FieldType( 1 ) - xn;
380 const FieldType icxn = FieldType( 1 ) / cxn;
382 for(
unsigned int i = 0; i < dim-1; ++i )
383 xb[ i ] = icxn * x[ i ];
384 isAffine = BottomMapping::Dphi_add( coords, xb, factor, J );
386 TopMapping::phi_add( coords, x, factor, q );
387 BottomMapping::phi_add( coords, xb, -factor, q );
389 for(
unsigned int j = 0; j < dim-1; ++j )
391 for(
unsigned int i = 0; i < dimW; ++i )
392 q[ i ] += J[ j ][ i ] * xb[ j ];
404 template<
class Mapping,
unsigned int codim >
405 class SubMappingCoords
407 typedef typename Mapping::GlobalCoordinate GlobalCoordinate;
408 typedef typename Mapping::ReferenceElement ReferenceElement;
410 static const unsigned int dimension = ReferenceElement::dimension;
412 const Mapping &mapping_;
413 const unsigned int i_;
416 SubMappingCoords (
const Mapping &mapping,
unsigned int i )
417 : mapping_( mapping ), i_( i )
420 const GlobalCoordinate &operator[] (
unsigned int j )
const
423 = ReferenceElement::template subNumbering< codim, dimension - codim >( i_, j );
424 return mapping_.corner( k );
437 template<
class CoordTraits,
class Topology,
unsigned int dimW >
440 typedef CoordStorage< CoordTraits, Topology, dimW > This;
443 static const unsigned int size = Topology::numCorners;
445 static const unsigned int dimWorld = dimW;
447 typedef typename CoordTraits::template Vector< dimWorld >::type GlobalCoordinate;
449 template<
class SubTopology >
452 typedef CoordStorage< CoordTraits, SubTopology, dimWorld > type;
455 template<
class CoordVector >
456 explicit CoordStorage (
const CoordVector &coords )
458 for(
unsigned int i = 0; i < size; ++i )
459 coords_[ i ] = coords[ i ];
462 const GlobalCoordinate &operator[] (
unsigned int i )
const
468 GlobalCoordinate coords_[ size ];
480 template<
class CoordTraits,
class Topology,
unsigned int dimW >
481 class CoordPointerStorage
483 typedef CoordPointerStorage< CoordTraits, Topology, dimW > This;
486 static const unsigned int size = Topology::numCorners;
488 static const unsigned int dimWorld = dimW;
490 typedef typename CoordTraits::template Vector< dimWorld >::type GlobalCoordinate;
492 template<
class SubTopology >
495 typedef CoordPointerStorage< CoordTraits, SubTopology, dimWorld > type;
498 template<
class CoordVector >
499 explicit CoordPointerStorage (
const CoordVector &coords )
501 for(
unsigned int i = 0; i < size; ++i )
502 coords_[ i ] = &(coords[ i ]);
505 const GlobalCoordinate &operator[] (
unsigned int i )
const
507 return *(coords_[ i ]);
511 const GlobalCoordinate *coords_[ size ];
524 template<
class CoordTraits,
class Topo,
unsigned int dimW,
525 class CStorage = CoordStorage< CoordTraits, Topo, dimW >,
526 bool affine =
false >
532 typedef Topo Topology;
533 typedef CStorage CornerStorage;
536 static const unsigned int dimension = Traits::dimension;
537 static const unsigned int dimWorld = Traits::dimWorld;
539 typedef typename Traits::FieldType FieldType;
540 typedef typename Traits::LocalCoordinate LocalCoordinate;
541 typedef typename Traits::GlobalCoordinate GlobalCoordinate;
542 typedef typename Traits::JacobianType JacobianType;
543 typedef typename Traits::JacobianTransposedType JacobianTransposedType;
545 typedef GenericGeometry::ReferenceElement< Topology, FieldType > ReferenceElement;
547 template<
unsigned int codim,
unsigned int i >
550 typedef typename GenericGeometry::SubTopology< Topo, codim, i >::type Topology;
551 typedef typename CStorage::template SubStorage< Topology >::type CornerStorage;
556 typedef GenericGeometry::GenericCornerMapping< Topology, Traits, affine > GenericMapping;
559 static const bool alwaysAffine = GenericMapping::alwaysAffine;
561 template<
class CoordVector >
566 const GlobalCoordinate &corner (
int i )
const
571 void global (
const LocalCoordinate &x, GlobalCoordinate &y )
const
573 GenericMapping::phi_set( coords_, x, FieldType( 1 ), y );
576 bool jacobianTransposed (
const LocalCoordinate &x,
577 JacobianTransposedType &JT )
const
579 return GenericMapping::Dphi_set( coords_, x, FieldType( 1 ), JT );
582 template<
unsigned int codim,
unsigned int i >
586 typedef SubMappingCoords< This, codim > CoordVector;
587 return Trace( CoordVector( *
this, i ) );
591 CornerStorage coords_;
implementation of GenericGeometry::Mapping for first order lagrange type reference mappings.
Definition: cornermapping.hh:528
Implements some reference element functionality needed by the generic geometries.
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79
Dune namespace.
Definition: alignment.hh:14
Default mapping traits using Dune::FieldVector and Dune::FieldMatrix.
Definition: geometrytraits.hh:53
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18