transformation.hh

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

Generated on Tue Jul 28 22:28:21 2009 for dune-grid by  doxygen 1.5.6