version 0.4.2
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/Dense>
20#include <Eigen/Sparse>
21
24
25namespace Eigen {
26template <typename Derived>
27struct EigenBase;
28}
29
30namespace Ikarus {
31template <auto stressIndexPair, typename MaterialImpl>
32struct VanishingStress;
33
34template <typename Derived>
36namespace Concepts {
37
46 template <typename Basis>
47 concept FlatInterLeavedBasis = requires {
48 std::is_same_v<typename Basis::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::FlatInterleaved>;
49 };
50
51 namespace Impl {
52 template <template <typename, int, typename> class U, typename T>
53 struct LagrangeNodeHelper : std::false_type
54 {
55 };
56 template <template <typename, int, typename> class U, typename GV, int k, typename R>
57 struct LagrangeNodeHelper<U, U<GV, k, R>> : std::true_type
58 {
59 };
60
61 template <template <typename, int, typename> class U, typename T, int k>
62 struct LagrangeNodeHelperOfOrder : std::false_type
63 {
64 };
65 template <template <typename, int, typename> class U, typename GV, int k, typename R>
66 struct LagrangeNodeHelperOfOrder<U, U<GV, k, R>, k> : std::true_type
67 {
68 };
69 } // namespace Impl
70
78 template <typename N>
79 concept LagrangeNode = Impl::LagrangeNodeHelper<Dune::Functions::LagrangeNode, N>::value;
80
88 template <typename N, int order>
89 concept LagrangeNodeOfOrder = Impl::LagrangeNodeHelperOfOrder<Dune::Functions::LagrangeNode, N, order>::value;
90
99 template <typename B>
100 concept FlatLexicographicBasis = requires {
101 std::is_same_v<typename B::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::FlatLexicographic>;
102 };
103
112 template <typename B>
114
123 template <typename Basis>
124 concept BlockedInterLeavedBasis = requires {
125 std::is_same_v<typename Basis::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::BlockedInterleaved>;
126 };
127
136 template <typename B>
137 concept BlockedLexicographicBasis = requires {
138 std::is_same_v<typename B::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::BlockedLexicographic>;
139 };
140
146 template <typename DLB>
147 concept DuneLocalBasis = requires(DLB& duneLocalBasis) {
148 typename DLB::Traits::RangeType;
149 typename DLB::Traits::JacobianType;
150 DLB::Traits::dimDomain;
151 typename DLB::Traits::DomainType;
152
153 typename DLB::Traits::DomainFieldType;
154 typename DLB::Traits::RangeFieldType;
155
156 duneLocalBasis.evaluateFunction(std::declval<typename DLB::Traits::DomainType>(),
157 std::declval<std::vector<typename DLB::Traits::RangeType>&>());
158 duneLocalBasis.evaluateJacobian(std::declval<typename DLB::Traits::DomainType>(),
159 std::declval<std::vector<typename DLB::Traits::JacobianType>&>());
160 };
161
171 template <typename B>
173
181 template <typename PF, typename NLO, typename SA>
182 concept PathFollowingStrategy = requires(PF pft, NLO nop, SA args) {
183 { pft(args) } -> std::same_as<void>;
184 { pft.initialPrediction(nop, args) } -> std::same_as<void>;
185 { pft.intermediatePrediction(nop, args) } -> std::same_as<void>;
186 };
187
196 template <typename ASS, typename NLSI, typename SA, typename NonLinearOperator>
197 concept AdaptiveStepSizingStrategy = requires(ASS adaptiveStepSizing, NLSI info, SA args, NonLinearOperator nop) {
198 { adaptiveStepSizing(info, args, nop) } -> std::same_as<void>;
199 { adaptiveStepSizing.targetIterations() } -> std::same_as<int>;
200 { adaptiveStepSizing.setTargetIterations(std::declval<int>()) } -> std::same_as<void>;
201 };
202
211 template <typename LS, typename M, typename V>
212 concept LinearSolverCheck = requires(LS& linearSolver, M& A, V& vec) {
213 linearSolver.analyzePattern(A);
214 linearSolver.factorize(A);
215 linearSolver.solve(vec, vec);
216 };
217
225 template <typename NLS>
227 std::tuple_size<typename NLS::NonLinearOperator::ParameterValues>::value == 2;
228 not(std::is_same_v<typename NLS::NonLinearOperator::ValueType, double> and
229 ((traits::isSpecializationTypeAndNonTypes<Eigen::Matrix,
230 typename NLS::NonLinearOperator::DerivativeType>::value) or
231 (traits::isSpecializationTypeNonTypeAndType<Eigen::SparseMatrix,
232 typename NLS::NonLinearOperator::DerivativeType>::value)));
233 };
234
242 template <typename L, typename R>
243 concept MultiplyAble = requires(L x, R y) { x* y; };
244
252 template <typename L, typename R>
253 concept AddAble = requires(L x, R y) { x + y; };
254
262 template <typename L, typename R>
263 concept SubstractAble = requires(L x, R y) { x - y; };
264
273 template <typename L, typename R>
274 concept MultiplyAssignAble = requires(L x, R y) { x *= y; };
275
284 template <typename L, typename R>
285 concept DivideAssignAble = requires(L x, R y) { x /= y; };
286
295 template <typename L, typename R>
296 concept AddAssignAble = requires(L x, R y) { x += y; };
297
306 template <typename L, typename R>
307 concept SubstractAssignAble = requires(L x, R y) { x -= y; };
308
316 template <typename L, typename R>
317 concept DivideAble = requires(L x, R y) { x / y; };
318
325 template <typename L>
326 concept NegateAble = requires(L x) { -x; };
327
334 template <typename L>
335 concept TransposeAble = requires(L x) { transpose(x); };
336
343 template <typename Op, typename... Args>
344 concept IsFunctorWithArgs = requires(Op op, Args... args) { op(args...); };
345
351 template <typename V>
352 concept EigenVector = static_cast<bool>(V::IsVectorAtCompileTime);
353
359 template <typename M>
360 concept EigenMatrix = traits::isSpecializationTypeAndNonTypes<Eigen::Matrix, M>::value;
361
362#define MAKE_EIGEN_FIXED_VECTOR_CONCEPT(Size) \
363 template <typename V> \
364 concept EigenVector##Size = \
365 static_cast<bool>(V::IsVectorAtCompileTime) and static_cast<bool>(V::SizeAtCompileTime == Size);
366
373
374#define MAKE_EIGEN_FIXED_MATRIX_CONCEPT(Size1, Size2) \
375 template <typename M> \
376 concept EigenMatrix##Size1##Size2 = static_cast<bool>(std::remove_cvref_t<M>::RowsAtCompileTime == Size1) and \
377 static_cast<bool>(std::remove_cvref_t<M>::ColsAtCompileTime == Size2);
378
380
383
388
395
404
415
416#define MAKE_EIGEN_FIXED_MATRIX_OR_VOIGT_CONCEPT(Size1, Size2) \
417 template <typename M> \
418 concept EigenMatrixOrVoigtNotation##Size1 = EigenMatrix##Size1##Size1<M> or EigenVector##Size2<M>;
419
423
424 namespace Impl {
425 template <template <typename...> class MaterialToCheck, typename Material>
426 consteval bool isMaterial() {
427 if constexpr (traits::isSpecialization<MaterialToCheck, Material>::value)
428 return true;
429
430 if constexpr (traits::isSpecializationNonTypeAndTypes<VanishingStress, Material>::value) {
431 if constexpr (traits::isSpecialization<MaterialToCheck, typename Material::Underlying>::value) {
432 return true;
433 } else {
434 return false;
435 }
436 } else
437 return false;
438 }
439 } // namespace Impl
452 template <template <typename...> class MaterialToCheck, typename Material>
453 concept IsMaterial = Impl::isMaterial<MaterialToCheck, Material>();
454
455 namespace Impl {
456 template <typename T>
457 concept ResultType = requires(T t) {
458 typename T::type; // The nested type 'type'
459 typename T::Vectorizer; // The nested type 'Vectorizer'
460 typename T::Matricizer; // The nested type 'Matricizer'
461 { toString(t) } -> std::same_as<std::string>; // The toString function
462 };
463 } // namespace Impl
464
474 template <template <typename, int, int> typename RT>
475 concept ResultType =
476 Impl::ResultType<RT<double, 1, 1>> or Impl::ResultType<RT<double, 1, 2>> or Impl::ResultType<RT<double, 1, 3>> or
477 Impl::ResultType<RT<double, 2, 3>> or Impl::ResultType<RT<double, 3, 3>>;
478
486 template <typename T>
487 concept FlatAssembler = requires(T t, const typename T::FERequirement& req,
488 typename T::AffordanceCollectionType affordance, DBCOption dbcOption) {
489 { t.scalar(req, affordance.scalarAffordance()) } -> std::convertible_to<const double&>;
490 { t.scalar() } -> std::convertible_to<const double&>;
491
492 { t.vector(req, affordance.vectorAffordance(), dbcOption) } -> std::convertible_to<const Eigen::VectorXd&>;
493 { t.vector(dbcOption) } -> std::convertible_to<const Eigen::VectorXd&>;
494 { t.vector() } -> std::convertible_to<const Eigen::VectorXd&>;
495
496 { t.matrix(req, affordance.matrixAffordance(), dbcOption) };
497 { t.matrix(dbcOption) };
498 { t.matrix() };
499
500 { t.requirement() } -> std::convertible_to<typename T::FERequirement&>;
501 { t.affordanceCollection() } -> std::convertible_to<typename T::AffordanceCollectionType>;
502 { t.dBCOption() } -> std::convertible_to<DBCOption>;
503
504 { t.bind(req, affordance, dbcOption) } -> std::same_as<void>;
505 { t.bind(req) } -> std::same_as<void>;
506 { t.bind(affordance) } -> std::same_as<void>;
507 { t.bind(dbcOption) } -> std::same_as<void>;
508
509 { t.bound() } -> std::convertible_to<bool>;
510 { t.boundToRequirement() } -> std::convertible_to<bool>;
511 { t.boundToAffordanceCollection() } -> std::convertible_to<bool>;
512 { t.boundToDBCOption() } -> std::convertible_to<bool>;
513 { t.estimateOfConnectivity() } -> std::convertible_to<size_t>;
514
515 { t.createFullVector(std::declval<Eigen::Ref<const Eigen::VectorXd>>()) } -> std::convertible_to<Eigen::VectorXd>;
516 { t.constraintsBelow(std::declval<size_t>()) } -> std::convertible_to<size_t>;
517 { t.isConstrained(std::declval<size_t>()) } -> std::convertible_to<bool>;
518 { t.size() } -> std::convertible_to<size_t>;
519 { t.reducedSize() } -> std::convertible_to<size_t>;
520 };
521
522} // namespace Concepts
523} // namespace Ikarus
Contains stl-like type traits.
#define MAKE_EIGEN_FIXED_MATRIX_CONCEPT(Size1, Size2)
Definition: concepts.hh:374
#define MAKE_EIGEN_FIXED_MATRIX_OR_VOIGT_CONCEPT(Size1, Size2)
Definition: concepts.hh:416
#define MAKE_EIGEN_FIXED_VECTOR_CONCEPT(Size)
Definition: concepts.hh:362
Definition: dirichletbcenforcement.hh:6
DBCOption
Definition: dirichletbcenforcement.hh:7
NonLinearOperator(const Impl::Functions< DerivativeArgs &&... > &a, const Impl::Parameter< ParameterArgs... > &b) -> NonLinearOperator< Impl::Functions< DerivativeArgs... >, Impl::Parameter< ParameterArgs... > >
auto transpose(const Eigen::EigenBase< Derived > &A)
constexpr std::string toString(DBCOption _e)
Definition: dirichletbcenforcement.hh:7
Definition: truncatedconjugategradient.hh:24
Definition: concepts.hh:27
Concept to check if a basis uses FlatInterleaved indexing strategy.
Definition: concepts.hh:47
Concept to check if a node in a basis tree is a Lagrangian node.
Definition: concepts.hh:79
Definition: concepts.hh:89
Concept to check if a basis uses FlatLexicographic indexing strategy.
Definition: concepts.hh:100
Concept to check if a basis uses FlatIndex indexing strategy.
Definition: concepts.hh:113
Concept to check if a basis uses BlockedInterleaved indexing strategy.
Definition: concepts.hh:124
Concept to check if a basis uses BlockedLexicographic indexing strategy.
Definition: concepts.hh:137
Concept to check if a local basis is a duneLocalBasis.
Definition: concepts.hh:147
Concept to check if a basis uses either BlockedLexicographic or BlockedInterleaved indexing strategy.
Definition: concepts.hh:172
Concept defining the requirements for a path-following strategy.
Definition: concepts.hh:182
Concept to check if a type implements all the needed functions to be an adaptive step sizing method.
Definition: concepts.hh:197
Concept to check if a linear solver implements all the needed functions for given vector and matrix t...
Definition: concepts.hh:212
Concept to check if a non-linear solver with its non-linear operator satisfies requirements for path ...
Definition: concepts.hh:226
Concept defining the requirements for types that support multiplication.
Definition: concepts.hh:243
Concept defining the requirements for types that support addition.
Definition: concepts.hh:253
Concept defining the requirements for types that support subtraction.
Definition: concepts.hh:263
Concept defining the requirements for types that support in-place multiplication.
Definition: concepts.hh:274
Concept defining the requirements for types that support in-place division.
Definition: concepts.hh:285
Concept defining the requirements for types that support in-place addition.
Definition: concepts.hh:296
Concept defining the requirements for types that support in-place subtraction.
Definition: concepts.hh:307
Concept defining the requirements for types that support division.
Definition: concepts.hh:317
Concept defining the requirements for types that support negation.
Definition: concepts.hh:326
Concept defining the requirements for types that support transposition.
Definition: concepts.hh:335
Concept defining the requirements for functors with arguments.
Definition: concepts.hh:344
Concept defining the requirements for Eigen vectors.
Definition: concepts.hh:352
Concept defining the requirements for Eigen matrices. This also includes Eigen vectors.
Definition: concepts.hh:360
Concept defining the requirements for a material type.
Definition: concepts.hh:453
A concept to check if a template type satisfies the ResultType requirements.
Definition: concepts.hh:475
Concept representing the requirements for a FlatAssembler.A type T satisfies FlatAssembler if it prov...
Definition: concepts.hh:487