58 real(kind=
rp),
allocatable :: w1(:)
59 real(kind=
rp),
allocatable :: w2(:)
60 real(kind=
rp),
allocatable :: w3(:)
61 real(kind=
rp),
allocatable :: r1(:)
62 real(kind=
rp),
allocatable :: r2(:)
63 real(kind=
rp),
allocatable :: r3(:)
64 real(kind=
rp),
allocatable :: p1(:)
65 real(kind=
rp),
allocatable :: p2(:)
66 real(kind=
rp),
allocatable :: p3(:)
67 real(kind=
rp),
allocatable :: z1(:)
68 real(kind=
rp),
allocatable :: z2(:)
69 real(kind=
rp),
allocatable :: z3(:)
70 real(kind=
rp),
allocatable :: tmp(:)
73 type(c_ptr) :: w1_d = c_null_ptr
74 type(c_ptr) :: w2_d = c_null_ptr
75 type(c_ptr) :: w3_d = c_null_ptr
77 type(c_ptr) :: r1_d = c_null_ptr
78 type(c_ptr) :: r2_d = c_null_ptr
79 type(c_ptr) :: r3_d = c_null_ptr
81 type(c_ptr) :: p1_d = c_null_ptr
82 type(c_ptr) :: p2_d = c_null_ptr
83 type(c_ptr) :: p3_d = c_null_ptr
85 type(c_ptr) :: z1_d = c_null_ptr
86 type(c_ptr) :: z2_d = c_null_ptr
87 type(c_ptr) :: z3_d = c_null_ptr
89 type(c_ptr) :: tmp_d = c_null_ptr
91 type(c_ptr) :: gs_event = c_null_ptr
105 class(
pc_t),
optional,
intent(in),
target :: M
106 integer,
intent(in) :: n
107 integer,
intent(in) :: max_iter
108 real(kind=
rp),
optional,
intent(in) :: rel_tol
109 real(kind=
rp),
optional,
intent(in) :: abs_tol
110 logical,
optional,
intent(in) :: monitor
126 allocate(this%tmp(n))
146 if (
present(rel_tol) .and.
present(abs_tol) .and.
present(monitor))
then
147 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
148 else if (
present(rel_tol) .and.
present(abs_tol))
then
149 call this%ksp_init(max_iter, rel_tol, abs_tol)
150 else if (
present(monitor) .and.
present(abs_tol))
then
151 call this%ksp_init(max_iter, abs_tol = abs_tol, monitor = monitor)
152 else if (
present(rel_tol) .and.
present(monitor))
then
153 call this%ksp_init(max_iter, rel_tol, monitor = monitor)
154 else if (
present(rel_tol))
then
155 call this%ksp_init(max_iter, rel_tol = rel_tol)
156 else if (
present(abs_tol))
then
157 call this%ksp_init(max_iter, abs_tol = abs_tol)
158 else if (
present(monitor))
then
159 call this%ksp_init(max_iter, monitor = monitor)
161 call this%ksp_init(max_iter)
173 if (
allocated(this%w1))
then
174 if (c_associated(this%w1_d))
then
180 if (
allocated(this%w2))
then
181 if (c_associated(this%w2_d))
then
187 if (
allocated(this%w3))
then
188 if (c_associated(this%w3_d))
then
194 if (
allocated(this%r1))
then
195 if (c_associated(this%r1_d))
then
201 if (
allocated(this%r2))
then
202 if (c_associated(this%r2_d))
then
208 if (
allocated(this%r3))
then
209 if (c_associated(this%r3_d))
then
215 if (
allocated(this%p1))
then
216 if (c_associated(this%p1_d))
then
222 if (
allocated(this%p2))
then
223 if (c_associated(this%p2_d))
then
229 if (
allocated(this%p3))
then
230 if (c_associated(this%p3_d))
then
236 if (
allocated(this%z1))
then
237 if (c_associated(this%z1_d))
then
243 if (
allocated(this%z2))
then
244 if (c_associated(this%z2_d))
then
250 if (
allocated(this%z3))
then
251 if (c_associated(this%z3_d))
then
257 if (
allocated(this%tmp))
then
258 if (c_associated(this%tmp_d))
then
266 if (c_associated(this%gs_event))
then
294 n, coef, bc_projector, gs_h, niter)
result(ksp_results)
296 class(
ax_t),
intent(in) :: ax
297 type(
field_t),
intent(inout) :: x
298 type(
field_t),
intent(inout) :: y
299 type(
field_t),
intent(inout) :: z
300 integer,
intent(in) :: n
301 real(kind=
rp),
dimension(n),
intent(in) :: fx
302 real(kind=
rp),
dimension(n),
intent(in) :: fy
303 real(kind=
rp),
dimension(n),
intent(in) :: fz
304 type(
coef_t),
intent(inout) :: coef
306 type(
gs_t),
intent(inout) :: gs_h
308 integer,
optional,
intent(in) :: niter
309 integer :: i, iter, max_iter
310 real(kind=
rp) :: rnorm, rtr, rtr0, rtz2, rtz1
311 real(kind=
rp) :: beta, pap, alpha, alphm, norm_fac
312 integer,
parameter :: gdim = 3
321 if (
present(niter))
then
324 max_iter = this%max_iter
326 norm_fac = 1.0_rp / sqrt(coef%volume)
328 associate(p1_d => this%p1_d, p2_d => this%p2_d, p3_d => this%p3_d, &
329 z1_d => this%z1_d, z2_d => this%z2_d, z3_d => this%z3_d, &
330 r1_d => this%r1_d, r2_d => this%r2_d, r3_d => this%r3_d, &
331 w1_d => this%w1_d, w2_d => this%w2_d, w3_d => this%w3_d, &
347 call device_vdot3(tmp_d, r1_d, r2_d, r3_d, r1_d, r2_d, r3_d, n)
351 rnorm = sqrt(rtr)*norm_fac
352 ksp_results%res_start = rnorm
353 ksp_results%res_final = rnorm
355 if (
abscmp(rnorm, 0.0_rp))
then
356 ksp_results%converged = .true.
360 call this%monitor_start(
'device_cpldCG')
361 do iter = 1, max_iter
362 call this%M%solve(this%z1, this%r1, n)
363 call this%M%solve(this%z2, this%r2, n)
364 call this%M%solve(this%z3, this%r3, n)
367 call device_vdot3(tmp_d, z1_d, z2_d, z3_d, r1_d, r2_d, r3_d, n)
372 if (iter .eq. 1) beta = 0.0_rp
377 call ax%compute_vector(this%w1, this%w2, this%w3, &
378 this%p1, this%p2, this%p3, coef, x%msh, x%Xh)
381 call gs_h%op(this%w1, this%w2, this%w3, n, gs_op_add, &
386 call bc_projector%apply(this%w1, this%w2, this%w3, n)
388 call device_vdot3(tmp_d, w1_d, w2_d, w3_d, p1_d, p2_d, p3_d, n)
395 p1_d, p2_d, p3_d, alpha, n, gdim)
397 w1_d, w2_d, w3_d, alphm, n, gdim)
398 call device_vdot3(tmp_d, r1_d, r2_d, r3_d, r1_d, r2_d, r3_d, n)
401 if (iter .eq. 1) rtr0 = rtr
402 rnorm = sqrt(rtr) * norm_fac
403 call this%monitor_iter(iter, rnorm)
404 if (rnorm .lt. this%abs_tol)
then
409 call this%monitor_stop()
410 ksp_results%res_final = rnorm
411 ksp_results%iter = iter
412 ksp_results%converged = this%is_converged(iter, rnorm)