3#ifndef DUNE_GEOMETRY_GENERICGEOMETRY_CACHED_MAPPING_HH
4#define DUNE_GEOMETRY_GENERICGEOMETRY_CACHED_MAPPING_HH
7#include <dune/geometry/genericgeometry/topologytypes.hh>
9#include <dune/geometry/genericgeometry/matrixhelper.hh>
10#include <dune/geometry/genericgeometry/mapping.hh>
15 namespace GenericGeometry
21 template<
unsigned int,
class >
22 class CachedJacobianTransposed;
24 template<
unsigned int,
class >
25 class CachedJacobianInverseTransposed;
32 template<
unsigned int dim,
class GeometryTraits >
35 friend class CachedJacobianTransposed< dim, GeometryTraits >;
38 static const unsigned int dimension = dim;
39 static const unsigned int dimWorld = GeometryTraits::dimWorld;
41 typedef MappingTraits< typename GeometryTraits::CoordTraits, dimension, dimWorld > Traits;
43 typedef typename GeometryTraits::Caching Caching;
47 jacobianTransposedComputed( false ),
48 jacobianInverseTransposedComputed( false ),
49 integrationElementComputed( false )
52 typename Traits::JacobianTransposedType jacobianTransposed;
53 typename Traits::JacobianType jacobianInverseTransposed;
54 typename Traits::FieldType integrationElement;
58 bool jacobianTransposedComputed : 1;
59 bool jacobianInverseTransposedComputed : 1;
60 bool integrationElementComputed : 1;
68 template<
unsigned int dim,
class GeometryTraits >
69 class CachedJacobianTransposed
71 friend class CachedJacobianInverseTransposed< dim, GeometryTraits >;
73 typedef CachedStorage< dim, GeometryTraits > Storage;
74 typedef typename Storage::Traits Traits;
76 typedef typename Traits::MatrixHelper MatrixHelper;
79 typedef typename Traits::FieldType ctype;
81 static const int rows = Traits::dimension;
82 static const int cols = Traits::dimWorld;
84 typedef typename Traits::JacobianTransposedType FieldMatrix;
86 operator bool ()
const
88 return storage().jacobianTransposedComputed;
91 operator const FieldMatrix & ()
const
93 return storage().jacobianTransposed;
96 template<
class X,
class Y >
97 void mv (
const X &x, Y &y )
const
99 static_cast< const FieldMatrix &
>( *this ).mv( x, y );
102 template<
class X,
class Y >
103 void mtv (
const X &x, Y &y )
const
105 static_cast< const FieldMatrix &
>( *this ).mtv( x, y );
108 template<
class X,
class Y >
109 void umv (
const X &x, Y &y )
const
111 static_cast< const FieldMatrix &
>( *this ).umv( x, y );
114 template<
class X,
class Y >
115 void umtv (
const X &x, Y &y )
const
117 static_cast< const FieldMatrix &
>( *this ).umtv( x, y );
120 template<
class X,
class Y >
121 void mmv (
const X &x, Y &y )
const
123 static_cast< const FieldMatrix &
>( *this ).mmv( x, y );
126 template<
class X,
class Y >
127 void mmtv (
const X &x, Y &y )
const
129 static_cast< const FieldMatrix &
>( *this ).mmtv( x, y );
134 if( !storage().integrationElementComputed )
136 storage().integrationElement = MatrixHelper::template sqrtDetAAT< rows, cols >( storage().jacobianTransposed );
137 storage().integrationElementComputed = storage().affine;
139 return storage().integrationElement;
143 Storage &storage ()
const {
return storage_; }
145 mutable Storage storage_;
153 template<
unsigned int dim,
class GeometryTraits >
154 class CachedJacobianInverseTransposed
156 template<
class,
class >
friend class CachedMapping;
158 typedef CachedJacobianTransposed< dim, GeometryTraits > JacobianTransposed;
159 typedef typename JacobianTransposed::Storage Storage;
160 typedef typename JacobianTransposed::Traits Traits;
162 typedef typename Traits::MatrixHelper MatrixHelper;
165 typedef typename Traits::FieldType ctype;
167 static const int rows = Traits::dimWorld;
168 static const int cols = Traits::dimension;
170 typedef typename Traits::JacobianType FieldMatrix;
172 operator bool ()
const
174 return storage().jacobianInverseTransposedComputed;
177 operator const FieldMatrix & ()
const
179 return storage().jacobianInverseTransposed;
182 template<
class X,
class Y >
183 void mv (
const X &x, Y &y )
const
185 static_cast< const FieldMatrix &
>( *this ).mv( x, y );
188 template<
class X,
class Y >
189 void mtv (
const X &x, Y &y )
const
191 static_cast< const FieldMatrix &
>( *this ).mtv( x, y );
194 template<
class X,
class Y >
195 void umv (
const X &x, Y &y )
const
197 static_cast< const FieldMatrix &
>( *this ).umv( x, y );
200 template<
class X,
class Y >
201 void umtv (
const X &x, Y &y )
const
203 static_cast< const FieldMatrix &
>( *this ).umtv( x, y );
206 template<
class X,
class Y >
207 void mmv (
const X &x, Y &y )
const
209 static_cast< const FieldMatrix &
>( *this ).mmv( x, y );
212 template<
class X,
class Y >
213 void mmtv (
const X &x, Y &y )
const
215 static_cast< const FieldMatrix &
>( *this ).mmtv( x, y );
221 return ctype( 1 ) / storage().integrationElement;
225 JacobianTransposed &jacobianTransposed () {
return jacobianTransposed_; }
226 const JacobianTransposed &jacobianTransposed ()
const {
return jacobianTransposed_; }
228 Storage &storage ()
const {
return jacobianTransposed().storage(); }
230 JacobianTransposed jacobianTransposed_;
238 template<
class Topology,
class GeometryTraits >
241 typedef CachedMapping< Topology, GeometryTraits > This;
243 typedef typename GeometryTraits::template Mapping< Topology >::type MappingImpl;
246 typedef MappingTraits< typename GeometryTraits::CoordTraits, Topology::dimension, GeometryTraits::dimWorld > Traits;
248 typedef GenericGeometry::Mapping< typename GeometryTraits::CoordTraits, Topology, GeometryTraits::dimWorld, MappingImpl > Mapping;
250 static const unsigned int dimension = Traits::dimension;
251 static const unsigned int dimWorld = Traits::dimWorld;
253 typedef typename Traits::FieldType FieldType;
254 typedef typename Traits::LocalCoordinate LocalCoordinate;
255 typedef typename Traits::GlobalCoordinate GlobalCoordinate;
257 typedef CachedStorage< dimension, GeometryTraits > Storage;
258 typedef CachedJacobianTransposed< dimension, GeometryTraits > JacobianTransposed;
259 typedef CachedJacobianInverseTransposed< dimension, GeometryTraits > JacobianInverseTransposed;
261 typedef GenericGeometry::ReferenceElement< Topology, FieldType > ReferenceElement;
264 static const bool alwaysAffine = Mapping::alwaysAffine;
266 typedef typename GeometryTraits::Caching Caching;
269 typedef typename Traits::MatrixHelper MatrixHelper;
272 template<
class CoordVector >
273 explicit CachedMapping (
const CoordVector &coords )
277 storage().affine =
true;
279 computeJacobianTransposed( baryCenter() );
283 template<
class CoordVector >
284 explicit CachedMapping (
const std::pair< const CoordVector &, bool > &coords )
285 : mapping_( coords.first )
287 storage().affine = coords.second;
291 bool affine ()
const {
return (alwaysAffine || storage().affine); }
294 int numCorners ()
const {
return ReferenceElement::numCorners; }
295 GlobalCoordinate corner (
int i )
const {
return mapping().corner( i ); }
296 GlobalCoordinate center ()
const {
return global( ReferenceElement::baryCenter() ); }
300 GlobalCoordinate global (
const LocalCoordinate &x )
const
303 if( jacobianTransposed() )
306 jacobianTransposed().umtv( x, y );
311 mapping().global( x, y );
315 LocalCoordinate local (
const GlobalCoordinate &y )
const
318 if( jacobianInverseTransposed() )
320 GlobalCoordinate z = y - corner( 0 );
321 jacobianInverseTransposed().mtv( z, x );
326 const JacobianTransposed &JT = jacobianTransposed( baryCenter() );
327 GlobalCoordinate z = y - corner( 0 );
328 MatrixHelper::template xTRightInvA< dimension, dimWorld >( JT, z, x );
331 mapping().local( y, x );
335 FieldType integrationElement (
const LocalCoordinate &x )
const
337 const EvaluationType evaluateI = Caching::evaluateIntegrationElement;
338 const EvaluationType evaluateJ = Caching::evaluateJacobianInverseTransposed;
339 if( ((evaluateI == PreCompute) || (evaluateJ == PreCompute)) && alwaysAffine )
340 return storage().integrationElement;
342 return jacobianTransposed( x ).det();
345 FieldType volume ()
const
349 return refVolume * integrationElement( baryCenter() );
352 const JacobianTransposed &jacobianTransposed (
const LocalCoordinate &x )
const
354 const EvaluationType evaluate = Caching::evaluateJacobianTransposed;
355 if( (evaluate == PreCompute) && alwaysAffine )
356 return jacobianTransposed();
358 if( !jacobianTransposed() )
359 computeJacobianTransposed( x );
360 return jacobianTransposed();
363 const JacobianInverseTransposed &
364 jacobianInverseTransposed (
const LocalCoordinate &x )
const
366 const EvaluationType evaluate = Caching::evaluateJacobianInverseTransposed;
367 if( (evaluate == PreCompute) && alwaysAffine )
368 return jacobianInverseTransposed();
370 if( !jacobianInverseTransposed() )
371 computeJacobianInverseTransposed( x );
372 return jacobianInverseTransposed();
375 const Mapping &mapping ()
const {
return mapping_; }
378 static const LocalCoordinate &baryCenter ()
380 return ReferenceElement::baryCenter();
383 Storage &storage ()
const
385 return jacobianInverseTransposed().storage();
388 const JacobianTransposed &jacobianTransposed ()
const
390 return jacobianInverseTransposed().jacobianTransposed();
393 const JacobianInverseTransposed &jacobianInverseTransposed ()
const
395 return jacobianInverseTransposed_;
400 assert( affine() == mapping().jacobianTransposed( baryCenter(), storage().jacobianTransposed ) );
404 if( (Caching::evaluateJacobianTransposed == PreCompute) && !jacobianTransposed() )
405 computeJacobianTransposed( baryCenter() );
407 if( Caching::evaluateJacobianInverseTransposed == PreCompute )
408 computeJacobianInverseTransposed( baryCenter() );
409 else if( Caching::evaluateIntegrationElement == PreCompute )
410 jacobianTransposed().det();
413 void computeJacobianTransposed (
const LocalCoordinate &x )
const
415 storage().affine = mapping().jacobianTransposed( x, storage().jacobianTransposed );
416 storage().jacobianTransposedComputed = affine();
419 void computeJacobianInverseTransposed (
const LocalCoordinate &x )
const
421 storage().integrationElement
422 = MatrixHelper::template rightInvA< dimension, dimWorld >( jacobianTransposed( x ), storage().jacobianInverseTransposed );
423 storage().integrationElementComputed = affine();
424 storage().jacobianInverseTransposedComputed = affine();
429 JacobianInverseTransposed jacobianInverseTransposed_;
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
ctype volume() const
obtain the volume of the reference element
Definition: referenceelements.hh:280
bool checkInside(const FieldVector< ctype, dim > &local) const
check if a coordinate is in the reference element
Definition: referenceelements.hh:167
Implements some reference element functionality needed by the generic geometries.
Dune namespace.
Definition: alignment.hh:14
A unique label for each type of element that can occur in a grid.