DUNE PDELab (2.7)

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,DerivativeLayoutNS::derivative> > All;
45 typedef BaseIterator<Derivatives<Field,dimension,1,0,DerivativeLayoutNS::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,DerivativeLayoutNS::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 DerivativeLayoutNS::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}
171
172#endif
vector space out of a tensor product of fields.
Definition: fvector.hh:96
Traits for type conversions and type information.
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.
PartitionSet<... > All
Type of PartitionSet for all partitions.
Definition: partitionset.hh:266
Dune namespace.
Definition: alignedallocator.hh:14
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)