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