76 subroutine cg_cpld_init(this, n, max_iter, M, rel_tol, abs_tol, monitor)
77 class(
cg_cpld_t),
target,
intent(inout) :: this
78 integer,
intent(in) :: max_iter
79 class(
pc_t),
optional,
intent(in),
target :: M
80 integer,
intent(in) :: n
81 real(kind=
rp),
optional,
intent(in) :: rel_tol
82 real(kind=
rp),
optional,
intent(in) :: abs_tol
83 logical,
optional,
intent(in) :: monitor
104 if (
present(rel_tol) .and.
present(abs_tol) .and.
present(monitor))
then
105 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
106 else if (
present(rel_tol) .and.
present(abs_tol))
then
107 call this%ksp_init(max_iter, rel_tol, abs_tol)
108 else if (
present(monitor) .and.
present(abs_tol))
then
109 call this%ksp_init(max_iter, abs_tol = abs_tol, monitor = monitor)
110 else if (
present(rel_tol) .and.
present(monitor))
then
111 call this%ksp_init(max_iter, rel_tol, monitor = monitor)
112 else if (
present(rel_tol))
then
113 call this%ksp_init(max_iter, rel_tol = rel_tol)
114 else if (
present(abs_tol))
then
115 call this%ksp_init(max_iter, abs_tol = abs_tol)
116 else if (
present(monitor))
then
117 call this%ksp_init(max_iter, monitor = monitor)
119 call this%ksp_init(max_iter)
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
224 if (
present(niter))
then
227 max_iter = this%max_iter
229 norm_fac = 1.0_rp / sqrt(coef%volume)
231 associate(p1 => this%p1, p2 => this%p2, p3 => this%p3, z1 => this%z1, &
232 z2 => this%z2, z3 => this%z3, r1 => this%r1, r2 => this%r2, &
233 r3 => this%r3, w1 => this%w1, w2 => this%w2, w3 => this%w3)
239 x%x(i,1,1,1) = 0.0_rp
240 y%x(i,1,1,1) = 0.0_rp
241 z%x(i,1,1,1) = 0.0_rp
251 tmp_xp = tmp_xp + (r1(i)**2 + r2(i)**2 + r3(i)**2) &
259 rnorm = sqrt(rtr)*norm_fac
260 ksp_results%res_start = rnorm
261 ksp_results%res_final = rnorm
263 if (
abscmp(rnorm, 0.0_rp))
then
264 ksp_results%converged = .true.
268 call this%monitor_start(
'cpldCG')
269 do iter = 1, max_iter
270 call this%M%solve(z1, this%r1, n)
271 call this%M%solve(z2, this%r2, n)
272 call this%M%solve(z3, this%r3, n)
278 tmp_xp = tmp_xp + (z1(i) * r1(i) &
280 + z3(i) * r3(i)) * coef%mult(i,1,1,1)
289 if (iter .eq. 1) beta = 0.0_rp
292 p1(i) = p1(i) * beta + z1(i)
293 p2(i) = p2(i) * beta + z2(i)
294 p3(i) = p3(i) * beta + z3(i)
298 call ax%compute_vector(w1, w2, w3, p1, p2, p3, coef, x%msh, x%Xh)
301 call gs_h%op(w1, w2, w3, n, gs_op_add)
304 call bc_projector%apply(w1, w2, w3, n)
309 tmp_xp = tmp_xp + (w1(i) * p1(i) &
311 + w3(i) * p3(i)) * coef%mult(i,1,1,1)
325 x%x(i,1,1,1) = x%x(i,1,1,1) + alpha * p1(i)
326 y%x(i,1,1,1) = y%x(i,1,1,1) + alpha * p2(i)
327 z%x(i,1,1,1) = z%x(i,1,1,1) + alpha * p3(i)
333 r1(i) = r1(i) - alpha * w1(i)
334 r2(i) = r2(i) - alpha * w2(i)
335 r3(i) = r3(i) - alpha * w3(i)
336 r1_xp =
real(r1(i), kind=
xp)
337 r2_xp =
real(r2(i), kind=
xp)
338 r3_xp =
real(r3(i), kind=
xp)
339 mult_xp =
real(coef%mult(i,1,1,1), kind=
xp)
341 (r1_xp * r1_xp + r2_xp * r2_xp + r3_xp * r3_xp) * mult_xp
350 if (iter .eq. 1) rtr0 = rtr
351 rnorm = sqrt(rtr) * norm_fac
352 call this%monitor_iter(iter, rnorm)
353 if (rnorm .lt. this%abs_tol)
then
358 call this%monitor_stop()
359 ksp_results%res_final = rnorm
360 ksp_results%iter = iter
361 ksp_results%converged = this%is_converged(iter, rnorm)