DUNE PDELab (git)

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// 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_L2INTERPOLATION_HH
6#define DUNE_L2INTERPOLATION_HH
7
10
12
13#include <dune/localfunctions/utility/field.hh>
14
15namespace Dune
16{
32 template< class B, class Q, bool onb >
34
35 template< class B, class Q >
36 class LocalL2InterpolationBase
37 {
38 typedef LocalL2InterpolationBase< B, Q > This;
39
40 public:
41 typedef B Basis;
42 typedef Q Quadrature;
43
44 static const unsigned int dimension = Basis::dimension;
45
47 template< class Function, class DofField>
48 void interpolate ( const Function &function, std::vector< DofField > &coefficients ) const
49 {
51
52 const unsigned int size = basis().size();
53 static std::vector< RangeVector > basisValues( size );
54
55 coefficients.resize( size );
56 basisValues.resize( size );
57 for( unsigned int i = 0; i < size; ++i )
58 coefficients[ i ] = Zero< DofField >();
59
60 for (auto&& qp : quadrature())
61 {
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 ];
68 }
69 }
70
71 const Basis &basis () const
72 {
73 return basis_;
74 }
75
76 const Quadrature &quadrature () const
77 {
78 return quadrature_;
79 }
80
81 protected:
82 LocalL2InterpolationBase ( const Basis &basis, const Quadrature &quadrature )
83 : basis_( basis ),
84 quadrature_( quadrature )
85 {}
86
87 const Basis &basis_;
88 const Quadrature &quadrature_;
89 };
90
91 template< class B, class Q >
92 struct LocalL2Interpolation<B,Q,true>
93 : public LocalL2InterpolationBase<B,Q>
94 {
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;
100 private:
101 LocalL2Interpolation ( const typename Base::Basis &basis, const typename Base::Quadrature &quadrature )
102 : Base(basis,quadrature)
103 {}
104 };
105 template< class B, class Q >
106 struct LocalL2Interpolation<B,Q,false>
107 : public LocalL2InterpolationBase<B,Q>
108 {
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
116 {
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)
121 {
122 coefficients[i] = 0;
123 for (unsigned int j=0; j<size; ++j)
124 {
125 coefficients[i] += field_cast<DofField>(massMatrix_[i][j]*val_[j]);
126 }
127 }
128 }
129 private:
130 LocalL2Interpolation ( const typename Base::Basis &basis, const typename Base::Quadrature &quadrature )
131 : Base(basis,quadrature),
132 val_(basis.size()),
133 massMatrix_(basis.size(),basis.size(),Field(0))
134 {
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 );
139
140 const Iterator end = Base::quadrature().end();
141 for( Iterator it = Base::quadrature().begin(); it != end; ++it )
142 {
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();
147 }
148 massMatrix_.invert();
149 }
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_;
155 };
156
161 template< class BasisFactory, bool onb >
163 {
164 static const unsigned int dimension = BasisFactory::dimension;
165 typedef typename BasisFactory::Key Key;
166 typedef typename BasisFactory::Object Basis;
167 typedef double Field;
171 typedef const LocalInterpolation Object;
172
173 template< GeometryType::Id geometryId >
174 static Object *create ( const Key &key )
175 {
176 constexpr Dune::GeometryType geometry = geometryId;
177 const Basis *basis = BasisFactory::template create< geometry >( key );
178 const Quadrature & quadrature = QuadratureProvider::rule(geometry, 2*basis->order()+1);
179 return new Object( *basis, quadrature );
180 }
181 static void release ( Object *object )
182 {
183 const Basis &basis = object->basis();
184 BasisFactory::release( &basis );
185 delete object;
186 }
187 };
188
189}
190
191#endif // #ifndef DUNE_L2INTERPOLATION_HH
vector space out of a tensor product of fields.
Definition: fvector.hh:91
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.
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)