73 subroutine cg_cpld_init(this, n, max_iter, M, rel_tol, abs_tol, monitor)
74 class(
cg_cpld_t),
target,
intent(inout) :: this
75 integer,
intent(in) :: max_iter
76 class(
pc_t),
optional,
intent(in),
target :: M
77 integer,
intent(in) :: n
78 real(kind=
rp),
optional,
intent(in) :: rel_tol
79 real(kind=
rp),
optional,
intent(in) :: abs_tol
80 logical,
optional,
intent(in) :: monitor
102 if (
present(rel_tol) .and.
present(abs_tol) .and.
present(monitor))
then
103 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
104 else if (
present(rel_tol) .and.
present(abs_tol))
then
105 call this%ksp_init(max_iter, rel_tol, abs_tol)
106 else if (
present(monitor) .and.
present(abs_tol))
then
107 call this%ksp_init(max_iter, abs_tol = abs_tol, monitor = monitor)
108 else if (
present(rel_tol) .and.
present(monitor))
then
109 call this%ksp_init(max_iter, rel_tol, monitor = monitor)
110 else if (
present(rel_tol))
then
111 call this%ksp_init(max_iter, rel_tol = rel_tol)
112 else if (
present(abs_tol))
then
113 call this%ksp_init(max_iter, abs_tol = abs_tol)
114 else if (
present(monitor))
then
115 call this%ksp_init(max_iter, monitor = monitor)
117 call this%ksp_init(max_iter)
206 n, coef, blstx, blsty, blstz, gs_h, niter)
result(ksp_results)
208 class(
ax_t),
intent(in) :: ax
209 type(
field_t),
intent(inout) :: x
210 type(
field_t),
intent(inout) :: y
211 type(
field_t),
intent(inout) :: z
212 integer,
intent(in) :: n
213 real(kind=
rp),
dimension(n),
intent(in) :: fx
214 real(kind=
rp),
dimension(n),
intent(in) :: fy
215 real(kind=
rp),
dimension(n),
intent(in) :: fz
216 type(
coef_t),
intent(inout) :: coef
220 type(
gs_t),
intent(inout) :: gs_h
222 integer,
optional,
intent(in) :: niter
223 integer :: i, iter, max_iter
224 real(kind=
rp) :: rnorm, rtr, rtr0, rtz2, rtz1
225 real(kind=
rp) :: beta, pap, alpha, alphm, norm_fac
227 if (
present(niter))
then
230 max_iter = this%max_iter
232 norm_fac = 1.0_rp / coef%volume
234 associate(p1 => this%p1, p2 => this%p2, p3 => this%p3, z1 => this%z1, &
235 z2 => this%z2, z3 => this%z3, r1 => this%r1, r2 => this%r2, &
236 r3 => this%r3, tmp => this%tmp, w1 => this%w1, w2 => this%w2, &
240 do concurrent(i = 1:n)
241 x%x(i,1,1,1) = 0.0_rp
242 y%x(i,1,1,1) = 0.0_rp
243 z%x(i,1,1,1) = 0.0_rp
253 tmp(i) = r1(i)**2 + r2(i)**2 + r3(i)**2
256 rtr =
glsc3(tmp, coef%mult, coef%binv, n)
257 rnorm = sqrt(rtr*norm_fac)
258 ksp_results%res_start = rnorm
259 ksp_results%res_final = rnorm
261 if (
abscmp(rnorm, 0.0_rp))
then
262 ksp_results%converged = .true.
266 call this%monitor_start(
'cpldCG')
267 do iter = 1, max_iter
268 call this%M%solve(z1, this%r1, n)
269 call this%M%solve(z2, this%r2, n)
270 call this%M%solve(z3, this%r3, n)
273 do concurrent(i = 1:n)
274 this%tmp(i) = z1(i) * r1(i) &
279 rtz1 =
glsc2(tmp, coef%mult, n)
282 if (iter .eq. 1) beta = 0.0_rp
283 do concurrent(i = 1:n)
284 p1(i) = p1(i) * beta + z1(i)
285 p2(i) = p2(i) * beta + z2(i)
286 p3(i) = p3(i) * beta + z3(i)
289 call ax%compute_vector(w1, w2, w3, p1, p2, p3, coef, x%msh, x%Xh)
290 call gs_h%op(w1, n, gs_op_add)
291 call gs_h%op(w2, n, gs_op_add)
292 call gs_h%op(w3, n, gs_op_add)
293 call blstx%apply_scalar(w1, n)
294 call blsty%apply_scalar(w2, n)
295 call blstz%apply_scalar(w3, n)
297 do concurrent(i = 1:n)
298 tmp(i) = w1(i) * p1(i) &
303 pap =
glsc2(tmp, coef%mult, n)
307 do concurrent(i = 1:n)
308 x%x(i,1,1,1) = x%x(i,1,1,1) + alpha * p1(i)
309 y%x(i,1,1,1) = y%x(i,1,1,1) + alpha * p2(i)
310 z%x(i,1,1,1) = z%x(i,1,1,1) + alpha * p3(i)
311 r1(i) = r1(i) + alphm * w1(i)
312 r2(i) = r2(i) + alphm * w2(i)
313 r3(i) = r3(i) + alphm * w3(i)
314 tmp(i) = r1(i)**2 + r2(i)**2 + r3(i)**2
317 rtr =
glsc3(tmp, coef%mult, coef%binv, n)
318 if (iter .eq. 1) rtr0 = rtr
319 rnorm = sqrt(rtr * norm_fac)
320 call this%monitor_iter(iter, rnorm)
321 if (rnorm .lt. this%abs_tol)
then
326 call this%monitor_stop()
327 ksp_results%res_final = rnorm
328 ksp_results%iter = iter
329 ksp_results%converged = this%is_converged(iter, rnorm)
type(ksp_monitor_t) function, dimension(3) cg_cpld_solve(this, ax, x, y, z, fx, fy, fz, n, coef, blstx, blsty, blstz, gs_h, niter)
Coupled PCG solve.