Step Size in Nonlinear Variational Solver

Hello everyone,

Currently I’m using nonlinearvariationalsolver in my problem with for loop to follow incremental loading. I wonder if there is a solver parameter that allows the nonlinear solver incremental loading without any for loop definition. For example, let’s say I will apply 100 N force. Nonlinear solver firstly will try in a single step and suppose it diverged in 10 iteration (max iteration), then I want to force the solver with F/2 increment, if it fails again it will goes up to F/1024 as an load fraction until it converges or it will stop at F/1024. Is it possible with a solver parameter ? Thanks.

A second question, is it possible to add “while loop” to change the relaxation and maximum iteration number as a parameter in the code iteratively by checking the convergece status of the problem ? How can I reach the residual and use as a data in the code ? Thanks.

According to the reference manual NonlinearVariationalSolver() returns two values, number of Newton iterations and convergence. Maybe you can try to use try: and except: when solver diverges to change increment, maximum iteration number and relaxation parameter?

Hello bmf,

Thank you for your answer. Can you give me an simple example about how can I return number of iterations and convergence as a parameter or number in the code by using NonlinearVariationalSolver() ?

Sorry for late reply. You can try something like this:

n_iterations, convergence = NonlinearVariationalSolver(problem)

Hello bmf,

I think it does not work in this way and gives the following error:

NonlinearVariationalSolver' object is not iterable

Sorry, my mistake. This is how I have it implemented in my code (though I don’t use NonlinearVariationalSolver anymore):

problem = NonlinearVariationalProblem(F, u_new, bc, J)
solver = NonlinearVariationalSolver(problem)
number_of_iterations, convergence = solver.solve()
1 Like

Hello bmf,

Thanks for your response. Now it works for each substep. It gives the total number of iterations for substep and convergence status as “0” or “1”.

However is there any way to visualize the corresponding status of each iteration (not only for a substep) and residual as print ?

I don’t think that it is possible by using NonlinearVariationalSolver. Maybe you can create custom solver as described here. The example for the Newton Method at the PDE Level can be found here. Be careful, the code needs modification before you can use it, since some parts are outdated.