DUNE-FEM (unstable)

basesetlocalkeystorage.hh
1#ifndef DUNE_FEM_BASESETLOCALKEYSTORAGE_HH
2#define DUNE_FEM_BASESETLOCALKEYSTORAGE_HH
3
4#include <utility>
5
7
10
11#include <dune/fem/common/forloop.hh>
12#include <dune/fem/space/common/allgeomtypes.hh>
13#include <dune/fem/storage/singletonlist.hh>
14
15
16namespace Dune
17{
18
19 namespace Fem
20 {
21
24 template< class Entry >
26 {
27 // interface class for factory
28 class FactoryIF
29 {
30 protected:
31 FactoryIF () {}
32 public:
33 virtual ~FactoryIF () {}
34 virtual Entry* getObject( const GeometryType& geomType ) const = 0;
35 virtual void removeObjects( std::vector<Entry*>& entryStorage ) const = 0;
36 virtual FactoryIF* clone() const = 0;
37 };
38
39 // factory implementation depends on type of singleton provider
40 template <class SingletonProvider>
41 class FactoryImpl : public FactoryIF
42 {
43 public:
44 FactoryImpl() {}
45
46 Entry* getObject( const GeometryType& geomType ) const
47 {
48 return & SingletonProvider :: getObject( geomType );
49 }
50
51 void removeObjects( std::vector<Entry*>& entryStorage ) const
52 {
53 const size_t size = entryStorage.size();
54 for( size_t i=0; i<size; ++i )
55 {
56 if( entryStorage[ i ] )
57 {
58 SingletonProvider :: removeObject( *(entryStorage[ i ]) );
59 entryStorage[ i ] = 0 ;
60 }
61 }
62 }
63
64 virtual FactoryIF* clone() const { return new FactoryImpl<SingletonProvider> (); }
65 };
66
67 // pointer to apropriate factory
68 const FactoryIF* factory_;
69 // vector caching singleton pointers
70 std::vector< Entry* > entryStorage_;
71 public:
72 // export value type confomring to std::vector
73 typedef Entry value_type ;
74
75 // default constructor
77 : factory_( 0 )
78 , entryStorage_()
79 {}
80
83 : factory_( other.factory_ ? other.factory_->clone() : 0 )
84 , entryStorage_( other.entryStorage_.size(), ( Entry * ) 0 )
85 {
86 // make a copy of the vector
87 const size_t size = entryStorage_.size();
88 for( size_t i=0; i<size; ++i )
89 {
90 Entry* otherEntry = other.entryStorage_[ i ];
91 if( otherEntry )
92 {
93 // we need the interface method geometry
94 // (on base function sets and compiled local keys )
95 entryStorage_[ i ] = factory_->getObject( otherEntry->type() );
96 }
97 }
98 }
99
102 : factory_( other.factory_ ),
103 entryStorage_( std::move( other.entryStorage_ ) )
104 {
105 other.factory_ = nullptr;
106 other.entryStorage_.clear();
107 }
108
111 {
112 if( entryStorage_.size() > 0 )
113 {
114 factory_->removeObjects( entryStorage_ );
115 }
116
117 delete factory_;
118 factory_ = 0;
119 }
120
121 // get maxSize of compiled keys
122 unsigned int maxSize() const
123 {
124 unsigned int maxSize = 0;
125 const size_t size = entryStorage_.size() ;
126 for( size_t i=0; i<size; ++i)
127 {
128 if( entryStorage_[ i ] )
129 {
130 unsigned int enSize = entryStorage_[ i ]->size();
131 maxSize = std::max( enSize , maxSize );
132 }
133 }
134 return maxSize;
135 }
136
138 template <class SingletonProvider>
139 bool insert( const GeometryType geomType )
140 {
141 // create factory if not existing yet
142 if( factory_ == 0 )
143 {
144 factory_ = new FactoryImpl< SingletonProvider > ();
145 }
146
147 // check that type of factory is correct
148 assert( dynamic_cast< const FactoryImpl< SingletonProvider >* > ( factory_ ) != 0 );
149
150 // get geometry type index
151 const size_t geomIndex = index( geomType ) ;
152
153 if( entryStorage_.size() <= geomIndex )
154 entryStorage_.resize( geomIndex + 1, (Entry* ) 0 );
155
156 assert( geomIndex < entryStorage_.size() );
157
158 // if entry is still not used, insert it
159 if( entryStorage_[ geomIndex ] == 0 )
160 {
161 entryStorage_[ geomIndex ] = factory_->getObject( geomType );
162 return true ;
163 }
164 return false ;
165 }
166
168 bool exists( const GeometryType& geomType ) const
169 {
170 if( index( geomType ) < static_cast< int >( entryStorage_.size() ) )
171 return (entryStorage_[ index( geomType ) ] != 0) ;
172 else
173 return false;
174 }
175
177 const Entry& operator [] ( const GeometryType& geomType ) const
178 {
179 // assert( factory_ );
180 assert( index( geomType ) < static_cast< int >( entryStorage_.size() ) );
181 assert( entryStorage_[ index( geomType ) ] != 0 );
182 return *( entryStorage_[ index( geomType ) ]);
183 }
184 protected:
185 int index( const GeometryType& geomType ) const
186 {
187 return LocalGeometryTypeIndex::index( geomType );
188 }
189 };
190
191
192
195 template< class CompiledLocalKey, unsigned int minPolOrder, unsigned int maxPolOrder >
197 {
198 public:
199 // type of compiled local key
200 typedef CompiledLocalKey CompiledLocalKeyType;
201
204
205 // vector containing storages for each polynomial order
206 typedef std::vector< LocalKeyStorageType > LocalKeyVectorType;
207
208 protected:
209 enum { numOrders = maxPolOrder - minPolOrder + 1 };
210
211 template <int pOrd>
212 struct ConstructCompiledLocalKeys
213 {
220 {
221 public:
223 static CompiledLocalKeyType* createObject( const GeometryType& type )
224 {
225 return new CompiledLocalKeyType( type, pOrd );
226 }
227
229 static void deleteObject( CompiledLocalKeyType* obj )
230 {
231 delete obj;
232 }
233 };
234
235 static void apply( LocalKeyVectorType& compiledLocalKeys,
236 const GeometryType& geometryType )
237 {
238 const size_t k = pOrd ;
239
241 typedef SingletonList
242 < GeometryType, CompiledLocalKeyType, CompiledLocalKeyFactory >
243 CompiledLocalKeySingletonProviderType;
244
245 // insert compiled local key
246 compiledLocalKeys[ k - minPolOrder ].template insert< CompiledLocalKeySingletonProviderType > ( geometryType );
247 }
248 };
249
250 protected:
251 // all lagrange point sets for available geometry types
252 LocalKeyVectorType compiledLocalKeys_ ;
253
254 private:
255 CompiledLocalKeyContainer( const CompiledLocalKeyContainer& );
256
257 public:
258 template <class GridPart>
259 CompiledLocalKeyContainer( const GridPart& gridPart )
260 : compiledLocalKeys_( numOrders )
261 {
262 typedef typename GridPart :: IndexSetType IndexSetType ;
263 typedef typename GridPart :: GridType GridType ;
264 const IndexSetType &indexSet = gridPart.indexSet();
265
266 // get all available geometry types
267 AllGeomTypes< IndexSetType, GridType > allGeometryTypes( indexSet );
268 const std :: vector< GeometryType >& geometryTypes
269 = allGeometryTypes.geomTypes( 0 );
270
271 // create compiled local keys
272 for( unsigned int i = 0; i < geometryTypes.size(); ++i )
273 {
274 Fem::ForLoop< ConstructCompiledLocalKeys, minPolOrder, maxPolOrder > ::
275 apply( compiledLocalKeys_, geometryTypes[ i ] );
276 }
277 }
278
285 inline const LocalKeyStorageType& compiledLocalKeys( const int order ) const
286 {
287 assert( order - minPolOrder >= 0 );
288 assert( int( order - minPolOrder ) < int( compiledLocalKeys_.size() ) );
289 return compiledLocalKeys_[ order - minPolOrder ];
290 }
291
299 inline const CompiledLocalKeyType &compiledLocalKey( const GeometryType& type, const int order ) const
300 {
301 return compiledLocalKeys( order )[ type ];
302 }
303 };
304
305 } // namespace Fem
306
307} // namespace Dune
308
309#endif // DUNE_FEM_BASESETLOCALKEYSTORAGE_HH
storage class for base function set pointer and compiled local key pointers
Definition: basesetlocalkeystorage.hh:26
BaseSetLocalKeyStorage(BaseSetLocalKeyStorage &&other)
move constructor
Definition: basesetlocalkeystorage.hh:101
BaseSetLocalKeyStorage(const BaseSetLocalKeyStorage &other)
copy constructor
Definition: basesetlocalkeystorage.hh:82
bool insert(const GeometryType geomType)
insert entry to storage for given geometry type
Definition: basesetlocalkeystorage.hh:139
bool exists(const GeometryType &geomType) const
return true if an entry for this geometry type exists
Definition: basesetlocalkeystorage.hh:168
const Entry & operator[](const GeometryType &geomType) const
access to stored entry with given geometry type
Definition: basesetlocalkeystorage.hh:177
~BaseSetLocalKeyStorage()
destructor
Definition: basesetlocalkeystorage.hh:110
CompiledLocalKeyFactory method createObject and deleteObject for the SingletonList.
Definition: basesetlocalkeystorage.hh:220
static void deleteObject(CompiledLocalKeyType *obj)
delete BaseFunctionSet
Definition: basesetlocalkeystorage.hh:229
static CompiledLocalKeyType * createObject(const GeometryType &type)
create new BaseFunctionSet
Definition: basesetlocalkeystorage.hh:223
class for storage local keys for a given range of polynomial order and available geometry type
Definition: basesetlocalkeystorage.hh:197
const CompiledLocalKeyType & compiledLocalKey(const GeometryType &type, const int order) const
provide access to the compiled local keys for a geometry type and polynomial order
Definition: basesetlocalkeystorage.hh:299
BaseSetLocalKeyStorage< CompiledLocalKeyType > LocalKeyStorageType
type of storage class for compiled local keys
Definition: basesetlocalkeystorage.hh:203
const LocalKeyStorageType & compiledLocalKeys(const int order) const
provide access to all compiled local keys for a given polynomial order
Definition: basesetlocalkeystorage.hh:285
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
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type within its dimension.
Definition: typeindex.hh:73
A few common exception classes.
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
STL namespace.
A unique label for each type of element that can occur in a grid.
Helper classes to provide indices for geometrytypes for use in a vector.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)