Chaste Release::3.1
|
#include <SimpleNewtonNonlinearSolver.hpp>
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 |
A solver class that uses Newton's method with damping.
Definition at line 46 of file SimpleNewtonNonlinearSolver.hpp.
SimpleNewtonNonlinearSolver::SimpleNewtonNonlinearSolver | ( | double | linearSolverRelativeTolerance = 1e-6 | ) |
Constructor.
linearSolverRelativeTolerance | defaults 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.
void SimpleNewtonNonlinearSolver::SetTolerance | ( | double | tolerance | ) |
Set a tolerance other than the default.
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.
writeStats | defaults 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 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
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 |
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().
The linear solver relative tolerance.
Definition at line 50 of file SimpleNewtonNonlinearSolver.hpp.
std::vector<double> SimpleNewtonNonlinearSolver::mTestDampingValues [private] |
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().
bool SimpleNewtonNonlinearSolver::mWriteStats [private] |
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().