Chaste Release::3.1
SimpleNewtonNonlinearSolver Class Reference

#include <SimpleNewtonNonlinearSolver.hpp>

Inheritance diagram for SimpleNewtonNonlinearSolver:
Collaboration diagram for SimpleNewtonNonlinearSolver:

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< doublemTestDampingValues

Detailed Description

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

Definition at line 46 of file SimpleNewtonNonlinearSolver.hpp.


Constructor & Destructor Documentation

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

Constructor.

Parameters:
linearSolverRelativeTolerancedefaults to 1e-6

Definition at line 41 of file SimpleNewtonNonlinearSolver.cpp.

References mTestDampingValues.

SimpleNewtonNonlinearSolver::~SimpleNewtonNonlinearSolver ( ) [virtual]

Destructor.

Definition at line 55 of file SimpleNewtonNonlinearSolver.cpp.


Member Function Documentation

void SimpleNewtonNonlinearSolver::SetTolerance ( double  tolerance)

Set a tolerance other than the default.

Parameters:
tolerance

Definition at line 166 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:
writeStatsdefaults to true

Definition at line 135 of file SimpleNewtonNonlinearSolver.hpp.

References mWriteStats.

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:
pComputeResidualpoints 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)
pComputeJacobianpoints 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).
initialGuessA 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
fillthe 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 58 of file SimpleNewtonNonlinearSolver.cpp.

References PetscVecTools::AddScaledVector(), PetscTools::Destroy(), EXCEPTION, mTestDampingValues, mTolerance, mWriteStats, LinearSystem::rGetLhsMatrix(), LinearSystem::rGetRhsVector(), LinearSystem::Solve(), PetscVecTools::WAXPY(), and LinearSystem::ZeroLinearSystem().


Member Data Documentation

The linear solver relative tolerance.

Definition at line 50 of file SimpleNewtonNonlinearSolver.hpp.

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

Definition at line 54 of file SimpleNewtonNonlinearSolver.hpp.

Referenced by SimpleNewtonNonlinearSolver(), and Solve().

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

Definition at line 51 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 52 of file SimpleNewtonNonlinearSolver.hpp.

Referenced by SetWriteStats(), and Solve().


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