From 45f41504f74896cf91733878fb5f012af653d967 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 3 Mar 2019 14:10:04 +0100 Subject: mg2d: fail if the residual grows too much from the original one --- mg2d.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mg2d.c b/mg2d.c index 5b94022..a8511da 100644 --- a/mg2d.c +++ b/mg2d.c @@ -512,7 +512,7 @@ int mg2d_solve(MG2DContext *ctx) MG2DLevel *root = priv->root; EGSContext *s_root = root->solver; int64_t time_start; - double res_prev, res_cur; + double res_orig, res_prev, res_cur; int ret; if (!priv->tp) { @@ -531,7 +531,8 @@ int mg2d_solve(MG2DContext *ctx) if (ret < 0) return ret; - res_prev = s_root->residual_max; + res_orig = s_root->residual_max; + res_prev = res_orig; for (int i = 0; i < ctx->maxiter; i++) { ret = mg_solve_subgrid(ctx, root); @@ -553,7 +554,7 @@ int mg2d_solve(MG2DContext *ctx) mg2di_log(&priv->logger, MG2D_LOG_VERBOSE, "finished toplevel iteration %d, residual %g -> %g (%g)\n", i, res_prev, res_cur, res_prev / res_cur); - if (res_cur / res_prev > 1e1) { + if (res_cur / res_prev > 1e1 || res_cur / res_orig > 1e3) { mg2di_log(&priv->logger, MG2D_LOG_ERROR, "A multigrid iteration diverged\n"); ret = MG2D_ERR_DIVERGE; goto fail; -- cgit v1.2.3