DUNE-FEM (unstable)

space.hh
1#ifndef DUNE_FEM_SPACE_LOCALFINITEELEMENT_SPACE_HH
2#define DUNE_FEM_SPACE_LOCALFINITEELEMENT_SPACE_HH
3
4#include <cassert>
5
6#include <memory>
7#include <utility>
8#include <vector>
9
10#include <dune/geometry/type.hh>
11
12#include <dune/fem/common/hybrid.hh>
13
14#include <dune/fem/gridpart/common/capabilities.hh>
15#include <dune/fem/space/basisfunctionset/default.hh>
16#include <dune/fem/space/basisfunctionset/transformed.hh>
17#include <dune/fem/space/common/defaultcommhandler.hh>
18#include <dune/fem/space/common/discretefunctionspace.hh>
19#include <dune/fem/space/common/functionspace.hh>
20#include <dune/fem/space/common/localinterpolation.hh>
21#include <dune/fem/space/mapper/compile.hh>
22#include <dune/fem/space/mapper/indexsetdofmapper.hh>
24#include <dune/fem/space/shapefunctionset/selectcaching.hh>
25#include <dune/fem/space/shapefunctionset/vectorial.hh>
26
27#include <dune/fem/space/localfiniteelement/shapefunctionset.hh>
28#include <dune/fem/space/localfiniteelement/capabilities.hh>
29#include <dune/fem/space/localfiniteelement/interpolation.hh>
30#include <dune/fem/space/localfiniteelement/localrestrictprolong.hh>
31
32namespace Dune
33{
34
35 namespace Fem
36 {
37
38 // LocalFiniteElementSpaceTraits
39 // -----------------------------
40
41 template< class LFEMap, class FunctionSpace, class Storage >
42 struct LocalFiniteElementSpaceTraits
43 {
44 typedef LocalFiniteElementSpace< LFEMap, FunctionSpace, Storage > DiscreteFunctionSpaceType;
45
46 typedef LFEMap LFEMapType;
47
48 typedef typename LFEMapType::GridPartType GridPartType;
49 typedef typename LFEMapType::LocalFiniteElementType LocalFiniteElementType;
50
51 typedef GridFunctionSpace< GridPartType, FunctionSpace > FunctionSpaceType;
52
53 static constexpr int codimension = 0;
54 static constexpr bool isScalar = LocalFiniteElementType::Traits::LocalBasisType::Traits::dimRange==1;
55
56 typedef std::conditional_t<isScalar,
57 Hybrid::IndexRange< int, FunctionSpace::dimRange >,
58 Hybrid::IndexRange< int, 1 >
59 > LocalBlockIndices;
60
61 private:
62 typedef typename GridPartType::template Codim< codimension >::EntityType EntityType;
63
64 // -1 is default value if pointSetId not available
65 static const int pointSetId = detail::SelectPointSetId< LFEMap >::value;
66
67 public:
68 // typedef Dune::Fem::IndexSetDofMapper< GridPartType, LagrangeLocalDofMapping< GridPartType > > BlockMapperType;
69 typedef Dune::Fem::IndexSetDofMapper< GridPartType > BlockMapperType;
70
71 typedef LocalFunctionsShapeFunctionSet< typename LocalFiniteElementType::Traits::LocalBasisType, pointSetId > LocalFunctionsShapeFunctionSetType;
72 typedef SelectCachingShapeFunctionSet< LocalFunctionsShapeFunctionSetType, Storage > StoredShapeFunctionSetType;
73
74 typedef ShapeFunctionSetProxy< StoredShapeFunctionSetType > ShapeFunctionSetProxyType;
75 // only extend to vector valued in case that the original space is scalar
76 typedef std::conditional_t<isScalar,
77 VectorialShapeFunctionSet< ShapeFunctionSetProxyType, typename FunctionSpaceType::RangeType >,
78 ShapeFunctionSetProxyType
79 > ShapeFunctionSetType;
80
81 private:
82 template< class LFEM >
83 static TransformedBasisFunctionSet< EntityType, ShapeFunctionSetType, typename LFEM::TransformationType > basisFunctionSet ( const LFEM & );
84
85 static DefaultBasisFunctionSet< EntityType, ShapeFunctionSetType > basisFunctionSet ( ... );
86
87 public:
88 typedef decltype( basisFunctionSet( std::declval< const LFEMapType & >() ) ) BasisFunctionSetType;
89
90 template< class DiscreteFunction, class Operation = DFCommunicationOperation::Add >
91 struct CommDataHandle
92 {
93 typedef DefaultCommunicationHandler< DiscreteFunction, Operation > Type;
94 typedef Operation OperationType;
95 };
96 };
97
98
99
100 // LocalFiniteElementSpace
101 // -----------------------
102
112 template< class LFEMap, class FunctionSpace, class Storage >
114 : public DiscreteFunctionSpaceDefault< LocalFiniteElementSpaceTraits< LFEMap, FunctionSpace, Storage > >
115 {
118 BaseType;
119
120 public:
121 typedef typename BaseType::Traits Traits;
122 typedef typename BaseType::FunctionSpaceType FunctionSpaceType;
123
124 typedef typename BaseType::GridPartType GridPartType;
125 typedef typename BaseType::EntityType EntityType;
126 typedef typename BaseType::IntersectionType IntersectionType;
127
128 typedef typename BaseType::Traits::ShapeFunctionSetType ShapeFunctionSetType;
129 typedef typename BaseType::BasisFunctionSetType BasisFunctionSetType;
130
131 typedef typename BaseType::BlockMapperType BlockMapperType;
132
133 typedef typename Traits::LocalFiniteElementType LocalFiniteElementType;
134
135 typedef typename Traits::LFEMapType LFEMapType;
136
137 private:
138 typedef typename LocalFiniteElementType::Traits::LocalBasisType LocalBasisType;
139 typedef typename LocalFiniteElementType::Traits::LocalInterpolationType LocalInterpolationType;
140 typedef typename LocalFiniteElementType::Traits::LocalCoefficientsType LocalCoefficientsType;
141
142 typedef typename LFEMapType::KeyType KeyType;
143
144 typedef typename Traits::LocalFunctionsShapeFunctionSetType LocalFunctionsShapeFunctionSetType;
145
146 struct LFEMapFactory
147 {
148 static LFEMapType *createObject ( std::pair< GridPartType *, KeyType > key ) { return new LFEMapType( *key.first, key.second ); }
149 static void deleteObject ( LFEMapType *object ) { delete object; }
150 };
151
153
154 typedef typename Traits::StoredShapeFunctionSetType StoredShapeFunctionSetType;
155 typedef std::vector< std::unique_ptr< StoredShapeFunctionSetType > > StoredShapeFunctionSetVectorType;
156
157 struct StoredShapeFunctionSetVectorFactory
158 {
159 static StoredShapeFunctionSetVectorType *createObject ( LFEMapType *lfeMap ) { return new StoredShapeFunctionSetVectorType( lfeMap->size() ); }
160 static void deleteObject ( StoredShapeFunctionSetVectorType *object ) { delete object; }
161 };
162
164
165 struct BlockMapperSingletonFactory
166 {
167 static BlockMapperType *createObject ( LFEMapType *lfeMap )
168 {
169 return new BlockMapperType( lfeMap->gridPart(), [ lfeMap ] ( const auto &refElement ) {
170 if( lfeMap->hasCoefficients( refElement.type() ) )
171 return Dune::Fem::compile( refElement, lfeMap->localCoefficients( refElement.type() ) );
172 else
173 return Dune::Fem::DofMapperCode();
174 } );
175 }
176
177 static void deleteObject ( BlockMapperType *object ) { delete object; }
178 };
179
181
182 public:
183 //- internal implementation
184 typedef LocalFiniteElementInterpolation< ThisType, LocalInterpolationType, Traits::isScalar > InterpolationImplType;
185
187 typedef LocalFEInterpolationWrapper< ThisType > InterpolationType;
188
189 using BaseType::order;
190
191 template< class GridPart, std::enable_if_t< std::is_same< GridPart, GridPartType >::value &&std::is_same< KeyType, std::tuple<> >::value, int > = 0 >
192 explicit LocalFiniteElementSpace ( GridPart &gridPart,
193 const InterfaceType commInterface = InteriorBorder_All_Interface,
194 const CommunicationDirection commDirection = ForwardCommunication )
195 : BaseType( gridPart, commInterface, commDirection ),
196 lfeMap_( &LFEMapProviderType::getObject( std::make_pair( &gridPart, KeyType() ) ) ),
197 storedShapeFunctionSetVector_( &StoredShapeFunctionSetVectorProviderType::getObject( lfeMap_.get() ) ),
198 blockMapper_( &BlockMapperProviderType::getObject( lfeMap_.get() ) )
199 {}
200
201 template< class GridPart, std::enable_if_t< std::is_same< GridPart, GridPartType >::value && !std::is_same< KeyType, std::tuple<> >::value, int > = 0 >
202 explicit LocalFiniteElementSpace ( GridPart &gridPart, const KeyType &key,
203 const InterfaceType commInterface = InteriorBorder_All_Interface,
204 const CommunicationDirection commDirection = ForwardCommunication )
205 : BaseType( gridPart, commInterface, commDirection ),
206 lfeMap_( &LFEMapProviderType::getObject( std::make_pair( &gridPart, key ) ) ),
207 storedShapeFunctionSetVector_( &StoredShapeFunctionSetVectorProviderType::getObject( lfeMap_.get() ) ),
208 blockMapper_( &BlockMapperProviderType::getObject( lfeMap_.get() ) )
209 {}
210
211 template< class GridPart, std::enable_if_t< std::is_same< GridPart, GridPartType >::value && !std::is_same< KeyType, std::tuple<> >::value, int > = 0 >
212 explicit LocalFiniteElementSpace ( GridPart &gridPart,
213 const InterfaceType commInterface = InteriorBorder_All_Interface,
214 const CommunicationDirection commDirection = ForwardCommunication )
215 : BaseType( gridPart, commInterface, commDirection ),
216 lfeMap_( &LFEMapProviderType::getObject( std::make_pair( &gridPart, KeyType(1) ) ) ),
217 storedShapeFunctionSetVector_( &StoredShapeFunctionSetVectorProviderType::getObject( lfeMap_.get() ) ),
218 blockMapper_( &BlockMapperProviderType::getObject( lfeMap_.get() ) )
219 {}
220 LocalFiniteElementSpace ( const ThisType & ) = delete;
221 LocalFiniteElementSpace ( ThisType && ) = delete;
222
223 ThisType &operator= ( const ThisType & ) = delete;
224 ThisType &operator= ( ThisType && ) = delete;
225
228
230 BasisFunctionSetType basisFunctionSet ( const EntityType &entity ) const
231 {
232 return BasisFunctionSetType( entity, shapeFunctionSet( entity ) );
233 }
234
242 ShapeFunctionSetType shapeFunctionSet ( const EntityType &entity ) const
243 {
244 return getShapeFunctionSet( (*lfeMap_)( entity ), entity.type() );
245 }
246
248 bool continuous () const { return true; }
249
251 bool continuous ( const IntersectionType &intersection ) const { return true; }
252
254 int order () const { return lfeMap_->order(); }
255
257 bool multipleGeometryTypes () const { return true; }
258
260 BlockMapperType &blockMapper () const { assert( blockMapper_ ); return *blockMapper_; }
261
267 {
268 return InterpolationType( *this );
269 }
270
276 [[deprecated("Use LocalInterpolation( space ) instead!")]]
277 InterpolationImplType interpolation ( const EntityType &entity ) const
278 {
279 return localInterpolation( entity );
280 }
281
287 InterpolationImplType localInterpolation ( const EntityType &entity ) const
288 {
289 auto lfe = (*lfeMap_)( entity );
290 return InterpolationImplType( BasisFunctionSetType( entity, getShapeFunctionSet( lfe, entity.type() ) ), std::get< 2 >( lfe ) );
291 }
292
293 typedef typename LFEMapType::LocalCoefficientsType QuadratureType;
294 const QuadratureType& quadrature ( const GeometryType &type ) const
295 {
296 return (*lfeMap_).localCoefficients(type);
297 }
298
299 private:
300 ShapeFunctionSetType getShapeFunctionSet ( std::tuple< std::size_t, const LocalBasisType &, const LocalInterpolationType & > lfe, const GeometryType &type ) const
301 {
302 auto &storedShapeFunctionSet = (*storedShapeFunctionSetVector_)[ std::get< 0 > ( lfe ) ];
303 if( !storedShapeFunctionSet )
304 storedShapeFunctionSet.reset( new StoredShapeFunctionSetType( type, LocalFunctionsShapeFunctionSetType( std::get< 1 >( lfe ) ) ) );
305 return ShapeFunctionSetType( storedShapeFunctionSet.get() );
306 }
307
308 std::unique_ptr< LFEMapType, typename LFEMapProviderType::Deleter > lfeMap_;
309 std::unique_ptr< StoredShapeFunctionSetVectorType, typename StoredShapeFunctionSetVectorProviderType::Deleter > storedShapeFunctionSetVector_;
310 std::unique_ptr< BlockMapperType, typename BlockMapperProviderType::Deleter > blockMapper_;
311 };
312
313 template< class LFEMap, class FunctionSpace, class Storage, int newRange >
314 struct ToNewDimRangeFunctionSpace<
315 LocalFiniteElementSpace<LFEMap, FunctionSpace, Storage>, newRange>
316 {
317 typedef LocalFiniteElementSpace<LFEMap, typename ToNewDimRangeFunctionSpace<FunctionSpace,newRange>::Type, Storage> Type;
318 };
319 template <class LFEMap, class FunctionSpace, class Storage, class NewFunctionSpace>
320 struct DifferentDiscreteFunctionSpace<
321 LocalFiniteElementSpace<LFEMap,FunctionSpace,Storage>, NewFunctionSpace>
322 {
323 typedef LocalFiniteElementSpace<LFEMap, NewFunctionSpace, Storage > Type;
324 };
325 } // namespace Fem
326
327} // namespace Dune
328
329#endif // #ifndef DUNE_FEM_SPACE_LOCALFINITEELEMENT_SPACE_HH
This is the class with default implementations for discrete function. The methods not marked with hav...
Definition: discretefunctionspace.hh:649
Traits::FunctionSpaceType FunctionSpaceType
type of function space
Definition: discretefunctionspace.hh:194
Traits::BasisFunctionSetType BasisFunctionSetType
type of basis function set of this space
Definition: discretefunctionspace.hh:201
GridPartType::IntersectionType IntersectionType
type of the intersections
Definition: discretefunctionspace.hh:226
int order() const
get global order of space
Definition: discretefunctionspace.hh:346
A vector valued function space.
Definition: functionspace.hh:60
Rannacher-Turek Space.
Definition: space.hh:115
InterpolationImplType localInterpolation(const EntityType &entity) const
return local interpolation
Definition: space.hh:287
BasisFunctionSetType basisFunctionSet(const EntityType &entity) const
get basis function set for given entity
Definition: space.hh:230
int order() const
get global order of space
Definition: space.hh:254
bool multipleGeometryTypes() const
returns true if the grid has more than one geometry type
Definition: space.hh:257
BlockMapperType & blockMapper() const
get a reference to the block mapper
Definition: space.hh:260
InterpolationType interpolation() const
return local interpolation object (uninitialized)
Definition: space.hh:266
bool continuous() const
returns true if the space contains only globally continuous functions
Definition: space.hh:248
bool continuous(const IntersectionType &intersection) const
returns true if the space contains only globally continuous functions
Definition: space.hh:251
ShapeFunctionSetType shapeFunctionSet(const EntityType &entity) const
return shape function set for given entity
Definition: space.hh:242
DFSpaceIdentifier type() const
return type identifier of discrete function space
Definition: space.hh:227
LocalFEInterpolationWrapper< ThisType > InterpolationType
Interpolation object.
Definition: space.hh:187
InterpolationImplType interpolation(const EntityType &entity) const
return local interpolation
Definition: space.hh:277
Singleton list for key/object pairs.
Definition: singletonlist.hh:53
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
DFSpaceIdentifier
enumerator for identification of spaces
Definition: discretefunctionspace.hh:95
@ LocalFiniteElementSpace_id
id for local finite element space
Definition: discretefunctionspace.hh:107
CommunicationDirection
Define a type for communication direction parameter.
Definition: gridenums.hh:170
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
@ ForwardCommunication
communicate as given in InterfaceType
Definition: gridenums.hh:171
@ InteriorBorder_All_Interface
send interior and border, receive all entities
Definition: gridenums.hh:88
Dune namespace.
Definition: alignedallocator.hh:13
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
STL namespace.
Provides a proxy class for pointers to a shape function set.
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 24, 22:29, 2024)