9#include <kernel/solver/iterative.hpp> 
   31      switch(precon_variant)
 
   33        case BiCGStabPreconVariant::left:
 
   35        case BiCGStabPreconVariant::right:
 
   38          return os << 
"unknown";
 
   48      if(s.compare_no_case(
"left") == 0)
 
   49        precon_variant = BiCGStabPreconVariant::left;
 
   50      else if(s.compare_no_case(
"right") == 0)
 
   51        precon_variant = BiCGStabPreconVariant::right;
 
   53        is.setstate(std::ios_base::failbit);
 
  134    template<
typename Matrix_, 
typename Filter_>
 
  191          std::shared_ptr<PrecondType> precond = 
nullptr,
 
  199          XASSERT(precon_variant == BiCGStabPreconVariant::left || precon_variant == BiCGStabPreconVariant::right);
 
  229          std::shared_ptr<PrecondType> precond = 
nullptr)
 
  231          BaseClass(
"BiCGStab", section_name, section, precond),
 
  242          auto p_variant_p = section->
query(
"precon_variant");
 
  243          if(p_variant_p.second && !p_variant_p.first.parse(this->_precon_variant))
 
  244            throw ParseError(section_name + 
".precon_variant", p_variant_p.first, 
"one of: left, right");
 
  271          _vec_r = this->_system_matrix.create_vector_r();
 
  275          _vec_tmp = this->_system_matrix.create_vector_r();
 
  296          this->_system_matrix.apply(this->_vec_r, vec_sol, vec_rhs, -
DataType(1));
 
  297          this->_system_filter.filter_def(this->_vec_r);
 
  313          this->_vec_r.copy(vec_def);
 
  337          XASSERT(precon_variant == BiCGStabPreconVariant::left || precon_variant == BiCGStabPreconVariant::right);
 
  357          Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
 
  366          const MatrixType& mat_sys(this->_system_matrix);
 
  367          const FilterType& fil_sys(this->_system_filter);
 
  373            Statistics::add_solver_expression(
 
  379          _vec_r_hat_0.copy(vec_r);
 
  381          vec_r_tilde.copy(vec_p_tilde);
 
  390            rho = vec_r_hat_0.dot(vec_r_tilde);
 
  395            rho = vec_r_hat_0.dot(vec_r);
 
  408            mat_sys.apply(vec_q, vec_p_tilde);
 
  409            fil_sys.filter_def(vec_q);
 
  416              Statistics::add_solver_expression(
 
  425              alpha = rho / vec_r_hat_0.dot(vec_q_tilde);
 
  430              alpha = rho / vec_r_hat_0.dot(vec_q);
 
  435            vec_sol.axpy(vec_p_tilde, alpha);
 
  438            vec_r.axpy(vec_q, -alpha);
 
  445              DataType def_half(vec_r.norm2());
 
  459              else if(this->_num_iter < this->
_min_iter)
 
  481                Statistics::add_solver_expression(
 
  482                  std::make_shared<ExpressionEndSolve>(this->
name(), status_half, this->
get_num_iter()));
 
  489            vec_r_tilde.axpy(vec_q_tilde, -alpha);
 
  492            mat_sys.apply(vec_t, vec_r_tilde);
 
  493            fil_sys.filter_def(vec_t);
 
  500              Statistics::add_solver_expression(
 
  509              omega = vec_t_tilde.dot(vec_r_tilde) / vec_t_tilde.dot(vec_t_tilde);
 
  514              omega = vec_t.dot(vec_r) / vec_t.dot(vec_t);
 
  522              Statistics::add_solver_expression(
 
  523                std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
 
  529            vec_sol.axpy(vec_r_tilde, omega);
 
  533            vec_r.axpy(vec_t, -omega);
 
  541              Statistics::add_solver_expression(
 
  542                std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
 
  548            vec_r_tilde.axpy(vec_t_tilde, -omega);
 
  555              rho = vec_r_hat_0.dot(vec_r_tilde);
 
  560              rho = vec_r_hat_0.dot(vec_r);
 
  564            DataType beta((rho/rho2)*(alpha/omega));
 
  570              Statistics::add_solver_expression(
 
  571                std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
 
  576            vec_p_tilde.axpy(vec_q_tilde, -omega);
 
  577            vec_p_tilde.scale(vec_p_tilde, beta);
 
  578            vec_p_tilde.axpy(vec_r_tilde); 
 
  583          Statistics::add_solver_expression(
 
  607    template<
typename Matrix_, 
typename Filter_>
 
  609      const Matrix_& matrix, 
const Filter_& filter,
 
  613      return std::make_shared<BiCGStab<Matrix_, Filter_>>(matrix, filter, precond, precon_variant);
 
  637    template<
typename Matrix_, 
typename Filter_>
 
  640      const Matrix_& matrix, 
const Filter_& filter,
 
  643      return std::make_shared<BiCGStab<Matrix_, Filter_>>(section_name, section, matrix, filter, precond);
 
#define XASSERT(expr)
Assertion macro definition.
Class for parser related errors.
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
(Preconditioned) Bi-Conjugate Gradient Stabilized solver implementation
SolverBase< VectorType > PrecondType
The type of the preconditioner.
virtual void force_defect_norm_calc(bool force) override
Forces the calculation of defect norms in every iteration (overridden)
virtual void init_symbolic() override
Symbolic initialization method.
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override
Solver application method.
PreconditionedIterativeSolver< VectorType > BaseClass
Our base class.
VectorType _vec_r_hat_0
The arbitrary starting vector.
BiCGStab(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor using a PropertyMap.
virtual Status correct(VectorType &vec_sol, const VectorType &vec_rhs) override
Solver correction method.
VectorType _vec_tmp
Temporary vector.
virtual String name() const override
Returns a descriptive string.
BiCGStab(const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr, BiCGStabPreconVariant precon_variant=BiCGStabPreconVariant::left)
Constructor.
VectorType _vec_r_tilde
The preconditioned defect vector.
const MatrixType & _system_matrix
the matrix for the solver
BiCGStabPreconVariant _precon_variant
Precondition from left or right?
virtual void set_precon_variant(BiCGStabPreconVariant precon_variant)
Sets the preconditioning variant (left or right)
VectorType _vec_t_tilde
t~[k] = M^{-1} A r~[k+1/2]
virtual void done_symbolic() override
Symbolic finalization method.
MatrixType::VectorTypeR VectorType
The vector type this solver can be applied to.
const FilterType & _system_filter
the filter for the solver
VectorType _vec_p_tilde
The preconditioned primal search direction.
MatrixType::DataType DataType
The floating point precision.
Status _apply_intern(VectorType &vec_sol, const VectorType &vec_rhs)
Internal function, applies the solver.
Matrix_ MatrixType
The matrix type this solver can be applied to.
VectorType _vec_q_tilde
q~[k] = M^{-1} A q[k]
Filter_ FilterType
The filter to apply.
VectorType _vec_r
The defect vector.
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 _min_iter
minimum number of iterations
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 _set_new_defect(const VectorType &vec_def, const VectorType &vec_sol)
Internal function: sets the new (next) defect vector.
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.
Polymorphic solver interface.
String class implementation.
bool isfinite(T_ x)
Checks whether a value is finite.
std::istream & operator>>(std::istream &is, Pack::Type &t)
stream input operator for Pack::Type
BiCGStabPreconVariant
Enum for different preconditioning variants for BiCGStab.
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< BiCGStab< Matrix_, Filter_ > > new_bicgstab(const Matrix_ &matrix, const Filter_ &filter, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr, BiCGStabPreconVariant precon_variant=BiCGStabPreconVariant::left)
Creates a new BiCGStab solver object.