73 class(
pc_t),
optional,
intent(in),
target :: M
74 integer,
intent(in) :: n
75 integer,
intent(in) :: max_iter
76 real(kind=
rp),
optional,
intent(in) :: rel_tol
77 real(kind=
rp),
optional,
intent(in) :: abs_tol
78 logical,
optional,
intent(in) :: monitor
95 if (
present(rel_tol) .and.
present(abs_tol) .and.
present(monitor))
then
96 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
97 else if (
present(rel_tol) .and.
present(abs_tol))
then
98 call this%ksp_init(max_iter, rel_tol, abs_tol)
99 else if (
present(monitor) .and.
present(abs_tol))
then
100 call this%ksp_init(max_iter, abs_tol = abs_tol, monitor = monitor)
101 else if (
present(rel_tol) .and.
present(monitor))
then
102 call this%ksp_init(max_iter, rel_tol, monitor = monitor)
103 else if (
present(rel_tol))
then
104 call this%ksp_init(max_iter, rel_tol = rel_tol)
105 else if (
present(abs_tol))
then
106 call this%ksp_init(max_iter, abs_tol = abs_tol)
107 else if (
present(monitor))
then
108 call this%ksp_init(max_iter, monitor = monitor)
110 call this%ksp_init(max_iter)
158 class(
ax_t),
intent(in) :: ax
159 type(
field_t),
intent(inout) :: x
160 integer,
intent(in) :: n
161 real(kind=
rp),
dimension(n),
intent(in) :: f
162 type(
coef_t),
intent(inout) :: coef
164 type(
gs_t),
intent(inout) :: gs_h
166 integer,
optional,
intent(in) :: niter
167 integer :: iter, max_iter, i, ierr
168 real(kind=
rp) :: rnorm, rtr, reduction(3), norm_fac
169 real(kind=
rp) :: alpha, beta, gamma1, gamma2, delta
170 real(kind=
rp) :: tmp1, tmp2, tmp3
171 type(mpi_request) :: request
172 type(mpi_status) :: status
174 if (
present(niter))
then
177 max_iter = this%max_iter
179 norm_fac = 1.0_rp / sqrt(coef%volume)
182 x%x(i,1,1,1) = 0.0_rp
190 call this%M%solve(this%u, this%r, n)
191 call ax%compute(this%w, this%u, coef, x%msh, x%Xh)
192 call gs_h%op(this%w, n, gs_op_add)
193 call blst%apply_scalar(this%w, n)
195 rtr =
glsc3(this%r, coef%mult, this%r, n)
196 rnorm = sqrt(rtr)*norm_fac
197 ksp_results%res_start = rnorm
198 ksp_results%res_final = rnorm
200 if(
abscmp(rnorm, 0.0_rp))
then
201 ksp_results%converged = .true.
207 call this%monitor_start(
'PipeCG')
208 do iter = 1, max_iter
214 tmp1 = tmp1 + this%r(i) * coef%mult(i,1,1,1) * this%u(i)
215 tmp2 = tmp2 + this%w(i) * coef%mult(i,1,1,1) * this%u(i)
216 tmp3 = tmp3 + this%r(i) * coef%mult(i,1,1,1) * this%r(i)
222 call mpi_iallreduce(mpi_in_place, reduction, 3, &
225 call this%M%solve(this%mi, this%w, n)
226 call ax%compute(this%ni, this%mi, coef, x%msh, x%Xh)
227 call gs_h%op(this%ni, n, gs_op_add)
228 call blst%apply(this%ni, n)
230 call mpi_wait(request, status, ierr)
232 gamma1 = reduction(1)
236 rnorm = sqrt(rtr)*norm_fac
237 call this%monitor_iter(iter, rnorm)
238 if (rnorm .lt. this%abs_tol)
then
242 if (iter .gt. 1)
then
243 beta = gamma1 / gamma2
244 alpha = gamma1 / (delta - (beta * gamma1/alpha))
251 this%z(i) = beta * this%z(i) + this%ni(i)
252 this%q(i) = beta * this%q(i) + this%mi(i)
253 this%s(i) = beta * this%s(i) + this%w(i)
254 this%p(i) = beta * this%p(i) + this%u(i)
258 x%x(i,1,1,1) = x%x(i,1,1,1) + alpha * this%p(i)
259 this%r(i) = this%r(i) - alpha * this%s(i)
260 this%u(i) = this%u(i) - alpha * this%q(i)
261 this%w(i) = this%w(i) - alpha * this%z(i)
265 call this%monitor_stop()
266 ksp_results%res_final = rnorm
267 ksp_results%iter = iter
273 n, coef, blstx, blsty, blstz, gs_h, niter)
result(ksp_results)
275 class(
ax_t),
intent(in) :: ax
276 type(
field_t),
intent(inout) :: x
277 type(
field_t),
intent(inout) :: y
278 type(
field_t),
intent(inout) :: z
279 integer,
intent(in) :: n
280 real(kind=
rp),
dimension(n),
intent(in) :: fx
281 real(kind=
rp),
dimension(n),
intent(in) :: fy
282 real(kind=
rp),
dimension(n),
intent(in) :: fz
283 type(
coef_t),
intent(inout) :: coef
287 type(
gs_t),
intent(inout) :: gs_h
289 integer,
optional,
intent(in) :: niter
291 ksp_results(1) = this%solve(ax, x, fx, n, coef, blstx, gs_h, niter)
292 ksp_results(2) = this%solve(ax, y, fy, n, coef, blsty, gs_h, niter)
293 ksp_results(3) = this%solve(ax, z, fz, n, coef, blstz, gs_h, niter)
type(ksp_monitor_t) function, dimension(3) sx_pipecg_solve_coupled(this, ax, x, y, z, fx, fy, fz, n, coef, blstx, blsty, blstz, gs_h, niter)
Pipelined PCG coupled solve.