9 #include <dolfinx/common/MPI.h>
10 #include <dolfinx/la/PETScKrylovSolver.h>
22 class PETScKrylovSolver;
57 void setF(
const std::function<
void(
const Vec, Vec)>& F, Vec b);
63 void setJ(
const std::function<
void(
const Vec, Mat)>& J, Mat Jmat);
68 void setP(
const std::function<
void(
const Vec, Mat)>& P, Mat Pmat);
86 void set_form(
const std::function<
void(Vec x)>& form);
99 const Vec dx, Vec x)>& update);
106 std::pair<int, bool>
solve(Vec x);
155 std::function<void(
const Vec x, Vec b)> _fnF;
160 std::function<void(
const Vec x, Mat J)> _fnJ;
165 std::function<void(
const Vec x, Mat P)> _fnP;
169 std::function<void(
const Vec x)> _system;
175 Mat _matJ =
nullptr, _matP =
nullptr;
187 int _krylov_iterations;
193 double _residual, _residual0;
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:32
This class implements Krylov methods for linear systems of the form Ax = b. It is a wrapper for the K...
Definition: PETScKrylovSolver.h:27
This class defines a Newton solver for nonlinear systems of equations of the form .
Definition: NewtonSolver.h:32
int max_it
Maximum number of iterations.
Definition: NewtonSolver.h:130
void setF(const 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:92
std::pair< int, bool > solve(Vec x)
Solve the nonlinear problem for given and Jacobian .
Definition: NewtonSolver.cpp:145
void setP(const std::function< void(const Vec, Mat)> &P, Mat Pmat)
Set the function for computing the preconditioner matrix (optional)
Definition: NewtonSolver.cpp:108
double relaxation_parameter
Relaxation parameter.
Definition: NewtonSolver.h:149
const la::PETScKrylovSolver & get_krylov_solver() const
Get the internal Krylov solver used to solve for the Newton updates const version The Krylov solver p...
Definition: NewtonSolver.cpp:116
double atol
Absolute tolerance.
Definition: NewtonSolver.h:136
void set_update(const std::function< void(const nls::NewtonSolver &solver, const Vec dx, Vec x)> &update)
Set function that is called after each Newton iteration to update the solution.
Definition: NewtonSolver.cpp:138
NewtonSolver(MPI_Comm comm)
Create nonlinear solver.
Definition: NewtonSolver.cpp:65
void set_form(const std::function< void(Vec x)> &form)
Set the function that is called before the residual or Jacobian are computed. It is commonly used to ...
Definition: NewtonSolver.cpp:126
int iteration() const
The number of Newton interations. It can can called by functions that check for convergence during a ...
Definition: NewtonSolver.cpp:278
int krylov_iterations() const
Return number of Krylov iterations elapsed since solve started.
Definition: NewtonSolver.cpp:276
bool report
Monitor convergence.
Definition: NewtonSolver.h:143
double rtol
Relative tolerance.
Definition: NewtonSolver.h:133
double residual0() const
Return initial residual.
Definition: NewtonSolver.cpp:282
~NewtonSolver()
Destructor.
Definition: NewtonSolver.cpp:80
bool error_on_nonconvergence
Throw error if solver fails to converge.
Definition: NewtonSolver.h:146
double residual() const
Return current residual.
Definition: NewtonSolver.cpp:280
std::string convergence_criterion
Convergence criterion.
Definition: NewtonSolver.h:140
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: NewtonSolver.cpp:284
void set_convergence_check(const std::function< std::pair< double, bool >(const nls::NewtonSolver &solver, const Vec r)> &c)
Set function that is called at the end of each Newton iteration to test for convergence.
Definition: NewtonSolver.cpp:131
void setJ(const 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:100