version 0.4.1
febase.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
13#pragma once
14
18
19namespace Ikarus {
20
21template <typename PreFE, template <typename, typename> class... Skills>
22class FE;
23
32template <typename BH, typename FER = FERequirements<>, bool useFlat = true, bool useEigenRef = false>
33struct PreFE
34{
35 using BasisHandler = BH;
36 using FERequirements = FER;
37 static constexpr int worldDim = BasisHandler::Basis::worlddim;
38 static constexpr bool useEigenReference = useEigenRef;
39 static constexpr bool useFlatBasis = useFlat;
41
42 template <template <typename, typename> class... Skills>
43 using FE = FE<PreFE, Skills...>;
44};
45
46namespace Impl {
47 // Since base classes are initialized, in declaration order before member variables, we have to make sure the
48 // localview_ object of FE is defined. To do this we add this artificial inheritance by inheriting below first from
49 // FEInit, which initializes the localview object first, siche we the other FEMixin base class constructors are called
50 template <typename PreFE, typename FE>
51 struct FEInit
52 {
53 using Traits = PreFE::Traits;
55 using LocalView = typename Traits::LocalView;
56 friend FE;
57 FEInit(const BasisHandler& basisHandler)
58 : localView_{[&]() -> LocalView {
59 if constexpr (Traits::useFlatBasis)
60 return basisHandler.flat().localView();
61 else
62 return basisHandler.untouched().localView();
63 }()} {}
64
65 private:
66 LocalView localView_;
67 };
68} // namespace Impl
69
79template <typename PreFE, template <typename, typename> class... Skills>
80class FE : private Impl::FEInit<PreFE, FE<PreFE, Skills...>>, public FEMixin<PreFE, Skills...>
81{
82 friend Impl::FEInit<PreFE, FE>;
83
84protected:
85 using Mixin = FEMixin<PreFE, Skills...>;
86 friend Mixin;
87
88public:
91 using LocalView = typename Traits::LocalView;
92 using GridView = typename Traits::GridView;
94 using GridElement = typename Traits::Element;
96
97 static constexpr int myDim = Traits::mydim;
98 static constexpr int worldDim = Traits::worlddim;
99 using PreTuple = std::tuple<typename Skills<PreFE, FE>::Pre...>;
100
107 explicit FE(const BasisHandler& basisHandler, typename Skills<PreFE, FE>::Pre... skillsArgs)
108 : Impl::FEInit<PreFE, FE>(basisHandler),
109 FEMixin<PreFE, Skills...>(std::forward<typename Skills<PreFE, FE>::Pre>(skillsArgs)...) {}
110
115 void bind(const GridElement& element) {
116 this->localView_.bind(element);
117 Mixin::bind();
118 }
119
124 [[nodiscard]] constexpr size_t size() const { return this->localView_.size(); }
125
130 const GridElement& gridElement() const { return this->localView_.element(); }
131
136 const LocalView& localView() const { return this->localView_; }
137
142 LocalView& localView() { return this->localView_; }
143};
144} // namespace Ikarus
Definition of the LinearElastic class for finite element mechanics computations.
Implementation of the finite element CRTP mixin class.
FETraits template structure for finite element traits.
Definition: simpleassemblers.hh:22
FE class is a base class for all finite elements.
Definition: febase.hh:81
const LocalView & localView() const
Get the const reference to the local view.
Definition: febase.hh:136
constexpr size_t size() const
Get the size of the local view.
Definition: febase.hh:124
Traits::BasisHandler BasisHandler
Type of the basisHandler.
Definition: febase.hh:90
std::tuple< typename Skills< PreFE, FE >::Pre... > PreTuple
Definition: febase.hh:99
FE(const BasisHandler &basisHandler, typename Skills< PreFE, FE >::Pre... skillsArgs)
Constructor for the FE class.
Definition: febase.hh:107
void bind(const GridElement &element)
Convenient function to bind the local view to the element.
Definition: febase.hh:115
typename Traits::GridView GridView
Type of the global view.
Definition: febase.hh:92
static constexpr int worldDim
Definition: febase.hh:98
typename Traits::FERequirementType FERequirementType
Definition: febase.hh:95
typename Traits::LocalView LocalView
Type of the local view.
Definition: febase.hh:91
friend Mixin
Definition: febase.hh:86
LocalView & localView()
Get the reference to the local view.
Definition: febase.hh:142
static constexpr int myDim
Definition: febase.hh:97
typename Traits::Element GridElement
Type of the grid element.
Definition: febase.hh:94
const GridElement & gridElement() const
Get the grid element associated with the local view.
Definition: febase.hh:130
typename Traits::GlobalIndex GlobalIndex
Type of the global index.
Definition: febase.hh:93
PreFE struct acts as a convenient wrapper for the FE class to access different type traits.
Definition: febase.hh:34
static constexpr bool useEigenReference
Definition: febase.hh:38
FER FERequirements
Definition: febase.hh:36
FE< PreFE, Skills... > FE
Definition: febase.hh:43
FETraits< BH, FER, useEigenRef, useFlat > Traits
Definition: febase.hh:40
static constexpr int worldDim
Definition: febase.hh:37
BH BasisHandler
Definition: febase.hh:35
static constexpr bool useFlatBasis
Definition: febase.hh:39
Traits for handling finite elements.
Definition: fetraits.hh:26
FER FERequirementType
Type of the requirements for the finite element.
Definition: fetraits.hh:31
typename Basis::LocalView LocalView
Type of the local view.
Definition: fetraits.hh:46
BH BasisHandler
Type of the basis of the finite element.
Definition: fetraits.hh:28
typename Basis::GridView GridView
Type of the grid view.
Definition: fetraits.hh:49
static constexpr bool useFlatBasis
A bool to indicate if the provided basishandler should hand out the flat basis.
Definition: fetraits.hh:34
static constexpr int worlddim
Dimension of the world space.
Definition: fetraits.hh:64
static constexpr int mydim
Dimension of the geometry.
Definition: fetraits.hh:67
typename LocalView::Element Element
Type of the grid element.
Definition: fetraits.hh:52
typename LocalView::MultiIndex GlobalIndex
Type of the global index.
Definition: fetraits.hh:58
CRTP mixin class for finite elements with additional skills.
Definition: mixin.hh:28
void bind()
Call all bind functions if the skill implements it.
Definition: mixin.hh:142
Struct representing a collection of skills.
Definition: mixin.hh:234
Wrapper class for a hierarchical basis constructed from a pre-basis.
Definition: utils/basis.hh:30
auto & flat()
Returns a reference to the flat version of the basis.
Definition: utils/basis.hh:55
auto & untouched()
Returns a reference to the untouched version of the basis.
Definition: utils/basis.hh:62