dune-grid  2.2.1
periodicfacetrans.hh
Go to the documentation of this file.
1 #ifndef DUNE_DGF_PERIODICFACETRANSBLOCK_HH
2 #define DUNE_DGF_PERIODICFACETRANSBLOCK_HH
3 
4 #include <iostream>
5 #include <vector>
6 
8 
9 
10 namespace Dune
11 {
12 
13  namespace dgf
14  {
15 
16  // PeriodicFaceTransformationBlock
17  // -------------------------------
18 
20  : public BasicBlock
21  {
22  template< class T >
23  class Matrix;
24 
25  struct AffineTransformation;
26 
27  private:
28  std::vector< AffineTransformation > transformations_;
29 
30  // copy not implemented
32 
33  public:
34  // initialize block and get dimension of world
35  PeriodicFaceTransformationBlock ( std::istream &in, int dimworld );
36 
37  const AffineTransformation &transformation ( int i ) const
38  {
39  assert( i < numTransformations() );
40  return transformations_[ i ];
41  }
42 
43  int numTransformations () const
44  {
45  return transformations_.size();
46  }
47 
48  private:
49  void match ( char what );
50  };
51 
52 
53  // PeriodicFaceTransformationBlock::Matrix
54  // ---------------------------------------
55 
56  template< class T >
58  {
59  int rows_;
60  int cols_;
61  std::vector< T > fields_;
62 
63  public:
64  Matrix ( int rows, int cols )
65  : rows_( rows ),
66  cols_( cols ),
67  fields_( rows * cols )
68  {}
69 
70  const T &operator() ( int i, int j ) const
71  {
72  return fields_[ i * cols_ + j ];
73  }
74 
75  T &operator() ( int i, int j )
76  {
77  return fields_[ i * cols_ + j ];
78  }
79 
80  int rows () const
81  {
82  return rows_;
83  }
84 
85  int cols () const
86  {
87  return cols_;
88  }
89  };
90 
91 
92  // PeriodicFaceTransformationBlock::AffineTransformation
93  // -----------------------------------------------------
94 
96  {
98  std::vector< double > shift;
99 
100  explicit AffineTransformation ( int dimworld )
101  : matrix( dimworld, dimworld ),
102  shift( dimworld )
103  {}
104  };
105 
106 
107  inline std::ostream &
109  {
110  for( int i = 0; i < trafo.matrix.rows(); ++i )
111  {
112  out << (i > 0 ? ", " : "");
113  for( int j = 0; j < trafo.matrix.cols(); ++j )
114  out << (j > 0 ? " " : "") << trafo.matrix( i, j );
115  }
116  out << " +";
117  for( unsigned int i = 0; i < trafo.shift.size(); ++i )
118  out << " " << trafo.shift[ i ];
119  return out;
120  }
121 
122  } // end namespace dgf
123 
124 } // end namespace Dune
125 
126 #endif