version 0.4.1
ferequirements.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
10#pragma once
11
12#include <iosfwd>
13#include <map>
14#include <set>
15#include <vector>
16
17#include <dune/common/exceptions.hh>
18
19#include <Eigen/Core>
20
23
24namespace Ikarus {
25// clang-format off
26
32// cppcheck-suppress MAKE_ENUM
34 noAffordance,
35 mechanicalPotentialEnergy,
36 microMagneticPotentialEnergy
37 );
38
45 noAffordance,
46 forces,
47 microMagneticForces
48 );
49
56 noAffordance,
58 materialstiffness,
59 geometricstiffness,
61 microMagneticHessian,
62 mass
63 );
64
71 noParameter,
72 loadfactor,
73 time
74 );
75
82 noSolution,
83 displacement,
84 velocity,
85 director,
86 magnetizationAndVectorPotential
87 );
88
89// clang-format on
90
94template <typename T>
95concept FEAffordance = std::is_same_v<std::remove_cvref_t<T>, ScalarAffordance> or
96 std::is_same_v<std::remove_cvref_t<T>, VectorAffordance> or
97 std::is_same_v<std::remove_cvref_t<T>, MatrixAffordance>;
98
102template <FEAffordance... Affordances>
103requires(sizeof...(Affordances) <= 3)
104struct AffordanceCollection : public std::tuple<Affordances...>
105{
106 using Base = std::tuple<Affordances...>;
107
109 constexpr AffordanceCollection(Affordances... affordances)
110 : Base(affordances...) {}
111
112 static constexpr bool hasScalarAffordance = traits::hasType<ScalarAffordance, std::tuple<Affordances...>>::value;
113 static constexpr bool hasVectorAffordance = traits::hasType<VectorAffordance, std::tuple<Affordances...>>::value;
114 static constexpr bool hasMatrixAffordance = traits::hasType<MatrixAffordance, std::tuple<Affordances...>>::value;
124 template <FEAffordance Affordance>
125 constexpr bool hasAffordance(Affordance&& affordances) const {
126 using AffordanceRaw = std::remove_cvref_t<Affordance>;
127 if constexpr (std::is_same_v<AffordanceRaw, AffordanceCollection>)
128 return affordances == *this;
129 else {
130 if constexpr (std::is_same_v<AffordanceRaw, ScalarAffordance>) {
131 if constexpr (hasScalarAffordance)
132 return affordances == std::get<ScalarAffordance>(*this);
133 else
134 return false;
135 }
136 if constexpr (std::is_same_v<AffordanceRaw, VectorAffordance>) {
137 if constexpr (hasVectorAffordance)
138 return affordances == std::get<VectorAffordance>(*this);
139 else
140 return false;
141 }
142 if constexpr (std::is_same_v<AffordanceRaw, MatrixAffordance>) {
143 if constexpr (hasMatrixAffordance)
144 return affordances == std::get<MatrixAffordance>(*this);
145 else
146 return false;
147 }
148 }
149 return false;
150 }
151
152 auto scalarAffordance() const
153 requires hasScalarAffordance
154 {
155 return std::get<ScalarAffordance>(*this);
156 }
157 auto vectorAffordance() const
158 requires hasVectorAffordance
159 {
160 return std::get<VectorAffordance>(*this);
161 }
162 auto matrixAffordance() const
163 requires hasMatrixAffordance
164 {
165 return std::get<MatrixAffordance>(*this);
166 }
167};
168
170
175
177 if (affordanceM == MatrixAffordance::stiffness)
179 else if (affordanceM == MatrixAffordance::microMagneticHessian)
181 else
183}
184
186 if (affordanceM == MatrixAffordance::stiffness)
188 else if (affordanceM == MatrixAffordance::microMagneticHessian)
190 else
192}
193
195 if (affordanceV == VectorAffordance::forces)
197 else if (affordanceV == VectorAffordance::microMagneticForces)
199 else
201}
202
203namespace AffordanceCollections {
206}
207
208namespace Impl {
209 template <typename T>
210 struct DeduceTypes
211 {
212 using InputType = T&;
213 using StorageType = std::reference_wrapper<T>;
214 using ReturnType = T&;
215 using ConstReturnType = const T&;
216 };
217
218 template <typename T>
219 struct DeduceTypes<std::reference_wrapper<T>>
220 {
221 using InputType = T&;
222 using StorageType = std::reference_wrapper<T>;
223 using ReturnType = T&;
224 using ConstReturnType = const T&;
225 };
226
227 template <typename T>
228 struct DeduceTypes<Eigen::Ref<T>>
229 {
230 using InputType = Eigen::Ref<T>&;
231 using StorageType = Eigen::Ref<T>;
232
233 using ReturnType = Eigen::Ref<T>&;
234 using ConstReturnType = const Eigen::Ref<T>&;
235 };
236} // namespace Impl
237
250template <FESolutions sol, FEParameter para, typename SV = Eigen::VectorXd, typename PM = double>
252{
253public:
254 static constexpr FESolutions globalSolutionTag = sol;
255 static constexpr FEParameter parameterTag = para;
256
257private:
258 using SVHelper = Impl::DeduceTypes<std::remove_cvref_t<SV>>;
259 using PMHelper = Impl::DeduceTypes<std::remove_cvref_t<PM>>;
260 using SolutionVectorReturnType = SVHelper::ReturnType;
261 using ParameterReturnType = PMHelper::ReturnType;
262 using SolutionVectorStorageType = SVHelper::StorageType;
263 using ParameterStorageType = PMHelper::StorageType;
264 using SolutionVectorInputType = SVHelper::InputType;
265 using ParameterInputType = PMHelper::InputType;
266
267public:
269 using ParameterType = PM;
270
271 FERequirements() = default;
272 FERequirements(SolutionVectorInputType solVec, ParameterInputType parameter)
273 : sol_{solVec},
274 parameter_{parameter} {}
275
284 FERequirements& insertParameter(ParameterInputType val) {
285 parameter_ = val;
286 return *this;
287 }
288
297 FERequirements& insertGlobalSolution(SolutionVectorInputType solVec) {
298 sol_ = solVec;
299 return *this;
300 }
301
308 SolutionVectorReturnType globalSolution() { return sol_.value(); }
309
316 SVHelper::ConstReturnType globalSolution() const { return sol_.value(); }
317
325 PMHelper::ConstReturnType parameter() const {
326 return parameter_.value();
327 ;
328 }
329
336 ParameterReturnType parameter() { return parameter_.value(); }
337
344 bool populated() const { return sol_.has_value() and parameter_.has_value(); }
345
346private:
347 std::optional<SolutionVectorStorageType> sol_;
348 std::optional<ParameterStorageType> parameter_;
349};
350
351template <FESolutions sol, FEParameter para, bool wrapWithRef = false, typename SV = Eigen::VectorXd,
352 typename PM = double>
354{
355private:
356 using typeEigen = std::conditional_t<wrapWithRef and Ikarus::Concepts::EigenMatrix<SV>, Eigen::Ref<SV>, SV>;
357
358public:
360};
361
362} // namespace Ikarus
Implementation of the make enum macro.
Definitions of ResultTypes used for finite element results.
FEParameter
A strongly typed enum class representing the FE parameter.
Definition: ferequirements.hh:74
FESolutions
A strongly typed enum class representing the type of the solutions vectors.
Definition: ferequirements.hh:87
#define MAKE_ENUM(type,...)
Macro to create an enumeration with a string conversion function.The macro creates an enum class with...
Definition: makeenum.hh:40
std::invoke_result_t< Fun, Args... > ReturnType
Type trait to obtain the return type of a callable type when given specific arguments.
Definition: traits.hh:74
STL namespace.
Definition: assemblermanipulatorbuildingblocks.hh:22
constexpr MatrixAffordance stiffnessdiffBucklingVector
Definition: ferequirements.hh:172
auto vectorAffordance(MatrixAffordance affordanceM)
Definition: ferequirements.hh:176
MatrixAffordance
A strongly typed enum class representing the matrix affordance.
Definition: ferequirements.hh:63
constexpr MatrixAffordance stiffness
Definition: ferequirements.hh:171
constexpr VectorAffordance forces
Definition: ferequirements.hh:169
constexpr ScalarAffordance potentialEnergy
Definition: ferequirements.hh:174
auto scalarAffordance(MatrixAffordance affordanceM)
Definition: ferequirements.hh:185
VectorAffordance
A strongly typed enum class representing the vector affordance.
Definition: ferequirements.hh:48
constexpr MatrixAffordance mass
Definition: ferequirements.hh:173
ScalarAffordance
A strongly typed enum class representing the scalar affordance.
Definition: ferequirements.hh:37
constexpr AffordanceCollection elastoStatics(ScalarAffordance::mechanicalPotentialEnergy, VectorAffordance::forces, MatrixAffordance::stiffness)
Definition: truncatedconjugategradient.hh:24
Struct representing a collection of affordances.
Definition: ferequirements.hh:105
std::tuple< Affordances... > Base
Definition: ferequirements.hh:106
auto vectorAffordance() const
Definition: ferequirements.hh:157
constexpr AffordanceCollection(Affordances... affordances)
Definition: ferequirements.hh:109
auto scalarAffordance() const
Definition: ferequirements.hh:152
constexpr bool hasAffordance(Affordance &&affordances) const
Check if a specific affordance is present in the requirements.
Definition: ferequirements.hh:125
auto matrixAffordance() const
Definition: ferequirements.hh:162
Class representing the requirements for finite element calculations.
Definition: ferequirements.hh:252
bool populated() const
Tells if the class contains all needed values.
Definition: ferequirements.hh:344
static constexpr FEParameter parameterTag
Definition: ferequirements.hh:255
SV SolutionVectorType
Definition: ferequirements.hh:268
PM ParameterType
Definition: ferequirements.hh:269
SolutionVectorReturnType globalSolution()
Get the global solution vector.
Definition: ferequirements.hh:308
FERequirements & insertParameter(ParameterInputType val)
Insert a parameter into the requirements.
Definition: ferequirements.hh:284
ParameterReturnType parameter()
Get the parameter value.
Definition: ferequirements.hh:336
FERequirements & insertGlobalSolution(SolutionVectorInputType solVec)
Insert a global solution vector into the requirements.
Definition: ferequirements.hh:297
static constexpr FESolutions globalSolutionTag
Definition: ferequirements.hh:254
FERequirements(SolutionVectorInputType solVec, ParameterInputType parameter)
Definition: ferequirements.hh:272
PMHelper::ConstReturnType parameter() const
Get the parameter value.
Definition: ferequirements.hh:325
SVHelper::ConstReturnType globalSolution() const
Get the global solution vector. *.
Definition: ferequirements.hh:316
Definition: ferequirements.hh:354
Type trait to check if a specified type is present in a tuple.
Definition: traits.hh:86
Concept to check if a given type is one of the predefined affordance enums or the AffordanceCollectio...
Definition: ferequirements.hh:95