Skip to content

Commit

Permalink
Merge pull request #100 from keiyamamo/improve_newtonsolver
Browse files Browse the repository at this point in the history
added check for nan value in the newtonsolver
  • Loading branch information
keiyamamo committed Nov 5, 2023
2 parents 16c98c0 + 0a43d45 commit da5e0de
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions turtleFSI/modules/newtonsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# PURPOSE.

from dolfin import assemble, derivative, TrialFunction, Matrix, norm, MPI, PETScOptions
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
Expand Down Expand Up @@ -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 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:
print("Newton iteration %d: r (atol) = %.3e (tol = %.3e), r (rel) = %.3e (tol = %.3e) "
Expand Down

0 comments on commit da5e0de

Please sign in to comment.