numerics 0.1.0
Loading...
Searching...
No Matches
concepts.hpp
Go to the documentation of this file.
1/// @file core/concepts.hpp
2/// @brief Storage and operator concepts for numerical routines.
3#pragma once
4
5#include "core/types.hpp"
6#include "core/vector.hpp"
7#include <concepts>
8#include <type_traits>
9
10namespace num {
11
12/// @brief Indexed real-valued vector interface.
13template<class V>
14concept VectorLike = requires(V v, const V cv, idx i) {
15 { cv.size() } -> std::convertible_to<idx>;
16 { cv[i] } -> std::convertible_to<real>;
17 { v[i] } -> std::convertible_to<real>;
18};
19
20/// @brief Any object exposing its contiguous real storage as a Vector via
21/// .vec(). Satisfied by Vector itself, ScalarField2D, ScalarField3D, ... --
22/// lets time integrators and solvers operate on fields without depending on
23/// the fields/ module.
24template<class T>
25concept VecField = requires(T& f) {
26 { f.vec() } -> std::same_as<Vector&>;
27};
28
29/// @brief Mutable indexed real-valued vector interface.
30template<class V>
31concept MutableVectorLike = VectorLike<V> && requires(V v, idx i, real a) {
32 { v[i] = a } -> std::same_as<real&>;
33};
34
35/// @brief Contiguous real-valued vector storage.
36template<class V>
37concept ContiguousVectorLike = VectorLike<V> && requires(V v, const V cv) {
38 { cv.data() } -> std::convertible_to<const real*>;
39 { v.data() } -> std::convertible_to<real*>;
40};
41
42/// @brief Dense row-major real matrix interface.
43template<class A>
44concept DenseMatrixLike = requires(A a, const A ca, idx i, idx j) {
45 { ca.rows() } -> std::convertible_to<idx>;
46 { ca.cols() } -> std::convertible_to<idx>;
47 { ca(i, j) } -> std::convertible_to<real>;
48 { a(i, j) } -> std::convertible_to<real>;
49};
50
51/// @brief Mutable dense row-major real matrix interface.
52template<class A>
54 DenseMatrixLike<A> && requires(A a, idx i, idx j, real x) {
55 { a(i, j) = x } -> std::same_as<real&>;
56 };
57
58/// @brief Contiguous dense row-major real matrix storage.
59template<class A>
60concept ContiguousDenseMatrixLike = DenseMatrixLike<A> && requires(A a, const A ca) {
61 { ca.data() } -> std::convertible_to<const real*>;
62 { a.data() } -> std::convertible_to<real*>;
63};
64
65/// @brief Compile-time contract for the matrix-free product y = A*x.
66template<class Op, class X = Vector, class Y = Vector>
68 VectorLike<X> && MutableVectorLike<Y> && requires(const Op& A, const X& x, Y& y) {
69 { A.rows() } -> std::convertible_to<idx>;
70 { A.cols() } -> std::convertible_to<idx>;
71 { A.apply(x, y) };
72 };
73
74/// @brief Operator declared to satisfy \f$A=A^T\f$.
75template<class Op, class X = Vector, class Y = Vector>
77 typename std::remove_cvref_t<Op>::symmetric_operator_tag;
78};
79
80/// @brief Operator declared to satisfy \f$x^T A x > 0\f$ for all nonzero \f$x\f$.
81template<class Op, class X = Vector, class Y = Vector>
83 typename std::remove_cvref_t<Op>::spd_operator_tag;
84};
85
86} // namespace num
Contiguous dense row-major real matrix storage.
Definition concepts.hpp:60
Contiguous real-valued vector storage.
Definition concepts.hpp:37
Dense row-major real matrix interface.
Definition concepts.hpp:44
Compile-time contract for the matrix-free product y = A*x.
Definition concepts.hpp:67
Mutable dense row-major real matrix interface.
Definition concepts.hpp:53
Mutable indexed real-valued vector interface.
Definition concepts.hpp:31
Operator declared to satisfy for all nonzero .
Definition concepts.hpp:82
Operator declared to satisfy .
Definition concepts.hpp:76
Any object exposing its contiguous real storage as a Vector via .vec(). Satisfied by Vector itself,...
Definition concepts.hpp:25
Indexed real-valued vector interface.
Definition concepts.hpp:14
Core type definitions.
double real
Definition types.hpp:10
std::size_t idx
Definition types.hpp:11
Dense vector storage and operations.