NEML2 2.0.0
Loading...
Searching...
No Matches
NonlinearSystem Class Referenceabstract

Definition of a nonlinear system of equations. More...

Detailed Description

Definition of a nonlinear system of equations.

#include <NonlinearSystem.h>

Inheritance diagram for NonlinearSystem:

Classes

struct  Jac
 
struct  Res
 
struct  Sol
 

Public Member Functions

 NonlinearSystem (const NonlinearSystem &)=default
 
 NonlinearSystem (NonlinearSystem &&) noexcept=default
 
NonlinearSystemoperator= (const NonlinearSystem &)=delete
 
NonlinearSystemoperator= (NonlinearSystem &&)=delete
 
virtual ~NonlinearSystem ()=default
 
 NonlinearSystem (const OptionSet &options)
 
virtual void init_scaling (const Sol< false > &x, const bool verbose=false)
 Compute algebraic Jacobian-based automatic scaling following https://cs.stanford.edu/people/paulliu/files/cs517-project.pdf.
 
Res< truescale (const Res< false > &r) const
 Apply scaling to the residual.
 
Res< falseunscale (const Res< true > &r) const
 Remove scaling to the residual.
 
Jac< truescale (const Jac< false > &J) const
 Apply scaling to the Jacobian.
 
Jac< falseunscale (const Jac< true > &J) const
 Remove scaling to the Jacobian.
 
Sol< truescale (const Sol< false > &u) const
 Apply scaling to the solution.
 
Sol< falseunscale (const Sol< true > &u) const
 Remove scaling to the solution.
 
virtual void set_guess (const Sol< true > &x) final
 Set the current guess.
 
virtual void set_guess (const Sol< false > &x)=0
 Set the unscaled current guess.
 
template<bool scaled>
Res< scaledresidual ()
 Assemble and return the residual.
 
template<bool scaled>
Res< scaledresidual (const Sol< scaled > &x)
 Convenient shortcut to set the current guess, assemble and return the residual.
 
template<bool scaled>
Jac< scaledJacobian ()
 Assemble and return the Jacobian.
 
template<bool scaled>
Jac< scaledJacobian (const Sol< scaled > &x)
 Convenient shortcut to set the current guess, assemble and return the Jacobian.
 
template<bool scaled>
std::tuple< Res< scaled >, Jac< scaled > > residual_and_Jacobian ()
 Assemble and return the residual and Jacobian.
 
template<bool scaled>
std::tuple< Res< scaled >, Jac< scaled > > residual_and_Jacobian (const Sol< scaled > &x)
 Convenient shortcut to set the current guess, assemble and return the residual and Jacobian.
 

Static Public Member Functions

static OptionSet expected_options ()
 
static void disable_automatic_scaling (OptionSet &options)
 
static void enable_automatic_scaling (OptionSet &options)
 

Protected Member Functions

virtual void assemble (Res< false > *r, Jac< false > *J)=0
 Compute the unscaled residual and Jacobian.
 

Protected Attributes

const bool _autoscale
 If true, do automatic scaling.
 
const Real _autoscale_tol
 Tolerance for convergence check of the iterative automatic scaling algorithm.
 
const unsigned int _autoscale_miter
 Maximum number of iterations allowed for the iterative automatic scaling algorithm.
 
bool _scaling_matrices_initialized
 Flag to indicate whether scaling matrices have been computed.
 
Tensor _row_scaling
 Row scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals.
 
Tensor _col_scaling
 Column scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals.
 

Constructor & Destructor Documentation

◆ NonlinearSystem() [1/3]

◆ NonlinearSystem() [2/3]

NonlinearSystem ( NonlinearSystem && )
defaultnoexcept

◆ ~NonlinearSystem()

virtual ~NonlinearSystem ( )
virtualdefault

◆ NonlinearSystem() [3/3]

Member Function Documentation

◆ assemble()

virtual void assemble ( Res< false > * r,
Jac< false > * J )
protectedpure virtual

Compute the unscaled residual and Jacobian.

Parameters
rPointer to the residual vector – nullptr if not requested
JPointer to the Jacobian matrix – nullptr if not requested

Implemented in Model, and TrustRegionSubProblem.

◆ disable_automatic_scaling()

void disable_automatic_scaling ( OptionSet & options)
static

◆ enable_automatic_scaling()

void enable_automatic_scaling ( OptionSet & options)
static

◆ expected_options()

OptionSet expected_options ( )
static

◆ init_scaling()

void init_scaling ( const Sol< false > & x,
const bool verbose = false )
virtual

Compute algebraic Jacobian-based automatic scaling following https://cs.stanford.edu/people/paulliu/files/cs517-project.pdf.

In a nutshell, given the original linearized system

\( \mathrm{J} \Delta \mathrm{x} = -\mathrm{r} \)

Instead of solving for \( \Delta \mathrm{x} \) directly, we solve for a scaled version of it:

\( \mathrm{J} \mathrm{C} \Delta \mathrm{x}' = -\mathrm{r} \)

where \( \mathrm{C} \) is a diagonal matrix, and apparently \( \Delta \mathrm{x} = \mathrm{C} \Delta \mathrm{x}' \). Then, left-multiply both sides by another diagonal matrix \( \mathrm{R} \), we get

\( \mathrm{R} \mathrm{J} \mathrm{C} \Delta \mathrm{x}' = -\mathrm{R} \mathrm{r} \)

which is equivalent to

\( \mathrm{J}' \Delta \mathrm{x}' = -\mathrm{r}' \)

where \( \mathrm{J}' = \mathrm{R} \mathrm{J} \mathrm{C} \) is the scaled Jacobian, and \( \mathrm{r}' = \mathrm{R} \mathrm{r} \) is the scaled residual. The goal of automatic scaling is to find the scaling matrices so that max-norm of the rows and columns of the scaled Jacobian is as close to 1 as possible.

Parameters
xUnscaled initial guess used to compute the initial unscaled residual and Jacobian
verbosePrint automatic scaling convergence information

◆ Jacobian() [1/2]

template<bool scaled>
NonlinearSystem::Jac< scaled > Jacobian ( )

Assemble and return the Jacobian.

◆ Jacobian() [2/2]

template<bool scaled>
NonlinearSystem::Jac< scaled > Jacobian ( const Sol< scaled > & x)

Convenient shortcut to set the current guess, assemble and return the Jacobian.

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ residual() [1/2]

template<bool scaled>
NonlinearSystem::Res< scaled > residual ( )

Assemble and return the residual.

◆ residual() [2/2]

template<bool scaled>
NonlinearSystem::Res< scaled > residual ( const Sol< scaled > & x)

Convenient shortcut to set the current guess, assemble and return the residual.

◆ residual_and_Jacobian() [1/2]

template<bool scaled>
std::tuple< NonlinearSystem::Res< scaled >, NonlinearSystem::Jac< scaled > > residual_and_Jacobian ( )

Assemble and return the residual and Jacobian.

◆ residual_and_Jacobian() [2/2]

template<bool scaled>
std::tuple< NonlinearSystem::Res< scaled >, NonlinearSystem::Jac< scaled > > residual_and_Jacobian ( const Sol< scaled > & x)

Convenient shortcut to set the current guess, assemble and return the residual and Jacobian.

◆ scale() [1/3]

NonlinearSystem::Jac< true > scale ( const Jac< false > & J) const

Apply scaling to the Jacobian.

◆ scale() [2/3]

NonlinearSystem::Res< true > scale ( const Res< false > & r) const

Apply scaling to the residual.

◆ scale() [3/3]

NonlinearSystem::Sol< true > scale ( const Sol< false > & u) const

Apply scaling to the solution.

◆ set_guess() [1/2]

virtual void set_guess ( const Sol< false > & x)
pure virtual

Set the unscaled current guess.

Implemented in Model, and TrustRegionSubProblem.

◆ set_guess() [2/2]

void set_guess ( const Sol< true > & x)
finalvirtual

Set the current guess.

◆ unscale() [1/3]

NonlinearSystem::Jac< false > unscale ( const Jac< true > & J) const

Remove scaling to the Jacobian.

◆ unscale() [2/3]

NonlinearSystem::Res< false > unscale ( const Res< true > & r) const

Remove scaling to the residual.

◆ unscale() [3/3]

NonlinearSystem::Sol< false > unscale ( const Sol< true > & u) const

Remove scaling to the solution.

Member Data Documentation

◆ _autoscale

const bool _autoscale
protected

If true, do automatic scaling.

◆ _autoscale_miter

const unsigned int _autoscale_miter
protected

Maximum number of iterations allowed for the iterative automatic scaling algorithm.

◆ _autoscale_tol

const Real _autoscale_tol
protected

Tolerance for convergence check of the iterative automatic scaling algorithm.

◆ _col_scaling

Tensor _col_scaling
protected

Column scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals.

◆ _row_scaling

Tensor _row_scaling
protected

Row scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals.

◆ _scaling_matrices_initialized

bool _scaling_matrices_initialized
protected

Flag to indicate whether scaling matrices have been computed.