diff options
Diffstat (limited to 'mg2d.c')
-rw-r--r-- | mg2d.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -17,6 +17,7 @@ */ #include <errno.h> +#include <float.h> #include <math.h> #include <stdlib.h> #include <stdint.h> @@ -256,6 +257,7 @@ static int mg_relax_step(MG2DLevel *level) static int mg_solve_subgrid(MG2DContext *ctx, MG2DLevel *level) { + double res_old, res_new; int ret; /* on the refined levels, use zero as the initial guess for the @@ -270,6 +272,8 @@ static int mg_solve_subgrid(MG2DContext *ctx, MG2DLevel *level) return ret; } + res_old = level->solver->residual_max; + /* handle coarsest grid */ if (!level->child) { @@ -333,6 +337,15 @@ static int mg_solve_subgrid(MG2DContext *ctx, MG2DLevel *level) } finish: + res_new = level->solver->residual_max; + if (!isfinite(res_new) || + (res_new > DBL_EPSILON && res_old / res_new <= 1e-1)) { + mg2di_log(&ctx->priv->logger, MG2D_LOG_ERROR, + "The relaxation step at level %d has diverged: %g -> %g\n", + level->depth, res_old, res_new); + return MG2D_ERR_DIVERGE; + } + return 0; } |