Loading...
Searching...
No Matches
solver.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
8
9namespace terra::util {
10class Table;
11}
12
13namespace terra::linalg::solvers {
14
15/// @brief Concept for types that behave like linear solvers.
16/// Requires exposing OperatorType and a solve_impl method.
17/// See OperatorLike in operator.hpp for operator requirements.
18template < typename T >
19concept SolverLike = requires(
20 // TODO: Cannot make solver const since we may have temporaries as members.
21 T& self,
22 // TODO: See OperatorLike for why A is not const.
23 typename T::OperatorType& A,
24 typename T::OperatorType::SrcVectorType& x,
25 const typename T::OperatorType::DstVectorType& b ) {
26 /// @brief Operator type to be solved.
27 typename T::OperatorType;
28
29 /// @brief Operator type must satisfy OperatorLike concept.
31
32 /// @brief Required solve implementation.
33 { self.solve_impl( A, x, b ) } -> std::same_as< void >;
34};
35
36/// @brief Alias for the solution vector type of a solver.
37template < SolverLike Solver >
39
40/// @brief Alias for the right-hand side vector type of a solver.
41template < SolverLike Solver >
43
44/// @brief Solve a linear system using the given solver and operator.
45/// Calls the solver's solve_impl method.
46/// @param solver The solver instance.
47/// @param A The operator (matrix).
48/// @param x Solution vector (output).
49/// @param b Right-hand side vector (input).
50template < SolverLike Solver, OperatorLike Operator, VectorLike SolutionVector, VectorLike RHSVector >
51void solve( Solver& solver, Operator& A, SolutionVector& x, const RHSVector& b )
52{
53 solver.solve_impl( A, x, b );
54}
55
56namespace detail {
57
58/// @brief Dummy solver for concept checks and testing.
59/// Implements solve_impl as a no-op.
60template < OperatorLike OperatorT >
62{
63 public:
64 /// @brief Operator type to be solved.
65 using OperatorType = OperatorT;
66
67 /// @brief Solution vector type.
69 /// @brief Right-hand side vector type.
71
72 /// @brief Dummy solve_impl, does nothing.
73 /// @param A Operator.
74 /// @param x Solution vector.
75 /// @param b Right-hand side vector.
76 void solve_impl( const OperatorType& A, SolutionVectorType& x, const RHSVectorType& b ) const
77 {
78 (void) A;
79 (void) x;
80 (void) b;
81 }
82};
83
84/// @brief Static assertion to check SolverLike concept for DummySolver.
86
87} // namespace detail
88
89} // namespace terra::linalg::solvers
Dummy solver for concept checks and testing. Implements solve_impl as a no-op.
Definition solver.hpp:62
SrcOf< OperatorType > SolutionVectorType
Solution vector type.
Definition solver.hpp:68
DstOf< OperatorType > RHSVectorType
Right-hand side vector type.
Definition solver.hpp:70
OperatorT OperatorType
Operator type to be solved.
Definition solver.hpp:65
void solve_impl(const OperatorType &A, SolutionVectorType &x, const RHSVectorType &b) const
Dummy solve_impl, does nothing.
Definition solver.hpp:76
Table class for storing and manipulating tabular data.
Definition table.hpp:84
Concept for types that behave like linear operators.
Definition operator.hpp:57
Concept for types that behave like linear solvers. Requires exposing OperatorType and a solve_impl me...
Definition solver.hpp:19
Definition block_preconditioner_2x2.hpp:7
DstOf< typename Solver::OperatorType > RHSOf
Alias for the right-hand side vector type of a solver.
Definition solver.hpp:42
void solve(Solver &solver, Operator &A, SolutionVector &x, const RHSVector &b)
Solve a linear system using the given solver and operator. Calls the solver's solve_impl method.
Definition solver.hpp:51
SrcOf< typename Solver::OperatorType > SolutionOf
Alias for the solution vector type of a solver.
Definition solver.hpp:38
Operator::SrcVectorType SrcOf
Alias for the source vector type of an operator.
Definition operator.hpp:145
Operator::DstVectorType DstOf
Alias for the destination vector type of an operator.
Definition operator.hpp:149
Definition solver.hpp:9