5#ifndef DUNE_LOCALFUNCTIONS_COMMON_LOCALFINITEELEMENTVARIANTCACHE_HH
6#define DUNE_LOCALFUNCTIONS_COMMON_LOCALFINITEELEMENTVARIANTCACHE_HH
13#include <dune/common/std/type_traits.hh>
14#include <dune/common/exceptions.hh>
15#include <dune/common/typelist.hh>
16#include <dune/common/hybridutilities.hh>
18#include <dune/geometry/type.hh>
19#include <dune/geometry/typeindex.hh>
32 template<std::
size_t dim>
33 struct FixedDimLocalGeometryTypeIndex {
34 inline static std::size_t index(
const GeometryType >)
37 DUNE_THROW(Dune::RangeError,
"Asking for dim=" << dim <<
" specific index of GeometryType with dimension " << gt.dim());
38 return LocalGeometryTypeIndex::index(gt);
70 template<
class LFEImplTuple>
71 struct GenerateLFEVariant;
73 template<
class Index,
class... LFEImpl>
74 struct GenerateLFEVariant<std::tuple<std::pair<Index, LFEImpl>...>>
76 using type = UniqueTypes_t<LocalFiniteElementVariant, decltype(std::declval<LFEImpl>()())...>;
79 using Base::getImplementations;
81 using Implementations =
decltype(std::declval<Base>().getImplementations());
98 template<
class... Args>
100 Base(std::forward<Args>(args)...)
102 Dune::Hybrid::forEach(getImplementations(), [&,
this](
auto feImpl) {
103 auto implIndex = feImpl.first;
104 if (cache_.size() < implIndex+1)
105 cache_.resize(implIndex+1);
106 cache_[implIndex] = feImpl.second();
126 template<
class... Key>
127 const auto&
get(
const Key&... key)
const
129 auto implIndex = index(key...);
130 if (implIndex >= cache_.size())
131 DUNE_THROW(Dune::RangeError,
"There is no LocalFiniteElement of the requested type.");
132 if (not(cache_[implIndex]))
133 DUNE_THROW(Dune::RangeError,
"There is no LocalFiniteElement of the requested type.");
134 return cache_[implIndex];
138 std::vector<FiniteElementType> cache_;
Definition bdfmcube.hh:18
A cache storing a compile time selection of local finite element implementations.
Definition localfiniteelementvariantcache.hh:68
LocalFiniteElementVariantCache & operator=(const LocalFiniteElementVariantCache &other)=default
Copy assignment.
LocalFiniteElementVariantCache(Args &&... args)
Default constructor.
Definition localfiniteelementvariantcache.hh:99
LocalFiniteElementVariantCache(LocalFiniteElementVariantCache &&other)=default
Move constructor.
const auto & get(const Key &... key) const
Get the LocalFiniteElement for the given key data.
Definition localfiniteelementvariantcache.hh:127
LocalFiniteElementVariantCache(const LocalFiniteElementVariantCache &other)=default
Copy constructor.
typename GenerateLFEVariant< Implementations >::type FiniteElementType
Type of exported LocalFiniteElement's.
Definition localfiniteelementvariantcache.hh:92