100 kspconvergedreason :: flag
101 class(PetscCnvgCtxType),
pointer :: context
102 petscerrorcode :: ierr
104 petscreal,
parameter :: min_one = -1.0
105 petscreal :: xnorm_inf, rnorm0, rnorm_inf_ims, rnorm_l2_ims
107 type(ConvergenceSummaryType),
pointer :: summary
109 summary => context%cnvg_summary
113 call kspbuildsolution(ksp, petsc_null_vec, x, ierr)
118 call kspbuildresidual(ksp, petsc_null_vec, petsc_null_vec, res, ierr)
121 rnorm0 = huge(rnorm0)
122 if (context%icnvgopt == 2 .or. &
123 context%icnvgopt == 3 .or. &
124 context%icnvgopt == 4)
then
125 call vecnorm(res, norm_2, rnorm_l2_ims, ierr)
126 rnorm0 = rnorm_l2_ims
132 context%rnorm_L2_init = rnorm0
133 if (rnorm_l2 < rnorm_l2_tol)
then
135 flag = ksp_converged_happy_breakdown
137 call veccopy(x, context%x_old, ierr)
139 flag = ksp_converged_iterating
142 call vecdestroy(res, ierr)
147 call vecwaxpy(context%delta_x, min_one, context%x_old, x, ierr)
150 call vecnorm(context%delta_x, norm_infinity, xnorm_inf, ierr)
153 rnorm_inf_ims = huge(rnorm_inf_ims)
154 if (context%icnvgopt == 0 .or. context%icnvgopt == 1)
then
155 call vecnorm(res, norm_infinity, rnorm_inf_ims, ierr)
159 call veccopy(x, context%x_old, ierr)
163 call fill_cnvg_summary(summary, context%delta_x, res, n)
165 if (rnorm_l2 < rnorm_l2_tol)
then
167 flag = ksp_converged_happy_breakdown
168 context%icnvg_ims = 1
170 if (n > 1 .and. context%icnvgopt == 1)
then
171 context%icnvg_ims = -1
175 flag = apply_check(context, n, xnorm_inf, rnorm_inf_ims, rnorm_l2_ims)
178 if (flag == ksp_converged_iterating)
then
180 if (n == context%max_its)
then
181 flag = ksp_diverged_its
185 call vecdestroy(res, ierr)