dune-grid  2.2.1
albertagrid/transformation.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALBERTA_TRANSFORMATION_HH
2 #define DUNE_ALBERTA_TRANSFORMATION_HH
3 
4 #include <dune/common/fvector.hh>
5 
7 
8 #if HAVE_ALBERTA
9 
10 namespace Dune
11 {
12 
14  {
16 
17  public:
19 
20  static const int dimension = Alberta::dimWorld;
21 
22  typedef FieldVector< ctype, dimension > WorldVector;
23 
24  explicit
26  : matrix_( (trafo != NULL ? trafo->M : GlobalSpace::identityMatrix()) ),
27  shift_( (trafo != NULL ? trafo->t : GlobalSpace::nullVector()) )
28  {}
29 
31  const GlobalSpace::Vector &shift )
32  : matrix_( matrix ),
33  shift_( shift )
34  {}
35 
36  WorldVector evaluate ( const WorldVector &x ) const
37  {
38  WorldVector y;
39  for( int i = 0; i < dimension; ++i )
40  {
41  const GlobalSpace::Vector &row = matrix_[ i ];
42  y[ i ] = shift_[ i ];
43  for( int j = 0; j < dimension; ++j )
44  y[ i ] += row[ j ] * x[ j ];
45  }
46  return y;
47  }
48 
50  {
51  // Note: ALBERTA requires the matrix to be orthogonal
52  WorldVector x( ctype( 0 ) );
53  for( int i = 0; i < dimension; ++i )
54  {
55  const GlobalSpace::Vector &row = matrix_[ i ];
56  const ctype v = y[ i ] - shift_[ i ];
57  for( int j = 0; j < dimension; ++j )
58  x[ j ] += row[ j ] * v;
59  }
60  return x;
61  }
62 
63  private:
64  const GlobalSpace::Matrix &matrix_;
65  const GlobalSpace::Vector &shift_;
66  };
67 
68 }
69 
70 #endif // #if HAVE_ALBERTA
71 
72 #endif // #ifndef DUNE_ALBERTA_TRANSFORMATION_HH