transformation.hh

00001 #ifndef DUNE_ALBERTA_TRANSFORMATION_HH
00002 #define DUNE_ALBERTA_TRANSFORMATION_HH
00003 
00004 #include <dune/common/fvector.hh>
00005 
00006 #include <dune/grid/albertagrid/misc.hh>
00007 
00008 #if HAVE_ALBERTA
00009 
00010 namespace Dune
00011 {
00012 
00013   class AlbertaTransformation
00014   {
00015   public:
00016     typedef Alberta::Real ctype;
00017 
00018     static const int dimension = Alberta::dimWorld;
00019 
00020     typedef FieldVector< ctype, dimension > WorldVector;
00021 
00022   private:
00023     typedef Alberta::GlobalSpace GlobalSpace;
00024 
00025     const GlobalSpace::Matrix &matrix_;
00026     const GlobalSpace::Vector &shift_;
00027 
00028   public:
00029     explicit
00030     AlbertaTransformation ( const Alberta::AffineTransformation *trafo = NULL )
00031     : matrix_( (trafo != NULL ? trafo->M : GlobalSpace::identityMatrix()) ),
00032       shift_( (trafo != NULL ? trafo->t : GlobalSpace::nullVector()) )
00033     {}
00034 
00035     AlbertaTransformation ( const GlobalSpace::Matrix &matrix,
00036                             const GlobalSpace::Vector &shift )
00037     : matrix_( matrix ),
00038       shift_( shift )
00039     {}
00040 
00041     WorldVector evaluate ( const WorldVector &x ) const
00042     {
00043       WorldVector y;
00044       for( int i = 0; i < dimension; ++i )
00045       {
00046         const GlobalSpace::Vector &row = matrix_[ i ];
00047         y[ i ] = shift_[ i ];
00048         for( int j = 0; j < dimension; ++j )
00049           y[ i ] += row[ j ] * x[ j ];
00050       }
00051       return y;
00052     }
00053 
00054     WorldVector evaluateInverse ( const WorldVector &y ) const
00055     {
00056       // Note: ALBERTA requires the matrix to be orthogonal
00057       WorldVector x( ctype( 0 ) );
00058       for( int i = 0; i < dimension; ++i )
00059       {
00060         const GlobalSpace::Vector &row = matrix_[ i ];
00061         const ctype v = y[ i ] - shift_[ i ];
00062         for( int j = 0; j < dimension; ++j )
00063           x[ j ] += row[ j ] * v;
00064       }
00065       return x;
00066     }
00067   };
00068 
00069 }
00070 
00071 #endif // #if HAVE_ALBERTA
00072 
00073 #endif

Generated on Sun Nov 15 22:28:44 2009 for dune-grid by  doxygen 1.5.6