Dune Core Modules (2.6.0)

l2interpolation.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_L2INTERPOLATION_HH
4#define DUNE_L2INTERPOLATION_HH
5
6#include <dune/geometry/topologyfactory.hh>
8
9#include <dune/localfunctions/utility/lfematrix.hh>
10
11namespace Dune
12{
28 template< class B, class Q, bool onb >
30
31 template< class B, class Q >
32 class LocalL2InterpolationBase
33 {
34 typedef LocalL2InterpolationBase< B, Q > This;
35
36 public:
37 typedef B Basis;
38 typedef Q Quadrature;
39
40 static const unsigned int dimension = Basis::dimension;
41
42 template< class Function, class DofField >
43 void interpolate ( const Function &function, std::vector< DofField > &coefficients ) const
44 {
45 typedef typename Quadrature::iterator Iterator;
47
48 const unsigned int size = basis().size();
49 static std::vector< RangeVector > basisValues( size );
50
51 coefficients.resize( size );
52 basisValues.resize( size );
53 for( unsigned int i = 0; i < size; ++i )
54 coefficients[ i ] = Zero< DofField >();
55
56 const Iterator end = quadrature().end();
57 for( Iterator it = quadrature().begin(); it != end; ++it )
58 {
59 basis().evaluate( it->position(), basisValues );
60 typename Function::RangeType val;
61 function.evaluate( field_cast<typename Function::DomainType::field_type>(it->position()), val );
62 RangeVector factor = field_cast< DofField >( val );
63 factor *= field_cast< DofField >( it->weight() );
64 for( unsigned int i = 0; i < size; ++i )
65 coefficients[ i ] += factor * basisValues[ i ];
66 }
67 }
68
69 const Basis &basis () const
70 {
71 return basis_;
72 }
73
74 const Quadrature &quadrature () const
75 {
76 return quadrature_;
77 }
78
79 protected:
80 LocalL2InterpolationBase ( const Basis &basis, const Quadrature &quadrature )
81 : basis_( basis ),
82 quadrature_( quadrature )
83 {}
84
85 const Basis &basis_;
86 const Quadrature &quadrature_;
87 };
88
89 template< class B, class Q >
90 struct LocalL2Interpolation<B,Q,true>
91 : public LocalL2InterpolationBase<B,Q>
92 {
93 typedef LocalL2InterpolationBase<B,Q> Base;
94 template< class BasisFactory, bool onb >
95 friend class LocalL2InterpolationFactory;
96 using typename Base::Basis;
97 using typename Base::Quadrature;
98 private:
99 LocalL2Interpolation ( const typename Base::Basis &basis, const typename Base::Quadrature &quadrature )
100 : Base(basis,quadrature)
101 {}
102 };
103 template< class B, class Q >
104 struct LocalL2Interpolation<B,Q,false>
105 : public LocalL2InterpolationBase<B,Q>
106 {
107 typedef LocalL2InterpolationBase<B,Q> Base;
108 template< class BasisFactory, bool onb >
109 friend class LocalL2InterpolationFactory;
110 using typename Base::Basis;
111 using typename Base::Quadrature;
112 template< class Function, class DofField >
113 void interpolate ( const Function &function, std::vector< DofField > &coefficients ) const
114 {
115 const unsigned size = Base::basis().size();
116 Base::interpolate(function,val_);
117 coefficients.resize( size );
118 for (unsigned int i=0; i<size; ++i)
119 {
120 coefficients[i] = 0;
121 for (unsigned int j=0; j<size; ++j)
122 {
123 coefficients[i] += field_cast<DofField>(massMatrix_(i,j)*val_[j]);
124 }
125 }
126 }
127 private:
128 LocalL2Interpolation ( const typename Base::Basis &basis, const typename Base::Quadrature &quadrature )
129 : Base(basis,quadrature),
130 val_(basis.size()),
131 massMatrix_()
132 {
133 typedef FieldVector< Field, Base::Basis::dimRange > RangeVector;
134 typedef typename Base::Quadrature::iterator Iterator;
135 const unsigned size = basis.size();
136 std::vector< RangeVector > basisValues( size );
137
138 massMatrix_.resize( size,size );
139 for (unsigned int i=0; i<size; ++i)
140 for (unsigned int j=0; j<size; ++j)
141 massMatrix_(i,j) = 0;
142 const Iterator end = Base::quadrature().end();
143 for( Iterator it = Base::quadrature().begin(); it != end; ++it )
144 {
145 Base::basis().evaluate( it->position(), basisValues );
146 for (unsigned int i=0; i<size; ++i)
147 for (unsigned int j=0; j<size; ++j)
148 massMatrix_(i,j) += (basisValues[i]*basisValues[j])*it->weight();
149 }
150 if ( !massMatrix_.invert() )
151 {
152 DUNE_THROW(MathError, "Mass matrix singular in LocalL2Interpolation");
153 }
154
155 }
156 typedef typename Base::Basis::StorageField Field;
157 typedef FieldVector< Field, Base::Basis::dimRange > RangeVector;
158 typedef LFEMatrix<Field> MassMatrix;
159 mutable std::vector<Field> val_;
160 MassMatrix massMatrix_;
161 };
162
167 template< class BasisFactory, bool onb >
168 struct LocalL2InterpolationFactory;
169 template< class BasisFactory, bool onb >
170 struct LocalL2InterpolationFactoryTraits
171 {
172 static const unsigned int dimension = BasisFactory::dimension;
173 // typedef typename BasisFactory::StorageField Field;
174 typedef double Field;
175 typedef QuadratureRule<Field,dimension> Quadrature;
176 typedef QuadratureRules<Field,dimension> QuadratureProvider;
177
178 typedef typename BasisFactory::Key Key;
179 typedef typename BasisFactory::Object Basis;
180 typedef LocalL2Interpolation< Basis, Quadrature, onb > LocalInterpolation;
181 typedef const LocalInterpolation Object;
182 typedef LocalL2InterpolationFactory<BasisFactory,onb> Factory;
183 };
184
185 template< class BasisFactory, bool onb >
187 public TopologyFactory< LocalL2InterpolationFactoryTraits<BasisFactory,onb> >
188 {
189 typedef LocalL2InterpolationFactoryTraits<BasisFactory,onb> Traits;
190 static const unsigned int dimension = Traits::dimension;
191 typedef typename Traits::Key Key;
192 typedef typename Traits::Basis Basis;
193 typedef typename Traits::Object Object;
194 typedef typename Traits::Field Field;
195 typedef typename Traits::Quadrature Quadrature;
196
197 template< class Topology >
198 static Object *createObject ( const Key &key )
199 {
200 Dune::GeometryType gt(Topology::id, Topology::dimension);
201 const Basis *basis = BasisFactory::template create< Topology >( key );
202 const Quadrature & quadrature = Traits::QuadratureProvider::rule(gt, 2*basis->order()+1);
203 return new Object( *basis, quadrature );
204 }
205 static void release ( Object *object )
206 {
207 const Basis &basis = object->basis();
208 BasisFactory::release( &basis );
209 delete object;
210 }
211 };
212
213}
214
215#endif // #ifndef DUNE_L2INTERPOLATION_HH
vector space out of a tensor product of fields.
Definition: fvector.hh:93
Base class template for function classes.
Definition: function.hh:29
void evaluate(const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Function evaluation.
RawRangeType RangeType
Raw type of input variable with removed reference and constness.
Definition: function.hh:36
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:277
Abstract base class for quadrature rules.
Definition: quadraturerules.hh:97
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:225
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:147
Dune namespace.
Definition: alignedallocator.hh:10
A factory class for the local l2 interpolations taking a basis factory.
Definition: l2interpolation.hh:188
A local L2 interpolation taking a test basis and a quadrature rule.
Definition: l2interpolation.hh:29
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:39
A class representing the zero of a given Field.
Definition: field.hh:77
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)