Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
|
#include <SimpleNewtonNonlinearSolver.hpp>
Public Member Functions | |
SimpleNewtonNonlinearSolver () | |
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) |
Public Member Functions inherited from AbstractNonlinearSolver | |
virtual | ~AbstractNonlinearSolver () |
Private Attributes | |
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 | ( | ) |
Constructor.
Definition at line 41 of file SimpleNewtonNonlinearSolver.cpp.
References mTestDampingValues.
|
virtual |
Destructor.
Definition at line 54 of file SimpleNewtonNonlinearSolver.cpp.
void SimpleNewtonNonlinearSolver::SetTolerance | ( | double | tolerance | ) |
Set a tolerance other than the default.
tolerance |
Definition at line 174 of file SimpleNewtonNonlinearSolver.cpp.
References mTolerance.
|
inline |
Call to set the solver to write details as it solves.
writeStats | defaults to true |
Definition at line 137 of file SimpleNewtonNonlinearSolver.hpp.
References mWriteStats.
|
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 57 of file SimpleNewtonNonlinearSolver.cpp.
References PetscVecTools::AddScaledVector(), PetscTools::Destroy(), EXCEPTION, mTestDampingValues, mTolerance, mWriteStats, LinearSystem::rGetLhsMatrix(), LinearSystem::rGetRhsVector(), LinearSystem::Solve(), PetscVecTools::WAXPY(), and LinearSystem::ZeroLinearSystem().
|
private |
Vector of possible damping factors (set in the constructor).
Definition at line 53 of file SimpleNewtonNonlinearSolver.hpp.
Referenced by SimpleNewtonNonlinearSolver(), and Solve().
|
private |
The tolerance (set to 1e-5 in constructor).
Definition at line 50 of file SimpleNewtonNonlinearSolver.hpp.
Referenced by SetTolerance(), and Solve().
|
private |
Whether the solver writes details as it solves (set to false in constructor).
Definition at line 51 of file SimpleNewtonNonlinearSolver.hpp.
Referenced by SetWriteStats(), and Solve().