13 #include "sll_working_precision.h"
65 character(len=*),
optional,
intent(in) :: filename
68 if(
present(pc_left) )
then
69 self%ptr_pc_left => pc_left
74 call self%initialize(linear_operator)
78 allocate(self%x_0(self%n_total_rows))
83 if (
present(filename))
then
84 call self%read_from_file(filename)
101 sll_real64,
dimension(:),
optional,
intent(in) :: x_0
105 if (
present(x_0))
then
111 call self%initialize_abstract(linear_operator)
115 call self%set_linear_operator(linear_operator)
129 sll_real64,
dimension(:),
intent(in) :: x_0
149 sll_int32,
intent(in) :: i_iteration
150 logical,
intent(inout) :: flag
151 sll_real64,
optional,
intent(in) :: r_err
152 sll_real64,
dimension(:),
optional,
intent(in) :: arr_err
155 if (self%verbose)
then
156 if (
present(r_err))
then
157 if (i_iteration <= self%n_maxiter)
then
158 print*,
'* cg: convergence after', i_iteration,
'iterations. Error ', r_err
160 print *,
'* cg: Warning - max iterations', self%n_maxiter,
'achieved without convergence. Error', r_err
177 character(len=*) ,
intent(in) :: filename
179 sll_int32,
parameter :: input_file_id = 111
185 namelist /linear_solver/ int_null_space, &
192 open(unit=input_file_id, file=trim(filename))
193 read( input_file_id, linear_solver)
197 self%n_maxiter = int_maxiter
198 self%atol = real_atol
202 self%null_space = .false.
203 if (int_null_space == 1)
then
204 self%null_space = .true.
209 self%verbose = .false.
210 if (int_verbose == 1)
then
211 self%verbose = .true.
231 sll_real64,
dimension(:),
intent(in ) :: rhs
232 sll_real64,
dimension(:),
intent( out) :: unknown
234 sll_real64,
dimension(:),
allocatable :: l_rhs
235 sll_int32,
parameter :: current_dof = 1
236 sll_int32 :: itr_used
241 allocate(l_rhs(self%n_total_rows))
259 call self%check_convergence( i_iteration=itr_used, &
279 sll_real64,
dimension (:),
intent(inout) :: x
280 sll_real64,
dimension (:),
intent(in) :: b
281 sll_int32,
intent(out) :: niterx
282 sll_real64,
intent(out) :: res
284 sll_int32 :: niterxmax
291 sll_real64,
dimension (self%n_total_rows) :: p
292 sll_real64,
dimension (self%n_total_rows) :: r
293 sll_real64,
dimension (self%n_total_rows) :: v
294 sll_real64,
dimension (self%n_total_rows) :: z
297 niterxmax = self%n_maxiter
298 nb = self%n_total_rows
303 call self%ptr_linear_operator%dot (x, v)
307 if(
associated( self%ptr_pc_left) )
then
308 call self%ptr_pc_left%solve(r, p)
320 call self%ptr_linear_operator%dot (p, v)
323 lambda = alpha / (sum(p*v)+1.d-25)
329 x(l) = x(l) + lambda*p(l)
330 r(l) = r(l) - lambda*v(l)
331 w1 = w1 + r(l) * r(l)
334 res=sqrt(w1/real(nb,f64))
335 if (res <= epsx)
exit
336 if(
associated( self%ptr_pc_left) )
then
338 call self%ptr_pc_left%solve(r, z)
365 logical ,
intent(in) :: verbose
368 call self%set_verbose_abstract(verbose)
383 print *,
">>>> linear_solver_cg"
384 print *,
"* verbose : ", self%verbose
385 print *,
"* atol : ", self%atol
386 print *,
"* null_space : ", self%null_space
387 print *,
"* n_maxiter : ", self%n_maxiter
401 deallocate (self%x_0)
module for abstract linear operator
module for abstract linear solver
module for conjugate gradient method in pure form
subroutine print_info_linear_solver_cg(self)
destroys a finite element cell
subroutine free_linear_solver_cg(self)
destroys the current object
integer(kind=i32), parameter sll_solver_maxiter
default maximum number of iterations for
subroutine initialize_linear_solver_cg(self, linear_operator, x_0)
initializes the linear solver
subroutine cg_linear_solver(self, x, b, niterx, res)
cg interface
subroutine read_from_file_linear_solver_cg(self, filename)
read from file
subroutine create_linear_solver_cg(self, linear_operator, pc_left, filename)
creates a linear solver
subroutine check_convergence_linear_solver_cg(self, i_iteration, flag, r_err, arr_err)
check the convergence of the current linear solver
real(kind=f64), parameter sll_solver_tolerance
default tolerance for iterative solvers
subroutine solve_real_linear_solver_cg(self, rhs, unknown)
af solves the linear system with real vectors
subroutine set_verbose_linear_solver_cg(self, verbose)
sets the verbose for the linear solver object
subroutine set_guess_linear_solver_cg(self, x_0)
sets the initial guess
integer(kind=i32), parameter sll_solver_bool_false
code id for False
module for abstract iterative linear solvers
class for abstract linear operator
class for abstract linear solver
class for the cg linear solver
class for abstract iterative linear solver