100 petscreal :: rnorm_l2
101 kspconvergedreason :: flag
102 class(PetscCnvgCtxType),
pointer :: context
103 petscerrorcode :: ierr
105 petscreal,
parameter :: min_one = -1.0
106 petscreal :: xnorm_inf, rnorm0, rnorm_inf_ims, rnorm_l2_ims
108 type(ConvergenceSummaryType),
pointer :: summary
110 summary => context%cnvg_summary
114 call kspbuildsolution(ksp, petsc_null_vec, x, ierr)
119 call kspbuildresidual(ksp, petsc_null_vec, petsc_null_vec, res, ierr)
122 rnorm0 = huge(rnorm0)
123 if (context%icnvgopt == 2 .or. &
124 context%icnvgopt == 3 .or. &
125 context%icnvgopt == 4)
then
126 call vecnorm(res, norm_2, rnorm_l2_ims, ierr)
127 rnorm0 = rnorm_l2_ims
129 else if (context%icnvgopt == 100)
then
135 context%rnorm_L2_init = rnorm0
136 if (rnorm_l2 < rnorm_l2_tol)
then
138 flag = ksp_converged_happy_breakdown
140 call veccopy(x, context%x_old, ierr)
142 flag = ksp_converged_iterating
145 call vecdestroy(res, ierr)
150 call vecwaxpy(context%delta_x, min_one, context%x_old, x, ierr)
153 call vecnorm(context%delta_x, norm_infinity, xnorm_inf, ierr)
156 rnorm_inf_ims = huge(rnorm_inf_ims)
157 if (context%icnvgopt == 0 .or. context%icnvgopt == 1)
then
158 call vecnorm(res, norm_infinity, rnorm_inf_ims, ierr)
162 call veccopy(x, context%x_old, ierr)
166 call fill_cnvg_summary(summary, context%delta_x, res, n)
168 if (rnorm_l2 < rnorm_l2_tol)
then
170 flag = ksp_converged_happy_breakdown
171 else if (context%icnvgopt < 100)
then
173 flag = apply_check(context, n, xnorm_inf, rnorm_inf_ims, rnorm_l2_ims)
174 else if (context%icnvgopt == 100)
then
176 flag = ksp_converged_iterating
177 if (xnorm_inf < context%dvclose .and. rnorm_l2 < context%rclose)
then
178 flag = ksp_converged_happy_breakdown
182 write (errmsg,
'(a,i0)')
"Invalid convergence option: ", context%icnvgopt
183 call store_error(errmsg, .true.)
186 if (flag == ksp_converged_iterating)
then
188 if (n == context%max_its)
then
189 flag = ksp_diverged_its
193 call vecdestroy(res, ierr)