3#ifndef DUNE_POLYNOMIALBASIS_HH
4#define DUNE_POLYNOMIALBASIS_HH
11#include <dune/localfunctions/common/localbasis.hh>
13#include <dune/localfunctions/utility/coeffmatrix.hh>
14#include <dune/localfunctions/utility/monomialbasis.hh>
15#include <dune/localfunctions/utility/multiindex.hh>
16#include <dune/localfunctions/utility/basisevaluator.hh>
61 template<
class Eval,
class CM,
class D=
double,
class R=
double >
65 typedef Eval Evaluator;
68 typedef CM CoefficientMatrix;
70 typedef typename CoefficientMatrix::Field StorageField;
72 static const unsigned int dimension = Evaluator::dimension;
73 static const unsigned int dimRange = Evaluator::dimRange*CoefficientMatrix::blockSize;
77 typedef typename Evaluator::Basis Basis;
78 typedef typename Evaluator::DomainVector DomainVector;
84 const CoefficientMatrix &coeffMatrix,
87 coeffMatrix_(&coeffMatrix),
89 order_(basis.order()),
96 const Basis &basis ()
const
101 const CoefficientMatrix &matrix ()
const
103 return *coeffMatrix_;
106 unsigned int order ()
const
111 unsigned int size ()
const
118 std::vector<typename Traits::RangeType>& out)
const
126 std::vector<typename Traits::JacobianType>& out)
const
134 std::vector<HessianType>& out)
const
141 void partial (
const std::array<unsigned int, dimension>& order,
143 std::vector<typename Traits::RangeType>& out)
const
146 if (totalOrder == 0) {
149 else if (totalOrder == 1) {
150 std::vector<typename Traits::JacobianType> jacs(out.size());
152 for (
unsigned int i=0;i<order.size();++i)
153 if (order[i]==1) k=i;
155 for (
unsigned int i=0;i<out.size();++i)
156 for (
unsigned int r=0;r<Traits::RangeType::dimension;++r)
157 out[i][r] = jacs[i][r][k];
159 else if (totalOrder == 2) {
160 std::vector<HessianType> hesss(out.size());
162 for (
unsigned int i=0;i<order.size();++i) {
163 if (order[i]==1 && k==-1) k=i;
164 else if (order[i]==1) l=i;
168 for (
unsigned int i=0;i<out.size();++i)
169 for (
unsigned int r=0;r<Traits::RangeType::dimension;++r)
170 out[i][r] = hesss[i][r][k][l];
177 template<
unsigned int deriv,
class F >
178 void evaluate (
const DomainVector &x, F *values )
const
180 coeffMatrix_->mult( eval_.template evaluate<deriv>( x ), size(), values);
182 template<
unsigned int deriv,
class DVector,
class F >
183 void evaluate (
const DVector &x, F *values )
const
185 assert( DVector::dimension == dimension);
187 for(
int d = 0; d < dimension; ++d )
189 evaluate<deriv>( bx, values );
192 template <
bool dummy,
class DVector>
195 static DomainVector apply(
const DVector &x )
197 assert( DVector::dimension == dimension);
199 for(
unsigned int d = 0; d < dimension; ++d )
204 template <
bool dummy>
205 struct Convert<dummy,DomainVector>
207 static const DomainVector &apply(
const DomainVector &x )
212 template<
unsigned int deriv,
class DVector,
class RVector >
213 void evaluate (
const DVector &x, RVector &values )
const
215 assert(values.size()>=size());
216 const DomainVector &bx = Convert<true,DVector>::apply(x);
217 coeffMatrix_->mult( eval_.template evaluate<deriv>( bx ), values );
221 void evaluate (
const DomainVector &x, std::vector<FieldVector<Fy,dimRange> > &values )
const
223 evaluate<0>(x,values);
225 template<
class DVector,
class RVector >
226 void evaluate (
const DVector &x, RVector &values )
const
228 assert( DVector::dimension == dimension);
230 for(
unsigned int d = 0; d < dimension; ++d )
232 evaluate<0>( bx, values );
235 template<
unsigned int deriv,
class Vector >
236 void evaluateSingle (
const DomainVector &x, Vector &values )
const
238 assert(values.size()>=size());
239 coeffMatrix_->template mult<deriv>( eval_.template evaluate<deriv>( x ), values );
241 template<
unsigned int deriv,
class Fy >
242 void evaluateSingle (
const DomainVector &x,
243 std::vector< FieldVector<FieldVector<Fy,LFETensor<Fy,dimension,deriv>::size>,dimRange> > &values)
const
245 evaluateSingle<deriv>(x,
reinterpret_cast<std::vector< FieldVector<Fy,LFETensor<Fy,dimension,deriv>::size*dimRange
> >&>(values));
247 template<
unsigned int deriv,
class Fy >
248 void evaluateSingle (
const DomainVector &x,
249 std::vector< FieldVector<LFETensor<Fy,dimension,deriv>,dimRange> > &values)
const
251 evaluateSingle<deriv>(x,
reinterpret_cast<std::vector< FieldVector<Fy,LFETensor<Fy,dimension,deriv>::size*dimRange
> >&>(values));
255 void jacobian (
const DomainVector &x,
256 std::vector<FieldMatrix<Fy,dimRange,dimension> > &values )
const
258 assert(values.size()>=size());
259 evaluateSingle<1>(x,
reinterpret_cast<std::vector<FieldVector<Fy,dimRange*dimension>
>&>(values));
261 template<
class DVector,
class RVector >
262 void jacobian (
const DVector &x, RVector &values )
const
264 assert( DVector::dimension == dimension);
266 for(
unsigned int d = 0; d < dimension; ++d )
268 jacobian( bx, values );
271 void hessian (
const DomainVector &x,
272 std::vector<HessianFyType<Fy>> &values )
const
274 assert(values.size()>=size());
277 const unsigned int hsize = LFETensor<Fy,dimension,2>::size;
278 std::vector< FieldVector< FieldVector<Fy,hsize>, dimRange> > y( size() );
279 evaluateSingle<2>( x, y );
281 for (
unsigned int i=0;i<size();++i)
282 for (
unsigned int r=0;r<dimRange;++r)
283 for (
unsigned int k=0;k<dimension;++k)
284 for (
unsigned int l=k;l<dimension;++l)
286 values[i][r][k][l] = y[i][r][q];
287 values[i][r][l][k] = y[i][r][q];
293 template<
class DVector,
class HVector >
294 void hessian (
const DVector &x, HVector &values )
const
296 assert( DVector::dimension == dimension);
298 for(
unsigned int d = 0; d < dimension; ++d )
300 hessian( bx, values );
304 void integrate ( std::vector<Fy> &values )
const
306 assert(values.size()>=size());
307 coeffMatrix_->mult( eval_.template integrate(), values );
311 PolynomialBasis(
const PolynomialBasis &other)
312 : basis_(other.basis_),
313 coeffMatrix_(other.coeffMatrix_),
315 order_(basis_.order()),
318 PolynomialBasis &operator=(
const PolynomialBasis&);
320 const CoefficientMatrix* coeffMatrix_;
321 mutable Evaluator eval_;
322 unsigned int order_,size_;
331 template<
class Eval,
class CM = SparseCoeffMatrix<
typename Eval::Field,Eval::dimRange>,
332 class D=
double,
class R=
double>
337 typedef CM CoefficientMatrix;
340 typedef Eval Evaluator;
346 typedef typename Base::Basis Basis;
349 :
Base(basis,coeffMatrix_,0)
352 template <
class Matrix>
353 void fill(
const Matrix& matrix)
355 coeffMatrix_.fill(matrix);
356 this->size_ = coeffMatrix_.size();
358 template <
class Matrix>
359 void fill(
const Matrix& matrix,
int size)
361 coeffMatrix_.fill(matrix);
362 assert(size<=coeffMatrix_.size());
369 CoefficientMatrix coeffMatrix_;
A dense n x m matrix.
Definition: fmatrix.hh:69
vector space out of a tensor product of fields.
Definition: fvector.hh:95
A generic dynamic dense matrix.
Definition: matrix.hh:559
Default exception for dummy implementations.
Definition: exceptions.hh:261
Definition: polynomialbasis.hh:335
Definition: polynomialbasis.hh:63
void evaluateHessian(const typename Traits::DomainType &x, std::vector< HessianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: polynomialbasis.hh:133
void evaluateFunction(const typename Traits::DomainType &x, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: polynomialbasis.hh:117
void evaluateJacobian(const typename Traits::DomainType &x, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: polynomialbasis.hh:125
void partial(const std::array< unsigned int, dimension > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of all shape functions.
Definition: polynomialbasis.hh:141
Implements a matrix constructed from a given type representing a field and compile-time given number ...
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:289
Dune namespace.
Definition: alignedallocator.hh:11
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:157
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:32
D DomainType
domain type
Definition: localbasis.hh:43