204 n, coef, bc_projector, gs_h, niter)
result(ksp_results)
206 class(
ax_t),
intent(in) :: ax
207 type(
field_t),
intent(inout) :: x
208 type(
field_t),
intent(inout) :: y
209 type(
field_t),
intent(inout) :: z
210 integer,
intent(in) :: n
211 real(kind=
rp),
dimension(n),
intent(in) :: fx
212 real(kind=
rp),
dimension(n),
intent(in) :: fy
213 real(kind=
rp),
dimension(n),
intent(in) :: fz
214 type(
coef_t),
intent(inout) :: coef
216 type(
gs_t),
intent(inout) :: gs_h
218 integer,
optional,
intent(in) :: niter
219 integer :: i, iter, max_iter, ierr
220 real(kind=
rp) :: rnorm, rtr, rtr0, rtz2, rtz1
221 real(kind=
rp) :: beta, pap, alpha, norm_fac
222 real(kind=
xp) :: tmp_xp, r1_xp, r2_xp, r3_xp, mult_xp
223 integer :: temp_indices(12)
225 if (
present(niter))
then
228 max_iter = this%max_iter
230 norm_fac = 1.0_rp / sqrt(coef%volume)
245 associate(p1 => this%p1, p2 => this%p2, p3 => this%p3, z1 => this%z1, &
246 z2 => this%z2, z3 => this%z3, r1 => this%r1, r2 => this%r2, &
247 r3 => this%r3, w1 => this%w1, w2 => this%w2, w3 => this%w3)
253 x%x(i,1,1,1) = 0.0_rp
254 y%x(i,1,1,1) = 0.0_rp
255 z%x(i,1,1,1) = 0.0_rp
265 tmp_xp = tmp_xp + (r1(i)**2 + r2(i)**2 + r3(i)**2) &
273 rnorm = sqrt(rtr)*norm_fac
274 ksp_results%res_start = rnorm
275 ksp_results%res_final = rnorm
277 if (
abscmp(rnorm, 0.0_rp))
then
278 ksp_results%converged = .true.
279 nullify(this%w1, this%w2, this%w3)
280 nullify(this%r1, this%r2, this%r3)
281 nullify(this%p1, this%p2, this%p3)
282 nullify(this%z1, this%z2, this%z3)
287 call this%monitor_start(
'cpldCG')
288 do iter = 1, max_iter
289 call this%M%solve(z1, this%r1, n)
290 call this%M%solve(z2, this%r2, n)
291 call this%M%solve(z3, this%r3, n)
297 tmp_xp = tmp_xp + (z1(i) * r1(i) &
299 + z3(i) * r3(i)) * coef%mult(i,1,1,1)
308 if (iter .eq. 1) beta = 0.0_rp
311 p1(i) = p1(i) * beta + z1(i)
312 p2(i) = p2(i) * beta + z2(i)
313 p3(i) = p3(i) * beta + z3(i)
317 call ax%compute_vector(w1, w2, w3, p1, p2, p3, coef, x%msh, x%Xh)
320 call gs_h%op(w1, w2, w3, n, gs_op_add)
323 call bc_projector%apply(w1, w2, w3, n)
328 tmp_xp = tmp_xp + (w1(i) * p1(i) &
330 + w3(i) * p3(i)) * coef%mult(i,1,1,1)
344 x%x(i,1,1,1) = x%x(i,1,1,1) + alpha * p1(i)
345 y%x(i,1,1,1) = y%x(i,1,1,1) + alpha * p2(i)
346 z%x(i,1,1,1) = z%x(i,1,1,1) + alpha * p3(i)
352 r1(i) = r1(i) - alpha * w1(i)
353 r2(i) = r2(i) - alpha * w2(i)
354 r3(i) = r3(i) - alpha * w3(i)
355 r1_xp =
real(r1(i), kind=
xp)
356 r2_xp =
real(r2(i), kind=
xp)
357 r3_xp =
real(r3(i), kind=
xp)
358 mult_xp =
real(coef%mult(i,1,1,1), kind=
xp)
360 (r1_xp * r1_xp + r2_xp * r2_xp + r3_xp * r3_xp) * mult_xp
369 if (iter .eq. 1) rtr0 = rtr
370 rnorm = sqrt(rtr) * norm_fac
371 call this%monitor_iter(iter, rnorm)
372 if (rnorm .lt. this%abs_tol)
then
377 nullify(this%w1, this%w2, this%w3)
378 nullify(this%r1, this%r2, this%r3)
379 nullify(this%p1, this%p2, this%p3)
380 nullify(this%z1, this%z2, this%z3)
382 call this%monitor_stop()
383 ksp_results%res_final = rnorm
384 ksp_results%iter = iter
385 ksp_results%converged = this%is_converged(iter, rnorm)