9.2
general documentation
cs_sles_default.h
Go to the documentation of this file.
1#ifndef CS_SLES_DEFAULT_H
2#define CS_SLES_DEFAULT_H
3
4/*============================================================================
5 * Sparse Linear Equation Solvers
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 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 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "base/cs_base.h"
35#include "base/cs_halo_perio.h"
36#include "alge/cs_matrix.h"
37#include "alge/cs_sles.h"
38
39/*----------------------------------------------------------------------------*/
40
42
43/*============================================================================
44 * Macro definitions
45 *============================================================================*/
46
47/*============================================================================
48 * Type definitions
49 *============================================================================*/
50
51/*============================================================================
52 * Global variables
53 *============================================================================*/
54
55/*=============================================================================
56 * Public function prototypes
57 *============================================================================*/
58
59/*----------------------------------------------------------------------------
60 * Default initializations for sparse linear equation solver API.
61 *----------------------------------------------------------------------------*/
62
63void
65
66/*----------------------------------------------------------------------------
67 * Default definition of a sparse linear equation solver
68 *
69 * parameters:
70 * f_id <-- associated field id, or < 0
71 * name <-- associated name if f_id < 0, or NULL
72 * a <-- matrix
73 *----------------------------------------------------------------------------*/
74
75void
76cs_sles_default(int f_id,
77 const char *name,
78 const cs_matrix_t *a);
79
80/*----------------------------------------------------------------------------
81 * Default setup setup for sparse linear equation solver API.
82 *
83 * This includes setup logging.
84 *----------------------------------------------------------------------------*/
85
86void
88
89/*----------------------------------------------------------------------------
90 * Return default verbosity associated to a field id, name couple.
91 *
92 * parameters:
93 * f_id <-- associated field id, or < 0
94 * name <-- associated name if f_id < 0, or NULL
95 *
96 * returns:
97 * verbosity associated with field or name
98 *----------------------------------------------------------------------------*/
99
100int
102 const char *name);
103
104/*----------------------------------------------------------------------------*/
105/*
106 * \brief Return pointer to matrix structure matching equation solve.
107 *
108 * Some matrix properties (such as assembly options and geometric
109 * association) are set immediately, but coefficients are not
110 * assigned at this stage.
111 *
112 * \param[in] f_id associated field id, or < 0
113 * \param[in] name associated name if f_id < 0, or nullptr
114 * \param[in] db_size block sizes for diagonal
115 * \param[in] eb_size block sizes for extra diagonal
116 * \param[in] symmetric indicate if matrix is symmetric
117 *
118 * \return pointer to matrix structure
119 */
120/*----------------------------------------------------------------------------*/
121
124 const char *name,
125 cs_lnum_t db_size,
126 cs_lnum_t eb_size,
127 bool symmetric);
128
129/*----------------------------------------------------------------------------
130 * Release of destroy matrix depending on whether is is cached or not.
131 *
132 * Matrices built by assembler are destroyed.
133 *
134 * parameters:
135 * matrix <-> pointer to matrix structure
136 *----------------------------------------------------------------------------*/
137
138void
140
141/*----------------------------------------------------------------------------
142 * Default finalization for sparse linear equation solver API.
143 *
144 * This includes performance data logging output.
145 *----------------------------------------------------------------------------*/
146
147void
149
150/*----------------------------------------------------------------------------*/
151/*
152 * \brief Call sparse linear equation solver for general colocated
153 * cell-centered finite volume scheme.
154 *
155 * The initial solution is assumed to be 0 (and does not need to
156 * be initialized before calling this function).
157 *
158 * \param[in] sc solver context
159 * \param[in] a matrix
160 * \param[in] precision solver precision
161 * \param[in] r_norm residual normalization
162 * \param[out] n_iter number of "equivalent" iterations
163 * \param[out] residual residual
164 * \param[in] rhs right hand side
165 * \param[out] vx system solution
166 *
167 * \return convergence state
168 */
169/*----------------------------------------------------------------------------*/
170
173 cs_matrix_t *a,
174 double precision,
175 double r_norm,
176 int *n_iter,
177 double *residual,
178 const cs_real_t *rhs,
179 cs_real_t *vx);
180
181/*----------------------------------------------------------------------------
182 * Call sparse linear equation solver using native matrix arrays.
183 *
184 * parameters:
185 * f_id <-- associated field id, or < 0
186 * name <-- associated name if f_id < 0, or NULL
187 * symmetric <-- indicates if matrix coefficients are symmetric
188 * diag_block_size <-- block sizes for diagonal
189 * extra_diag_block_size <-- block sizes for extra diagonal
190 * da <-- diagonal values (NULL if zero)
191 * xa <-- extradiagonal values (NULL if zero)
192 * r_epsilon <-- precision
193 * r_norm <-- residual normalization
194 * n_iter --> number of iterations
195 * residual --> residual
196 * rhs <-- right hand side
197 * vx <-> system solution
198 *
199 * returns:
200 * convergence state
201 *----------------------------------------------------------------------------*/
202
204cs_sles_solve_native(int f_id,
205 const char *name,
206 bool symmetric,
207 cs_lnum_t diag_block_size,
208 cs_lnum_t extra_diag_block_size,
209 const cs_real_t *da,
210 const cs_real_t *xa,
211 double precision,
212 double r_norm,
213 int *n_iter,
214 double *residual,
215 const cs_real_t *rhs,
216 cs_real_t *vx);
217
218/*----------------------------------------------------------------------------
219 * Free sparse linear equation solver setup using native matrix arrays.
220 *
221 * parameters:
222 * f_id <-- associated field id, or < 0
223 * name <-- associated name if f_id < 0, or NULL
224 *----------------------------------------------------------------------------*/
225
226void
227cs_sles_free_native(int f_id,
228 const char *name);
229
230/*----------------------------------------------------------------------------
231 * Error handler attempting fallback to alternative solution procedure for
232 * sparse linear equation solver.
233 *
234 * In case of divergence with an iterative solver, this error handler
235 * switches to a default preconditioner, then resets the solution vector.
236 *
237 * The default error for the solver type handler is then set, in case
238 * the solution fails again.
239 *
240 * Note that this error handler may rebuild solver contexts, so should not
241 * be used in conjunction with shared contexts (such as multigrid
242 * ascent/descent contexts), but only for "outer" solvers.
243 *
244 * parameters:
245 * sles <-> pointer to solver object
246 * state <-- convergence status
247 * a <-- matrix
248 * rhs <-- right hand side
249 * vx <-> system solution
250 *
251 * returns:
252 * true if fallback solution is possible, false otherwise
253 *----------------------------------------------------------------------------*/
254
255bool
258 const cs_matrix_t *a,
259 const cs_real_t rhs[],
260 cs_real_t vx[]);
261
262/*----------------------------------------------------------------------------*/
263
265
266#endif /* CS_SLES_DEFAULT_H */
#define BEGIN_C_DECLS
Definition: cs_defs.h:528
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
#define END_C_DECLS
Definition: cs_defs.h:529
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:108
cs_sles_convergence_state_t
Definition: cs_sles.h:57
struct _cs_sles_t cs_sles_t
Definition: cs_sles.h:72
void cs_sles_free_native(int f_id, const char *name)
Free sparse linear equation solver setup using native matrix arrays.
Definition: cs_sles_default.cpp:1163
cs_matrix_t * cs_sles_default_get_matrix(int f_id, const char *name, cs_lnum_t db_size, cs_lnum_t eb_size, bool symmetric)
Return pointer to matrix structure matching equation solve.
Definition: cs_sles_default.cpp:669
int cs_sles_default_get_verbosity(int f_id, const char *name)
Return default verbosity associated to a field id, name couple.
Definition: cs_sles_default.cpp:626
cs_sles_convergence_state_t cs_sles_solve_native(int f_id, const char *name, bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size, const cs_real_t *da, const cs_real_t *xa, double precision, double r_norm, int *n_iter, double *residual, const cs_real_t *rhs, cs_real_t *vx)
Call sparse linear equation solver using native matrix arrays.
Definition: cs_sles_default.cpp:1002
void cs_sles_default_setup(void)
Default setup for sparse linear equation solver API.
Definition: cs_sles_default.cpp:550
cs_sles_convergence_state_t cs_sles_solve_ccc_fv(cs_sles_t *sc, cs_matrix_t *a, double precision, double r_norm, int *n_iter, double *residual, const cs_real_t *rhs, cs_real_t *vx)
Call sparse linear equation solver for general colocated cell-centered finite volume scheme.
Definition: cs_sles_default.cpp:890
void cs_sles_default_log_setup(void)
void cs_sles_default_finalize(void)
Default finalization for sparse linear equation solver API.
Definition: cs_sles_default.cpp:606
bool cs_sles_default_error(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 attempting fallback to alternative solution procedure for sparse linear equation solver...
Definition: cs_sles_default.cpp:1217
void cs_sles_default(int f_id, const char *name, const cs_matrix_t *a)
Default definition of a sparse linear equation solver.
Definition: cs_sles_default.cpp:531
void cs_sles_default_release_matrix(cs_matrix_t **m)
Definition: cs_sles_default.cpp:863