5#ifndef DUNE_L2INTERPOLATION_HH
6#define DUNE_L2INTERPOLATION_HH
13#include <dune/localfunctions/utility/field.hh>
32 template<
class B,
class Q,
bool onb >
35 template<
class B,
class Q >
36 class LocalL2InterpolationBase
38 typedef LocalL2InterpolationBase< B, Q > This;
44 static const unsigned int dimension = Basis::dimension;
47 template<
class Function,
class DofField>
48 void interpolate (
const Function &function, std::vector< DofField > &coefficients )
const
52 const unsigned int size = basis().size();
53 static std::vector< RangeVector > basisValues(
size );
55 coefficients.resize(
size );
56 basisValues.resize(
size );
57 for(
unsigned int i = 0; i <
size; ++i )
60 for (
auto&& qp : quadrature())
62 basis().evaluate( qp.position(), basisValues );
63 auto val = function( qp.position() );
64 RangeVector factor = field_cast< DofField >( val );
65 factor *= field_cast< DofField >( qp.weight() );
66 for(
unsigned int i = 0; i <
size; ++i )
67 coefficients[ i ] += factor * basisValues[ i ];
71 const Basis &basis ()
const
76 const Quadrature &quadrature ()
const
82 LocalL2InterpolationBase (
const Basis &basis,
const Quadrature &quadrature )
84 quadrature_( quadrature )
88 const Quadrature &quadrature_;
91 template<
class B,
class Q >
92 struct LocalL2Interpolation<B,Q,true>
93 :
public LocalL2InterpolationBase<B,Q>
95 typedef LocalL2InterpolationBase<B,Q> Base;
96 template<
class BasisFactory,
bool onb >
97 friend class LocalL2InterpolationFactory;
98 using typename Base::Basis;
99 using typename Base::Quadrature;
101 LocalL2Interpolation (
const typename Base::Basis &basis,
const typename Base::Quadrature &quadrature )
102 : Base(basis,quadrature)
105 template<
class B,
class Q >
106 struct LocalL2Interpolation<B,Q,false>
107 :
public LocalL2InterpolationBase<B,Q>
109 typedef LocalL2InterpolationBase<B,Q> Base;
110 template<
class BasisFactory,
bool onb >
111 friend class LocalL2InterpolationFactory;
112 using typename Base::Basis;
113 using typename Base::Quadrature;
114 template<
class Function,
class DofField >
115 void interpolate (
const Function &function, std::vector< DofField > &coefficients )
const
117 const unsigned size = Base::basis().size();
118 Base::interpolate(function,val_);
119 coefficients.resize(
size );
120 for (
unsigned int i=0; i<
size; ++i)
123 for (
unsigned int j=0; j<
size; ++j)
125 coefficients[i] += field_cast<DofField>(massMatrix_[i][j]*val_[j]);
130 LocalL2Interpolation (
const typename Base::Basis &basis,
const typename Base::Quadrature &quadrature )
131 : Base(basis,quadrature),
133 massMatrix_(basis.
size(),basis.
size(),Field(0))
135 typedef FieldVector< Field, Base::Basis::dimRange > RangeVector;
136 typedef typename Base::Quadrature::iterator Iterator;
137 const unsigned size = basis.size();
138 std::vector< RangeVector > basisValues(
size );
140 const Iterator end = Base::quadrature().end();
141 for( Iterator it = Base::quadrature().begin(); it != end; ++it )
143 Base::basis().evaluate( it->position(), basisValues );
144 for (
unsigned int i=0; i<
size; ++i)
145 for (
unsigned int j=0; j<
size; ++j)
146 massMatrix_[i][j] += (basisValues[i]*basisValues[j])*it->weight();
148 massMatrix_.invert();
150 typedef typename Base::Basis::StorageField Field;
151 typedef FieldVector< Field, Base::Basis::dimRange > RangeVector;
152 typedef DynamicMatrix<Field> MassMatrix;
153 mutable std::vector<Field> val_;
154 MassMatrix massMatrix_;
161 template<
class BasisFactory,
bool onb >
164 static const unsigned int dimension = BasisFactory::dimension;
165 typedef typename BasisFactory::Key Key;
166 typedef typename BasisFactory::Object Basis;
167 typedef double Field;
173 template< GeometryType::Id geometryId >
174 static Object *create (
const Key &key )
177 const Basis *basis = BasisFactory::template create< geometry >( key );
179 return new Object( *basis, quadrature );
181 static void release (
Object *
object )
183 const Basis &basis =
object->basis();
184 BasisFactory::release( &basis );
vector space out of a tensor product of fields.
Definition: fvector.hh:92
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Abstract base class for quadrature rules.
Definition: quadraturerules.hh:214
A container for all quadrature rules of dimension dim
Definition: quadraturerules.hh:260
static const QuadratureRule & rule(const GeometryType &t, int p, QuadratureType::Enum qt=QuadratureType::GaussLegendre)
select the appropriate QuadratureRule for GeometryType t and order p
Definition: quadraturerules.hh:326
Infrastructure for concepts.
This file implements a dense matrix with dynamic numbers of rows and columns.
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 factory class for the local l2 interpolations taking a basis factory.
Definition: l2interpolation.hh:163
A local L2 interpolation taking a test basis and a quadrature rule.
Definition: l2interpolation.hh:33
A class representing the zero of a given Field.
Definition: field.hh:79