3#ifndef DUNE_BASISEVALUATOR_HH
4#define DUNE_BASISEVALUATOR_HH
14#include <dune/localfunctions/utility/field.hh>
15#include <dune/localfunctions/utility/multiindex.hh>
16#include <dune/localfunctions/utility/tensor.hh>
28 struct MonomialEvaluator
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;
36 typedef std::vector<Field> Container;
38 template<
class Deriv >
41 template <
unsigned int deriv>
44 typedef BaseIterator<Derivatives<Field,dimension,dimRange,deriv,derivative> >
All;
45 typedef BaseIterator<Derivatives<Field,dimension,1,0,value> > Integrate;
48 unsigned int size()
const
54 MonomialEvaluator(
const Basis &basis,
unsigned int order,
unsigned int size)
63 const int totalSize = Derivatives<Field,dimension,dimRange,deriv,derivative>::size*size_;
64 container_.resize(totalSize);
66 MonomialEvaluator(
const MonomialEvaluator&);
68 unsigned int order_,size_;
74 template<
class Deriv >
75 struct MonomialEvaluator< B >::BaseIterator
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;
85 typedef std::vector<Field> Container;
86 typedef typename Container::iterator CIter;
88 explicit BaseIterator ( Container &container )
89 : pos_( container.begin() ),
90 end_( container.end() )
93 const Deriv &operator*()
const
96 return reinterpret_cast<const Deriv&
>(*pos_);
99 const Deriv *operator->()
const
101 return &(operator*());
109 BaseIterator &operator++ ()
115 BaseIterator &operator+= (
unsigned int skip )
117 pos_ += skip*blockSize;
127 struct StandardEvaluator
128 :
public MonomialEvaluator< B >
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;
138 template <
unsigned int deriv>
139 struct Iterator :
public Base::template Iterator<deriv>
142 StandardEvaluator(
const Basis &basis)
143 : Base(basis,basis.order(),basis.size())
145 template <
unsigned int deriv,
class DVector>
146 typename Iterator<deriv>::All evaluate(
const DVector &x)
148 Base::template resize<deriv>();
149 basis_.template evaluate<deriv>(x,&(container_[0]));
150 return typename Iterator<deriv>::All(container_);
152 typename Iterator<0>::Integrate integrate()
154 Base::template resize<0>();
155 basis_.integrate(&(container_[0]));
156 return typename Iterator<0>::Integrate(container_);
160 StandardEvaluator (
const Basis &basis,
unsigned int size )
161 : Base( basis, basis.order(), size )
165 StandardEvaluator(
const StandardEvaluator&);
167 using Base::container_;
171 template<
class B,
class Fill >
173 :
public StandardEvaluator< B >
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;
183 template <
unsigned int deriv>
186 typedef typename Base::template BaseIterator<Derivatives<Field,dimension,dimRange,deriv,Fill::layout> >
All;
189 VecEvaluator (
const Basis &basis,
const Fill &fill )
190 : Base( basis, basis.size() ),
192 size_( basis.size()*dimRange )
194 template <
unsigned int deriv>
195 typename Iterator<deriv>::All evaluate(
const DomainVector &x)
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);
203 template <
unsigned int deriv,
class DVector>
204 typename Iterator<deriv>::All evaluate(
const DVector &x)
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);
212 unsigned int size()
const
218 VecEvaluator (
const Basis &basis,
const Fill &fill,
unsigned int size )
219 : Base( basis, basis.size() ),
229 const int totalSize = Derivatives<Field,dimension,dimRange,deriv,derivative>::size*size_;
230 vecContainer_.resize(totalSize);
233 VecEvaluator(
const VecEvaluator&);
235 Container vecContainer_;
240 template <
int dimR,DerivativeLayout layout>
244 struct DiagonalFill<dimR,derivative>
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
252 typedef std::vector<Field> Container;
253 typename Container::iterator vecIter = vecContainer.begin();
254 for ( ; !iter.done(); ++iter)
256 const typename Iter::Block &block = iter->block();
257 for (
int r1=0; r1<dimR; ++r1)
260 apply<Field>(r1,x,block,b,vecIter);
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
269 unsigned int bStart = b;
270 unsigned int bEnd = b+Block::size;
271 apply<Field>(r1,x,block,bStart,bEnd,vecIter);
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
279 for (
int r2=0; r2<dimR; ++r2)
281 for (
unsigned int bb=bStart; bb<bEnd; ++bb)
283 *vecIter = (r1==r2 ? block[bb] : Field(0));
290 struct DiagonalFill<dimR,value>
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
298 typedef std::vector<Field> Container;
299 typename Container::iterator vecIter = vecContainer.begin();
300 for ( ; !iter.done(); ++iter)
302 const typename Iter::Block &block = iter->block();
303 for (
int r1=0; r1<dimR; ++r1)
306 apply<Field>(std::integral_constant<int,deriv>(),r1,x,block,b,vecIter);
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
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);
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
326 apply<Field>(r1,x,block,b,b+1,vecIter);
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
334 for (
int r2=0; r2<dimR; ++r2)
336 for (
unsigned int bb=bStart; bb<bEnd; ++bb)
338 *vecIter = (r1==r2 ? block[bb] : Field(0));
345 template <
class B,
int dimR,DerivativeLayout layout>
346 struct VectorialEvaluator
347 :
public VecEvaluator<B,DiagonalFill<dimR,layout> >
349 typedef DiagonalFill<dimR,layout> Fill;
350 typedef VecEvaluator< B,Fill > Base;
351 VectorialEvaluator(
const B &basis)
352 : Base(basis,fill_,basis.size()*dimR)
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.