version 0.4.1
concepts.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
9#pragma once
10
11#include <concepts>
12#include <type_traits>
13#include <utility>
14#include <vector>
15
16#include <dune/functions/functionspacebases/basistags.hh>
17#include <dune/functions/functionspacebases/lagrangebasis.hh>
18
19#include <Eigen/Sparse>
20
22
23namespace Eigen {
24template <typename Derived>
25struct EigenBase;
26}
27
28namespace Ikarus {
29template <auto stressIndexPair, typename MaterialImpl>
30struct VanishingStress;
31
32template <typename Derived>
34namespace Concepts {
35
44 template <typename Basis>
45 concept FlatInterLeavedBasis = requires {
46 std::is_same_v<typename Basis::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::FlatInterleaved>;
47 };
48
49 namespace Impl {
50 template <template <typename, int, typename> class U, typename T>
51 struct LagrangeNodeHelper : std::false_type
52 {
53 };
54 template <template <typename, int, typename> class U, typename GV, int k, typename R>
55 struct LagrangeNodeHelper<U, U<GV, k, R>> : std::true_type
56 {
57 };
58
59 template <template <typename, int, typename> class U, typename T, int k>
60 struct LagrangeNodeHelperOfOrder : std::false_type
61 {
62 };
63 template <template <typename, int, typename> class U, typename GV, int k, typename R>
64 struct LagrangeNodeHelperOfOrder<U, U<GV, k, R>, k> : std::true_type
65 {
66 };
67 } // namespace Impl
68
76 template <typename N>
77 concept LagrangeNode = Impl::LagrangeNodeHelper<Dune::Functions::LagrangeNode, N>::value;
78
86 template <typename N, int order>
87 concept LagrangeNodeOfOrder = Impl::LagrangeNodeHelperOfOrder<Dune::Functions::LagrangeNode, N, order>::value;
88
97 template <typename B>
98 concept FlatLexicographicBasis = requires {
99 std::is_same_v<typename B::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::FlatLexicographic>;
100 };
101
110 template <typename B>
112
121 template <typename Basis>
122 concept BlockedInterLeavedBasis = requires {
123 std::is_same_v<typename Basis::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::BlockedInterleaved>;
124 };
125
134 template <typename B>
135 concept BlockedLexicographicBasis = requires {
136 std::is_same_v<typename B::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::BlockedLexicographic>;
137 };
138
144 template <typename DLB>
145 concept DuneLocalBasis = requires(DLB& duneLocalBasis) {
146 typename DLB::Traits::RangeType;
147 typename DLB::Traits::JacobianType;
148 DLB::Traits::dimDomain;
149 typename DLB::Traits::DomainType;
150
151 typename DLB::Traits::DomainFieldType;
152 typename DLB::Traits::RangeFieldType;
153
154 duneLocalBasis.evaluateFunction(std::declval<typename DLB::Traits::DomainType>(),
155 std::declval<std::vector<typename DLB::Traits::RangeType>&>());
156 duneLocalBasis.evaluateJacobian(std::declval<typename DLB::Traits::DomainType>(),
157 std::declval<std::vector<typename DLB::Traits::JacobianType>&>());
158 };
159
169 template <typename B>
171
179 template <typename PF, typename NLO, typename SA>
180 concept PathFollowingStrategy = requires(PF pft, NLO nop, SA args) {
181 { pft(args) } -> std::same_as<void>;
182 { pft.initialPrediction(nop, args) } -> std::same_as<void>;
183 { pft.intermediatePrediction(nop, args) } -> std::same_as<void>;
184 };
185
194 template <typename ASS, typename NLSI, typename SA, typename NonLinearOperator>
195 concept AdaptiveStepSizingStrategy = requires(ASS adaptiveStepSizing, NLSI info, SA args, NonLinearOperator nop) {
196 { adaptiveStepSizing(info, args, nop) } -> std::same_as<void>;
197 { adaptiveStepSizing.targetIterations() } -> std::same_as<int>;
198 { adaptiveStepSizing.setTargetIterations(std::declval<int>()) } -> std::same_as<void>;
199 };
200
209 template <typename LS, typename M, typename V>
210 concept LinearSolverCheck = requires(LS& linearSolver, M& A, V& vec) {
211 linearSolver.analyzePattern(A);
212 linearSolver.factorize(A);
213 linearSolver.solve(vec, vec);
214 };
215
223 template <typename NLS>
225 std::tuple_size<typename NLS::NonLinearOperator::ParameterValues>::value == 2;
226 not(std::is_same_v<typename NLS::NonLinearOperator::ValueType, double> and
227 ((traits::isSpecializationTypeAndNonTypes<Eigen::Matrix,
228 typename NLS::NonLinearOperator::DerivativeType>::value) or
229 (traits::isSpecializationTypeNonTypeAndType<Eigen::SparseMatrix,
230 typename NLS::NonLinearOperator::DerivativeType>::value)));
231 };
232
240 template <typename L, typename R>
241 concept MultiplyAble = requires(L x, R y) { x* y; };
242
250 template <typename L, typename R>
251 concept AddAble = requires(L x, R y) { x + y; };
252
260 template <typename L, typename R>
261 concept SubstractAble = requires(L x, R y) { x - y; };
262
271 template <typename L, typename R>
272 concept MultiplyAssignAble = requires(L x, R y) { x *= y; };
273
282 template <typename L, typename R>
283 concept DivideAssignAble = requires(L x, R y) { x /= y; };
284
293 template <typename L, typename R>
294 concept AddAssignAble = requires(L x, R y) { x += y; };
295
304 template <typename L, typename R>
305 concept SubstractAssignAble = requires(L x, R y) { x -= y; };
306
314 template <typename L, typename R>
315 concept DivideAble = requires(L x, R y) { x / y; };
316
323 template <typename L>
324 concept NegateAble = requires(L x) { -x; };
325
332 template <typename L>
333 concept TransposeAble = requires(L x) { transpose(x); };
334
342 template <typename Op, typename... Args>
343 concept IsFunctorWithArgs = requires(Op op, Args... args) { op(args...); };
344
352 template <typename V>
353 concept EigenVector = static_cast<bool>(V::IsVectorAtCompileTime);
354
355#define MAKE_EIGEN_FIXED_VECTOR_CONCEPT(Size) \
356 template <typename V> \
357 concept EigenVector##Size = \
358 static_cast<bool>(V::IsVectorAtCompileTime) and static_cast<bool>(V::SizeAtCompileTime == Size);
359
366
367#define MAKE_EIGEN_FIXED_MATRIX_CONCEPT(Size1, Size2) \
368 template <typename M> \
369 concept EigenMatrix##Size1##Size2 = static_cast<bool>(std::remove_cvref_t<M>::RowsAtCompileTime == Size1) and \
370 static_cast<bool>(std::remove_cvref_t<M>::ColsAtCompileTime == Size2);
371
373
376
381
388
397
408
409#define MAKE_EIGEN_FIXED_MATRIX_OR_VOIGT_CONCEPT(Size1, Size2) \
410 template <typename M> \
411 concept EigenMatrixOrVoigtNotation##Size1 = EigenMatrix##Size1##Size1<M> or EigenVector##Size2<M>;
412
416
417 namespace Impl {
418 template <template <typename...> class MaterialToCheck, typename Material>
419 consteval bool isMaterial() {
420 if constexpr (traits::isSpecialization<MaterialToCheck, Material>::value)
421 return true;
422
423 if constexpr (traits::isSpecializationNonTypeAndTypes<VanishingStress, Material>::value) {
424 if constexpr (traits::isSpecialization<MaterialToCheck, typename Material::Underlying>::value) {
425 return true;
426 } else {
427 return false;
428 }
429 } else
430 return false;
431 }
432 } // namespace Impl
445 template <template <typename...> class MaterialToCheck, typename Material>
446 concept IsMaterial = Impl::isMaterial<MaterialToCheck, Material>();
447
448 namespace Impl {
449 template <typename T>
450 concept ResultType = requires(T t) {
451 typename T::type; // The nested type 'type'
452 typename T::Vectorizer; // The nested type 'Vectorizer'
453 typename T::Matricizer; // The nested type 'Matricizer'
454 { toString(t) } -> std::same_as<std::string>; // The toString function
455 };
456 } // namespace Impl
457
467 template <template <typename, int, int> typename RT>
468 concept ResultType =
469 Impl::ResultType<RT<double, 1, 1>> or Impl::ResultType<RT<double, 1, 2>> or Impl::ResultType<RT<double, 1, 3>> or
470 Impl::ResultType<RT<double, 2, 3>> or Impl::ResultType<RT<double, 3, 3>>;
471} // namespace Concepts
472} // namespace Ikarus
#define MAKE_EIGEN_FIXED_MATRIX_CONCEPT(Size1, Size2)
Definition: concepts.hh:367
#define MAKE_EIGEN_FIXED_MATRIX_OR_VOIGT_CONCEPT(Size1, Size2)
Definition: concepts.hh:409
#define MAKE_EIGEN_FIXED_VECTOR_CONCEPT(Size)
Definition: concepts.hh:355
Contains stl-like type traits.
Definition: simpleassemblers.hh:22
constexpr std::string toString(ScalarAffordances _e)
Definition: ferequirements.hh:37
auto transpose(const Eigen::EigenBase< Derived > &A)
Definition: truncatedconjugategradient.hh:24
Definition: concepts.hh:25
Concept to check if a basis uses FlatInterleaved indexing strategy.
Definition: concepts.hh:45
Concept to check if a node in a basis tree is a Lagrangian node.
Definition: concepts.hh:77
Definition: concepts.hh:87
Concept to check if a basis uses FlatLexicographic indexing strategy.
Definition: concepts.hh:98
Concept to check if a basis uses FlatIndex indexing strategy.
Definition: concepts.hh:111
Concept to check if a basis uses BlockedInterleaved indexing strategy.
Definition: concepts.hh:122
Concept to check if a basis uses BlockedLexicographic indexing strategy.
Definition: concepts.hh:135
Concept to check if a local basis is a duneLocalBasis.
Definition: concepts.hh:145
Concept to check if a basis uses either BlockedLexicographic or BlockedInterleaved indexing strategy.
Definition: concepts.hh:170
Concept defining the requirements for a path-following strategy.
Definition: concepts.hh:180
Concept to check if a type implements all the needed functions to be an adaptive step sizing method.
Definition: concepts.hh:195
Concept to check if a linear solver implements all the needed functions for given vector and matrix t...
Definition: concepts.hh:210
Concept to check if a non-linear solver with its non-linear operator satisfies requirements for path ...
Definition: concepts.hh:224
Concept defining the requirements for types that support multiplication.
Definition: concepts.hh:241
Concept defining the requirements for types that support addition.
Definition: concepts.hh:251
Concept defining the requirements for types that support subtraction.
Definition: concepts.hh:261
Concept defining the requirements for types that support in-place multiplication.
Definition: concepts.hh:272
Concept defining the requirements for types that support in-place division.
Definition: concepts.hh:283
Concept defining the requirements for types that support in-place addition.
Definition: concepts.hh:294
Concept defining the requirements for types that support in-place subtraction.
Definition: concepts.hh:305
Concept defining the requirements for types that support division.
Definition: concepts.hh:315
Concept defining the requirements for types that support negation.
Definition: concepts.hh:324
Concept defining the requirements for types that support transposition.
Definition: concepts.hh:333
Concept defining the requirements for functors with arguments.
Definition: concepts.hh:343
Concept defining the requirements for Eigen vectors.
Definition: concepts.hh:353
Concept defining the requirements for a material type.
Definition: concepts.hh:446
A concept to check if a template type satisfies the ResultType requirements.
Definition: concepts.hh:468