| 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 ml_nox_fineinterface.H |
| 16 |
* |
| 17 |
* \class Ml_Nox_Fineinterface |
| 18 |
* |
| 19 |
* \brief virtual class Ml_Nox_Fineinterface used by ML_Nox_Preconditioner |
| 20 |
* |
| 21 |
* \date Last update do Doxygen: 31-Mar-05 |
| 22 |
* |
| 23 |
*/ |
| 24 |
#include "TrilinosCouplings_config.h" |
| 25 |
|
| 26 |
#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) |
| 27 |
|
| 28 |
#ifndef ML_NOX_FINEINTERFACE_H |
| 29 |
#define ML_NOX_FINEINTERFACE_H |
| 30 |
|
| 31 |
#include <iostream> |
| 32 |
// ML headers |
| 33 |
#include "ml_common.h" |
| 34 |
#include "ml_include.h" |
| 35 |
// Epetra headers |
| 36 |
#include "Epetra_Vector.h" |
| 37 |
#include "Epetra_Operator.h" |
| 38 |
#include "Epetra_RowMatrix.h" |
| 39 |
#include "Epetra_CrsGraph.h" |
| 40 |
// NOX interfaces |
| 41 |
#include "NOX_EpetraNew_Interface_Required.H" |
| 42 |
#include "NOX_EpetraNew_Interface_Jacobian.H" |
| 43 |
#include "NOX_EpetraNew_Interface_Preconditioner.H" |
| 44 |
#include "NOX_Parameter_PrePostOperator.H" |
| 45 |
|
| 46 |
//! ML_NOX: default namespace for all ML/NOX nonlinear methods |
| 47 |
namespace ML_NOX |
| 48 |
{ |
| 49 |
/*! |
| 50 |
|
| 51 |
\brief Ml_Nox_Fineinterface: a virtual class used by ML_Nox_Preconditioner |
| 52 |
|
| 53 |
ML_NOX::Ml_Nox_Fineinterface is a pure virtual class that serves as |
| 54 |
an interface between the ML_Nox_Preconditioner and any application. |
| 55 |
It implements all three NOX interfaces NOX::EpetraNew::Interface::Required, |
| 56 |
NOX::EpetraNew::Interface::Jacobian and NOX::EpetraNew::Interface::Preconditioner. |
| 57 |
Besides serving as an interface for the nonlinear iteration, it also serves as an |
| 58 |
interface to do finite differencing of Jacobians and as the fine level interface all |
| 59 |
coarser level interfaces refer to. It therefore plays a major role in using |
| 60 |
the ML_Nox_Preconditioner. |
| 61 |
|
| 62 |
To make use of the full functionality of this class it |
| 63 |
requires ML to be configured with the following options: |
| 64 |
- \c --with-ml_nox |
| 65 |
- \c --enable-epetra |
| 66 |
- \c --enable-epetraext |
| 67 |
- \c --enable-nox |
| 68 |
- \c --enable-nox-epetra |
| 69 |
- \c --enable-prerelease |
| 70 |
- \c --enable-aztecoo |
| 71 |
- \c --enable-amesos |
| 72 |
|
| 73 |
\note |
| 74 |
Currently, using this class makes it necessary to configure and make install |
| 75 |
of Trilinos WITHOUT the --with-ml_nox, and then repeating the configure |
| 76 |
and make install process WITH the --with-ml_nox option to be able to resolve the |
| 77 |
dependencies of this class on NOX header files |
| 78 |
|
| 79 |
\author Michael Gee, SNL 9214 |
| 80 |
*/ |
| 81 |
class Ml_Nox_Fineinterface : public virtual NOX::EpetraNew::Interface::Required, |
| 82 |
public virtual NOX::EpetraNew::Interface::Jacobian, |
| 83 |
public virtual NOX::EpetraNew::Interface::Preconditioner, |
| 84 |
public virtual NOX::Parameter::PrePostOperator |
| 85 |
|
| 86 |
{ |
| 87 |
public: |
| 88 |
|
| 89 |
//! Constructor |
| 90 |
/*! Constructor |
| 91 |
*/ |
| 92 |
Ml_Nox_Fineinterface() |
| 93 |
{ isnewJacobian_=false; numJacobian_=0; printlevel_=10; t_ = 0.; ncalls_computeF_=0; return;} |
| 94 |
|
| 95 |
//! virtual Constructor |
| 96 |
/*! virtual Constructor |
| 97 |
*/ |
| 98 |
virtual ~Ml_Nox_Fineinterface() {}; |
| 99 |
|
| 100 |
//! Compute and return F (derived from NOX::EpetraNew::Interface::Required) |
| 101 |
/*! Compute and return F (derived from NOX::EpetraNew::Interface::Required). This method is called |
| 102 |
by the nonlinear preconditioner. It supplies a solution vector x and needs a residual vector F computed |
| 103 |
by this funtion on output. |
| 104 |
\param x (In) : current solution vector |
| 105 |
\param F (Out) : residual vector matching x |
| 106 |
\param fillFlag (In) : flag indicating for what purpose this routine was called, see NOX documentation of |
| 107 |
NOX::EpetraNew::Interface::Required |
| 108 |
*/ |
| 109 |
virtual bool computeF(const Epetra_Vector& x, Epetra_Vector& F, const FillType fillFlag) = 0; |
| 110 |
|
| 111 |
//! Compute the current Jacobian (derived from NOX::EpetraNew::Interface::Jacobian) |
| 112 |
/*! Compute the current Jacobian (derived from NOX::EpetraNew::Interface::Jacobian). |
| 113 |
This method is called by the nonlinear preconditioner. It supplies a solution vector x and wants |
| 114 |
a Jacobian computed matching this solution vector on output. |
| 115 |
getJacobian will be used to obtain the Jacobian |
| 116 |
\sa getJacobian |
| 117 |
\param x (In) : current solution vector |
| 118 |
*/ |
| 119 |
virtual bool computeJacobian(const Epetra_Vector& x) = 0; |
| 120 |
|
| 121 |
// Compute Preconditioner (derived from NOX::EpetraNew::Interface::Preconditioner) |
| 122 |
//! Compute the current Preconditioner (derived from NOX::EpetraNew::Interface::Preconditioner) |
| 123 |
/*! FIXME: just found out that this interface is never used by ML_Nox_Preconditioner, |
| 124 |
as ML_Nox_Preconditioner implements it's own NOX::EpetraNew::Interface::Preconditioner. |
| 125 |
delete this? |
| 126 |
*/ |
| 127 |
virtual bool computePreconditioner(const Epetra_Vector& x, |
| 128 |
NOX::Parameter::List* precParams = 0) = 0; |
| 129 |
|
| 130 |
//! Return the Jacobian from the application. |
| 131 |
/*! Return the Jacobian from the application. The ML_Nox_Preconditioner uses this |
| 132 |
method to get the jacobian from the application. It will never be used in the matrixfree case. |
| 133 |
\sa ML_Nox_Preconditioner |
| 134 |
*/ |
| 135 |
virtual Epetra_CrsMatrix* getJacobian() = 0; |
| 136 |
|
| 137 |
// return the graph from the problem |
| 138 |
// Return the Graph of the fine level problem from the application. |
| 139 |
//! Return the Graph of the fine level problem from the application. |
| 140 |
/*! Return the Graph of the fine level problem from the application. |
| 141 |
The ML_Nox_Preconditioner uses this method to get the graph of |
| 142 |
the fine level problem from the application. |
| 143 |
*/ |
| 144 |
virtual const Epetra_CrsGraph* getGraph() = 0; |
| 145 |
virtual const Epetra_CrsGraph* getModifiedGraph() = 0; |
| 146 |
|
| 147 |
//! Return the current solution from the application. |
| 148 |
/*! Return the current solution from the application. |
| 149 |
The ML_Nox_Preconditioner uses this method to get the current solution vector of |
| 150 |
the fine level problem from the application. |
| 151 |
*/ |
| 152 |
virtual const Epetra_Vector* getSolution() = 0; |
| 153 |
|
| 154 |
//! Return the Map of the current solution from the application. |
| 155 |
/*! Return the Map of the current solution from the application. |
| 156 |
The ML_Nox_Preconditioner uses this method to get the map of the current solution vector of |
| 157 |
the fine level problem from the application. |
| 158 |
*/ |
| 159 |
virtual const Epetra_Map& getMap() = 0; |
| 160 |
|
| 161 |
//! Query whether the current Jacobian matches the current solution vector. |
| 162 |
/*! Query whether the current Jacobian matches the current solution vector. |
| 163 |
*/ |
| 164 |
virtual bool isnewJacobian() { return isnewJacobian_; } |
| 165 |
|
| 166 |
//! Query how often the Jacobian has been recomputed. |
| 167 |
/*! Query how often the Jacobian has been recomputed. |
| 168 |
*/ |
| 169 |
virtual int getnumJacobian() { return numJacobian_; } |
| 170 |
|
| 171 |
//! Compute and return the Nullspace of the problem from the application. |
| 172 |
/*! Compute and return the Nullspace of the problem from the application. This method is called |
| 173 |
by the nonlinear preconditioner to obtain the Nullspace of the problem from the application. |
| 174 |
If the application returns NULL on exit, the ML_Nox_Preconditioner will use a default Nullspace of |
| 175 |
correct size (given by dim_nullsp) and will assume constant number of dofs per node (constant block size). |
| 176 |
This will lead to errors in the aggregation process if the problem is NOT of constant block size! |
| 177 |
\param nummyrows (In) : dimension of the nullspace vectors |
| 178 |
\param numpde (In) : number of PDEs (normally dofs per node) |
| 179 |
\param dim_nullsp (In) : dimension of the nullspace |
| 180 |
*/ |
| 181 |
virtual double* Get_Nullspace(const int nummyrows, const int numpde, |
| 182 |
const int dim_nullsp) = 0; |
| 183 |
|
| 184 |
|
| 185 |
// Apply constraints |
| 186 |
virtual void ApplyAllConstraints(Epetra_Vector& gradient, int level) |
| 187 |
{ return;} |
| 188 |
|
| 189 |
// get block information |
| 190 |
//! Compute and return the block node information from the application. |
| 191 |
/*! Compute and return the block node information from the application. This method is called |
| 192 |
by the nonlinear preconditioner to obtain information about non-constant block sizes. It is used |
| 193 |
only in the case of the VBMETIS aggregation scheme. If on exit blocks and block_pde are NULL, the |
| 194 |
ML_Nox_Preconditioner will assume a constant vblock size and will use METIS instead of the VBMETIS |
| 195 |
aggregation scheme. |
| 196 |
\param nblocks (Out) : on exit, number of variable sized nodal blocks |
| 197 |
\param blocks (Out) : on exit, allocated vector of length NumMyRows containing the block indize |
| 198 |
of each row in C-style numbering (starting with 0) |
| 199 |
\param block_pde (Out) : on exit, allocated vector of length NumMyRows containing the number of |
| 200 |
PDE a certain row belongs to. |
| 201 |
*/ |
| 202 |
virtual bool getBlockInfo(int *nblocks, int** blocks, int **block_pde) = 0; |
| 203 |
|
| 204 |
//! Query the summed time spent in this interface. |
| 205 |
/*! Query the summed time spent in this interface. This is for performance analysis. |
| 206 |
*/ |
| 207 |
double getsumtime() {return t_;} |
| 208 |
|
| 209 |
//! Reset the summed time spent in this interface to a certain value. |
| 210 |
/*! Reset the summed time spent in this interface to a certain value. |
| 211 |
This is for performance analysis. |
| 212 |
*/ |
| 213 |
void resetsumtime() { t_ = 0.; return; } |
| 214 |
|
| 215 |
//! Query the number of calls to the computeF method of this class. |
| 216 |
/*! Query the number of calls to the computeF method of this class. This is for performance analysis. |
| 217 |
*/ |
| 218 |
int getnumcallscomputeF() { return ncalls_computeF_; } |
| 219 |
|
| 220 |
//! Reset the number of calls to the computeF method of this class. |
| 221 |
/*! Reset the number of calls to the computeF method of this class. This is for performance analysis. |
| 222 |
*/ |
| 223 |
bool setnumcallscomputeF(int ncalls) { ncalls_computeF_=ncalls; return true; } |
| 224 |
|
| 225 |
// get the output level |
| 226 |
inline int OutLevel() { return printlevel_; } |
| 227 |
|
| 228 |
// output method to look at the iterate |
| 229 |
#if 0 |
| 230 |
virtual bool PrintSol(int id) = 0; |
| 231 |
#endif |
| 232 |
|
| 233 |
public: |
| 234 |
|
| 235 |
//! Flag to indicate, that the Jacobian has been evaluated by the application. |
| 236 |
/*! Flag to indicate, that the Jacobian has been evaluated by the application. |
| 237 |
the ML_NOX::Ml_Nox_Fineinterface should set this to true, whenever |
| 238 |
the evaluated Jacobian matches the F in the computeF. |
| 239 |
It should be set to false if there is either no Jacobian evaluated or |
| 240 |
it does not match the F from the computeF function |
| 241 |
*/ |
| 242 |
bool isnewJacobian_; |
| 243 |
|
| 244 |
//! count number of evaluated Jacobians |
| 245 |
/*! The user's ML_NOX::Ml_Nox_Fineinterface derived class should use this to |
| 246 |
count the number of Jacobian evaluations for statistical and debug-purpose |
| 247 |
*/ |
| 248 |
int numJacobian_; |
| 249 |
|
| 250 |
//! Printlevel |
| 251 |
/*! The user's ML_NOX::Ml_Nox_Fineinterface derived class should set a |
| 252 |
printlevel value between 0 and 10 |
| 253 |
*/ |
| 254 |
int printlevel_; |
| 255 |
|
| 256 |
//! t_ should be used for time measurement of time spent in this class |
| 257 |
/*! t_ should be used for time measurement. The methods getsumtime and resetsumtime will be used |
| 258 |
to query this value for performance measurement |
| 259 |
*/ |
| 260 |
double t_; |
| 261 |
|
| 262 |
//! ncalls_computeF_ is used to count the number of calls to computeF |
| 263 |
/*! ncalls_computeF_ is used to count the number of calls to computeF |
| 264 |
*/ |
| 265 |
int ncalls_computeF_; |
| 266 |
|
| 267 |
private: |
| 268 |
// don't want copy-ctor and = operator |
| 269 |
Ml_Nox_Fineinterface(ML_NOX::Ml_Nox_Fineinterface& old); |
| 270 |
//Ml_Nox_Fineinterface operator = (const ML_NOX::Ml_Nox_Fineinterface& old); |
| 271 |
|
| 272 |
}; |
| 273 |
} // namespace ML_NOX |
| 274 |
|
| 275 |
|
| 276 |
#endif // ML_NOX_FINEINTERFACE_H |
| 277 |
#endif // defined(HAVE_ML_NOX) && defined(HAVE_ML_EPETRA) |