SimpleNewtonNonlinearSolver Class Reference

#include <SimpleNewtonNonlinearSolver.hpp>

Inheritance diagram for SimpleNewtonNonlinearSolver:

Inheritance graph
[legend]
Collaboration diagram for SimpleNewtonNonlinearSolver:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 SimpleNewtonNonlinearSolver (double linearSolverRelativeTolerance=1e-6)
virtual ~SimpleNewtonNonlinearSolver ()
virtual Vec Solve (PetscErrorCode(*pComputeResidual)(SNES, Vec, Vec, void *), PetscErrorCode(*pComputeJacobian)(SNES, Vec, Mat *, Mat *, MatStructure *, void *), Vec initialGuess, unsigned fill, void *pContext)
void SetTolerance (double tolerance)
void SetWriteStats (bool writeStats=true)

Private Attributes

double mLinearSolverRelativeTolerance
double mTolerance
bool mWriteStats
std::vector< double > mTestDampingValues


Detailed Description

A solver class that uses Newton's method with damping.

Definition at line 40 of file SimpleNewtonNonlinearSolver.hpp.


Constructor & Destructor Documentation

SimpleNewtonNonlinearSolver::SimpleNewtonNonlinearSolver ( double  linearSolverRelativeTolerance = 1e-6  ) 

Constructor.

Parameters:
linearSolverRelativeTolerance defaults to 1e-6

Definition at line 35 of file SimpleNewtonNonlinearSolver.cpp.

References mTestDampingValues.

SimpleNewtonNonlinearSolver::~SimpleNewtonNonlinearSolver (  )  [virtual]

Destructor.

Definition at line 49 of file SimpleNewtonNonlinearSolver.cpp.


Member Function Documentation

Vec SimpleNewtonNonlinearSolver::Solve ( PetscErrorCode(*)(SNES, Vec, Vec, void *)  pComputeResidual,
PetscErrorCode(*)(SNES, Vec, Mat *, Mat *, MatStructure *, void *)  pComputeJacobian,
Vec  initialGuess,
unsigned  fill,
void *  pContext 
) [virtual]

Solve()

Solve a nonlinear system using Newton's method with damping. Newton's algorithm is

x_new = x_old - J^{-1} f

where J is the Jacobian matrix evaluated at x_old and f the residual evaluated at x_old. The Newton method with damping is

x_new = x_old - s J^{-1} f

where s is some damping factor. Here s is chosen by just looked at a fixed set of possible damping factors and choosing the one which gives the best x_new (the one for which the residual evaluated at x_new has the lowest norm).

The solver quits once the ||f||/numVariables

Parameters:
pComputeResidual points to the function which computes the residual, it must take arguments SNES (a PETSc nonlinear solver object), Vec (current guess - a vector of the correct size), Vec (a Vec of the correct size in which the residual is returned), void* (a pointer to anything you may need to refer to when calculating the residual)
pComputeJacobian points to the function which computes the Jacobian, it must take arguments SNES (a PETSc nonlinear solver * object), Mat* (a pointer to the Jacobian matrix) ,Mat* (a pointer to a preconditioner matrix), MatStructure* (points to the PETSc matrix type e.g. AIJ), void* (a pointer to anything you may need to refer to when calculating the residual).
initialGuess A PETSc Vec of the correct size, containing initial guesses for the nonlinear solver.
pContext [optional] A pointer to a class that may have to be used in the ComputeResidual and ComputeJacobian functions
fill the expected maximum number of nonzeros in a row of the Jacobian matrix
Returns:
Returns a PETSc Vec of the solution.
To be used in the form: Vec answer=solver->Solve(&ComputeResidual, &ComputeJacobian, initialGuess, NULL);

In the same file, but outside this class the functions ComputeResidual and ComputeJacobian must sit, using the input arguments specified above.

Implements AbstractNonlinearSolver.

Definition at line 52 of file SimpleNewtonNonlinearSolver.cpp.

References EXCEPTION, mTestDampingValues, mTolerance, mWriteStats, LinearSystem::rGetLhsMatrix(), LinearSystem::rGetRhsVector(), LinearSystem::Solve(), and LinearSystem::ZeroLinearSystem().

void SimpleNewtonNonlinearSolver::SetTolerance ( double  tolerance  ) 

Set a tolerance other than the default.

Parameters:
tolerance 

Definition at line 177 of file SimpleNewtonNonlinearSolver.cpp.

References mTolerance.

void SimpleNewtonNonlinearSolver::SetWriteStats ( bool  writeStats = true  )  [inline]

Call to set the solver to write details as it solves.

Parameters:
writeStats defaults to true

Definition at line 128 of file SimpleNewtonNonlinearSolver.hpp.

References mWriteStats.


Member Data Documentation

The linear solver relative tolerance.

Definition at line 43 of file SimpleNewtonNonlinearSolver.hpp.

The tolerance (set to 1e-5 in constructor).

Definition at line 44 of file SimpleNewtonNonlinearSolver.hpp.

Referenced by SetTolerance(), and Solve().

Whether the solver writes details as it solves (set to false in constructor).

Definition at line 45 of file SimpleNewtonNonlinearSolver.hpp.

Referenced by SetWriteStats(), and Solve().

std::vector<double> SimpleNewtonNonlinearSolver::mTestDampingValues [private]

Vector of possible damping factors (set in the constructor).

Definition at line 47 of file SimpleNewtonNonlinearSolver.hpp.

Referenced by SimpleNewtonNonlinearSolver(), and Solve().


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

Generated on Mon Nov 1 12:37:21 2010 for Chaste by  doxygen 1.5.5