Debian Codegraph @

packages/trilinoscouplings/src/ifpack/Ifpack_ML.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 #ifndef IFPACK_ML_H
11 #define IFPACK_ML_H
12
13 #include "Ifpack_ConfigDefs.h"
14 #ifdef HAVE_IFPACK_ML
15
16 #include "Ifpack_Preconditioner.h"
17 #include "Epetra_Operator.h"
18 #include "Teuchos_ParameterList.hpp"
19 #include "Teuchos_RefCountPtr.hpp"
20 #include "ml_MultiLevelPreconditioner.h"
21
22 class Epetra_Map;
23 class Epetra_Time;
24 class Epetra_Comm;
25 class ML_BaseSolver;
26 class Epetra_LinearProblem;
27 class Epetra_RowMatrix;
28
29 //! Ifpack_ML: a class to use ML's multilevel methods as preconditioners.
30 /*!
31 Class Ifpack_ML enables the use of ML's multilevel methods as
32 Ifpack_Preconditioners.
33
34 Ifpack_ML is just a bare-bone wrap to ML. Currently, the
35 only parameter required recognized by SetParameters() is
36 \c "ml: solver type" (defaulted to \c
37 "ML_Klu"), which defined the ML solver. The Teuchos list
38 in input to SetParameters() is copied, then the copied list is
39 used to set the parameters of the ML object.
40
41 This class works with matrices whose communicator contains only one
42 process, that is, either serial matrices, or Ifpack_LocalFilter'd matrices.
43
44 \warning The number of flops is NOT updated.
45
46 \author Jonathan Hu.
47
48 \date Last update April, 2007.
49
50 */
51 class Ifpack_ML : public Ifpack_Preconditioner {
52
53 public:
54
55 //@{ \name Constructors/Destructors.
56
57 //! Constructor.
58 Ifpack_ML(Epetra_RowMatrix* Matrix);
59
60 //@{ \name Destructor.
61 //! Destructor
62 virtual ~Ifpack_ML() {};
63
64 //@}
65
66 //@{ \name Attribute set methods.
67
68 //! If true, transpose of this operator will be applied (not implemented).
69 /*! This flag allows the transpose of the given operator to be used
70 * implicitly.
71
72 \param
73 UseTranspose - (In) If true, multiply by the transpose of operator,
74 otherwise just use operator.
75
76 \return Integer error code, set to 0 if successful. Set to -1 if this
77 implementation does not support transpose.
78 */
79
80 virtual int SetUseTranspose(bool UseTranspose);
81 //@}
82
83 //@{ \name Mathematical functions.
84
85 //! Applies the matrix to an Epetra_MultiVector.
86 /*!
87 \param
88 X - (In) A Epetra_MultiVector of dimension NumVectors to multiply with
89 matrix.
90 \param
91 Y - (Out) A Epetra_MultiVector of dimension NumVectors containing result.
92
93 \return Integer error code, set to 0 if successful.
94 */
95 virtual int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
96
97 //! Applies the preconditioner to X, returns the result in Y.
98 /*!
99 \param
100 X - (In) A Epetra_MultiVector of dimension NumVectors to be preconditioned.
101 \param
102 Y - (Out) A Epetra_MultiVector of dimension NumVectors containing result.
103
104 \return Integer error code, set to 0 if successful.
105
106 \warning In order to work with AztecOO, any implementation of this method
107 must support the case where X and Y are the same object.
108 */
109 virtual int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
110
111 //! Returns the infinity norm of the global matrix (not implemented)
112 virtual double NormInf() const;
113 //@}
114
115 //@{ \name Attribute access functions
116
117 //! Returns a character string describing the operator
118 virtual const char * Label() const;
119
120 //! Returns the current UseTranspose setting.
121 virtual bool UseTranspose() const;
122
123 //! Returns true if the \e this object can provide an approximate Inf-norm, false otherwise.
124 virtual bool HasNormInf() const;
125
126 //! Returns a pointer to the Epetra_Comm communicator associated with this operator.
127 virtual const Epetra_Comm & Comm() const;
128
129 //! Returns the Epetra_Map object associated with the domain of this operator.
130 virtual const Epetra_Map & OperatorDomainMap() const;
131
132 //! Returns the Epetra_Map object associated with the range of this operator.
133 virtual const Epetra_Map & OperatorRangeMap() const;
134
135 //@}
136
137 //@{ \name Construction and application methods.
138
139 //! Returns \c true is the preconditioner has been successfully initialized.
140 virtual bool IsInitialized() const
141 {
142 return(IsInitialized_);
143 }
144
145 //! Initializes the preconditioners.
146 /*! \return
147 * 0 if successful, 1 if problems occurred.
148 */
149 virtual int Initialize();
150
151 //! Returns \c true if the preconditioner has been successfully computed.
152 virtual bool IsComputed() const
153 {
154 return(IsComputed_);
155 }
156
157 //! Computes the preconditioners.
158 /*! \return
159 * 0 if successful, 1 if problems occurred.
160 */
161 virtual int Compute();
162
163 //! Sets all the parameters for the preconditioner.
164 /*! Parameters currently supported:
165 * - \c "ml: solver type" : Specifies the solver type
166 * for ML. Default: \c ML_Klu.
167 *
168 * The input list will be copied, then passed to the ML
169 * object through ML::SetParameters().
170 */
171 virtual int SetParameters(Teuchos::ParameterList& List);
172
173 //@}
174
175 //@{ \name Query methods.
176
177 //! Returns a const reference to the internally stored matrix.
178 virtual const Epetra_RowMatrix& Matrix() const
179 {
180 return(*Matrix_);
181 }
182
183 //! Returns the estimated condition number, computes it if necessary.
184 virtual double Condest(const Ifpack_CondestType CT = Ifpack_Cheap,
185 const int MaxIters = 1550,
186 const double Tol = 1e-9,
187 Epetra_RowMatrix* Matrix= 0);
188
189 //! Returns the estimated condition number, never computes it.
190 virtual double Condest() const
191 {
192 return(Condest_);
193 }
194
195 //! Returns the number of calls to Initialize().
196 virtual int NumInitialize() const
197 {
198 return(NumInitialize_);
199 }
200
201 //! Returns the number of calls to Compute().
202 virtual int NumCompute() const
203 {
204 return(NumCompute_);
205 }
206
207 //! Returns the number of calls to ApplyInverse().
208 virtual int NumApplyInverse() const
209 {
210 return(NumApplyInverse_);
211 }
212
213 //! Returns the total time spent in Initialize().
214 virtual double InitializeTime() const
215 {
216 return(InitializeTime_);
217 }
218
219 //! Returns the total time spent in Compute().
220 virtual double ComputeTime() const
221 {
222 return(ComputeTime_);
223 }
224
225 //! Returns the total time spent in ApplyInverse().
226 virtual double ApplyInverseTime() const
227 {
228 return(ApplyInverseTime_);
229 }
230
231 //! Returns the number of flops in the initialization phase.
232 virtual double InitializeFlops() const
233 {
234 return(0.0);
235 }
236
237 //! Returns the total number of flops to computate the preconditioner.
238 virtual double ComputeFlops() const
239 {
240 return(ComputeFlops_);
241 }
242
243 //! Returns the total number of flops to apply the preconditioner.
244 virtual double ApplyInverseFlops() const
245 {
246 return(ApplyInverseFlops_);
247 }
248
249 // Returns a constant reference to the internally stored
250 virtual const Teuchos::ParameterList& List() const
251 {
252 return(List_);
253 }
254
255 //! Prints on ostream basic information about \c this object.
256 virtual std::ostream& Print(std::ostream& os) const;
257
258 //@}
259
260 protected:
261
262 //@{ \name Methods to get/set private data
263
264 //! Sets the label.
265 inline void SetLabel(const char* Label)
266 {
267 Label_ = Label;
268 }
269
270 //! Sets \c IsInitialized_.
271 inline void SetIsInitialized(const bool IsInitialized)
272 {
273 IsInitialized_ = IsInitialized;
274 }
275
276 //! Sets \c IsComputed_.
277 inline void SetIsComputed(const int IsComputed)
278 {
279 IsComputed_ = IsComputed;
280 }
281
282 //! Sets \c NumInitialize_.
283 inline void SetNumInitialize(const int NumInitialize)
284 {
285 NumInitialize_ = NumInitialize;
286 }
287
288 //! Sets \c NumCompute_.
289 inline void SetNumCompute(const int NumCompute)
290 {
291 NumCompute_ = NumCompute;
292 }
293
294 //! Sets \c NumApplyInverse_.
295 inline void SetNumApplyInverse(const int NumApplyInverse)
296 {
297 NumApplyInverse_ = NumApplyInverse;
298 }
299
300 //! Sets \c InitializeTime_.
301 inline void SetInitializeTime(const double InitializeTime)
302 {
303 InitializeTime_ = InitializeTime;
304 }
305
306 //! Sets \c ComputeTime_.
307 inline void SetComputeTime(const double ComputeTime)
308 {
309 ComputeTime_ = ComputeTime;
310 }
311
312 //! Sets \c ApplyInverseTime_.
313 inline void SetApplyInverseTime(const double ApplyInverseTime)
314 {
315 ApplyInverseTime_ = ApplyInverseTime;
316 }
317
318 //! Sets \c ComputeFlops_.
319 inline void SetComputeFlops(const double ComputeFlops)
320 {
321 ComputeFlops_ = ComputeFlops;
322 }
323
324 //! Sets \c ComputeFlops_.
325 inline void SetApplyInverseFlops(const double ApplyInverseFlops)
326 {
327 ApplyInverseFlops_ = ApplyInverseFlops;
328 }
329
330 //! Set \c List_.
331 inline void SetList(const Teuchos::ParameterList& List)
332 {
333 List_ = List;
334 }
335 //@}
336
337 private:
338
339 //! Pointers to the matrix to be preconditioned.
340 Teuchos::RefCountPtr<const Epetra_RowMatrix> Matrix_;
341
342 //! ML solver, use to apply the inverse of the local matrix.
343 Teuchos::RefCountPtr<ML_Epetra::MultiLevelPreconditioner> MLPrec_;
344 //! Contains a copy of the input parameter list.
345 Teuchos::ParameterList List_;
346
347 //! Contains the label of \c this object.
348 string Label_;
349 //! If true, the preconditioner has been successfully initialized.
350 bool IsInitialized_;
351 //! If true, the preconditioner has been successfully computed.
352 bool IsComputed_;
353 //! If true, the preconditioner solves for the transpose of the matrix.
354 bool UseTranspose_;
355
356 //! Contains the number of successful calls to Initialize().
357 int NumInitialize_;
358 //! Contains the number of successful call to Compute().
359 int NumCompute_;
360 //! Contains the number of successful call to ApplyInverse().
361 mutable int NumApplyInverse_;
362
363 //! Contains the time for all successful calls to Initialize().
364 double InitializeTime_;
365 //! Contains the time for all successful calls to Compute().
366 double ComputeTime_;
367 //! Contains the time for all successful calls to ApplyInverse().
368 mutable double ApplyInverseTime_;
369 //! Time object.
370 Teuchos::RefCountPtr<Epetra_Time> Time_;
371
372 //! Contains the number of flops for Compute().
373 double ComputeFlops_;
374 //! Contain sthe number of flops for ApplyInverse().
375 double ApplyInverseFlops_;
376
377 //! Contains the estimated condition number.
378 double Condest_;
379 };
380
381 #endif // HAVE_IFPACK_ML
382 #endif // IFPACK_ML_H