Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
krylov_solver_template.f90
Go to the documentation of this file.
1
3 use ax_product, only : ax_t
4 use coefs, only : coef_t
5 use field, only : field_t
6 use gather_scatter, only : gs_t
7 use krylov, only : ksp_t, ksp_monitor_t, krylov_allocate, register_krylov
8 use num_types, only : rp
9 use precon, only : pc_t
11 use utils, only : neko_error
14 implicit none
15 private
16
18 contains
19 procedure :: init => krylov_solver_template_init
20 procedure :: free => krylov_solver_template_free
22 procedure :: solve_coupled => krylov_solver_template_solve_coupled
24
26
27contains
28
29 subroutine krylov_solver_template_init(this, n, max_iter, M, rel_tol, &
30 abs_tol, monitor)
31 class(krylov_solver_template_t), target, intent(inout) :: this
32 integer, intent(in) :: n, max_iter
33 class(pc_t), target, optional, intent(in) :: M
34 real(kind=rp), optional, intent(in) :: rel_tol, abs_tol
35 logical, optional, intent(in) :: monitor
36
37 call this%free()
38 if (present(m)) call this%set_pc(m)
39 if (present(rel_tol) .and. present(abs_tol) .and. present(monitor)) then
40 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
41 else if (present(rel_tol) .and. present(abs_tol)) then
42 call this%ksp_init(max_iter, rel_tol, abs_tol)
43 else if (present(rel_tol)) then
44 call this%ksp_init(max_iter, rel_tol = rel_tol)
45 else if (present(abs_tol)) then
46 call this%ksp_init(max_iter, abs_tol = abs_tol)
47 else if (present(monitor)) then
48 call this%ksp_init(max_iter, monitor = monitor)
49 else
50 call this%ksp_init(max_iter)
51 end if
52 ! TODO: Allocate work arrays of length n.
53 end subroutine krylov_solver_template_init
54
56 class(krylov_solver_template_t), intent(inout) :: this
57 ! TODO: Deallocate work arrays and other derived-type state.
58 call this%ksp_free()
59 end subroutine krylov_solver_template_free
60
61 function krylov_solver_template_solve(this, Ax, x, f, n, coef, bc_projector, &
62 gs_h, niter) result(ksp_results)
63 class(krylov_solver_template_t), intent(inout) :: this
64 class(ax_t), intent(in) :: ax
65 type(field_t), intent(inout) :: x
66 integer, intent(in) :: n
67 real(kind=rp), intent(in) :: f(n)
68 type(coef_t), intent(inout) :: coef
69 class(scalar_bc_projector_t), intent(inout) :: bc_projector
70 type(gs_t), intent(inout) :: gs_h
71 integer, optional, intent(in) :: niter
72 type(ksp_monitor_t) :: ksp_results
73
74 ! TODO: Implement the Krylov iteration and return its monitor data.
75 call neko_error('krylov_solver_template: solve is not implemented')
77
78 function krylov_solver_template_solve_coupled(this, Ax, x, y, z, fx, fy, fz, &
79 n, coef, bc_projector, gs_h, niter) result(ksp_results)
80 class(krylov_solver_template_t), intent(inout) :: this
81 class(ax_t), intent(in) :: ax
82 type(field_t), intent(inout) :: x, y, z
83 integer, intent(in) :: n
84 real(kind=rp), intent(in) :: fx(n), fy(n), fz(n)
85 type(coef_t), intent(inout) :: coef
86 class(vector_bc_projector_t), intent(inout) :: bc_projector
87 type(gs_t), intent(inout) :: gs_h
88 integer, optional, intent(in) :: niter
89 type(ksp_monitor_t) :: ksp_results(3)
90 type(scalar_bc_projector_t), pointer :: bc_x, bc_y, bc_z
91
92 ! A valid default when a solver applies independently to each component.
93 call vector_bc_projector_components(bc_projector, bc_x, bc_y, bc_z)
94 ksp_results(1) = this%solve(ax, x, fx, n, coef, bc_x, gs_h, niter)
95 ksp_results(2) = this%solve(ax, y, fy, n, coef, bc_y, gs_h, niter)
96 ksp_results(3) = this%solve(ax, z, fz, n, coef, bc_z, gs_h, niter)
98
100 procedure(krylov_allocate), pointer :: allocator
102 call register_krylov('krylov_solver_template', allocator)
104
106 class(ksp_t), allocatable, intent(inout) :: obj
107 allocate(krylov_solver_template_t :: obj)
109end module krylov_solver_template
__device__ T solve(const T u, const T y, const T guess, const T nu, const T kappa, const T B)
Factory for Krylov solvers. Both creates and initializes the object.
Definition krylov.f90:251
Defines a Matrix-vector product.
Definition ax.f90:34
Coefficients.
Definition coef.f90:34
Defines a field.
Definition field.f90:34
Gather-scatter.
Template for a user-defined Krylov solver.
subroutine krylov_solver_template_free(this)
subroutine, public krylov_solver_template_register_types()
subroutine krylov_solver_template_allocate(obj)
type(ksp_monitor_t) function krylov_solver_template_solve(this, ax, x, f, n, coef, bc_projector, gs_h, niter)
type(ksp_monitor_t) function, dimension(3) krylov_solver_template_solve_coupled(this, ax, x, y, z, fx, fy, fz, n, coef, bc_projector, gs_h, niter)
subroutine krylov_solver_template_init(this, n, max_iter, m, rel_tol, abs_tol, monitor)
Implements the base abstract type for Krylov solvers plus helper types.
Definition krylov.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Krylov preconditioner.
Definition precon.f90:34
Implements scalar_projector_t.
Utilities.
Definition utils.f90:35
Implements boundary condition projectors for vector fields. Two types concrete types are provided: se...
subroutine, public vector_bc_projector_components(this, x, y, z)
Access the component scalar projectors from a segregated vector projector.
Base type for a matrix-vector product providing .
Definition ax.f90:43
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:93
Gather-scatter kernel.
Type for storing initial and final residuals in a Krylov solver.
Definition krylov.f90:57
Base abstract type for a canonical Krylov method, solving .
Definition krylov.f90:74
Defines a canonical Krylov preconditioner.
Definition precon.f90:40
Projector for scalar boundary conditions.
Abstract type for resolving vector boundary conditions.