11#include <dolfinx/common/MPI.h>
12#include <dolfinx/la/petsc.h>
66 void setF(std::function<
void(
const Vec, Vec)> F, Vec b);
74 void setJ(std::function<
void(
const Vec, Mat)> J, Mat Jmat);
85 void setP(std::function<
void(
const Vec, Mat)> P, Mat Pmat);
108 void set_form(std::function<
void(Vec)> form);
114 std::function<std::pair<double, bool>(
const NewtonSolver&,
const Vec)> c);
126 std::function<
void(
const NewtonSolver& solver,
const Vec, Vec)> update);
133 std::pair<int, bool>
solve(Vec x);
153 MPI_Comm
comm()
const;
181 std::function<void(
const Vec x, Vec b)> _fnF;
186 std::function<void(
const Vec x, Mat J)> _fnJ;
191 std::function<void(
const Vec x, Mat P)> _fnP;
195 std::function<void(
const Vec x)> _system;
201 Mat _matJ =
nullptr, _matP =
nullptr;
204 std::function<std::pair<double, bool>(
const NewtonSolver& solver,
209 std::function<void(
const NewtonSolver& solver,
const Vec dx, Vec x)>
213 int _krylov_iterations;
219 double _residual, _residual0;
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:42
double relaxation_parameter
Relaxation parameter.
Definition NewtonSolver.h:175
int krylov_iterations() const
Number of Krylov iterations elapsed since solve started.
Definition NewtonSolver.cpp:278
void set_form(std::function< void(Vec)> form)
Set the function that is called before the residual or Jacobian are computed. It is commonly used to ...
Definition NewtonSolver.cpp:132
void setF(std::function< void(const Vec, Vec)> F, Vec b)
Set the function for computing the residual and the vector to assemble the residual into.
Definition NewtonSolver.cpp:97
NewtonSolver(NewtonSolver &&solver)=default
Move constructor.
double rtol
Relative convergence tolerance.
Definition NewtonSolver.h:159
~NewtonSolver()
Destructor.
Definition NewtonSolver.cpp:85
NewtonSolver & operator=(NewtonSolver &&solver)=default
Move assignment constructor.
double atol
Absolute convergence tolerance.
Definition NewtonSolver.h:162
NewtonSolver(MPI_Comm comm)
Create nonlinear solver.
Definition NewtonSolver.cpp:71
double residual() const
Get current residual.
Definition NewtonSolver.cpp:285
void setP(std::function< void(const Vec, Mat)> P, Mat Pmat)
Set the function for computing the preconditioner matrix.
Definition NewtonSolver.cpp:113
double residual0() const
Get initial residual.
Definition NewtonSolver.cpp:287
std::string convergence_criterion
Convergence criterion.
Definition NewtonSolver.h:166
int iteration() const
Get number of Newton iterations. It can be called by functions that check for convergence during a so...
Definition NewtonSolver.cpp:283
void set_update(std::function< void(const NewtonSolver &solver, const Vec, Vec)> update)
Optional set function that is called after each inner solve for the Newton increment to update the so...
Definition NewtonSolver.cpp:143
void setJ(std::function< void(const Vec, Mat)> J, Mat Jmat)
Set the function for computing the Jacobian and the matrix to assemble the Jacobian into.
Definition NewtonSolver.cpp:105
bool report
Monitor convergence.
Definition NewtonSolver.h:169
void set_convergence_check(std::function< std::pair< double, bool >(const NewtonSolver &, const Vec)> c)
Set function that is called at the end of each Newton iteration to test for convergence.
Definition NewtonSolver.cpp:137
bool error_on_nonconvergence
Throw error if solver fails to converge.
Definition NewtonSolver.h:172
MPI_Comm comm() const
Get MPI communicator.
Definition NewtonSolver.cpp:289
const la::petsc::KrylovSolver & get_krylov_solver() const
Get the internal Krylov solver used to solve for the Newton updates (const version).
Definition NewtonSolver.cpp:122
std::pair< int, bool > solve(Vec x)
Solve the nonlinear problem.
Definition NewtonSolver.cpp:149
int max_it
Maximum number of iterations.
Definition NewtonSolver.h:156
PETSc linear algebra functions.
Definition petsc.h:36
Top-level namespace.
Definition defines.h:12