Debian Codegraph @

packages/trilinoscouplings/src/ml/NonlinML/ml_nox_preconditioner.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 /*!
15 * \file ml_nox_preconditioner.H
16 *
17 * \class ML_Nox_Preconditioner
18 *
19 * \brief ML nonlinear preconditioner and solver
20 *
21 * \date Last update do Doxygen: 31-Mar-05
22 *
23 */
24 // ML-headers
25 #include "ml_common.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 ML_NOX_PRECONDITIONER_H
31 #define ML_NOX_PRECONDITIONER_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_Operator.h"
40 #include "Epetra_CrsMatrix.h"
41 #include "Epetra_RowMatrix.h"
42 #include "Epetra_CrsGraph.h"
43 #include "Epetra_LinearProblem.h"
44 #include "Epetra_Object.h"
45 #include "Epetra_Comm.h"
46 #include "Epetra_SerialComm.h"
47 #ifdef ML_MPI
48 #include "Epetra_MpiComm.h"
49 #endif
50 #include "Epetra_SerialComm.h"
51
52 // NOX-headers
53 #include "NOX_Epetra_Interface.H"
54
55 // ML-headers
56 #include "ml_common.h"
57 #include "ml_include.h"
58 #include "ml_epetra_utils.h"
59 #include "ml_epetra.h"
60 #include "ml_epetra_operator.h"
61 #include "ml_MultiLevelOperator.h"
62 #include "ml_agg_VBMETIS.h"
63 // a matrixfree level
64 #include "ml_nox_matrixfreelevel.H"
65 // a nonlinear level
66 #include "ml_nox_nonlinearlevel.H"
67 // utils
68 #include "ml_nox_preconditioner_utils.H"
69 // this is the wrapper for the Epetra_CrsGraph used by ml in matrix-free method
70 // it is derived from Epetra_RowMatrix so the ml - Epetra_RowMatrix - wrapper will take it
71 #include "ml_Epetra_wrap_CrsGraph_as_RowMatrix.H"
72
73 // interface to user code on fine level
74 #include "ml_nox_fineinterface.H"
75
76
77
78 // ---------- Forward Declarations ----------
79 class Epetra_MultiVector;
80 class Epetra_BlockMap;
81 class Epetra_Comm;
82 class Nox_Problem_Interface;
83 //! ML_NOX: default namespace for all ML/NOX nonlinear methods
84 namespace ML_NOX
85 {
86 /*!
87
88 \brief ML_Nox_Preconditioner: a class to define a multilevel nonlinear preconditioner and solver
89
90 Class ML_NOX::ML_Nox_Preconditioner defines an algebraic nonlinear preconditioner
91 or solver that is based on a full approximation scheme (FAS) approach and
92 is implemented making use of NOX' nonlinear solver capabilities.
93 It operates on Epetra objects and implements an Epetra_Operator to be easily
94 used as a preconditioner to some outer nonlinear iteration.
95 It also implements the NOX::EpetraNew::Interface::Preconditioner from NOX
96 so it can serve as it's own interface (see NOX documentation for details).
97 In this class several methods and options can be chosen, which are described in the
98 parameter set functions
99
100
101 To make use of the full functionality of this class it
102 requires ML to be configured with the following options:
103 - \c --with-ml_nox
104 - \c --enable-epetra
105 - \c --enable-epetraext
106 - \c --enable-nox
107 - \c --enable-nox-epetra
108 - \c --enable-prerelease
109 - \c --enable-aztecoo
110 - \c --enable-amesos
111
112 \warning
113 Currently, using this class makes it necessary to configure and make install
114 of Trilinos WITHOUT the --with-ml_nox, and then repeating the configure
115 and make install process WITH the --with-ml_nox option to be able to resolve the
116 dependencies of this class on NOX header files
117
118 \note
119 an example is given in the directory ml/examples/NonlinML
120
121 \author Michael Gee, SNL 9214
122 */
123 class ML_Nox_Preconditioner : public virtual Epetra_Operator,
124 public NOX::EpetraNew::Interface::Preconditioner
125 {
126 public:
127
128
129
130 //! Constructs an ML_Nox_Preconditioner class with default values.
131 /*!
132 Constructs a ML_Nox_Preconditioner class and sets a set of default values.
133 This constructor does NOT actually create the Multilevel hierarchy and the
134 methods, this is done by a call to computePreconditioner.
135 \param interface (In) : ref to an ML_NOX::Ml_Nox_Fineinterface derived class
136 \param comm (In) : the Epetra_Comm to be used
137 */
138 explicit ML_Nox_Preconditioner(ML_NOX::Ml_Nox_Fineinterface& interface,
139 const Epetra_Comm& comm);
140
141 //! Constructs an ML_Nox_Preconditioner class with parameter list.
142 /*!
143 Constructs a ML_Nox_Preconditioner class and sets a set of default values.
144 This constructor does NOT actually create the Multilevel hierarchy and the
145 methods, this is done by a call to computePreconditioner.<br>
146
147 <b>Teuchos parameters recognized and there default values:</b>
148 \code
149 Teuchos::ParameterList mlparams;
150 mlparams.set("nlnML output",6); // Level of output to be generated (0-10), 6 recommended
151 mlparams.set("nlnML max levels",10); // Max # of levels to produce
152 mlparams.set("nlnML coarse: max size",128); // Size of coarse grid where to stop coarsening
153 mlparams.set("nlnML is linear preconditioner",false); // Act as linear preconditioner, else run FAS-cycle as nonlinear preconditioner
154 mlparams.set("nlnML is matrixfree",true); // Finite difference for Jacobian
155 mlparams.set("nlnML finite difference fine level",true); // Finite difference for Jacobian on fine level only
156
157 mlparams.set("nlnML finite difference alpha",1.0e-07); // Finite differencing perturbation parameter
158 mlparams.set("nlnML finite difference beta",1.0e-06); // ---"---
159 mlparams.set("nlnML finite difference centered",false); // Finite differnencing scheme, true=centered, false=forward
160
161 mlparams.set("nlnML absolute residual tolerance",1.0e-05); // Internal absolute residual tolerance for FAS-cycle
162 mlparams.set("nlnML max cycles",250); // Max. # FAS-cycles before giving up
163 mlparams.set("nlnML adaptive recompute",0.0); // Recompute preconditioner when outer residual is above this tolerance
164 mlparams.set("nlnML offset recompute",0); // Recompute preconditioner every offset outer iterations
165 mlparams.set("nlnML additional adaptive nullspace",0); // # additional adaptive nullspace candidates to compute
166
167 mlparams.set("nlnML PDE equations",3); // # PDE equations (degrees of freedom per node)
168 mlparams.set("nlnML null space: dimension",3); // nullspace dimension
169 mlparams.set("nlnML spatial dimension",3); // spatial dimension of problem
170
171 mlparams.set("nlnML coarse: type","Uncoupled"); // aggregation scheme: Uncoupled METIS VBMETIS
172 mlparams.set("nlnML nodes per aggregate",27); // # nodes per aggregate for aggregation schemes "METIS" / "VBMETIS"
173
174 mlparams.set("nlnML use nlncg on fine level",true); // use nonlinear CG as smoother on fine level, else use Newton-Krylov
175 mlparams.set("nlnML use nlncg on medium level",true); // use nonlinear CG as smoother, else use Newton-Krylov
176 mlparams.set("nlnML use nlncg on coarsest level",true); // use nonlinear CG as smoother on coarsest level, else use Newton-Krylov
177
178 mlparams.set("nlnML max iterations newton-krylov fine level",5); // # iterations LINEAR CG in Newton-Krylov smoother fine level
179 mlparams.set("nlnML max iterations newton-krylov medium level" ,5); // # iterations LINEAR CG in Newton-Krylov smoother
180 mlparams.set("nlnML max iterations newton-krylov coarsest level",5); // # iterations LINEAR CG in Newton-Krylov smoother coarsest level
181
182 mlparams.set("nlnML linear smoother type fine level","SGS"); // type of linear fine smoother : SGS BSGS Jacobi MLS Bcheby AmesosKLU
183 mlparams.set("nlnML linear smoother type medium level","SGS"); // type of linear smoother : SGS BSGS Jacobi MLS Bcheby AmesosKLU
184 mlparams.set("nlnML linear smoother type coarsest level","AmesosKLU"); // type of linear coarse smoother: SGS BSGS Jacobi MLS Bcheby AmesosKLU
185 mlparams.set("nlnML linear smoother sweeps fine level",2); // # of linear smoother sweeps/polynomial order for linear fine smoother
186 mlparams.set("nlnML linear smoother sweeps medium level",2); // # of linear smoother sweeps/polynomial order for linear smoother
187 mlparams.set("nlnML linear smoother sweeps coarsest level",1); // # of linear smoother sweeps/polynomial order for linear coarse smoother
188
189 mlparams.set("nlnML nonlinear presmoothing sweeps fine level",0); // # nonlinear presmoothing sweeps in FAS-cycle fine level
190 mlparams.set("nlnML nonlinear presmoothing sweeps medium level",0); // # nonlinear presmoothing sweeps in FAS-cycle
191 mlparams.set("nlnML nonlinear smoothing sweeps coarse level",3); // # nonlinear sweeps in FAS-cycle coarsest level
192 mlparams.set("nlnML nonlinear postsmoothing sweeps medium level",3); // # nonlinear postsmoothing sweeps in FAS-cycle
193 mlparams.set("nlnML nonlinear postsmoothing sweeps fine level",3); // # nonlinear postsmoothing sweeps in FAS-cycle fine level
194 \endcode
195
196 \param interface (In) : ref to an ML_NOX::Ml_Nox_Fineinterface derived class
197 \param mlparams (In) : Teuchos parameter list
198 \param comm (In) : the Epetra_Comm to be used
199 */
200 explicit ML_Nox_Preconditioner(ML_NOX::Ml_Nox_Fineinterface& interface,
201 Teuchos::ParameterList& mlparams,
202 const Epetra_Comm& comm);
203
204
205 //! Destroys the preconditioner.
206 /*!
207 Destroys the ML_Nox_Preconditioner.
208 */
209 ~ML_Nox_Preconditioner();
210
211
212
213 //! Set the type of nonlinear method to be used.
214 /*!
215 Set the type of nonlinear method to be used on each level of the hierarchy
216 \param islinPrec (In) : if true, compute a linear multigrid operator,
217 if false, create a FAS multilevel hierarchy
218 \param maxlevel (In) : maximum number of levels.
219 \param ismatrixfree (In) : if true, use Finite Differencing to construct the Jacobians
220 on all levels. In this case, the preconditioner will
221 ask for a Epetra_CrsGraph through the fine level interface
222 and will build a plain aggregation hierarchy based on it.
223 If Jacobi is chosen as a smoother on any level, on that level
224 only the main diagonal of the Jacobian will be computed.
225 If false, the preconditioner will ask for an Epetra_CrsMatrix
226 and an Epetra_CrsGraph through the fine level interface and will
227 construct a smoothed aggregation MG hierarchy based on it.
228 Coarse level operators will then be Galerkin.
229 \param ismatfreelev0 (In) : if true AND ismatrixfree==true, the preconditioner
230 will construct a finite difference Jacobian on the fine level and
231 then will use it to construct a smoothed aggregation hierarchy.
232 Coarse level operators will be Galerkin. Option has no effect when
233 ismatrixfree==false.
234 */
235 bool SetNonlinearMethod(bool islinPrec, int maxlevel, bool ismatrixfree,
236 bool ismatfreelev0, bool fixdiagonal);
237
238 //! Set type of coarsening algorithm to be used.
239 /*!
240 Set type of coarsening algorithm to be used. Currently, this class recognizes
241 the ML-coarsening schemes Uncoupled, METIS and VBMETIS.
242 \param coarsentype (In) : string giving the coarsening scheme,
243 currently "Uncoupled", "METIS" and "VBMETIS" are
244 recognized
245 \param maxlevel (In) : maximum number of levels to generate
246 \param maxcoarsesize (In) : coarse grid size to stop coarsening when reached
247 \param nnodeperagg (In) : objective how many nodes to put in one aggregate for
248 coarsening schemes "METIS" and "VBMETIS".
249 */
250 bool SetCoarsenType(string coarsentype,int maxlevel,int maxcoarsesize,
251 int nnodeperagg);
252
253 //! Set type of smoother.
254 /*!
255 Set type of smoother. Currently, this class recognizes
256 the ML-smoothers Jacobi, SGS and AmesosKLU.
257 \param finesmoothertype (In) : string giving the fine level smoother,
258 currently "Jacobi", "SGS" and "AmesosKLU" are
259 recognized.
260 \param smoothertype (In) : string giving the smoother on all
261 intermediate levels, currently "Jacobi", "SGS" and "AmesosKLU" are
262 recognized.
263 \param coarsesolve (In) : string giving the smoother on the coarsest level,
264 currently "Jacobi", "SGS" and "AmesosKLU" are
265 recognized.
266 */
267 bool SetSmoothers(string finesmoothertype,string smoothertype,
268 string coarsesolve);
269
270 //! Set type of nonlinear solver for each level.
271 /*!
272 Set type of nonlinear solver for each level and number of LINEAR
273 CG-iterations allowed inside Newton's method.
274 \param usenlnCG_fine (In) : If true, use nlnCG on finest level, if
275 false, use Newton's method.
276 \param usenlnCG (In) : If true, use nlnCG on all intermediate levels,
277 if false use Newton's method.
278 \param usenlnCG_coarse (In) : If true, use nlnCG on coarsest level, if
279 false, use Newton's method.
280 \param useBroyden (In) : If true, use Broyden update for Jacobian,
281 will only affect levels on which Newton's
282 method is used.
283 \param nitersCG_fine (In) : If Newton's method is used on finest level,
284 this is the max. number of LINEAR CG iterations
285 allowed for the linear solve inside.
286 \param nitersCG (In) : If Newton's method is used on intermediate levels,
287 this is the max. number of LINEAR CG iterations
288 allowed for the linear solve inside.
289 \param nitersCG_fine (In) : If Newton's method is used on coarsest level,
290 this is the max. number of LINEAR CG iterations
291 allowed for the linear solve inside.
292 \note
293 When using Newton's method with or without Broyden update, Aztec's PCG will
294 be used as linear solver inside. The preconditioner to this LINEAR CG will then
295 be the smoother chosen via the method SetSmoothers.
296 */
297 bool SetNonlinearSolvers(bool usenlnCG_fine, bool usenlnCG, bool usenlnCG_coarse,
298 bool useBroyden, int nitersCG_fine, int nitersCG, int nitersCG_coarse);
299
300
301 //! Set number of sweeps of smoother.
302 /*!
303 Set number of sweeps of smoother.
304 \param nsmooth_fine (In) : Number of smoothing sweeps on fine level
305 \param nsmooth (In) : Number of smoothing sweeps on intermediate levels
306 \param nsmooth_coarse (In) : Number of smoothing sweeps on coarsest level
307 \note
308 When using nlnCG on a level, this is the number of sweeps of the
309 preconditioner to nlnCG. When using Newton's method on a level, this is
310 the number of sweeps of the preconditioner to the LINEAR CG inside
311 the Newton iteration on that level.
312 */
313 bool SetSmootherSweeps(int nsmooth_fine, int nsmooth, int nsmooth_coarse);
314
315
316 //! Set the ML print level.
317 /*!
318 Set the ML print level between 0 and 10.
319 \param printlevel (In) : (0-10), amount of output generated by NOX/ML
320 */
321 bool SetPrintLevel(int printlevel);
322
323
324 //! Set the offset for recomputing this preconditioner.
325 /*!
326 Set the offset for recomputing this preconditioner. Every offset times, the
327 preconditioner is applied it will recreate itself and will use the
328 fine level interface to obtain either a new fine level Jacobian or
329 to compute a Finite Differencing - Jacobian.
330 \param offset (In) : How often to apply this preconditioner before recomputing it.
331 */
332 bool SetRecomputeOffset(int offset);
333
334 //! Set the offset for recomputing this preconditioner.
335 /*!
336 Set the offset for recomputing this preconditioner. Every offset times, the
337 preconditioner is applied it will recreate itself and will use the
338 fine level interface to obtain either a new fine level Jacobian or
339 to compute a Finite Differencing - Jacobian.
340 Optionally, the MG hierarchy and Jacobian can be recomputed after the
341 recomputestep iteration
342 \param offset (In) : How often to apply this preconditioner before recomputing it.
343 */
344 bool SetRecomputeOffset(int offset, int recomputestep, double adaptrecompute, int adaptns);
345
346 //! Set dimensions for the PDE and the Nullspace.
347 /*!
348 Set dimensions for the PDE and the Nullspace.
349 \param spatialDimension (In) : spatial dimension of the problem.
350 \param numPDE (In) : Number of PDE equations, normally number of dofs per node.
351 \param dimNS (In) : Dimension of the nullspace. The preconditioner will ask for
352 the Nullspace through the fine level interface. If know
353 Nullspace is supplied there, the default Nullspace is used
354 and a warning is printed.
355 */
356 bool SetDimensions(int spatialDimension, int numPDE, int dimNS);
357
358 //! Set convergence criteria for nonlinear preconditioner.
359 /*!
360 Set convergence criteria for nonlinear preconditioner. Takes effect for
361 islinPrec==false only.
362 \param FAS_normF (In) : Residual norm a nonlinear iteration on some level is
363 considered converged.
364 \param FAS_nupdate (In) : Norm of stepsize a nonlinear iteration on some level is
365 considered converged.
366 */
367 bool SetConvergenceCriteria(double FAS_normF, double FAS_nupdate);
368
369 //! Set cycle for nonlinear preconditioner.
370 /*!
371 Set cycle for nonlinear preconditioner. Takes effect for
372 islinPrec==false only.
373 \param prefsmooth (In) : maximum number of nonlinear iterations to take
374 as a presmoothing step on finest level
375 \param presmooth (In) : maximum number of nonlinear iterations to take
376 as a presmoothing step on coarse levels
377 \param coarsesmooth (In) : maximum number of nonlinear iterations to take
378 on coarsest level
379 \param postsmooth (In) : maximum number of nonlinear iterations to take
380 as a postsmoothing step on coarse levels
381 \param postfsmooth (In) : maximum number of nonlinear iterations to take
382 as a postsmoothing step on finest level
383 \param maxcycle (In) : maximum number of nonlinear MG cycles to take
384 before we give up
385 */
386
387 bool SetFAScycle(int prefsmooth,int presmooth,int coarsesmooth, int postsmooth,
388 int postfsmooth,int maxcycle);
389
390 //! Set finite differencing method.
391 /*!
392 Set finite differencing method. Takes effect for
393 ismatrixfree==true only.
394 \param centered (In) : if true, use centered finite differencing, else use
395 forward finite differencing (true is twice the cost)
396 \param alpha (In) : perturbation parameter, see EpetraExt manual
397 \param beta (In) : perturbation parameter, see EpetraExt manual
398 */
399 bool SetFiniteDifferencing(bool centered,double alpha,double beta);
400
401 //! Register the outer Nox iterative method with the nonlinear preconditioner.
402 /*!
403 Register the outer Nox iterative method with the nonlinear preconditioner.
404 This is necessary, because the outer NOX iterative method will provide the
405 nonlinear preconditioner with current solution and residual. Necessary only
406 in the islinearPrec==false case and when used as a preconditioner. If used as
407 stand-alone solver, this is not necessary.
408 \param noxsolver (In) : ptr to the NOX::Solver::Manager of the outer
409 Nox iterative method.
410 */
411 bool set_nox_solver(NOX::Solver::Manager* noxsolver) {noxsolver_ = noxsolver; return true;}
412
413
414
415 //! Returns the label of this class.
416 /*!
417 Returns the label of this class.
418 */
419 const char* Label() const {return(&(label_[0]));}
420
421 //! get Comm of this class
422 /*!
423 Derived from Epetra_Operator, returns ref to the Epetra_Comm of this class
424 */
425 const Epetra_Comm & Comm() const {return(comm_);}
426
427 //! Get fine level OperatorDomainMap.
428 /*!
429 Derived from Epetra_Operator, get fine level OperatorDomainMap.
430 */
431 const Epetra_Map & OperatorDomainMap() const {return interface_.getMap();}
432
433 //! Get fine level OperatorRangeMap.
434 /*!
435 Derived from Epetra_Operator, get fine level OperatorRangeMap.
436 */
437 const Epetra_Map & OperatorRangeMap() const {return interface_.getMap();}
438
439 //! Check initialization flag of the instant of this class
440 /*!
441 check the init-flag of this instant, if false, ApplyInverse will throw an error.
442 */
443 bool isinit() const {return(isinit_);}
444
445 //! Set the initialization flag of the instant of this class
446 /*!
447 Set the init-flag of this instant.
448 */
449 bool setinit(bool flag)
450 {isinit_=flag; ncalls_NewPrec_ = 0; return(true);}
451
452 //! Get the offset to recompute this preconditioner.
453 /*!
454 Get the offset to recompute this preconditioner.
455 */
456 int getoffset() {return(offset_newPrec_);}
457
458
459
460 // derived from NOX::EpetraNew::Interface::Preconditioner
461 //! Construct the preconditioner.
462 /*!
463 Construct the preconditioner. This is derived from the
464 NOX::EpetraNew::Interface::Preconditioner class. Nox will use this to
465 (re)compute the preconditioner.
466 \param x (In) : Vector of the current solution
467 \param precParams (In) : ignored
468 */
469 virtual bool computePreconditioner(const Epetra_Vector& x,
470 NOX::Parameter::List* precParams = 0);
471
472 //! ApplyInverse the preconditioner
473 /*!
474 ApplyInverse the preconditioner. Method is derived from Epetra_Operator.
475 \param X (In) : Epetra_MultiVector matching the fine level map of this
476 preconditioner
477 \param Y (Out) : Epetra_MultiVector containing the result on output
478 */
479 int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const ;
480
481 // Apply the nonlinear multigrid FAS-solver
482 //! Apply the nonlinear multigrid FAS-solver.
483 /*!
484 Apply the nonlinear multigrid FAS-solver.
485 This preconditioner can act as a stand-alone FAS-Solver. Will throw an error,
486 if islinearPrec==true;
487 */
488 int solve();
489
490 //! Apply the preconditioner, not implemented.
491 /*!
492 Derived from Epetra_Operator, not implemented.
493 */
494 int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
495 { cout << "ML_Nox_Preconditioner::Apply does not make sense for an ML-Multilevel Operator\n"
496 << "Use ApplyInverse\n";return(-1);}
497
498 //! SetUseTranspose, not implemented.
499 /*!
500 Derived from Epetra_Operator, not implemented.
501 */
502 int SetUseTranspose(bool UseTranspose);
503
504 //! NormInf, not implemented.
505 /*!
506 Derived from Epetra_Operator, not implemented.
507 */
508 double NormInf() const {return(-1.0);}
509
510
511 //! UseTranspose, not implemented.
512 /*!
513 Derived from Epetra_Operator, not implemented.
514 */
515 bool UseTranspose() const {return(usetranspose_);}
516
517 //! HasNormInf, not implemented.
518 /*!
519 Derived from Epetra_Operator, always returns false.
520 */
521 bool HasNormInf() const {return(false);}
522
523 private:
524 // don't want copy-ctor and = operator
525 ML_Nox_Preconditioner(ML_Nox_Preconditioner& old);
526 ML_Nox_Preconditioner operator = (const ML_Nox_Preconditioner& old);
527
528 // Init the preconditioner to default values
529 bool Initialize();
530
531 // Compute Preconditioner functions,
532 // depending on type of preconditioner and whether the Jacobian was supplied or not
533 bool compPrec(const Epetra_Vector& x);
534 bool ML_Nox_compute_Jacobian_Linearpreconditioner(const Epetra_Vector& xfine);
535 bool ML_Nox_compute_Matrixfree_Linearpreconditioner(const Epetra_Vector& xfine);
536 bool ML_Nox_compute_Jacobian_Nonlinearpreconditioner(const Epetra_Vector& xfine);
537 bool ML_Nox_compute_Matrixfree_Nonlinearpreconditioner(const Epetra_Vector& xfine);
538
539 // utils
540 bool Set_Smoothers();
541 bool fix_MainDiagonal(Epetra_CrsMatrix** A, int level) const;
542 bool test_nullspace(int dimns, double* nullsp, Epetra_CrsMatrix* Jac) const;
543 Epetra_CrsMatrix* ML_Nox_computeFineLevelJacobian(const Epetra_Vector& x);
544
545 // ApplyInverse functions,
546 // depending on type of preconditioner
547 int ML_Nox_ApplyInverse_Linear(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
548 int ML_Nox_ApplyInverse_NonLinear(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
549
550 // nonlinear multigrid functions
551 //the FAS-preconditioner
552 bool ML_Nox_FAS_cycle(Epetra_Vector* f, Epetra_Vector* x, int level, bool* converged, double* finenorm) const;
553 // the FAS-solver
554 bool ML_Nox_FAS_cycle1(Epetra_Vector* f, Epetra_Vector* x, int level, bool* converged);
555
556 // destructor of vector of matfreelevels
557 bool destroy_matfreelevels(ML_NOX::ML_Nox_MatrixfreeLevel*** m, int nlevel);
558 // destructor of vector of nonlinearlevels
559 bool destroy_nonlinearlevels(ML_NOX::ML_Nox_NonlinearLevel*** nln, int nlevel);
560
561 // run adatpve setup
562 bool Ml_Nox_adaptivesetup(double** oldns, Epetra_CrsMatrix* Jac,int oldnumpde,int olddimns);
563
564 private:
565 // ---general data---
566 char* label_; // the label of this class
567 Teuchos::ParameterList* params_; // holding the parameters list
568 bool usetranspose_; // use transpose of operator (not supported)
569 bool isinit_; // flag whether preconditioner is valid
570 bool ismatrixfree_; // use Graph or Jacobian in building the preconditioner
571 bool matfreelev0_;
572 bool fixdiagonal_;
573 bool islinearPrec_; // do standard linear ML-SA-Preconditioner (not matrixfree!))
574 ML_NOX::Ml_Nox_Fineinterface& interface_; // the user interface
575 const Epetra_Comm& comm_; // the communicator;
576 bool destroyfineJac_; // flag to indicate this class destroys the fineJac_
577 Epetra_CrsMatrix* fineJac_; // fine grid matrix (only used when ismatrixfree_=false)
578 int offset_newPrec_; // how often to recompute the precond from scratch
579 int recompute_newPrec_;// initial recomputing step
580 double adaptive_NewPrec_; // recompute preconditioner if residual is larger than this
581 int adaptns_; // run adaptive setup to create additional adaptns_ kernel vectors
582 int ncalls_NewPrec_; // how often computePreconditioner is called
583
584 // ---data related to the ML-hierarchy---
585 ML* ml_; // the ml handle
586 ML_Aggregate* ag_; // the aggregate handle
587 int ml_N_levels_; // max. number of levels
588 int ml_printlevel_; // ML's printlevel (0 - 10)
589 int ml_spatialDimension_; // spatial dimension of the problem
590 int ml_numPDE_; // number of pdes per node
591 int ml_dim_nullsp_; // dimension of nullspace
592 int ml_dim_nullsp2_; // dimension of nullspace
593 string ml_coarsentype_; // type of coarsening algorithm: Uncoupled MIS METIS VBMETIS
594 int ml_nnodeperagg_; // objective number of nodes per aggregate with coarsentypes METIS & VBMETIS
595 string ml_smoothertype_; // type of smoothing algorithm: SGS BSGS Jacobi
596 string ml_fsmoothertype_; // type of smoothing algorithm: SGS BSGS Jacobi on level 0
597 string ml_coarsesolve_; // type of coarse solver: SGS BSGS AmesosKLU Jacobi
598 int ml_maxcoarsesize_; // max. coarse grid size
599 int ml_nlevel_; // number of level generated by ML_Gen_MGHierarchy_UsingAggregation
600 int ml_coarsestlev_; // index of the coarsest level;
601 int ml_nblocks_;
602 int* ml_blocks_; // block information for Block-smoothers and aggregation scheme VBMETIS
603 int* ml_block_pde_; // information which pde each row belongs to
604 int nsmooth_fine_; // number of smoothing steps on finest level
605 int nsmooth_; // number of smoothing steps on intermediate levels
606 int nsmooth_coarse_; // number of smoothing steps on coarsest level
607
608 // ---the linear preconditioner---
609 ML_Epetra::MultiLevelOperator* ml_linPrec_; // the linear preconditioner class
610 Epetra_Map* ml_map_; // the linear operators range and domain map map
611
612 // ---matrix-free method---
613 const Epetra_CrsGraph* fineGraph_; // the fine grid graph (only used when ismatrixfree_=true)
614 ML_Epetra::CrsGraphWrapper* ml_graphwrap_; // in the matrix-free case this wraps the input fine level graph as an Epetra_RowMatrix
615 int nmatfreelevel_; // number of matfreelevels, should be equal to ml_nlevel_
616 ML_NOX::ML_Nox_MatrixfreeLevel** ml_matfreelevel_; // vector of matrix-free levels (including fine level)
617 double fd_alpha_; // FiniteDifferencing parameters (for matrixfree only)
618 double fd_beta_;
619 bool fd_centered_; // use centered finite differencing
620
621 // --- data special to the nonlinear preconditioner ---
622 int n_nlnlevel_;
623 ML_NOX::ML_Nox_NonlinearLevel** nlnLevel_; // ptr to vector of coarse interfaces
624 double FAS_normF_; // coarse NOX's convergence criteria
625 double FAS_nupdate_;
626 int FAS_maxiter_;
627 int FAS_prefinesmooth_;
628 int FAS_presmooth_;
629 int FAS_coarsesmooth_;
630 int FAS_postsmooth_;
631 int FAS_postfinesmooth_;
632 int FAS_maxcycle_;
633 NOX::Solver::Manager* noxsolver_;
634
635 bool useBroyden_; // use Broyden update for Newton's method
636 bool usenlnCG_fine_;
637 bool usenlnCG_;
638 bool usenlnCG_coarse_;
639 int nitersCG_fine_;
640 int nitersCG_;
641 int nitersCG_coarse_;
642
643 }; // class ML_Nox_Preconditioner : public virtual Epetra_Operator
644 } // namespace ML_NOX
645
646
647 #endif // ML_NOX_PRECONDITIONER_H
648 #endif // defined(HAVE_ML_NOX) && defined(HAVE_ML_EPETRA)