dune-grid  2.2.0
interval.hh
Go to the documentation of this file.
00001 #ifndef DUNE_DGF_INTERVALBLOCK_HH
00002 #define DUNE_DGF_INTERVALBLOCK_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     struct IntervalBlock
00017     : public BasicBlock
00018     {
00019       struct Interval
00020       {
00021         std::vector< double > p[ 2 ]; // lower and upper boundary points
00022         std::vector< double > h;      // width of the cells in each direction
00023         std::vector< int > n;         // number of cells in each direction
00024       };
00025 
00026     private:
00027       std::vector< Interval > intervals_;
00028       bool good_;                      //data read correctly
00029       int dimw_;                       //dimension of world
00030 
00031     public:
00032       explicit IntervalBlock ( std::istream &in );
00033 
00034       void get ( std::vector< std::vector< double > > &vtx, int &nofvtx,
00035                  std::vector< std::vector< unsigned int > > &simplex, int &nofsimpl )
00036       {
00037         for( size_t i = 0; i < intervals_.size(); ++i )
00038         {
00039           int oldvtx = nofvtx;
00040           nofvtx += getVtx( i, vtx );
00041           nofsimpl += getHexa( i, simplex, oldvtx );
00042         }
00043       }
00044 
00045       void get ( std::vector< std::vector< double > > &vtx, int &nofvtx )
00046       {
00047         for( size_t i = 0; i < intervals_.size(); ++i )
00048           nofvtx += getVtx( i, vtx );
00049       }
00050 
00051       const Interval &get ( int block ) const
00052       {
00053         return intervals_[ block ];
00054       }
00055 
00056       int numIntervals () const
00057       {
00058         return intervals_.size();
00059       }
00060 
00061       int dimw () const
00062       {
00063         return dimw_;
00064       }
00065 
00066       int getVtx ( int block, std::vector< std::vector< double > > &vtx ) const;
00067       int getHexa ( int block, std::vector< std::vector< unsigned int > > &cubes,
00068                     int offset = 0 ) const;
00069 
00070       int nofvtx ( int block ) const
00071       {
00072         const Interval &interval = get( block );
00073         int n = 1;
00074         for( int i = 0; i < dimw_; ++i )
00075           n *= (interval.n[ i ] + 1);
00076         return n;
00077       }
00078 
00079       int nofhexa ( int block ) const
00080       {
00081         const Interval &interval = get( block );
00082         int n = 1;
00083         for( int i = 0; i < dimw_; ++i )
00084           n *= interval.n[ i ];
00085         return n;
00086       }
00087 
00088     private:
00089       template< class T >
00090       void parseLine ( std::vector< T > &v );
00091 
00092       bool next ();
00093     };
00094 
00095     inline std::ostream &
00096     operator<< ( std::ostream &out, const IntervalBlock::Interval &interval )
00097     {
00098       if( interval.p[ 0 ].empty() || interval.p[ 1 ].empty() || interval.n.empty() )
00099         return out << "Interval {}";
00100 
00101       out << "Interval { p0 = (" << interval.p[ 0 ][ 0 ];
00102       for( size_t i = 1; i < interval.p[ 0 ].size(); ++i )
00103         out << ", " << interval.p[ 0 ][ i ];
00104       out << "), p1 = (" << interval.p[ 1 ][ 0 ];
00105       for( size_t i = 1; i < interval.p[ 1 ].size(); ++i )
00106         out << ", " << interval.p[ 1 ][ i ];
00107       out << "), n = (" << interval.n[ 0 ];
00108       for( size_t i = 1; i < interval.n.size(); ++i )
00109         out << ", " << interval.n[ i ];
00110       return out << ") }";
00111     }
00112     
00113   } // end namespace dgf
00114   
00115 } // end namespace Dune
00116 
00117 #endif