DUNE PDELab (git)

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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_BASISEVALUATOR_HH
6#define DUNE_BASISEVALUATOR_HH
7
8#include <vector>
9
13
14#include <dune/geometry/type.hh>
15
16#include <dune/localfunctions/utility/field.hh>
17#include <dune/localfunctions/utility/multiindex.hh>
18#include <dune/localfunctions/utility/tensor.hh>
19
20namespace Dune
21{
22 /*******************************************
23 * Should be removed as soon as the Tensor
24 * classes have been revisited. See remarks
25 * in tensor.hh (also hold true here).
26 *******************************************/
27
28
29 template <class B>
30 struct MonomialEvaluator
31 {
32 typedef B Basis;
33 typedef typename Basis::Field Field;
34 typedef typename Basis::DomainVector DomainVector;
35 static const int dimension = Basis::dimension;
36 static const int dimRange = Basis::dimRange;
37
38 typedef std::vector<Field> Container;
39
40 template< class Deriv >
41 struct BaseIterator;
42
43 template <unsigned int deriv>
44 struct Iterator
45 {
46 typedef BaseIterator<Derivatives<Field,dimension,dimRange,deriv,DerivativeLayoutNS::derivative> > All;
47 typedef BaseIterator<Derivatives<Field,dimension,1,0,DerivativeLayoutNS::value> > Integrate;
48 };
49
50 unsigned int size() const
51 {
52 return size_;
53 }
54
55 protected:
56 MonomialEvaluator(const Basis &basis,unsigned int order,unsigned int size)
57 : basis_(basis),
58 order_(order),
59 size_(size),
60 container_(0)
61 {}
62 template <int deriv>
63 void resize()
64 {
65 const int totalSize = Derivatives<Field,dimension,dimRange,deriv,DerivativeLayoutNS::derivative>::size*size_;
66 container_.resize(totalSize);
67 }
68 MonomialEvaluator(const MonomialEvaluator&);
69 const Basis &basis_;
70 unsigned int order_,size_;
71 Container container_;
72 };
73
74
75 template< class B >
76 template< class Deriv >
77 struct MonomialEvaluator< B >::BaseIterator
78 {
79 typedef Deriv Derivatives;
80 typedef typename Deriv::Field Field;
81 static const unsigned int blockSize = Deriv::size;
83 static const DerivativeLayoutNS::DerivativeLayout layout = Deriv::layout;
84 static const unsigned int dimDomain = Deriv::dimDomain;
85 static const unsigned int dimRange = Deriv::dimRange;
86
87 typedef std::vector<Field> Container;
88 typedef typename Container::iterator CIter;
89
90 explicit BaseIterator ( Container &container )
91 : pos_( container.begin() ),
92 end_( container.end() )
93 {}
94
95 const Deriv &operator*() const
96 {
97 assert(!done());
98 return reinterpret_cast<const Deriv&>(*pos_);
99 }
100
101 const Deriv *operator->() const
102 {
103 return &(operator*());
104 }
105
106 bool done () const
107 {
108 return pos_ == end_;
109 }
110
111 BaseIterator &operator++ ()
112 {
113 pos_ += blockSize;
114 return *this;
115 }
116
117 BaseIterator &operator+= ( unsigned int skip )
118 {
119 pos_ += skip*blockSize;
120 return *this;
121 }
122
123 private:
124 CIter pos_;
125 const CIter end_;
126 };
127
128 template< class B >
129 struct StandardEvaluator
130 : public MonomialEvaluator< B >
131 {
132 typedef B Basis;
133 typedef typename Basis::Field Field;
134 typedef typename Basis::DomainVector DomainVector;
135 typedef std::vector<Field> Container;
136 static const int dimension = Basis::dimension;
137 static const int dimRange = Basis::dimRange;
138 typedef MonomialEvaluator<B> Base;
139
140 template <unsigned int deriv>
141 struct Iterator : public Base::template Iterator<deriv>
142 {};
143
144 StandardEvaluator(const Basis &basis)
145 : Base(basis,basis.order(),basis.size())
146 {}
147 template <unsigned int deriv,class DVector>
148 typename Iterator<deriv>::All evaluate(const DVector &x)
149 {
150 Base::template resize<deriv>();
151 basis_.template evaluate<deriv>(x,&(container_[0]));
152 return typename Iterator<deriv>::All(container_);
153 }
154 typename Iterator<0>::Integrate integrate()
155 {
156 Base::template resize<0>();
157 basis_.integrate(&(container_[0]));
158 return typename Iterator<0>::Integrate(container_);
159 }
160
161 protected:
162 StandardEvaluator ( const Basis &basis, unsigned int size )
163 : Base( basis, basis.order(), size )
164 {}
165
166 private:
167 StandardEvaluator(const StandardEvaluator&);
168 using Base::basis_;
169 using Base::container_;
170 };
171
172}
173
174#endif
vector space out of a tensor product of fields.
Definition: fvector.hh:91
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:267
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
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 (Nov 13, 23:29, 2024)