3 #ifndef DUNE_LOCALFUNCTIONS_COMMON_LOCALFINITEELEMENTVARIANTCACHE_HH
4 #define DUNE_LOCALFUNCTIONS_COMMON_LOCALFINITEELEMENTVARIANTCACHE_HH
11 #include <dune/common/std/type_traits.hh>
12 #include <dune/common/exceptions.hh>
13 #include <dune/common/typelist.hh>
14 #include <dune/common/hybridutilities.hh>
16 #include <dune/geometry/type.hh>
17 #include <dune/geometry/typeindex.hh>
30 template<std::
size_t dim>
31 struct FixedDimLocalGeometryTypeIndex {
32 inline static std::size_t index(
const GeometryType >)
35 DUNE_THROW(Dune::RangeError,
"Asking for dim=" << dim <<
" specific index of GeometryType with dimension " << gt.dim());
36 return LocalGeometryTypeIndex::index(gt);
68 template<
class LFEImplTuple>
69 struct GenerateLFEVariant;
71 template<
class Index,
class... LFEImpl>
72 struct GenerateLFEVariant<std::tuple<std::pair<Index, LFEImpl>...>>
74 using type = UniqueTypes_t<LocalFiniteElementVariant, decltype(std::declval<LFEImpl>()())...>;
77 using Base::getImplementations;
79 using Implementations = decltype(std::declval<Base>().getImplementations());
96 template<
class... Args>
98 Base(std::forward<Args>(args)...)
100 Dune::Hybrid::forEach(getImplementations(), [&,
this](
auto feImpl) {
101 auto implIndex = feImpl.first;
102 if (cache_.size() < implIndex+1)
103 cache_.resize(implIndex+1);
104 cache_[implIndex] = feImpl.second();
118 template<
class... Key>
119 const auto&
get(
const Key&... key)
const
121 auto implIndex = index(key...);
122 if (implIndex >= cache_.size())
123 DUNE_THROW(Dune::RangeError,
"There is no LocalFiniteElement of the requested type.");
124 if (not(cache_[implIndex]))
125 DUNE_THROW(Dune::RangeError,
"There is no LocalFiniteElement of the requested type.");
126 return cache_[implIndex];
130 std::vector<FiniteElementType> cache_;
Definition: bdfmcube.hh:16
A cache storing a compile time selection of local finite element implementations.
Definition: localfiniteelementvariantcache.hh:66
LocalFiniteElementVariantCache(Args &&... args)
Default constructor.
Definition: localfiniteelementvariantcache.hh:97
LocalFiniteElementVariantCache(LocalFiniteElementVariantCache &&other)=default
Move constructor.
LocalFiniteElementVariantCache(const LocalFiniteElementVariantCache &other)=default
Copy constructor.
const auto & get(const Key &... key) const
Get the LocalFiniteElement for the given key data.
Definition: localfiniteelementvariantcache.hh:119
typename GenerateLFEVariant< Implementations >::type FiniteElementType
Type of exported LocalFiniteElement's.
Definition: localfiniteelementvariantcache.hh:90