9#include <kernel/solver/iterative.hpp>
31 template<
typename Matrix_,
typename Filter_>
43 typedef typename MatrixType::DataType
DataType;
71 std::shared_ptr<PrecondType> precond =
nullptr) :
104 std::shared_ptr<PrecondType> precond =
nullptr) :
105 BaseClass(
"RBiCGStab", section_name, section, precond),
138 _vec_v = this->_system_matrix.create_vector_r();
139 _vec_vh = this->_system_matrix.create_vector_r();
140 _vec_z = this->_system_matrix.create_vector_r();
141 _vec_s = this->_system_matrix.create_vector_r();
142 _vec_t = this->_system_matrix.create_vector_r();
143 _vec_th = this->_system_matrix.create_vector_r();
144 _vec_r = this->_system_matrix.create_vector_r();
145 _vec_r0 = this->_system_matrix.create_vector_r();
152 this->_vec_v.clear();
153 this->_vec_vh.clear();
154 this->_vec_z.clear();
155 this->_vec_s.clear();
156 this->_vec_t.clear();
157 this->_vec_th.clear();
158 this->_vec_r.clear();
159 this->_vec_r0.clear();
167 this->_vec_r.copy(vec_def);
186 this->_system_matrix.apply(this->_vec_r, vec_sol, vec_rhs, -
DataType(1));
187 this->_system_filter.filter_def(this->_vec_r);
215 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
217 const MatrixType& matrix(this->_system_matrix);
218 const FilterType& filter(this->_system_filter);
246 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
250 auto dot_rho = vec_r.dot_async(vec_r);
262 rho = dot_rho.wait();
272 matrix.apply(vec_v, vec_vh);
273 filter.filter_def(vec_v);
275 auto dot_delta = vec_v.dot_async(vec_r0);
285 delta = dot_delta.wait();
289 vec_th.axpy(vec_s, -alpha);
291 matrix.apply(vec_t, vec_th);
292 filter.filter_def(vec_t);
294 vec_sol.axpy(vec_vh, alpha);
295 vec_r.axpy(vec_v, -alpha);
296 auto norm_def_half = vec_r.norm2_async();
298 auto dot_theta = vec_t.dot_async(vec_r);
299 auto dot_phi = vec_t.dot_async(vec_t);
300 auto dot_psi = vec_t.dot_async(vec_r0);
310 theta = dot_theta.wait();
311 phi = dot_phi.wait();
312 psi = dot_psi.wait();
319 DataType def_half(norm_def_half.wait());
349 Statistics::add_solver_expression(
350 std::make_shared<ExpressionEndSolve>(this->
name(), status_half, this->
get_num_iter()));
358 vec_sol.axpy(vec_th, omega);
359 vec_r.axpy(vec_t, -omega);
361 auto norm_def_cur = vec_r.norm2_async();
364 vec_z.scale(vec_z, -omega);
366 beta = (rho / rho_old) * (alpha / omega);
368 vec_vh.axpy(vec_s, -omega);
369 vec_vh.scale(vec_vh, beta);
376 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
402 template<
typename Matrix_,
typename Filter_>
404 const Matrix_& matrix,
const Filter_& filter,
407 return std::make_shared<RBiCGStab<Matrix_, Filter_>>(matrix, filter, precond);
431 template<
typename Matrix_,
typename Filter_>
434 const Matrix_& matrix,
const Filter_& filter,
437 return std::make_shared<RBiCGStab<Matrix_, Filter_>>(section_name, section, matrix, filter, precond);
A class organizing a tree of key-value pairs.
Helper class for iteration statistics collection.
void destroy()
destroy the objects contents (and generate Statistics::expression) before the actual destructor call
bool _force_def_norm_calc
whether skipping of defect computation is allowed or not
Index get_num_iter() const
Returns number of performed iterations.
Status _status
current status of the solver
void _set_comm_by_matrix(const Matrix_ &matrix)
Sets the communicator for the solver from a matrix.
bool is_diverged() const
checks for divergence
DataType _def_prev
previous iteration defect
virtual void _plot_iter_line(Index num_iter, DataType def_cur, DataType def_prev)
Plots an iteration line.
virtual Status _update_defect(const DataType def_cur_norm)
Internal function: sets the new (next) defect norm.
Index _num_iter
number of performed iterations
bool _plot_iter(Status st=Status::progress) const
Plot the current iteration?
DataType _def_cur
current defect
virtual void plot_summary() const
Plot a summary of the last solver run.
virtual Status _set_initial_defect(const VectorType &vec_def, const VectorType &vec_sol)
Internal function: sets the initial defect vector.
bool is_converged() const
checks for convergence
Abstract base-class for preconditioned iterative solvers.
virtual void init_symbolic() override
Symbolic initialization method.
bool _apply_precond(VectorType &vec_cor, const VectorType &vec_def, const Filter_ &filter)
Applies the preconditioner onto a defect vector.
virtual void done_symbolic() override
Symbolic finalization method.
(Preconditioned) reordered BiCGStab solver implementation
MatrixType::VectorTypeR VectorType
The vector type this solver can be applied to.
virtual String name() const override
Returns a descriptive string.
PreconditionedIterativeSolver< VectorType > BaseClass
Our base class.
SolverBase< VectorType > PrecondType
The type of the preconditioner that can be used.
const MatrixType & _system_matrix
the matrix for the solver
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override
Solver application method.
virtual Status correct(VectorType &vec_sol, const VectorType &vec_rhs) override
Solver correction method.
const FilterType & _system_filter
the filter for the solver
Filter_ FilterType
The filter for projecting solution, rhs, defect and correction vectors to subspaces.
RBiCGStab(const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor.
virtual void init_symbolic() override
Symbolic initialization method.
RBiCGStab(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor using a PropertyMap.
MatrixType::DataType DataType
The floating point precision.
VectorType _vec_v
temp vectors
Matrix_ MatrixType
The type of matrix this solver can be applied to.
virtual void force_defect_norm_calc(bool force) override
Forces the calculation of defect norms in every iteration (overridden)
virtual Status _apply_intern(VectorType &vec_sol)
Internal function, applies the solver.
virtual void done_symbolic() override
Symbolic finalization method.
Polymorphic solver interface.
String class implementation.
bool isfinite(T_ x)
Checks whether a value is finite.
Status
Solver status return codes enumeration.
@ success
solving successful (convergence criterion fulfilled)
@ progress
continue iteration (internal use only)
@ undefined
undefined status
@ diverged
solver diverged (divergence criterion fulfilled)
@ aborted
premature abort (solver aborted due to internal errors or preconditioner failure)
std::shared_ptr< RBiCGStab< Matrix_, Filter_ > > new_rbicgstab(const Matrix_ &matrix, const Filter_ &filter, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr)
Creates a new RBiCGStab solver object.