25#include "neml2/solvers/NewtonWithLineSearch.h"
27#include "neml2/misc/math.h"
37 options.
doc() =
"The Newton-Raphson solver with line search.";
39 options.
set<
unsigned int>(
"max_linesearch_iterations") = 10;
40 options.
set(
"max_linesearch_iterations").doc() =
41 "Maximum allowable linesearch iterations. No error is produced upon reaching the maximum "
42 "number of iterations, and the scale factor in the last iteration is used to scale the step.";
44 options.
set<
Real>(
"linesearch_cutback") = 2.0;
45 options.
set(
"linesearch_cutback").doc() =
"Linesearch cut-back factor when the current scale "
46 "factor cannot sufficiently reduce the residual.";
48 options.
set<
Real>(
"linesearch_stopping_criteria") = 1.0e-3;
49 options.
set(
"linesearch_stopping_criteria").doc() =
50 "The lineseach tolerance slightly relaxing the definition of residual decrease";
57 _linesearch_miter(options.get<
unsigned int>(
"max_linesearch_iterations")),
58 _linesearch_sigma(options.get<
Real>(
"linesearch_cutback")),
59 _linesearch_c(options.get<
Real>(
"linesearch_stopping_criteria"))
80 const auto &
R =
system.residual_view();
91 std::cout <<
" LS ITERATION " << std::setw(3) <<
i <<
", alpha = " << std::scientific
92 << torch::min(
_alpha).item<
Real>() <<
", |R| = " << std::scientific
93 << torch::max(torch::sqrt(
nR2)).
item<Real>() <<
", |Rc| = " << std::scientific
94 << torch::min(torch::sqrt(
crit)).item<
Real>() << std::endl;
Derived batch_index(TorchSlice indices) const
Get a batch.
Definition BatchTensorBase.cxx:184
void batch_index_put(TorchSlice indices, const torch::Tensor &other)
Set a index sliced on the batch dimensions to a value.
Definition BatchTensorBase.cxx:202
Definition BatchTensor.h:32
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
static Scalar ones(const torch::TensorOptions &options=default_tensor_options())
Unbatched unit tensor.
Definition FixedDimTensor.h:161
The nonlinear solver solves a nonlinear system of equations.
Definition NewtonWithLineSearch.h:38
NewtonWithLineSearch(const OptionSet &options)
Definition NewtonWithLineSearch.cxx:55
virtual void linesearch(NonlinearSystem &system, const BatchTensor &x, const BatchTensor &dx)
Perform Armijo linesearch.
Definition NewtonWithLineSearch.cxx:74
Scalar _alpha
The line search parameter.
Definition NewtonWithLineSearch.h:61
Real _linesearch_c
Stopping criteria for linesearch.
Definition NewtonWithLineSearch.h:58
Real _linesearch_sigma
Decrease factor for linesearch.
Definition NewtonWithLineSearch.h:55
virtual void update(NonlinearSystem &system, BatchTensor &x) override
Update trial solution.
Definition NewtonWithLineSearch.cxx:64
static OptionSet expected_options()
Definition NewtonWithLineSearch.cxx:34
unsigned int _linesearch_miter
Linesearch maximum iterations.
Definition NewtonWithLineSearch.h:52
The nonlinear solver solves a nonlinear system of equations.
Definition Newton.h:39
static OptionSet expected_options()
Definition Newton.cxx:34
virtual BatchTensor solve_direction(const NonlinearSystem &system)
Find the current update direction.
Definition Newton.cxx:121
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
T & set(const std::string &)
Definition OptionSet.h:436
const bool verbose
Whether to print additional (debugging) information during the solve.
Definition Solver.h:49
BatchTensor bvv(const BatchTensor &a, const BatchTensor &b)
Batched vector-vector (dot) product.
Definition BatchTensor.cxx:137
Definition CrossRef.cxx:32