75 class(
pc_t),
optional,
intent(in),
target :: M
76 integer,
intent(in) :: n
77 integer,
intent(in) :: max_iter
78 real(kind=
rp),
optional,
intent(in) :: rel_tol
79 real(kind=
rp),
optional,
intent(in) :: abs_tol
80 logical,
optional,
intent(in) :: monitor
97 if (
present(rel_tol) .and.
present(abs_tol) .and.
present(monitor))
then
98 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
99 else if (
present(rel_tol) .and.
present(abs_tol))
then
100 call this%ksp_init(max_iter, rel_tol, abs_tol)
101 else if (
present(monitor) .and.
present(abs_tol))
then
102 call this%ksp_init(max_iter, abs_tol = abs_tol, monitor = monitor)
103 else if (
present(rel_tol) .and.
present(monitor))
then
104 call this%ksp_init(max_iter, rel_tol, monitor = monitor)
105 else if (
present(rel_tol))
then
106 call this%ksp_init(max_iter, rel_tol = rel_tol)
107 else if (
present(abs_tol))
then
108 call this%ksp_init(max_iter, abs_tol = abs_tol)
109 else if (
present(monitor))
then
110 call this%ksp_init(max_iter, monitor = monitor)
112 call this%ksp_init(max_iter)
160 class(
ax_t),
intent(in) :: ax
161 type(
field_t),
intent(inout) :: x
162 integer,
intent(in) :: n
163 real(kind=
rp),
dimension(n),
intent(in) :: f
164 type(
coef_t),
intent(inout) :: coef
166 type(
gs_t),
intent(inout) :: gs_h
168 integer,
optional,
intent(in) :: niter
169 integer :: iter, max_iter, i, ierr
170 real(kind=
rp) :: rnorm, rtr, reduction(3), norm_fac
171 real(kind=
rp) :: alpha, beta, gamma1, gamma2, delta
172 real(kind=
rp) :: tmp1, tmp2, tmp3
173 type(mpi_request) :: request
174 type(mpi_status) :: status
176 if (
present(niter))
then
179 max_iter = this%max_iter
181 norm_fac = 1.0_rp / sqrt(coef%volume)
184 x%x(i,1,1,1) = 0.0_rp
192 call this%M%solve(this%u, this%r, n)
193 call ax%compute(this%w, this%u, coef, x%msh, x%Xh)
194 call gs_h%op(this%w, n, gs_op_add)
195 call bc_projector%apply(this%w, n)
197 rtr =
glsc3(this%r, coef%mult, this%r, n)
198 rnorm = sqrt(rtr)*norm_fac
199 ksp_results%res_start = rnorm
200 ksp_results%res_final = rnorm
202 if (
abscmp(rnorm, 0.0_rp))
then
203 ksp_results%converged = .true.
209 call this%monitor_start(
'PipeCG')
210 do iter = 1, max_iter
216 tmp1 = tmp1 + this%r(i) * coef%mult(i,1,1,1) * this%u(i)
217 tmp2 = tmp2 + this%w(i) * coef%mult(i,1,1,1) * this%u(i)
218 tmp3 = tmp3 + this%r(i) * coef%mult(i,1,1,1) * this%r(i)
224 call mpi_iallreduce(mpi_in_place, reduction, 3, &
227 call this%M%solve(this%mi, this%w, n)
228 call ax%compute(this%ni, this%mi, coef, x%msh, x%Xh)
229 call gs_h%op(this%ni, n, gs_op_add)
230 call bc_projector%apply(this%ni, n)
232 call mpi_wait(request, status, ierr)
234 gamma1 = reduction(1)
238 rnorm = sqrt(rtr)*norm_fac
239 call this%monitor_iter(iter, rnorm)
240 if (rnorm .lt. this%abs_tol)
then
244 if (iter .gt. 1)
then
245 beta = gamma1 / gamma2
246 alpha = gamma1 / (delta - (beta * gamma1/alpha))
253 this%z(i) = beta * this%z(i) + this%ni(i)
254 this%q(i) = beta * this%q(i) + this%mi(i)
255 this%s(i) = beta * this%s(i) + this%w(i)
256 this%p(i) = beta * this%p(i) + this%u(i)
260 x%x(i,1,1,1) = x%x(i,1,1,1) + alpha * this%p(i)
261 this%r(i) = this%r(i) - alpha * this%s(i)
262 this%u(i) = this%u(i) - alpha * this%q(i)
263 this%w(i) = this%w(i) - alpha * this%z(i)
267 call this%monitor_stop()
268 ksp_results%res_final = rnorm
269 ksp_results%iter = iter
275 n, coef, bc_projector, gs_h, niter)
result(ksp_results)
277 class(
ax_t),
intent(in) :: ax
278 type(
field_t),
intent(inout) :: x
279 type(
field_t),
intent(inout) :: y
280 type(
field_t),
intent(inout) :: z
281 integer,
intent(in) :: n
282 real(kind=
rp),
dimension(n),
intent(in) :: fx
283 real(kind=
rp),
dimension(n),
intent(in) :: fy
284 real(kind=
rp),
dimension(n),
intent(in) :: fz
285 type(
coef_t),
intent(inout) :: coef
287 type(
gs_t),
intent(inout) :: gs_h
289 integer,
optional,
intent(in) :: niter
293 ksp_results(1) = this%solve(ax, x, fx, n, coef, bc_x, gs_h, niter)
294 ksp_results(2) = this%solve(ax, y, fy, n, coef, bc_y, gs_h, niter)
295 ksp_results(3) = this%solve(ax, z, fz, n, coef, bc_z, gs_h, niter)
type(ksp_monitor_t) function, dimension(3) sx_pipecg_solve_coupled(this, ax, x, y, z, fx, fy, fz, n, coef, bc_projector, gs_h, niter)
Pipelined PCG coupled solve.