version 0.4
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 {
24 template <typename Derived>
25 struct EigenBase;
26}
27
28namespace Ikarus {
29 template <auto stressIndexPair, typename MaterialImpl>
30 struct VanishingStress;
31
32 template <typename Derived>
34 namespace 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 template <template <typename, int, typename> class U, typename GV, int k, typename R>
53 struct LagrangeNodeHelper<U, U<GV, k, R>> : std::true_type {};
54
55 template <template <typename, int, typename> class U, typename T, int k>
56 struct LagrangeNodeHelperOfOrder : std::false_type {};
57 template <template <typename, int, typename> class U, typename GV, int k, typename R>
58 struct LagrangeNodeHelperOfOrder<U, U<GV, k, R>, k> : std::true_type {};
59 } // namespace Impl
60
68 template <typename Node>
69 concept LagrangeNode = Impl::LagrangeNodeHelper<Dune::Functions::LagrangeNode, Node>::value;
70
78 template <typename Node, int order>
79 concept LagrangeNodeOfOrder = Impl::LagrangeNodeHelperOfOrder<Dune::Functions::LagrangeNode, Node, order>::value;
80
89 template <typename Basis>
90 concept FlatLexicographicBasis = requires {
91 std::is_same_v<typename Basis::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::FlatLexicographic>;
92 };
93
102 template <typename Basis>
104
113 template <typename Basis>
114 concept BlockedInterLeavedBasis = requires {
115 std::is_same_v<typename Basis::PreBasis::IndexMergingStrategy, Dune::Functions::BasisFactory::BlockedInterleaved>;
116 };
117
126 template <typename Basis>
127 concept BlockedLexicographicBasis = requires {
128 std::is_same_v<typename Basis::PreBasis::IndexMergingStrategy,
129 Dune::Functions::BasisFactory::BlockedLexicographic>;
130 };
131
137 template <typename DuneLocalBasisImpl>
138 concept DuneLocalBasis = requires(DuneLocalBasisImpl& duneLocalBasis) {
139 typename DuneLocalBasisImpl::Traits::RangeType;
140 typename DuneLocalBasisImpl::Traits::JacobianType;
141 DuneLocalBasisImpl::Traits::dimDomain;
142 typename DuneLocalBasisImpl::Traits::DomainType;
143
144 typename DuneLocalBasisImpl::Traits::DomainFieldType;
145 typename DuneLocalBasisImpl::Traits::RangeFieldType;
146
147 duneLocalBasis.evaluateFunction(std::declval<typename DuneLocalBasisImpl::Traits::DomainType>(),
148 std::declval<std::vector<typename DuneLocalBasisImpl::Traits::RangeType>&>());
149 duneLocalBasis.evaluateJacobian(std::declval<typename DuneLocalBasisImpl::Traits::DomainType>(),
150 std::declval<std::vector<typename DuneLocalBasisImpl::Traits::JacobianType>&>());
151 };
152
162 template <typename Basis>
164
173 template <typename Basis>
174 concept PowerBasis = requires {
175 Basis::PreBasis::Node::isPower == true;
176 };
177
185 template <typename PathFollowingImpl, typename NonLinearOperator, typename SubsidiaryArgs>
186 concept PathFollowingStrategy = requires(PathFollowingImpl pft, NonLinearOperator nop, SubsidiaryArgs args) {
187 { pft(args) } -> std::same_as<void>;
188 { pft.initialPrediction(nop, args) } -> std::same_as<void>;
189 { pft.intermediatePrediction(nop, args) } -> std::same_as<void>;
190 };
191
200 template <typename AdaptiveStepSizing, typename NonLinearSolverInformation, typename SubsidiaryArgs,
201 typename NonLinearOperator>
202 concept AdaptiveStepSizingStrategy = requires(AdaptiveStepSizing adaptiveSS, NonLinearSolverInformation info,
203 SubsidiaryArgs args, NonLinearOperator nop) {
204 { adaptiveSS(info, args, nop) } -> std::same_as<void>;
205 { adaptiveSS.targetIterations() } -> std::same_as<int>;
206 { adaptiveSS.setTargetIterations(std::declval<int>()) } -> std::same_as<void>;
207 };
208
217 template <typename LinearSolver, typename MatrixType, typename VectorType>
218 concept LinearSolverCheck = requires(LinearSolver& linearSolver, MatrixType& Ax, VectorType& vec) {
219 linearSolver.analyzePattern(Ax);
220 linearSolver.factorize(Ax);
221 linearSolver.solve(vec, vec);
222 };
223
231 template <typename NonLinearSolver>
233 std::tuple_size<typename NonLinearSolver::NonLinearOperator::ParameterValues>::value == 2;
234 not(std::is_same_v<
235 typename NonLinearSolver::NonLinearOperator::ValueType,
236 double> and ((traits::isSpecializationTypeAndNonTypes<Eigen::Matrix, typename NonLinearSolver::NonLinearOperator::DerivativeType>::value) or (traits::isSpecializationTypeNonTypeAndType<Eigen::SparseMatrix, typename NonLinearSolver::NonLinearOperator::DerivativeType>::value)));
237 };
238
246 template <typename L, typename R>
247 concept MultiplyAble = requires(L x, R y) {
248 x* y;
249 };
250
258 template <typename L, typename R>
259 concept AddAble = requires(L x, R y) {
260 x + y;
261 };
262
270 template <typename L, typename R>
271 concept SubstractAble = requires(L x, R y) {
272 x - y;
273 };
274
283 template <typename L, typename R>
284 concept MultiplyAssignAble = requires(L x, R y) {
285 x *= y;
286 };
287
296 template <typename L, typename R>
297 concept DivideAssignAble = requires(L x, R y) {
298 x /= y;
299 };
300
309 template <typename L, typename R>
310 concept AddAssignAble = requires(L x, R y) {
311 x += y;
312 };
313
322 template <typename L, typename R>
323 concept SubstractAssignAble = requires(L x, R y) {
324 x -= y;
325 };
326
334 template <typename L, typename R>
335 concept DivideAble = requires(L x, R y) {
336 x / y;
337 };
338
345 template <typename L>
346 concept NegateAble = requires(L x) {
347 -x;
348 };
349
356 template <typename L>
357 concept TransposeAble = requires(L x) {
358 transpose(x);
359 };
360
368 template <typename Op, typename... Args>
369 concept IsFunctorWithArgs = requires(Op op, Args... args) {
370 op(args...);
371 };
372
380 template <typename V>
381 concept EigenVector = static_cast<bool>(V::IsVectorAtCompileTime);
382
383#define MAKE_EIGEN_FIXED_VECTOR_CONCEPT(Size) \
384 template <typename V> \
385 concept EigenVector##Size \
386 = static_cast<bool>(V::IsVectorAtCompileTime) and static_cast<bool>(V::SizeAtCompileTime == Size);
387
394
395#define MAKE_EIGEN_FIXED_MATRIX_CONCEPT(Size1, Size2) \
396 template <typename M> \
397 concept EigenMatrix##Size1##Size2 = static_cast<bool>(std::remove_cvref_t<M>::RowsAtCompileTime == Size1) \
398 and static_cast<bool>(std::remove_cvref_t<M>::ColsAtCompileTime == Size2);
399
401
404
409
416
425
436
437#define MAKE_EIGEN_FIXED_MATRIX_OR_VOIGT_CONCEPT(Size1, Size2) \
438 template <typename M> \
439 concept EigenMatrixOrVoigtNotation##Size1 = EigenMatrix##Size1##Size1<M> or EigenVector##Size2<M>;
440
444
445 namespace Impl {
446 template <template <typename...> class MaterialToCheck, typename Material>
447 consteval bool isMaterial() {
448 if constexpr (traits::isSpecialization<MaterialToCheck, Material>::value) return true;
449
450 if constexpr (traits::isSpecializationNonTypeAndTypes<VanishingStress, Material>::value) {
451 if constexpr (traits::isSpecialization<MaterialToCheck, typename Material::Underlying>::value) {
452 return true;
453 } else {
454 return false;
455 }
456 } else
457 return false;
458 }
459 } // namespace Impl
472 template <template <typename...> class MaterialToCheck, typename Material>
473 concept IsMaterial = Impl::isMaterial<MaterialToCheck, Material>();
474
475 } // namespace Concepts
476} // namespace Ikarus
#define MAKE_EIGEN_FIXED_MATRIX_CONCEPT(Size1, Size2)
Definition: concepts.hh:395
#define MAKE_EIGEN_FIXED_MATRIX_OR_VOIGT_CONCEPT(Size1, Size2)
Definition: concepts.hh:437
#define MAKE_EIGEN_FIXED_VECTOR_CONCEPT(Size)
Definition: concepts.hh:383
Contains stl-like type traits.
Definition: simpleassemblers.hh:21
auto transpose(const Eigen::EigenBase< Derived > &A)
LinearSolverTemplate< double > LinearSolver
Definition: linearsolver.hh:234
Definition: truncatedconjugategradient.hh:24
Structure containing arguments for subsidiary functions.
Definition: pathfollowingfunctions.hh:38
Information about the result of a non-linear solver.
Definition: solverinfos.hh:18
Definition: concepts.hh:25
Represents a NonLinearOperator class for handling nonlinear operators.
Definition: nonlinearoperator.hh:154
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:69
Definition: concepts.hh:79
Concept to check if a basis uses FlatLexicographic indexing strategy.
Definition: concepts.hh:90
Concept to check if a basis uses FlatIndex indexing strategy.
Definition: concepts.hh:103
Concept to check if a basis uses BlockedInterleaved indexing strategy.
Definition: concepts.hh:114
Concept to check if a basis uses BlockedLexicographic indexing strategy.
Definition: concepts.hh:127
Concept to check if a local basis is a duneLocalBasis.
Definition: concepts.hh:138
Concept to check if a basis uses either BlockedLexicographic or BlockedInterleaved indexing strategy.
Definition: concepts.hh:163
Concept to check if a basis uses power indexing strategy.
Definition: concepts.hh:174
Concept defining the requirements for a path-following strategy.
Definition: concepts.hh:186
Concept to check if a type implements all the needed functions to be an adaptive step sizing method.
Definition: concepts.hh:202
Concept to check if a linear solver implements all the needed functions for given vector and matrix t...
Definition: concepts.hh:218
Concept to check if a non-linear solver with its non-linear operator satisfies requirements for path ...
Definition: concepts.hh:232
Concept defining the requirements for types that support multiplication.
Definition: concepts.hh:247
Concept defining the requirements for types that support addition.
Definition: concepts.hh:259
Concept defining the requirements for types that support subtraction.
Definition: concepts.hh:271
Concept defining the requirements for types that support in-place multiplication.
Definition: concepts.hh:284
Concept defining the requirements for types that support in-place division.
Definition: concepts.hh:297
Concept defining the requirements for types that support in-place addition.
Definition: concepts.hh:310
Concept defining the requirements for types that support in-place subtraction.
Definition: concepts.hh:323
Concept defining the requirements for types that support division.
Definition: concepts.hh:335
Concept defining the requirements for types that support negation.
Definition: concepts.hh:346
Concept defining the requirements for types that support transposition.
Definition: concepts.hh:357
Concept defining the requirements for functors with arguments.
Definition: concepts.hh:369
Concept defining the requirements for Eigen vectors.
Definition: concepts.hh:381
Concept defining the requirements for a material type.
Definition: concepts.hh:473