19 OperatorLike OperatorT,
20 OperatorLike ProlongationT,
21 OperatorLike RestrictionT,
23 SolverLike CoarseGridSolverT >
47 std::vector< ProlongationType > P_additive_;
48 std::vector< RestrictionType > R_;
49 std::vector< OperatorT > A_c_;
50 std::vector< SolutionVectorType > tmp_r_;
51 std::vector< SolutionVectorType > tmp_e_;
52 std::vector< SolutionVectorType > tmp_;
53 std::vector< SmootherType > smoothers_pre_;
54 std::vector< SmootherType > smoothers_post_;
60 std::shared_ptr< util::Table > statistics_;
61 std::string tag_ =
"multigrid";
82 const std::vector< ProlongationType >& P_additive,
83 const std::vector< RestrictionType >& R,
84 const std::vector< OperatorT >& A_c,
85 const std::vector< SolutionVectorType >& tmp_r,
86 const std::vector< SolutionVectorType >& tmp_e,
87 const std::vector< SolutionVectorType >& tmp,
88 const std::vector< SmootherType >& smoothers_pre,
89 const std::vector< SmootherType >& smoothers_post,
93 : P_additive_( P_additive )
99 , smoothers_pre_( smoothers_pre )
100 , smoothers_post_( smoothers_post )
101 , coarse_grid_solver_( coarse_grid_solver )
102 , num_cycles_( num_cycles )
103 , relative_residual_threshold_( relative_residual_threshold )
108 void set_tag(
const std::string& tag ) { tag_ = tag; }
112 void collect_statistics(
const std::shared_ptr< util::Table >& statistics ) { statistics_ = statistics; }
121 if ( P_additive_.size() != A_c_.size() || R_.size() != A_c_.size() || tmp_r_.size() != A_c_.size() ||
122 tmp_e_.size() != A_c_.size() || tmp_.size() != A_c_.size() + 1 )
124 throw std::runtime_error(
125 "Multigrid: P_additive, R, A_c, tmp_e, and tmp_r must be available for all coarse levels. tmp "
126 "requires the finest grid allocated, too." );
129 const int max_level = P_additive_.size();
135 apply( A, x, tmp_[max_level] );
136 lincomb( tmp_[max_level], { 1.0, -1.0 }, { b, tmp_[max_level] } );
137 initial_residual =
norm_2( tmp_[max_level] );
139 statistics_->add_row(
142 {
"relative_residual", 1.0 },
143 {
"absolute_residual", initial_residual },
144 {
"residual_convergence_rate", 1.0 } } );
147 ScalarType previous_absolut_residual = initial_residual;
149 for (
int cycle = 1; cycle <= num_cycles_; ++cycle )
151 solve_recursive( A, x, b, max_level );
155 apply( A, x, tmp_[max_level] );
156 lincomb( tmp_[max_level], { 1.0, -1.0 }, { b, tmp_[max_level] } );
157 const auto absolute_residual =
norm_2( tmp_[max_level] );
159 const auto relative_residual = absolute_residual / initial_residual;
161 statistics_->add_row(
164 {
"relative_residual", relative_residual },
165 {
"absolute_residual", absolute_residual },
166 {
"residual_convergence_rate", absolute_residual / previous_absolut_residual } } );
168 if ( relative_residual <= relative_residual_threshold_ )
173 previous_absolut_residual = absolute_residual;
188 solve( coarse_grid_solver_, A, tmp_e_[0], tmp_r_[0] );
193 solve( smoothers_pre_[level], A, x, b );
196 apply( A, x, tmp_[level] );
197 lincomb( tmp_[level], { 1.0, -1.0 }, { b, tmp_[level] } );
200 apply( R_[level - 1], tmp_[level], tmp_r_[level - 1] );
203 assign( tmp_e_[level - 1], 0.0 );
204 solve_recursive( A_c_[level - 1], tmp_e_[level - 1], tmp_r_[level - 1], level - 1 );
207 apply( P_additive_[level - 1], tmp_e_[level - 1], x );
210 solve( smoothers_post_[level], A, x, b );
Multigrid solver for linear systems.
Definition multigrid.hpp:25
SmootherT SmootherType
Smoother type.
Definition multigrid.hpp:34
void set_tag(const std::string &tag)
Set a tag string for statistics output.
Definition multigrid.hpp:108
ProlongationT ProlongationType
Prolongation operator type.
Definition multigrid.hpp:30
void collect_statistics(const std::shared_ptr< util::Table > &statistics)
Collect statistics in a shared table.
Definition multigrid.hpp:112
RestrictionT RestrictionType
Restriction operator type.
Definition multigrid.hpp:32
SrcOf< OperatorType > SolutionVectorType
Solution vector type.
Definition multigrid.hpp:39
OperatorT OperatorType
Operator type to be solved.
Definition multigrid.hpp:28
Multigrid(const std::vector< ProlongationType > &P_additive, const std::vector< RestrictionType > &R, const std::vector< OperatorT > &A_c, const std::vector< SolutionVectorType > &tmp_r, const std::vector< SolutionVectorType > &tmp_e, const std::vector< SolutionVectorType > &tmp, const std::vector< SmootherType > &smoothers_pre, const std::vector< SmootherType > &smoothers_post, const CoarseGridSolverType &coarse_grid_solver, int num_cycles, ScalarType relative_residual_threshold)
Construct a multigrid solver.
Definition multigrid.hpp:81
DstOf< OperatorType > RHSVectorType
Right-hand side vector type.
Definition multigrid.hpp:41
void solve_impl(OperatorType &A, SolutionVectorType &x, const RHSVectorType &b)
Solve the linear system using multigrid cycles. Calls the recursive V-cycle and updates statistics.
Definition multigrid.hpp:119
CoarseGridSolverT CoarseGridSolverType
Coarse grid solver type.
Definition multigrid.hpp:36
SolutionVectorType::ScalarType ScalarType
Scalar type for computations.
Definition multigrid.hpp:44
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
ScalarOf< Vector > norm_2(const Vector &y)
Compute the 2-norm (Euclidean norm) of a vector. Implements: .
Definition vector.hpp:166
Operator::SrcVectorType SrcOf
Alias for the source vector type of an operator.
Definition operator.hpp:145
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