| 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 NOX_COARSEPROBLEM_INTERFACE_H |
| 21 |
#define NOX_COARSEPROBLEM_INTERFACE_H |
| 22 |
|
| 23 |
#include <iostream> |
| 24 |
|
| 25 |
// Epetra headers |
| 26 |
#include "Epetra_Vector.h" |
| 27 |
#include "Epetra_Operator.h" |
| 28 |
#include "Epetra_RowMatrix.h" |
| 29 |
#include "Epetra_CrsMatrix.h" |
| 30 |
#include "Epetra_CrsGraph.h" |
| 31 |
#include "Epetra_Comm.h" |
| 32 |
#include "Epetra_SerialComm.h" |
| 33 |
#ifdef ML_MPI |
| 34 |
#include "Epetra_MpiComm.h" |
| 35 |
#endif |
| 36 |
#include "Epetra_Map.h" |
| 37 |
#include "Epetra_Export.h" |
| 38 |
#include "Epetra_Import.h" |
| 39 |
|
| 40 |
// NOX headers |
| 41 |
#include "NOX_EpetraNew_Interface_Required.H" |
| 42 |
#include "NOX_EpetraNew_Interface_Jacobian.H" |
| 43 |
#include "NOX_EpetraNew_Interface_Preconditioner.H" |
| 44 |
|
| 45 |
// ML-headers |
| 46 |
#include "ml_include.h" |
| 47 |
#include "ml_epetra_utils.h" |
| 48 |
#include "ml_epetra.h" |
| 49 |
#include "ml_epetra_operator.h" |
| 50 |
#include "ml_MultiLevelOperator.h" |
| 51 |
|
| 52 |
// User Defined |
| 53 |
#include "ml_nox_fineinterface.H" |
| 54 |
|
| 55 |
// forward declarations |
| 56 |
class Nox_Problem_Interface; |
| 57 |
class Epetra_CrsMatrix; |
| 58 |
|
| 59 |
|
| 60 |
namespace ML_NOX |
| 61 |
{ |
| 62 |
class Nox_CoarseProblem_Interface : public NOX::EpetraNew::Interface::Required, |
| 63 |
public NOX::EpetraNew::Interface::Jacobian, |
| 64 |
public NOX::EpetraNew::Interface::Preconditioner |
| 65 |
{ |
| 66 |
public: |
| 67 |
Nox_CoarseProblem_Interface(ML_NOX::Ml_Nox_Fineinterface& interface, |
| 68 |
int level, |
| 69 |
int plevel, |
| 70 |
Epetra_CrsMatrix** P, |
| 71 |
const Epetra_BlockMap* this_RowMap, |
| 72 |
int nlevel); |
| 73 |
|
| 74 |
~Nox_CoarseProblem_Interface(); |
| 75 |
|
| 76 |
//! recreate this interface. This is a constructor reusing previous data |
| 77 |
bool recreate(int plevel,Epetra_CrsMatrix** P, const Epetra_BlockMap* this_RowMap); |
| 78 |
|
| 79 |
//! Compute and return F (derived) |
| 80 |
bool computeF(const Epetra_Vector& x, Epetra_Vector& F, const FillType fillFlag); |
| 81 |
|
| 82 |
//! Compute an explicit Jacobian (derived) |
| 83 |
bool computeJacobian(const Epetra_Vector& x); |
| 84 |
|
| 85 |
//! Computes a user supplied preconditioner based on input vector x. |
| 86 |
//! Returns true if computation was successful. (derived) |
| 87 |
bool computePreconditioner(const Epetra_Vector& x, |
| 88 |
NOX::Parameter::List* precParams = 0); |
| 89 |
|
| 90 |
// restrict a fine level vector to this coarse level |
| 91 |
Epetra_Vector* restrict_fine_to_this(const Epetra_Vector& xfine); |
| 92 |
|
| 93 |
// prolong a this coarse level vector to the fine level |
| 94 |
Epetra_Vector* prolong_this_to_fine(const Epetra_Vector& xcoarse); |
| 95 |
|
| 96 |
// return number of calls to the computeF-member |
| 97 |
int numcallscomputeF() { return nFcalls_; } |
| 98 |
|
| 99 |
// reset number of calls to the computeF-member to zero |
| 100 |
bool resetnumcallscomputeF() { nFcalls_=0; return true;} |
| 101 |
|
| 102 |
//! set the ptr to the prolonagation hierarchy |
| 103 |
bool setP(Epetra_CrsMatrix** P) { P_ = P; return true;} |
| 104 |
|
| 105 |
//! destroy the P-hierarchy WARNING: this may only be called once for all coarse interfaces! |
| 106 |
bool destroyP() |
| 107 |
{ |
| 108 |
if (P_) |
| 109 |
{ |
| 110 |
int i; |
| 111 |
for (i=0; i<nlevel_; i++) |
| 112 |
if (P_[i]) |
| 113 |
{ |
| 114 |
delete P_[i]; |
| 115 |
P_[i] = 0; |
| 116 |
} |
| 117 |
delete [] (P_); |
| 118 |
P_ = 0; |
| 119 |
} |
| 120 |
return true; |
| 121 |
} // destroyP() |
| 122 |
|
| 123 |
// set the FAS-modified system |
| 124 |
bool setModifiedSystem(bool flag, Epetra_Vector* fbar, Epetra_Vector* fxbar) |
| 125 |
{ isFASmodfied_ = flag; fbar_ = fbar; fxbar_ = fxbar; return true; } |
| 126 |
|
| 127 |
// check the FAS flag |
| 128 |
bool isFAS() { return isFASmodfied_; } |
| 129 |
|
| 130 |
// restrict vector to next coarser level |
| 131 |
Epetra_Vector* restrict_to_next_coarser_level(Epetra_Vector* thisvec, int current, int next); |
| 132 |
|
| 133 |
// prolong vector from next coarser level to current level |
| 134 |
Epetra_Vector* prolong_to_this_level(Epetra_Vector* coarsevec, int current, int next); |
| 135 |
|
| 136 |
// apply constraints to the gradient |
| 137 |
void ApplyAllConstraints(Epetra_Vector& gradient); |
| 138 |
|
| 139 |
// return the level of this interface |
| 140 |
int Level() { return level_; } |
| 141 |
|
| 142 |
// return the rowmap of this level |
| 143 |
const Epetra_BlockMap* BlockMap() { return this_RowMap_; } |
| 144 |
|
| 145 |
private: |
| 146 |
// don't want copy-ctor and = operator |
| 147 |
Nox_CoarseProblem_Interface(ML_NOX::Nox_CoarseProblem_Interface& old); |
| 148 |
Nox_CoarseProblem_Interface operator = (const ML_NOX::Nox_CoarseProblem_Interface& old); |
| 149 |
|
| 150 |
//! Application Operator: Object that points to the user's evaluation routines. |
| 151 |
/*! This is used to point to the actual routines and to store |
| 152 |
* auxiliary data required by the user's application for function/Jacobian |
| 153 |
* evaluations that NOX does not need to know about. This is type of |
| 154 |
* passdown class design by the application code. |
| 155 |
*/ |
| 156 |
ML_NOX::Ml_Nox_Fineinterface& fineinterface_; |
| 157 |
int level_; // the level this interface belongs to |
| 158 |
int nlevel_; // total number of levels |
| 159 |
int ml_printlevel_; // ML-printlevel |
| 160 |
int nFcalls_; // number of calls to computeF |
| 161 |
// NOTE: this class is NOT in charge of destroying P_! |
| 162 |
Epetra_CrsMatrix** P_; // ptr to prolongators extracted from the ml-hierarchy |
| 163 |
const Epetra_BlockMap* this_RowMap_; // the RowMap of this levels operator |
| 164 |
#if 1 |
| 165 |
vector<Epetra_Vector*> wvec_; // working vectors for prolongation/restriction |
| 166 |
#endif |
| 167 |
// NOTE: this class in not in charge of destroying fbar_, fxbar_ ! |
| 168 |
bool isFASmodfied_; // set the flag, that computeFshall return modfied answer |
| 169 |
Epetra_Vector* fbar_; // vector used to modify the answer when solving FAS-coarse grid |
| 170 |
Epetra_Vector* fxbar_; // vector used to modify the answer when solving FAS-coarse grid |
| 171 |
}; |
| 172 |
} // namespace ML_NOX |
| 173 |
|
| 174 |
|
| 175 |
#endif // NOX_COARSEPROBLEM_INTERFACE_H |
| 176 |
#endif // defined(HAVE_ML_NOX) && defined(HAVE_ML_EPETRA) |