Flagging Convergence in Newton Solver

Hello all. I’m currently working with a non-linear problem, where I need to run multiple material samples through the same FEA. Sometimes the particular set-up of a sample means it doesn’t converge within the maximum number of iterations, crashing the whole programme. I want to be able to end the current sample if it hasn’t converged after x amount of iterations, without ending the entire programme. I also need to flag that the current data set didn’t converge, so I can review it later.

Looking through the documentation, I’ve found the converged() command, but am unsure how to use it, or even whether this is applicable in my case.

Any help or guidance would be greatly appreciated!

You can set error_on_nonconvergence to False, see for instance: Bitbucket
or Custom NewtonSolver using the mixed-dimensional branch and PETScNestMatrix

Hi dokken, thank you for this! I’m trying to implement it, but keep getting the error:

RuntimeError: Parameter error_on_nonconvergence not found in Parameters object

I’m trying to use this with the in-built Newton solver - is this parameter compatible with this solver?

In case it’s of any help, here’s a snippet of my code (I think this is the only relevant part, but do say if there’s anything else you need):

            problem = NonlinearVariationalProblem(F, u, bcs, J)
            solver = NonlinearVariationalSolver(problem)    
    
            solver.parameters["newton_solver"]["maximum_iterations"]=2
            solver.parameters["error_on_nonconvergence"] = False

            solver.solve()

Thank you again for your help!

what about:

solver.parameters["newton_solver"]["error_on_nonconvergence"] = False

That’s working perfectly now, thank you so much for your help!