82 subroutine sx_gmres_init(this, n, max_iter, M, rel_tol, abs_tol, monitor)
83 class(
sx_gmres_t),
target,
intent(inout) :: this
84 integer,
intent(in) :: n
85 integer,
intent(in) :: max_iter
86 class(
pc_t),
optional,
intent(in),
target :: M
87 real(kind=
rp),
optional,
intent(in) :: rel_tol
88 real(kind=
rp),
optional,
intent(in) :: abs_tol
89 logical,
optional,
intent(in) :: monitor
101 allocate(this%wk1(n))
103 allocate(this%c(this%lgmres))
104 allocate(this%s(this%lgmres))
105 allocate(this%gam(this%lgmres + 1))
107 allocate(this%z(n, this%lgmres))
108 allocate(this%v(n, this%lgmres))
110 allocate(this%h(this%lgmres, this%lgmres))
113 if (
present(rel_tol) .and.
present(abs_tol) .and.
present(monitor))
then
114 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
115 else if (
present(rel_tol) .and.
present(abs_tol))
then
116 call this%ksp_init(max_iter, rel_tol, abs_tol)
117 else if (
present(monitor) .and.
present(abs_tol))
then
118 call this%ksp_init(max_iter, abs_tol = abs_tol, monitor = monitor)
119 else if (
present(rel_tol) .and.
present(monitor))
then
120 call this%ksp_init(max_iter, rel_tol, monitor = monitor)
121 else if (
present(rel_tol))
then
122 call this%ksp_init(max_iter, rel_tol = rel_tol)
123 else if (
present(abs_tol))
then
124 call this%ksp_init(max_iter, abs_tol = abs_tol)
125 else if (
present(monitor))
then
126 call this%ksp_init(max_iter, monitor = monitor)
128 call this%ksp_init(max_iter)
213 class(
ax_t),
intent(in) :: ax
214 type(
field_t),
intent(inout) :: x
215 integer,
intent(in) :: n
216 real(kind=
rp),
dimension(n),
intent(in) :: f
217 type(
coef_t),
intent(inout) :: coef
219 type(
gs_t),
intent(inout) :: gs_h
221 integer,
optional,
intent(in) :: niter
222 integer :: iter, max_iter, glb_n
223 integer :: i, j, k, ierr
224 real(kind=
rp),
parameter :: one = 1.0
225 real(kind=
rp) :: rnorm
226 real(kind=
rp) :: alpha, temp, l
227 real(kind=
rp) :: ratio, div0, norm_fac
234 glb_n = n / x%msh%nelv * x%msh%glb_nelv
236 if (
present(niter))
then
239 max_iter = this%max_iter
242 call rone(this%ml, n)
243 call rone(this%mu, n)
244 norm_fac = one / sqrt(coef%volume)
246 call rzero(this%gam, this%lgmres + 1)
247 call rone(this%s, this%lgmres)
248 call rone(this%c, this%lgmres)
249 call rzero(this%h, this%lgmres * this%lgmres)
251 call this%monitor_start(
'GMRES')
252 do while (.not. conv .and. iter .lt. max_iter)
255 if (iter .eq. 0)
then
256 call col3(this%r, this%ml, f, n)
259 call copy (this%r,f,n)
260 call ax%compute(this%w, x%x, coef, x%msh, x%Xh)
261 call gs_h%op(this%w, n, gs_op_add)
262 call bc_projector%apply(this%w, n)
263 call add2s2(this%r, this%w, -one, n)
264 call col2(this%r, this%ml, n)
266 this%gam(1) = sqrt(
glsc3(this%r, this%r, coef%mult, n))
267 if (iter .eq. 0)
then
268 div0 = this%gam(1) * norm_fac
269 ksp_results%res_start = div0
272 if (
abscmp(this%gam(1), 0.0_rp))
exit
275 temp = one / this%gam(1)
276 call cmult2(this%v(1,1), this%r, temp, n)
277 do j = 1, this%lgmres
279 call col3(this%w, this%mu, this%v(1,j), n)
282 call this%M%solve(this%z(1,j), this%w, n)
284 call ax%compute(this%w, this%z(1,j), coef, x%msh, x%Xh)
285 call gs_h%op(this%w, n, gs_op_add)
286 call bc_projector%apply(this%w, n)
287 call col2(this%w, this%ml, n)
292 this%h(i,j) = this%h(i,j) + &
293 this%w(k) * this%v(k,i) * coef%mult(k,1,1,1)
298 call mpi_allreduce(this%h(1,j), this%wk1, j, &
300 call copy(this%h(1,j), this%wk1, j)
304 this%w(k) = this%w(k) - this%h(i,j) * this%v(k,i)
311 this%h(i ,j) = this%c(i)*temp + this%s(i)*this%h(i+1,j)
312 this%h(i+1,j) = -this%s(i)*temp + this%c(i)*this%h(i+1,j)
315 alpha = sqrt(
glsc3(this%w, this%w, coef%mult, n))
317 if (
abscmp(alpha, 0.0_rp))
then
321 l = sqrt(this%h(j,j) * this%h(j,j) + alpha**2)
323 this%c(j) = this%h(j,j) * temp
324 this%s(j) = alpha * temp
326 this%gam(j+1) = -this%s(j) * this%gam(j)
327 this%gam(j) = this%c(j) * this%gam(j)
329 rnorm = abs(this%gam(j+1)) * norm_fac
330 call this%monitor_iter(iter, rnorm)
332 if (rnorm .lt. this%abs_tol)
then
337 if (iter + 1 .gt. max_iter)
exit
339 if (j .lt. this%lgmres)
then
341 call cmult2(this%v(1,j+1), this%w, temp, n)
344 j = min(j, this%lgmres)
349 temp = temp - this%h(k,i) * this%c(i)
351 this%c(k) = temp / this%h(k,k)
356 x%x(k,1,1,1) = x%x(k,1,1,1) + this%c(i) * this%z(k,i)
360 call this%monitor_stop()
361 ksp_results%res_final = rnorm
362 ksp_results%iter = iter
363 ksp_results%converged = this%is_converged(iter, rnorm)
368 n, coef, bc_projector, gs_h, niter)
result(ksp_results)
370 class(
ax_t),
intent(in) :: ax
371 type(
field_t),
intent(inout) :: x
372 type(
field_t),
intent(inout) :: y
373 type(
field_t),
intent(inout) :: z
374 integer,
intent(in) :: n
375 real(kind=
rp),
dimension(n),
intent(in) :: fx
376 real(kind=
rp),
dimension(n),
intent(in) :: fy
377 real(kind=
rp),
dimension(n),
intent(in) :: fz
378 type(
coef_t),
intent(inout) :: coef
380 type(
gs_t),
intent(inout) :: gs_h
382 integer,
optional,
intent(in) :: niter
386 ksp_results(1) = this%solve(ax, x, fx, n, coef, bc_x, gs_h, niter)
387 ksp_results(2) = this%solve(ax, y, fy, n, coef, bc_y, gs_h, niter)
388 ksp_results(3) = this%solve(ax, z, fz, n, coef, bc_z, gs_h, niter)
type(ksp_monitor_t) function, dimension(3) sx_gmres_solve_coupled(this, ax, x, y, z, fx, fy, fz, n, coef, bc_projector, gs_h, niter)
Standard GMRES coupled solve.