From 295cf70edfb290975d83f5e8f93aa18feef8bc21 Mon Sep 17 00:00:00 2001 From: Kei Date: Thu, 2 Nov 2023 17:09:51 +0100 Subject: [PATCH 1/2] added check for nan value in the newtonsolver --- turtleFSI/modules/newtonsolver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/turtleFSI/modules/newtonsolver.py b/turtleFSI/modules/newtonsolver.py index c24afcc..df17826 100644 --- a/turtleFSI/modules/newtonsolver.py +++ b/turtleFSI/modules/newtonsolver.py @@ -4,6 +4,7 @@ # PURPOSE. from dolfin import assemble, derivative, TrialFunction, Matrix, norm, MPI, PETScOptions +from numpy import nan as np_nan PETScOptions.set("mat_mumps_icntl_4", 1) # If negatvie or zero, MUMPS will suppress diagnositc printining, statistics, and warning messages. PETScOptions.set("mat_mumps_icntl_14", 400) # allocate more memory to mumps @@ -103,8 +104,8 @@ def newtonsolver(F, J_nonlinear, A_pre, A, b, bcs, lmbda, recompute, recompute_t # Check residual residual = b.norm('l2') rel_res = norm(dvp_res, 'l2') - if rel_res > 1E20 or residual > 1E20: - raise RuntimeError("Error: The simulation has diverged during the Newton solve.") + if rel_res > 1E20 or residual > 1E20 or rel_res is np_nan or residual is np_nan: + raise RuntimeError("Error: The simulation has diverged during the Newton solve with residual = %.3e and relative residual = %.3e" % (residual, rel_res)) if MPI.rank(MPI.comm_world) == 0 and verbose: print("Newton iteration %d: r (atol) = %.3e (tol = %.3e), r (rel) = %.3e (tol = %.3e) " From 0a43d453f4309697d9e5e7ceefeca53453d78ca1 Mon Sep 17 00:00:00 2001 From: Kei Date: Fri, 3 Nov 2023 12:04:17 +0100 Subject: [PATCH 2/2] use isnan instead of is --- turtleFSI/modules/newtonsolver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/turtleFSI/modules/newtonsolver.py b/turtleFSI/modules/newtonsolver.py index df17826..699fc2c 100644 --- a/turtleFSI/modules/newtonsolver.py +++ b/turtleFSI/modules/newtonsolver.py @@ -4,7 +4,7 @@ # PURPOSE. from dolfin import assemble, derivative, TrialFunction, Matrix, norm, MPI, PETScOptions -from numpy import nan as np_nan +from numpy import isnan PETScOptions.set("mat_mumps_icntl_4", 1) # If negatvie or zero, MUMPS will suppress diagnositc printining, statistics, and warning messages. PETScOptions.set("mat_mumps_icntl_14", 400) # allocate more memory to mumps @@ -104,7 +104,7 @@ def newtonsolver(F, J_nonlinear, A_pre, A, b, bcs, lmbda, recompute, recompute_t # Check residual residual = b.norm('l2') rel_res = norm(dvp_res, 'l2') - if rel_res > 1E20 or residual > 1E20 or rel_res is np_nan or residual is np_nan: + if rel_res > 1E20 or residual > 1E20 or isnan(rel_res) or isnan(residual): raise RuntimeError("Error: The simulation has diverged during the Newton solve with residual = %.3e and relative residual = %.3e" % (residual, rel_res)) if MPI.rank(MPI.comm_world) == 0 and verbose: