My fenics version is 2019, I using fenics by docker.
I’m having a problem with non-convergence due to the initial value being too large, so I’d like to know how to set up Newton solver to help my code converge using ‘Newton’s Method with Line Search’.
So there are no code snippets.
You can assign initial data to the unknown function through a projection or interpolation.
If you want a line-search method, I would use the SNES backend of legacy dolfin.
Hi!
I am also trying to use line search with legacy Fenics 2019. Could you develop a little more on how to use the SNES backend of legacy dolfin?
Right now, my Newton solver configuration looks as follows (in C++)
auto KrylovSolver_ = std::make_shared<PETScKrylovSolver>("gmres", preconditioner_);
KSP ksp = KrylovSolver_->ksp();
PETScOptions::set("ksp_rtol", 1.0e-8);
PETScOptions::set("ksp_atol", 1.0e-12);
PETScOptions::set("ksp_gmres_restart", 50);
PETScOptions::set("pc_factor_levels", 4);
PETScOptions::set("pc_factor_fill", 2.0);
PETScOptions::set("pc_factor_mat_ordering_type", "rcm");
KSPSetFromOptions(ksp);
newtonSolver_ = std::make_shared<NewtonSolver>(MPI_COMM_WORLD, KrylovSolver_, PETScFactory::instance());
newtonSolver_->parameters["maximum_iterations"] = 100;
newtonSolver_->parameters["absolute_tolerance"] = 1.0e-8;
newtonSolver_->parameters["relative_tolerance"] = 1.0e-8;
I’ve personally never used the snes backend from C++ in legacy DOLFIN.
I would have a look at Bitbucket
1 Like
Thanks! I figured out how to implement it. I’m leaving the code here in case it’s useful to someone.
// Initialize PETSc SNES solver with linesearch
PETScOptions::set("snes_type", "newtonls"); // Newton with line search
PETScOptions::set("snes_linesearch_type", "bt"); // Backtracking line search
PETScOptions::set("snes_max_it", 100);
PETScOptions::set("snes_atol", 1.0e-8);
PETScOptions::set("snes_rtol", 1.0e-8);
PETScOptions::set("ksp_type", "gmres");
PETScOptions::set("ksp_rtol", 1.0e-8);
PETScOptions::set("ksp_atol", 1.0e-12);
PETScOptions::set("ksp_gmres_restart", 50);
PETScOptions::set("pc_type", preconditioner_);
PETScOptions::set("pc_factor_levels", 4);
PETScOptions::set("pc_factor_fill", 2.0);
PETScOptions::set("pc_factor_mat_ordering_type", "rcm");
PETScOptions::set("snes_monitor");
PETScOptions::set("ksp_converged_reason");
newtonSolver_ = std::make_shared<PETScSNESSolver>();