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-2022 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  //=============================================================================
54  //=============================================================================
56  {
57  public:
60  {
61  // Initialise pointers
63  Epetra_matrix_pt = 0;
64  }
65 
68  {
70  }
71 
76 
79  {
80  // delete the Epetra preconditioner
83 
84  // delete the epetra matrix
85  delete Epetra_matrix_pt;
86  Epetra_matrix_pt = 0;
87  }
88 
91 
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 
106  void setup();
107 
111  void setup(Epetra_CrsMatrix* epetra_matrix_pt);
112 
115 
119  {
121  }
122 
126  {
128  }
129 
130  protected:
134  Epetra_CrsMatrix* epetra_matrix_pt) = 0;
135 
139 
142  Epetra_CrsMatrix* Epetra_matrix_pt;
143  };
144 
145 
146  //============================================================================
150  //============================================================================
152  {
153  public:
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 
168 
171 
173  /*void operator=(const TrilinosMLPreconditioner&) = delete;*/
174 
178  {
179  ML_Epetra::SetDefaults("NSSA", ML_parameters);
180  }
181 
182 
186  {
187  ML_Epetra::SetDefaults("DD", ML_parameters);
188  }
189 
190 
194  {
195  ML_Epetra::SetDefaults("DD-ML", ML_parameters);
196  }
197 
201  {
202  ML_Epetra::SetDefaults("SA", ML_parameters);
203  }
204 
206  void set_max_levels(int max_levels)
207  {
208  ML_parameters.set("max levels", max_levels);
209  }
210 
212  void set_n_cycles(int n_cycles)
213  {
214  ML_parameters.set("cycle applications", n_cycles);
215  }
216 
218  void set_smoother_damping(double smoother_damping)
219  {
220  ML_parameters.set("smoother: damping factor", smoother_damping);
221  }
222 
224  void set_smoother_sweeps(int smoother_sweeps)
225  {
226  ML_parameters.set("smoother: sweeps", smoother_sweeps);
227  }
228 
231  {
232  ML_parameters.set("smoother: type", "Jacobi");
233  }
234 
237  {
238  ML_parameters.set("smoother: type", "symmetric Gauss-Seidel");
239  }
240 
242  void set_output(int output)
243  {
244  ML_parameters.set("output", output);
245  }
246 
247 
250  static int Default_n_cycles;
251 
252  protected:
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  //============================================================================
266  //============================================================================
268  {
269  public:
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 
284 
287 
289  /*void operator=(const TrilinosIFPACKPreconditioner&) = delete;*/
290 
293  {
294  Preconditioner_type = "ILU";
295  }
296 
299  {
300  Preconditioner_type = "ILUT";
301  }
302 
305  {
306  return ILU_fill_level;
307  }
308 
310  double& ilut_fill_level()
311  {
312  return ILUT_fill_level;
313  }
314 
317  {
318  return Absolute_threshold;
319  }
320 
323  {
324  return Relative_threshold;
325  }
326 
327  protected:
330  void setup_trilinos_preconditioner(Epetra_CrsMatrix* epetra_matrix_pt);
331 
334 
337 
340 
342  int Overlap;
343 
346 
349  };
350 } // namespace oomph
351 #endif
Definition: double_vector.h:58
Definition: preconditioner.h:54
Definition: trilinos_preconditioners.h:268
double & ilut_fill_level()
Access function for ILUT_fill_level.
Definition: trilinos_preconditioners.h:310
virtual ~TrilinosIFPACKPreconditioner()
Destructor – empty, cleanup is done in base class.
Definition: trilinos_preconditioners.h:283
double Absolute_threshold
Value of absolute threshold, used to peturb diagonal.
Definition: trilinos_preconditioners.h:345
int & ilu_fill_level()
Access function for ILU_fill_level.
Definition: trilinos_preconditioners.h:304
double & absolute_threshold()
Access function for the absolute threshold.
Definition: trilinos_preconditioners.h:316
TrilinosIFPACKPreconditioner()
Constructor.
Definition: trilinos_preconditioners.h:271
string Preconditioner_type
Type of ILU preconditioner.
Definition: trilinos_preconditioners.h:333
int ILU_fill_level
Level of fill for "ILU".
Definition: trilinos_preconditioners.h:336
void set_preconditioner_ILU()
Broken assignment operator.
Definition: trilinos_preconditioners.h:292
void setup_trilinos_preconditioner(Epetra_CrsMatrix *epetra_matrix_pt)
Definition: trilinos_preconditioners.cc:237
void set_preconditioner_ILUT()
Function to set Preconditioner_type to "ILUT".
Definition: trilinos_preconditioners.h:298
double ILUT_fill_level
Level of fill for "ILUT".
Definition: trilinos_preconditioners.h:339
double Relative_threshold
Value of relative threshold, used to pertub diagonal.
Definition: trilinos_preconditioners.h:348
int Overlap
Value of overlap level - used in parallel ILU.
Definition: trilinos_preconditioners.h:342
double & relative_threshold()
Access function for the relative threshold.
Definition: trilinos_preconditioners.h:322
TrilinosIFPACKPreconditioner(const TrilinosIFPACKPreconditioner &)=delete
Broken copy constructor.
Definition: trilinos_preconditioners.h:152
void set_smoother_sweeps(int smoother_sweeps)
Function to set Smoother_sweeps.
Definition: trilinos_preconditioners.h:224
void set_smoother_gauss_seidel()
Function to set smoother type to "symmetric Gauss-Seidel".
Definition: trilinos_preconditioners.h:236
void set_max_levels(int max_levels)
Function to set maximum number of levels.
Definition: trilinos_preconditioners.h:206
virtual ~TrilinosMLPreconditioner()
Destructor empty – clean up is done in base class.
Definition: trilinos_preconditioners.h:167
void set_n_cycles(int n_cycles)
Function to set the number of cycles used.
Definition: trilinos_preconditioners.h:212
static int Default_n_cycles
Definition: trilinos_preconditioners.h:250
TrilinosMLPreconditioner()
Definition: trilinos_preconditioners.h:157
Teuchos::ParameterList ML_parameters
Definition: trilinos_preconditioners.h:258
void set_NSSA_default_values()
Broken assignment operator.
Definition: trilinos_preconditioners.h:177
void set_DDML_default_values()
Definition: trilinos_preconditioners.h:193
void set_smoother_damping(double smoother_damping)
Function to set Smoother_damping.
Definition: trilinos_preconditioners.h:218
void set_output(int output)
Function to set output - controls level of information output by ML.
Definition: trilinos_preconditioners.h:242
void set_SA_default_values()
Definition: trilinos_preconditioners.h:200
void set_DD_default_values()
Definition: trilinos_preconditioners.h:185
TrilinosMLPreconditioner(const TrilinosMLPreconditioner &)=delete
Broken copy constructor.
void setup_trilinos_preconditioner(Epetra_CrsMatrix *epetra_matrix_pt)
Definition: trilinos_preconditioners.cc:196
void set_smoother_jacobi()
Function to set smoother type to "Jacobi".
Definition: trilinos_preconditioners.h:230
Base class for Trilinos preconditioners as oomph-lib preconditioner.
Definition: trilinos_preconditioners.h:56
Epetra_Operator * Epetra_preconditioner_pt
Definition: trilinos_preconditioners.h:138
Epetra_Operator * epetra_operator_pt() const
Definition: trilinos_preconditioners.h:125
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
applies the preconditioner
Definition: trilinos_preconditioners.cc:126
Epetra_Operator *& epetra_operator_pt()
Definition: trilinos_preconditioners.h:118
Epetra_CrsMatrix * Epetra_matrix_pt
Definition: trilinos_preconditioners.h:142
virtual ~TrilinosPreconditionerBase()
Destructor.
Definition: trilinos_preconditioners.h:67
void clean_up_memory()
deletes the preconditioner, matrices and maps
Definition: trilinos_preconditioners.h:78
static double Cumulative_preconditioner_solve_time
Definition: trilinos_preconditioners.h:75
void setup()
Broken assignment operator.
Definition: trilinos_preconditioners.cc:53
virtual void setup_trilinos_preconditioner(Epetra_CrsMatrix *epetra_matrix_pt)=0
TrilinosPreconditionerBase()
Constructor.
Definition: trilinos_preconditioners.h:59
TrilinosPreconditionerBase(const TrilinosPreconditionerBase &)=delete
Broken copy constructor.
r
Definition: UniformPSDSelfTest.py:20
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
void output(std::ostream &outfile)
Output with default number of plot points.
Definition: gen_axisym_advection_diffusion_elements.h:161