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