57 real(kind=
rp),
allocatable :: w1(:)
58 real(kind=
rp),
allocatable :: w2(:)
59 real(kind=
rp),
allocatable :: w3(:)
60 real(kind=
rp),
allocatable :: r1(:)
61 real(kind=
rp),
allocatable :: r2(:)
62 real(kind=
rp),
allocatable :: r3(:)
63 real(kind=
rp),
allocatable :: p1(:)
64 real(kind=
rp),
allocatable :: p2(:)
65 real(kind=
rp),
allocatable :: p3(:)
66 real(kind=
rp),
allocatable :: z1(:)
67 real(kind=
rp),
allocatable :: z2(:)
68 real(kind=
rp),
allocatable :: z3(:)
69 real(kind=
rp),
allocatable :: tmp(:)
72 type(c_ptr) :: w1_d = c_null_ptr
73 type(c_ptr) :: w2_d = c_null_ptr
74 type(c_ptr) :: w3_d = c_null_ptr
76 type(c_ptr) :: r1_d = c_null_ptr
77 type(c_ptr) :: r2_d = c_null_ptr
78 type(c_ptr) :: r3_d = c_null_ptr
80 type(c_ptr) :: p1_d = c_null_ptr
81 type(c_ptr) :: p2_d = c_null_ptr
82 type(c_ptr) :: p3_d = c_null_ptr
84 type(c_ptr) :: z1_d = c_null_ptr
85 type(c_ptr) :: z2_d = c_null_ptr
86 type(c_ptr) :: z3_d = c_null_ptr
88 type(c_ptr) :: tmp_d = c_null_ptr
90 type(c_ptr) :: gs_event = c_null_ptr
104 class(
pc_t),
optional,
intent(in),
target :: M
105 integer,
intent(in) :: n
106 integer,
intent(in) :: max_iter
107 real(kind=
rp),
optional,
intent(in) :: rel_tol
108 real(kind=
rp),
optional,
intent(in) :: abs_tol
109 logical,
optional,
intent(in) :: monitor
125 allocate(this%tmp(n))
145 if (
present(rel_tol) .and.
present(abs_tol) .and.
present(monitor))
then
146 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
147 else if (
present(rel_tol) .and.
present(abs_tol))
then
148 call this%ksp_init(max_iter, rel_tol, abs_tol)
149 else if (
present(monitor) .and.
present(abs_tol))
then
150 call this%ksp_init(max_iter, abs_tol = abs_tol, monitor = monitor)
151 else if (
present(rel_tol) .and.
present(monitor))
then
152 call this%ksp_init(max_iter, rel_tol, monitor = monitor)
153 else if (
present(rel_tol))
then
154 call this%ksp_init(max_iter, rel_tol = rel_tol)
155 else if (
present(abs_tol))
then
156 call this%ksp_init(max_iter, abs_tol = abs_tol)
157 else if (
present(monitor))
then
158 call this%ksp_init(max_iter, monitor = monitor)
160 call this%ksp_init(max_iter)
172 if (
allocated(this%w1))
then
173 if (c_associated(this%w1_d))
then
179 if (
allocated(this%w2))
then
180 if (c_associated(this%w2_d))
then
186 if (
allocated(this%w3))
then
187 if (c_associated(this%w3_d))
then
193 if (
allocated(this%r1))
then
194 if (c_associated(this%r1_d))
then
200 if (
allocated(this%r2))
then
201 if (c_associated(this%r2_d))
then
207 if (
allocated(this%r3))
then
208 if (c_associated(this%r3_d))
then
214 if (
allocated(this%p1))
then
215 if (c_associated(this%p1_d))
then
221 if (
allocated(this%p2))
then
222 if (c_associated(this%p2_d))
then
228 if (
allocated(this%p3))
then
229 if (c_associated(this%p3_d))
then
235 if (
allocated(this%z1))
then
236 if (c_associated(this%z1_d))
then
242 if (
allocated(this%z2))
then
243 if (c_associated(this%z2_d))
then
249 if (
allocated(this%z3))
then
250 if (c_associated(this%z3_d))
then
256 if (
allocated(this%tmp))
then
257 if (c_associated(this%tmp_d))
then
265 if (c_associated(this%gs_event))
then
293 n, coef, blstx, blsty, blstz, gs_h, niter)
result(ksp_results)
295 class(
ax_t),
intent(in) :: ax
296 type(
field_t),
intent(inout) :: x
297 type(
field_t),
intent(inout) :: y
298 type(
field_t),
intent(inout) :: z
299 integer,
intent(in) :: n
300 real(kind=
rp),
dimension(n),
intent(in) :: fx
301 real(kind=
rp),
dimension(n),
intent(in) :: fy
302 real(kind=
rp),
dimension(n),
intent(in) :: fz
303 type(
coef_t),
intent(inout) :: coef
307 type(
gs_t),
intent(inout) :: gs_h
309 integer,
optional,
intent(in) :: niter
310 integer :: i, iter, max_iter
311 real(kind=
rp) :: rnorm, rtr, rtr0, rtz2, rtz1
312 real(kind=
rp) :: beta, pap, alpha, alphm, norm_fac
313 integer,
parameter :: gdim = 3
322 if (
present(niter))
then
325 max_iter = this%max_iter
327 norm_fac = 1.0_rp / sqrt(coef%volume)
329 associate(p1_d => this%p1_d, p2_d => this%p2_d, p3_d => this%p3_d, &
330 z1_d => this%z1_d, z2_d => this%z2_d, z3_d => this%z3_d, &
331 r1_d => this%r1_d, r2_d => this%r2_d, r3_d => this%r3_d, &
332 w1_d => this%w1_d, w2_d => this%w2_d, w3_d => this%w3_d, &
348 call device_vdot3(tmp_d, r1_d, r2_d, r3_d, r1_d, r2_d, r3_d, n)
352 rnorm = sqrt(rtr)*norm_fac
353 ksp_results%res_start = rnorm
354 ksp_results%res_final = rnorm
356 if (
abscmp(rnorm, 0.0_rp))
then
357 ksp_results%converged = .true.
361 call this%monitor_start(
'device_cpldCG')
362 do iter = 1, max_iter
363 call this%M%solve(this%z1, this%r1, n)
364 call this%M%solve(this%z2, this%r2, n)
365 call this%M%solve(this%z3, this%r3, n)
368 call device_vdot3(tmp_d, z1_d, z2_d, z3_d, r1_d, r2_d, r3_d, n)
373 if (iter .eq. 1) beta = 0.0_rp
378 call ax%compute_vector(this%w1, this%w2, this%w3, &
379 this%p1, this%p2, this%p3, coef, x%msh, x%Xh)
382 call gs_h%op(this%w1, this%w2, this%w3, n, gs_op_add, &
387 call blstx%apply(this%w1, n)
388 call blsty%apply(this%w2, n)
389 call blstz%apply(this%w3, n)
391 call device_vdot3(tmp_d, w1_d, w2_d, w3_d, p1_d, p2_d, p3_d, n)
398 p1_d, p2_d, p3_d, alpha, n, gdim)
400 w1_d, w2_d, w3_d, alphm, n, gdim)
401 call device_vdot3(tmp_d, r1_d, r2_d, r3_d, r1_d, r2_d, r3_d, n)
404 if (iter .eq. 1) rtr0 = rtr
405 rnorm = sqrt(rtr) * norm_fac
406 call this%monitor_iter(iter, rnorm)
407 if (rnorm .lt. this%abs_tol)
then
412 call this%monitor_stop()
413 ksp_results%res_final = rnorm
414 ksp_results%iter = iter
415 ksp_results%converged = this%is_converged(iter, rnorm)
type(ksp_monitor_t) function, dimension(3) cg_cpld_device_solve(this, ax, x, y, z, fx, fy, fz, n, coef, blstx, blsty, blstz, gs_h, niter)
Standard PCG solve.