Cantera  3.1.0b1
Loading...
Searching...
No Matches
MultiNewton Class Reference

Newton iterator for multi-domain, one-dimensional problems. More...

#include <MultiNewton.h>

Detailed Description

Newton iterator for multi-domain, one-dimensional problems.

Used by class OneDim.

Definition at line 23 of file MultiNewton.h.

Public Member Functions

 MultiNewton (int sz)
 Constructor.
 
 MultiNewton (const MultiNewton &)=delete
 
MultiNewtonoperator= (const MultiNewton &)=delete
 
size_t size ()
 Get the number of variables in the system.
 
void step (double *x, double *step, OneDim &r, MultiJac &jac, int loglevel)
 Compute the undamped Newton step.
 
double boundStep (const double *x0, const double *step0, const OneDim &r, int loglevel)
 Return the factor by which the undamped Newton step 'step0' must be multiplied in order to keep all solution components in all domains between their specified lower and upper bounds.
 
int dampStep (const double *x0, const double *step0, double *x1, double *step1, double &s1, OneDim &r, MultiJac &jac, int loglevel, bool writetitle)
 Performs a damped Newton step to solve the system of nonlinear equations.
 
double norm2 (const double *x, const double *step, OneDim &r) const
 Compute the weighted 2-norm of step.
 
int solve (double *x0, double *x1, OneDim &r, MultiJac &jac, int loglevel)
 Find the solution to F(x) = 0 by damped Newton iteration.
 
void setOptions (int maxJacAge=5)
 Set options.
 
void resize (size_t points)
 Change the problem size.
 

Protected Attributes

vector< double > m_x
 Work array holding the system state after the last successful step. Size m_n.
 
vector< double > m_stp
 Work array holding the undamped Newton step or the system residual. Size m_n.
 
vector< double > m_stp1
 Work array holding the damped Newton step. Size m_n.
 
int m_maxAge = 5
 Maximum allowable Jacobian age before it is recomputed.
 
double m_dampFactor = sqrt(2.0)
 Factor by which the damping coefficient is reduced in each iteration.
 
size_t m_maxDampIter = 7
 Maximum number of damping iterations.
 
size_t m_n
 number of variables
 
double m_elapsed = 0.0
 Elapsed CPU time spent computing the Jacobian.
 

Constructor & Destructor Documentation

◆ MultiNewton()

MultiNewton ( int  sz)

Constructor.

Parameters
szNumber of variables in the system

Definition at line 159 of file MultiNewton.cpp.

◆ ~MultiNewton()

virtual ~MultiNewton ( )
inlinevirtual

Definition at line 29 of file MultiNewton.h.

Member Function Documentation

◆ size()

size_t size ( )
inline

Get the number of variables in the system.

Definition at line 34 of file MultiNewton.h.

◆ step()

void step ( double *  x,
double *  step,
OneDim r,
MultiJac jac,
int  loglevel 
)

Compute the undamped Newton step.

The residual function is evaluated at x, but the Jacobian is not recomputed.

Definition at line 184 of file MultiNewton.cpp.

◆ boundStep()

double boundStep ( const double *  x0,
const double *  step0,
const OneDim r,
int  loglevel 
)

Return the factor by which the undamped Newton step 'step0' must be multiplied in order to keep all solution components in all domains between their specified lower and upper bounds.

Definition at line 217 of file MultiNewton.cpp.

◆ dampStep()

int dampStep ( const double *  x0,
const double *  step0,
double *  x1,
double *  step1,
double &  s1,
OneDim r,
MultiJac jac,
int  loglevel,
bool  writetitle 
)

Performs a damped Newton step to solve the system of nonlinear equations.

On entry, step0 must contain an undamped Newton step for the solution x0. This method attempts to find a damping coefficient alpha_k such that the next undamped step would have a norm smaller than that of step0. If successful, the new solution after taking the damped step is returned in x1, and the undamped step at x1 is returned in step1.

This uses the method outlined in Kee et al. [17].

The system of equations can be written in the form:

\[ F(x) = 0 \]

Where \( F \) is the system of nonlinear equations and \( x \) is the solution vector.

For the damped Newton method we are solving:

\[ x_{k+1} - x_k = \Delta x_k = -\alpha_k J^{-1}(x_k) F(x_k) \]

Where \( J \) is the Jacobian matrix of \( F \) with respect to \( x \), and \( \alpha_k \) is the damping factor, and \( \Delta x_k \) is the Newton step at \( x_k \), sometimes called the correction vector. In the equations here, \( k \) is just an iteration variable.

In this method, the Jacobian does not update, even when the solution vector is evaluated at different points.

The general algorithm is described below.

We want to solve the equation:

\[ x_{k+1} = x_k + \alpha_k \Delta x_k \]

Pick \( \alpha_k \) such that \( \Vert \Delta x_{k+1} \Vert < \Vert \Delta x_k \Vert \) where \( \Delta x_k = J^{-1}(x_k) F(x_k) \), and \( \Delta x_{k+1} = J^{-1}(x_{k}) F(x_{k+1}) \).

Parameters
[in]x0initial solution about which a Newton step will be taken
[in]step0initial undamped Newton step
[out]x1solution after taking the damped Newton step
[out]step1Newton step after taking the damped Newton step
[out]s1norm of the subsequent Newton step after taking the damped Newton step
[in]rdomain object, used for evaluating residuals over all domains
[in]jacJacobian evaluator
[in]loglevelcontrols amount of printed diagnostics
[in]writetitlecontrols if logging title is printed
Returns
  • 1 a damping coefficient was found and the solution converges.
  • 0 a damping coefficient was found, but the solution has not converged yet.
  • -2 no suitable damping coefficient was found within the maximum iterations.
  • -3 the current solution x0 is too close to the solution bounds and the step would exceed the bounds on one or more components.

Definition at line 229 of file MultiNewton.cpp.

◆ norm2()

double norm2 ( const double *  x,
const double *  step,
OneDim r 
) const

Compute the weighted 2-norm of step.

Definition at line 172 of file MultiNewton.cpp.

◆ solve()

int solve ( double *  x0,
double *  x1,
OneDim r,
MultiJac jac,
int  loglevel 
)

Find the solution to F(x) = 0 by damped Newton iteration.

On entry, x0 contains an initial estimate of the solution. On successful return, x1 contains the converged solution. If failure occurs, x1 will contain the value of x0 i.e. no change in solution.

The convergence criteria is when the 2-norm of the Newton step is less than one.

Returns
  • 1 a converged solution was found.
  • -2 no suitable damping coefficient was found within the maximum iterations.
  • -3 the current solution x0 is too close to the solution bounds and the step would exceed the bounds on one or more components.

Definition at line 311 of file MultiNewton.cpp.

◆ setOptions()

void setOptions ( int  maxJacAge = 5)
inline

Set options.

Parameters
maxJacAgeMaximum number of steps that can be taken before requiring a Jacobian update

Definition at line 138 of file MultiNewton.h.

◆ resize()

void resize ( size_t  points)

Change the problem size.

Definition at line 164 of file MultiNewton.cpp.

Member Data Documentation

◆ m_x

vector<double> m_x
protected

Work array holding the system state after the last successful step. Size m_n.

Definition at line 147 of file MultiNewton.h.

◆ m_stp

vector<double> m_stp
protected

Work array holding the undamped Newton step or the system residual. Size m_n.

Definition at line 150 of file MultiNewton.h.

◆ m_stp1

vector<double> m_stp1
protected

Work array holding the damped Newton step. Size m_n.

Definition at line 153 of file MultiNewton.h.

◆ m_maxAge

int m_maxAge = 5
protected

Maximum allowable Jacobian age before it is recomputed.

Definition at line 156 of file MultiNewton.h.

◆ m_dampFactor

double m_dampFactor = sqrt(2.0)
protected

Factor by which the damping coefficient is reduced in each iteration.

Definition at line 159 of file MultiNewton.h.

◆ m_maxDampIter

size_t m_maxDampIter = 7
protected

Maximum number of damping iterations.

Definition at line 162 of file MultiNewton.h.

◆ m_n

size_t m_n
protected

number of variables

Definition at line 165 of file MultiNewton.h.

◆ m_elapsed

double m_elapsed = 0.0
protected

Elapsed CPU time spent computing the Jacobian.

Definition at line 168 of file MultiNewton.h.


The documentation for this class was generated from the following files: