dune-grid 2.9.0
interval.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 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
13
14
15namespace Dune
16{
17
18 namespace dgf
19 {
20
22 : public BasicBlock
23 {
24 struct Interval
25 {
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
Include standard header files.
Definition: agrid.hh:60
std::ostream & operator<<(std::ostream &out, const IntervalBlock::Interval &interval)
Definition: interval.hh:123
Definition: basic.hh:31
Definition: interval.hh:23
IntervalBlock(std::istream &in)
Definition: interval.cc:18
void get(std::vector< std::vector< double > > &vtx, int &nofvtx, std::vector< std::vector< unsigned int > > &simplex, int &nofsimpl)
Definition: interval.hh:61
int numIntervals() const
Definition: interval.hh:83
int getVtx(int block, std::vector< std::vector< double > > &vtx) const
Definition: interval.cc:84
const Interval & get(int block) const
Definition: interval.hh:78
int getHexa(int block, std::vector< std::vector< unsigned int > > &cubes, int offset=0) const
Definition: interval.cc:122
int nofhexa(int block) const
Definition: interval.hh:106
int dimw() const
Definition: interval.hh:88
int nofvtx(int block) const
Definition: interval.hh:97
void get(std::vector< std::vector< double > > &vtx, int &nofvtx)
Definition: interval.hh:72
Definition: interval.hh:25
Interval()
Definition: interval.hh:26
std::array< std::vector< double >, 2 > p
Definition: interval.hh:47
std::vector< int > n
Definition: interval.hh:49
Interval(const Interval &interval, const std::vector< int > &map)
Definition: interval.hh:27
void copy(const Interval &interval, const std::vector< int > &map)
Definition: interval.hh:31
std::vector< double > h
Definition: interval.hh:48