Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
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)
61struct hypre_IJMatrix_struct;
62typedef struct hypre_IJMatrix_struct *HYPRE_IJMatrix;
63struct hypre_IJVector_struct;
64typedef struct hypre_IJVector_struct *HYPRE_IJVector;
65struct hypre_ParCSRMatrix_struct;
66typedef struct hypre_ParCSRMatrix_struct* HYPRE_ParCSRMatrix;
67struct hypre_ParVector_struct;
68typedef struct hypre_ParVector_struct * HYPRE_ParVector;
69struct hypre_Solver_struct;
70typedef struct hypre_Solver_struct *HYPRE_Solver;
71struct hypre_ParVector_struct;
72typedef struct hypre_ParVector_struct hypre_ParVector;
73//struct hypre_Vector;
74
75#ifndef HYPRE_ENUMS
76#define HYPRE_ENUMS
78 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
99typedef HYPRE_Int (*int_func)(HYPRE_Solver, HYPRE_Int);
100typedef HYPRE_Int (*double_func)(HYPRE_Solver, double);
101typedef HYPRE_Int (*double_int_func)(HYPRE_Solver, double, HYPRE_Int);
102typedef HYPRE_Int (*int_double_func)(HYPRE_Solver, HYPRE_Int, double);
103typedef HYPRE_Int (*int_int_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Int);
104typedef HYPRE_Int (*int_star_func)(HYPRE_Solver, HYPRE_Int*);
105typedef HYPRE_Int (*int_star_star_func)(HYPRE_Solver, HYPRE_Int**);
106typedef HYPRE_Int (*double_star_func)(HYPRE_Solver, double*);
107typedef HYPRE_Int (*int_int_double_double_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Int, double, double);
108typedef HYPRE_Int (*int_int_int_double_int_int_func)(HYPRE_Solver, HYPRE_Int, HYPRE_Int, HYPRE_Int, double, HYPRE_Int, HYPRE_Int);
109typedef HYPRE_Int (*char_star_func)(HYPRE_Solver, char*);
110
111
112namespace Ifpack2 {
113
114 void IFPACK2_CHK_ERRV(int code);
115
116 void IFPACK2_CHK_ERR(int code);
117
119 class FunctionParameter {
120 public:
122 FunctionParameter(Hypre_Chooser chooser, int_func funct, HYPRE_Int param1) :
123 chooser_(chooser),
124 option_(0),
125 int_func_(funct),
126 int_param1_(param1) {}
127
128 FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1) :
129 chooser_(chooser),
130 option_(0),
131 int_func_(hypreMapIntFunc_.at(funct_name)),
132 int_param1_(param1) {}
133
135 FunctionParameter(Hypre_Chooser chooser, double_func funct, double param1):
136 chooser_(chooser),
137 option_(1),
138 double_func_(funct),
139 double_param1_(param1) {}
140
141 FunctionParameter(Hypre_Chooser chooser, std::string funct_name, double param1):
142 chooser_(chooser),
143 option_(1),
144 double_func_(hypreMapDoubleFunc_.at(funct_name)),
145 double_param1_(param1) {}
146
148 FunctionParameter(Hypre_Chooser chooser, double_int_func funct, double param1, HYPRE_Int param2):
149 chooser_(chooser),
150 option_(2),
151 double_int_func_(funct),
152 int_param1_(param2),
153 double_param1_(param1) {}
154
156 FunctionParameter(Hypre_Chooser chooser, int_double_func funct, HYPRE_Int param1, double param2):
157 chooser_(chooser),
158 option_(10),
159 int_double_func_(funct),
160 int_param1_(param1),
161 double_param1_(param2) {}
162
163 FunctionParameter(Hypre_Chooser chooser, std::string funct_name, double param1, HYPRE_Int param2):
164 chooser_(chooser),
165 option_(2),
166 double_int_func_(hypreMapDoubleIntFunc_.at(funct_name)),
167 int_param1_(param2),
168 double_param1_(param1) {}
169
171 FunctionParameter(Hypre_Chooser chooser, int_int_func funct, HYPRE_Int param1, HYPRE_Int param2):
172 chooser_(chooser),
173 option_(3),
174 int_int_func_(funct),
175 int_param1_(param1),
176 int_param2_(param2) {}
177
178 FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1, HYPRE_Int param2):
179 chooser_(chooser),
180 option_(3),
181 int_int_func_(hypreMapIntIntFunc_.at(funct_name)),
182 int_param1_(param1),
183 int_param2_(param2) {}
184
186 FunctionParameter(Hypre_Chooser chooser, int_star_func funct, HYPRE_Int *param1):
187 chooser_(chooser),
188 option_(4),
189 int_star_func_(funct),
190 int_star_param_(param1) {}
191
192 FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int *param1):
193 chooser_(chooser),
194 option_(4),
195 int_star_func_(hypreMapIntStarFunc_.at(funct_name)),
196 int_star_param_(param1) {}
197
199 FunctionParameter(Hypre_Chooser chooser, double_star_func funct, double* param1):
200 chooser_(chooser),
201 option_(5),
202 double_star_func_(funct),
203 double_star_param_(param1) {}
204
205 FunctionParameter(Hypre_Chooser chooser, std::string funct_name, double* param1):
206 chooser_(chooser),
207 option_(5),
208 double_star_func_(hypreMapDoubleStarFunc_.at(funct_name)),
209 double_star_param_(param1) {}
210
212 FunctionParameter(Hypre_Chooser chooser, int_int_double_double_func funct, HYPRE_Int param1, HYPRE_Int param2, double param3, double param4):
213 chooser_(chooser),
214 option_(6),
215 int_int_double_double_func_(funct),
216 int_param1_(param1),
217 int_param2_(param2),
218 double_param1_(param3),
219 double_param2_(param4) {}
220
221 FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int param1, HYPRE_Int param2, double param3, double param4):
222 chooser_(chooser),
223 option_(6),
224 int_int_double_double_func_(hypreMapIntIntDoubleDoubleFunc_.at(funct_name)),
225 int_param1_(param1),
226 int_param2_(param2),
227 double_param1_(param3),
228 double_param2_(param4) {}
229
231 FunctionParameter(Hypre_Chooser chooser, int_star_star_func funct, HYPRE_Int ** param1):
232 chooser_(chooser),
233 option_(7),
234 int_star_star_func_(funct),
235 int_star_star_param_(param1) {}
236
237 FunctionParameter(Hypre_Chooser chooser, std::string funct_name, HYPRE_Int** param1):
238 chooser_(chooser),
239 option_(7),
240 int_star_star_func_(hypreMapIntStarStarFunc_.at(funct_name)),
241 int_star_star_param_(param1) {}
242
244 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):
245 chooser_(chooser),
246 option_(8),
247 int_int_int_double_int_int_func_(funct),
248 int_param1_(param1),
249 int_param2_(param2),
250 int_param3_(param3),
251 int_param4_(param5),
252 int_param5_(param6),
253 double_param1_(param4) {}
254
255 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):
256 chooser_(chooser),
257 option_(8),
258 int_int_int_double_int_int_func_(hypreMapIntIntIntDoubleIntIntFunc_.at(funct_name)),
259 int_param1_(param1),
260 int_param2_(param2),
261 int_param3_(param3),
262 int_param4_(param5),
263 int_param5_(param6),
264 double_param1_(param4) {}
265
267 FunctionParameter(Hypre_Chooser chooser, char_star_func funct, char *param1):
268 chooser_(chooser),
269 option_(9),
270 char_star_func_(funct),
271 char_star_param_(param1) {}
272
273 FunctionParameter(Hypre_Chooser chooser, std::string funct_name, char *param1):
274 chooser_(chooser),
275 option_(9),
276 char_star_func_(hypreMapCharStarFunc_.at(funct_name)),
277 char_star_param_(param1) {}
278
280 int CallFunction(HYPRE_Solver solver, HYPRE_Solver precond) {
281 if(chooser_ == Hypre_Is_Solver){
282 if(option_ == 0){
283 return int_func_(solver, int_param1_);
284 } else if(option_ == 1){
285 return double_func_(solver, double_param1_);
286 } else if(option_ == 2){
287 return double_int_func_(solver, double_param1_, int_param1_);
288 } else if (option_ == 3){
289 return int_int_func_(solver, int_param1_, int_param2_);
290 } else if (option_ == 4){
291 return int_star_func_(solver, int_star_param_);
292 } else if (option_ == 5){
293 return double_star_func_(solver, double_star_param_);
294 } else if (option_ == 6) {
295 return int_int_double_double_func_(solver, int_param1_, int_param2_, double_param1_, double_param2_);
296 } else if (option_ == 7) {
297 return int_star_star_func_(solver, int_star_star_param_);
298 } else if (option_ == 8) {
299 return int_int_int_double_int_int_func_(solver, int_param1_, int_param2_, int_param3_, double_param1_, int_param4_, int_param5_);
300 } else if (option_ == 9) {
301 return char_star_func_(solver, char_star_param_);
302 } else if (option_ == 10) {
303 return int_double_func_(solver, int_param1_, double_param1_);
304 } else {
305 IFPACK2_CHK_ERR(-2);
306 }
307 } else {
308 if(option_ == 0){
309 return int_func_(precond, int_param1_);
310 } else if(option_ == 1){
311 return double_func_(precond, double_param1_);
312 } else if(option_ == 2){
313 return double_int_func_(precond, double_param1_, int_param1_);
314 } else if(option_ == 3) {
315 return int_int_func_(precond, int_param1_, int_param2_);
316 } else if(option_ == 4) {
317 return int_star_func_(precond, int_star_param_);
318 } else if(option_ == 5) {
319 return double_star_func_(precond, double_star_param_);
320 } else if (option_ == 6) {
321 return int_int_double_double_func_(precond, int_param1_, int_param2_, double_param1_, double_param2_);
322 } else if (option_ == 7) {
323 return int_star_star_func_(precond, int_star_star_param_);
324 } else if (option_ == 8) {
325 return int_int_int_double_int_int_func_(precond, int_param1_, int_param2_, int_param3_, double_param1_, int_param4_, int_param5_);
326 } else if (option_ == 9) {
327 return char_star_func_(solver, char_star_param_);
328 } else if (option_ == 10) {
329 return int_double_func_(precond, int_param1_, double_param1_);
330 } else {
331 IFPACK2_CHK_ERR(-2);
332 }
333 }
334 return 0;
335 }
336
337 static bool isFuncIntInt(std::string funct_name) {
338 return (hypreMapIntIntFunc_.find(funct_name) != hypreMapIntIntFunc_.end());
339 }
340
341 static bool isFuncIntIntDoubleDouble(std::string funct_name) {
342 return (hypreMapIntIntDoubleDoubleFunc_.find(funct_name) != hypreMapIntIntDoubleDoubleFunc_.end());
343 }
344
345 static bool isFuncIntIntIntDoubleIntInt(std::string funct_name) {
346 return (hypreMapIntIntIntDoubleIntIntFunc_.find(funct_name) != hypreMapIntIntIntDoubleIntIntFunc_.end());
347 }
348
349 static bool isFuncIntStarStar(std::string funct_name) {
350 return (hypreMapIntStarStarFunc_.find(funct_name) != hypreMapIntStarStarFunc_.end());
351 }
352
353 private:
354 Hypre_Chooser chooser_;
355 int option_;
356 int_func int_func_;
357 double_func double_func_;
358 double_int_func double_int_func_;
359 int_double_func int_double_func_;
360 int_int_func int_int_func_;
361 int_star_func int_star_func_;
362 double_star_func double_star_func_;
363 int_int_double_double_func int_int_double_double_func_;
364 int_int_int_double_int_int_func int_int_int_double_int_int_func_;
365 int_star_star_func int_star_star_func_;
366 char_star_func char_star_func_;
367 HYPRE_Int int_param1_;
368 HYPRE_Int int_param2_;
369 HYPRE_Int int_param3_;
370 HYPRE_Int int_param4_;
371 HYPRE_Int int_param5_;
372 double double_param1_;
373 double double_param2_;
374 HYPRE_Int *int_star_param_;
375 HYPRE_Int **int_star_star_param_;
376 double *double_star_param_;
377 char *char_star_param_;
378
379 static const std::map<std::string, int_func> hypreMapIntFunc_;
380 static const std::map<std::string, double_func> hypreMapDoubleFunc_;
381 static const std::map<std::string, double_int_func> hypreMapDoubleIntFunc_;
382 static const std::map<std::string, int_double_func> hypreMapIntDoubleFunc_;
383 static const std::map<std::string, int_int_func> hypreMapIntIntFunc_;
384 static const std::map<std::string, int_star_func> hypreMapIntStarFunc_;
385 static const std::map<std::string, double_star_func> hypreMapDoubleStarFunc_;
386 static const std::map<std::string, int_int_double_double_func> hypreMapIntIntDoubleDoubleFunc_;
387 static const std::map<std::string, int_int_int_double_int_int_func> hypreMapIntIntIntDoubleIntIntFunc_;
388 static const std::map<std::string, int_star_star_func> hypreMapIntStarStarFunc_;
389 static const std::map<std::string, char_star_func> hypreMapCharStarFunc_;
390
391 };
392
393}
394
395#endif // HAVE_IFPACK2_HYPRE && HAVE_IFPACK2_MPI
396
397#endif /* IFPACK2_HYPRE_FUNCTIONPARAMETERS_HPP */
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:74
@ GMRES
Uses AztecOO's GMRES.
Definition Ifpack2_CondestType.hpp:53