DUNE PDELab (git)

interval.hh
1// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5#ifndef DUNE_DGF_INTERVALBLOCK_HH
6#define DUNE_DGF_INTERVALBLOCK_HH
7
8#include <iostream>
9#include <vector>
10#include <array>
11
12#include <dune/grid/io/file/dgfparser/blocks/basic.hh>
13
14
15namespace Dune
16{
17
18 namespace dgf
19 {
20
21 struct IntervalBlock
22 : public BasicBlock
23 {
24 struct Interval
25 {
26 Interval() {}
27 Interval( const Interval& interval, const std::vector<int>& map )
28 {
29 copy( interval, map );
30 }
31 void copy(const Interval& interval, const std::vector<int>& map )
32 {
33 const int size = map.size();
34 p[0].resize( size );
35 p[1].resize( size );
36 n.resize( size );
37 h.resize( size );
38 assert( size == int(interval.n.size()) );
39 for( int i=0; i<size; ++i )
40 {
41 p[ 0 ][ i ] = interval.p[ 0 ][ map[ i ] ];
42 p[ 1 ][ i ] = interval.p[ 1 ][ map[ i ] ];
43 n[ i ] = interval.n[ map[ i ] ];
44 h[ i ] = interval.h[ map[ i ] ];
45 }
46 }
47 std::array< std::vector< double >, 2 > p; // lower and upper boundary points
48 std::vector< double > h; // width of the cells in each direction
49 std::vector< int > n; // number of cells in each direction
50 };
51
52 private:
53 std::vector< Interval > intervals_;
54 std::vector< int > map_;
55 bool good_; //data read correctly
56 int dimw_; //dimension of world
57
58 public:
59 explicit IntervalBlock ( std::istream &in );
60
61 void get ( std::vector< std::vector< double > > &vtx, int &nofvtx,
62 std::vector< std::vector< unsigned int > > &simplex, int &nofsimpl )
63 {
64 for( size_t i = 0; i < intervals_.size(); ++i )
65 {
66 int oldvtx = nofvtx;
67 nofvtx += getVtx( i, vtx );
68 nofsimpl += getHexa( i, simplex, oldvtx );
69 }
70 }
71
72 void get ( std::vector< std::vector< double > > &vtx, int &nofvtx )
73 {
74 for( size_t i = 0; i < intervals_.size(); ++i )
75 nofvtx += getVtx( i, vtx );
76 }
77
78 const Interval &get ( int block ) const
79 {
80 return intervals_[ block ];
81 }
82
83 int numIntervals () const
84 {
85 return intervals_.size();
86 }
87
88 int dimw () const
89 {
90 return dimw_;
91 }
92
93 int getVtx ( int block, std::vector< std::vector< double > > &vtx ) const;
94 int getHexa ( int block, std::vector< std::vector< unsigned int > > &cubes,
95 int offset = 0 ) const;
96
97 int nofvtx ( int block ) const
98 {
99 const Interval &interval = get( block );
100 int n = 1;
101 for( int i = 0; i < dimw_; ++i )
102 n *= (interval.n[ i ] + 1);
103 return n;
104 }
105
106 int nofhexa ( int block ) const
107 {
108 const Interval &interval = get( block );
109 int n = 1;
110 for( int i = 0; i < dimw_; ++i )
111 n *= interval.n[ i ];
112 return n;
113 }
114
115 private:
116 template< class T >
117 void parseLine ( std::vector< T > &v );
118
119 bool next ();
120 };
121
122 inline std::ostream &
123 operator<< ( std::ostream &out, const IntervalBlock::Interval &interval )
124 {
125 if( interval.p[ 0 ].empty() || interval.p[ 1 ].empty() || interval.n.empty() )
126 return out << "Interval {}";
127
128 out << "Interval { p0 = (" << interval.p[ 0 ][ 0 ];
129 for( size_t i = 1; i < interval.p[ 0 ].size(); ++i )
130 out << ", " << interval.p[ 0 ][ i ];
131 out << "), p1 = (" << interval.p[ 1 ][ 0 ];
132 for( size_t i = 1; i < interval.p[ 1 ].size(); ++i )
133 out << ", " << interval.p[ 1 ][ i ];
134 out << "), n = (" << interval.n[ 0 ];
135 for( size_t i = 1; i < interval.n.size(); ++i )
136 out << ", " << interval.n[ i ];
137 return out << ") }";
138 }
139
140 } // end namespace dgf
141
142} // end namespace Dune
143
144#endif
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:453
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)