Ifpack2 Templated Preconditioning Package  Version 1.0
Ifpack2_Hypre_FunctionParameters.hpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 
44 #ifndef IFPACK2_HYPRE_FUNCTIONPARAMETERS_HPP
45 #define IFPACK2_HYPRE_FUNCTIONPARAMETERS_HPP
46 
47 #include "Ifpack2_ConfigDefs.hpp"
48 #if defined(HAVE_IFPACK2_HYPRE) && defined(HAVE_IFPACK2_MPI)
49 
50 #include <sstream>
51 #include "HYPRE_utilities.h"
52 #include "HYPRE_IJ_mv.h"
53 #include "HYPRE_parcsr_ls.h"
54 #include "krylov.h"
55 #include "_hypre_parcsr_mv.h"
56 #include "_hypre_IJ_mv.h"
57 #include "HYPRE_parcsr_mv.h"
58 #include "HYPRE.h"
59 
60 // Hypre forward declarations (to avoid downstream header pollution)
61 struct hypre_IJMatrix_struct;
62 typedef struct hypre_IJMatrix_struct *HYPRE_IJMatrix;
63 struct hypre_IJVector_struct;
64 typedef struct hypre_IJVector_struct *HYPRE_IJVector;
65 struct hypre_ParCSRMatrix_struct;
66 typedef struct hypre_ParCSRMatrix_struct* HYPRE_ParCSRMatrix;
67 struct hypre_ParVector_struct;
68 typedef struct hypre_ParVector_struct * HYPRE_ParVector;
69 struct hypre_Solver_struct;
70 typedef struct hypre_Solver_struct *HYPRE_Solver;
71 struct hypre_ParVector_struct;
72 typedef struct hypre_ParVector_struct hypre_ParVector;
73 //struct hypre_Vector;
74 
75 #ifndef HYPRE_ENUMS
76 #define HYPRE_ENUMS
77  enum Hypre_Solver{
79  BoomerAMG,
80  ParaSails,
81  Euclid,
82  AMS,
83  Hybrid,
84  PCG,
85  GMRES,
86  FlexGMRES,
87  LGMRES,
88  BiCGSTAB
89  };
90 
92  enum Hypre_Chooser{
93  Hypre_Is_Solver,
94  Hypre_Is_Preconditioner
95  };
96 #endif //HYPRE_ENUMS
97 
98 // The Python script that generates the ParameterMap needs to be after these typedefs
99 typedef HYPRE_Int (*int_func)(HYPRE_Solver, HYPRE_Int);
100 typedef HYPRE_Int (*double_func)(HYPRE_Solver, double);
101 typedef HYPRE_Int (*double_int_func)(HYPRE_Solver, double, HYPRE_Int);
102 typedef HYPRE_Int (*int_int_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Int);
103 typedef HYPRE_Int (*int_star_func)(HYPRE_Solver, HYPRE_Int*);
104 typedef HYPRE_Int (*int_star_star_func)(HYPRE_Solver, HYPRE_Int**);
105 typedef HYPRE_Int (*double_star_func)(HYPRE_Solver, double*);
106 typedef HYPRE_Int (*int_int_double_double_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Int, double, double);
107 typedef HYPRE_Int (*int_int_int_double_int_int_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Int, HYPRE_Int, double, HYPRE_Int, HYPRE_Int);
108 typedef HYPRE_Int (*char_star_func)(HYPRE_Solver, char*);
109 
110 
111 namespace Ifpack2 {
112 
113  void IFPACK2_CHK_ERRV(int code);
114 
115  void IFPACK2_CHK_ERR(int code);
116 
118  class FunctionParameter {
119  public:
121  FunctionParameter(Hypre_Chooser chooser, int_func funct, HYPRE_Int param1) :
122  chooser_(chooser),
123  option_(0),
124  int_func_(funct),
125  int_param1_(param1) {}
126 
127  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1) :
128  chooser_(chooser),
129  option_(0),
130  int_func_(hypreMapIntFunc_.at(funct_name)),
131  int_param1_(param1) {}
132 
134  FunctionParameter(Hypre_Chooser chooser, double_func funct, double param1):
135  chooser_(chooser),
136  option_(1),
137  double_func_(funct),
138  double_param1_(param1) {}
139 
140  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, double param1):
141  chooser_(chooser),
142  option_(1),
143  double_func_(hypreMapDoubleFunc_.at(funct_name)),
144  double_param1_(param1) {}
145 
147  FunctionParameter(Hypre_Chooser chooser, double_int_func funct, double param1, HYPRE_Int param2):
148  chooser_(chooser),
149  option_(2),
150  double_int_func_(funct),
151  int_param1_(param2),
152  double_param1_(param1) {}
153 
154  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, double param1, HYPRE_Int param2):
155  chooser_(chooser),
156  option_(2),
157  double_int_func_(hypreMapDoubleIntFunc_.at(funct_name)),
158  int_param1_(param2),
159  double_param1_(param1) {}
160 
162  FunctionParameter(Hypre_Chooser chooser, int_int_func funct, HYPRE_Int param1, HYPRE_Int param2):
163  chooser_(chooser),
164  option_(3),
165  int_int_func_(funct),
166  int_param1_(param1),
167  int_param2_(param2) {}
168 
169  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1, HYPRE_Int param2):
170  chooser_(chooser),
171  option_(3),
172  int_int_func_(hypreMapIntIntFunc_.at(funct_name)),
173  int_param1_(param1),
174  int_param2_(param2) {}
175 
177  FunctionParameter(Hypre_Chooser chooser, int_star_func funct, HYPRE_Int *param1):
178  chooser_(chooser),
179  option_(4),
180  int_star_func_(funct),
181  int_star_param_(param1) {}
182 
183  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int *param1):
184  chooser_(chooser),
185  option_(4),
186  int_star_func_(hypreMapIntStarFunc_.at(funct_name)),
187  int_star_param_(param1) {}
188 
190  FunctionParameter(Hypre_Chooser chooser, double_star_func funct, double* param1):
191  chooser_(chooser),
192  option_(5),
193  double_star_func_(funct),
194  double_star_param_(param1) {}
195 
196  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, double* param1):
197  chooser_(chooser),
198  option_(5),
199  double_star_func_(hypreMapDoubleStarFunc_.at(funct_name)),
200  double_star_param_(param1) {}
201 
203  FunctionParameter(Hypre_Chooser chooser, int_int_double_double_func funct, HYPRE_Int param1, HYPRE_Int param2, double param3, double param4):
204  chooser_(chooser),
205  option_(6),
206  int_int_double_double_func_(funct),
207  int_param1_(param1),
208  int_param2_(param2),
209  double_param1_(param3),
210  double_param2_(param4) {}
211 
212  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1, HYPRE_Int param2, double param3, double param4):
213  chooser_(chooser),
214  option_(6),
215  int_int_double_double_func_(hypreMapIntIntDoubleDoubleFunc_.at(funct_name)),
216  int_param1_(param1),
217  int_param2_(param2),
218  double_param1_(param3),
219  double_param2_(param4) {}
220 
222  FunctionParameter(Hypre_Chooser chooser, int_star_star_func funct, HYPRE_Int ** param1):
223  chooser_(chooser),
224  option_(7),
225  int_star_star_func_(funct),
226  int_star_star_param_(param1) {}
227 
228  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int** param1):
229  chooser_(chooser),
230  option_(7),
231  int_star_star_func_(hypreMapIntStarStarFunc_.at(funct_name)),
232  int_star_star_param_(param1) {}
233 
235  FunctionParameter(Hypre_Chooser chooser, int_int_int_double_int_int_func funct, HYPRE_Int param1, HYPRE_Int param2, HYPRE_Int param3, double param4, HYPRE_Int param5, HYPRE_Int param6):
236  chooser_(chooser),
237  option_(8),
238  int_int_int_double_int_int_func_(funct),
239  int_param1_(param1),
240  int_param2_(param2),
241  int_param3_(param3),
242  int_param4_(param5),
243  int_param5_(param6),
244  double_param1_(param4) {}
245 
246  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1, HYPRE_Int param2, HYPRE_Int param3, double param4, HYPRE_Int param5, HYPRE_Int param6):
247  chooser_(chooser),
248  option_(8),
249  int_int_int_double_int_int_func_(hypreMapIntIntIntDoubleIntIntFunc_.at(funct_name)),
250  int_param1_(param1),
251  int_param2_(param2),
252  int_param3_(param3),
253  int_param4_(param5),
254  int_param5_(param6),
255  double_param1_(param4) {}
256 
258  FunctionParameter(Hypre_Chooser chooser, char_star_func funct, char *param1):
259  chooser_(chooser),
260  option_(9),
261  char_star_func_(funct),
262  char_star_param_(param1) {}
263 
264  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, char *param1):
265  chooser_(chooser),
266  option_(9),
267  char_star_func_(hypreMapCharStarFunc_.at(funct_name)),
268  char_star_param_(param1) {}
269 
271  int CallFunction(HYPRE_Solver solver, HYPRE_Solver precond) {
272  if(chooser_ == Hypre_Is_Solver){
273  if(option_ == 0){
274  return int_func_(solver, int_param1_);
275  } else if(option_ == 1){
276  return double_func_(solver, double_param1_);
277  } else if(option_ == 2){
278  return double_int_func_(solver, double_param1_, int_param1_);
279  } else if (option_ == 3){
280  return int_int_func_(solver, int_param1_, int_param2_);
281  } else if (option_ == 4){
282  return int_star_func_(solver, int_star_param_);
283  } else if (option_ == 5){
284  return double_star_func_(solver, double_star_param_);
285  } else if (option_ == 6) {
286  return int_int_double_double_func_(solver, int_param1_, int_param2_, double_param1_, double_param2_);
287  } else if (option_ == 7) {
288  return int_star_star_func_(solver, int_star_star_param_);
289  } else if (option_ == 8) {
290  return int_int_int_double_int_int_func_(solver, int_param1_, int_param2_, int_param3_, double_param1_, int_param4_, int_param5_);
291  } else if (option_ == 9) {
292  return char_star_func_(solver, char_star_param_);
293  } else {
294  IFPACK2_CHK_ERR(-2);
295  }
296  } else {
297  if(option_ == 0){
298  return int_func_(precond, int_param1_);
299  } else if(option_ == 1){
300  return double_func_(precond, double_param1_);
301  } else if(option_ == 2){
302  return double_int_func_(precond, double_param1_, int_param1_);
303  } else if(option_ == 3) {
304  return int_int_func_(precond, int_param1_, int_param2_);
305  } else if(option_ == 4) {
306  return int_star_func_(precond, int_star_param_);
307  } else if(option_ == 5) {
308  return double_star_func_(precond, double_star_param_);
309  } else if (option_ == 6) {
310  return int_int_double_double_func_(precond, int_param1_, int_param2_, double_param1_, double_param2_);
311  } else if (option_ == 7) {
312  return int_star_star_func_(precond, int_star_star_param_);
313  } else if (option_ == 8) {
314  return int_int_int_double_int_int_func_(precond, int_param1_, int_param2_, int_param3_, double_param1_, int_param4_, int_param5_);
315  } else if (option_ == 9) {
316  return char_star_func_(solver, char_star_param_);
317  } else {
318  IFPACK2_CHK_ERR(-2);
319  }
320  }
321  return 0;
322  }
323 
324  static bool isFuncIntInt(std::string funct_name) {
325  return (hypreMapIntIntFunc_.find(funct_name) != hypreMapIntIntFunc_.end());
326  }
327 
328  static bool isFuncIntIntDoubleDouble(std::string funct_name) {
329  return (hypreMapIntIntDoubleDoubleFunc_.find(funct_name) != hypreMapIntIntDoubleDoubleFunc_.end());
330  }
331 
332  static bool isFuncIntIntIntDoubleIntInt(std::string funct_name) {
333  return (hypreMapIntIntIntDoubleIntIntFunc_.find(funct_name) != hypreMapIntIntIntDoubleIntIntFunc_.end());
334  }
335 
336  static bool isFuncIntStarStar(std::string funct_name) {
337  return (hypreMapIntStarStarFunc_.find(funct_name) != hypreMapIntStarStarFunc_.end());
338  }
339 
340  private:
341  Hypre_Chooser chooser_;
342  int option_;
343  int_func int_func_;
344  double_func double_func_;
345  double_int_func double_int_func_;
346  int_int_func int_int_func_;
347  int_star_func int_star_func_;
348  double_star_func double_star_func_;
349  int_int_double_double_func int_int_double_double_func_;
350  int_int_int_double_int_int_func int_int_int_double_int_int_func_;
351  int_star_star_func int_star_star_func_;
352  char_star_func char_star_func_;
353  HYPRE_Int int_param1_;
354  HYPRE_Int int_param2_;
355  HYPRE_Int int_param3_;
356  HYPRE_Int int_param4_;
357  HYPRE_Int int_param5_;
358  double double_param1_;
359  double double_param2_;
360  HYPRE_Int *int_star_param_;
361  HYPRE_Int **int_star_star_param_;
362  double *double_star_param_;
363  char *char_star_param_;
364 
365  static const std::map<std::string, int_func> hypreMapIntFunc_;
366  static const std::map<std::string, double_func> hypreMapDoubleFunc_;
367  static const std::map<std::string, double_int_func> hypreMapDoubleIntFunc_;
368  static const std::map<std::string, int_int_func> hypreMapIntIntFunc_;
369  static const std::map<std::string, int_star_func> hypreMapIntStarFunc_;
370  static const std::map<std::string, double_star_func> hypreMapDoubleStarFunc_;
371  static const std::map<std::string, int_int_double_double_func> hypreMapIntIntDoubleDoubleFunc_;
372  static const std::map<std::string, int_int_int_double_int_int_func> hypreMapIntIntIntDoubleIntIntFunc_;
373  static const std::map<std::string, int_star_star_func> hypreMapIntStarStarFunc_;
374  static const std::map<std::string, char_star_func> hypreMapCharStarFunc_;
375 
376  };
377 
378 }
379 
380 #endif // HAVE_IFPACK2_HYPRE && HAVE_IFPACK2_MPI
381 
382 #endif /* IFPACK2_HYPRE_FUNCTIONPARAMETERS_HPP */
Uses AztecOO&#39;s GMRES.
Definition: Ifpack2_CondestType.hpp:53
Preconditioners and smoothers for Tpetra sparse matrices.
Definition: Ifpack2_AdditiveSchwarz_decl.hpp:73