DUNE-FEM (unstable)

localrestrictprolong.hh
1#ifndef DUNE_FEM_LFESPACE_LOCALRESTRICTPROLONG_HH
2#define DUNE_FEM_LFESPACE_LOCALRESTRICTPROLONG_HH
3
5#include <dune/geometry/referenceelements.hh>
6#include <dune/fem/function/localfunction/localfunction.hh>
7#include <dune/fem/space/localfiniteelement/space.hh>
8#include <dune/fem/space/common/localinterpolation.hh>
9#include <dune/fem/space/common/localrestrictprolong.hh>
10
11namespace Dune
12{
13
14 namespace Fem
15 {
16
17 namespace Impl
18 {
19 template< class LocalGeometry, class LF>
20 struct FatherWrapper
21 {
22 typedef std::remove_reference_t< LF > LocalFunctionType;
23 typedef std::remove_reference_t< LocalGeometry > LocalGeometryType;
24 struct Traits
25 {
26 typedef typename LocalFunctionType::DomainType DomainType;
27 typedef typename LocalFunctionType::RangeType RangeType;
28 };
29 typedef typename LocalFunctionType::EntityType EntityType;
30 typedef typename LocalFunctionType::FunctionSpaceType FunctionSpaceType;
31 typedef typename LocalFunctionType::DomainType DomainType;
32 typedef typename LocalFunctionType::RangeType RangeType;
33 typedef typename LocalFunctionType::JacobianRangeType JacobianRangeType;
34 typedef typename LocalFunctionType::HessianRangeType HessianRangeType;
35
36 FatherWrapper ( const LocalGeometryType &localGeo, const LocalFunctionType &lfFather)
37 : localGeo_(localGeo), lfFather_(lfFather) {}
38 template <class Point>
39 void evaluate ( const Point &x, RangeType &y ) const
40 {
41 lfFather_.evaluate( localGeo_.global(coordinate(x)), y);
42 }
43 template <class Quadrature, class RangeArray>
44 void evaluateQuadrature( const Quadrature& quadrature, RangeArray& values ) const
45 {
46 const unsigned int nop = quadrature.nop();
47 values.resize( nop );
48 for( unsigned int qp=0; qp<nop; ++qp)
49 evaluate( quadrature[ qp ], values[ qp ]);
50 }
51
52 const EntityType& entity () const { return lfFather_.entity(); }
53 unsigned int order () const { return lfFather_.order(); }
54
55 bool valid () const { return lfFather_.valid(); }
56
57 private:
58 const LocalGeometryType &localGeo_;
59 const LocalFunctionType &lfFather_;
60 };
61 template< class BasisFunctionSet, class LF>
62 struct SonsWrapper
63 {
64 typedef std::remove_reference_t< LF > LocalFunctionType;
65 typedef std::remove_reference_t< BasisFunctionSet > BasisFunctionSetType;
66 struct Traits
67 {
68 typedef typename LocalFunctionType::DomainType DomainType;
69 typedef typename LocalFunctionType::RangeType RangeType;
70 };
71 typedef typename LocalFunctionType::FunctionSpaceType FunctionSpaceType;
72 typedef typename LocalFunctionType::DomainType DomainType;
73 typedef typename LocalFunctionType::RangeType RangeType;
74 typedef typename LocalFunctionType::JacobianRangeType JacobianRangeType;
75 typedef typename LocalFunctionType::HessianRangeType HessianRangeType;
76 typedef typename LocalFunctionType::EntityType EntityType;
77 typedef typename EntityType::LocalGeometry LocalGeometryType;
78
79 template <class LFFather>
80 SonsWrapper ( const LFFather &father,
81 const std::vector< EntityType >& childEntities,
82 const std::vector< BasisFunctionSetType >& childBasisSets,
83 const std::vector< std::vector<double> >& childDofs )
84 : father_(father.entity())
85 , order_(father.order())
86 , childEntities_(childEntities), childBasisSets_(childBasisSets), childDofs_(childDofs)
87 {}
88 template <class Point>
89 void evaluate ( const Point &x, RangeType &val ) const
90 {
91 val = RangeType(0);
92 RangeType tmp;
93 double weight = 0;
94 for (unsigned int i=0; i<childEntities_.size();++i)
95 {
97 ::general( childEntities_[i].type() );
98 auto y = childEntities_[i].geometryInFather().local(coordinate(x));
99 if( refSon.checkInside( y ) )
100 {
101 childBasisSets_[i].evaluateAll( y, childDofs_[i], tmp );
102 val += tmp;
103 weight += 1.;
104 }
105 }
106 assert( weight > 0); // weight==0 would mean that point was found in none of the children
107 val /= weight;
108 }
109 template <class Quadrature, class RangeArray>
110 void evaluateQuadrature( const Quadrature& quadrature, RangeArray& values ) const
111 {
112 const unsigned int nop = quadrature.nop();
113 values.resize( nop );
114 for( unsigned int qp=0; qp<nop; ++qp)
115 evaluate( quadrature[ qp ], values[ qp ]);
116 }
117 const EntityType& entity () const { return father_; }
118 unsigned int order () const { return order_; }
119
120 bool valid() const { return true; }
121
122 private:
123 const EntityType &father_;
124 unsigned int order_;
125 const std::vector< EntityType >& childEntities_;
126 const std::vector< BasisFunctionSetType >& childBasisSets_;
127 const std::vector< std::vector<double> >& childDofs_;
128 };
129
130 // a detailed description is given in MR308
131 // https://gitlab.dune-project.org/dune-fem/dune-fem/merge_requests/308
132 template< class LFESpace >
133 struct DefaultLocalRestrictProlongLFE
134 {
135 typedef LFESpace DiscreteFunctionSpaceType;
136 typedef DefaultLocalRestrictProlongLFE< DiscreteFunctionSpaceType > ThisType;
137
138 typedef typename DiscreteFunctionSpaceType::DomainFieldType DomainFieldType;
139 typedef typename DiscreteFunctionSpaceType::BasisFunctionSetType BasisFunctionSetType;
140 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
141 typedef typename EntityType::LocalGeometry LocalGeometryType;
142 typedef typename EntityType::EntitySeed EntitySeedType;
143
144 DefaultLocalRestrictProlongLFE (const DiscreteFunctionSpaceType &space)
145 : space_( space ),
146 interpolation_( space_ ),
147 childSeeds_(0), childDofs_(0)
148 {}
149
156 void setFatherChildWeight ( const DomainFieldType &weight )
157 {
158 }
159
161 template< class LFFather, class LFSon, class LocalGeometry >
162 void restrictLocal ( LFFather &lfFather, const LFSon &lfSon,
163 const LocalGeometry &geometryInFather, bool initialize ) const
164 {
165 assert( lfFather.numDofs() == lfSon.numDofs() );
166
167 if (initialize)
168 {
169 childSeeds_.resize(0);
170 childDofs_.resize(0);
171 }
172
173 childSeeds_.push_back(lfSon.entity().seed());
174 childDofs_.push_back(std::vector<double>(lfSon.size()));
175 std::vector<double>& chDofs = childDofs_.back();
176 const unsigned int numDofs = lfSon.size();
177 for (unsigned int i=0;i<numDofs; ++i )
178 chDofs[i] = lfSon[i];
179 }
180
181 template <class LFFather>
182 void restrictFinalize( LFFather &lfFather ) const
183 {
184 std::vector< EntityType > childEntities(childSeeds_.size());
185 std::vector< BasisFunctionSetType > childBasisSets(childSeeds_.size());
186 const unsigned int cSize = childSeeds_.size();
187 for (unsigned int i=0; i<cSize; ++i)
188 {
189 childEntities[i] = space_.gridPart().entity( childSeeds_[i] );
190 childBasisSets[i] = space_.basisFunctionSet( childEntities[i] );
191 }
192
193
194 // bind interpolation object to father
195 auto guard = bindGuard( interpolation_, lfFather.entity() );
196
197 typedef Impl::SonsWrapper<BasisFunctionSetType, LFFather> SonsWrapperType;
198 SonsWrapperType sonsWrapper( lfFather, childEntities, childBasisSets, childDofs_ );
199
200 // call interpolation
201 interpolation_( sonsWrapper, lfFather );
202 }
203
205 template< class LFFather, class LFSon, class LocalGeometry >
206 void prolongLocal ( const LFFather &lfFather, LFSon &lfSon,
207 const LocalGeometry &geometryInFather, bool initialize ) const
208 {
209 assert( lfFather.numDofs() == lfSon.numDofs() );
210
211 typedef Impl::FatherWrapper<LocalGeometry,LFFather> FatherWrapperType;
212 FatherWrapperType fatherWrapper(geometryInFather,lfFather);
213
214 // bind interpolation object to father
215 auto guard = bindGuard( interpolation_, lfSon.entity() );
216
217 // call interpolation
218 interpolation_( fatherWrapper, lfSon );
219 }
220
222 bool needCommunication () const { return true; }
223
224 protected:
225 template< class Entity >
226 static DomainFieldType calcWeight ( const Entity &father, const Entity &son )
227 {
228 return son.geometry().volume() / father.geometry().volume();
229 }
230 const DiscreteFunctionSpaceType &space_;
231 mutable LocalInterpolation< DiscreteFunctionSpaceType > interpolation_;
232
233 mutable std::vector< EntitySeedType > childSeeds_;
234 mutable std::vector< std::vector<double> > childDofs_;
235
236 mutable std::vector< double > tmpDofs_;
237 };
238 } // namespce Impl
239
240 template< class LFEMap, class FunctionSpace, class Storage >
241 class DefaultLocalRestrictProlong< LocalFiniteElementSpace< LFEMap, FunctionSpace, Storage > >
242 : public Impl::DefaultLocalRestrictProlongLFE
243 < LocalFiniteElementSpace< LFEMap, FunctionSpace, Storage > >
244 {
245 public:
246 typedef Impl::DefaultLocalRestrictProlongLFE
247 < LocalFiniteElementSpace< LFEMap, FunctionSpace, Storage > > BaseType;
248 using BaseType::BaseType;
249 };
250 template< class LFEMap, class FunctionSpace, class Storage >
251 class DefaultLocalRestrictProlong< DiscontinuousLocalFiniteElementSpace< LFEMap, FunctionSpace, Storage > >
252 : public Impl::DefaultLocalRestrictProlongLFE
253 < DiscontinuousLocalFiniteElementSpace< LFEMap, FunctionSpace, Storage > >
254
255 {
256 public:
257 typedef Impl::DefaultLocalRestrictProlongLFE
258 < DiscontinuousLocalFiniteElementSpace< LFEMap, FunctionSpace, Storage > > BaseType;
259 using BaseType::BaseType;
260 };
261 } // namespace Fem
262
263} // namespace Dune
264
265#endif // #ifndef DUNE_FEM_LOCALRESTRICTPROLONG_HH
A vector valued function space.
Definition: functionspace.hh:60
actual interface class for quadratures
This file implements a dense matrix with dynamic numbers of rows and columns.
Dune namespace.
Definition: alignedallocator.hh:13
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 27, 22:35, 2025)