60 real(kind=
rp) :: res_start
62 real(kind=
rp) :: res_final
64 logical :: converged = .false.
69 class(
pc_t),
pointer :: m => null()
70 real(kind=
rp) :: rel_tol
71 real(kind=
rp) :: abs_tol
73 class(
pc_t),
allocatable :: m_ident
109 function ksp_method(this, Ax, x, f, n, coef, blst, gs_h, niter) &
120 class(
ksp_t),
intent(inout) :: this
121 class(
ax_t),
intent(in) :: ax
122 type(
field_t),
intent(inout) :: x
123 integer,
intent(in) :: n
124 real(kind=
rp),
dimension(n),
intent(in) :: f
125 type(
coef_t),
intent(inout) :: coef
127 type(
gs_t),
intent(inout) :: gs_h
128 integer,
optional,
intent(in) :: niter
148 n, coef, blstx, blsty, blstz, gs_h, niter)
result(ksp_results)
158 class(
ksp_t),
intent(inout) :: this
159 class(
ax_t),
intent(in) :: ax
160 type(
field_t),
intent(inout) :: x
161 type(
field_t),
intent(inout) :: y
162 type(
field_t),
intent(inout) :: z
163 integer,
intent(in) :: n
164 real(kind=
rp),
dimension(n),
intent(in) :: fx
165 real(kind=
rp),
dimension(n),
intent(in) :: fy
166 real(kind=
rp),
dimension(n),
intent(in) :: fz
167 type(
coef_t),
intent(inout) :: coef
171 type(
gs_t),
intent(inout) :: gs_h
172 integer,
optional,
intent(in) :: niter
181 class(
ksp_t),
intent(inout) :: this
194 module subroutine krylov_solver_factory(object, n, type_name, &
195 max_iter, abstol, m, monitor)
196 class(ksp_t),
allocatable,
intent(inout) :: object
197 integer,
intent(in),
value :: n
198 character(len=*),
intent(in) :: type_name
199 integer,
intent(in) :: max_iter
200 real(kind=
rp),
optional :: abstol
201 class(
pc_t),
optional,
intent(in),
target :: m
202 logical,
optional,
intent(in) :: monitor
203 end subroutine krylov_solver_factory
206 module subroutine krylov_solver_destroy(object)
207 class(ksp_t),
allocatable,
intent(inout) :: object
208 end subroutine krylov_solver_destroy
211 public :: krylov_solver_factory, krylov_solver_destroy
219 subroutine krylov_init(this, max_iter, rel_tol, abs_tol, M, monitor)
220 class(ksp_t),
target,
intent(inout) :: this
221 integer,
intent(in) :: max_iter
222 real(kind=
rp),
optional,
intent(in) :: rel_tol
223 real(kind=
rp),
optional,
intent(in) :: abs_tol
224 class(
pc_t),
optional,
target,
intent(in) :: m
225 logical,
optional,
intent(in) :: monitor
227 call krylov_free(this)
229 if (
present(rel_tol))
then
230 this%rel_tol = rel_tol
232 this%rel_tol = ksp_rel_tol
235 if (
present(abs_tol))
then
236 this%abs_tol = abs_tol
238 this%abs_tol = ksp_abs_tol
241 this%max_iter = max_iter
246 if (.not.
associated(this%M))
then
250 allocate(
ident_t::this%M_ident)
252 this%M => this%M_ident
256 if (
present(monitor))
then
257 this%monitor = monitor
259 this%monitor = .false.
262 end subroutine krylov_init
265 subroutine krylov_free(this)
266 class(ksp_t),
intent(inout) :: this
270 end subroutine krylov_free
274 subroutine krylov_set_pc(this, M)
275 class(ksp_t),
intent(inout) :: this
276 class(
pc_t),
target,
intent(in) :: M
278 if (
associated(this%M))
then
279 select type (pc => this%M)
283 call neko_error(
'Preconditioner already defined')
289 end subroutine krylov_set_pc
292 subroutine krylov_monitor_start(this, name)
293 class(ksp_t),
intent(in) :: this
294 character(len=*) :: name
295 character(len=LOG_SIZE) :: log_buf
297 if (this%monitor)
then
298 write(log_buf,
'(A)')
'Krylov monitor (' // trim(name) //
')'
299 call neko_log%section(trim(log_buf))
302 write(log_buf,
'(A)')
' Iter. Residual'
304 write(log_buf,
'(A)')
'---------------------'
307 end subroutine krylov_monitor_start
310 subroutine krylov_monitor_stop(this)
311 class(ksp_t),
intent(in) :: this
313 if (this%monitor)
then
318 end subroutine krylov_monitor_stop
322 subroutine krylov_monitor_iter(this, iter, rnorm)
323 class(ksp_t),
intent(in) :: this
324 integer,
intent(in) :: iter
325 real(kind=
rp),
intent(in) :: rnorm
326 character(len=LOG_SIZE) :: log_buf
328 if (this%monitor)
then
329 write(log_buf,
'(I6,E15.7)') iter, rnorm
333 end subroutine krylov_monitor_iter
343 pure function krylov_is_converged(this, iter, residual)
result(converged)
344 class(ksp_t),
intent(in) :: this
345 integer,
intent(in) :: iter
346 real(kind=
rp),
intent(in) :: residual
350 if (iter .ge. this%max_iter) converged = .false.
351 if (residual .gt. this%abs_tol) converged = .false.
353 end function krylov_is_converged
Abstract interface for a Krylov method's coupled solve routine.
Abstract interface for a Krylov method's solve routine.
Abstract interface for deallocating a Krylov method.
Defines a Matrix-vector product.
Identity Krylov preconditioner for accelerators.
Krylov preconditioner (identity)
Implements the base abstract type for Krylov solvers plus helper types.
real(kind=rp), parameter, public ksp_rel_tol
Relative tolerance.
real(kind=rp), parameter, public ksp_abs_tol
Absolut tolerance.
subroutine krylov_free(this)
Deallocate a Krylov solver.
integer, parameter, public ksp_max_iter
Maximum number of iters.
subroutine krylov_monitor_iter(this, iter, rnorm)
Monitor iteration.
subroutine krylov_init(this, max_iter, rel_tol, abs_tol, m, monitor)
Factory for Krylov solvers. Both creates and initializes the object.
subroutine krylov_monitor_start(this, name)
Monitor start.
pure logical function krylov_is_converged(this, iter, residual)
Check for convergence.
subroutine krylov_set_pc(this, m)
Setup a Krylov solver's preconditioner.
subroutine krylov_monitor_stop(this)
Monitor stop.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
integer, parameter neko_bcknd_device
integer, parameter, public c_rp
integer, parameter, public rp
Global precision used in computations.
subroutine, public neko_warning(warning_msg)
Reports a warning to standard output.
Base type for a matrix-vector product providing .
A list of allocatable `bc_t`. Follows the standard interface of lists.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Defines a canonical Krylov preconditioner for accelerators.
Defines a canonical Krylov preconditioner.
Type for storing initial and final residuals in a Krylov solver.
Base abstract type for a canonical Krylov method, solving .
Defines a canonical Krylov preconditioner.