DUNE-FEM (unstable)

localdofstorage.hh
1#ifndef DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_LOCALDOFSTORAGE_HH
2#define DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_LOCALDOFSTORAGE_HH
3
4#include <cassert>
5#include <cstddef>
6
7#include <algorithm>
8#include <ostream>
9#include <vector>
10
11namespace Dune
12{
13
14 namespace Fem
15 {
16
17 namespace hpDG
18 {
19
20 // LocalDofStorage
21 // ---------------
22
23 template< class GlobalKey >
24 class LocalDofStorage
25 {
26 using ThisType = LocalDofStorage< GlobalKey >;
27
28 using container = std::vector< GlobalKey >;
29
30 public:
32 using value_type = GlobalKey;
33
35 using iterator = typename container::iterator;
37 using const_iterator = typename container::const_iterator;
38
44 LocalDofStorage () : size_( 0 ), new_size_( 0 ) {}
45
53 LocalDofStorage ( const ThisType & ) = default;
54
56 LocalDofStorage ( ThisType && ) = default;
57
59 ThisType &operator= ( const ThisType & ) = default;
60
62 ThisType &operator= ( ThisType && ) = default;
63
69 iterator begin () { return dofs_.begin(); }
70
72 const_iterator begin () const { return dofs_.cbegin(); }
73
75 iterator end () { return begin() + size(); }
76
78 const_iterator end () const { return begin() + size(); }
79
85 std::size_t size () const { return size_; }
86
94 template< class Function >
95 Function reserve ( std::size_t new_size, Function function )
96 {
97 // remember new size
98 new_size_ = new_size;
99
100 // enlarge dof vector if needed
101 const std::size_t old_size = dofs_.size();
102 if( old_size < new_size_ )
103 {
104 dofs_.resize( new_size );
105 for( std::size_t i = old_size; i < new_size; ++i )
106 dofs_[ i ] = function();
107 }
108
109 return std::move( function );
110 }
111
113 template< class Function >
114 Function resize ( Function function )
115 {
116 assert( new_size_ <= dofs_.size() );
117 size_ = new_size_;
118
119 const std::size_t holes = dofs_.size() - size_;
120 std::for_each( dofs_.rbegin(), dofs_.rbegin() + holes, function );
121
122 dofs_.resize( size_ );
123 // dofs_.shrink_to_fit();
124
125 return std::move( function );
126 }
127
135 GlobalKey &operator[] ( std::size_t n ) { return dofs_[ n ]; }
136
138 const GlobalKey &operator[] ( std::size_t n ) const { return dofs_[ n ]; }
139
142#ifndef DOXYGEN
143
144 friend std::ostream &operator<< ( std::ostream &ostream, const LocalDofStorage &storage )
145 {
146 const auto &dofs = storage.dofs_;
147 const std::size_t size = dofs.size();
148 for( std::size_t i = 0; i < size; ++i )
149 ostream << dofs[ i ] << " ";
150 ostream << "[" << storage.size_ << "; " << storage.new_size_ << "]";
151 return ostream;
152 }
153
154#endif // #ifndef DOXYGEN
155
156 private:
157 std::size_t size_, new_size_;
158 std::vector< GlobalKey > dofs_;
159 };
160
161 } // namespace hpDG
162
163 } // namespace Fem
164
165} // namespace Dune
166
167#endif // #ifndef DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_LOCALDOFSTORAGE_HH
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)