25template < OperatorLike OperatorT, SolverLike PreconditionerT = IdentitySolver< OperatorT > >
36 using ScalarType =
typename SolutionVectorType::ScalarType;
44 const std::shared_ptr< util::Table >& statistics,
45 const std::vector< SolutionVectorType >& tmp )
56 const std::shared_ptr< util::Table >& statistics,
57 const std::vector< SolutionVectorType >& tmp,
58 const PreconditionerT preconditioner )
59 : tag_(
"pminres_solver" )
61 , statistics_( statistics )
63 , preconditioner_( preconditioner )
68 void set_tag(
const std::string& tag ) { tag_ = tag; }
78 auto& v_j_minus_1_ = tmp_[1];
80 auto& w_j_minus_1_ = tmp_[3];
82 auto& z_j_plus_1_ = tmp_[5];
90 lincomb( v_j_, { 1.0, -1.0 }, { b, v_j_ } );
92 solve( preconditioner_, A, z_, v_j_ );
107 statistics_->add_row(
110 {
"relative_residual", 1.0 },
111 {
"absolute_residual", initial_residual } } );
119 for (
int iteration = 1; iteration <= params_.
max_iterations(); ++iteration )
121 lincomb( z_, { 1.0 / gamma_j }, { z_ } );
127 lincomb( v_j_minus_1_, { 1.0, -delta / gamma_j, -gamma_j / gamma_j_minus_1 }, { az_, v_j_, v_j_minus_1_ } );
128 swap( v_j_minus_1_, v_j_ );
130 assign( z_j_plus_1_, 0.0 );
131 solve( preconditioner_, A, z_j_plus_1_, v_j_ );
133 const ScalarType gamma_j_plus_1 = std::sqrt(
dot( z_j_plus_1_, v_j_ ) );
135 const ScalarType alpha_0 = c_j * delta - c_j_minus_1 * s_j * gamma_j;
136 const ScalarType alpha_1 = std::sqrt( alpha_0 * alpha_0 + gamma_j_plus_1 * gamma_j_plus_1 );
137 const ScalarType alpha_2 = s_j * delta + c_j_minus_1 * c_j * gamma_j;
138 const ScalarType alpha_3 = s_j_minus_1 * gamma_j;
140 const ScalarType c_j_plus_1 = alpha_0 / alpha_1;
141 const ScalarType s_j_plus_1 = gamma_j_plus_1 / alpha_1;
144 w_j_minus_1_, { 1.0 / alpha_1, -alpha_3 / alpha_1, -alpha_2 / alpha_1 }, { z_, w_j_minus_1_, w_j_ } );
145 swap( w_j_minus_1_, w_j_ );
147 lincomb( x, { 1.0, c_j_plus_1 * eta }, { x, w_j_ } );
149 eta = -s_j_plus_1 * eta;
151 const ScalarType absolute_residual = std::abs( eta );
152 const ScalarType relative_residual = absolute_residual / initial_residual;
156 statistics_->add_row(
158 {
"iteration", iteration },
159 {
"relative_residual", relative_residual },
160 {
"absolute_residual", absolute_residual } } );
173 swap( z_, z_j_plus_1_ );
175 gamma_j_minus_1 = gamma_j;
176 gamma_j = gamma_j_plus_1;
191 std::shared_ptr< util::Table > statistics_;
193 std::vector< SolutionVectorType > tmp_;
195 PreconditionerT preconditioner_;
Dummy operator for testing concepts. Implements apply_impl as a no-op.
Definition operator.hpp:167
Dummy vector class for concept checks and testing. Implements required vector operations as no-ops.
Definition vector.hpp:210
"Identity solver" for linear systems.
Definition identity_solver.hpp:21
Definition iterative_solver_info.hpp:7
double absolute_residual_tolerance() const
Definition iterative_solver_info.hpp:20
int max_iterations() const
Definition iterative_solver_info.hpp:18
double relative_residual_tolerance() const
Definition iterative_solver_info.hpp:19
Preconditioned MINRES (PMINRES) iterative solver for symmetric indefinite linear systems.
Definition pminres.hpp:27
PMINRES(const IterativeSolverParameters ¶ms, const std::shared_ptr< util::Table > &statistics, const std::vector< SolutionVectorType > &tmp, const PreconditionerT preconditioner)
Construct a PMINRES solver with a custom preconditioner.
Definition pminres.hpp:54
typename SolutionVectorType::ScalarType ScalarType
Scalar type for computations.
Definition pminres.hpp:36
OperatorT OperatorType
Operator type to be solved.
Definition pminres.hpp:30
SrcOf< OperatorType > SolutionVectorType
Solution vector type.
Definition pminres.hpp:32
PMINRES(const IterativeSolverParameters ¶ms, const std::shared_ptr< util::Table > &statistics, const std::vector< SolutionVectorType > &tmp)
Construct a PMINRES solver with default identity preconditioner.
Definition pminres.hpp:42
void solve_impl(OperatorType &A, SolutionVectorType &x, const RHSVectorType &b)
Solve the linear system using PMINRES. Calls the iterative solver and updates statistics.
Definition pminres.hpp:75
void set_tag(const std::string &tag)
Set a tag string for statistics output.
Definition pminres.hpp:68
DstOf< OperatorType > RHSVectorType
Right-hand side vector type.
Definition pminres.hpp:34
Definition block_preconditioner_2x2.hpp:7
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
void lincomb(Vector &y, const std::vector< ScalarOf< Vector > > &c, const std::vector< Vector > &x, const ScalarOf< Vector > &c0)
Compute a linear combination of vectors. Implements: .
Definition vector.hpp:72
Operator::SrcVectorType SrcOf
Alias for the source vector type of an operator.
Definition operator.hpp:145
ScalarOf< Vector > dot(const Vector &y, const Vector &x)
Compute the dot product of two vectors. Implements: .
Definition vector.hpp:118
void apply(LinearForm &L, typename LinearForm::DstVectorType &dst)
Apply a linear form and write to a destination vector.
Definition linear_form.hpp:37
Operator::DstVectorType DstOf
Alias for the destination vector type of an operator.
Definition operator.hpp:149
void assign(Vector &y, const ScalarOf< Vector > &c0)
Assign a scalar value to a vector. Implements: .
Definition vector.hpp:97
void swap(Vector &x, Vector &y)
Swap the contents of two vectors. Exchanges the entries of and .
Definition vector.hpp:199