DUNE LocalFunctions (unstable)

lagrangelfecache.hh
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_LAGRANGELFECACHE_HH
6#define DUNE_LOCALFUNCTIONS_LAGRANGE_LAGRANGELFECACHE_HH
7
8#include <tuple>
9#include <utility>
10
11#include <dune/geometry/type.hh>
12#include <dune/geometry/typeindex.hh>
13
14#include <dune/localfunctions/lagrange/lagrangecube.hh>
15#include <dune/localfunctions/lagrange/lagrangeprism.hh>
16#include <dune/localfunctions/lagrange/lagrangepyramid.hh>
17#include <dune/localfunctions/lagrange/lagrangesimplex.hh>
18#include <dune/localfunctions/lagrange/p0.hh>
19#include <dune/localfunctions/common/localfiniteelementvariantcache.hh>
20
21
22namespace Dune {
23
24
25
26namespace Impl {
27
28 // Provide implemented Lagrange local finite elements
29
30 template<class D, class R, std::size_t dim, int compileTimeOrder>
31 class ImplementedLagrangeFiniteElements : public FixedDimLocalGeometryTypeIndex<dim>
32 {
33 int runTimeOrder_;
34 public:
35
36 ImplementedLagrangeFiniteElements(int runTimeOrder = compileTimeOrder)
37 : runTimeOrder_(runTimeOrder)
38 {
39 if (runTimeOrder < 0)
40 DUNE_THROW(Dune::InvalidStateException, "LagrangeLocalFiniteElementCache: Run-time order must be non-negative.");
41 if ((compileTimeOrder >= 0) and (runTimeOrder != compileTimeOrder))
42 DUNE_THROW(Dune::InvalidStateException, "LagrangeLocalFiniteElementCache: Run-time order must be consistent with compile-time order when providing both.");
43 }
44
45 using FixedDimLocalGeometryTypeIndex<dim>::index;
46
47 auto getImplementations() const
48 {
49 if constexpr (compileTimeOrder >= 0)
50 {
51 if constexpr ((dim != 3) and (compileTimeOrder == 0))
52 return std::make_tuple(
53 std::make_pair(index(GeometryTypes::simplex(dim)), []() { return P0LocalFiniteElement<D,R,dim>(GeometryTypes::simplex(dim)); }),
54 std::make_pair(index(GeometryTypes::cube(dim)), []() { return P0LocalFiniteElement<D,R,dim>(GeometryTypes::cube(dim)); }),
55 std::make_pair(index(GeometryTypes::none(dim)), []() { return P0LocalFiniteElement<D,R,dim>(GeometryTypes::none(dim)); })
56 );
57 else if constexpr ((dim == 3) and (compileTimeOrder <= 2))
58 return std::make_tuple(
59 std::make_pair(index(GeometryTypes::tetrahedron), []() { return LagrangeSimplexLocalFiniteElement<D,R,dim,compileTimeOrder>(); }),
60 std::make_pair(index(GeometryTypes::hexahedron), []() { return LagrangeCubeLocalFiniteElement<D,R,dim,compileTimeOrder>(); }),
61 std::make_pair(index(GeometryTypes::prism), []() { return LagrangePrismLocalFiniteElement<D,R,compileTimeOrder>(); }),
62 std::make_pair(index(GeometryTypes::pyramid), []() { return LagrangePyramidLocalFiniteElement<D,R,compileTimeOrder>(); })
63 );
64 else
65 return std::make_tuple(
66 std::make_pair(index(GeometryTypes::simplex(dim)), []() { return LagrangeSimplexLocalFiniteElement<D,R,dim,compileTimeOrder>(); }),
67 std::make_pair(index(GeometryTypes::cube(dim)), []() { return LagrangeCubeLocalFiniteElement<D,R,dim,compileTimeOrder>(); })
68 );
69 }
70 else
71 {
72 if constexpr (dim == 3)
73 {
74 constexpr auto unusedIndex = std::numeric_limits<decltype(index(GeometryTypes::simplex(dim)))>::max();
75 auto prismOrder = (runTimeOrder_<= 2) ? runTimeOrder_ : 0;
76 auto prismIndex = (runTimeOrder_<= 2) ? index(GeometryTypes::prism) : unusedIndex;
77 auto pyramidOrder = (runTimeOrder_<= 2) ? runTimeOrder_ : 0;
78 auto pyramidIndex = (runTimeOrder_<= 2) ? index(GeometryTypes::pyramid) : unusedIndex;
79 return std::make_tuple(
80 std::make_pair(index(GeometryTypes::tetrahedron), [&]() { return LagrangeSimplexLocalFiniteElement<D,R,dim,compileTimeOrder>(runTimeOrder_); }),
81 std::make_pair(index(GeometryTypes::hexahedron), [&]() { return LagrangeCubeLocalFiniteElement<D,R,dim,compileTimeOrder>(runTimeOrder_); }),
82 std::make_pair(prismIndex, [=]() { return LagrangePrismLocalFiniteElement<D,R,compileTimeOrder>(prismOrder); }),
83 std::make_pair(pyramidIndex, [=]() { return LagrangePyramidLocalFiniteElement<D,R,compileTimeOrder>(pyramidOrder); })
84 );
85 }
86 else
87 return std::make_tuple(
88 std::make_pair(index(GeometryTypes::simplex(dim)), [&]() { return LagrangeSimplexLocalFiniteElement<D,R,dim,compileTimeOrder>(runTimeOrder_); }),
89 std::make_pair(index(GeometryTypes::cube(dim)), [&]() { return LagrangeCubeLocalFiniteElement<D,R,dim,compileTimeOrder>(runTimeOrder_); })
90 );
91 }
92 }
93 };
94
95} // namespace Impl
96
97
98
112template<class D, class R, std::size_t dim, int compileTimeOrder = -1>
113using LagrangeLocalFiniteElementCache = LocalFiniteElementVariantCache<Impl::ImplementedLagrangeFiniteElements<D,R,dim, compileTimeOrder>>;
114
115
116
117} // namespace Dune
118
119
120
121
122#endif // DUNE_LOCALFUNCTIONS_LAGRANGE_LAGRANGELFECACHE_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (May 28, 22:40, 2026)