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/Dense>
20#include <Eigen/Sparse>
21
22#include <autodiff/forward/dual/dual.hpp>
23
27
28namespace Eigen {
29template <typename Derived>
30struct EigenBase;
31}
32
33namespace Ikarus {
34template <auto matrixIndexPair, typename MaterialImpl>
35struct VanishingStress;
36
37template <typename Derived>
39namespace Concepts {
40
49 template <typename Basis>
50 concept FlatInterLeavedBasis = requires {
51 std::is_same_v<typename Basis::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::FlatInterleaved>;
52 };
53
54 namespace Impl {
55 template <template <typename, int, typename> class U, typename T>
56 struct LagrangeNodeHelper : std::false_type
57 {
58 };
59 template <template <typename, int, typename> class U, typename GV, int k, typename R>
60 struct LagrangeNodeHelper<U, U<GV, k, R>> : std::true_type
61 {
62 };
63
64 template <template <typename, int, typename> class U, typename T, int k>
65 struct LagrangeNodeHelperOfOrder : std::false_type
66 {
67 };
68 template <template <typename, int, typename> class U, typename GV, int k, typename R>
69 struct LagrangeNodeHelperOfOrder<U, U<GV, k, R>, k> : std::true_type
70 {
71 };
72 } // namespace Impl
73
81 template <typename N>
82 concept LagrangeNode = Impl::LagrangeNodeHelper<Dune::Functions::LagrangeNode, N>::value;
83
91 template <typename N, int order>
92 concept LagrangeNodeOfOrder = Impl::LagrangeNodeHelperOfOrder<Dune::Functions::LagrangeNode, N, order>::value;
93
102 template <typename B>
103 concept FlatLexicographicBasis = requires {
104 std::is_same_v<typename B::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::FlatLexicographic>;
105 };
106
115 template <typename B>
117
126 template <typename Basis>
127 concept BlockedInterLeavedBasis = requires {
128 std::is_same_v<typename Basis::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::BlockedInterleaved>;
129 };
130
139 template <typename B>
140 concept BlockedLexicographicBasis = requires {
141 std::is_same_v<typename B::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::BlockedLexicographic>;
142 };
143
149 template <typename DLB>
150 concept DuneLocalBasis = requires(DLB& duneLocalBasis) {
151 typename DLB::Traits::RangeType;
152 typename DLB::Traits::JacobianType;
153 DLB::Traits::dimDomain;
154 typename DLB::Traits::DomainType;
155
156 typename DLB::Traits::DomainFieldType;
157 typename DLB::Traits::RangeFieldType;
158
159 duneLocalBasis.evaluateFunction(std::declval<typename DLB::Traits::DomainType>(),
160 std::declval<std::vector<typename DLB::Traits::RangeType>&>());
161 duneLocalBasis.evaluateJacobian(std::declval<typename DLB::Traits::DomainType>(),
162 std::declval<std::vector<typename DLB::Traits::JacobianType>&>());
163 };
164
174 template <typename B>
176
184 template <typename PF, typename NLO, typename SA>
185 concept PathFollowingStrategy = requires(PF pft, NLO nop, SA args) {
186 { pft(args) } -> std::same_as<void>;
187 { pft.initialPrediction(nop, args) } -> std::same_as<void>;
188 { pft.intermediatePrediction(nop, args) } -> std::same_as<void>;
189 };
190
199 template <typename ASS, typename NLSI, typename SA, typename NonLinearOperator>
200 concept AdaptiveStepSizingStrategy = requires(ASS adaptiveStepSizing, NLSI info, SA args, NonLinearOperator nop) {
201 { adaptiveStepSizing(info, args, nop) } -> std::same_as<void>;
202 { adaptiveStepSizing.targetIterations() } -> std::same_as<int>;
203 { adaptiveStepSizing.setTargetIterations(std::declval<int>()) } -> std::same_as<void>;
204 };
205
214 template <typename LS, typename M, typename V>
215 concept LinearSolverCheck = requires(LS& linearSolver, M& A, V& vec) {
216 linearSolver.analyzePattern(A);
217 linearSolver.factorize(A);
218 linearSolver.solve(vec, vec);
219 };
220
228 template <typename NLS>
230 std::tuple_size<typename NLS::NonLinearOperator::ParameterValues>::value == 2;
231 not(std::is_same_v<typename NLS::NonLinearOperator::ValueType, double> and
232 ((traits::isSpecializationTypeAndNonTypes<Eigen::Matrix,
233 typename NLS::NonLinearOperator::DerivativeType>::value) or
234 (traits::isSpecializationTypeNonTypeAndType<Eigen::SparseMatrix,
235 typename NLS::NonLinearOperator::DerivativeType>::value)));
236 };
237
245 template <typename L, typename R>
246 concept MultiplyAble = requires(L x, R y) { x* y; };
247
255 template <typename L, typename R>
256 concept AddAble = requires(L x, R y) { x + y; };
257
265 template <typename L, typename R>
266 concept SubstractAble = requires(L x, R y) { x - y; };
267
276 template <typename L, typename R>
277 concept MultiplyAssignAble = requires(L x, R y) { x *= y; };
278
287 template <typename L, typename R>
288 concept DivideAssignAble = requires(L x, R y) { x /= y; };
289
298 template <typename L, typename R>
299 concept AddAssignAble = requires(L x, R y) { x += y; };
300
309 template <typename L, typename R>
310 concept SubstractAssignAble = requires(L x, R y) { x -= y; };
311
319 template <typename L, typename R>
320 concept DivideAble = requires(L x, R y) { x / y; };
321
328 template <typename L>
329 concept NegateAble = requires(L x) { -x; };
330
337 template <typename L>
338 concept TransposeAble = requires(L x) { transpose(x); };
339
346 template <typename Op, typename... Args>
347 concept IsFunctorWithArgs = requires(Op op, Args... args) { op(args...); };
348
354 template <typename V>
355 concept EigenVector = static_cast<bool>(V::IsVectorAtCompileTime);
356
362 template <typename M>
363 concept EigenMatrix = traits::isSpecializationTypeAndNonTypes<Eigen::Matrix, M>::value;
364
365#define MAKE_EIGEN_FIXED_VECTOR_CONCEPT(Size) \
366 template <typename V> \
367 concept EigenVector##Size = \
368 static_cast<bool>(V::IsVectorAtCompileTime) and static_cast<bool>(V::SizeAtCompileTime == Size);
369
376
377#define MAKE_EIGEN_FIXED_MATRIX_CONCEPT(Size1, Size2) \
378 template <typename M> \
379 concept EigenMatrix##Size1##Size2 = static_cast<bool>(std::remove_cvref_t<M>::RowsAtCompileTime == Size1) and \
380 static_cast<bool>(std::remove_cvref_t<M>::ColsAtCompileTime == Size2);
381
383
386
391
398
407
418
419#define MAKE_EIGEN_FIXED_MATRIX_OR_VOIGT_CONCEPT(Size1, Size2) \
420 template <typename M> \
421 concept EigenMatrixOrVoigtNotation##Size1 = EigenMatrix##Size1##Size1<M> or EigenVector##Size2<M>;
422
426
427 namespace Impl {
428 template <template <typename...> class MaterialToCheck, typename Material>
429 consteval bool isMaterial() {
430 if constexpr (traits::isSpecialization<MaterialToCheck, Material>::value)
431 return true;
432
433 if constexpr (Material::isReduced) {
434 if constexpr (traits::isSpecialization<MaterialToCheck, typename Material::Underlying>::value) {
435 return true;
436 } else {
437 return false;
438 }
439 } else
440 return false;
441 }
442 } // namespace Impl
443
456 template <template <typename...> class MaterialToCheck, typename Material>
457 concept IsMaterial = Impl::isMaterial<MaterialToCheck, Material>();
458
459 namespace Impl {
460 template <typename T>
461 concept ResultType = requires(T t) {
462 typename T::type; // The nested type 'type'
463 typename T::Vectorizer; // The nested type 'Vectorizer'
464 typename T::Matricizer; // The nested type 'Matricizer'
465 { toString(t) } -> std::same_as<std::string>; // The toString function
466 };
467 } // namespace Impl
468
475 template <typename MAT>
477
487 template <template <typename, int, int> typename RT>
488 concept ResultType =
489 Impl::ResultType<RT<double, 1, 1>> or Impl::ResultType<RT<double, 1, 2>> or Impl::ResultType<RT<double, 1, 3>> or
490 Impl::ResultType<RT<double, 2, 3>> or Impl::ResultType<RT<double, 3, 3>>;
491
499 template <typename T>
500 concept FlatAssembler = requires(T t, const typename T::FERequirement& req,
501 typename T::AffordanceCollectionType affordance, DBCOption dbcOption) {
502 { t.requirement() } -> std::convertible_to<typename T::FERequirement&>;
503 { t.affordanceCollection() } -> std::convertible_to<typename T::AffordanceCollectionType>;
504 { t.dBCOption() } -> std::convertible_to<DBCOption>;
505
506 { t.bind(req, affordance, dbcOption) } -> std::same_as<void>;
507 { t.bind(req) } -> std::same_as<void>;
508 { t.bind(affordance) } -> std::same_as<void>;
509 { t.bind(dbcOption) } -> std::same_as<void>;
510
511 { t.bound() } -> std::convertible_to<bool>;
512 { t.boundToRequirement() } -> std::convertible_to<bool>;
513 { t.boundToAffordanceCollection() } -> std::convertible_to<bool>;
514 { t.boundToDBCOption() } -> std::convertible_to<bool>;
515 { t.estimateOfConnectivity() } -> std::convertible_to<size_t>;
516
517 { t.createFullVector(std::declval<Eigen::Ref<const Eigen::VectorXd>>()) } -> std::convertible_to<Eigen::VectorXd>;
518 { t.constraintsBelow(std::declval<size_t>()) } -> std::convertible_to<size_t>;
519 { t.isConstrained(std::declval<size_t>()) } -> std::convertible_to<bool>;
520 { t.size() } -> std::convertible_to<size_t>;
521 { t.reducedSize() } -> std::convertible_to<size_t>;
522 };
523
530 template <typename T>
532 Concepts::FlatAssembler<T> and requires(T t, const typename T::FERequirement& req,
533 typename T::AffordanceCollectionType affordance, DBCOption dbcOption) {
534 { t.scalar(req, affordance.scalarAffordance()) } -> std::convertible_to<const double&>;
535 { t.scalar() } -> std::convertible_to<const double&>;
536 };
537
544 template <typename T>
546 requires(T t, const typename T::FERequirement& req,
547 typename T::AffordanceCollectionType affordance, DBCOption dbcOption) {
548 {
549 t.vector(req, affordance.vectorAffordance(), dbcOption)
550 } -> std::convertible_to<const Eigen::VectorXd&>;
551 { t.vector(dbcOption) } -> std::convertible_to<const Eigen::VectorXd&>;
552 { t.vector() } -> std::convertible_to<const Eigen::VectorXd&>;
553 };
554
561 template <typename T>
563 requires(T t, const typename T::FERequirement& req,
564 typename T::AffordanceCollectionType affordance, DBCOption dbcOption) {
565 { t.matrix(req, affordance.matrixAffordance(), dbcOption) };
566 { t.matrix(dbcOption) };
567 { t.matrix() };
568 };
569
570 // adapted from /dune/dune-vtk/dune/vtk/utility/concepts.hh
571 template <class DC>
572 concept DataCollector = requires(DC dc) {
573 typename DC::GridView;
574 { dc.update() } -> std::same_as<void>;
575 { dc.numPoints() } -> std::convertible_to<std::uint64_t>;
576 { dc.numCells() } -> std::convertible_to<std::uint64_t>;
577 { dc.gridView() } -> std::same_as<const typename DC::GridView&>;
578 };
579
580 template <class GV>
581 concept GridView = requires(GV g) {
582 typename GV::Grid;
583 GV::dimension;
584 GV::dimensionworld;
585
586 { g.grid() };
587 };
588
589 namespace Impl {
590 template <typename T>
591 struct is_dual : std::false_type
592 {
593 };
594
595 // Specialization for Dual<T, U>: this will be true for Dual types
596 template <typename T, typename U>
597 struct is_dual<autodiff::detail::Dual<T, U>> : std::true_type
598 {
599 };
600 } // namespace Impl
601
607 template <typename T>
608 concept AutodiffScalar = Impl::is_dual<T>::value;
609
610} // namespace Concepts
611} // namespace Ikarus
Contains stl-like type traits.
#define MAKE_EIGEN_FIXED_MATRIX_CONCEPT(Size1, Size2)
Definition: concepts.hh:377
#define MAKE_EIGEN_FIXED_MATRIX_OR_VOIGT_CONCEPT(Size1, Size2)
Definition: concepts.hh:419
#define MAKE_EIGEN_FIXED_VECTOR_CONCEPT(Size)
Definition: concepts.hh:365
Definition of several material related enums.
Definition: assemblermanipulatorbuildingblocks.hh:22
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
static constexpr bool isReduced
Static constant for determining if the material has vanishing stress or strain components (is reduced...
Definition: finiteelements/mechanics/materials/interface.hh:86
Definition: concepts.hh:30
Concept to check if a basis uses FlatInterleaved indexing strategy.
Definition: concepts.hh:50
Concept to check if a node in a basis tree is a Lagrangian node.
Definition: concepts.hh:82
Definition: concepts.hh:92
Concept to check if a basis uses FlatLexicographic indexing strategy.
Definition: concepts.hh:103
Concept to check if a basis uses FlatIndex indexing strategy.
Definition: concepts.hh:116
Concept to check if a basis uses BlockedInterleaved indexing strategy.
Definition: concepts.hh:127
Concept to check if a basis uses BlockedLexicographic indexing strategy.
Definition: concepts.hh:140
Concept to check if a local basis is a duneLocalBasis.
Definition: concepts.hh:150
Concept to check if a basis uses either BlockedLexicographic or BlockedInterleaved indexing strategy.
Definition: concepts.hh:175
Concept defining the requirements for a path-following strategy.
Definition: concepts.hh:185
Concept to check if a type implements all the needed functions to be an adaptive step sizing method.
Definition: concepts.hh:200
Concept to check if a linear solver implements all the needed functions for given vector and matrix t...
Definition: concepts.hh:215
Concept to check if a non-linear solver with its non-linear operator satisfies requirements for path ...
Definition: concepts.hh:229
Concept defining the requirements for types that support multiplication.
Definition: concepts.hh:246
Concept defining the requirements for types that support addition.
Definition: concepts.hh:256
Concept defining the requirements for types that support subtraction.
Definition: concepts.hh:266
Concept defining the requirements for types that support in-place multiplication.
Definition: concepts.hh:277
Concept defining the requirements for types that support in-place division.
Definition: concepts.hh:288
Concept defining the requirements for types that support in-place addition.
Definition: concepts.hh:299
Concept defining the requirements for types that support in-place subtraction.
Definition: concepts.hh:310
Concept defining the requirements for types that support division.
Definition: concepts.hh:320
Concept defining the requirements for types that support negation.
Definition: concepts.hh:329
Concept defining the requirements for types that support transposition.
Definition: concepts.hh:338
Concept defining the requirements for functors with arguments.
Definition: concepts.hh:347
Concept defining the requirements for Eigen vectors.
Definition: concepts.hh:355
Concept defining the requirements for Eigen matrices. This also includes Eigen vectors.
Definition: concepts.hh:363
Concept defining the requirements for a material type.
Definition: concepts.hh:457
Concepts defining the requirements for a material to be geometrically linear This is the case when th...
Definition: concepts.hh:476
A concept to check if a template type satisfies the ResultType requirements.
Definition: concepts.hh:488
Concept representing the requirements for a FlatAssembler.A type T satisfies FlatAssembler if it prov...
Definition: concepts.hh:500
Concept representing the requirements for a ScalarFlatAssembler.A type T satisfies ScalarFlatAssemble...
Definition: concepts.hh:531
Concept representing the requirements for a VectorFlatAssembler.A type T satisfies VectorFlatAssemble...
Definition: concepts.hh:545
Concept representing the requirements for a MatrixFlatAssembler.A type T satisfies MatrixFlatAssemble...
Definition: concepts.hh:562
Definition: concepts.hh:572
Definition: concepts.hh:581
Concept to check if the underlying scalar type is a dual type.
Definition: concepts.hh:608