diff options
author | Anton Khirnov <anton@khirnov.net> | 2019-03-03 14:10:04 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2019-03-04 17:14:07 +0100 |
commit | 45f41504f74896cf91733878fb5f012af653d967 (patch) | |
tree | cadfbf554b6c6a8d32240ca0a071cc6be95c875c | |
parent | e15597d9ddbe1e1e0207ddecbd88aae516627f3b (diff) |
mg2d: fail if the residual grows too much from the original one
-rw-r--r-- | mg2d.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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; |