NEML2 1.4.0
Loading...
Searching...
No Matches
Newton Class Reference

The nonlinear solver solves a nonlinear system of equations. More...

Detailed Description

The nonlinear solver solves a nonlinear system of equations.

The Newton-Raphson method is used to iteratively update the initial guess until the residual becomes zero within specified tolerances.

#include <Newton.h>

Inheritance diagram for Newton:

Public Member Functions

 Newton (const OptionSet &options)
 
virtual std::tuple< bool, size_tsolve (NonlinearSystem &system, Tensor &x) override
 Solve the given nonlinear system.
 
- Public Member Functions inherited from NonlinearSolver
 NonlinearSolver (const OptionSet &options)
 Construct a new NonlinearSolver object.
 
- Public Member Functions inherited from Solver
 Solver (const OptionSet &options)
 Construct a new Solver object.
 
- Public Member Functions inherited from NEML2Object
 NEML2Object (const OptionSet &options)
 Construct a new NEML2Object object.
 
virtual ~NEML2Object ()=default
 
const OptionSetinput_options () const
 
virtual void setup ()
 Setup this object.
 
const std::string & name () const
 A readonly reference to the object's name.
 
const std::string & type () const
 A readonly reference to the object's type.
 
const std::string & path () const
 A readonly reference to the object's path.
 
const std::string & doc () const
 A readonly reference to the object's docstring.
 
template<typename T = NEML2Object>
const T * host () const
 Get a readonly pointer to the host.
 
template<typename T = NEML2Object>
T * host ()
 Get a writable pointer to the host.
 

Static Public Member Functions

static OptionSet expected_options ()
 
- Static Public Member Functions inherited from NonlinearSolver
static OptionSet expected_options ()
 
- Static Public Member Functions inherited from Solver
static OptionSet expected_options ()
 
- Static Public Member Functions inherited from NEML2Object
static OptionSet expected_options ()
 

Protected Member Functions

virtual void prepare (const NonlinearSystem &, const Tensor &)
 Prepare solver internal data before the iterative update.
 
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 the absolute tolerance or or the ratio between the residual norm and the initial residual norm is below the relative tolerance.
 
virtual void update (NonlinearSystem &system, Tensor &x)
 Update trial solution.
 
virtual void final_update (NonlinearSystem &system, Tensor &x)
 Do a final update to track AD function graph.
 
virtual Tensor solve_direction (const NonlinearSystem &system)
 Find the current update direction.
 

Additional Inherited Members

- Public Attributes inherited from NonlinearSolver
Real atol
 Absolute tolerance.
 
Real rtol
 Relative tolerance.
 
unsigned int miters
 Maximum number of iterations.
 
- Public Attributes inherited from Solver
const bool verbose
 Whether to print additional (debugging) information during the solve.
 

Constructor & Destructor Documentation

◆ Newton()

Newton ( const OptionSet & options)

Member Function Documentation

◆ converged()

bool converged ( size_t itr,
const torch::Tensor & nR,
const torch::Tensor & nR0 ) const
protectedvirtual

Check for convergence. The current iteration is said to be converged if the residual norm is below the absolute tolerance or or the ratio between the residual norm and the initial residual norm is below the relative tolerance.

Parameters
itrThe current iteration number
nRThe current residual norm
nR0The initial residual norm
Returns
true Converged
false Not converged

◆ expected_options()

OptionSet expected_options ( )
static

◆ final_update()

void final_update ( NonlinearSystem & system,
Tensor & x )
protectedvirtual

Do a final update to track AD function graph.

◆ prepare()

virtual void prepare ( const NonlinearSystem & ,
const Tensor &  )
inlineprotectedvirtual

Prepare solver internal data before the iterative update.

Reimplemented in NewtonWithTrustRegion.

◆ solve()

std::tuple< bool, size_t > solve ( NonlinearSystem & system,
Tensor & sol )
overridevirtual

Solve the given nonlinear system.

Parameters
systemThe nonlinear system of equations.
solThe initial solution which will be iteratively updated during the solve. It will be the solution to the system upon convergence
Returns
A boolean indicating whether the solve has succeeded and the number of iterations before convergence.

Implements NonlinearSolver.

◆ solve_direction()

Tensor solve_direction ( const NonlinearSystem & system)
protectedvirtual

Find the current update direction.

Reimplemented in NewtonWithTrustRegion.

◆ update()

void update ( NonlinearSystem & system,
Tensor & x )
protectedvirtual

Update trial solution.

Reimplemented in NewtonWithLineSearch, and NewtonWithTrustRegion.