DUNE-FEM (unstable)

code.hh
1#ifndef DUNE_FEM_DOFMAPPER_CODE_HH
2#define DUNE_FEM_DOFMAPPER_CODE_HH
3
4#include <algorithm>
5#include <cassert>
6#include <iostream>
7
8namespace Dune
9{
10
11 namespace Fem
12 {
13
14 // DofMapperCode
15 // -------------
16
17 class DofMapperCode
18 {
19 protected:
20 typedef const unsigned int *ConstIterator;
21 typedef unsigned int *Iterator;
22
23 DofMapperCode ( unsigned int numBlocks, unsigned int numDofs )
24 {
25 code_ = new unsigned int[ size( numBlocks, numDofs ) ];
26 code_[ 0 ] = numBlocks;
27 code_[ 1 ] = numDofs;
28 }
29
30 public:
31 DofMapperCode ()
32 {
33 code_ = new unsigned int[ size( 0, 0 ) ];
34 code_[ 1 ] = code_[ 0 ] = 0;
35 }
36
37 DofMapperCode ( const DofMapperCode &other )
38 {
39 code_ = new unsigned int[ other.size() ];
40 std::copy( ConstIterator( other.code_ ), other.end(), code_ );
41 }
42
43 ~DofMapperCode ()
44 {
45 delete[] code_;
46 }
47
48 const DofMapperCode &operator= ( const DofMapperCode &other )
49 {
50 if( size() != other.size() )
51 {
52 delete[] code_;
53 code_ = new unsigned int[ other.size() ];
54 }
55 std::copy( ConstIterator( other.code_ ), other.end(), code_ );
56 return *this;
57 }
58
78 template< class Functor >
79 void operator() ( Functor f ) const
80 {
81 for( ConstIterator it = begin(); it != end(); )
82 {
83 const unsigned int gtIndex = *(it++);
84 const unsigned int subEntity = *(it++);
85 unsigned int nDofs = *(it++);
86 f( gtIndex, subEntity, ConstIterator( it ), ConstIterator( it + nDofs ) );
87 it += nDofs;
88 }
89 }
90
91 unsigned int numBlocks () const { return code_[ 0 ]; }
92 unsigned int numDofs () const { return code_[ 1 ]; }
93
94 friend std::ostream &operator<< ( std::ostream &out, const DofMapperCode &code )
95 {
96 out << "{ " << code.numBlocks() << ", " << code.numDofs();
97 for( DofMapperCode::ConstIterator it = code.begin(); it != code.end(); ++it )
98 out << ", " << *it;
99 return out << " }";
100 }
101
102 protected:
103 ConstIterator begin () const { return code_ + 2; }
104 Iterator begin () { return code_ + 2; }
105 ConstIterator end () const { return code_ + size(); }
106 Iterator end () { return code_ + size(); }
107
108 std::size_t size () const { return size( numBlocks(), numDofs() ); }
109
116 static std::size_t size ( unsigned int numBlocks, unsigned int numDofs )
117 {
118 return 2 + 3*numBlocks + numDofs;
119 }
120
121 // Format of the code_ array:
122 //
123 // code_[0]: number of subentities with DoFs
124 // code_[1]: total number of DoFs
125 //
126 // For all k = 0 ... (numBlocks-1)
127 // (NB: k corresponds to a subentity with DoFs)
128 // It follows a variable size block (offset_0 := 2):
129 //
130 // code_[offset_k + 0]: global geometry type index of the subentity
131 // (this also encodes the codim)
132 // code_[offset_k + 1]: local number i_k of subentity (0 <= i_k < refElem.size( codim ))
133 // code_[offset_k + 2]: #DoFs n_k attached to this subentity
134 //
135 // code_[offset_k + 3 + j]:
136 // for 0 <= j < n_k, the local index of the given DoF, where "local" now
137 // means the number of the corresponding local basis function of the bulk
138 // element, i.e., not the numbering inside the entity.
139 //
140 // offset_(k+1) := (offset_k + 3 + n_k) is then just the start of the
141 // next block.
142 unsigned int *code_;
143 };
144
145
146
147 // DofMapperCodeWriter
148 // -------------------
149
150 class DofMapperCodeWriter
151 : public DofMapperCode
152 {
153 public:
154 DofMapperCodeWriter ( unsigned int numBlocks, unsigned int numDofs )
155 : DofMapperCode( numBlocks, numDofs )
156 {}
157
158 const unsigned int &operator[] ( unsigned int i ) const
159 {
160 assert( (std::ptrdiff_t)i < end() - begin() );
161 return begin()[ i ];
162 }
163
164 unsigned int &operator[] ( unsigned int i )
165 {
166 assert( (std::ptrdiff_t)i < end() - begin() );
167 return begin()[ i ];
168 }
169 };
170
171 } // namespace Fem
172
173} // namespace Dune
174
175#endif // #ifndef DUNE_FEM_DOFMAPPER_CODE_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 (Jul 27, 22:29, 2024)