version 0.4.7
flatprebasis.hh
Go to the documentation of this file.
1// Original File: https://gitlab.mn.tu-dresden.de/amdis/amdis-core/-/blob/master/amdis/functions/FlatPreBasis.hpp
2// SPDX-FileCopyrightText: 2023 Copyright (c) AMDiS
3// SPDX-License-Identifier: MIT
4// Modifications:
5// SPDX-FileCopyrightText: 2021-2026 The Ikarus Developers ikarus@ibb.uni-stuttgart.de
6// SPDX-License-Identifier: LGPL-3.0-or-later
7
13#pragma once
14
15#include <cstddef>
16#include <utility>
17
18#include <dune/common/indices.hh>
19#include <dune/functions/functionspacebases/basistags.hh>
20#include <dune/functions/functionspacebases/compositebasis.hh>
21#include <dune/functions/functionspacebases/powerbasis.hh>
22
23#include <Eigen/Core>
24
25namespace Ikarus {
38template <class PreBasis>
40{
41 using type = PreBasis;
42
44 template <class PB>
45 static type create(PB const& preBasis) {
46 return type(preBasis.gridView());
47 }
48
50 static const PreBasis& create(const PreBasis& preBasis) { return preBasis; }
51};
52
54template <class PreBasis>
56
58template <class IMS>
60{
61 using type = IMS;
62};
63
64// specialization for BlockedInterleaved
65template <>
66struct FlatIndexMergingStrategy<Dune::Functions::BasisFactory::BlockedInterleaved>
67{
68 using type = Dune::Functions::BasisFactory::FlatInterleaved;
69};
70
71// specialization for BlockedLexicographic
72template <>
73struct FlatIndexMergingStrategy<Dune::Functions::BasisFactory::BlockedLexicographic>
74{
75 using type = Dune::Functions::BasisFactory::FlatLexicographic;
76};
77
78// specialization for composite bases
79template <class IMS, class... SPB>
80struct FlatPreBasis<Dune::Functions::CompositePreBasis<IMS, SPB...>>
81{
83 using type = Dune::Functions::CompositePreBasis<FIMS, FlatPreBasis_t<SPB>...>;
84
85 template <class PreBasis>
86 static type create(const PreBasis& preBasis) {
87 return create(preBasis, std::index_sequence_for<SPB...>{});
88 }
89
90 template <class PreBasis, std::size_t... I>
91 static type create(const PreBasis& preBasis, std::index_sequence<I...>) {
92 return type(FlatPreBasis<SPB>::create(preBasis.subPreBasis(Dune::index_constant<I>{}))...);
93 }
94};
95
96// specialization for power bases
97template <class IMS, class SPB, std::size_t C>
98struct FlatPreBasis<Dune::Functions::PowerPreBasis<IMS, SPB, C>>
99{
101 using type = Dune::Functions::PowerPreBasis<FIMS, FlatPreBasis_t<SPB>, C>;
102
103 template <class PreBasis>
104 static type create(const PreBasis& preBasis) {
105 return type(FlatPreBasis<SPB>::create(preBasis.subPreBasis()));
106 }
107};
108
111template <class PreBasis>
112decltype(auto) flatPreBasis(const PreBasis& preBasis) {
113 return FlatPreBasis<PreBasis>::create(preBasis);
114}
115
116namespace utils {
117 namespace Impl {
118 template <typename Tree>
119 struct PreBasisInfo
120 {
121 };
122
123 template <typename Tree>
124 requires(Tree::isLeaf)
125 struct PreBasisInfo<Tree>
126 {
127 static constexpr std::size_t size = 0;
128 using NodalSolutionType = double;
129 };
130
131 template <typename Tree>
132 requires(Tree::isPower)
133 struct PreBasisInfo<Tree>
134 {
135 static constexpr std::size_t size = Tree::degree();
136 using NodalSolutionType = Eigen::Vector<double, size>;
137 };
138
139 template <typename Tree>
140 requires(Tree::isComposite)
141 struct PreBasisInfo<Tree>
142 {
143 using ChildTreeType = Tree::template Child<0>::Type;
144 static_assert(not ChildTreeType::isComposite, "Cannot handle a composite basis within a composite basis.");
145
146 static constexpr std::size_t size = PreBasisInfo<ChildTreeType>::size;
147 using NodalSolutionType = PreBasisInfo<ChildTreeType>::NodalSolutionType;
148 };
149 } // namespace Impl
150} // namespace utils
151
152} // end namespace Ikarus
decltype(auto) flatPreBasis(const PreBasis &preBasis)
Generator function for a flatted PreBasis.
Definition: flatprebasis.hh:112
Definition: assemblermanipulatorbuildingblocks.hh:22
typename FlatPreBasis< PreBasis >::type FlatPreBasis_t
Type alias for flatted PreBasis.
Definition: flatprebasis.hh:55
Definition: utils/dirichletvalues.hh:36
Transform a PreBasis into one with flat index-merging strategyThis utility takes a pre-basis and conv...
Definition: flatprebasis.hh:40
PreBasis type
Definition: flatprebasis.hh:41
static type create(PB const &preBasis)
Try to construct the pre-basis using a gridView.
Definition: flatprebasis.hh:45
static const PreBasis & create(const PreBasis &preBasis)
Do not transform the preBasis if already flat.
Definition: flatprebasis.hh:50
Define the flat index-merging strategy for a given strategy IMS
Definition: flatprebasis.hh:60
IMS type
Definition: flatprebasis.hh:61
Dune::Functions::BasisFactory::FlatInterleaved type
Definition: flatprebasis.hh:68
Dune::Functions::BasisFactory::FlatLexicographic type
Definition: flatprebasis.hh:75
typename FlatIndexMergingStrategy< IMS >::type FIMS
Definition: flatprebasis.hh:82
Dune::Functions::CompositePreBasis< FIMS, FlatPreBasis_t< SPB >... > type
Definition: flatprebasis.hh:83
static type create(const PreBasis &preBasis)
Definition: flatprebasis.hh:86
static type create(const PreBasis &preBasis, std::index_sequence< I... >)
Definition: flatprebasis.hh:91
static type create(const PreBasis &preBasis)
Definition: flatprebasis.hh:104
Dune::Functions::PowerPreBasis< FIMS, FlatPreBasis_t< SPB >, C > type
Definition: flatprebasis.hh:101
typename FlatIndexMergingStrategy< IMS >::type FIMS
Definition: flatprebasis.hh:100