Debian Codegraph @

packages/trilinoscouplings/src/ml/NonlinML/ml_nox_nonlinearlevel.H

raw
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_NONLINEARLEVEL_H
21 #define ML_NOX_NONLINEARLEVEL_H
22
23 #include <vector>
24
25 // epetra-headers
26 #include "Epetra_Map.h"
27 #include "Epetra_Vector.h"
28 #include "Epetra_MultiVector.h"
29 #include "Epetra_IntVector.h"
30 #include "Epetra_Operator.h"
31 #include "Epetra_CrsMatrix.h"
32 #include "Epetra_RowMatrix.h"
33 #include "Epetra_CrsGraph.h"
34 #include "Epetra_LinearProblem.h"
35 #include "Epetra_Object.h"
36 #include "Epetra_Comm.h"
37 #include "Epetra_SerialComm.h"
38 #ifdef PARALLEL
39 #include "Epetra_MpiComm.h"
40 #endif
41 #include "Epetra_MapColoring.h"
42 #include "Epetra_Export.h"
43 #include "Epetra_Import.h"
44
45 // NOX-headers
46 #include <NOX.H>
47 #include <NOX_Epetra.H>
48 #include "NOX_EpetraNew_Interface_Required.H"
49 #include "NOX_EpetraNew_Interface_Jacobian.H"
50 #include "NOX_EpetraNew_Interface_Preconditioner.H"
51 #include "NOX_EpetraNew_FiniteDifference.H"
52 #include "NOX_EpetraNew_FiniteDifferenceColoring.H"
53 #include "NOX_EpetraNew_LinearSystemAztecOO.H"
54 #include "NOX_EpetraNew_BroydenOperator.H"
55
56 // ML-headers
57 #include "ml_common.h"
58 #include "ml_include.h"
59 #include "ml_epetra_utils.h"
60 #include "ml_epetra.h"
61 #include "ml_epetra_operator.h"
62 #include "ml_MultiLevelOperator.h"
63
64 // the NOX::EpetraNew::LinearSystem - derived linear System
65 #include "ml_nox_linearsystem.H"
66
67 // interface to user code on fine level
68 #include "ml_nox_fineinterface.H"
69
70 // interface to user code on coarse levels
71 #include "ml_nox_coarseinterface.H"
72 #include "ml_nox_coarse_prepostoperator.H"
73
74 #include "ml_nox_ConstrainedMultiLevelOperator.H"
75
76 // the graph coloring class - EpetraExt headers
77 #include "EpetraExt_MapColoring.h"
78 #include "EpetraExt_MapColoringIndex.h"
79
80 // ---------- Forward Declarations ----------
81 class Epetra_MultiVector;
82 class Epetra_BlockMap;
83 class Epetra_Comm;
84 class Nox_Problem_Interface;
85 class Nox_CoarseProblem_Interface;
86 class Epetra_MapColoring;
87 class Epetra_IntVector;
88
89 namespace ML_NOX
90 {
91 class ML_Nox_NonlinearLevel : public NOX::EpetraNew::Interface::Preconditioner,
92 public NOX::EpetraNew::Interface::Jacobian
93 {
94
95 public:
96
97 // constructor for case ismatrixfree==false
98 explicit ML_Nox_NonlinearLevel(
99 int level, int nlevel, int printlevel, ML* ml, ML_Aggregate* ag,
100 Epetra_CrsMatrix** P, ML_NOX::Ml_Nox_Fineinterface& interface,
101 const Epetra_Comm& comm, const Epetra_Vector& xfine, bool ismatrixfree,
102 bool matfreelev0, bool isnlnCG, int nitersCG, bool broyden,
103 Epetra_CrsMatrix* Jac, string fsmoothertype, string smoothertype,
104 string coarsesolvetype,
105 int nsmooth_fine, int nsmooth, int nsmooth_coarse,
106 double conv_normF,
107 double conv_nupdate, int conv_maxiter, int numPDE, int nullspdim);
108
109 // constructor for case ismatrixfree==true
110 explicit ML_Nox_NonlinearLevel(
111 int level, int nlevel, int printlevel, ML* ml, ML_Aggregate* ag,
112 Epetra_CrsMatrix** P, ML_NOX::Ml_Nox_Fineinterface& interface,
113 const Epetra_Comm& comm, const Epetra_Vector& xfine, bool ismatrixfree,
114 bool isnlnCG, int nitersCG, bool broyden,
115 string fsmoothertype, string smoothertype, string coarsesolvetype,
116 int nsmooth_fine, int nsmooth, int nsmooth_coarse,
117 double conv_normF, double conv_nupdate, int conv_maxiter,
118 int numPDE, int nullspdim, Epetra_CrsMatrix* Mat,
119 ML_NOX::Nox_CoarseProblem_Interface* coarseinterface);
120
121 // destructor
122 ~ML_Nox_NonlinearLevel();
123
124 //! Computes a user defined preconditioner. (derived)
125 bool computePreconditioner(const Epetra_Vector& x,
126 NOX::Parameter::List* precParams = 0);
127
128 // destroy the P-hierarchy in the coarse interface
129 bool destroyP() { if (coarseinterface_) return coarseinterface_->destroyP();
130 else return false; }
131 // set the ptr to the P-hierarchy in the coarseinterface_
132 bool setP(Epetra_CrsMatrix** P) { if (coarseinterface_) return coarseinterface_->setP(P);
133 else return false; }
134
135 // set the FAS-modified system flag
136 bool setModifiedSystem(bool flag, Epetra_Vector* fbar, Epetra_Vector* fxbar)
137 { return coarseinterface_->setModifiedSystem(flag,fbar,fxbar);}
138
139 // iterate on this level's nln problem numiter times or until NOX converged
140 bool iterate(Epetra_Vector* f, Epetra_Vector* x, int numiter);
141 bool iterate(Epetra_Vector* f, Epetra_Vector* x, int numiter, double* norm);
142
143 // restrict vector to next coarser level
144 Epetra_Vector* restrict_to_next_coarser_level(Epetra_Vector* finevec, int current, int next)
145 { return coarseinterface_->restrict_to_next_coarser_level(finevec,current,next);}
146
147 // prolong vector from next coarser level to current level
148 Epetra_Vector* prolong_to_this_level(Epetra_Vector* coarsevec, int current, int next)
149 { return coarseinterface_->prolong_to_this_level(coarsevec,current,next);}
150
151
152 // evaluate the nonlinear function on this level
153 bool computeF(const Epetra_Vector& x, Epetra_Vector& F,
154 NOX::EpetraNew::Interface::Required::FillType fillFlag)
155 { return coarseinterface_->computeF(x,F,fillFlag);}
156
157 // Compute Jacobian (derived from NOX::EpetraNew::Interface::Jacobian)
158 bool computeJacobian(const Epetra_Vector& x);
159
160 // apply constrints using the coarse interface
161 void ApplyAllConstraints(Epetra_Vector& gradient)
162 { coarseinterface_->ApplyAllConstraints(gradient); return; }
163
164 private:
165 // don't want copy-ctor and = operator
166 ML_Nox_NonlinearLevel(ML_NOX::ML_Nox_NonlinearLevel& old);
167 ML_Nox_NonlinearLevel operator = (const ML_NOX::ML_Nox_NonlinearLevel& old);
168
169 // create a NOX convergence test
170 bool create_Nox_Convergencetest(double conv_normF, double conv_nupdate, int conv_maxiter);
171
172 // set the smoother for one nonlinear level
173 bool Set_Smoother(ML* ml, ML_Aggregate* ag, int level, int nlevel,
174 ML* thislevel_ml, ML_Aggregate* thislevel_ag,
175 string smoothertype, int nsmooth);
176
177 // iterate on this level's nln problem numiter times or until NOX converged
178 bool applySmoother(Epetra_Vector* f, Epetra_Vector* x, int numiter);
179
180 int level_; // the level we are on here
181 int nlevel_; // total number of levels
182 int ml_printlevel_; // ML's output level
183 ML* ml_; // the overall ML-hierarchy
184 ML_Aggregate* ag_; // the overall ML-hierarchy
185 Epetra_CrsMatrix* SmootherA_; // this level's preconditioner to this level's nlnCG
186 ML_NOX::Ml_Nox_Fineinterface& fineinterface_; // the fineinterface
187 const Epetra_Comm& comm_; // Epetra_Comm
188 ML_NOX::Nox_CoarseProblem_Interface* coarseinterface_; // this level's coarse interface
189 ML_NOX::Ml_Nox_CoarsePrePostOperator* coarseprepost_;
190 ML* thislevel_ml_; // this level's 1-Level ML as a smoother to this level's nlnCG
191 ML_Aggregate* thislevel_ag_; // this level's 1-Level ML as a smoother to this level's nlnCG
192 ML_NOX::ML_Nox_ConstrainedMultiLevelOperator* thislevel_prec_; // this level's 1-Level ML-smoother
193 Epetra_Vector* xthis_; // this level's current solution
194
195 NOX::EpetraNew::MatrixFree* thislevel_A_; // this level's Matrixfree operator
196 ML_NOX::Ml_Nox_LinearSystem* thislevel_linSys_; // this level's NOX-linearSystem
197 NOX::Parameter::List* nlParams_; // this level's NOX parameter list
198
199 NOX::StatusTest::NormF* absresid_; // a combination of NOX-convergence criteria
200 NOX::StatusTest::NormUpdate* nupdate_;
201 NOX::StatusTest::FiniteValue* fv_;
202 NOX::StatusTest::MaxIters* maxiters_;
203 NOX::StatusTest::Combo* combo1_;
204 NOX::StatusTest::Combo* combo2_;
205
206 NOX::Epetra::Vector* initialGuess_; // the initial guess for NOX
207 NOX::EpetraNew::Group* group_; // whatever that is, one needs it
208 NOX::Solver::Manager* solver_; // this level's NOX-solver (nlnCG)
209 double conv_normF_; // this level's NOX's convergence test
210 double conv_nupdate_;
211 int conv_maxiter_;
212
213 // --- for the matrixfree method ---
214 bool ismatrixfree_; // flag to indicate whether this level is matrixfree or not
215
216 // -- for the Newton method
217 bool isnlnCG_; // flag to switch nlnCG/Neweton's method
218 int nitersCG_; // number of Aztec-CG iterations as linear solve in mod. Newton's method
219 bool broyden_; // use Broyden update for jacobian in case of Newton's method
220 NOX::EpetraNew::LinearSystemAztecOO* azlinSys_; // the aztec linear system to be used with mod. Newton's method
221 Epetra_Vector* clone_;
222 NOX::EpetraNew::BroydenOperator* Broyd_; // Broyden operator
223 }; // class ML_Nox_NonlinearLevel
224 } // namespace ML_NOX
225
226
227 #endif // ML_NOX_NONLINEARLEVEL_H
228 #endif // defined(HAVE_ML_NOX) && defined(HAVE_ML_EPETRA)