9.2
general documentation
cs_matrix_default.h
Go to the documentation of this file.
1#ifndef CS_MATRIX_DEFAULT_H
2#define CS_MATRIX_DEFAULT_H
3
4/*============================================================================
5 * Default Sparse Matrix structure and Tuning.
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_defs.h"
35
36#include "base/cs_field.h"
37#include "base/cs_halo.h"
38#include "alge/cs_matrix.h"
39#include "base/cs_numbering.h"
40#include "base/cs_halo_perio.h"
41
42/*============================================================================
43 * Macro definitions
44 *============================================================================*/
45
46/*============================================================================
47 * Type definitions
48 *============================================================================*/
49
50/*============================================================================
51 * Global variables
52 *============================================================================*/
53
54/*=============================================================================
55 * Public function prototypes
56 *============================================================================*/
57
58/*----------------------------------------------------------------------------
59 * Matrix (native format) vector product
60 *
61 * parameters:
62 * symmetric <-- Symmetry indicator:
63 * db_size <-- block sizes for diagonal
64 * eb_size <-- block sizes for extra diagonal
65 * f_id <-- associated field id, or < 0
66 * dam <-- Matrix diagonal
67 * xam <-- Matrix extra-diagonal terms
68 * vx <-- A*vx
69 * vy <-> vy = A*vx
70 *----------------------------------------------------------------------------*/
71
72void
74 cs_lnum_t db_size,
75 cs_lnum_t eb_size,
76 int f_id,
77 const cs_real_t *dam,
78 const cs_real_t *xam,
79 cs_real_t *vx,
80 cs_real_t *vy);
81
82/*----------------------------------------------------------------------------
83 * Initialize sparse matrix API.
84 *----------------------------------------------------------------------------*/
85
86void
88
89/*----------------------------------------------------------------------------
90 * Finalize sparse matrix API.
91 *----------------------------------------------------------------------------*/
92
93void
95
96/*----------------------------------------------------------------------------
97 * Update sparse matrix API in case of mesh modification.
98 *----------------------------------------------------------------------------*/
99
100void
102
103/*----------------------------------------------------------------------------
104 * Return default matrix for a given fill type
105 *
106 * parameters:
107 * symmetric <-- Indicates if matrix coefficients are symmetric
108 * diag_block_size <-- Block sizes for diagonal
109 * extra_diag_block_size <-- Block sizes for extra diagonal
110 *
111 * returns:
112 * pointer to default matrix structure adapted to fill type
113 *----------------------------------------------------------------------------*/
114
116cs_matrix_default(bool symmetric,
117 cs_lnum_t diag_block_size,
118 cs_lnum_t extra_diag_block_size);
119
120/*----------------------------------------------------------------------------
121 * Return MSR matrix
122 *
123 * returns:
124 * pointer to MSR matrix
125 *----------------------------------------------------------------------------*/
126
128cs_matrix_msr(void);
129
130/*----------------------------------------------------------------------------
131 * Return CSR matrix for a given fill type
132 *
133 * returns:
134 * pointer to CSR matrix
135 *----------------------------------------------------------------------------*/
136
138cs_matrix_csr(void);
139
140/*----------------------------------------------------------------------------
141 * Return native matrix
142 *
143 * returns:
144 * pointer to native matrix
145 *----------------------------------------------------------------------------*/
146
148cs_matrix_native(void);
149
150/*----------------------------------------------------------------------------*/
151/*
152 * \brief Return matrix wrapper for external library for a given fill type.
153 *
154 * \param[in] type_name Matrix type name
155 * \param[in] symmetric Indicates if coefficients are symmetric
156 * \param[in] diag_block_size Block sizes for diagonal
157 * \param[in] extra_diag_block_size Block sizes for extra diagonal
158 *
159 * \return Pointer to matrix matching requested type
160 */
161/*----------------------------------------------------------------------------*/
162
164cs_matrix_external(const char *type_name,
165 bool symmetric,
166 cs_lnum_t diag_block_size,
167 cs_lnum_t extra_diag_block_size);
168
169/*----------------------------------------------------------------------------*/
170/*
171 * \brief Copy base matrix to external library matrix type for given fill type.
172 *
173 * Note that the matrix containers share the same assigned structure,
174 * so they must be both destroyed before that structure.
175 *
176 * Coefficients and matching structures are not copied or created.
177 *
178 * This function is intended to allow sharing of a base structure or assembler
179 * with an external library matrix wrapper, so as to allow efficient
180 * coefficient assignment, but with external coefficient handling.
181 *
182 * The matrix shoud be converted to the desired external type after calling
183 * this function, so that it can the be accessed using \ref cs_matrix_external.
184 *
185 * \param[in] symmetric Indicates if matrix coefficients are symmetric
186 * \param[in] diag_block_size Block sizes for diagonal
187 * \param[in] extra_diag_block_size Block sizes for extra diagonal
188 *
189 * \return pointer to native matrix adapted to fill type
190 */
191/*----------------------------------------------------------------------------*/
192
195 bool symmetric,
196 cs_lnum_t diag_block_size,
197 cs_lnum_t extra_diag_block_size);
198
199/*----------------------------------------------------------------------------
200 * Determine or apply default tuning for a given matrix type
201 *
202 * Information from the variant used fo this definition is copied,
203 * so it may be freed after calling this function.
204 *
205 * parameters:
206 * fill type <-- Fill type for which tuning behavior is set
207 * mv <-- Matrix variant to use for this type
208 *----------------------------------------------------------------------------*/
209
210void
212
213/*----------------------------------------------------------------------------
214 * Set number of matrix computation runs for tuning.
215 *
216 * If this function is not called, defaults are:
217 * - minimum of 10 runs
218 *
219 * parameters:
220 * n_min_products <-- minimum number of SpM.V products for tuning.
221 *----------------------------------------------------------------------------*/
222
223void
224cs_matrix_set_tuning_runs(int n_min_products);
225
226/*----------------------------------------------------------------------------
227 * Get number of matrix computation runs for tuning.
228 *
229 * return:
230 * minimum number of SpM.V calls for tuning
231 *----------------------------------------------------------------------------*/
232
233int
235
236/*----------------------------------------------------------------------------*/
237/*
238 * \brief Set default matrix type for a given fill type.
239 *
240 * \param[in] fill type Fill type for which tuning behavior is set
241 * \param[in] type Matrix type to use
242 */
243/*----------------------------------------------------------------------------*/
244
245void
247 cs_matrix_type_t type);
248
249/*----------------------------------------------------------------------------*/
250/*
251 * \brief Return a (0-based) global block row numbering for a given matrix.
252 *
253 * The numbering is built or updated if not previously used, or if the
254 * previous call considered a different matrix or halo, and is simply
255 * returned otherwise.
256 * In other words, this works as a matrix global numbering cache.
257 *
258 * The matrix's halo is used for the update.
259 *
260 * \param[in] m associated matrix
261 *
262 * \return pointer to requested global numbering
263 */
264/*----------------------------------------------------------------------------*/
265
266const cs_gnum_t *
268
269/*----------------------------------------------------------------------------*/
270/*
271 * \brief Return a (0-based) global block row numbering for a given matrix.
272 *
273 * The numbering is built or updated if not previously used, or if the
274 * previous call considered a different matrix or halo, and is simply
275 * returned otherwise.
276 * In other words, this works as a matrix global numbering cache.
277 *
278 * \param[in] m associated matrix
279 * \param[in] halo associated halo
280 *
281 * \return pointer to requested global numbering
282 */
283/*----------------------------------------------------------------------------*/
284
285const cs_gnum_t *
287 const cs_halo_t *halo);
288
289/*----------------------------------------------------------------------------*/
290/*
291 * \brief Return matrix associated with a matrix assembler.
292 *
293 * Coefficients are not assigned at this stage.
294 *
295 * \param[in] f pointer to associated field
296 * \param[in] type matrix type
297 *
298 * \return pointer to associated matrix structure
299 */
300/*----------------------------------------------------------------------------*/
301
304 cs_matrix_type_t type);
305
306/*----------------------------------------------------------------------------*/
307/*
308 * \brief Assign coefficients to a matrix using a matrix assembler.
309 *
310 * \param[in] f pointer to associated field
311 * \param[in] type matrix type
312 * \param[in] symmetric is matrix symmetric ?
313 * \param[in] diag_block_size block sizes for diagonal, or nullptr
314 * \param[in] extra_diag_block_size block sizes for extra diagonal, or nullptr
315 * \param[in] da diagonal values (nullptr if zero)
316 * \param[in] xa extradiagonal values (nullptr if zero)
317 * casts as:
318 * xa[n_edges] if symmetric,
319 * xa[n_edges][2] if non symmetric
320 *
321 * \return pointer to associated matrix structure
322 */
323/*----------------------------------------------------------------------------*/
324
327 cs_matrix_type_t type,
328 bool symmetric,
329 cs_lnum_t diag_block_size,
330 cs_lnum_t extra_diag_block_size,
331 const cs_real_t *da,
332 const cs_real_t *xa);
333
334/*----------------------------------------------------------------------------
335 * Release of destroy matrix depending on whether is is cached or not.
336 *
337 * Matrices built by assembler are destroyed.
338 *
339 * parameters:
340 * matrix <-> pointer to matrix structure pointer
341 *----------------------------------------------------------------------------*/
342
343void
345
346/*----------------------------------------------------------------------------*/
347
348#endif /* CS_MATRIX_DEFAULT_H */
Field descriptor.
Definition: cs_field.h:275
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:317
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_matrix_fill_type_t
Definition: cs_matrix.h:70
cs_matrix_type_t
Definition: cs_matrix.h:52
cs_matrix_t * cs_matrix_by_assembler(const cs_field_t *f, cs_matrix_type_t type)
Return matrix associated with a matrix assembler.
Definition: cs_matrix_default.cpp:962
int cs_matrix_get_tuning_runs(void)
Definition: cs_matrix_default.cpp:864
cs_matrix_t * cs_matrix_external(const char *type_name, bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Return matrix wrapper for external library for a given fill type.
Definition: cs_matrix_default.cpp:666
const cs_gnum_t * cs_matrix_get_block_row_g_id(const cs_matrix_t *m)
Return a (0-based) global block row numbering for a given matrix.
Definition: cs_matrix_default.cpp:906
cs_matrix_t * cs_matrix_msr(void)
Definition: cs_matrix_default.cpp:621
cs_matrix_t * cs_matrix_copy_to_external(cs_matrix_t *src, bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Copy base matrix to external library matrix type for given fill type.
Definition: cs_matrix_default.cpp:771
void cs_matrix_finalize(void)
Definition: cs_matrix_default.cpp:496
void cs_matrix_update_mesh(void)
Definition: cs_matrix_default.cpp:551
void cs_matrix_vector_native_multiply(bool symmetric, cs_lnum_t db_size, cs_lnum_t eb_size, int f_id, const cs_real_t *dam, const cs_real_t *xam, cs_real_t *vx, cs_real_t *vy)
Definition: cs_matrix_default.cpp:431
cs_matrix_t * cs_matrix_set_coefficients_by_assembler(const cs_field_t *f, cs_matrix_type_t type, 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)
Assign coefficients to a matrix using a matrix assembler.
Definition: cs_matrix_default.cpp:1007
void cs_matrix_release(cs_matrix_t **m)
Definition: cs_matrix_default.cpp:1141
void cs_matrix_initialize(void)
Definition: cs_matrix_default.cpp:475
void cs_matrix_default_set_type(cs_matrix_fill_type_t fill_type, cs_matrix_type_t type)
Set default matrix type for a given fill type.
Definition: cs_matrix_default.cpp:882
cs_matrix_t * cs_matrix_csr(void)
Definition: cs_matrix_default.cpp:634
void cs_matrix_default_set_tuned(cs_matrix_t *m)
Definition: cs_matrix_default.cpp:810
cs_matrix_t * cs_matrix_default(bool symmetric, cs_lnum_t diag_block_size, cs_lnum_t extra_diag_block_size)
Definition: cs_matrix_default.cpp:594
cs_matrix_t * cs_matrix_native(void)
Definition: cs_matrix_default.cpp:647
void cs_matrix_set_tuning_runs(int n_min_products)
Definition: cs_matrix_default.cpp:848
Definition: cs_halo.h:74