| 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_nonlinearlevel.H |
| 16 |
* |
| 17 |
* \class NLNML_NonlinearLevel |
| 18 |
* |
| 19 |
* \brief a nonlinear coarse grid class |
| 20 |
* |
| 21 |
* \date Last update do Doxygen: 31-Mar-05 |
| 22 |
* |
| 23 |
*/ |
| 24 |
#include "ml_common.h" |
| 25 |
#include "ml_include.h" |
| 26 |
#include "TrilinosCouplings_config.h" |
| 27 |
|
| 28 |
#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) |
| 29 |
|
| 30 |
#ifndef NLNML_NONLINEARLEVEL_H |
| 31 |
#define NLNML_NONLINEARLEVEL_H |
| 32 |
|
| 33 |
#include <vector> |
| 34 |
|
| 35 |
// epetra-headers |
| 36 |
#include "Epetra_Map.h" |
| 37 |
#include "Epetra_Vector.h" |
| 38 |
#include "Epetra_MultiVector.h" |
| 39 |
#include "Epetra_IntVector.h" |
| 40 |
#include "Epetra_Operator.h" |
| 41 |
#include "Epetra_CrsMatrix.h" |
| 42 |
#include "Epetra_RowMatrix.h" |
| 43 |
#include "Epetra_CrsGraph.h" |
| 44 |
#include "Epetra_LinearProblem.h" |
| 45 |
#include "Epetra_Object.h" |
| 46 |
#include "Epetra_Comm.h" |
| 47 |
#include "Epetra_SerialComm.h" |
| 48 |
#ifdef PARALLEL |
| 49 |
#include "Epetra_MpiComm.h" |
| 50 |
#endif |
| 51 |
#include "Epetra_MapColoring.h" |
| 52 |
#include "Epetra_Export.h" |
| 53 |
#include "Epetra_Import.h" |
| 54 |
|
| 55 |
// NOX-headers |
| 56 |
#include <NOX.H> |
| 57 |
#include <NOX_Epetra.H> |
| 58 |
#include "NOX_Epetra_Interface_Required.H" |
| 59 |
#include "NOX_Epetra_Interface_Jacobian.H" |
| 60 |
#include "NOX_Epetra_Interface_Preconditioner.H" |
| 61 |
#include "NOX_Epetra_FiniteDifference.H" |
| 62 |
#include "NOX_Epetra_FiniteDifferenceColoring.H" |
| 63 |
#include "NOX_Epetra_LinearSystem_AztecOO.H" |
| 64 |
|
| 65 |
// ML-headers |
| 66 |
#include "ml_common.h" |
| 67 |
#include "ml_include.h" |
| 68 |
#include "ml_epetra_utils.h" |
| 69 |
#include "ml_epetra.h" |
| 70 |
#include "ml_epetra_operator.h" |
| 71 |
#include "ml_MultiLevelOperator.h" |
| 72 |
#include "ml_agg_VBMETIS.h" |
| 73 |
|
| 74 |
// own headers |
| 75 |
#include "nlnml_linearsystem.H" |
| 76 |
#include "nlnml_finelevelnoxinterface.H" |
| 77 |
#include "nlnml_prepostoperator.H" |
| 78 |
#include "nlnml_ConstrainedMultiLevelOperator.H" |
| 79 |
|
| 80 |
// ---------- Forward Declarations ---------- |
| 81 |
namespace NLNML { |
| 82 |
class NLNML_FineLevelNoxInterface; |
| 83 |
} |
| 84 |
|
| 85 |
using namespace Teuchos; |
| 86 |
namespace NLNML |
| 87 |
{ |
| 88 |
|
| 89 |
class NLNML_NonlinearLevel : public virtual NOX::Epetra::Interface::Jacobian, |
| 90 |
public virtual NOX::Epetra::Interface::Preconditioner |
| 91 |
{ |
| 92 |
public: |
| 93 |
|
| 94 |
explicit NLNML_NonlinearLevel( |
| 95 |
int level, RefCountPtr<Teuchos::ParameterList> params, |
| 96 |
ML* ml, ML_Aggregate* ag, |
| 97 |
RefCountPtr< std::vector< RefCountPtr<Epetra_CrsMatrix> > > P, |
| 98 |
RefCountPtr<NLNML::NLNML_FineLevelNoxInterface> finterface, |
| 99 |
const Epetra_Comm& comm, |
| 100 |
RefCountPtr<Epetra_CrsMatrix> fineJac, |
| 101 |
const Epetra_Vector& xfine, |
| 102 |
bool isnlncg, int niterscg, |
| 103 |
int numpde, int dimns); |
| 104 |
|
| 105 |
virtual ~NLNML_NonlinearLevel(); |
| 106 |
|
| 107 |
bool computeJacobian(const Epetra_Vector& x, Epetra_Operator& Jac); |
| 108 |
|
| 109 |
bool computePreconditioner(const Epetra_Vector& x, |
| 110 |
Epetra_Operator& M, |
| 111 |
Teuchos::ParameterList* precParams = 0); |
| 112 |
|
| 113 |
const Epetra_Comm & Comm() const {return(comm_);} |
| 114 |
|
| 115 |
inline int OutLevel() const { return params_->get("nlnML output",0); } |
| 116 |
|
| 117 |
bool setModifiedSystem(bool flag, Epetra_Vector* fbar, Epetra_Vector* fxbar) |
| 118 |
{ return coarseinterface_->setModifiedSystem(flag,fbar,fxbar);} |
| 119 |
|
| 120 |
// evaluate the nonlinear function on this level |
| 121 |
bool computeF(const Epetra_Vector& x, Epetra_Vector& F, |
| 122 |
NOX::Epetra::Interface::Required::FillType fillFlag) |
| 123 |
{ return coarseinterface_->computeF(x,F,fillFlag);} |
| 124 |
|
| 125 |
bool Iterate(Epetra_Vector* f, Epetra_Vector* x, int numiter, double* norm); |
| 126 |
|
| 127 |
// restrict vector to next coarser level |
| 128 |
Epetra_Vector* restrict_to_next_coarser_level(Epetra_Vector* finevec, int current, int next) |
| 129 |
{ return coarseinterface_->restrict_to_next_coarser_level(finevec,current,next);} |
| 130 |
|
| 131 |
// prolong vector from next coarser level to current level |
| 132 |
Epetra_Vector* prolong_to_this_level(Epetra_Vector* coarsevec, int current, int next) |
| 133 |
{ return coarseinterface_->prolong_to_this_level(coarsevec,current,next);} |
| 134 |
|
| 135 |
private: |
| 136 |
|
| 137 |
// don't want copy-ctor and = operator |
| 138 |
NLNML_NonlinearLevel(NLNML::NLNML_NonlinearLevel& old); |
| 139 |
NLNML_NonlinearLevel operator = (const NLNML::NLNML_NonlinearLevel& old); |
| 140 |
|
| 141 |
inline int Level() const { return level_; } |
| 142 |
|
| 143 |
bool Set_Smoother(ML* ml, ML_Aggregate* ag, int level, int nlevel, |
| 144 |
ML* thislevel_ml, ML_Aggregate* thislevel_ag, |
| 145 |
string smoothertype, int nsmooth); |
| 146 |
|
| 147 |
void create_Nox_Convergencetest(double normf, double norm_update, int maxiter); |
| 148 |
|
| 149 |
template<typename kind> |
| 150 |
kind getParameter(string name,kind dvalue) const |
| 151 |
{ return (*params_).get(name,dvalue); } |
| 152 |
|
| 153 |
template<typename kind> |
| 154 |
void setParameter(string name,kind dvalue) const |
| 155 |
{ (*params_).set(name,dvalue); return; } |
| 156 |
|
| 157 |
int level_; |
| 158 |
bool isnlncg_; |
| 159 |
ML* ml_; |
| 160 |
ML_Aggregate* ag_; |
| 161 |
ML* thislevel_ml_; // this level's 1-Level ML as a smoother to this level's nlnCG |
| 162 |
ML_Aggregate* thislevel_ag_; // this level's 1-Level ML as a smoother to this level's nlnCG |
| 163 |
RefCountPtr<Teuchos::ParameterList> params_; |
| 164 |
RefCountPtr< std::vector< RefCountPtr<Epetra_CrsMatrix> > > P_; |
| 165 |
RefCountPtr<NLNML::NLNML_FineLevelNoxInterface> fineinterface_; |
| 166 |
const Epetra_Comm& comm_; |
| 167 |
RefCountPtr<Epetra_CrsMatrix> fineJac_; |
| 168 |
RefCountPtr<Epetra_CrsMatrix> SmootherA_; |
| 169 |
RefCountPtr<NLNML::NLNML_CoarseLevelNoxInterface> coarseinterface_; |
| 170 |
RefCountPtr<NLNML::NLNML_PrePostOperator> prepost_; |
| 171 |
RefCountPtr<Epetra_Vector> xthis_; |
| 172 |
RefCountPtr<NLNML::NLNML_ConstrainedMultiLevelOperator> thislevel_prec_; |
| 173 |
RefCountPtr<Teuchos::ParameterList> nlparams_; |
| 174 |
RefCountPtr<NOX::Epetra::MatrixFree> thislevel_A_; |
| 175 |
RefCountPtr<NLNML::NLNML_LinearSystem> thislevel_linSys_; |
| 176 |
RefCountPtr<NOX::Epetra::LinearSystemAztecOO> azlinSys_; |
| 177 |
RefCountPtr<NOX::Epetra::Group> group_; |
| 178 |
//JJH |
| 179 |
//RefCountPtr<NOX::Solver::Manager> solver_; |
| 180 |
RCP<NOX::Solver::Generic> solver_; |
| 181 |
|
| 182 |
RefCountPtr<NOX::StatusTest::NormF> absresid_; |
| 183 |
RefCountPtr<NOX::StatusTest::NormUpdate> nupdate_; |
| 184 |
RefCountPtr<NOX::StatusTest::Combo> combo1_; |
| 185 |
RefCountPtr<NOX::StatusTest::FiniteValue> fv_; |
| 186 |
RefCountPtr<NOX::StatusTest::MaxIters> maxiters_; |
| 187 |
RefCountPtr<NOX::StatusTest::Combo> combo2_; |
| 188 |
|
| 189 |
}; // class NLNML_NonlinearLevel |
| 190 |
} // namespace NLNML |
| 191 |
|
| 192 |
#endif |
| 193 |
#endif |