| 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 |
/*! |
| 15 |
* \file nlnml_finelevelnoxinterface.H |
| 16 |
* |
| 17 |
* \class NLNML_finelevelnoxinterface |
| 18 |
* |
| 19 |
* \brief virtual class NLNML_finelevelnoxinterface used by the nonlinear preconditioner |
| 20 |
* |
| 21 |
* \date Last update do Doxygen: 31-Mar-06 |
| 22 |
* |
| 23 |
*/ |
| 24 |
// ML headers |
| 25 |
#include "ml_common.h" |
| 26 |
#include "ml_include.h" |
| 27 |
#include "TrilinosCouplings_config.h" |
| 28 |
|
| 29 |
#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) |
| 30 |
#ifndef NLNML_FINELEVELNOXINTERFACE_H |
| 31 |
#define NLNML_FINELEVELNOXINTERFACE_H |
| 32 |
|
| 33 |
#include <iostream> |
| 34 |
// Epetra headers |
| 35 |
#include "Epetra_Vector.h" |
| 36 |
#include "Epetra_Operator.h" |
| 37 |
#include "Epetra_RowMatrix.h" |
| 38 |
#include "Epetra_CrsGraph.h" |
| 39 |
// NOX interface |
| 40 |
#include "NOX_Epetra_Interface_Jacobian.H" |
| 41 |
#include "NOX_Epetra_Interface_Required.H" |
| 42 |
|
| 43 |
//! NLNML: default namespace for all ML/NOX nonlinear methods |
| 44 |
namespace NLNML |
| 45 |
{ |
| 46 |
|
| 47 |
/*! |
| 48 |
|
| 49 |
\brief Ml_Nox_Fineinterface: a virtual class used by NLNML_Preconditioner |
| 50 |
|
| 51 |
NLNML::NLNML_FineLevelNoxInterface is a pure virtual class that serves as |
| 52 |
an interface between the NLNML_Preconditioner and any application. |
| 53 |
It implements NOX interfaces NOX::Epetra::Interface::Required and |
| 54 |
NOX::EpetraNew::Interface::Jacobian. |
| 55 |
Besides serving as an interface for the nonlinear iteration, it also serves as an |
| 56 |
interface to do finite differencing of Jacobians and as the fine level interface all |
| 57 |
coarser level interfaces refer to. It therefore plays a major role in using |
| 58 |
the NLNML_Preconditioner. |
| 59 |
|
| 60 |
To make use of the full functionality of this class it |
| 61 |
requires ML to be configured with the following options: |
| 62 |
- \c --with-ml_nox |
| 63 |
- \c --enable-epetra |
| 64 |
- \c --enable-epetraext |
| 65 |
- \c --enable-nox |
| 66 |
- \c --enable-nox-epetra |
| 67 |
- \c --enable-prerelease |
| 68 |
- \c --enable-aztecoo |
| 69 |
- \c --enable-amesos |
| 70 |
|
| 71 |
\author Michael Gee, SNL 1414 |
| 72 |
*/ |
| 73 |
class NLNML_FineLevelNoxInterface : public virtual NOX::Epetra::Interface::Required, |
| 74 |
public virtual NOX::Epetra::Interface::Jacobian |
| 75 |
{ |
| 76 |
public: |
| 77 |
|
| 78 |
//! Constructor |
| 79 |
NLNML_FineLevelNoxInterface() |
| 80 |
{ isnewJacobian_=false; numJacobian_=0; printlevel_=0; t_ = 0.; ncalls_computeF_=0; return;} |
| 81 |
|
| 82 |
//! virtual Destructor |
| 83 |
virtual ~NLNML_FineLevelNoxInterface() {} |
| 84 |
|
| 85 |
//! Compute and return F (derived from NOX::Epetra::Interface::Required) |
| 86 |
/*! Compute and return F (derived from NOX::Epetra::Interface::Required). This method is called |
| 87 |
by the nonlinear preconditioner. It supplies a solution vector x and needs a residual vector F computed |
| 88 |
by this funtion on output. |
| 89 |
\param x (In) : current solution vector |
| 90 |
\param F (Out) : residual vector matching x |
| 91 |
\param fillFlag (In) : flag indicating for what purpose this routine was called, see NOX documentation of |
| 92 |
NOX::Epetra::Interface::Required |
| 93 |
*/ |
| 94 |
virtual bool computeF(const Epetra_Vector& x, Epetra_Vector& F, |
| 95 |
const FillType fillFlag) = 0; |
| 96 |
|
| 97 |
//! Compute the current Jacobian (derived from NOX::Epetra::Interface::Jacobian) |
| 98 |
/*! Compute the current Jacobian (derived from NOX::Epetra::Interface::Jacobian). |
| 99 |
This method is called by the nonlinear preconditioner. It supplies a solution vector x and wants |
| 100 |
a Jacobian computed matching this solution vector on output. |
| 101 |
getJacobian will be used to obtain the Jacobian |
| 102 |
\sa getJacobian |
| 103 |
\param x (In) : current solution vector |
| 104 |
\param Jac (In) : the Jacobian to be computed |
| 105 |
*/ |
| 106 |
virtual bool computeJacobian(const Epetra_Vector& x, Epetra_Operator& Jac) = 0; |
| 107 |
|
| 108 |
//! Return the Jacobian from the application. |
| 109 |
/*! Return the Jacobian from the application. The NLNML_Preconditioner uses this |
| 110 |
method to get the jacobian from the application. It will never be used in the matrixfree case. |
| 111 |
\sa NLNML_Preconditioner |
| 112 |
*/ |
| 113 |
virtual Epetra_CrsMatrix* getJacobian() = 0; |
| 114 |
|
| 115 |
//! Return the Graph of the fine level problem from the application. |
| 116 |
/*! Return the Graph of the fine level problem from the application. |
| 117 |
The NLNML_Preconditioner uses this method to get the graph of |
| 118 |
the fine level problem from the application to do finite differencing |
| 119 |
*/ |
| 120 |
virtual const Epetra_CrsGraph* getGraph() = 0; |
| 121 |
|
| 122 |
//! Return the modified Graph of the fine level problem from the application. |
| 123 |
/*! Return a graph that has sufficient modifications to reflect |
| 124 |
constraints that will be applied to the solution and residual. |
| 125 |
See Sandia report for more details |
| 126 |
*/ |
| 127 |
virtual const Epetra_CrsGraph* getModifiedGraph() = 0; |
| 128 |
|
| 129 |
//! Return the current solution from the application. |
| 130 |
/*! Return the current solution from the application. |
| 131 |
The NLNML_Preconditioner uses this method to get the current solution vector of |
| 132 |
the fine level problem from the application. |
| 133 |
*/ |
| 134 |
virtual const Epetra_Vector* getSolution() = 0; |
| 135 |
|
| 136 |
//! Return the Map of the current solution from the application. |
| 137 |
/*! Return the Map of the current solution from the application. |
| 138 |
The NLNML_Preconditioner uses this method to get the map of the current solution vector of |
| 139 |
the fine level problem from the application. |
| 140 |
*/ |
| 141 |
virtual const Epetra_Map& getMap() = 0; |
| 142 |
|
| 143 |
//! Compute and return the Nullspace of the problem from the application. |
| 144 |
/*! Compute and return the Nullspace of the problem from the application. This method is called |
| 145 |
by the nonlinear preconditioner to obtain the Nullspace of the problem from the application. |
| 146 |
If the application returns NULL on exit, the NLNML_Preconditioner will use a default Nullspace of |
| 147 |
correct size (supplied in parameter list) and will assume constant number of dofs per node (constant block size). |
| 148 |
This will lead to errors in the aggregation process if the problem is NOT of constant block size! |
| 149 |
\param nummyrows (In) : dimension of the nullspace vectors |
| 150 |
\param numpde (In) : number of PDEs (normally dofs per node) |
| 151 |
\param dim_nullsp (In) : dimension of the nullspace |
| 152 |
*/ |
| 153 |
virtual double* Get_Nullspace(const int nummyrows, const int numpde, |
| 154 |
const int dim_nullsp) = 0; |
| 155 |
|
| 156 |
// get block information |
| 157 |
//! Compute and return the block node information from the application. |
| 158 |
/*! Compute and return the block node information from the application. This method is called |
| 159 |
by the nonlinear preconditioner to obtain information about non-constant block sizes. It is used |
| 160 |
only in the case of the VBMETIS aggregation scheme. If on exit blocks and block_pde are NULL, the |
| 161 |
NLNML_Preconditioner will assume a constant vblock size and will use METIS instead of the VBMETIS |
| 162 |
aggregation scheme. |
| 163 |
\param nblocks (Out) : on exit, number of variable sized nodal blocks |
| 164 |
\param blocks (Out) : on exit, allocated vector of length NumMyRows containing the block indize |
| 165 |
of each row in C-style numbering (starting with 0) |
| 166 |
\param block_pde (Out) : on exit, allocated vector of length NumMyRows containing the number of |
| 167 |
PDE a certain row belongs to. |
| 168 |
*/ |
| 169 |
virtual bool getBlockInfo(int *nblocks, std::vector<int>& blocks, std::vector<int>& block_pde) = 0; |
| 170 |
|
| 171 |
//! Dummy routine to apply constraints |
| 172 |
/*! If the underlying application needs to apply constraints to the |
| 173 |
gradient computed by the preconditioner this method has to be implemented. |
| 174 |
*/ |
| 175 |
virtual void ApplyAllConstraints(Epetra_Vector& gradient, int level) |
| 176 |
{ return;} |
| 177 |
|
| 178 |
//! Query whether the current Jacobian matches the current solution vector. |
| 179 |
virtual bool isnewJacobian() { return isnewJacobian_; } |
| 180 |
|
| 181 |
//! Query how often the Jacobian has been recomputed. |
| 182 |
virtual int getnumJacobian() { return numJacobian_; } |
| 183 |
|
| 184 |
//! Query the summed time spent in this interface. |
| 185 |
double getsumtime() {return t_;} |
| 186 |
|
| 187 |
//! Reset the summed time spent in this interface |
| 188 |
void resetsumtime() { t_ = 0.; return; } |
| 189 |
|
| 190 |
//! Query the number of calls to the computeF method of this class. |
| 191 |
int getnumcallscomputeF() { return ncalls_computeF_; } |
| 192 |
|
| 193 |
//! Reset the number of calls to the computeF method of this class to a certain value |
| 194 |
bool setnumcallscomputeF(int ncalls) { ncalls_computeF_=ncalls; return true; } |
| 195 |
|
| 196 |
//! Returns the level of output to be generated [ 0 - 10 ] |
| 197 |
inline int OutLevel() { return printlevel_; } |
| 198 |
|
| 199 |
private: |
| 200 |
|
| 201 |
NLNML_FineLevelNoxInterface(NLNML_FineLevelNoxInterface& old); |
| 202 |
|
| 203 |
protected: |
| 204 |
|
| 205 |
bool isnewJacobian_; |
| 206 |
int numJacobian_; |
| 207 |
int printlevel_; |
| 208 |
double t_; |
| 209 |
int ncalls_computeF_; |
| 210 |
|
| 211 |
}; // class NLNML_FineLevelNoxInterface |
| 212 |
} // namespace NLNML |
| 213 |
|
| 214 |
#endif |
| 215 |
#endif |