8.3
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-2024 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
58typedef 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
101typedef void
102(cs_sles_hypre_setup_hook_t) (int verbosity,
103 void *context,
104 void *solver);
105
106/* HYPRE linear solver context (opaque) */
107
108typedef 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
151cs_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
190void
191cs_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
206void *
207cs_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
220void
221cs_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 <-- residual normalization
237 * n_iter --> number of iterations
238 * residual --> residual
239 * rhs <-- right hand side
240 * vx_ini <-- initial system solution
241 * (vx if nonzero, nullptr if zero)
242 * vx <-> system solution
243 * aux_size <-- number of elements in aux_vectors (in bytes)
244 * aux_vectors --- optional working area (internal allocation if NULL)
245 *
246 * returns:
247 * convergence state
248 *----------------------------------------------------------------------------*/
249
251cs_sles_hypre_solve(void *context,
252 const char *name,
253 const cs_matrix_t *a,
254 int verbosity,
255 double precision,
256 double r_norm,
257 int *n_iter,
258 double *residual,
259 const cs_real_t *rhs,
260 cs_real_t *vx_ini,
261 cs_real_t *vx,
262 size_t aux_size,
263 void *aux_vectors);
264
265/*----------------------------------------------------------------------------
266 * Free HYPRE linear equation solver setup context.
267 *
268 * This function frees resolution-related data, such as
269 * buffers and preconditioning but does not free the whole context,
270 * as info used for logging (especially performance data) is maintained.
271
272 * parameters:
273 * context <-> pointer to HYPRE linear solver info
274 * (actual type: cs_sles_hypre_t *)
275 *----------------------------------------------------------------------------*/
276
277void
278cs_sles_hypre_free(void *context);
279
280/*----------------------------------------------------------------------------*/
296/*----------------------------------------------------------------------------*/
297
298bool
301 const cs_matrix_t *a,
302 const cs_real_t *rhs,
303 cs_real_t *vx);
304
305/*----------------------------------------------------------------------------
306 * Log sparse linear equation solver info.
307 *
308 * parameters:
309 * context <-> pointer to HYPRE linear solver info
310 * (actual type: cs_sles_hypre_t *)
311 * log_type <-- log type
312 *----------------------------------------------------------------------------*/
313
314void
315cs_sles_hypre_log(const void *context,
316 cs_log_t log_type);
317
318/*----------------------------------------------------------------------------*/
326/*----------------------------------------------------------------------------*/
327
328void
330 int n_max_iter);
331
332/*----------------------------------------------------------------------------*/
342/*----------------------------------------------------------------------------*/
343
344void
346 int use_device);
347
348/*----------------------------------------------------------------------------*/
356/*----------------------------------------------------------------------------*/
357
358int
360
361/*----------------------------------------------------------------------------*/
367/*----------------------------------------------------------------------------*/
368
369void
371
372/*----------------------------------------------------------------------------*/
373
375
376#endif /* __CS_SLES_HYPRE_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
double cs_real_t
Floating-point value.
Definition: cs_defs.h:342
#define END_C_DECLS
Definition: cs_defs.h:543
cs_log_t
Definition: cs_log.h:48
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:110
cs_sles_convergence_state_t
Definition: cs_sles.h:56
struct _cs_sles_t cs_sles_t
Definition: cs_sles.h:68
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.
Definition: cs_sles_hypre.cpp:355
cs_sles_hypre_type_t
Definition: cs_sles_hypre.h:58
@ CS_SLES_HYPRE_FLEXGMRES
Definition: cs_sles_hypre.h:68
@ CS_SLES_HYPRE_EUCLID
Definition: cs_sles_hypre.h:74
@ CS_SLES_HYPRE_PARASAILS
Definition: cs_sles_hypre.h:75
@ CS_SLES_HYPRE_GMRES
Definition: cs_sles_hypre.h:67
@ CS_SLES_HYPRE_BICGSTAB
Definition: cs_sles_hypre.h:66
@ CS_SLES_HYPRE_NONE
Definition: cs_sles_hypre.h:79
@ CS_SLES_HYPRE_ILU
Definition: cs_sles_hypre.h:64
@ CS_SLES_HYPRE_PCG
Definition: cs_sles_hypre.h:70
@ CS_SLES_HYPRE_LGMRES
Definition: cs_sles_hypre.h:69
@ CS_SLES_HYPRE_BOOMERAMG
Definition: cs_sles_hypre.h:62
@ CS_SLES_HYPRE_HYBRID
Definition: cs_sles_hypre.h:63
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 *residual, const cs_real_t *rhs, cs_real_t *vx_ini, cs_real_t *vx, size_t aux_size, void *aux_vectors)
Call HYPRE linear equation solver.
Definition: cs_sles_hypre.cpp:985
void cs_sles_hypre_set_n_max_iter(cs_sles_hypre_t *context, int n_max_iter)
Set the max. number of iterations associated to the given HYPRE contrext.
Definition: cs_sles_hypre.cpp:1366
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.
Definition: cs_sles_hypre.cpp:1423
void cs_sles_hypre_free(void *context)
Free HYPRE linear equation solver setup context.
Definition: cs_sles_hypre.cpp:1281
void cs_sles_hypre_destroy(void **context)
Destroy iterative sparse linear system solver info and context.
Definition: cs_sles_hypre.cpp:413
void cs_sles_hypre_log(const void *context, cs_log_t log_type)
Log sparse linear equation solver info.
Definition: cs_sles_hypre.cpp:513
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.
Definition: cs_sles_hypre.cpp:476
void cs_sles_hypre_setup(void *context, const char *name, const cs_matrix_t *a, int verbosity)
Setup iterative sparse linear equation solver.
Definition: cs_sles_hypre.cpp:585
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.
Definition: cs_sles_hypre.cpp:1444
void * cs_sles_hypre_copy(const void *context)
Create HYPRE sparse linear system solver info and context based on existing info and context.
Definition: cs_sles_hypre.cpp:442
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.cpp:302
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
struct _cs_sles_hypre_t cs_sles_hypre_t
Definition: cs_sles_hypre.h:108
void cs_sles_hypre_library_info(cs_log_t log_type)
Print information on hypre library.
Definition: cs_sles_hypre.cpp:1458