| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Trilinos: An Object-Oriented Solver Framework |
| 4 |
// |
| 5 |
// Copyright 2001-2024 NTESS and the Trilinos contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
/* ******************************************************************** */ |
| 11 |
/* See the file COPYRIGHT for a complete copyright notice, contact */ |
| 12 |
/* person and disclaimer. */ |
| 13 |
/* ******************************************************************** */ |
| 14 |
// ML-headers |
| 15 |
#include "ml_common.h" |
| 16 |
#include "TrilinosCouplings_config.h" |
| 17 |
|
| 18 |
#if defined(HAVE_ML_NOX) && defined(HAVE_ML_EPETRA) && defined(HAVE_ML_AZTECOO) && defined(HAVE_ML_TEUCHOS) && defined(HAVE_ML_IFPACK) && defined(HAVE_ML_AMESOS) && defined(HAVE_ML_EPETRAEXT) |
| 19 |
|
| 20 |
#ifndef ML_NOX_LINEARSYSTEM_H |
| 21 |
#define ML_NOX_LINEARSYSTEM_H |
| 22 |
|
| 23 |
// NOX |
| 24 |
#include "NOX_Epetra_Vector.H" |
| 25 |
#include "NOX_Utils.H" |
| 26 |
#include "NOX_Common.H" |
| 27 |
#include "NOX_EpetraNew_LinearSystem.H" |
| 28 |
#include "NOX_EpetraNew_MatrixFree.H" |
| 29 |
#include "NOX_EpetraNew_Interface_Jacobian.H" |
| 30 |
#include "NOX_EpetraNew_Interface_Preconditioner.H" |
| 31 |
#include "NOX_EpetraNew_Interface_Required.H" |
| 32 |
|
| 33 |
// Epetra |
| 34 |
#include "Epetra_MultiVector.h" |
| 35 |
#include "Epetra_Vector.h" |
| 36 |
|
| 37 |
#include "ml_nox_coarseinterface.H" |
| 38 |
|
| 39 |
// Forward declares |
| 40 |
namespace NOX { |
| 41 |
namespace EpetraNew { |
| 42 |
class Scaling; |
| 43 |
} |
| 44 |
namespace Parameter { |
| 45 |
class List; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
class Epetra_Vector; |
| 51 |
class Epetra_Operator; |
| 52 |
class Epetra_MultiVector; |
| 53 |
class Epetra_Vector; |
| 54 |
|
| 55 |
namespace ML_NOX { |
| 56 |
|
| 57 |
// a linear system class to work with NOX' nlnCG, not a full impl. of a linear system! |
| 58 |
class Ml_Nox_LinearSystem : public virtual NOX::EpetraNew::LinearSystem |
| 59 |
{ |
| 60 |
|
| 61 |
public: |
| 62 |
//! Constructor. |
| 63 |
Ml_Nox_LinearSystem(NOX::EpetraNew::Interface::Jacobian& iJac, |
| 64 |
Epetra_Operator& J, |
| 65 |
NOX::EpetraNew::Interface::Preconditioner& iPrec, |
| 66 |
ML_NOX::Nox_CoarseProblem_Interface* coarseinterface, |
| 67 |
Epetra_Operator& Prec, |
| 68 |
const Epetra_Vector& soln, |
| 69 |
bool ismatrixfree, |
| 70 |
int level, |
| 71 |
int printlevel); |
| 72 |
|
| 73 |
//! Destructor. |
| 74 |
virtual ~Ml_Nox_LinearSystem(); |
| 75 |
|
| 76 |
/*! |
| 77 |
\brief Applies Jacobian to the given input vector and puts the answer in the result. |
| 78 |
|
| 79 |
Computes |
| 80 |
\f[ v = J u, \f] |
| 81 |
where \f$J\f$ is the Jacobian, \f$u\f$ is the input vector, |
| 82 |
and \f$v\f$ is the result vector. Returns true if successful. |
| 83 |
*/ |
| 84 |
virtual bool applyJacobian(const NOX::Epetra::Vector& input, |
| 85 |
NOX::Epetra::Vector& result) const ; |
| 86 |
|
| 87 |
/*! |
| 88 |
\brief Applies Jacobian-Transpose to the given input vector and puts the answer in the result. |
| 89 |
|
| 90 |
Computes |
| 91 |
\f[ v = J^T u, \f] |
| 92 |
where \f$J\f$ is the Jacobian, \f$u\f$ is the input vector, and \f$v\f$ is the result vector. Returns true if successful. |
| 93 |
|
| 94 |
*/ |
| 95 |
virtual bool applyJacobianTranspose(const NOX::Epetra::Vector& input, |
| 96 |
NOX::Epetra::Vector& result) const; |
| 97 |
|
| 98 |
/*! |
| 99 |
\brief Applies the inverse of the Jacobian matrix to the given |
| 100 |
input vector and puts the answer in result. |
| 101 |
|
| 102 |
Computes |
| 103 |
\f[ v = J^{-1} u, \f] |
| 104 |
where \f$J\f$ is the Jacobian, \f$u\f$ is the input vector, |
| 105 |
and \f$v\f$ is the result vector. |
| 106 |
|
| 107 |
The parameter list contains the linear solver options. |
| 108 |
*/ |
| 109 |
virtual bool applyJacobianInverse(NOX::Parameter::List ¶ms, |
| 110 |
const NOX::Epetra::Vector &input, |
| 111 |
NOX::Epetra::Vector &result); |
| 112 |
|
| 113 |
/*! |
| 114 |
\brief Apply right preconditiong to the given input vector |
| 115 |
|
| 116 |
Let \f$M\f$ be a right preconditioner for the Jacobian \f$J\f$; in |
| 117 |
other words, \f$M\f$ is a matrix such that |
| 118 |
\f[ JM \approx I. \f] |
| 119 |
|
| 120 |
Compute |
| 121 |
\f[ u = M^{-1} v, \f] |
| 122 |
where \f$u\f$ is the input vector and \f$v\f$ is the result vector. |
| 123 |
|
| 124 |
If <em>useTranspose</em> is true, then the transpose of the |
| 125 |
preconditioner is applied: |
| 126 |
\f[ u = {M^{-1}}^T v, \f] |
| 127 |
The transpose preconditioner is currently only required for |
| 128 |
Tensor methods. |
| 129 |
|
| 130 |
The parameter list contains the linear solver options. |
| 131 |
*/ |
| 132 |
virtual bool applyRightPreconditioning(bool useTranspose, |
| 133 |
NOX::Parameter::List& params, |
| 134 |
const NOX::Epetra::Vector& input, |
| 135 |
NOX::Epetra::Vector& result) const; |
| 136 |
|
| 137 |
/*! |
| 138 |
\brief Sets the diagonal scaling vector(s) used in scaling the linear system. |
| 139 |
|
| 140 |
See NOX::EpetraNew::Scaling for details on how to specify scaling |
| 141 |
of the linear system. |
| 142 |
*/ |
| 143 |
virtual void resetScaling(NOX::EpetraNew::Scaling& scalingObject); |
| 144 |
|
| 145 |
//! Evaluates the Jacobian based on the solution vector x. |
| 146 |
virtual bool computeJacobian(Epetra_Vector& x); |
| 147 |
|
| 148 |
/*! |
| 149 |
\brief Explicitly constructs a preconditioner based on the solution vector x and the parameter list p. |
| 150 |
|
| 151 |
The user has the option of recomputing the graph when a new |
| 152 |
preconditioner is created. The NOX::EpetraNew::Group controls the |
| 153 |
isValid flag for the preconditioner and will control when to call this. |
| 154 |
*/ |
| 155 |
virtual bool createPreconditioner(Epetra_Vector& x, |
| 156 |
NOX::Parameter::List& p, |
| 157 |
bool recomputeGraph) const; |
| 158 |
|
| 159 |
/*! |
| 160 |
\brief Deletes the preconditioner. |
| 161 |
|
| 162 |
The NOX::EpetraNew::Group controls the isValid flag for the preconditioner and will control when to call this. |
| 163 |
*/ |
| 164 |
virtual bool destroyPreconditioner() const ; |
| 165 |
|
| 166 |
/*! |
| 167 |
\brief Allows reuse of a preconditioner, which is handled separately by the ML_Nox_Preconditioner |
| 168 |
|
| 169 |
The child object will manage setting of this bool flag. Default implementation is to return false. |
| 170 |
*/ |
| 171 |
virtual bool checkPreconditionerReuse() |
| 172 |
{ return false; } |
| 173 |
|
| 174 |
//! Return Jacobian operator |
| 175 |
virtual const Epetra_Operator& getJacobianOperator() const ; |
| 176 |
|
| 177 |
//! Return Jacobian operator |
| 178 |
virtual Epetra_Operator& getJacobianOperator(); |
| 179 |
|
| 180 |
//! Return preconditioner operator |
| 181 |
virtual const Epetra_Operator& getGeneratedPrecOperator() const; |
| 182 |
|
| 183 |
//! Return preconditioner operator |
| 184 |
virtual Epetra_Operator& getGeneratedPrecOperator(); |
| 185 |
|
| 186 |
//! Set Jacobian operator for solve |
| 187 |
virtual void |
| 188 |
setJacobianOperatorForSolve(const Epetra_Operator& solveJacOp); |
| 189 |
|
| 190 |
//! Set preconditioner operator for solve |
| 191 |
virtual void |
| 192 |
setPrecOperatorForSolve(const Epetra_Operator& solvePrecOp); |
| 193 |
|
| 194 |
private: |
| 195 |
|
| 196 |
// the Jacobian interface, referring to either the interface or |
| 197 |
// referring to the NOX::EpetraNew::MatrixFree operator that |
| 198 |
// implements an NOX::EpetraNew::Interface::Jacobian |
| 199 |
NOX::EpetraNew::Interface::Jacobian& iJac_; |
| 200 |
|
| 201 |
// the Jacobian, either an Epetra_RowMatrix from the interface |
| 202 |
// or an NOX::EpetraNew::MatrixFree operator |
| 203 |
Epetra_Operator& J_; |
| 204 |
|
| 205 |
// interface referring to the ML_Nox_Preconditioner that implements |
| 206 |
// a NOX::EpetraNew::Interface::Preconditioner and |
| 207 |
// a Epetra_Operator |
| 208 |
NOX::EpetraNew::Interface::Preconditioner& iPrec_; |
| 209 |
|
| 210 |
// the ML_Nox_Preconditioner |
| 211 |
Epetra_Operator* Precptr_; |
| 212 |
|
| 213 |
// the current solution vector |
| 214 |
const Epetra_Vector& soln_; |
| 215 |
|
| 216 |
// the level this linearsystem lives on |
| 217 |
int level_; |
| 218 |
|
| 219 |
// indicates wether Jacobian is NOX::EpetraNew::MatrixFree operator |
| 220 |
// or Epetra_RowMatrix from the interface |
| 221 |
bool ismatrixfree_; |
| 222 |
|
| 223 |
// indicator for output level (0-10) |
| 224 |
int printlevel_; |
| 225 |
|
| 226 |
// a coarse grid interface |
| 227 |
ML_NOX::Nox_CoarseProblem_Interface* coarseinterface_; |
| 228 |
|
| 229 |
}; |
| 230 |
|
| 231 |
} // namespace ML_NOX |
| 232 |
|
| 233 |
|
| 234 |
#endif // ML_NOX_LINEARSYSTEM_H |
| 235 |
#endif // defined(HAVE_ML_NOX) && defined(HAVE_ML_EPETRA) |