Newton iterator for multi-domain, one-dimensional problems. More...
#include <MultiNewton.h>
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 | |
MultiNewton & | operator= (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. | |
MultiNewton | ( | int | sz | ) |
Constructor.
sz | Number of variables in the system |
Definition at line 159 of file MultiNewton.cpp.
|
inlinevirtual |
Definition at line 29 of file MultiNewton.h.
|
inline |
Get the number of variables in the system.
Definition at line 34 of file MultiNewton.h.
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.
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.
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}) \).
[in] | x0 | initial solution about which a Newton step will be taken |
[in] | step0 | initial undamped Newton step |
[out] | x1 | solution after taking the damped Newton step |
[out] | step1 | Newton step after taking the damped Newton step |
[out] | s1 | norm of the subsequent Newton step after taking the damped Newton step |
[in] | r | domain object, used for evaluating residuals over all domains |
[in] | jac | Jacobian evaluator |
[in] | loglevel | controls amount of printed diagnostics |
[in] | writetitle | controls if logging title is printed |
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.
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.
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.
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.
|
inline |
Set options.
maxJacAge | Maximum number of steps that can be taken before requiring a Jacobian update |
Definition at line 138 of file MultiNewton.h.
void resize | ( | size_t | points | ) |
Change the problem size.
Definition at line 164 of file MultiNewton.cpp.
|
protected |
Work array holding the system state after the last successful step. Size m_n.
Definition at line 147 of file MultiNewton.h.
|
protected |
Work array holding the undamped Newton step or the system residual. Size m_n.
Definition at line 150 of file MultiNewton.h.
|
protected |
Work array holding the damped Newton step. Size m_n.
Definition at line 153 of file MultiNewton.h.
|
protected |
Maximum allowable Jacobian age before it is recomputed.
Definition at line 156 of file MultiNewton.h.
|
protected |
Factor by which the damping coefficient is reduced in each iteration.
Definition at line 159 of file MultiNewton.h.
|
protected |
Maximum number of damping iterations.
Definition at line 162 of file MultiNewton.h.
|
protected |
number of variables
Definition at line 165 of file MultiNewton.h.
|
protected |
Elapsed CPU time spent computing the Jacobian.
Definition at line 168 of file MultiNewton.h.