25#include "neml2/solvers/Newton.h"
27#include "neml2/misc/math.h"
37 options.
doc() =
"The standard Newton-Raphson solver which always takes the 'full' Newton step.";
47std::tuple<bool, size_t>
53 auto nR0 =
nR.clone();
96 std::cout <<
"ITERATION " << std::setw(3) <<
itr <<
", |R| = " << std::scientific
97 << torch::max(
nR).item<
Real>() <<
", |R0| = " << std::scientific
98 << torch::max(
nR0).item<
Real>() << std::endl;
101 return torch::all(torch::logical_or(
nR <
atol,
nR /
nR0 <
rtol)).item<
bool>();
109 x.variable_data() +=
system.scale_direction(
dx);
124 if (
system.residual_view().base_dim() == 0)
125 return -
system.residual_view() /
system.Jacobian_view();
Definition BatchTensor.h:32
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
The nonlinear solver solves a nonlinear system of equations.
Definition Newton.h:39
virtual void final_update(NonlinearSystem &system, BatchTensor &x)
Do a final update to track AD function graph.
Definition Newton.cxx:114
virtual std::tuple< bool, size_t > solve(NonlinearSystem &system, BatchTensor &x) override
Solve the given nonlinear system.
Definition Newton.cxx:48
virtual bool converged(size_t itr, const torch::Tensor &nR, const torch::Tensor &nR0) const
Check for convergence. The current iteration is said to be converged if the residual norm is below th...
Definition Newton.cxx:92
virtual void prepare(const NonlinearSystem &, const BatchTensor &)
Prepare solver internal data before the iterative update.
Definition Newton.h:49
static OptionSet expected_options()
Definition Newton.cxx:34
Newton(const OptionSet &options)
Definition Newton.cxx:42
virtual void update(NonlinearSystem &system, BatchTensor &x)
Update trial solution.
Definition Newton.cxx:105
virtual BatchTensor solve_direction(const NonlinearSystem &system)
Find the current update direction.
Definition Newton.cxx:121
The nonlinear solver solves a nonlinear system of equations.
Definition NonlinearSolver.h:37
unsigned int miters
Maximum number of iterations.
Definition NonlinearSolver.h:64
Real rtol
Relative tolerance.
Definition NonlinearSolver.h:62
static OptionSet expected_options()
Definition NonlinearSolver.cxx:30
Real atol
Absolute tolerance.
Definition NonlinearSolver.h:60
Definition of a nonlinear system of equations.
Definition NonlinearSystem.h:37
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
const std::string & doc() const
A readonly reference to the option set's docstring.
Definition OptionSet.h:91
const bool verbose
Whether to print additional (debugging) information during the solve.
Definition Solver.h:49
BatchTensor solve(const BatchTensor &A, const BatchTensor &B)
Solve the linear system A X = B.
Definition math.cxx:340
Definition CrossRef.cxx:32