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