dune-grid  2.2.0
periodicfacetrans.hh
Go to the documentation of this file.
00001 #ifndef DUNE_DGF_PERIODICFACETRANSBLOCK_HH
00002 #define DUNE_DGF_PERIODICFACETRANSBLOCK_HH
00003 
00004 #include <iostream>
00005 #include <vector>
00006 
00007 #include <dune/grid/io/file/dgfparser/blocks/basic.hh>
00008 
00009 
00010 namespace Dune
00011 {    
00012 
00013   namespace dgf    
00014   {
00015 
00016     // PeriodicFaceTransformationBlock
00017     // -------------------------------
00018 
00019     struct PeriodicFaceTransformationBlock
00020     : public BasicBlock
00021     {
00022       template< class T >
00023       class Matrix;
00024 
00025       struct AffineTransformation;
00026 
00027     private:
00028       std::vector< AffineTransformation > transformations_;
00029 
00030       // copy not implemented
00031       PeriodicFaceTransformationBlock ( const PeriodicFaceTransformationBlock & );
00032 
00033     public:
00034       // initialize block and get dimension of world
00035       PeriodicFaceTransformationBlock ( std::istream &in, int dimworld );
00036 
00037       const AffineTransformation &transformation ( int i ) const
00038       {
00039         assert( i < numTransformations() );
00040         return transformations_[ i ];
00041       }
00042 
00043       int numTransformations () const
00044       {
00045         return transformations_.size();
00046       }
00047 
00048     private:
00049       void match ( char what );
00050     };
00051 
00052 
00053     // PeriodicFaceTransformationBlock::Matrix
00054     // ---------------------------------------
00055 
00056     template< class T >
00057     class PeriodicFaceTransformationBlock::Matrix
00058     {
00059       int rows_;
00060       int cols_;
00061       std::vector< T > fields_;
00062 
00063     public:
00064       Matrix ( int rows, int cols )
00065       : rows_( rows ),
00066         cols_( cols ),
00067         fields_( rows * cols )
00068       {}
00069 
00070       const T &operator() ( int i, int j ) const
00071       {
00072         return fields_[ i * cols_ + j ];
00073       }
00074 
00075       T &operator() ( int i, int j )
00076       {
00077         return fields_[ i * cols_ + j ];
00078       }
00079 
00080       int rows () const
00081       {
00082         return rows_;
00083       }
00084 
00085       int cols () const
00086       {
00087         return cols_;
00088       }
00089     };
00090 
00091 
00092     // PeriodicFaceTransformationBlock::AffineTransformation
00093     // -----------------------------------------------------
00094 
00095     struct PeriodicFaceTransformationBlock::AffineTransformation
00096     {
00097       Matrix< double > matrix;
00098       std::vector< double > shift;
00099 
00100       explicit AffineTransformation ( int dimworld )
00101       : matrix( dimworld, dimworld ),
00102         shift( dimworld )
00103       {}
00104     };
00105 
00106 
00107     inline std::ostream &
00108     operator<< ( std::ostream &out, const PeriodicFaceTransformationBlock::AffineTransformation &trafo )
00109     {
00110       for( int i = 0; i < trafo.matrix.rows(); ++i )
00111       {
00112         out << (i > 0 ? ", " : "");
00113         for( int j = 0; j < trafo.matrix.cols(); ++j )
00114           out << (j > 0 ? " " : "") << trafo.matrix( i, j );
00115       }
00116       out << " +";
00117       for( unsigned int i = 0; i < trafo.shift.size(); ++i )
00118         out << " " << trafo.shift[ i ];
00119       return out;
00120     }
00121     
00122   } // end namespace dgf
00123 
00124 } // end namespace Dune
00125 
00126 #endif