dune-grid  2.2.1
interval.hh
Go to the documentation of this file.
1 #ifndef DUNE_DGF_INTERVALBLOCK_HH
2 #define DUNE_DGF_INTERVALBLOCK_HH
3 
4 #include <iostream>
5 #include <vector>
6 
8 
9 
10 namespace Dune
11 {
12 
13  namespace dgf
14  {
15 
17  : public BasicBlock
18  {
19  struct Interval
20  {
21  std::vector< double > p[ 2 ]; // lower and upper boundary points
22  std::vector< double > h; // width of the cells in each direction
23  std::vector< int > n; // number of cells in each direction
24  };
25 
26  private:
27  std::vector< Interval > intervals_;
28  bool good_; //data read correctly
29  int dimw_; //dimension of world
30 
31  public:
32  explicit IntervalBlock ( std::istream &in );
33 
34  void get ( std::vector< std::vector< double > > &vtx, int &nofvtx,
35  std::vector< std::vector< unsigned int > > &simplex, int &nofsimpl )
36  {
37  for( size_t i = 0; i < intervals_.size(); ++i )
38  {
39  int oldvtx = nofvtx;
40  nofvtx += getVtx( i, vtx );
41  nofsimpl += getHexa( i, simplex, oldvtx );
42  }
43  }
44 
45  void get ( std::vector< std::vector< double > > &vtx, int &nofvtx )
46  {
47  for( size_t i = 0; i < intervals_.size(); ++i )
48  nofvtx += getVtx( i, vtx );
49  }
50 
51  const Interval &get ( int block ) const
52  {
53  return intervals_[ block ];
54  }
55 
56  int numIntervals () const
57  {
58  return intervals_.size();
59  }
60 
61  int dimw () const
62  {
63  return dimw_;
64  }
65 
66  int getVtx ( int block, std::vector< std::vector< double > > &vtx ) const;
67  int getHexa ( int block, std::vector< std::vector< unsigned int > > &cubes,
68  int offset = 0 ) const;
69 
70  int nofvtx ( int block ) const
71  {
72  const Interval &interval = get( block );
73  int n = 1;
74  for( int i = 0; i < dimw_; ++i )
75  n *= (interval.n[ i ] + 1);
76  return n;
77  }
78 
79  int nofhexa ( int block ) const
80  {
81  const Interval &interval = get( block );
82  int n = 1;
83  for( int i = 0; i < dimw_; ++i )
84  n *= interval.n[ i ];
85  return n;
86  }
87 
88  private:
89  template< class T >
90  void parseLine ( std::vector< T > &v );
91 
92  bool next ();
93  };
94 
95  inline std::ostream &
96  operator<< ( std::ostream &out, const IntervalBlock::Interval &interval )
97  {
98  if( interval.p[ 0 ].empty() || interval.p[ 1 ].empty() || interval.n.empty() )
99  return out << "Interval {}";
100 
101  out << "Interval { p0 = (" << interval.p[ 0 ][ 0 ];
102  for( size_t i = 1; i < interval.p[ 0 ].size(); ++i )
103  out << ", " << interval.p[ 0 ][ i ];
104  out << "), p1 = (" << interval.p[ 1 ][ 0 ];
105  for( size_t i = 1; i < interval.p[ 1 ].size(); ++i )
106  out << ", " << interval.p[ 1 ][ i ];
107  out << "), n = (" << interval.n[ 0 ];
108  for( size_t i = 1; i < interval.n.size(); ++i )
109  out << ", " << interval.n[ i ];
110  return out << ") }";
111  }
112 
113  } // end namespace dgf
114 
115 } // end namespace Dune
116 
117 #endif