trilinos_preconditioners.h
Go to the documentation of this file.
1 // LIC// ====================================================================
2 // LIC// This file forms part of oomph-lib, the object-oriented,
3 // LIC// multi-physics finite-element library, available
4 // LIC// at http://www.oomph-lib.org.
5 // LIC//
6 // LIC// Copyright (C) 2006-2023 Matthias Heil and Andrew Hazel
7 // LIC//
8 // LIC// This library is free software; you can redistribute it and/or
9 // LIC// modify it under the terms of the GNU Lesser General Public
10 // LIC// License as published by the Free Software Foundation; either
11 // LIC// version 2.1 of the License, or (at your option) any later version.
12 // LIC//
13 // LIC// This library is distributed in the hope that it will be useful,
14 // LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // LIC// Lesser General Public License for more details.
17 // LIC//
18 // LIC// You should have received a copy of the GNU Lesser General Public
19 // LIC// License along with this library; if not, write to the Free Software
20 // LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 // LIC// 02110-1301 USA.
22 // LIC//
23 // LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24 // LIC//
25 // LIC//====================================================================
26 #ifndef OOMPH_TRILINOS_OPERATORS_HEADER
27 #define OOMPH_TRILINOS_OPERATORS_HEADER
28 
29 // Config header generated by autoconfig
30 #ifdef HAVE_CONFIG_H
31 #include <oomph-lib-config.h>
32 #endif
33 
34 #ifdef OOMPH_HAS_MPI
35 #include "mpi.h"
36 #endif
37 
38 // Needed in trilinos (as of gcc 4.6.* or so...)
39 #include <cstddef>
40 
41 // trilinos headers
42 #include "ml_include.h"
43 #include "ml_MultiLevelPreconditioner.h"
44 #include "Ifpack.h"
45 
46 // oomph-lib headers
47 #include "trilinos_helpers.h"
48 #include "preconditioner.h"
49 
50 namespace oomph
51 {
52  //=============================================================================
53  /// Base class for Trilinos preconditioners as oomph-lib preconditioner.
54  //=============================================================================
56  {
57  public:
58  /// Constructor.
60  {
61  // Initialise pointers
63  Epetra_matrix_pt = 0;
64  }
65 
66  /// Destructor.
68  {
70  }
71 
72  /// Static double that accumulates the preconditioner
73  /// solve time of all instantiations of this class. Reset
74  /// it manually, e.g. after every Newton solve.
76 
77  /// deletes the preconditioner, matrices and maps
79  {
80  // delete the Epetra preconditioner
83 
84  // delete the epetra matrix
85  delete Epetra_matrix_pt;
86  Epetra_matrix_pt = 0;
87  }
88 
89  /// Broken copy constructor.
91 
92  /// Broken assignment operator.
93  // Commented out broken assignment operator because this can lead to a
94  // conflict warning when used in the virtual inheritence hierarchy.
95  // Essentially the compiler doesn't realise that two separate
96  // implementations of the broken function are the same and so, quite
97  // rightly, it shouts.
98  /*void operator=(const TrilinosPreconditionerBase&) = delete;*/
99 
100  /// Function to set up a preconditioner for the linear system
101  /// defined by matrix_pt. This function must be called before using
102  /// preconditioner_solve.
103  /// \b NOTE 1. matrix_pt must point to an object of class CRDoubleMatrix or
104  /// DistributedCRDoubleMatrix
105  /// This method should be called by oomph-lib solvers and preconditioners
106  void setup();
107 
108  /// Function to setup a preconditioner for the linear system defined
109  /// by the oomph-lib oomph_matrix_pt and Epetra epetra_matrix_pt matrices.
110  /// This method is called by Trilinos solvers.
111  void setup(Epetra_CrsMatrix* epetra_matrix_pt);
112 
113  /// applies the preconditioner
115 
116  /// Access function to Epetra_preconditioner_pt.
117  /// For use with \c TrilinosAztecOOSolver
118  Epetra_Operator*& epetra_operator_pt()
119  {
121  }
122 
123  /// Access function to Epetra_preconditioner_pt (const version)
124  /// For use with \c TrilinosAztecOOSolver
125  Epetra_Operator* epetra_operator_pt() const
126  {
128  }
129 
130  protected:
131  /// Function to set up a specific Trilinos preconditioner.
132  /// This is called by setup(...).
134  Epetra_CrsMatrix* epetra_matrix_pt) = 0;
135 
136  /// The preconditioner which will be set up using function
137  /// setup_trilinos_preconditioner(...)
138  Epetra_Operator* Epetra_preconditioner_pt;
139 
140  /// Pointer used to store the epetra matrix - only used when this
141  /// preconditioner is setup using the oomph-lib interface
142  Epetra_CrsMatrix* Epetra_matrix_pt;
143  };
144 
145 
146  //============================================================================
147  /// An interface to the Trilinos ML class - provides a function
148  /// to construct a serial ML object, and functions to modify some
149  /// of the ML paramaters.
150  //============================================================================
152  {
153  public:
154  /// Constructor. Build with Smooth Aggretation (SA) default
155  /// settings, but our own default number of V cycles (initialised
156  /// to 1 to replicate TrilinosML's own behaviour).
158  {
159  // set default values
160  ML_Epetra::SetDefaults("SA", ML_parameters);
161 
162  // Set number of MG cycles performed in preconditioner
163  ML_parameters.set("cycle applications", Default_n_cycles);
164  }
165 
166  /// Destructor empty -- clean up is done in base class
168 
169  /// Broken copy constructor.
171 
172  /// Broken assignment operator.
173  /*void operator=(const TrilinosMLPreconditioner&) = delete;*/
174 
175  /// Set control flags to values for Petrov-Galerkin
176  /// preconditioning - for non symmetric systems
178  {
179  ML_Epetra::SetDefaults("NSSA", ML_parameters);
180  }
181 
182 
183  /// Set control flags to values for classical smoothed aggregation-
184  /// based 2-level domain decomposition
186  {
187  ML_Epetra::SetDefaults("DD", ML_parameters);
188  }
189 
190 
191  /// Set control flags to values 3-level algebraic domain
192  /// decomposition
194  {
195  ML_Epetra::SetDefaults("DD-ML", ML_parameters);
196  }
197 
198  /// Set control flags to values for classical smoothed
199  /// aggregation preconditioning
201  {
202  ML_Epetra::SetDefaults("SA", ML_parameters);
203  }
204 
205  /// Function to set maximum number of levels
206  void set_max_levels(int max_levels)
207  {
208  ML_parameters.set("max levels", max_levels);
209  }
210 
211  /// Function to set the number of cycles used
212  void set_n_cycles(int n_cycles)
213  {
214  ML_parameters.set("cycle applications", n_cycles);
215  }
216 
217  /// Function to set Smoother_damping
218  void set_smoother_damping(double smoother_damping)
219  {
220  ML_parameters.set("smoother: damping factor", smoother_damping);
221  }
222 
223  /// Function to set Smoother_sweeps
224  void set_smoother_sweeps(int smoother_sweeps)
225  {
226  ML_parameters.set("smoother: sweeps", smoother_sweeps);
227  }
228 
229  /// Function to set smoother type to "Jacobi"
231  {
232  ML_parameters.set("smoother: type", "Jacobi");
233  }
234 
235  /// Function to set smoother type to "symmetric Gauss-Seidel"
237  {
238  ML_parameters.set("smoother: type", "symmetric Gauss-Seidel");
239  }
240 
241  /// Function to set output - controls level of information output by ML
242  void set_output(int output)
243  {
244  ML_parameters.set("output", output);
245  }
246 
247 
248  /// Default number of V cycles (one to be consistent with
249  /// previous default) (It's an int because Trilinos wants it to be!)
250  static int Default_n_cycles;
251 
252  protected:
253  /// Function to set up the ML preconditioner. It is assumed
254  /// Trilinos_matrix_pt points to a suitable matrix.
255  void setup_trilinos_preconditioner(Epetra_CrsMatrix* epetra_matrix_pt);
256 
257  // Parameter list of control flags for the preconditioner
258  Teuchos::ParameterList ML_parameters;
259  };
260 
261 
262  //============================================================================
263  /// An interface to the Trilinos IFPACK class- provides a function
264  /// to construct an IFPACK object, and functions to modify some
265  /// of the IFPACK paramaters.
266  //============================================================================
268  {
269  public:
270  /// Constructor.
272  {
273  // set default values
274  Preconditioner_type = "ILU";
275  ILU_fill_level = 0;
276  ILUT_fill_level = 1.0;
277  Overlap = 0;
278  Absolute_threshold = 0.0;
279  Relative_threshold = 1.0;
280  }
281 
282  /// Destructor -- empty, cleanup is done in base class
284 
285  /// Broken copy constructor.
287 
288  /// Broken assignment operator.
289  /*void operator=(const TrilinosIFPACKPreconditioner&) = delete;*/
290 
291  /// Function to set Preconditioner_type to "ILU"
293  {
294  Preconditioner_type = "ILU";
295  }
296 
297  /// Function to set Preconditioner_type to "ILUT"
299  {
300  Preconditioner_type = "ILUT";
301  }
302 
303  /// Access function for ILU_fill_level
305  {
306  return ILU_fill_level;
307  }
308 
309  /// Access function for ILUT_fill_level
310  double& ilut_fill_level()
311  {
312  return ILUT_fill_level;
313  }
314 
315  /// Access function for the absolute threshold
317  {
318  return Absolute_threshold;
319  }
320 
321  /// Access function for the relative threshold
323  {
324  return Relative_threshold;
325  }
326 
327  protected:
328  /// Function to set up an IFPACK preconditioner. It is assumed
329  /// Trilinos_matrix_pt points to a suitable matrix.
330  void setup_trilinos_preconditioner(Epetra_CrsMatrix* epetra_matrix_pt);
331 
332  /// Type of ILU preconditioner
334 
335  /// Level of fill for "ILU"
337 
338  /// Level of fill for "ILUT"
340 
341  /// Value of overlap level - used in parallel ILU
342  int Overlap;
343 
344  /// Value of absolute threshold, used to peturb diagonal
346 
347  /// Value of relative threshold, used to pertub diagonal
349  };
350 } // namespace oomph
351 #endif
A vector in the mathematical sense, initially developed for linear algebra type applications....
Definition: double_vector.h:58
Preconditioner base class. Gives an interface to call all other preconditioners through and stores th...
An interface to the Trilinos IFPACK class- provides a function to construct an IFPACK object,...
double & ilut_fill_level()
Access function for ILUT_fill_level.
virtual ~TrilinosIFPACKPreconditioner()
Destructor – empty, cleanup is done in base class.
double Absolute_threshold
Value of absolute threshold, used to peturb diagonal.
int & ilu_fill_level()
Access function for ILU_fill_level.
double & absolute_threshold()
Access function for the absolute threshold.
string Preconditioner_type
Type of ILU preconditioner.
int ILU_fill_level
Level of fill for "ILU".
void set_preconditioner_ILU()
Broken assignment operator.
void setup_trilinos_preconditioner(Epetra_CrsMatrix *epetra_matrix_pt)
Function to set up an IFPACK preconditioner. It is assumed Trilinos_matrix_pt points to a suitable ma...
void set_preconditioner_ILUT()
Function to set Preconditioner_type to "ILUT".
double ILUT_fill_level
Level of fill for "ILUT".
double Relative_threshold
Value of relative threshold, used to pertub diagonal.
int Overlap
Value of overlap level - used in parallel ILU.
double & relative_threshold()
Access function for the relative threshold.
TrilinosIFPACKPreconditioner(const TrilinosIFPACKPreconditioner &)=delete
Broken copy constructor.
An interface to the Trilinos ML class - provides a function to construct a serial ML object,...
void set_smoother_sweeps(int smoother_sweeps)
Function to set Smoother_sweeps.
void set_smoother_gauss_seidel()
Function to set smoother type to "symmetric Gauss-Seidel".
void set_max_levels(int max_levels)
Function to set maximum number of levels.
virtual ~TrilinosMLPreconditioner()
Destructor empty – clean up is done in base class.
void set_n_cycles(int n_cycles)
Function to set the number of cycles used.
static int Default_n_cycles
Default number of V cycles (one to be consistent with previous default) (It's an int because Trilinos...
TrilinosMLPreconditioner()
Constructor. Build with Smooth Aggretation (SA) default settings, but our own default number of V cyc...
void set_NSSA_default_values()
Broken assignment operator.
void set_DDML_default_values()
Set control flags to values 3-level algebraic domain decomposition.
void set_smoother_damping(double smoother_damping)
Function to set Smoother_damping.
void set_output(int output)
Function to set output - controls level of information output by ML.
void set_SA_default_values()
Set control flags to values for classical smoothed aggregation preconditioning.
void set_DD_default_values()
Set control flags to values for classical smoothed aggregation- based 2-level domain decomposition.
TrilinosMLPreconditioner(const TrilinosMLPreconditioner &)=delete
Broken copy constructor.
void setup_trilinos_preconditioner(Epetra_CrsMatrix *epetra_matrix_pt)
Function to set up the ML preconditioner. It is assumed Trilinos_matrix_pt points to a suitable matri...
void set_smoother_jacobi()
Function to set smoother type to "Jacobi".
Base class for Trilinos preconditioners as oomph-lib preconditioner.
Epetra_Operator * Epetra_preconditioner_pt
The preconditioner which will be set up using function setup_trilinos_preconditioner(....
Epetra_Operator * epetra_operator_pt() const
Access function to Epetra_preconditioner_pt (const version) For use with TrilinosAztecOOSolver.
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
applies the preconditioner
Epetra_Operator *& epetra_operator_pt()
Access function to Epetra_preconditioner_pt. For use with TrilinosAztecOOSolver.
Epetra_CrsMatrix * Epetra_matrix_pt
Pointer used to store the epetra matrix - only used when this preconditioner is setup using the oomph...
void clean_up_memory()
deletes the preconditioner, matrices and maps
static double Cumulative_preconditioner_solve_time
Static double that accumulates the preconditioner solve time of all instantiations of this class....
void setup()
Broken assignment operator.
virtual void setup_trilinos_preconditioner(Epetra_CrsMatrix *epetra_matrix_pt)=0
Function to set up a specific Trilinos preconditioner. This is called by setup(......
TrilinosPreconditionerBase(const TrilinosPreconditionerBase &)=delete
Broken copy constructor.
void output()
Doc the command line arguments.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...