11#include <dolfinx/common/MPI.h>
12#include <dolfinx/la/petsc.h>
59 void setF(std::function<
void(
const Vec, Vec)> F, Vec b);
65 void setJ(std::function<
void(
const Vec, Mat)> J, Mat Jmat);
71 void setP(std::function<
void(
const Vec, Mat)> P, Mat Pmat);
93 void set_form(std::function<
void(Vec)> form);
99 std::function<std::pair<double, bool>(
const NewtonSolver&,
const Vec)> c);
105 std::function<
void(
const NewtonSolver& solver,
const Vec, Vec)> update);
112 std::pair<int, bool>
solve(Vec x);
133 MPI_Comm
comm()
const;
161 std::function<void(
const Vec x, Vec b)> _fnF;
166 std::function<void(
const Vec x, Mat J)> _fnJ;
171 std::function<void(
const Vec x, Mat P)> _fnP;
175 std::function<void(
const Vec x)> _system;
181 Mat _matJ =
nullptr, _matP =
nullptr;
184 std::function<std::pair<double, bool>(
const NewtonSolver& solver,
189 std::function<void(
const NewtonSolver& solver,
const Vec dx, Vec x)>
193 int _krylov_iterations;
199 double _residual, _residual0;
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:43
Definition NewtonSolver.h:34
double relaxation_parameter
Relaxation parameter.
Definition NewtonSolver.h:155
int krylov_iterations() const
Get number of Krylov iterations elapsed since solve started.
Definition NewtonSolver.cpp:276
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:128
void setF(std::function< void(const Vec, Vec)> F, Vec b)
Set the function for computing the residual and the vector to the assemble the residual into.
Definition NewtonSolver.cpp:93
NewtonSolver(NewtonSolver &&solver)=default
Move constructor.
double rtol
Relative tolerance.
Definition NewtonSolver.h:139
~NewtonSolver()
Destructor.
Definition NewtonSolver.cpp:81
NewtonSolver & operator=(NewtonSolver &&solver)=default
Move assignment constructor.
double atol
Absolute tolerance.
Definition NewtonSolver.h:142
NewtonSolver(MPI_Comm comm)
Definition NewtonSolver.cpp:69
double residual() const
Get current residual.
Definition NewtonSolver.cpp:283
void setP(std::function< void(const Vec, Mat)> P, Mat Pmat)
Set the function for computing the preconditioner matrix (optional).
Definition NewtonSolver.cpp:109
double residual0() const
Return initial residual.
Definition NewtonSolver.cpp:285
std::string convergence_criterion
Convergence criterion.
Definition NewtonSolver.h:146
int iteration() const
The number of Newton iterations. It can can called by functions that check for convergence during a s...
Definition NewtonSolver.cpp:281
void set_update(std::function< void(const NewtonSolver &solver, const Vec, Vec)> update)
Set function that is called after each Newton iteration to update the solution.
Definition NewtonSolver.cpp:139
void setJ(std::function< void(const Vec, Mat)> J, Mat Jmat)
Set the function for computing the Jacobian (dF/dx) and the matrix to assemble the residual into.
Definition NewtonSolver.cpp:101
bool report
Monitor convergence.
Definition NewtonSolver.h:149
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:133
bool error_on_nonconvergence
Throw error if solver fails to converge.
Definition NewtonSolver.h:152
MPI_Comm comm() const
Get MPI communicator.
Definition NewtonSolver.cpp:287
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:118
std::pair< int, bool > solve(Vec x)
Solve the nonlinear problem for given and Jacobian .
Definition NewtonSolver.cpp:145
int max_it
Maximum number of iterations.
Definition NewtonSolver.h:136
Top-level namespace.
Definition defines.h:12