NOX Development
Loading...
Searching...
No Matches
Public Member Functions | List of all members
NOX::Petsc::Group Class Reference

Concrete implementation of NOX::Abstract::Group for Petsc. More...

#include <NOX_Petsc_Group.H>

Inheritance diagram for NOX::Petsc::Group:
Inheritance graph
[legend]
Collaboration diagram for NOX::Petsc::Group:
Collaboration graph
[legend]

Public Member Functions

 Group (Interface &i, Vec &x, Mat &J)
 Constructor.
 
 Group (const Group &source, CopyType type=DeepCopy)
 Copy constructor. If type is DeepCopy, takes ownership of valid shared Jacobian.
 
virtual ~Group ()
 Destructor.
 
virtual Abstract::Groupoperator= (const NOX::Abstract::Group &source)
 Copies the source group into this group.
 
virtual Abstract::Groupoperator= (const Group &source)
 See above.
 
"Compute" functions.
virtual void setX (const Vector &y)
 
virtual void setX (const Abstract::Vector &y)
 See above.
 
virtual void computeX (const Group &grp, const Vector &d, double step)
 
virtual void computeX (const Abstract::Group &grp, const Abstract::Vector &d, double step)
 See above.
 
virtual Abstract::Group::ReturnType computeF ()
 Compute and store F(x).
 
virtual Abstract::Group::ReturnType computeJacobian ()
 Compute and store Jacobian.
 
virtual Abstract::Group::ReturnType computeGradient ()
 Compute and store gradient.
 
virtual Abstract::Group::ReturnType computeNewton (Teuchos::ParameterList &params)
 Compute the Newton direction, using parameters for the linear solve.
 
Jacobian operations.

Operations using the Jacobian matrix. These may not be defined in matrix-free scenarios.

virtual Abstract::Group::ReturnType applyJacobian (const Vector &input, Vector &result) const
 
virtual Abstract::Group::ReturnType applyJacobian (const Abstract::Vector &input, Abstract::Vector &result) const
 See above.
 
virtual Abstract::Group::ReturnType applyJacobianTranspose (const Vector &input, Vector &result) const
 
virtual Abstract::Group::ReturnType applyJacobianTranspose (const Abstract::Vector &input, Abstract::Vector &result) const
 See above.
 
virtual Abstract::Group::ReturnType applyRightPreconditioning (const Vector &input, Vector &result) const
 Preconditions a vector using one of the available methods in Petsc.
 
virtual Abstract::Group::ReturnType applyRightPreconditioning (Teuchos::ParameterList &, const Abstract::Vector &input, Abstract::Vector &result) const
 See above.
 
"Is" functions

Checks to see if various objects have been computed. Returns true if the corresponding "compute" function has been called since the last update to the solution vector (via instantiation or computeX).

virtual bool isF () const
 Return true if F is valid.
 
virtual bool isJacobian () const
 Return true if the Jacobian is valid.
 
virtual bool isGradient () const
 Return true if the gradient is valid.
 
virtual bool isNewton () const
 Return true if the Newton direction is valid.
 
virtual bool isPreconditioner () const
 
- Public Member Functions inherited from NOX::Abstract::Group
 Group ()
 Constructor.
 
virtual ~Group ()
 Destructor.
 
virtual NOX::Abstract::Groupoperator= (const NOX::Abstract::Group &source)=0
 Copies the source group into this group.
 
virtual void setX (const NOX::Abstract::Vector &y)=0
 Set the solution vector x to y.
 
virtual void computeX (const NOX::Abstract::Group &grp, const NOX::Abstract::Vector &d, double step)=0
 Compute x = grp.x + step * d.
 
virtual NOX::Abstract::Group::ReturnType computeF ()=0
 Compute and store F(x).
 
virtual NOX::Abstract::Group::ReturnType computeJacobian ()
 Compute and store Jacobian.
 
virtual NOX::Abstract::Group::ReturnType computeGradient ()
 Compute and store gradient.
 
virtual NOX::Abstract::Group::ReturnType computeNewton (Teuchos::ParameterList &params)
 Compute the Newton direction, using parameters for the linear solve.
 
virtual NOX::Abstract::Group::ReturnType applyJacobianInverse (Teuchos::ParameterList &params, const NOX::Abstract::Vector &input, NOX::Abstract::Vector &result) const
 Applies the inverse of the Jacobian matrix to the given input vector and puts the answer in result.
 
virtual NOX::Abstract::Group::ReturnType applyRightPreconditioning (bool useTranspose, Teuchos::ParameterList &params, const NOX::Abstract::Vector &input, NOX::Abstract::Vector &result) const
 Apply right preconditiong to the given input vector.
 
virtual NOX::Abstract::Group::ReturnType applyJacobianMultiVector (const NOX::Abstract::MultiVector &input, NOX::Abstract::MultiVector &result) const
 applyJacobian for multiple right-hand sides
 
virtual NOX::Abstract::Group::ReturnType applyJacobianTransposeMultiVector (const NOX::Abstract::MultiVector &input, NOX::Abstract::MultiVector &result) const
 applyJacobianTranspose for multiple right-hand sides
 
virtual NOX::Abstract::Group::ReturnType applyJacobianInverseMultiVector (Teuchos::ParameterList &params, const NOX::Abstract::MultiVector &input, NOX::Abstract::MultiVector &result) const
 applyJacobianInverse for multiple right-hand sides
 
virtual NOX::Abstract::Group::ReturnType applyRightPreconditioningMultiVector (bool useTranspose, Teuchos::ParameterList &params, const NOX::Abstract::MultiVector &input, NOX::Abstract::MultiVector &result) const
 applyRightPreconditioning for multiple right-hand sides
 
virtual const NOX::Abstract::VectorgetScaledX () const
 
virtual void logLastLinearSolveStats (NOX::SolverStats &stats) const
 Adds statistics from last linear solve to the SovlerStats object.
 
virtual NOX::Abstract::Group::ReturnType getNormLastLinearSolveResidual (double &residual) const
 Return the norm of the last linear solve residual as the result of either a call to computeNewton() or applyJacobianInverse().
 

Protected Attributes

Vectors
Vector xVector
 Solution vector.
 
Vector RHSVector
 Right-hand-side vector (function evaluation).
 
Vector gradVector
 Gradient vector (steepest descent vector).
 
Vector NewtonVector
 Newton direction vector.
 
IsValid flags

True if the current solution is up-to-date with respect to the currect xVector.

bool isValidRHS
 
bool isValidJacobian
 
bool isValidGrad
 
bool isValidNewton
 
bool isValidPreconditioner
 
double normRHS
 Norm of RHS.
 
SharedJacobiansharedJacobianPtr
 Pointer to shared Jacobian matrix.
 
SharedJacobiansharedJacobian
 Reference to shared Jacobian matrix.
 
std::string jacType
 Specification of Jacobian Type.
 
InterfaceuserInterface
 Reference to the user supplied interface functions.
 

"Get" functions

Note that these function do not check whether or not the vectors are valid. Must use the "Is" functions for that purpose.

virtual const Abstract::VectorgetX () const
 Return solution vector.
 
virtual const Abstract::VectorgetF () const
 Return F(x)
 
virtual double getNormF () const
 Return 2-norm of F(x).
 
virtual const Abstract::VectorgetGradient () const
 Return gradient.
 
virtual const Abstract::VectorgetNewton () const
 Return Newton direction.
 
virtual Teuchos::RCP< const Abstract::VectorgetXPtr () const
 Return RCP to solution vector.
 
virtual Teuchos::RCP< const Abstract::VectorgetFPtr () const
 Return RCP to F(x)
 
virtual Teuchos::RCP< const Abstract::VectorgetGradientPtr () const
 Return RCP to gradient.
 
virtual Teuchos::RCP< const Abstract::VectorgetNewtonPtr () const
 Return RCP to Newton direction.
 
virtual Teuchos::RCP< NOX::Abstract::Groupclone (CopyType type=DeepCopy) const
 Create a new Group of the same derived type as this one by cloning this one, and return a ref count pointer to the new group.
 
virtual void resetIsValid ()
 resets the isValid flags to false
 

Additional Inherited Members

- Public Types inherited from NOX::Abstract::Group
enum  ReturnType {
  Ok , NotDefined , BadDependency , NotConverged ,
  Failed
}
 The computation of, say, the Newton direction in computeNewton() may fail in many different ways, so we have included a variety of return codes to describe the failures. Of course, we also have a code for success. More...
 

Detailed Description

Concrete implementation of NOX::Abstract::Group for Petsc.

Constructor & Destructor Documentation

◆ ~Group()

Group::~Group ( )
virtual

Destructor.

Reimplemented from NOX::Abstract::Group.

References sharedJacobianPtr.

Member Function Documentation

◆ applyJacobian()

Abstract::Group::ReturnType Group::applyJacobian ( const Abstract::Vector input,
Abstract::Vector result 
) const
virtual

See above.

Reimplemented from NOX::Abstract::Group.

◆ applyJacobianTranspose()

Abstract::Group::ReturnType Group::applyJacobianTranspose ( const Abstract::Vector input,
Abstract::Vector result 
) const
virtual

See above.

Reimplemented from NOX::Abstract::Group.

◆ applyRightPreconditioning()

Abstract::Group::ReturnType Group::applyRightPreconditioning ( const Vector input,
Vector result 
) const
virtual

Preconditions a vector using one of the available methods in Petsc.

Currently, the preconditioning method corresponds to whatever is available in the user's Petsc installation and is specified in the local .petscrc file. For example, a direct solve can be accomplished by specifying -pc_type lu (serial only), whereas diagonal scaling can be achieved via -pc_type jacobi.

References NOX::Abstract::Group::BadDependency, NOX::Petsc::SharedJacobian::getJacobian(), NOX::Petsc::Vector::getPetscVector(), isJacobian(), NOX::Abstract::Group::Ok, and sharedJacobian.

Referenced by applyRightPreconditioning().

◆ clone()

Teuchos::RCP< NOX::Abstract::Group > Group::clone ( CopyType  type = DeepCopy) const
virtual

Create a new Group of the same derived type as this one by cloning this one, and return a ref count pointer to the new group.

If type is NOX::DeepCopy, then we need to create an exact replica of "this". Otherwise, if type is NOX::ShapeCopy, we need only replicate the shape of "this" (only the memory is allocated, the values are not copied into the vectors and Jacobian). Returns NULL if clone is not supported.

Note
Any shared data should have its ownership transfered to this group from the source for a NOX::DeepCopy.

Implements NOX::Abstract::Group.

◆ computeF()

Abstract::Group::ReturnType Group::computeF ( )
virtual

Compute and store F(x).

Note
It's generally useful to also compute and store the 2-norm of F(x) at this point for later access by the getNormF() function.
Returns

Implements NOX::Abstract::Group.

References NOX::Petsc::Interface::computeF(), NOX::Petsc::Vector::getPetscVector(), isF(), NOX::Petsc::Vector::norm(), normRHS, NOX::Abstract::Group::Ok, RHSVector, userInterface, and xVector.

◆ computeGradient()

Abstract::Group::ReturnType Group::computeGradient ( )
virtual

Compute and store gradient.

We can pose the nonlinear equation problem $ F(x) = 0$ as an optimization problem as follows:

\[
\min f(x) \equiv \frac{1}{2} \|F(x)\|_2^2.
\]

In that case, the gradient (of $ f$) is defined as

\[
g \equiv J^T F.
\]

Returns

Reimplemented from NOX::Abstract::Group.

References NOX::Petsc::SharedJacobian::getJacobian(), NOX::Petsc::Vector::getPetscVector(), gradVector, isF(), isGradient(), isJacobian(), NOX::Abstract::Group::Ok, RHSVector, and sharedJacobian.

◆ computeJacobian()

Abstract::Group::ReturnType Group::computeJacobian ( )
virtual

Compute and store Jacobian.

Recall that

\[
F(x) = \left[ \begin{array}{c} F_1(x) \\ F_2(x) \\ \vdots \\ F_n(x) \\ \end{array} \right].
\]

The Jacobian is denoted by $ J$ and defined by

\[
J_{ij} = \frac{\partial F_i}{\partial x_j} (x).
\]

Note
If this is a shared object, this group should take ownership of the Jacobian before it computes it.
Returns

Reimplemented from NOX::Abstract::Group.

References NOX::Petsc::Interface::computeJacobian(), NOX::Petsc::SharedJacobian::getJacobian(), NOX::Petsc::Vector::getPetscVector(), isJacobian(), jacType, NOX::Abstract::Group::Ok, sharedJacobian, userInterface, and xVector.

◆ computeNewton()

Abstract::Group::ReturnType Group::computeNewton ( Teuchos::ParameterList &  params)
virtual

Compute the Newton direction, using parameters for the linear solve.

The Newton direction is the solution, s, of

\[
J s = -F.
\]

The parameters are from the "Linear %Solver" sublist of the "Direction" sublist that is passed to solver during construction.

The "Tolerance" parameter may be added/modified in the sublist of "Linear Solver" parameters that is passed into this function. The solution should be such that

\[
\frac{\| J s - (-F) \|_2}{\max \{ 1, \|F\|_2\} } < \mbox{Tolerance}
\]

Returns

Reimplemented from NOX::Abstract::Group.

References NOX::Petsc::SharedJacobian::getJacobian(), NOX::Petsc::Vector::getPetscVector(), isF(), isJacobian(), isNewton(), NewtonVector, NOX::Abstract::Group::Ok, RHSVector, NOX::Petsc::Vector::scale(), and sharedJacobian.

◆ computeX()

void Group::computeX ( const Abstract::Group grp,
const Abstract::Vector d,
double  step 
)
virtual

See above.

Implements NOX::Abstract::Group.

◆ getF()

const Abstract::Vector & Group::getF ( ) const
virtual

Return F(x)

Implements NOX::Abstract::Group.

References isF(), and RHSVector.

◆ getFPtr()

Teuchos::RCP< const Abstract::Vector > Group::getFPtr ( ) const
virtual

Return RCP to F(x)

Implements NOX::Abstract::Group.

References isF(), and RHSVector.

◆ getGradient()

const Abstract::Vector & Group::getGradient ( ) const
virtual

Return gradient.

Implements NOX::Abstract::Group.

References gradVector, and isGradient().

◆ getGradientPtr()

Teuchos::RCP< const Abstract::Vector > Group::getGradientPtr ( ) const
virtual

Return RCP to gradient.

Implements NOX::Abstract::Group.

References gradVector, and isGradient().

◆ getNewton()

const Abstract::Vector & Group::getNewton ( ) const
virtual

Return Newton direction.

Implements NOX::Abstract::Group.

References isNewton(), and NewtonVector.

◆ getNewtonPtr()

Teuchos::RCP< const Abstract::Vector > Group::getNewtonPtr ( ) const
virtual

Return RCP to Newton direction.

Implements NOX::Abstract::Group.

References isNewton(), and NewtonVector.

◆ getNormF()

double Group::getNormF ( ) const
virtual

Return 2-norm of F(x).

In other words,

\[ \sqrt{\sum_{i=1}^n F_i^2} \]

Implements NOX::Abstract::Group.

References isF(), and normRHS.

◆ getX()

const Abstract::Vector & Group::getX ( ) const
virtual

Return solution vector.

Implements NOX::Abstract::Group.

References xVector.

◆ getXPtr()

Teuchos::RCP< const Abstract::Vector > Group::getXPtr ( ) const
virtual

Return RCP to solution vector.

Implements NOX::Abstract::Group.

References xVector.

◆ isF()

bool Group::isF ( ) const
virtual

Return true if F is valid.

Implements NOX::Abstract::Group.

Referenced by computeF(), computeGradient(), computeNewton(), getF(), getFPtr(), and getNormF().

◆ isGradient()

bool Group::isGradient ( ) const
virtual

Return true if the gradient is valid.

Note
Default implementation in NOX::Abstract::Group returns false.

Reimplemented from NOX::Abstract::Group.

Referenced by computeGradient(), getGradient(), and getGradientPtr().

◆ isJacobian()

bool Group::isJacobian ( ) const
virtual

Return true if the Jacobian is valid.

Note
Default implementation in NOX::Abstract::Group returns false.

Reimplemented from NOX::Abstract::Group.

References NOX::Petsc::SharedJacobian::isOwner(), and sharedJacobian.

Referenced by applyRightPreconditioning(), computeGradient(), computeJacobian(), and computeNewton().

◆ isNewton()

bool Group::isNewton ( ) const
virtual

Return true if the Newton direction is valid.

Note
Default implementation in NOX::Abstract::Group returns false.

Reimplemented from NOX::Abstract::Group.

Referenced by computeNewton(), getNewton(), and getNewtonPtr().

◆ operator=()

Abstract::Group & Group::operator= ( const NOX::Abstract::Group source)
virtual

Copies the source group into this group.

Note
Any shared data owned by the source should have its ownership transfered to this group. This may result in a secret modification to the source object.

Implements NOX::Abstract::Group.

References operator=().

Referenced by operator=().

◆ setX()

void Group::setX ( const Abstract::Vector y)
virtual

See above.

Implements NOX::Abstract::Group.


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