Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_linear_solver_iter_abstract.F90
Go to the documentation of this file.
1 
10 
12 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13 #include "sll_working_precision.h"
14 
15  use sll_m_linear_solver_abstract, only: &
17 
20 
23 
24  implicit none
25 
26  public :: &
28 
29  private
30  ! ..................................................
34 
35  sll_int32 :: n_maxiter = 2000
36  logical :: null_space = .false.
37 
38  sll_real64 :: atol = 1.0d-9
39 
40  sll_real64,dimension(:), allocatable :: x_0
41 
42  class(sll_t_linear_operator_abstract), pointer :: ptr_linear_operator => null()
43  class(sll_t_linear_operator_abstract), allocatable :: p_linear_operator
44  class(sll_t_linear_solver_abstract), pointer :: ptr_pc_left => null()
45  contains
46 
47  procedure(sll_p_set_guess_linear_solver_iter_abstract) , deferred :: set_guess
48  procedure(sll_p_check_convergence_linear_solver_iter_abstract), deferred :: check_convergence
49 
50  procedure :: compute_residual_error => compute_residual_error_linear_solver_iter_abstract
51  procedure :: set_linear_operator => set_linop_linear_solver_iter_abstract
52  procedure :: set_tolerance => set_tolerance_linear_solver_iter_abstract
53  !procedure :: free_abstract => free_abstract_linear_solver_iter_abstract
55  ! ..................................................
56 
57 
58  ! ..................................................
59  abstract interface
63 
64  class(sll_t_linear_solver_iter_abstract), intent(inout) :: self
65  sll_real64, dimension(:), intent(in) :: x_0
67  end interface
68  ! ..................................................
69 
70  ! ..................................................
71  abstract interface
72  subroutine sll_p_check_convergence_linear_solver_iter_abstract(self, i_iteration, flag, r_err, arr_err)
75 
76  class(sll_t_linear_solver_iter_abstract), intent(in) :: self
77  sll_int32, intent(in) :: i_iteration
78  logical, intent(inout) :: flag
79  sll_real64, optional, intent(in) :: r_err
80  sll_real64, dimension(:), optional, intent(in) :: arr_err
82  end interface
83  ! ..................................................
84 contains
85  ! ..................................................
91  subroutine compute_residual_error_linear_solver_iter_abstract(self, unknown, rhs, r_err)
92  implicit none
93  class(sll_t_linear_solver_iter_abstract), intent(in) :: self
94  sll_real64, dimension(:), intent(in) :: unknown
95  sll_real64, dimension(:), intent(in) :: rhs
96  sll_real64, intent(inout) :: r_err
97  ! local
98  sll_int32 :: n
99  sll_real64, dimension(:), allocatable :: residu
100 
101  ! ...
102  n = size(unknown, 1)
103  allocate(residu(n))
104  residu = 0.0_f64
105  ! ...
106 
107  ! ...
108  call self % ptr_linear_operator % dot(unknown, residu)
109  residu = rhs - residu
110 
111  r_err = maxval(abs(residu))
112  ! ...
113 
115  ! ..................................................
116 
117  ! ..................................................
122  subroutine set_linop_linear_solver_iter_abstract(self, linear_operator)
123  implicit none
124  class(sll_t_linear_solver_iter_abstract), target, intent(inout) :: self
125  class(sll_t_linear_operator_abstract), target, intent(in) :: linear_operator
126  ! local
127 
128  ! ..............................................................
129  ! creation / allocation of the nullspace linear_operator if used
130  ! ..............................................................
131  ! ...
132  if (self % null_space) then
133  ! ... we need to distinguish between two cases
134  ! - first call => allocation + creation + set ptr_linear_operator
135  ! - other calls => set ptr_linear_operator
136  ! ...
137 
138  ! ...
139  if (.not. allocated(self % p_linear_operator)) then
140  ! ...
141  allocate(sll_t_linear_operator_penalized::self % p_linear_operator)
142  ! ...
143 
144  ! ...
145  select type (p_linear_operator => self % p_linear_operator)
148  call p_linear_operator % create(linear_operator=linear_operator)
149  end select
150  ! ...
151  end if
152  ! ...
153 
154  ! ...
155  self % ptr_linear_operator => self % p_linear_operator
156  ! ...
157  else
158  ! ...
159  self % ptr_linear_operator => linear_operator
160  ! ...
161  end if
162  ! ...
163 
165  ! ..................................................
166 
167  ! ..................................................
173  implicit none
174  class(sll_t_linear_solver_iter_abstract), intent(inout) :: self
175  sll_real64, intent(in) :: atol
176 
177  ! ...
178  self % atol = atol
179  ! ...
180 
182  ! ..................................................
183 
184  ! ..................................................
189  implicit none
190  class(sll_t_linear_solver_iter_abstract), intent(inout) :: self
191  ! local
192 
193  ! ............................................
194  ! desctruction of the linear operator
195  ! ............................................
196  select type (p_linear_operator => self % p_linear_operator)
198  call p_linear_operator % free()
199  end select
200  if (allocated(self % p_linear_operator)) then
201  deallocate(self % p_linear_operator)
202  end if
203  ! ............................................
204 
205  ! ...
206  self % ptr_linear_operator => null()
207  ! ...
208 
209  ! ...
210 ! self % is_allocated = .false.
211  ! ...
212 
214  ! ..................................................
215 
216 
module for abstract linear operator
module for a penalized linear operator
module for abstract linear solver
module for abstract iterative linear solvers
subroutine free_abstract_linear_solver_iter_abstract(self)
abstract free for an iterative solver
subroutine set_tolerance_linear_solver_iter_abstract(self, atol)
set absolute tolerance
subroutine compute_residual_error_linear_solver_iter_abstract(self, unknown, rhs, r_err)
computes the residual error for an iterative solver
subroutine set_linop_linear_solver_iter_abstract(self, linear_operator)
sets a linear operator for an iterative solver
Module to select the kind parameter.
    Report Typos and Errors