3#include "dg/algorithm.h" 
   64template< 
class ContainerType >
 
   79        m_v = m_vp = m_vm = copyable;
 
   80        m_max_iter = max_iterations;
 
   81        m_iter = max_iterations;
 
   83        set_iter( max_iterations);
 
 
   86    template<
class ...Params>
 
  144    template < 
class MatrixType, 
class ContainerType0, 
class ContainerType1,
 
  145             class ContainerType2, 
class FuncTe1>
 
  146    unsigned solve(ContainerType0& x, FuncTe1 f,
 
  147            MatrixType&& A, 
const ContainerType1& b,
 
  148            const ContainerType2& weights, 
value_type eps,
 
  150            std::string error_norm = 
"universal",
 
  154        tridiag( f, std::forward<MatrixType>(A), b, weights, eps,
 
  155                nrmb_correction, error_norm, res_fac, q);
 
  156        if( 
"residual" == error_norm)
 
  159        normMbVy(std::forward<MatrixType>(A), m_TH, m_yH, 
x, b,
 
 
  174    template< 
class MatrixType, 
class ContainerType0, 
class ContainerType1>
 
  176            const ContainerType1& weights, 
value_type eps = 1e-12,
 
  178            std::string error_norm = 
"universal",
 
  183        tridiag( op, std::forward<MatrixType>(A), b, weights, eps,
 
  184                nrmb_correction, error_norm, res_fac, q);
 
 
  200    template< 
class MatrixType, 
class ContainerType0,
 
  201        class ContainerType1,
class ContainerType2>
 
  204            const ContainerType0& 
y,
 
  216        unsigned less_iter = 0;
 
  217        for( 
unsigned i=0; i<
y.size(); i++)
 
  222        for ( 
unsigned i=0; i<less_iter-1; i++)
 
  226                    -T.M[i]/T.P[i], m_vm,
 
 
  256    template < 
class UnaryOp, 
class MatrixType,
 
  257             class ContainerType1, 
class ContainerType2>
 
  259            MatrixType&& A, 
const ContainerType1& b,
 
  260            const ContainerType2& weights, 
value_type eps,
 
  262            std::string error_norm = 
"residual",
 
  268        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
  273            DG_RANK0 std::cout << 
"# Norm of b  "<<m_bnorm <<
"\n";
 
  274            DG_RANK0 std::cout << 
"# Res factor "<<res_fac <<
"\n";
 
  275            DG_RANK0 std::cout << 
"# Residual errors: \n";
 
  286        for( 
unsigned i=0; i<m_max_iter; i++)
 
  298                    DG_RANK0 std::cout << 
"beta["<<i+1 <<
"]=0 encountered\n";
 
  305            if( 
"residual" == error_norm)
 
  307                residual = compute_residual_error( m_TH, i)*m_bnorm;
 
  312                if( i>=q &&(  (i<=10) || (i>10 && i%10 == 0) ))
 
  314                    residual = compute_universal_error( m_TH, i, q, f,
 
  325                DG_RANK0 std::cout << 
"# ||r||_W = " << residual << 
"\tat i = " << i << 
"\n";
 
  326            if (res_fac*residual< eps*(xnorm + nrmb_correction) )
 
  334            set_iter( m_max_iter);
 
 
  342        return TH.P[iter]*fabs(T1); 
 
  344    template<
class UnaryOp>
 
  346            unsigned q, UnaryOp f, 
HVec& yH)
 
  348        unsigned new_iter = iter + 1 + q;
 
  351        for( 
unsigned u=0; u<iter+1; u++)
 
  353            THtilde.M[u] = TH.M[u];
 
  354            THtilde.O[u] = TH.O[u];
 
  355            THtilde.P[u] = TH.P[u];
 
  357        for( 
unsigned u=1; u<=q; u++)
 
  359            THtilde.M[ iter+u] = u==1 ? TH.P[iter] :
 
  361            THtilde.O[ iter+u] = TH.O[ iter-u];
 
  362            THtilde.P[ iter+u] = TH.M[ iter-u];
 
  365        HVec yHtilde = f( THtilde);
 
  366        for( 
unsigned u=0; u<yH.size(); u++)
 
  374    void set_iter( 
unsigned new_iter) {
 
  378    ContainerType  m_v, m_vp, m_vm;
 
  381    unsigned m_iter, m_max_iter;
 
  382    bool m_verbose = 
false;
 
 
Tridiagonalize  and approximate  via Lanczos algorithm. A is self-adjoint in the weights .
Definition lanczos.h:66
value_type get_bnorm() const
Norm of b from last call to operator()
Definition lanczos.h:110
const dg::TriDiagonal< thrust::host_vector< value_type > > & tridiag(UnaryOp f, MatrixType &&A, const ContainerType1 &b, const ContainerType2 &weights, value_type eps, value_type nrmb_correction, std::string error_norm="residual", value_type res_fac=1., unsigned q=1)
Tridiagonalization of A using Lanczos method.
Definition lanczos.h:258
get_value_type< ContainerType > value_type
Definition lanczos.h:68
const dg::TriDiagonal< thrust::host_vector< value_type > > & tridiag(MatrixType &&A, const ContainerType0 &b, const ContainerType1 &weights, value_type eps=1e-12, value_type nrmb_correction=1., std::string error_norm="universal", value_type res_fac=1., unsigned q=1)
Definition lanczos.h:175
void normMbVy(MatrixType &&A, const dg::TriDiagonal< thrust::host_vector< value_type > > &T, const ContainerType0 &y, ContainerType1 &x, const ContainerType2 &b, value_type bnorm)
compute  from a given tridiagonal matrix T and in-place re-computation of V
Definition lanczos.h:202
UniversalLanczos(const ContainerType ©able, unsigned max_iterations)
Allocate memory for the method.
Definition lanczos.h:77
void set_verbose(bool verbose)
Set or unset debugging output during iterations.
Definition lanczos.h:106
unsigned get_max() const
Get the current maximum number of iterations.
Definition lanczos.h:102
unsigned get_iter() const
Get the number of iterations in the last call to tridiag or solve (same as T.num_rows)
Definition lanczos.h:115
UniversalLanczos()
Allocate nothing, Call construct method before usage.
Definition lanczos.h:70
unsigned solve(ContainerType0 &x, FuncTe1 f, MatrixType &&A, const ContainerType1 &b, const ContainerType2 &weights, value_type eps, value_type nrmb_correction=1., std::string error_norm="universal", value_type res_fac=1., unsigned q=1)
via Lanczos and matrix function computation. A is self-adjoint in the weights .
Definition lanczos.h:146
void set_max(unsigned new_max)
Set the maximum number of iterations.
Definition lanczos.h:95
void construct(Params &&...ps)
Perfect forward parameters to one of the constructors.
Definition lanczos.h:87
void copy(const ContainerTypeIn &source, ContainerTypeOut &target)
void axpbypgz(value_type alpha, const ContainerType1 &x, value_type1 beta, const ContainerType2 &y, value_type2 gamma, ContainerType &z)
void axpby(value_type alpha, const ContainerType1 &x, value_type1 beta, ContainerType &y)
void scal(ContainerType &x, value_type alpha)
auto dot(const ContainerType1 &x, const MatrixType &m, const ContainerType2 &y)
void symv(MatrixType &&M, const ContainerType1 &x, ContainerType2 &y)
typename TensorTraits< std::decay_t< Vector > >::value_type get_value_type
value_type compute_Tinv_m1(const dg::TriDiagonal< thrust::host_vector< value_type > > &T, unsigned size)
Computes the value of  via a Thomas algorithm.
Definition tridiaginv.h:105
auto make_Linear_Te1(int exp)
Create a functor that computes  directly.
Definition matrixfunction.h:180
thrust::host_vector< double > HVec
Classes for Krylov space approximations of a Matrix-Vector product.
void resize(unsigned size)
double value_type
Definition tridiaginv_b.cpp:6