74 subroutine sx_gmres_init(this, n, max_iter, M, rel_tol, abs_tol, monitor)
75 class(
sx_gmres_t),
target,
intent(inout) :: this
76 integer,
intent(in) :: n
77 integer,
intent(in) :: max_iter
78 class(
pc_t),
optional,
intent(in),
target :: M
79 real(kind=
rp),
optional,
intent(in) :: rel_tol
80 real(kind=
rp),
optional,
intent(in) :: abs_tol
81 logical,
optional,
intent(in) :: monitor
95 allocate(this%c(this%lgmres))
96 allocate(this%s(this%lgmres))
97 allocate(this%gam(this%lgmres + 1))
99 allocate(this%z(n,this%lgmres))
100 allocate(this%v(n,this%lgmres))
102 allocate(this%h(this%lgmres,this%lgmres))
105 if (
present(rel_tol) .and.
present(abs_tol) .and.
present(monitor))
then
106 call this%ksp_init(max_iter, rel_tol, abs_tol, monitor = monitor)
107 else if (
present(rel_tol) .and.
present(abs_tol))
then
108 call this%ksp_init(max_iter, rel_tol, abs_tol)
109 else if (
present(monitor) .and.
present(abs_tol))
then
110 call this%ksp_init(max_iter, abs_tol = abs_tol, monitor = monitor)
111 else if (
present(rel_tol) .and.
present(monitor))
then
112 call this%ksp_init(max_iter, rel_tol, monitor = monitor)
113 else if (
present(rel_tol))
then
114 call this%ksp_init(max_iter, rel_tol = rel_tol)
115 else if (
present(abs_tol))
then
116 call this%ksp_init(max_iter, abs_tol = abs_tol)
117 else if (
present(monitor))
then
118 call this%ksp_init(max_iter, monitor = monitor)
120 call this%ksp_init(max_iter)
183 class(
ax_t),
intent(in) :: ax
184 type(
field_t),
intent(inout) :: x
185 integer,
intent(in) :: n
186 real(kind=
rp),
dimension(n),
intent(in) :: f
187 type(
coef_t),
intent(inout) :: coef
189 type(
gs_t),
intent(inout) :: gs_h
191 integer,
optional,
intent(in) :: niter
192 integer :: iter, max_iter, glb_n
193 integer :: i, j, k, ierr
194 real(kind=
rp),
parameter :: one = 1.0
195 real(kind=
rp) :: rnorm
196 real(kind=
rp) :: alpha, temp, l
197 real(kind=
rp) :: ratio, div0, norm_fac
204 glb_n = n / x%msh%nelv * x%msh%glb_nelv
206 if (
present(niter))
then
209 max_iter = this%max_iter
212 call rone(this%ml, n)
213 call rone(this%mu, n)
214 norm_fac = one / sqrt(coef%volume)
216 call rzero(this%gam, this%lgmres + 1)
217 call rone(this%s, this%lgmres)
218 call rone(this%c, this%lgmres)
219 call rzero(this%h, this%lgmres * this%lgmres)
221 call this%monitor_start(
'GMRES')
222 do while (.not. conv .and. iter .lt. max_iter)
226 call col3(this%r,this%ml,f,n)
229 call copy (this%r,f,n)
230 call ax%compute(this%w, x%x, coef, x%msh, x%Xh)
231 call gs_h%op(this%w, n, gs_op_add)
232 call blst%apply(this%w, n)
233 call add2s2(this%r,this%w,-one,n)
234 call col2(this%r,this%ml,n)
236 this%gam(1) = sqrt(
glsc3(this%r, this%r, coef%mult, n))
238 div0 = this%gam(1) * norm_fac
239 ksp_results%res_start = div0
242 if (
abscmp(this%gam(1), 0.0_rp))
exit
245 temp = one / this%gam(1)
246 call cmult2(this%v(1,1), this%r, temp, n)
247 do j = 1, this%lgmres
249 call col3(this%w, this%mu, this%v(1,j), n)
252 call this%M%solve(this%z(1,j), this%w, n)
254 call ax%compute(this%w, this%z(1,j), coef, x%msh, x%Xh)
255 call gs_h%op(this%w, n, gs_op_add)
256 call blst%apply(this%w, n)
257 call col2(this%w, this%ml, n)
262 this%h(i,j) = this%h(i,j) + &
263 this%w(k) * this%v(k,i) * coef%mult(k,1,1,1)
268 call mpi_allreduce(this%h(1,j), this%wk1, j, &
270 call copy(this%h(1,j), this%wk1, j)
274 this%w(k) = this%w(k) - this%h(i,j) * this%v(k,i)
281 this%h(i ,j) = this%c(i)*temp + this%s(i)*this%h(i+1,j)
282 this%h(i+1,j) = -this%s(i)*temp + this%c(i)*this%h(i+1,j)
285 alpha = sqrt(
glsc3(this%w, this%w, coef%mult, n))
287 if(
abscmp(alpha, 0.0_rp))
then
291 l = sqrt(this%h(j,j) * this%h(j,j) + alpha**2)
293 this%c(j) = this%h(j,j) * temp
294 this%s(j) = alpha * temp
296 this%gam(j+1) = -this%s(j) * this%gam(j)
297 this%gam(j) = this%c(j) * this%gam(j)
299 rnorm = abs(this%gam(j+1)) * norm_fac
300 call this%monitor_iter(iter, rnorm)
302 if (rnorm .lt. this%abs_tol)
then
307 if (iter + 1 .gt. max_iter)
exit
309 if( j .lt. this%lgmres)
then
311 call cmult2(this%v(1,j+1), this%w, temp, n)
314 j = min(j, this%lgmres)
319 temp = temp - this%h(k,i) * this%c(i)
321 this%c(k) = temp / this%h(k,k)
326 x%x(k,1,1,1) = x%x(k,1,1,1) + this%c(i) * this%z(k,i)
330 call this%monitor_stop()
331 ksp_results%res_final = rnorm
332 ksp_results%iter = iter
333 ksp_results%converged = this%is_converged(iter, rnorm)
338 n, coef, blstx, blsty, blstz, gs_h, niter)
result(ksp_results)
340 class(
ax_t),
intent(in) :: ax
341 type(
field_t),
intent(inout) :: x
342 type(
field_t),
intent(inout) :: y
343 type(
field_t),
intent(inout) :: z
344 integer,
intent(in) :: n
345 real(kind=
rp),
dimension(n),
intent(in) :: fx
346 real(kind=
rp),
dimension(n),
intent(in) :: fy
347 real(kind=
rp),
dimension(n),
intent(in) :: fz
348 type(
coef_t),
intent(inout) :: coef
352 type(
gs_t),
intent(inout) :: gs_h
354 integer,
optional,
intent(in) :: niter
356 ksp_results(1) = this%solve(ax, x, fx, n, coef, blstx, gs_h, niter)
357 ksp_results(2) = this%solve(ax, y, fy, n, coef, blsty, gs_h, niter)
358 ksp_results(3) = this%solve(ax, z, fz, n, coef, blstz, gs_h, niter)
type(ksp_monitor_t) function, dimension(3) sx_gmres_solve_coupled(this, ax, x, y, z, fx, fy, fz, n, coef, blstx, blsty, blstz, gs_h, niter)
Standard GMRES coupled solve.