55 real(kind=
rp),
allocatable :: w1(:)
56 real(kind=
rp),
allocatable :: w2(:)
57 real(kind=
rp),
allocatable :: w3(:)
58 real(kind=
rp),
allocatable :: r1(:)
59 real(kind=
rp),
allocatable :: r2(:)
60 real(kind=
rp),
allocatable :: r3(:)
61 real(kind=
rp),
allocatable :: p1(:)
62 real(kind=
rp),
allocatable :: p2(:)
63 real(kind=
rp),
allocatable :: p3(:)
64 real(kind=
rp),
allocatable :: z1(:)
65 real(kind=
rp),
allocatable :: z2(:)
66 real(kind=
rp),
allocatable :: z3(:)
67 real(kind=
rp),
allocatable :: tmp(:)
70 type(c_ptr) :: w1_d = c_null_ptr
71 type(c_ptr) :: w2_d = c_null_ptr
72 type(c_ptr) :: w3_d = c_null_ptr
74 type(c_ptr) :: r1_d = c_null_ptr
75 type(c_ptr) :: r2_d = c_null_ptr
76 type(c_ptr) :: r3_d = c_null_ptr
78 type(c_ptr) :: p1_d = c_null_ptr
79 type(c_ptr) :: p2_d = c_null_ptr
80 type(c_ptr) :: p3_d = c_null_ptr
82 type(c_ptr) :: z1_d = c_null_ptr
83 type(c_ptr) :: z2_d = c_null_ptr
84 type(c_ptr) :: z3_d = c_null_ptr
86 type(c_ptr) :: tmp_d = c_null_ptr
88 type(c_ptr) :: gs_event = c_null_ptr
101 class(
pc_t),
optional,
intent(in),
target :: M
102 integer,
intent(in) :: n
103 integer,
intent(in) :: max_iter
104 real(kind=
rp),
optional,
intent(in) :: rel_tol
105 real(kind=
rp),
optional,
intent(in) :: abs_tol
106 logical,
optional,
intent(in) :: monitor
122 allocate(this%tmp(n))
142 if (
present(rel_tol) .and.
present(abs_tol) .and.
present(monitor))
then
143 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
144 else if (
present(rel_tol) .and.
present(abs_tol))
then
145 call this%ksp_init(max_iter, rel_tol, abs_tol)
146 else if (
present(monitor) .and.
present(abs_tol))
then
147 call this%ksp_init(max_iter, abs_tol = abs_tol, monitor = monitor)
148 else if (
present(rel_tol) .and.
present(monitor))
then
149 call this%ksp_init(max_iter, rel_tol, monitor = monitor)
150 else if (
present(rel_tol))
then
151 call this%ksp_init(max_iter, rel_tol = rel_tol)
152 else if (
present(abs_tol))
then
153 call this%ksp_init(max_iter, abs_tol = abs_tol)
154 else if (
present(monitor))
then
155 call this%ksp_init(max_iter, monitor = monitor)
157 call this%ksp_init(max_iter)
169 if (
allocated(this%w1))
then
170 if (c_associated(this%w1_d))
then
176 if (
allocated(this%w2))
then
177 if (c_associated(this%w2_d))
then
183 if (
allocated(this%w3))
then
184 if (c_associated(this%w3_d))
then
190 if (
allocated(this%r1))
then
191 if (c_associated(this%r1_d))
then
197 if (
allocated(this%r2))
then
198 if (c_associated(this%r2_d))
then
204 if (
allocated(this%r3))
then
205 if (c_associated(this%r3_d))
then
211 if (
allocated(this%p1))
then
212 if (c_associated(this%p1_d))
then
218 if (
allocated(this%p2))
then
219 if (c_associated(this%p2_d))
then
225 if (
allocated(this%p3))
then
226 if (c_associated(this%p3_d))
then
232 if (
allocated(this%z1))
then
233 if (c_associated(this%z1_d))
then
239 if (
allocated(this%z2))
then
240 if (c_associated(this%z2_d))
then
246 if (
allocated(this%z3))
then
247 if (c_associated(this%z3_d))
then
253 if (
allocated(this%tmp))
then
254 if (c_associated(this%tmp_d))
then
262 if (c_associated(this%gs_event))
then
290 n, coef, blstx, blsty, blstz, gs_h, niter)
result(ksp_results)
292 class(
ax_t),
intent(in) :: ax
293 type(
field_t),
intent(inout) :: x
294 type(
field_t),
intent(inout) :: y
295 type(
field_t),
intent(inout) :: z
296 integer,
intent(in) :: n
297 real(kind=
rp),
dimension(n),
intent(in) :: fx
298 real(kind=
rp),
dimension(n),
intent(in) :: fy
299 real(kind=
rp),
dimension(n),
intent(in) :: fz
300 type(
coef_t),
intent(inout) :: coef
304 type(
gs_t),
intent(inout) :: gs_h
306 integer,
optional,
intent(in) :: niter
307 integer :: i, iter, max_iter
308 real(kind=
rp) :: rnorm, rtr, rtr0, rtz2, rtz1
309 real(kind=
rp) :: beta, pap, alpha, alphm, norm_fac
310 integer,
parameter :: gdim = 3
319 if (
present(niter))
then
322 max_iter = this%max_iter
324 norm_fac = 1.0_rp / sqrt(coef%volume)
326 associate(p1_d => this%p1_d, p2_d => this%p2_d, p3_d => this%p3_d, &
327 z1_d => this%z1_d, z2_d => this%z2_d, z3_d => this%z3_d, &
328 r1_d => this%r1_d, r2_d => this%r2_d, r3_d => this%r3_d, &
329 w1_d => this%w1_d, w2_d => this%w2_d, w3_d => this%w3_d, &
345 call device_vdot3(tmp_d, r1_d, r2_d, r3_d, r1_d, r2_d, r3_d, n)
349 rnorm = sqrt(rtr)*norm_fac
350 ksp_results%res_start = rnorm
351 ksp_results%res_final = rnorm
353 if(
abscmp(rnorm, 0.0_rp))
then
354 ksp_results%converged = .true.
358 call this%monitor_start(
'device_cpldCG')
359 do iter = 1, max_iter
360 call this%M%solve(this%z1, this%r1, n)
361 call this%M%solve(this%z2, this%r2, n)
362 call this%M%solve(this%z3, this%r3, n)
365 call device_vdot3(tmp_d, z1_d, z2_d, z3_d, r1_d, r2_d, r3_d, n)
370 if (iter .eq. 1) beta = 0.0_rp
375 call ax%compute_vector(this%w1, this%w2, this%w3, &
376 this%p1, this%p2, this%p3, coef, x%msh, x%Xh)
379 call gs_h%op(this%w1, n, gs_op_add, this%gs_event)
381 call gs_h%op(this%w2, n, gs_op_add, this%gs_event)
383 call gs_h%op(this%w3, n, gs_op_add, this%gs_event)
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.