33template<
class ContainerType>
52 max_iter(max_iterations),
58 sigma.assign(m_l+1,0);
59 gamma.assign(m_l+1,0);
60 gammap.assign(m_l+1,0);
61 gammapp.assign(m_l+1,0);
62 tau.assign( m_l+1, std::vector<value_type>( m_l+1, 0));
70 template<
class ...Params>
74 *
this =
BICGSTABl( std::forward<Params>( ps)...);
78 void set_max(
unsigned new_max) {max_iter = new_max;}
81 unsigned get_max()
const {
return max_iter;}
84 const ContainerType&
copyable()
const{
return m_tmp;}
92 m_throw_on_fail = throw_on_fail;
115 template<
class MatrixType0,
class ContainerType0,
class ContainerType1,
class MatrixType1,
class ContainerType2 >
116 unsigned solve( MatrixType0&& A, ContainerType0& x,
const ContainerType1& b, MatrixType1&& P,
const ContainerType2& W,
value_type eps = 1e-12,
value_type nrmb_correction = 1);
119 unsigned max_iter, m_l;
121 std::vector<ContainerType> rhat;
122 std::vector<ContainerType> uhat;
123 std::vector<value_type> sigma, gamma, gammap, gammapp;
124 std::vector<std::vector<value_type>> tau;
125 bool m_verbose =
false, m_throw_on_fail =
true;
130template<
class ContainerType>
131template<
class Matrix,
class ContainerType0,
class ContainerType1,
class Preconditioner,
class ContainerType2>
132unsigned BICGSTABl< ContainerType>::solve( Matrix&& A, ContainerType0& x,
const ContainerType1& b, Preconditioner&& P,
const ContainerType2& W, value_type eps, value_type nrmb_correction)
136 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
140 value_type tol = eps*(nrmb + nrmb_correction);
154 value_type rho_0 = 1;
155 value_type alpha = 0;
156 value_type omega = 1;
157 ContainerType0& xhat=x;
159 for (
unsigned k = 0; k < max_iter; k+= m_l){
161 rho_0 = -omega*rho_0;
164 for(
unsigned j = 0; j<m_l;j++)
167 value_type beta = alpha*rho_1/rho_0;
169 for(
unsigned i = 0; i<=j;i++)
179 for(
unsigned i = 0; i<=j; i++)
189 for(
unsigned j = 1; j<=m_l; j++){
190 for(
unsigned i = 1; i<j;i++){
198 gamma[m_l] = gammap[m_l];
201 for(
unsigned j=m_l-1;j>=1;j--){
203 for(
unsigned i=j+1;i<=m_l;i++){
204 tmp += tau[j][i]*gamma[i];
206 gamma[j] = gammap[j]-tmp;
208 for(
unsigned j=1;j<=m_l-1;j++){
210 for(
unsigned i=j+1;i<=m_l-1;i++){
211 tmp += tau[j][i]*gamma[i+1];
213 gammapp[j] = gamma[j+1]+tmp;
218 for(
unsigned j = 1; j<=m_l-1; j++){
227 DG_RANK0 std::cout <<
"# Error is now : " << err <<
" Against " << tol << std::endl;
230 DG_RANK0 std::cout <<
"# Exited with error : " << err <<
" After " << k+m_l <<
" Iterations." << std::endl;
235 DG_RANK0 std::cout <<
"# Failed to converge within max_iter" << std::endl;
239 <<
"After "<<max_iter<<
" BICGSTABL iterations with rtol "<<eps<<
" and atol "<<eps*nrmb_correction );
Preconditioned BICGSTAB(l) method to solve .
Definition: bicgstabl.h:35
void set_max(unsigned new_max)
Set the maximum number of iterations.
Definition: bicgstabl.h:78
void set_throw_on_fail(bool throw_on_fail)
Set or unset a throw on failure-to-converge.
Definition: bicgstabl.h:91
void set_verbose(bool verbose)
Set or unset debugging output during iterations.
Definition: bicgstabl.h:88
BICGSTABl()=default
Allocate nothing, Call construct method before usage.
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition: bicgstabl.h:71
unsigned get_max() const
Get the current maximum number of iterations.
Definition: bicgstabl.h:81
dg::get_value_type< ContainerType > value_type
Definition: bicgstabl.h:38
const ContainerType & copyable() const
Return an object of same size as the object used for construction.
Definition: bicgstabl.h:84
ContainerType container_type
Definition: bicgstabl.h:37
BICGSTABl(const ContainerType ©able, unsigned max_iterations, unsigned l_input)
Allocate memory for the preconditioned BICGSTABl method.
Definition: bicgstabl.h:50
unsigned solve(MatrixType0 &&A, ContainerType0 &x, const ContainerType1 &b, MatrixType1 &&P, const ContainerType2 &W, value_type eps=1e-12, value_type nrmb_correction=1)
Solve using a preconditioned BICGSTABl method.
#define _ping_
Definition: exceptions.h:12
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
Definition: blas1.h:164
void axpby(get_value_type< ContainerType > alpha, const ContainerType1 &x, get_value_type< ContainerType > beta, ContainerType &y)
Definition: blas1.h:231
void symv(MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
Definition: blas2.h:287
get_value_type< MatrixType > dot(const ContainerType1 &x, const MatrixType &m, const ContainerType2 &y)
; Binary reproducible general dot product
Definition: blas2.h:85
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
Definition: tensor_traits.h:38
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
Indicate failure to converge.
Definition: exceptions.h:126
Useful typedefs of commonly used types.
#define DG_RANK0
Definition: typedefs.h:147