dune-localfunctions 2.10
Loading...
Searching...
No Matches
cache.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_LOCALFUNCTIONS_LAGRANGE_CACHE_HH
6#define DUNE_LOCALFUNCTIONS_LAGRANGE_CACHE_HH
7
8#include <map>
9#include <optional>
10#include <type_traits>
11
12#include <dune/geometry/type.hh>
13#include <dune/geometry/typeindex.hh>
14
22
23
24namespace Dune {
25
37template <class Domain, class Range, int dim>
39{
40public:
42
44 explicit DynamicLagrangeLocalFiniteElementCache (unsigned int order)
45 : order_(order)
46 , data_()
47 {}
48
55 const FiniteElementType& get (GeometryType type) const
56 {
57 auto [it,_] = data_.try_emplace(type,type,order_);
58 return it->second;
59 }
60
61private:
62 unsigned int order_;
63 mutable std::map<GeometryType, FiniteElementType> data_;
64};
65
66
78template <GeometryType::Id id, class Domain, class Range, std::size_t dim, std::size_t order>
80{
81 struct UnknownToplogy {};
82
83 static constexpr bool isSimplex = GeometryType(id).isSimplex();
84 static constexpr bool isCube = GeometryType(id).isCube();
85 static constexpr bool isPrism = GeometryType(id).isPrism();
86 static constexpr bool isPyramid = GeometryType(id).isPyramid();
87
88public:
90 = std::conditional_t<isSimplex, LagrangeSimplexLocalFiniteElement<Domain,Range,dim,order>,
91 std::conditional_t<isCube, LagrangeCubeLocalFiniteElement<Domain,Range,dim,order>,
92 std::conditional_t<isPrism, LagrangePrismLocalFiniteElement<Domain,Range,order>,
93 std::conditional_t<isPyramid, LagrangePyramidLocalFiniteElement<Domain,Range,order>, UnknownToplogy> > > >;
94
96 explicit StaticLagrangeLocalFiniteElementCache (std::integral_constant<std::size_t,order> = {})
97 {
98 lfe_.emplace();
99 }
100
102 const FiniteElementType& get ([[maybe_unused]] GeometryType type) const
103 {
104 assert(GeometryType::Id(type) == id);
105 assert(!!lfe_);
106 return *lfe_;
107 }
108
109private:
110 std::optional<FiniteElementType> lfe_{};
111};
112
113
127template <class Domain, class Range, std::size_t dim, std::size_t order>
128class StaticLagrangeLocalFiniteElementCache<GeometryType::Id(~0u), Domain, Range, dim, order>
129 : public LagrangeLocalFiniteElementCache<Domain,Range,dim,order>
130{
132public:
133 using Base::Base;
134};
135
136} // namespace Dune
137
138#endif // DUNE_LOCALFUNCTIONS_LAGRANGE_CACHE_HH
Convenience header that includes all implementations of Lagrange finite elements.
Definition bdfmcube.hh:18
A cache storing a compile time selection of local finite element implementations.
Definition localfiniteelementvariantcache.hh:68
Lagrange local finite elements for a given set of interpolation points.
Definition lagrange.hh:66
A cache that stores Lagrange finite elements for the given dimension and order.
Definition cache.hh:39
DynamicLagrangeLocalFiniteElementCache(unsigned int order)
Construct an empty cache.
Definition cache.hh:44
const FiniteElementType & get(GeometryType type) const
Obtain the cached local finite-element.
Definition cache.hh:55
A cache that stores all available Pk/Qk like local finite elements for the given dimension and order ...
Definition cache.hh:80
const FiniteElementType & get(GeometryType type) const
Obtain the cached local finite-element.
Definition cache.hh:102
std::conditional_t< isSimplex, LagrangeSimplexLocalFiniteElement< Domain, Range, dim, order >, std::conditional_t< isCube, LagrangeCubeLocalFiniteElement< Domain, Range, dim, order >, std::conditional_t< isPrism, LagrangePrismLocalFiniteElement< Domain, Range, order >, std::conditional_t< isPyramid, LagrangePyramidLocalFiniteElement< Domain, Range, order >, UnknownToplogy > > > > FiniteElementType
Definition cache.hh:93
StaticLagrangeLocalFiniteElementCache(std::integral_constant< std::size_t, order >={})
Construct the local-finite element for the order specified as template parameter.
Definition cache.hh:96