1#ifndef DUNE_FEM_BASESETLOCALKEYSTORAGE_HH
2#define DUNE_FEM_BASESETLOCALKEYSTORAGE_HH
11#include <dune/fem/common/forloop.hh>
12#include <dune/fem/space/common/allgeomtypes.hh>
13#include <dune/fem/storage/singletonlist.hh>
24 template<
class Entry >
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;
40 template <
class SingletonProv
ider>
41 class FactoryImpl :
public FactoryIF
48 return & SingletonProvider :: getObject( geomType );
51 void removeObjects( std::vector<Entry*>& entryStorage )
const
53 const size_t size = entryStorage.size();
54 for(
size_t i=0; i<
size; ++i )
56 if( entryStorage[ i ] )
58 SingletonProvider :: removeObject( *(entryStorage[ i ]) );
59 entryStorage[ i ] = 0 ;
64 virtual FactoryIF* clone()
const {
return new FactoryImpl<SingletonProvider> (); }
68 const FactoryIF* factory_;
70 std::vector< Entry* > entryStorage_;
73 typedef Entry value_type ;
83 : factory_( other.factory_ ? other.factory_->clone() : 0 )
84 , entryStorage_( other.entryStorage_.
size(), ( Entry * ) 0 )
87 const size_t size = entryStorage_.size();
88 for(
size_t i=0; i<
size; ++i )
90 Entry* otherEntry = other.entryStorage_[ i ];
95 entryStorage_[ i ] = factory_->getObject( otherEntry->type() );
102 : factory_( other.factory_ ),
103 entryStorage_(
std::move( other.entryStorage_ ) )
105 other.factory_ =
nullptr;
106 other.entryStorage_.clear();
112 if( entryStorage_.size() > 0 )
114 factory_->removeObjects( entryStorage_ );
122 unsigned int maxSize()
const
124 unsigned int maxSize = 0;
125 const size_t size = entryStorage_.size() ;
126 for(
size_t i=0; i<
size; ++i)
128 if( entryStorage_[ i ] )
130 unsigned int enSize = entryStorage_[ i ]->size();
131 maxSize = std::max( enSize , maxSize );
138 template <
class SingletonProv
ider>
144 factory_ =
new FactoryImpl< SingletonProvider > ();
148 assert(
dynamic_cast< const FactoryImpl< SingletonProvider >*
> ( factory_ ) != 0 );
151 const size_t geomIndex = index( geomType ) ;
153 if( entryStorage_.size() <= geomIndex )
154 entryStorage_.resize( geomIndex + 1, (Entry* ) 0 );
156 assert( geomIndex < entryStorage_.size() );
159 if( entryStorage_[ geomIndex ] == 0 )
161 entryStorage_[ geomIndex ] = factory_->getObject( geomType );
170 if( index( geomType ) <
static_cast< int >( entryStorage_.size() ) )
171 return (entryStorage_[ index( geomType ) ] != 0) ;
180 assert( index( geomType ) <
static_cast< int >( entryStorage_.size() ) );
181 assert( entryStorage_[ index( geomType ) ] != 0 );
182 return *( entryStorage_[ index( geomType ) ]);
195 template<
class CompiledLocalKey,
unsigned int minPolOrder,
unsigned int maxPolOrder >
200 typedef CompiledLocalKey CompiledLocalKeyType;
206 typedef std::vector< LocalKeyStorageType > LocalKeyVectorType;
209 enum { numOrders = maxPolOrder - minPolOrder + 1 };
212 struct ConstructCompiledLocalKeys
225 return new CompiledLocalKeyType( type, pOrd );
238 const size_t k = pOrd ;
242 <
GeometryType, CompiledLocalKeyType, CompiledLocalKeyFactory >
243 CompiledLocalKeySingletonProviderType;
246 compiledLocalKeys[ k - minPolOrder ].template insert< CompiledLocalKeySingletonProviderType > ( geometryType );
252 LocalKeyVectorType compiledLocalKeys_ ;
255 CompiledLocalKeyContainer(
const CompiledLocalKeyContainer& );
258 template <
class Gr
idPart>
259 CompiledLocalKeyContainer(
const GridPart& gridPart )
260 : compiledLocalKeys_( numOrders )
262 typedef typename GridPart :: IndexSetType IndexSetType ;
263 typedef typename GridPart :: GridType GridType ;
264 const IndexSetType &indexSet = gridPart.indexSet();
267 AllGeomTypes< IndexSetType, GridType > allGeometryTypes( indexSet );
268 const std :: vector< GeometryType >& geometryTypes
269 = allGeometryTypes.geomTypes( 0 );
272 for(
unsigned int i = 0; i < geometryTypes.size(); ++i )
274 Fem::ForLoop< ConstructCompiledLocalKeys, minPolOrder, maxPolOrder > ::
275 apply( compiledLocalKeys_, geometryTypes[ i ] );
287 assert( order - minPolOrder >= 0 );
288 assert(
int( order - minPolOrder ) <
int( compiledLocalKeys_.size() ) );
289 return compiledLocalKeys_[ order - minPolOrder ];
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 >)
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
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.