9#include <kernel/solver/iterative.hpp>
32 switch(precon_variant)
34 case BiCGStabLPreconVariant::left:
36 case BiCGStabLPreconVariant::right:
39 return os <<
"-unknown-";
49 if(s.compare_no_case(
"left") == 0)
50 precon_variant = BiCGStabLPreconVariant::left;
51 else if(s.compare_no_case(
"right") == 0)
52 precon_variant = BiCGStabLPreconVariant::right;
54 is.setstate(std::ios_base::failbit);
92 template<
typename Matrix_,
typename Filter_>
156 std::shared_ptr<PrecondType> precond =
nullptr,
170 XASSERT(precon_variant == BiCGStabLPreconVariant::left || precon_variant == BiCGStabLPreconVariant::right);
171 XASSERTM(
_l > 0,
"bicgstabl polynomial degree must be greater than zero!");
197 std::shared_ptr<PrecondType> precond =
nullptr)
199 BaseClass(
"BiCGStabL", section_name, section, precond),
210 auto p_variant_p = section->
query(
"precon_variant");
211 if(p_variant_p.second && !p_variant_p.first.parse(this->_precon_variant))
212 throw ParseError(section_name +
".precon_variant", p_variant_p.first,
"one of: left, right");
215 std::pair<String , bool> l_pair = section->
query(
"polynomial_degree");
218 if (l_pair.second && (!l_pair.first.parse(l_pm) || (l_pm <= 0)))
219 throw ParseError(section_name +
".polynomial_degree", l_pair.first,
"a positive integer");
249 _vec_u0 = this->_system_matrix.create_vector_r();
250 _vec_pc = this->_system_matrix.create_vector_r();
254 for (
int i=0; i <=
_l; i++)
267 for (
int i=0; i <=
_l; i++)
279 this->_system_matrix.apply(this->_vec_rj_hat.at(0), vec_sol, vec_rhs, -
DataType(1));
280 this->_system_filter.filter_def(this->_vec_rj_hat.at(0));
296 this->_vec_rj_hat.at(0).copy(vec_def);
320 XASSERT(precon_variant == BiCGStabLPreconVariant::left || precon_variant == BiCGStabLPreconVariant::right);
339 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
353 std::vector<DataType> gamma_prime (
Index(l) ,
DataType(0) );
354 std::vector<DataType> gamma_prime_prime (
Index(l) ,
DataType(0) );
356 DataType rho_0(1), alpha(0), omega(1), rho_1(0), beta(0), gamma(0);
359 const MatrixType& mat_sys(this->_system_matrix);
360 const FilterType& fil_sys(this->_system_filter);
371 Statistics::add_solver_expression(
385 for(
int j(0); j < l ; j++)
388 beta = alpha * rho_1 / rho_0;
390 for (
int i(0) ; i <= j ; i++)
404 Statistics::add_solver_expression(
413 Statistics::add_solver_expression(
422 alpha = rho_0 / gamma;
424 for (
int i(0) ; i <= j ; i++)
436 Statistics::add_solver_expression(
445 Statistics::add_solver_expression(
455 for (
int j(0) ; j < l ; j++)
458 for (
int i(0); i<j ; i++)
466 gamma_j.at(
Index(l-1)) = gamma_prime.at(
Index(l-1));
467 omega = gamma_j.at(
Index(l-1));
469 for (
int j(l-2) ; j >= 0 ; j--)
471 gamma_j.at(
Index(j)) = gamma_prime.at(
Index(j));
472 for (
int i(j+1) ; i < l ; i++)
474 gamma_j.at(
Index(j)) -= tau.at(
Index(i*(l-1) + j) ) * gamma_j.at(
Index(i));
478 for (
int j(0); j < l-1 ; j++)
480 gamma_prime_prime.at(
Index(j) ) = gamma_j.at(
Index(j+1) );
481 for (
int i(j+1) ; i < l-1 ; i++)
483 gamma_prime_prime.at(
Index(j)) += tau.at(
Index(i*(l-1) + j)) * gamma_j.at(
Index(i+1));
490 for (
int j(1) ; j<l; j++)
499 mat_sys.apply(
_vec_pc, vec_sol);
513 Statistics::add_solver_expression(
514 std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
515 if (_precon_variant == BiCGStabLPreconVariant::right)
519 Statistics::add_solver_expression(
530 Statistics::add_solver_expression(
557 template<
typename Matrix_,
typename Filter_>
559 const Matrix_& matrix,
const Filter_& filter,
int l = 2,
563 return std::make_shared<BiCGStabL<Matrix_, Filter_>>(matrix, filter, l, precond, precon_variant);
587 template<
typename Matrix_,
typename Filter_>
590 const Matrix_& matrix,
const Filter_& filter,
593 return std::make_shared<BiCGStabL<Matrix_, Filter_>>(section_name, section, matrix, filter, precond);
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
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) BiCGStab(l) solver implementation
virtual Status correct(VectorType &vec_sol, const VectorType &vec_rhs) override
Solver correction method.
Filter_ FilterType
The filter to apply.
virtual void done_symbolic() override
Symbolic finalization method.
BiCGStabL(const MatrixType &matrix, const FilterType &filter, int l=2, std::shared_ptr< PrecondType > precond=nullptr, BiCGStabLPreconVariant precon_variant=BiCGStabLPreconVariant::left)
Constructor.
VectorType _vec_r0_tilde
arbitrary vector for the algorithm
std::vector< VectorType > _vec_uj_hat
vector 'list' for the algorithm (size = l+1);
VectorType _vec_pc
auxiliary vector for preconditioning
virtual void init_symbolic() override
Symbolic initialization method.
virtual String name() const override
Returns a descriptive string.
virtual void force_defect_norm_calc(bool force) override
Forces the calculation of defect norms in every iteration (overridden)
int _l
Parameter l configuring the solver.
MatrixType::VectorTypeR VectorType
The vector type this solver can be applied to.
Matrix_ MatrixType
The matrix type this solver can be applied to.
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override
Solver application method.
VectorType _vec_u0
vector for the algorithm
BiCGStabL(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor using a PropertyMap.
const MatrixType & _system_matrix
the matrix for the solver
BiCGStabLPreconVariant _precon_variant
Precondition from left or right?
Status _apply_intern(VectorType &vec_sol, const VectorType &vec_rhs)
Internal function, applies the solver.
virtual void set_precon_variant(BiCGStabLPreconVariant precon_variant)
Sets the preconditioning variant (left or right)
MatrixType::DataType DataType
The floating point precision.
SolverBase< VectorType > PrecondType
The type of the preconditioner.
std::vector< VectorType > _vec_rj_hat
vector 'list' for the algorithm (size = l+1); r[0] is the residual vector of the preconditioned syste...
const FilterType & _system_filter
the filter for the solver
PreconditionedIterativeSolver< VectorType > BaseClass
Our base class.
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
void set_plot_name(const String &plot_name)
Sets the plot name of the solver.
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.
virtual Status _set_new_defect(const VectorType &vec_def, const VectorType &vec_sol)
Internal function: sets the new (next) defect vector.
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.
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.
std::istream & operator>>(std::istream &is, Pack::Type &t)
stream input operator for Pack::Type
std::shared_ptr< BiCGStabL< Matrix_, Filter_ > > new_bicgstabl(const Matrix_ &matrix, const Filter_ &filter, int l=2, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr, BiCGStabLPreconVariant precon_variant=BiCGStabLPreconVariant::left)
Creates a new BiCGStabL solver object.
Status
Solver status return codes enumeration.
@ progress
continue iteration (internal use only)
@ undefined
undefined status
@ aborted
premature abort (solver aborted due to internal errors or preconditioner failure)
BiCGStabLPreconVariant
Enum for diffent preconditioning variants for BiCGStabL.
String stringify(const T_ &item)
Converts an item into a String.
std::uint64_t Index
Index data type.