Dune Core Modules (2.8.0)

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#include <array>
9
10#include <dune/grid/io/file/dgfparser/blocks/basic.hh>
11
12
13namespace Dune
14{
15
16 namespace dgf
17 {
18
19 struct IntervalBlock
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
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:461
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)