Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
Dune::Fufem::Forms::CacheManager< CT, dimension > Class Template Reference

A class for managing caches of different types. More...

#include <dune/fufem/forms/shapefunctioncache.hh>

Inheritance diagram for Dune::Fufem::Forms::CacheManager< CT, dimension >:
Inheritance graph

Public Types

using QuadratureRule = Dune::QuadratureRule< CT, dimension >
 
using size_type = std::size_t
 

Public Member Functions

 CacheManager ()=default
 
 CacheManager (CacheManager &&other)=default
 
 CacheManager (const CacheManager &other)=default
 
CacheManageroperator= (const CacheManager &)=delete
 
CacheManageroperator= (CacheManager &&)=delete
 
void clear ()
 Clear all stored data.
 
const QuadratureRulerule () const
 Obtain the associated quadrature rule.
 
void setRule (const QuadratureRule &rule)
 Set the associated quadrature rule for all stored caches.
 
void invalidate ()
 Invalidate all stores caches.
 
void report () const
 
template<class Cache >
size_type registerCache (UniqueCacheId uniqueCacheId, Cache &&cache)
 Register a new cache.
 
template<class Cache >
auto & getCache (size_type index)
 Obtain a registered cache.
 

Detailed Description

template<class CT, int dimension>
class Dune::Fufem::Forms::CacheManager< CT, dimension >

A class for managing caches of different types.

This class can store a collection of caches of different type using type erasure. Each stored cache is identified using a UniqueCacheId. A cache object is stored in the CacheManager by calling cacheManager.registerCache(uniqueCacheId, cache). Later calls with the same uniqueCacheId will not store a new instance but reuse the existing one.

While registering the caches is in general not critical, requesting existing caches happens inside of local loops. Thus this class is optimized for fast retrieval of stored caches. To avoid a map lookup, all caches are stored in a plain vector and accessed by an index. The index of the newly stored or reused cache is returned by the registerCache() method.

A stored cache can be queried using cacheManager.getCache<Cache>(index). Notice that the template parameter is needed in order to cast the type-erased stored cache to the actual implementation class type.

This class provides the interface of a cache itself and is designed for being stored inside of a MultipleQuadratureCache. It is especially copy-constructible. Copying a CacheManager will create copies of all stored caches preserving the exact erased type and indices. Thus the following is guaranteed to work (and actually the intended usage): Register caches in one CacheManager A and store the obtained indices. Create a copy B of A. Set a different QuadratureRule for B. Obtain caches from B with the indices obtained while registering in A.

Member Typedef Documentation

◆ QuadratureRule

template<class CT , int dimension>
using Dune::Fufem::Forms::CacheManager< CT, dimension >::QuadratureRule = Dune::QuadratureRule<CT, dimension>

◆ size_type

template<class CT , int dimension>
using Dune::Fufem::Forms::CacheManager< CT, dimension >::size_type = std::size_t

Constructor & Destructor Documentation

◆ CacheManager() [1/3]

template<class CT , int dimension>
Dune::Fufem::Forms::CacheManager< CT, dimension >::CacheManager ( )
default

◆ CacheManager() [2/3]

template<class CT , int dimension>
Dune::Fufem::Forms::CacheManager< CT, dimension >::CacheManager ( CacheManager< CT, dimension > &&  other)
default

◆ CacheManager() [3/3]

template<class CT , int dimension>
Dune::Fufem::Forms::CacheManager< CT, dimension >::CacheManager ( const CacheManager< CT, dimension > &  other)
default

Member Function Documentation

◆ clear()

template<class CT , int dimension>
void Dune::Fufem::Forms::CacheManager< CT, dimension >::clear ( )
inline

Clear all stored data.

◆ getCache()

template<class CT , int dimension>
template<class Cache >
auto & Dune::Fufem::Forms::CacheManager< CT, dimension >::getCache ( size_type  index)
inline

Obtain a registered cache.

Template Parameters
CacheType of the stored cache
Parameters
indexIndex of the stored cache as returned by registerCache()
Returns
The cache stored under the given index casted to the provided type.

Using a Cache type other than the one used when storing the cache is undefined behaviour.

◆ invalidate()

template<class CT , int dimension>
void Dune::Fufem::Forms::CacheManager< CT, dimension >::invalidate ( )
inline

Invalidate all stores caches.

◆ operator=() [1/2]

template<class CT , int dimension>
CacheManager & Dune::Fufem::Forms::CacheManager< CT, dimension >::operator= ( CacheManager< CT, dimension > &&  )
delete

◆ operator=() [2/2]

template<class CT , int dimension>
CacheManager & Dune::Fufem::Forms::CacheManager< CT, dimension >::operator= ( const CacheManager< CT, dimension > &  )
delete

◆ registerCache()

template<class CT , int dimension>
template<class Cache >
size_type Dune::Fufem::Forms::CacheManager< CT, dimension >::registerCache ( UniqueCacheId  uniqueCacheId,
Cache &&  cache 
)
inline

Register a new cache.

Parameters
uniqueCacheIdUnique identifier of the cache to be registered
cacheCache to be registered
Returns
Index of the stored cache

If there is no cache registered with the provided uniqueCacheId, this will store a copy of the provided cache under the id. If there Otherwise the already stored cache is reused and the provided argument is ignored. In any case the returned index can be used to obtain the cache later.

◆ report()

template<class CT , int dimension>
void Dune::Fufem::Forms::CacheManager< CT, dimension >::report ( ) const
inline

◆ rule()

template<class CT , int dimension>
const QuadratureRule & Dune::Fufem::Forms::CacheManager< CT, dimension >::rule ( ) const
inline

Obtain the associated quadrature rule.

◆ setRule()

template<class CT , int dimension>
void Dune::Fufem::Forms::CacheManager< CT, dimension >::setRule ( const QuadratureRule rule)
inline

Set the associated quadrature rule for all stored caches.


The documentation for this class was generated from the following file: