Understanding solver parameters in NonlinearVariationalSolver
Hi everyone, I am trying to understand the usage of solver parameters that are passed to the NonlinearVariationalSolver in firedrake. In order to do some tests, I decided to reproduce some of my previous calculations done in FEniCS for nonlinear viscoelasticity. In old dolfin, I had the following for solver parameters to be passed to PETSc's SNES: snes_solver_parameters = {"nonlinear_solver": "snes", "snes_solver": {"linear_solver": "lu", "maximum_iterations": 50, "report": True, "line_search": 'basic', "error_on_nonconvergence": False, "relative_tolerance": 1e-7, "absolute_tolerance": 1e-8}} ... ... solver = NonlinearVariationalSolver(problem) solver.parameters.update(snes_solver_parameters) Now as I understand, in Firedrake the options passed to the solver are consistent with the corresponding names in PETSc (correct me if I am wrong), and therefore I did: solver_params={ "snes_type": "newtonls", "ksp_type": "preonly", "pc_type": "lu", "snes_max_it": 100, "snes_rtol": 1.e-7, "snes_atol": 1.e-8, "snes_view": None, "ksp_atol": 1.e-10, # not needed? "ksp_rtol":1.e-8, "ksp_view": None, "snes_linesearch_type": "basic", "snes_no_convergence_test": 1 # this has no effect } solver = NonlinearVariationalSolver(problem, solver_parameters=solver_params) However, for some reason, I am unable to get the solver to converge when trying to solve the exact same problem as FEniCS. I experimented with different quadrature degrees as well as tweaked the solver parameters for SNES to best match what I am doing in dolfin. I understand that the form compiler is different hence the precise code that is generated may be different (I am not an expert on code generation) even though the python scripts may look similar due to UFL syntax. In fact the weird part is that the solver seems to converge fine till a certain point in my input (loading). You can see this in the plot below where I plot the final stress-stretch relation obtained at a point in my domain from dolfin and firedrake.. [image: firedrake_vs_fenics.png] I have marked the abscissa beyond which the solver fails to converge in Firedrake. The complete codes are here: https://github.com/bhaveshshrimali/comparingFiredrakeFEniCS I tried setting the option `snes_no_convergence_test` to 1/True but that had no effect as the SNES solver still diverges with `DIVERGED_DTOL`. In the end I put the call to solve inside a try/catch block to at least be able to see the solution till that point. And it surprisingly is accurate till that point. Would anyone have any clue of what could be going wrong? I wouldn't expect that you go through the entire code(s) as that could be fairly long, but any pointers would be helpful :) I am using firedrake via Docker on windows. Thanks --
Give -snes_view -snes_converged_reason -snes_monitor -ksp_converged_reason -ksp_monitor_true_residual and send all the output. That way I might be able to see what is happening when you do not converge. Also, line search 'basic' is not a good choice usually. I would either use the default, or 'cp', or maybe 'nleqerr' that Patrick added. Thanks, Matt On Sat, Jun 26, 2021 at 10:14 PM Bhavesh Shrimali < bhavesh.shrimali@gmail.com> wrote:
Hi everyone,
I am trying to understand the usage of solver parameters that are passed to the NonlinearVariationalSolver in firedrake. In order to do some tests, I decided to reproduce some of my previous calculations done in FEniCS for nonlinear viscoelasticity. In old dolfin, I had the following for solver parameters to be passed to PETSc's SNES:
snes_solver_parameters = {"nonlinear_solver": "snes", "snes_solver": {"linear_solver": "lu", "maximum_iterations": 50, "report": True, "line_search": 'basic', "error_on_nonconvergence": False, "relative_tolerance": 1e-7, "absolute_tolerance": 1e-8}} ... ... solver = NonlinearVariationalSolver(problem) solver.parameters.update(snes_solver_parameters)
Now as I understand, in Firedrake the options passed to the solver are consistent with the corresponding names in PETSc (correct me if I am wrong), and therefore I did:
solver_params={ "snes_type": "newtonls", "ksp_type": "preonly", "pc_type": "lu", "snes_max_it": 100, "snes_rtol": 1.e-7, "snes_atol": 1.e-8, "snes_view": None, "ksp_atol": 1.e-10, # not needed? "ksp_rtol":1.e-8, "ksp_view": None, "snes_linesearch_type": "basic", "snes_no_convergence_test": 1 # this has no effect } solver = NonlinearVariationalSolver(problem, solver_parameters=solver_params)
However, for some reason, I am unable to get the solver to converge when trying to solve the exact same problem as FEniCS. I experimented with different quadrature degrees as well as tweaked the solver parameters for SNES to best match what I am doing in dolfin. I understand that the form compiler is different hence the precise code that is generated may be different (I am not an expert on code generation) even though the python scripts may look similar due to UFL syntax.
In fact the weird part is that the solver seems to converge fine till a certain point in my input (loading). You can see this in the plot below where I plot the final stress-stretch relation obtained at a point in my domain from dolfin and firedrake..
[image: firedrake_vs_fenics.png]
I have marked the abscissa beyond which the solver fails to converge in Firedrake. The complete codes are here: https://github.com/bhaveshshrimali/comparingFiredrakeFEniCS
I tried setting the option `snes_no_convergence_test` to 1/True but that had no effect as the SNES solver still diverges with `DIVERGED_DTOL`. In the end I put the call to solve inside a try/catch block to at least be able to see the solution till that point. And it surprisingly is accurate till that point.
Would anyone have any clue of what could be going wrong? I wouldn't expect that you go through the entire code(s) as that could be fairly long, but any pointers would be helpful :)
I am using firedrake via Docker on windows.
Thanks
--
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
Note that 'basic' IS now the Firedrake default, so if you want backtracking line search then add '-snes_linesearch_type' : 'bt', to the solver parameters. Ed On Sun, Jun 27, 2021 at 6:01 AM Matthew Knepley <knepley@gmail.com> wrote:
Give
-snes_view -snes_converged_reason -snes_monitor -ksp_converged_reason -ksp_monitor_true_residual
and send all the output. That way I might be able to see what is happening when you do not converge. Also, line search 'basic' is not a good choice usually. I would either use the default, or 'cp', or maybe 'nleqerr' that Patrick added.
Thanks,
Matt
On Sat, Jun 26, 2021 at 10:14 PM Bhavesh Shrimali < bhavesh.shrimali@gmail.com> wrote:
Hi everyone,
I am trying to understand the usage of solver parameters that are passed to the NonlinearVariationalSolver in firedrake. In order to do some tests, I decided to reproduce some of my previous calculations done in FEniCS for nonlinear viscoelasticity. In old dolfin, I had the following for solver parameters to be passed to PETSc's SNES:
snes_solver_parameters = {"nonlinear_solver": "snes", "snes_solver": {"linear_solver": "lu", "maximum_iterations": 50, "report": True, "line_search": 'basic', "error_on_nonconvergence": False, "relative_tolerance": 1e-7, "absolute_tolerance": 1e-8}} ... ... solver = NonlinearVariationalSolver(problem) solver.parameters.update(snes_solver_parameters)
Now as I understand, in Firedrake the options passed to the solver are consistent with the corresponding names in PETSc (correct me if I am wrong), and therefore I did:
solver_params={ "snes_type": "newtonls", "ksp_type": "preonly", "pc_type": "lu", "snes_max_it": 100, "snes_rtol": 1.e-7, "snes_atol": 1.e-8, "snes_view": None, "ksp_atol": 1.e-10, # not needed? "ksp_rtol":1.e-8, "ksp_view": None, "snes_linesearch_type": "basic", "snes_no_convergence_test": 1 # this has no effect } solver = NonlinearVariationalSolver(problem, solver_parameters=solver_params)
However, for some reason, I am unable to get the solver to converge when trying to solve the exact same problem as FEniCS. I experimented with different quadrature degrees as well as tweaked the solver parameters for SNES to best match what I am doing in dolfin. I understand that the form compiler is different hence the precise code that is generated may be different (I am not an expert on code generation) even though the python scripts may look similar due to UFL syntax.
In fact the weird part is that the solver seems to converge fine till a certain point in my input (loading). You can see this in the plot below where I plot the final stress-stretch relation obtained at a point in my domain from dolfin and firedrake..
[image: firedrake_vs_fenics.png]
I have marked the abscissa beyond which the solver fails to converge in Firedrake. The complete codes are here: https://github.com/bhaveshshrimali/comparingFiredrakeFEniCS
I tried setting the option `snes_no_convergence_test` to 1/True but that had no effect as the SNES solver still diverges with `DIVERGED_DTOL`. In the end I put the call to solve inside a try/catch block to at least be able to see the solution till that point. And it surprisingly is accurate till that point.
Would anyone have any clue of what could be going wrong? I wouldn't expect that you go through the entire code(s) as that could be fairly long, but any pointers would be helpful :)
I am using firedrake via Docker on windows.
Thanks
--
_______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/> _______________________________________________ firedrake mailing list firedrake@imperial.ac.uk https://mailman.ic.ac.uk/mailman/listinfo/firedrake
-- Ed Bueler Dept of Mathematics and Statistics University of Alaska Fairbanks Fairbanks, AK 99775-6660 306C Chapman
participants (3)
- 
                
                Bhavesh Shrimali
- 
                
                Ed Bueler
- 
                
                Matthew Knepley