/usr/include/dune/localfunctions/utility/polynomialbasis.hh is in libdune-localfunctions-dev 2.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | #ifndef DUNE_POLYNOMIALBASIS_HH
#define DUNE_POLYNOMIALBASIS_HH
#include <fstream>
#include <dune/common/fmatrix.hh>
#include <dune/localfunctions/common/localbasis.hh>
#include <dune/localfunctions/utility/coeffmatrix.hh>
#include <dune/localfunctions/utility/monomialbasis.hh>
#include <dune/localfunctions/utility/multiindex.hh>
#include <dune/localfunctions/utility/basisevaluator.hh>
namespace Dune
{
// PolynomialBasis
// ---------------
/**
* This is the basis class for a ''polynomial''
* basis, i.e., a basis consisting of linear
* combiniations of a underlying second basis set.
* Examples are standard polynomials where the
* underlying basis is given by the MonomialBasis
* class. The basis evaluation is given by the matrix
* vector multiplication between the coefficient
* matrix and the vector filled by evaluating the
* underlying basis set.
* This class is constructed using a reference of
* the underlying basis and the coefficient matrix.
* A specialization holding an instance
* of the coefficient matrix is provided by the class
* template< class Eval, class CM = SparseCoeffMatrix<typename Eval::Field,Eval::dimRange> >
* class PolynomialBasisWithMatrix;
*
* \tparam B Basis set with
* static const int dimension -> dimension of reference element
* typedef DomainVector -> coordinates in reference element
* int size(int order) const -> number of basis functions
* void evaluate( order, x, val ) const
* int order
* DomainVector x
* Container val
* \tparam CM stroage for coefficience with
* typedef Field -> field of coefficience
* static const int dimRange -> coeficience are of type
* FieldMatrix<Field,dimRange,dimRange>
* void mult( val, y )
* Container val
* std::vector<RangeVector> y
* \tparam Container access to basis functions through forward iterator
* typedef value_type
* typedef const_iterator
* const_iterator begin()
**/
template< class Eval, class CM, class D=double, class R=double >
class PolynomialBasis
{
typedef PolynomialBasis< Eval, CM > This;
typedef Eval Evaluator;
public:
typedef CM CoefficientMatrix;
typedef typename CoefficientMatrix::Field StorageField;
static const unsigned int dimension = Evaluator::dimension;
static const unsigned int dimRange = Evaluator::dimRange*CoefficientMatrix::blockSize;
typedef LocalBasisTraits<D,dimension,FieldVector<D,dimension>,
R,dimRange,FieldVector<R,dimRange>,
FieldMatrix<R,dimRange,dimension> > Traits;
typedef typename Evaluator::Basis Basis;
typedef typename Evaluator::DomainVector DomainVector;
PolynomialBasis (const Basis &basis,
const CoefficientMatrix &coeffMatrix,
unsigned int size)
: basis_(basis),
coeffMatrix_(&coeffMatrix),
eval_(basis),
order_(basis.order()),
size_(size)
{
// assert(coeffMatrix_);
// assert(size_ <= coeffMatrix.size()); // !!!
}
const Basis &basis () const
{
return basis_;
}
const CoefficientMatrix &matrix () const
{
return *coeffMatrix_;
}
const unsigned int order () const
{
return order_;
}
const unsigned int size () const
{
return size_;
}
//! \brief Evaluate all shape functions
void evaluateFunction (const typename Traits::DomainType& x,
std::vector<typename Traits::RangeType>& out) const
{
out.resize(size());
evaluate(x,out);
}
//! \brief Evaluate Jacobian of all shape functions
void evaluateJacobian (const typename Traits::DomainType& x, // position
std::vector<typename Traits::JacobianType>& out) const // return value
{
out.resize(size());
jacobian(x,out);
}
template< unsigned int deriv, class F >
void evaluate ( const DomainVector &x, F *values ) const
{
coeffMatrix_->mult( eval_.template evaluate<deriv>( x ), size(), values);
}
template< unsigned int deriv, class DVector, class F >
void evaluate ( const DVector &x, F *values ) const
{
assert( DVector::dimension == dimension);
DomainVector bx;
for( int d = 0; d < dimension; ++d )
field_cast( x[ d ], bx[ d ] );
evaluate<deriv>( bx, values );
}
template <bool dummy,class DVector>
struct Convert
{
static DomainVector apply( const DVector &x )
{
assert( DVector::dimension == dimension);
DomainVector bx;
for( unsigned int d = 0; d < dimension; ++d )
field_cast( x[ d ], bx[ d ] );
return bx;
}
};
template <bool dummy>
struct Convert<dummy,DomainVector>
{
static const DomainVector &apply( const DomainVector &x )
{
return x;
}
};
template< unsigned int deriv, class DVector, class RVector >
void evaluate ( const DVector &x, RVector &values ) const
{
assert(values.size()>=size());
const DomainVector &bx = Convert<true,DVector>::apply(x);
coeffMatrix_->mult( eval_.template evaluate<deriv>( bx ), values );
}
template <class Fy>
void evaluate ( const DomainVector &x, std::vector<FieldVector<Fy,dimRange> > &values ) const
{
evaluate<0>(x,values);
}
template< class DVector, class RVector >
void evaluate ( const DVector &x, RVector &values ) const
{
assert( DVector::dimension == dimension);
DomainVector bx;
for( unsigned int d = 0; d < dimension; ++d )
field_cast( x[ d ], bx[ d ] );
evaluate<0>( bx, values );
}
template< unsigned int deriv, class Vector >
void evaluateSingle ( const DomainVector &x, Vector &values ) const
{
assert(values.size()>=size());
coeffMatrix_->template mult<deriv>( eval_.template evaluate<deriv>( x ), values );
}
template< unsigned int deriv, class Fy >
void evaluateSingle ( const DomainVector &x,
std::vector< FieldVector<FieldVector<Fy,LFETensor<Fy,dimension,deriv>::size>,dimRange> > &values) const
{
evaluateSingle<deriv>(x,reinterpret_cast<std::vector< FieldVector<Fy,LFETensor<Fy,dimension,deriv>::size*dimRange> >&>(values));
}
template< unsigned int deriv, class Fy >
void evaluateSingle ( const DomainVector &x,
std::vector< FieldVector<LFETensor<Fy,dimension,deriv>,dimRange> > &values) const
{
evaluateSingle<deriv>(x,reinterpret_cast<std::vector< FieldVector<Fy,LFETensor<Fy,dimension,deriv>::size*dimRange> >&>(values));
}
template <class Fy>
void jacobian ( const DomainVector &x, std::vector<FieldMatrix<Fy,dimRange,dimension> > &values ) const
{
assert(values.size()>=size());
evaluateSingle<1>(x,reinterpret_cast<std::vector<FieldVector<Fy,dimRange*dimension> >&>(values));
}
template< class DVector, class RVector >
void jacobian ( const DVector &x, RVector &values ) const
{
assert( DVector::dimension == dimension);
DomainVector bx;
for( unsigned int d = 0; d < dimension; ++d )
field_cast( x[ d ], bx[ d ] );
jacobian( bx, values );
}
template <class Fy>
void integrate ( std::vector<Fy> &values ) const
{
assert(values.size()>=size());
coeffMatrix_->mult( eval_.template integrate(), values );
}
protected:
PolynomialBasis(const PolynomialBasis &other)
: basis_(other.basis_),
coeffMatrix_(other.coeffMatrix_),
eval_(basis_),
order_(basis_.order()),
size_(other.size_)
{
}
PolynomialBasis &operator=(const PolynomialBasis&);
const Basis &basis_;
const CoefficientMatrix* coeffMatrix_;
mutable Evaluator eval_;
unsigned int order_,size_;
};
/**
* Specialized version of PolynomialBasis with FieldMatrix for matrix
* coefficience and std::vector for container type with FieldVector as
* value type. This class stores the coefficient matrix with can be
* constructed via the fill method
*/
template< class Eval, class CM = SparseCoeffMatrix<typename Eval::Field,Eval::dimRange>,
class D=double, class R=double>
class PolynomialBasisWithMatrix
: public PolynomialBasis< Eval, CM, D, R >
{
public:
typedef CM CoefficientMatrix;
private:
typedef Eval Evaluator;
typedef PolynomialBasisWithMatrix< Evaluator, CM > This;
typedef PolynomialBasis<Evaluator,CM> Base;
public:
typedef typename Base::Basis Basis;
PolynomialBasisWithMatrix (const Basis &basis)
: Base(basis,coeffMatrix_,0)
{}
template <class Matrix>
void fill(const Matrix& matrix)
{
coeffMatrix_.fill(matrix);
this->size_ = coeffMatrix_.size();
}
template <class Matrix>
void fill(const Matrix& matrix,int size)
{
coeffMatrix_.fill(matrix);
assert(size<=coeffMatrix_.size());
this->size_ = size;
}
private:
PolynomialBasisWithMatrix(const PolynomialBasisWithMatrix &);
PolynomialBasisWithMatrix &operator=(const PolynomialBasisWithMatrix &);
CoefficientMatrix coeffMatrix_;
};
}
#endif // DUNE_POLYNOMIALBASIS_HH
|