mapping.hh
00001 #ifndef DUNE_GENERICGEOMETRY_MAPPING_HH
00002 #define DUNE_GENERICGEOMETRY_MAPPING_HH
00003
00004 #include <dune/grid/genericgeometry/misc.hh>
00005 #include <dune/grid/genericgeometry/topologytypes.hh>
00006 #include <dune/grid/genericgeometry/referenceelements.hh>
00007 #include <dune/grid/genericgeometry/matrix.hh>
00008 #include <dune/grid/genericgeometry/hybridmapping.hh>
00009
00010 namespace Dune
00011 {
00012
00013 namespace GenericGeometry
00014 {
00015
00016
00017
00018
00028 template< class CoordTraits, class Topo, int dimW, class Impl >
00029 class Mapping
00030 {
00031 typedef Mapping< CoordTraits, Topo, dimW, Impl > This;
00032
00033 typedef Impl Implementation;
00034
00035 public:
00036 typedef Topo Topology;
00037 typedef MappingTraits< CoordTraits, Topology :: dimension, dimW > Traits;
00038
00039 static const unsigned int dimension = Traits :: dimension;
00040 static const unsigned int dimWorld = Traits :: dimWorld;
00041
00042 typedef typename Traits :: FieldType FieldType;
00043 typedef typename Traits :: LocalCoordType LocalCoordType;
00044 typedef typename Traits :: GlobalCoordType GlobalCoordType;
00045 typedef typename Traits :: JacobianType JacobianType;
00046 typedef typename Traits :: JacobianTransposedType JacobianTransposedType;
00047
00048 typedef typename Traits :: MatrixHelper MatrixHelper;
00049
00050 typedef GenericGeometry :: ReferenceElement< Topology, FieldType > ReferenceElement;
00051
00052 template< unsigned int codim, unsigned int i >
00053 struct SubTopology
00054 {
00055 typedef typename GenericGeometry :: SubTopology< Topo, codim, i > :: type Topology;
00056 typedef typename Implementation :: template SubTopology< codim, i > :: Trace TraceImpl;
00057 typedef Mapping< CoordTraits, Topology, dimWorld, TraceImpl > Trace;
00058 };
00059
00060 static const bool alwaysAffine = Implementation :: alwaysAffine;
00061
00062 protected:
00063 Implementation impl_;
00064
00065 public:
00066 template< class CoordVector >
00067 explicit Mapping ( const CoordVector &coords )
00068 : impl_( coords )
00069 {}
00070
00071 Mapping ( const Implementation &implementation )
00072 : impl_( implementation )
00073 {}
00074
00075 const GlobalCoordType &corner ( int i ) const
00076 {
00077 return implementation().corner( i );
00078 }
00079
00080 void global ( const LocalCoordType &x, GlobalCoordType &y ) const
00081 {
00082 implementation().global( x, y );
00083 }
00084
00085 void local ( const GlobalCoordType &y, LocalCoordType &x ) const
00086 {
00087 x = ReferenceElement :: template baryCenter< 0 >( 0 );
00088 LocalCoordType dx;
00089 do
00090 {
00091 JacobianTransposedType JT;
00092 jacobianTransposed( x, JT );
00093 GlobalCoordType z;
00094 global( x, z );
00095 z -= y;
00096 MatrixHelper :: template xTRightInvA< dimension, dimWorld >( JT, z, dx );
00097 x -= dx;
00098 } while( dx.two_norm2() > 1e-12 );
00099 }
00100
00101 bool jacobianTransposed ( const LocalCoordType &x,
00102 JacobianTransposedType &JT ) const
00103 {
00104 return implementation().jacobianTransposed( x, JT );
00105 }
00106
00107 FieldType
00108 jacobianInverseTransposed ( const LocalCoordType &x, JacobianType &JTInv ) const
00109 {
00110 JacobianTransposedType JT;
00111 jacobianTransposed( x, JT );
00112 return MatrixHelper :: template rightInvA< dimension, dimWorld >( JT, JTInv );
00113 }
00114
00115 FieldType integrationElement ( const LocalCoordType &x ) const
00116 {
00117 JacobianTransposedType JT;
00118 jacobianTransposed( x, JT );
00119 return MatrixHelper :: template detAAT< dimension, dimWorld >( JT );
00120 }
00121
00122 const Implementation &implementation () const
00123 {
00124 return impl_;
00125 }
00126
00127 template< unsigned int codim, unsigned int i >
00128 typename SubTopology< codim, i > :: Trace trace () const
00129 {
00130 return impl_.template trace< codim, i >();
00131 }
00132 };
00133
00134 }
00135
00136 }
00137
00138 #endif