Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Hypre_FunctionParameters.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4 //
5 // Copyright 2009 NTESS and the Ifpack2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef IFPACK2_HYPRE_FUNCTIONPARAMETERS_HPP
11 #define IFPACK2_HYPRE_FUNCTIONPARAMETERS_HPP
12 
13 #include "Ifpack2_ConfigDefs.hpp"
14 #if defined(HAVE_IFPACK2_HYPRE) && defined(HAVE_IFPACK2_MPI)
15 
16 #include <sstream>
17 #include "HYPRE_utilities.h"
18 #include "HYPRE_IJ_mv.h"
19 #include "HYPRE_parcsr_ls.h"
20 #include "krylov.h"
21 #include "_hypre_parcsr_mv.h"
22 #include "_hypre_IJ_mv.h"
23 #include "HYPRE_parcsr_mv.h"
24 #include "HYPRE.h"
25 
26 // Hypre forward declarations (to avoid downstream header pollution)
27 struct hypre_IJMatrix_struct;
28 typedef struct hypre_IJMatrix_struct *HYPRE_IJMatrix;
29 struct hypre_IJVector_struct;
30 typedef struct hypre_IJVector_struct *HYPRE_IJVector;
31 struct hypre_ParCSRMatrix_struct;
32 typedef struct hypre_ParCSRMatrix_struct *HYPRE_ParCSRMatrix;
33 struct hypre_ParVector_struct;
34 typedef struct hypre_ParVector_struct *HYPRE_ParVector;
35 struct hypre_Solver_struct;
36 typedef struct hypre_Solver_struct *HYPRE_Solver;
37 struct hypre_ParVector_struct;
38 typedef struct hypre_ParVector_struct hypre_ParVector;
39 // struct hypre_Vector;
40 
41 #ifndef HYPRE_ENUMS
42 #define HYPRE_ENUMS
43 enum Hypre_Solver {
45  BoomerAMG,
46  ParaSails,
47  Euclid,
48  AMS,
49  Hybrid,
50  PCG,
51  GMRES,
52  FlexGMRES,
53  LGMRES,
54  BiCGSTAB
55 };
56 
58 enum Hypre_Chooser {
59  Hypre_Is_Solver,
60  Hypre_Is_Preconditioner
61 };
62 #endif // HYPRE_ENUMS
63 
64 // The Python script that generates the ParameterMap needs to be after these typedefs
65 typedef HYPRE_Int (*int_func)(HYPRE_Solver, HYPRE_Int);
66 typedef HYPRE_Int (*double_func)(HYPRE_Solver, HYPRE_Real);
67 typedef HYPRE_Int (*double_int_func)(HYPRE_Solver, HYPRE_Real, HYPRE_Int);
68 typedef HYPRE_Int (*int_double_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Real);
69 typedef HYPRE_Int (*int_int_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Int);
70 typedef HYPRE_Int (*int_star_func)(HYPRE_Solver, HYPRE_Int *);
71 typedef HYPRE_Int (*int_star_star_func)(HYPRE_Solver, HYPRE_Int **);
72 typedef HYPRE_Int (*double_star_func)(HYPRE_Solver, HYPRE_Real *);
73 typedef HYPRE_Int (*int_int_double_double_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Int, HYPRE_Real, HYPRE_Real);
74 typedef HYPRE_Int (*int_int_int_double_int_int_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Int, HYPRE_Int, HYPRE_Real, HYPRE_Int, HYPRE_Int);
75 typedef HYPRE_Int (*char_star_func)(HYPRE_Solver, char *);
76 
77 namespace Ifpack2 {
78 
79 void IFPACK2_CHK_ERRV(int code);
80 
81 void IFPACK2_CHK_ERR(int code);
82 
84 class FunctionParameter {
85  public:
87  FunctionParameter(Hypre_Chooser chooser, int_func funct, HYPRE_Int param1)
88  : chooser_(chooser)
89  , option_(0)
90  , int_func_(funct)
91  , int_param1_(param1) {}
92 
93  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1)
94  : chooser_(chooser)
95  , option_(0)
96  , int_func_(hypreMapIntFunc_.at(funct_name))
97  , int_param1_(param1) {}
98 
100  FunctionParameter(Hypre_Chooser chooser, double_func funct, HYPRE_Real param1)
101  : chooser_(chooser)
102  , option_(1)
103  , double_func_(funct)
104  , double_param1_(param1) {}
105 
106  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Real param1)
107  : chooser_(chooser)
108  , option_(1)
109  , double_func_(hypreMapDoubleFunc_.at(funct_name))
110  , double_param1_(param1) {}
111 
113  FunctionParameter(Hypre_Chooser chooser, double_int_func funct, HYPRE_Real param1, HYPRE_Int param2)
114  : chooser_(chooser)
115  , option_(2)
116  , double_int_func_(funct)
117  , int_param1_(param2)
118  , double_param1_(param1) {}
119 
121  FunctionParameter(Hypre_Chooser chooser, int_double_func funct, HYPRE_Int param1, HYPRE_Real param2)
122  : chooser_(chooser)
123  , option_(10)
124  , int_double_func_(funct)
125  , int_param1_(param1)
126  , double_param1_(param2) {}
127 
128  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Real param1, HYPRE_Int param2)
129  : chooser_(chooser)
130  , option_(2)
131  , double_int_func_(hypreMapDoubleIntFunc_.at(funct_name))
132  , int_param1_(param2)
133  , double_param1_(param1) {}
134 
136  FunctionParameter(Hypre_Chooser chooser, int_int_func funct, HYPRE_Int param1, HYPRE_Int param2)
137  : chooser_(chooser)
138  , option_(3)
139  , int_int_func_(funct)
140  , int_param1_(param1)
141  , int_param2_(param2) {}
142 
143  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1, HYPRE_Int param2)
144  : chooser_(chooser)
145  , option_(3)
146  , int_int_func_(hypreMapIntIntFunc_.at(funct_name))
147  , int_param1_(param1)
148  , int_param2_(param2) {}
149 
151  FunctionParameter(Hypre_Chooser chooser, int_star_func funct, HYPRE_Int *param1)
152  : chooser_(chooser)
153  , option_(4)
154  , int_star_func_(funct)
155  , int_star_param_(param1) {}
156 
157  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int *param1)
158  : chooser_(chooser)
159  , option_(4)
160  , int_star_func_(hypreMapIntStarFunc_.at(funct_name))
161  , int_star_param_(param1) {}
162 
164  FunctionParameter(Hypre_Chooser chooser, double_star_func funct, double *param1)
165  : chooser_(chooser)
166  , option_(5)
167  , double_star_func_(funct)
168  , double_star_param_(param1) {}
169 
170  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, double *param1)
171  : chooser_(chooser)
172  , option_(5)
173  , double_star_func_(hypreMapDoubleStarFunc_.at(funct_name))
174  , double_star_param_(param1) {}
175 
177  FunctionParameter(Hypre_Chooser chooser, int_int_double_double_func funct, HYPRE_Int param1, HYPRE_Int param2, HYPRE_Real param3, HYPRE_Real param4)
178  : chooser_(chooser)
179  , option_(6)
180  , int_int_double_double_func_(funct)
181  , int_param1_(param1)
182  , int_param2_(param2)
183  , double_param1_(param3)
184  , double_param2_(param4) {}
185 
186  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1, HYPRE_Int param2, HYPRE_Real param3, HYPRE_Real param4)
187  : chooser_(chooser)
188  , option_(6)
189  , int_int_double_double_func_(hypreMapIntIntDoubleDoubleFunc_.at(funct_name))
190  , int_param1_(param1)
191  , int_param2_(param2)
192  , double_param1_(param3)
193  , double_param2_(param4) {}
194 
196  FunctionParameter(Hypre_Chooser chooser, int_star_star_func funct, HYPRE_Int **param1)
197  : chooser_(chooser)
198  , option_(7)
199  , int_star_star_func_(funct)
200  , int_star_star_param_(param1) {}
201 
202  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int **param1)
203  : chooser_(chooser)
204  , option_(7)
205  , int_star_star_func_(hypreMapIntStarStarFunc_.at(funct_name))
206  , int_star_star_param_(param1) {}
207 
209  FunctionParameter(Hypre_Chooser chooser, int_int_int_double_int_int_func funct, HYPRE_Int param1, HYPRE_Int param2, HYPRE_Int param3, HYPRE_Real param4, HYPRE_Int param5, HYPRE_Int param6)
210  : chooser_(chooser)
211  , option_(8)
212  , int_int_int_double_int_int_func_(funct)
213  , int_param1_(param1)
214  , int_param2_(param2)
215  , int_param3_(param3)
216  , int_param4_(param5)
217  , int_param5_(param6)
218  , double_param1_(param4) {}
219 
220  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1, HYPRE_Int param2, HYPRE_Int param3, HYPRE_Real param4, HYPRE_Int param5, HYPRE_Int param6)
221  : chooser_(chooser)
222  , option_(8)
223  , int_int_int_double_int_int_func_(hypreMapIntIntIntDoubleIntIntFunc_.at(funct_name))
224  , int_param1_(param1)
225  , int_param2_(param2)
226  , int_param3_(param3)
227  , int_param4_(param5)
228  , int_param5_(param6)
229  , double_param1_(param4) {}
230 
232  FunctionParameter(Hypre_Chooser chooser, char_star_func funct, char *param1)
233  : chooser_(chooser)
234  , option_(9)
235  , char_star_func_(funct)
236  , char_star_param_(param1) {}
237 
238  FunctionParameter(Hypre_Chooser chooser, std::string funct_name, char *param1)
239  : chooser_(chooser)
240  , option_(9)
241  , char_star_func_(hypreMapCharStarFunc_.at(funct_name))
242  , char_star_param_(param1) {}
243 
245  int CallFunction(HYPRE_Solver solver, HYPRE_Solver precond) {
246  if (chooser_ == Hypre_Is_Solver) {
247  if (option_ == 0) {
248  return int_func_(solver, int_param1_);
249  } else if (option_ == 1) {
250  return double_func_(solver, double_param1_);
251  } else if (option_ == 2) {
252  return double_int_func_(solver, double_param1_, int_param1_);
253  } else if (option_ == 3) {
254  return int_int_func_(solver, int_param1_, int_param2_);
255  } else if (option_ == 4) {
256  return int_star_func_(solver, int_star_param_);
257  } else if (option_ == 5) {
258  return double_star_func_(solver, double_star_param_);
259  } else if (option_ == 6) {
260  return int_int_double_double_func_(solver, int_param1_, int_param2_, double_param1_, double_param2_);
261  } else if (option_ == 7) {
262  return int_star_star_func_(solver, int_star_star_param_);
263  } else if (option_ == 8) {
264  return int_int_int_double_int_int_func_(solver, int_param1_, int_param2_, int_param3_, double_param1_, int_param4_, int_param5_);
265  } else if (option_ == 9) {
266  return char_star_func_(solver, char_star_param_);
267  } else if (option_ == 10) {
268  return int_double_func_(solver, int_param1_, double_param1_);
269  } else {
270  IFPACK2_CHK_ERR(-2);
271  }
272  } else {
273  if (option_ == 0) {
274  return int_func_(precond, int_param1_);
275  } else if (option_ == 1) {
276  return double_func_(precond, double_param1_);
277  } else if (option_ == 2) {
278  return double_int_func_(precond, double_param1_, int_param1_);
279  } else if (option_ == 3) {
280  return int_int_func_(precond, int_param1_, int_param2_);
281  } else if (option_ == 4) {
282  return int_star_func_(precond, int_star_param_);
283  } else if (option_ == 5) {
284  return double_star_func_(precond, double_star_param_);
285  } else if (option_ == 6) {
286  return int_int_double_double_func_(precond, int_param1_, int_param2_, double_param1_, double_param2_);
287  } else if (option_ == 7) {
288  return int_star_star_func_(precond, int_star_star_param_);
289  } else if (option_ == 8) {
290  return int_int_int_double_int_int_func_(precond, 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 if (option_ == 10) {
294  return int_double_func_(precond, int_param1_, double_param1_);
295  } else {
296  IFPACK2_CHK_ERR(-2);
297  }
298  }
299  return 0;
300  }
301 
302  static bool isFuncIntInt(std::string funct_name) {
303  return (hypreMapIntIntFunc_.find(funct_name) != hypreMapIntIntFunc_.end());
304  }
305 
306  static bool isFuncIntIntDoubleDouble(std::string funct_name) {
307  return (hypreMapIntIntDoubleDoubleFunc_.find(funct_name) != hypreMapIntIntDoubleDoubleFunc_.end());
308  }
309 
310  static bool isFuncIntIntIntDoubleIntInt(std::string funct_name) {
311  return (hypreMapIntIntIntDoubleIntIntFunc_.find(funct_name) != hypreMapIntIntIntDoubleIntIntFunc_.end());
312  }
313 
314  static bool isFuncIntStarStar(std::string funct_name) {
315  return (hypreMapIntStarStarFunc_.find(funct_name) != hypreMapIntStarStarFunc_.end());
316  }
317 
318  private:
319  Hypre_Chooser chooser_;
320  int option_;
321  int_func int_func_;
322  double_func double_func_;
323  double_int_func double_int_func_;
324  int_double_func int_double_func_;
325  int_int_func int_int_func_;
326  int_star_func int_star_func_;
327  double_star_func double_star_func_;
328  int_int_double_double_func int_int_double_double_func_;
329  int_int_int_double_int_int_func int_int_int_double_int_int_func_;
330  int_star_star_func int_star_star_func_;
331  char_star_func char_star_func_;
332  HYPRE_Int int_param1_;
333  HYPRE_Int int_param2_;
334  HYPRE_Int int_param3_;
335  HYPRE_Int int_param4_;
336  HYPRE_Int int_param5_;
337  HYPRE_Real double_param1_;
338  HYPRE_Real double_param2_;
339  HYPRE_Int *int_star_param_;
340  HYPRE_Int **int_star_star_param_;
341  HYPRE_Real *double_star_param_;
342  char *char_star_param_;
343 
344  static const std::map<std::string, int_func> hypreMapIntFunc_;
345  static const std::map<std::string, double_func> hypreMapDoubleFunc_;
346  static const std::map<std::string, double_int_func> hypreMapDoubleIntFunc_;
347  static const std::map<std::string, int_double_func> hypreMapIntDoubleFunc_;
348  static const std::map<std::string, int_int_func> hypreMapIntIntFunc_;
349  static const std::map<std::string, int_star_func> hypreMapIntStarFunc_;
350  static const std::map<std::string, double_star_func> hypreMapDoubleStarFunc_;
351  static const std::map<std::string, int_int_double_double_func> hypreMapIntIntDoubleDoubleFunc_;
352  static const std::map<std::string, int_int_int_double_int_int_func> hypreMapIntIntIntDoubleIntIntFunc_;
353  static const std::map<std::string, int_star_star_func> hypreMapIntStarStarFunc_;
354  static const std::map<std::string, char_star_func> hypreMapCharStarFunc_;
355 };
356 
357 } // namespace Ifpack2
358 
359 #endif // HAVE_IFPACK2_HYPRE && HAVE_IFPACK2_MPI
360 
361 #endif /* IFPACK2_HYPRE_FUNCTIONPARAMETERS_HPP */
Uses AztecOO&#39;s GMRES.
Definition: Ifpack2_CondestType.hpp:20