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
95{
99};
100
104template <typename T>
105concept FEAffordance = std::is_same_v<std::remove_cvref_t<T>, ScalarAffordances> or
106 std::is_same_v<std::remove_cvref_t<T>, VectorAffordances> or
107 std::is_same_v<std::remove_cvref_t<T>, MatrixAffordances> or
108 std::is_same_v<std::remove_cvref_t<T>, AffordanceCollectionImpl>;
109
111
115
117
118namespace AffordanceCollections {
121}
122
123namespace Impl {
124 template <typename T>
125 struct DeduceRawVectorType
126 {
127 static_assert(!std::is_same<T, T>::value, "You should end up in the provided specializations");
128 };
129
130 template <typename T>
131 struct DeduceRawVectorType<std::reference_wrapper<T>>
132 {
133 using Type = T;
134 };
135
136 template <typename T>
137 struct DeduceRawVectorType<Eigen::Ref<T>>
138 {
139 using Type = Eigen::Ref<T>;
140 };
141} // namespace Impl
142
155template <typename SV = std::reference_wrapper<Eigen::VectorXd>, typename PM = std::reference_wrapper<double>>
157{
158public:
160 using SolutionVectorTypeRaw = typename Impl::DeduceRawVectorType<std::remove_cvref_t<SV>>::Type;
161 using ParameterType = PM;
162 using ParameterTypeRaw = typename PM::type;
163
173 template <FEAffordance Affordance>
174 FERequirements& addAffordance(Affordance&& affordance) {
175 if constexpr (std::is_same_v<std::remove_cvref_t<Affordance>, ScalarAffordances>)
176 affordances_.scalarAffordances = affordance;
177 else if constexpr (std::is_same_v<std::remove_cvref_t<Affordance>, VectorAffordances>)
178 affordances_.vectorAffordances = affordance;
179 else if constexpr (std::is_same_v<std::remove_cvref_t<Affordance>, MatrixAffordances>)
180 affordances_.matrixAffordances = affordance;
181 else if constexpr (std::is_same_v<std::remove_cvref_t<Affordance>, AffordanceCollectionImpl>)
182 affordances_ = affordance;
183 return *this;
184 }
185
196 parameter_.insert_or_assign(key, val);
197 return *this;
198 }
199
210 sols_.insert_or_assign(key, sol);
211 return *this;
212 }
213
225 try {
226 if constexpr (std::is_same_v<SolutionVectorType, std::reference_wrapper<Eigen::VectorXd>>)
227 return sols_.at(key).get();
228 else
229 return sols_.at(key);
230 } catch (std::out_of_range& oor) {
231 DUNE_THROW(Dune::RangeError, std::string("Out of Range error: ") + std::string(oor.what()) +
232 " in getGlobalSolution with key" + toString(key));
233 abort();
234 }
235 }
236
248 try {
249 return parameter_.at(key).get();
250 } catch (std::out_of_range& oor) {
251 DUNE_THROW(Dune::RangeError, std::string("Out of Range error: ") + std::string(oor.what()) +
252 " in getParameter with key" + toString(key));
253 abort();
254 }
255 }
256
266 template <FEAffordance Affordance>
267 bool hasAffordance(Affordance&& affordance) const {
268 if constexpr (std::is_same_v<std::remove_cvref_t<Affordance>, ScalarAffordances>)
269 return affordances_.scalarAffordances == affordance;
270 else if constexpr (std::is_same_v<std::remove_cvref_t<Affordance>, VectorAffordances>)
271 return affordances_.vectorAffordances == affordance;
272 else if constexpr (std::is_same_v<std::remove_cvref_t<Affordance>, MatrixAffordances>)
273 return affordances_.matrixAffordances == affordance;
274 else if constexpr (std::is_same_v<std::remove_cvref_t<Affordance>, AffordanceCollectionImpl>)
275 return affordances_ == affordance;
276 }
277
278private:
279 std::map<FESolutions, SolutionVectorType> sols_;
280 std::map<FEParameter, ParameterType> parameter_;
281 AffordanceCollectionImpl affordances_;
282};
283
297template <typename SV = std::reference_wrapper<Eigen::VectorXd>, typename PM = std::reference_wrapper<double>>
298class [[deprecated(
299 "FErequirements is deprecaded and will be removed after v0.5. Use FERequirements instead.")]] FErequirements
300 : public FERequirements<SV, PM>
301{
303
304public:
305 FErequirements() = default;
307 : Base(std::forward<Base>(base)) {}
308 FErequirements(const Base& base)
309 : Base(base) {}
311 Base::operator=(base);
312 return *this;
313 }
315 Base::operator=(std::forward<Base>(base));
316 return *this;
317 }
318};
319
320} // namespace Ikarus
Implementation of the make enum macro.
Definitions of ResultTypes used for finite element results.
VectorAffordances
A strongly typed enum class representing the vector affordance.
Definition: ferequirements.hh:48
MatrixAffordances
A strongly typed enum class representing the matrix affordance.
Definition: ferequirements.hh:63
ScalarAffordances
A strongly typed enum class representing the scalar affordance.
Definition: ferequirements.hh:37
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
Definition: simpleassemblers.hh:22
constexpr std::string toString(ScalarAffordances _e)
Definition: ferequirements.hh:37
constexpr MatrixAffordances stiffness
Definition: ferequirements.hh:112
constexpr ScalarAffordances potentialEnergy
Definition: ferequirements.hh:116
constexpr MatrixAffordances mass
Definition: ferequirements.hh:114
constexpr MatrixAffordances stiffnessdiffBucklingVector
Definition: ferequirements.hh:113
constexpr VectorAffordances forces
Definition: ferequirements.hh:110
constexpr AffordanceCollectionImpl elastoStatics
Definition: ferequirements.hh:119
Definition: truncatedconjugategradient.hh:24
Struct representing a collection of affordances.
Definition: ferequirements.hh:95
VectorAffordances vectorAffordances
Definition: ferequirements.hh:97
ScalarAffordances scalarAffordances
Definition: ferequirements.hh:96
MatrixAffordances matrixAffordances
Definition: ferequirements.hh:98
Class representing the requirements for finite element calculations.
Definition: ferequirements.hh:157
bool hasAffordance(Affordance &&affordance) const
Check if a specific affordance is present in the requirements.
Definition: ferequirements.hh:267
const ParameterTypeRaw & getParameter(FEParameter &&key) const
Get the raw parameter value for a specific key.
Definition: ferequirements.hh:247
FERequirements & insertGlobalSolution(const FESolutions &key, SolutionVectorTypeRaw &sol)
Insert a global solution vector into the requirements.
Definition: ferequirements.hh:209
const SolutionVectorTypeRaw & getGlobalSolution(const FESolutions &key) const
Get the raw global solution vector for a specific type.
Definition: ferequirements.hh:224
PM ParameterType
Definition: ferequirements.hh:161
SV SolutionVectorType
Definition: ferequirements.hh:159
FERequirements & addAffordance(Affordance &&affordance)
Add an affordance to the requirements.
Definition: ferequirements.hh:174
typename Impl::DeduceRawVectorType< std::remove_cvref_t< SV > >::Type SolutionVectorTypeRaw
Definition: ferequirements.hh:160
FERequirements & insertParameter(const FEParameter &key, ParameterTypeRaw &val)
Insert a parameter into the requirements.
Definition: ferequirements.hh:195
typename PM::type ParameterTypeRaw
Definition: ferequirements.hh:162
Class representing the requirements for finite element calculations.
Definition: ferequirements.hh:301
FErequirements & operator=(const Base &base)
Definition: ferequirements.hh:310
FErequirements & operator=(Base &&base)
Definition: ferequirements.hh:314
FErequirements(Base &&base)
Definition: ferequirements.hh:306
FErequirements(const Base &base)
Definition: ferequirements.hh:308
Concept to check if a given type is one of the predefined affordance enums or the AffordanceCollectio...
Definition: ferequirements.hh:105