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
111 class(
ksp_t),
target,
intent(inout) :: this
112 integer,
intent(in) :: max_iter
113 class(
pc_t),
optional,
intent(in),
target :: M
114 integer,
intent(in) :: n
115 real(kind=
rp),
optional,
intent(in) :: rel_tol
116 real(kind=
rp),
optional,
intent(in) :: abs_tol
117 logical,
optional,
intent(in) :: monitor
131 function ksp_method(this, Ax, x, f, n, coef, blst, gs_h, niter) &
142 class(
ksp_t),
intent(inout) :: this
143 class(
ax_t),
intent(in) :: ax
144 type(
field_t),
intent(inout) :: x
145 integer,
intent(in) :: n
146 real(kind=
rp),
dimension(n),
intent(in) :: f
147 type(
coef_t),
intent(inout) :: coef
149 type(
gs_t),
intent(inout) :: gs_h
150 integer,
optional,
intent(in) :: niter
131 function ksp_method(this, Ax, x, f, n, coef, blst, gs_h, niter) &
…
170 n, coef, blstx, blsty, blstz, gs_h, niter)
result(ksp_results)
180 class(
ksp_t),
intent(inout) :: this
181 class(
ax_t),
intent(in) :: ax
182 type(
field_t),
intent(inout) :: x
183 type(
field_t),
intent(inout) :: y
184 type(
field_t),
intent(inout) :: z
185 integer,
intent(in) :: n
186 real(kind=
rp),
dimension(n),
intent(in) :: fx
187 real(kind=
rp),
dimension(n),
intent(in) :: fy
188 real(kind=
rp),
dimension(n),
intent(in) :: fz
189 type(
coef_t),
intent(inout) :: coef
193 type(
gs_t),
intent(inout) :: gs_h
194 integer,
optional,
intent(in) :: niter
203 class(
ksp_t),
intent(inout) :: this
216 module subroutine krylov_solver_factory(object, n, type_name, &
217 max_iter, abstol, m, monitor)
218 class(ksp_t),
allocatable,
intent(inout) :: object
219 integer,
intent(in),
value :: n
220 character(len=*),
intent(in) :: type_name
221 integer,
intent(in) :: max_iter
222 real(kind=
rp),
optional :: abstol
223 class(
pc_t),
optional,
intent(in),
target :: m
224 logical,
optional,
intent(in) :: monitor
225 end subroutine krylov_solver_factory
229 public :: krylov_solver_factory
237 subroutine krylov_init(this, max_iter, rel_tol, abs_tol, M, monitor)
238 class(ksp_t),
target,
intent(inout) :: this
239 integer,
intent(in) :: max_iter
240 real(kind=
rp),
optional,
intent(in) :: rel_tol
241 real(kind=
rp),
optional,
intent(in) :: abs_tol
242 class(
pc_t),
optional,
target,
intent(in) :: m
243 logical,
optional,
intent(in) :: monitor
245 call krylov_free(this)
247 if (
present(rel_tol))
then
248 this%rel_tol = rel_tol
250 this%rel_tol = ksp_rel_tol
253 if (
present(abs_tol))
then
254 this%abs_tol = abs_tol
256 this%abs_tol = ksp_abs_tol
259 this%max_iter = max_iter
264 if (.not.
associated(this%M))
then
268 allocate(
ident_t::this%M_ident)
270 this%M => this%M_ident
274 if (
present(monitor))
then
275 this%monitor = monitor
277 this%monitor = .false.
237 subroutine krylov_init(this, max_iter, rel_tol, abs_tol, M, monitor)
…
280 end subroutine krylov_init
283 subroutine krylov_free(this)
284 class(ksp_t),
intent(inout) :: this
283 subroutine krylov_free(this)
…
288 end subroutine krylov_free
292 subroutine krylov_set_pc(this, M)
293 class(ksp_t),
intent(inout) :: this
294 class(
pc_t),
target,
intent(in) :: M
296 if (
associated(this%M))
then
297 select type (pc => this%M)
301 call neko_error(
'Preconditioner already defined')
292 subroutine krylov_set_pc(this, M)
…
307 end subroutine krylov_set_pc
310 subroutine krylov_monitor_start(this, name)
311 class(ksp_t),
intent(in) :: this
312 character(len=*) :: name
313 character(len=LOG_SIZE) :: log_buf
315 if (this%monitor)
then
316 write(log_buf,
'(A)')
'Krylov monitor (' // trim(name) //
')'
317 call neko_log%section(trim(log_buf))
320 write(log_buf,
'(A)')
' Iter. Residual'
322 write(log_buf,
'(A)')
'---------------------'
310 subroutine krylov_monitor_start(this, name)
…
325 end subroutine krylov_monitor_start
328 subroutine krylov_monitor_stop(this)
329 class(ksp_t),
intent(in) :: this
331 if (this%monitor)
then
328 subroutine krylov_monitor_stop(this)
…
336 end subroutine krylov_monitor_stop
340 subroutine krylov_monitor_iter(this, iter, rnorm)
341 class(ksp_t),
intent(in) :: this
342 integer,
intent(in) :: iter
343 real(kind=
rp),
intent(in) :: rnorm
344 character(len=LOG_SIZE) :: log_buf
346 if (this%monitor)
then
347 write(log_buf,
'(I6,E15.7)') iter, rnorm
340 subroutine krylov_monitor_iter(this, iter, rnorm)
…
351 end subroutine krylov_monitor_iter
361 pure function krylov_is_converged(this, iter, residual)
result(converged)
362 class(ksp_t),
intent(in) :: this
363 integer,
intent(in) :: iter
364 real(kind=
rp),
intent(in) :: residual
368 if (iter .ge. this%max_iter) converged = .false.
369 if (residual .gt. this%abs_tol) converged = .false.
361 pure function krylov_is_converged(this, iter, residual)
result(converged)
…
371 end function krylov_is_converged
Abstract interface for a Krylov method's constructor.
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.