8.0
general documentation
Loading...
Searching...
No Matches
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-2023 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
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 <-- 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
249cs_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
274void
275cs_sles_hypre_free(void *context);
276
277/*----------------------------------------------------------------------------*/
293/*----------------------------------------------------------------------------*/
294
295bool
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
311void
312cs_sles_hypre_log(const void *context,
313 cs_log_t log_type);
314
315/*----------------------------------------------------------------------------*/
323/*----------------------------------------------------------------------------*/
324
325void
327 int n_max_iter);
328
329/*----------------------------------------------------------------------------*/
339/*----------------------------------------------------------------------------*/
340
341void
343 int use_device);
344
345/*----------------------------------------------------------------------------*/
353/*----------------------------------------------------------------------------*/
354
355int
357
358/*----------------------------------------------------------------------------*/
364/*----------------------------------------------------------------------------*/
365
366void
368
369/*----------------------------------------------------------------------------*/
370
372
373#endif /* __CS_SLES_HYPRE_H__ */
#define BEGIN_C_DECLS
Definition cs_defs.h:509
double cs_real_t
Floating-point value.
Definition cs_defs.h:319
#define END_C_DECLS
Definition cs_defs.h:510
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_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)
Call HYPRE linear equation solver.
Definition cs_sles_hypre.c:975
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.c:353
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
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.c:1328
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.c:1385
void cs_sles_hypre_free(void *context)
Free HYPRE linear equation solver setup context.
Definition cs_sles_hypre.c:1246
void cs_sles_hypre_destroy(void **context)
Destroy iterative sparse linear system solver info and context.
Definition cs_sles_hypre.c:407
void cs_sles_hypre_log(const void *context, cs_log_t log_type)
Log sparse linear equation solver info.
Definition cs_sles_hypre.c:510
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.c:470
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.c:580
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.c:1406
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.c:436
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.c:300
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.c:1420
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