Prevent the code from stopping due to a PETSc error

Hello,

I am solving a time-dependent nonlinear problem (hyperelasticity+phase field). I have coded my own nonlinear solver and for the linear system of equations, I am using PETSc Krylov solver with the following configuration

pc = PETScPreconditioner("petsc_amg") 
PETScOptions.set("mg_levels_ksp_type", "chebyshev")
PETScOptions.set("mg_levels_pc_type", "jacobi")
PETScOptions.set("mg_levels_esteig_ksp_type", "cg")
PETScOptions.set("mg_levels_ksp_chebyshev_esteig_steps", 50)
solver_u = PETScKrylovSolver("cg", pc)
max_iterations=450
solver_u.parameters["maximum_iterations"] = max_iterations
solver_u.parameters["error_on_nonconvergence"] = False

The issue I am encountering is that sometimes during the solution of the linear system, after the simulation time has progressed quite a bit, the code gets terminated with this error:

Error:   Unable to successfully call PETSc function 'KSPSolve'.
*** Reason:  PETSc error code is: 77 (Petsc has generated inconsistent data).
*** Where:   This error was encountered inside /tmp/dolfin/dolfin/la/PETScKrylovSolver.cpp.
*** Process: 130

So I have two questions about this:

  1. What could be the potential reasons behind this error?
  2. Can I somehow prevent the code from stopping due to this error, so that I can tweak some parameters to potentially make it progress?

Thank you!

This could be because you run out of memory.