Dune Core Modules (2.6.0)

basisevaluator.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_BASISEVALUATOR_HH
4#define DUNE_BASISEVALUATOR_HH
5
6#include <vector>
7
11
12#include <dune/geometry/type.hh>
13
14#include <dune/localfunctions/utility/field.hh>
15#include <dune/localfunctions/utility/multiindex.hh>
16#include <dune/localfunctions/utility/tensor.hh>
17
18namespace Dune
19{
20 /*******************************************
21 * Should be removed as soon as the Tensor
22 * classes have been revisited. See remarks
23 * in tensor.hh (also hold true here).
24 *******************************************/
25
26
27 template <class B>
28 struct MonomialEvaluator
29 {
30 typedef B Basis;
31 typedef typename Basis::Field Field;
32 typedef typename Basis::DomainVector DomainVector;
33 static const int dimension = Basis::dimension;
34 static const int dimRange = Basis::dimRange;
35
36 typedef std::vector<Field> Container;
37
38 template< class Deriv >
39 struct BaseIterator;
40
41 template <unsigned int deriv>
42 struct Iterator
43 {
44 typedef BaseIterator<Derivatives<Field,dimension,dimRange,deriv,derivative> > All;
45 typedef BaseIterator<Derivatives<Field,dimension,1,0,value> > Integrate;
46 };
47
48 unsigned int size() const
49 {
50 return size_;
51 }
52
53 protected:
54 MonomialEvaluator(const Basis &basis,unsigned int order,unsigned int size)
55 : basis_(basis),
56 order_(order),
57 size_(size),
58 container_(0)
59 {}
60 template <int deriv>
61 void resize()
62 {
63 const int totalSize = Derivatives<Field,dimension,dimRange,deriv,derivative>::size*size_;
64 container_.resize(totalSize);
65 }
66 MonomialEvaluator(const MonomialEvaluator&);
67 const Basis &basis_;
68 unsigned int order_,size_;
69 Container container_;
70 };
71
72
73 template< class B >
74 template< class Deriv >
75 struct MonomialEvaluator< B >::BaseIterator
76 {
77 typedef Deriv Derivatives;
78 typedef typename Deriv::Field Field;
79 static const unsigned int blockSize = Deriv::size;
81 static const DerivativeLayout layout = Deriv::layout;
82 static const unsigned int dimDomain = Deriv::dimDomain;
83 static const unsigned int dimRange = Deriv::dimRange;
84
85 typedef std::vector<Field> Container;
86 typedef typename Container::iterator CIter;
87
88 explicit BaseIterator ( Container &container )
89 : pos_( container.begin() ),
90 end_( container.end() )
91 {}
92
93 const Deriv &operator*() const
94 {
95 assert(!done());
96 return reinterpret_cast<const Deriv&>(*pos_);
97 }
98
99 const Deriv *operator->() const
100 {
101 return &(operator*());
102 }
103
104 bool done () const
105 {
106 return pos_ == end_;
107 }
108
109 BaseIterator &operator++ ()
110 {
111 pos_ += blockSize;
112 return *this;
113 }
114
115 BaseIterator &operator+= ( unsigned int skip )
116 {
117 pos_ += skip*blockSize;
118 return *this;
119 }
120
121 private:
122 CIter pos_;
123 const CIter end_;
124 };
125
126 template< class B >
127 struct StandardEvaluator
128 : public MonomialEvaluator< B >
129 {
130 typedef B Basis;
131 typedef typename Basis::Field Field;
132 typedef typename Basis::DomainVector DomainVector;
133 typedef std::vector<Field> Container;
134 static const int dimension = Basis::dimension;
135 static const int dimRange = Basis::dimRange;
136 typedef MonomialEvaluator<B> Base;
137
138 template <unsigned int deriv>
139 struct Iterator : public Base::template Iterator<deriv>
140 {};
141
142 StandardEvaluator(const Basis &basis)
143 : Base(basis,basis.order(),basis.size())
144 {}
145 template <unsigned int deriv,class DVector>
146 typename Iterator<deriv>::All evaluate(const DVector &x)
147 {
148 Base::template resize<deriv>();
149 basis_.template evaluate<deriv>(x,&(container_[0]));
150 return typename Iterator<deriv>::All(container_);
151 }
152 typename Iterator<0>::Integrate integrate()
153 {
154 Base::template resize<0>();
155 basis_.integrate(&(container_[0]));
156 return typename Iterator<0>::Integrate(container_);
157 }
158
159 protected:
160 StandardEvaluator ( const Basis &basis, unsigned int size )
161 : Base( basis, basis.order(), size )
162 {}
163
164 private:
165 StandardEvaluator(const StandardEvaluator&);
166 using Base::basis_;
167 using Base::container_;
168 };
169
170#if 0 // OLD OLD
171 template< class B, class Fill >
172 struct VecEvaluator
173 : public StandardEvaluator< B >
174 {
175 typedef B Basis;
176 typedef typename Basis::Field Field;
177 static const int dimension = Basis::dimension;
178 static const int dimRange = Basis::dimRange*Fill::dimRange;
179 typedef typename Basis::DomainVector DomainVector;
180 typedef std::vector<Field> Container;
181 typedef StandardEvaluator<B> Base;
182
183 template <unsigned int deriv>
184 struct Iterator
185 {
186 typedef typename Base::template BaseIterator<Derivatives<Field,dimension,dimRange,deriv,Fill::layout> > All;
187 };
188
189 VecEvaluator ( const Basis &basis, const Fill &fill )
190 : Base( basis, basis.size() ),
191 fill_( fill ),
192 size_( basis.size()*dimRange )
193 {}
194 template <unsigned int deriv>
195 typename Iterator<deriv>::All evaluate(const DomainVector &x)
196 {
197 resize< deriv >();
198 fill_.template apply<deriv>( x,Base::template evaluate<deriv>(x), vecContainer_ );
199 std::vector<Derivatives<Field,dimension,dimRange,deriv,Fill::layout> >& derivContainer =
200 reinterpret_cast<std::vector<Derivatives<Field,dimension,dimRange,deriv,Fill::layout> >&>(vecContainer_);
201 return typename Iterator<deriv>::All(derivContainer);
202 }
203 template <unsigned int deriv,class DVector>
204 typename Iterator<deriv>::All evaluate(const DVector &x)
205 {
206 resize< deriv >();
207 fill_.template apply<deriv>( x,Base::template evaluate<deriv>(x), vecContainer_ );
208 std::vector<Derivatives<Field,dimension,dimRange,deriv,Fill::layout> >& derivContainer =
209 reinterpret_cast<std::vector<Derivatives<Field,dimension,dimRange,deriv,Fill::layout> >&>(vecContainer_);
210 return typename Iterator<deriv>::All(derivContainer);
211 }
212 unsigned int size() const
213 {
214 return size_;
215 }
216
217 protected:
218 VecEvaluator ( const Basis &basis, const Fill &fill, unsigned int size )
219 : Base( basis, basis.size() ),
220 fill_( fill ),
221 size_( size )
222 {
223 resize< 2 >();
224 }
225
226 template <int deriv>
227 void resize()
228 {
229 const int totalSize = Derivatives<Field,dimension,dimRange,deriv,derivative>::size*size_;
230 vecContainer_.resize(totalSize);
231 }
232
233 VecEvaluator(const VecEvaluator&);
234
235 Container vecContainer_;
236 const Fill &fill_;
237 unsigned int size_;
238 };
239
240 template <int dimR,DerivativeLayout layout>
241 struct DiagonalFill;
242
243 template <int dimR>
244 struct DiagonalFill<dimR,derivative>
245 {
246 static const DerivativeLayout layout = derivative;
247 static const int dimRange = dimR;
248 template <int deriv, class Domain, class Iter,class Field>
249 void apply(const Domain &x,
250 Iter iter,std::vector<Field> &vecContainer) const
251 {
252 typedef std::vector<Field> Container;
253 typename Container::iterator vecIter = vecContainer.begin();
254 for ( ; !iter.done(); ++iter)
255 {
256 const typename Iter::Block &block = iter->block();
257 for (int r1=0; r1<dimR; ++r1)
258 {
259 unsigned int b = 0;
260 apply<Field>(r1,x,block,b,vecIter);
261 }
262 }
263 }
264 template <class Field, class Domain, class Block,class VecIter>
265 void apply(int r1, const Domain &x,
266 const Block &block,unsigned int &b,
267 VecIter &vecIter) const
268 {
269 unsigned int bStart = b;
270 unsigned int bEnd = b+Block::size;
271 apply<Field>(r1,x,block,bStart,bEnd,vecIter);
272 b=bEnd;
273 }
274 template <class Field, class Domain, class Block,class VecIter>
275 void apply(int r1, const Domain &x,const Block &block,
276 unsigned int bStart, unsigned int bEnd,
277 VecIter &vecIter) const
278 {
279 for (int r2=0; r2<dimR; ++r2)
280 {
281 for (unsigned int bb=bStart; bb<bEnd; ++bb)
282 {
283 *vecIter = (r1==r2 ? block[bb] : Field(0));
284 ++vecIter;
285 }
286 }
287 }
288 };
289 template <int dimR>
290 struct DiagonalFill<dimR,value>
291 {
292 static const DerivativeLayout layout = value;
293 static const int dimRange = dimR;
294 template <int deriv, class Domain, class Iter,class Field>
295 void apply(const Domain &x,
296 Iter iter,std::vector<Field> &vecContainer) const
297 {
298 typedef std::vector<Field> Container;
299 typename Container::iterator vecIter = vecContainer.begin();
300 for ( ; !iter.done(); ++iter)
301 {
302 const typename Iter::Block &block = iter->block();
303 for (int r1=0; r1<dimR; ++r1)
304 {
305 unsigned int b = 0;
306 apply<Field>(std::integral_constant<int,deriv>(),r1,x,block,b,vecIter);
307 }
308 }
309 }
310 template <class Field, class Domain, class Block,class VecIter,int deriv>
311 void apply(const integral_constat<int,deriv>&, int r1, const Domain &x,
312 const Block &block,unsigned int &b,
313 VecIter &vecIter) const
314 {
315 apply<Field>(std::integral_constant<int,deriv-1>(),r1,x,block,b,vecIter);
316 unsigned int bStart = b;
317 unsigned int bEnd = b+LFETensor<Field,Domain::dimension,deriv>::size;
318 apply<Field>(r1,x,block,bStart,bEnd,vecIter);
319 b=bEnd;
320 }
321 template <class Field, class Domain, class Block,class VecIter>
322 void apply(const std::integral_constant<int,0>&, int r1, const Domain &x,
323 const Block &block,unsigned int &b,
324 VecIter &vecIter) const
325 {
326 apply<Field>(r1,x,block,b,b+1,vecIter);
327 ++b;
328 }
329 template <class Field, class Domain, class Block,class VecIter>
330 void apply(int r1, const Domain &x,const Block &block,
331 unsigned int bStart, unsigned int bEnd,
332 VecIter &vecIter) const
333 {
334 for (int r2=0; r2<dimR; ++r2)
335 {
336 for (unsigned int bb=bStart; bb<bEnd; ++bb)
337 {
338 *vecIter = (r1==r2 ? block[bb] : Field(0));
339 ++vecIter;
340 }
341 }
342 }
343 };
344
345 template <class B,int dimR,DerivativeLayout layout>
346 struct VectorialEvaluator
347 : public VecEvaluator<B,DiagonalFill<dimR,layout> >
348 {
349 typedef DiagonalFill<dimR,layout> Fill;
350 typedef VecEvaluator< B,Fill > Base;
351 VectorialEvaluator(const B &basis)
352 : Base(basis,fill_,basis.size()*dimR)
353 {}
354 private:
355 Fill fill_;
356 };
357#endif // OLD OLD
358
359}
360
361#endif
vector space out of a tensor product of fields.
Definition: fvector.hh:93
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:58
PartitionSet<... > All
Type of PartitionSet for all partitions.
Definition: partitionset.hh:266
Dune namespace.
Definition: alignedallocator.hh:10
A unique label for each type of element that can occur in a grid.
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)