55template<
class ContainerType>
70 r(
copyable), p(r), ap(r), max_iter(max_iterations){}
73 void set_max(
unsigned new_max) {max_iter = new_max;}
76 unsigned get_max()
const {
return max_iter;}
79 const ContainerType&
copyable()
const{
return r;}
88 m_throw_on_fail = throw_on_fail;
92 template<
class ...Params>
96 *
this =
PCG( std::forward<Params>( ps)...);
126 template<
class MatrixType0,
class ContainerType0,
class ContainerType1,
class MatrixType1,
class ContainerType2 >
127 unsigned solve( MatrixType0&& A, ContainerType0& x,
const ContainerType1& b, MatrixType1&& P,
const ContainerType2& W,
value_type eps = 1e-12,
value_type nrmb_correction = 1,
int test_frequency = 1);
129 ContainerType r, p, ap;
131 bool m_verbose =
false, m_throw_on_fail =
true;
135template<
class ContainerType>
136template<
class Matrix,
class ContainerType0,
class ContainerType1,
class Preconditioner,
class ContainerType2>
137unsigned PCG< ContainerType>::solve( Matrix&& A, ContainerType0& x,
const ContainerType1& b, Preconditioner&& P,
const ContainerType2& W, value_type eps, value_type nrmb_correction,
int save_on_dots )
142 value_type tol = eps*(nrmb + nrmb_correction);
145 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
149 DG_RANK0 std::cout <<
"# Norm of W b "<<nrmb <<
"\n";
150 DG_RANK0 std::cout <<
"# Residual errors: \n";
161 blas2::symv( std::forward<Preconditioner>(P), r, p );
163 value_type alpha, nrmzr_new;
164 for(
unsigned i=1; i<max_iter; i++)
170 if( 0 == i%save_on_dots )
175 DG_RANK0 std::cout <<
"# < Critical "<<tol <<
"\t ";
189 <<
"After "<<max_iter<<
" PCG iterations with rtol "<<eps<<
" and atol "<<eps*nrmb_correction );
Preconditioned conjugate gradient method to solve .
Definition: pcg.h:57
void set_throw_on_fail(bool throw_on_fail)
Set or unset a throw on failure-to-converge.
Definition: pcg.h:87
PCG()=default
Allocate nothing, Call construct method before usage.
PCG(const ContainerType ©able, unsigned max_iterations)
Allocate memory for the pcg method.
Definition: pcg.h:69
get_value_type< ContainerType > value_type
Definition: pcg.h:60
void set_verbose(bool verbose)
Set or unset debugging output during iterations.
Definition: pcg.h:83
const ContainerType & copyable() const
Return an object of same size as the object used for construction.
Definition: pcg.h:79
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition: pcg.h:93
void set_max(unsigned new_max)
Set the maximum number of iterations.
Definition: pcg.h:73
ContainerType container_type
Definition: pcg.h:59
unsigned get_max() const
Get the current maximum number of iterations.
Definition: pcg.h:76
unsigned solve(MatrixType0 &&A, ContainerType0 &x, const ContainerType1 &b, MatrixType1 &&P, const ContainerType2 &W, value_type eps=1e-12, value_type nrmb_correction=1, int test_frequency=1)
Solve using a preconditioned conjugate gradient 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