Dune Core Modules (2.4.1)

interval.hh
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
10
11#include <dune/grid/io/file/dgfparser/blocks/basic.hh>
12
13
14namespace Dune
15{
16
17 namespace dgf
18 {
19
20 struct IntervalBlock
21 : public BasicBlock
22 {
23 struct Interval
24 {
25 array< std::vector< double >, 2 > p; // lower and upper boundary points
26 std::vector< double > h; // width of the cells in each direction
27 std::vector< int > n; // number of cells in each direction
28 };
29
30 private:
31 std::vector< Interval > intervals_;
32 bool good_; //data read correctly
33 int dimw_; //dimension of world
34
35 public:
36 explicit IntervalBlock ( std::istream &in );
37
38 void get ( std::vector< std::vector< double > > &vtx, int &nofvtx,
39 std::vector< std::vector< unsigned int > > &simplex, int &nofsimpl )
40 {
41 for( size_t i = 0; i < intervals_.size(); ++i )
42 {
43 int oldvtx = nofvtx;
44 nofvtx += getVtx( i, vtx );
45 nofsimpl += getHexa( i, simplex, oldvtx );
46 }
47 }
48
49 void get ( std::vector< std::vector< double > > &vtx, int &nofvtx )
50 {
51 for( size_t i = 0; i < intervals_.size(); ++i )
52 nofvtx += getVtx( i, vtx );
53 }
54
55 const Interval &get ( int block ) const
56 {
57 return intervals_[ block ];
58 }
59
60 int numIntervals () const
61 {
62 return intervals_.size();
63 }
64
65 int dimw () const
66 {
67 return dimw_;
68 }
69
70 int getVtx ( int block, std::vector< std::vector< double > > &vtx ) const;
71 int getHexa ( int block, std::vector< std::vector< unsigned int > > &cubes,
72 int offset = 0 ) const;
73
74 int nofvtx ( int block ) const
75 {
76 const Interval &interval = get( block );
77 int n = 1;
78 for( int i = 0; i < dimw_; ++i )
79 n *= (interval.n[ i ] + 1);
80 return n;
81 }
82
83 int nofhexa ( int block ) const
84 {
85 const Interval &interval = get( block );
86 int n = 1;
87 for( int i = 0; i < dimw_; ++i )
88 n *= interval.n[ i ];
89 return n;
90 }
91
92 private:
93 template< class T >
94 void parseLine ( std::vector< T > &v );
95
96 bool next ();
97 };
98
99 inline std::ostream &
100 operator<< ( std::ostream &out, const IntervalBlock::Interval &interval )
101 {
102 if( interval.p[ 0 ].empty() || interval.p[ 1 ].empty() || interval.n.empty() )
103 return out << "Interval {}";
104
105 out << "Interval { p0 = (" << interval.p[ 0 ][ 0 ];
106 for( size_t i = 1; i < interval.p[ 0 ].size(); ++i )
107 out << ", " << interval.p[ 0 ][ i ];
108 out << "), p1 = (" << interval.p[ 1 ][ 0 ];
109 for( size_t i = 1; i < interval.p[ 1 ].size(); ++i )
110 out << ", " << interval.p[ 1 ][ i ];
111 out << "), n = (" << interval.n[ 0 ];
112 for( size_t i = 1; i < interval.n.size(); ++i )
113 out << ", " << interval.n[ i ];
114 return out << ") }";
115 }
116
117 } // end namespace dgf
118
119} // end namespace Dune
120
121#endif
Fallback implementation of the std::array class (a static array)
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:26
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)