7.1
general documentation
cs_sles_hypre.h
Go to the documentation of this file.
1 #ifndef __CS_SLES_HYPRE_H__
2 #define __CS_SLES_HYPRE_H__
3 
4 /*============================================================================
5  * Sparse Linear Equation Solvers using HYPRE
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2021 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 /*----------------------------------------------------------------------------
31  * HYPRE headers
32  *----------------------------------------------------------------------------*/
33 
34 /*----------------------------------------------------------------------------
35  * Local headers
36  *----------------------------------------------------------------------------*/
37 
38 #include "cs_base.h"
39 #include "cs_matrix.h"
40 #include "cs_sles.h"
41 
42 /*----------------------------------------------------------------------------*/
43 
45 
46 /*============================================================================
47  * Macro definitions
48  *============================================================================*/
49 
50 /*============================================================================
51  * Type definitions
52  *============================================================================*/
53 
54 /*----------------------------------------------------------------------------
55  * Solver and preconditioner types
56  *----------------------------------------------------------------------------*/
57 
58 typedef enum {
59 
60  /* Solver or preconditioner */
61 
72  /* Preconditioner only */
73 
77  /* End of allowable solvers */
78 
82 
83 /*----------------------------------------------------------------------------
84  * Function pointer for user settings of a HYPRE solver setup.
85  *
86  * This function is called during the setup stage for a HYPRE solver.
87  *
88  * When first called, the solver argument is NULL, and must be created
89  * using HYPRE functions.
90  *
91  * Note: if the context pointer is non-NULL, it must point to valid data
92  * when the selection function is called so that value or structure should
93  * not be temporary (i.e. local);
94  *
95  * parameters:
96  * verbosity <-- verbosity level
97  * context <-> pointer to optional (untyped) value or structure
98  * solver <-> handle to HYPRE solver (to be cast as HYPRE_Solver)
99  *----------------------------------------------------------------------------*/
100 
101 typedef void
102 (cs_sles_hypre_setup_hook_t) (int verbosity,
103  void *context,
104  void *solver);
105 
106 /* HYPRE linear solver context (opaque) */
107 
108 typedef struct _cs_sles_hypre_t cs_sles_hypre_t;
109 
110 /*============================================================================
111  * Global variables
112  *============================================================================*/
113 
114 /*=============================================================================
115  * Public function prototypes
116  *============================================================================*/
117 
118 /*----------------------------------------------------------------------------*/
148 /*----------------------------------------------------------------------------*/
149 
151 cs_sles_hypre_define(int f_id,
152  const char *name,
153  cs_sles_hypre_type_t solver_type,
154  cs_sles_hypre_type_t precond_type,
155  cs_sles_hypre_setup_hook_t *setup_hook,
156  void *context);
157 
158 /*----------------------------------------------------------------------------*/
174 /*----------------------------------------------------------------------------*/
175 
178  cs_sles_hypre_type_t precond_type,
179  cs_sles_hypre_setup_hook_t *setup_hook,
180  void *context);
181 
182 /*----------------------------------------------------------------------------
183  * Destroy HYPRE linear system solver info and context.
184  *
185  * parameters:
186  * context <-> pointer to HYPRE linear solver info
187  * (actual type: cs_sles_hypre_t **)
188  *----------------------------------------------------------------------------*/
189 
190 void
191 cs_sles_hypre_destroy(void **context);
192 
193 /*----------------------------------------------------------------------------
194  * Create HYPRE linear system solver info and context
195  * based on existing info and context.
196  *
197  * parameters:
198  * context <-- pointer to reference info and context
199  * (actual type: cs_sles_hypre_t *)
200  *
201  * returns:
202  * pointer to newly created solver info object
203  * (actual type: cs_sles_hypre_t *)
204  *----------------------------------------------------------------------------*/
205 
206 void *
207 cs_sles_hypre_copy(const void *context);
208 
209 /*----------------------------------------------------------------------------
210  * Setup HYPRE linear equation solver.
211  *
212  * parameters:
213  * context <-> pointer to HYPRE linear solver info
214  * (actual type: cs_sles_hypre_t *)
215  * name <-- pointer to system name
216  * a <-- associated matrix
217  * verbosity <-- verbosity level
218  *----------------------------------------------------------------------------*/
219 
220 void
221 cs_sles_hypre_setup(void *context,
222  const char *name,
223  const cs_matrix_t *a,
224  int verbosity);
225 
226 /*----------------------------------------------------------------------------
227  * Call HYPRE linear equation solver.
228  *
229  * parameters:
230  * context <-> pointer to HYPRE linear solver info
231  * (actual type: cs_sles_hypre_t *)
232  * name <-- pointer to system name
233  * a <-- matrix
234  * verbosity <-- verbosity level
235  * precision <-- solver precision
236  * r_norm <-- residue normalization
237  * n_iter --> number of iterations
238  * residue --> residue
239  * rhs <-- right hand side
240  * vx <-> system solution
241  * aux_size <-- number of elements in aux_vectors (in bytes)
242  * aux_vectors --- optional working area (internal allocation if NULL)
243  *
244  * returns:
245  * convergence state
246  *----------------------------------------------------------------------------*/
247 
249 cs_sles_hypre_solve(void *context,
250  const char *name,
251  const cs_matrix_t *a,
252  int verbosity,
253  double precision,
254  double r_norm,
255  int *n_iter,
256  double *residue,
257  const cs_real_t *rhs,
258  cs_real_t *vx,
259  size_t aux_size,
260  void *aux_vectors);
261 
262 /*----------------------------------------------------------------------------
263  * Free HYPRE linear equation solver setup context.
264  *
265  * This function frees resolution-related data, such as
266  * buffers and preconditioning but does not free the whole context,
267  * as info used for logging (especially performance data) is maintained.
268 
269  * parameters:
270  * context <-> pointer to HYPRE linear solver info
271  * (actual type: cs_sles_hypre_t *)
272  *----------------------------------------------------------------------------*/
273 
274 void
275 cs_sles_hypre_free(void *context);
276 
277 /*----------------------------------------------------------------------------*/
293 /*----------------------------------------------------------------------------*/
294 
295 bool
298  const cs_matrix_t *a,
299  const cs_real_t *rhs,
300  cs_real_t *vx);
301 
302 /*----------------------------------------------------------------------------
303  * Log sparse linear equation solver info.
304  *
305  * parameters:
306  * context <-> pointer to HYPRE linear solver info
307  * (actual type: cs_sles_hypre_t *)
308  * log_type <-- log type
309  *----------------------------------------------------------------------------*/
310 
311 void
312 cs_sles_hypre_log(const void *context,
313  cs_log_t log_type);
314 
315 /*----------------------------------------------------------------------------*/
325 /*----------------------------------------------------------------------------*/
326 
327 void
329  int use_device);
330 
331 /*----------------------------------------------------------------------------*/
339 /*----------------------------------------------------------------------------*/
340 
341 int
343 
344 /*----------------------------------------------------------------------------*/
350 /*----------------------------------------------------------------------------*/
351 
352 void
354 
355 /*----------------------------------------------------------------------------*/
356 
358 
359 #endif /* __CS_SLES_HYPRE_H__ */
Definition: cs_sles_hypre.h:74
void cs_sles_hypre_set_host_device(cs_sles_hypre_t *context, int use_device)
Define whether the solver should run on the host or accelerated device.
#define BEGIN_C_DECLS
Definition: cs_defs.h:510
cs_sles_hypre_type_t
Definition: cs_sles_hypre.h:58
Definition: cs_sles_hypre.h:79
Definition: cs_sles_hypre.h:67
Definition: cs_sles_hypre.h:75
int cs_sles_hypre_get_host_device(const cs_sles_hypre_t *context)
Query whether the solver should run on the host or accelerated device.
cs_sles_convergence_state_t cs_sles_hypre_solve(void *context, const char *name, const cs_matrix_t *a, int verbosity, double precision, double r_norm, int *n_iter, double *residue, const cs_real_t *rhs, cs_real_t *vx, size_t aux_size, void *aux_vectors)
Definition: cs_sles_hypre.h:63
void cs_sles_hypre_log(const void *context, cs_log_t log_type)
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
cs_sles_hypre_t * cs_sles_hypre_define(int f_id, const char *name, cs_sles_hypre_type_t solver_type, cs_sles_hypre_type_t precond_type, cs_sles_hypre_setup_hook_t *setup_hook, void *context)
Define and associate a HYPRE linear system solver for a given field or equation name.
Definition: cs_sles_hypre.h:68
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:93
cs_sles_convergence_state_t
Convergence status indicator.
Definition: cs_sles.h:56
struct _cs_sles_t cs_sles_t
Definition: cs_sles.h:68
void cs_sles_hypre_setup(void *context, const char *name, const cs_matrix_t *a, int verbosity)
void cs_sles_hypre_destroy(void **context)
Definition: cs_sles_hypre.h:64
void * cs_sles_hypre_copy(const void *context)
double precision, save a
Definition: cs_fuel_incl.f90:146
void cs_sles_hypre_free(void *context)
bool cs_sles_hypre_error_post_and_abort(cs_sles_t *sles, cs_sles_convergence_state_t state, const cs_matrix_t *a, const cs_real_t *rhs, cs_real_t *vx)
Error handler for HYPRE solver.
cs_sles_hypre_t * cs_sles_hypre_create(cs_sles_hypre_type_t solver_type, cs_sles_hypre_type_t precond_type, cs_sles_hypre_setup_hook_t *setup_hook, void *context)
Create HYPRE linear system solver info and context.
cs_log_t
Definition: cs_log.h:48
void cs_sles_hypre_library_info(cs_log_t log_type)
Print information on hypre library.
void() cs_sles_hypre_setup_hook_t(int verbosity, void *context, void *solver)
Function pointer for settings of a HYPRE solver setup.
Definition: cs_sles_hypre.h:102
Definition: cs_sles_hypre.h:66
#define END_C_DECLS
Definition: cs_defs.h:511
Definition: cs_sles_hypre.h:69
Definition: cs_sles_hypre.h:70
struct _cs_sles_hypre_t cs_sles_hypre_t
Definition: cs_sles_hypre.h:108
Definition: cs_sles_hypre.h:62