9.1
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-2025 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
45
46/*============================================================================
47 * Macro definitions
48 *============================================================================*/
49
50/*============================================================================
51 * Type definitions
52 *============================================================================*/
53
54/*============================================================================
55 * Global variables
56 *============================================================================*/
57
58/*=============================================================================
59 * Public function prototypes
60 *============================================================================*/
61
62/*----------------------------------------------------------------------------
63 * Matrix (native format) vector product
64 *
65 * parameters:
66 * symmetric <-- Symmetry indicator:
67 * db_size <-- block sizes for diagonal
68 * eb_size <-- block sizes for extra diagonal
69 * f_id <-- associated field id, or < 0
70 * dam <-- Matrix diagonal
71 * xam <-- Matrix extra-diagonal terms
72 * vx <-- A*vx
73 * vy <-> vy = A*vx
74 *----------------------------------------------------------------------------*/
75
76void
78 cs_lnum_t db_size,
79 cs_lnum_t eb_size,
80 int f_id,
81 const cs_real_t *dam,
82 const cs_real_t *xam,
83 cs_real_t *vx,
84 cs_real_t *vy);
85
86/*----------------------------------------------------------------------------
87 * Initialize sparse matrix API.
88 *----------------------------------------------------------------------------*/
89
90void
92
93/*----------------------------------------------------------------------------
94 * Finalize sparse matrix API.
95 *----------------------------------------------------------------------------*/
96
97void
99
100/*----------------------------------------------------------------------------
101 * Update sparse matrix API in case of mesh modification.
102 *----------------------------------------------------------------------------*/
103
104void
106
107/*----------------------------------------------------------------------------
108 * Return default matrix for a given fill type
109 *
110 * parameters:
111 * symmetric <-- Indicates if matrix coefficients are symmetric
112 * diag_block_size <-- Block sizes for diagonal
113 * extra_diag_block_size <-- Block sizes for extra diagonal
114 *
115 * returns:
116 * pointer to default matrix structure adapted to fill type
117 *----------------------------------------------------------------------------*/
118
120cs_matrix_default(bool symmetric,
121 cs_lnum_t diag_block_size,
122 cs_lnum_t extra_diag_block_size);
123
124/*----------------------------------------------------------------------------
125 * Return MSR matrix
126 *
127 * returns:
128 * pointer to MSR matrix
129 *----------------------------------------------------------------------------*/
130
132cs_matrix_msr(void);
133
134/*----------------------------------------------------------------------------
135 * Return CSR matrix for a given fill type
136 *
137 * returns:
138 * pointer to CSR matrix
139 *----------------------------------------------------------------------------*/
140
142cs_matrix_csr(void);
143
144/*----------------------------------------------------------------------------
145 * Return native matrix
146 *
147 * returns:
148 * pointer to native matrix
149 *----------------------------------------------------------------------------*/
150
152cs_matrix_native(void);
153
154/*----------------------------------------------------------------------------*/
155/*
156 * \brief Return matrix wrapper for external library for a given fill type.
157 *
158 * \param[in] type_name Matrix type name
159 * \param[in] symmetric Indicates if coefficients are symmetric
160 * \param[in] diag_block_size Block sizes for diagonal
161 * \param[in] extra_diag_block_size Block sizes for extra diagonal
162 *
163 * \return Pointer to matrix matching requested type
164 */
165/*----------------------------------------------------------------------------*/
166
168cs_matrix_external(const char *type_name,
169 bool symmetric,
170 cs_lnum_t diag_block_size,
171 cs_lnum_t extra_diag_block_size);
172
173/*----------------------------------------------------------------------------*/
174/*
175 * \brief Copy base matrix to external library matrix type for given fill type.
176 *
177 * Note that the matrix containers share the same assigned structure,
178 * so they must be both destroyed before that structure.
179 *
180 * Coefficients and matching structures are not copied or created.
181 *
182 * This function is intended to allow sharing of a base structure or assembler
183 * with an external library matrix wrapper, so as to allow efficient
184 * coefficient assignment, but with external coefficient handling.
185 *
186 * The matrix shoud be converted to the desired external type after calling
187 * this function, so that it can the be accessed using \ref cs_matrix_external.
188 *
189 * \param[in] symmetric Indicates if matrix coefficients are symmetric
190 * \param[in] diag_block_size Block sizes for diagonal
191 * \param[in] extra_diag_block_size Block sizes for extra diagonal
192 *
193 * \return pointer to native matrix adapted to fill type
194 */
195/*----------------------------------------------------------------------------*/
196
199 bool symmetric,
200 cs_lnum_t diag_block_size,
201 cs_lnum_t extra_diag_block_size);
202
203/*----------------------------------------------------------------------------
204 * Determine or apply default tuning for a given matrix type
205 *
206 * Information from the variant used fo this definition is copied,
207 * so it may be freed after calling this function.
208 *
209 * parameters:
210 * fill type <-- Fill type for which tuning behavior is set
211 * mv <-- Matrix variant to use for this type
212 *----------------------------------------------------------------------------*/
213
214void
216
217/*----------------------------------------------------------------------------
218 * Set number of matrix computation runs for tuning.
219 *
220 * If this function is not called, defaults are:
221 * - minimum of 10 runs
222 *
223 * parameters:
224 * n_min_products <-- minimum number of SpM.V products for tuning.
225 *----------------------------------------------------------------------------*/
226
227void
228cs_matrix_set_tuning_runs(int n_min_products);
229
230/*----------------------------------------------------------------------------
231 * Get number of matrix computation runs for tuning.
232 *
233 * return:
234 * minimum number of SpM.V calls for tuning
235 *----------------------------------------------------------------------------*/
236
237int
239
240/*----------------------------------------------------------------------------*/
241/*
242 * \brief Set default matrix type for a given fill type.
243 *
244 * \param[in] fill type Fill type for which tuning behavior is set
245 * \param[in] type Matrix type to use
246 */
247/*----------------------------------------------------------------------------*/
248
249void
251 cs_matrix_type_t type);
252
253/*----------------------------------------------------------------------------*/
254/*
255 * \brief Return a (0-based) global block row numbering for a given matrix.
256 *
257 * The numbering is built or updated if not previously used, or if the
258 * previous call considered a different matrix or halo, and is simply
259 * returned otherwise.
260 * In other words, this works as a matrix global numbering cache.
261 *
262 * The matrix's halo is used for the update.
263 *
264 * \param[in] m associated matrix
265 *
266 * \return pointer to requested global numbering
267 */
268/*----------------------------------------------------------------------------*/
269
270const cs_gnum_t *
272
274#ifdef __cplusplus
275
276/*----------------------------------------------------------------------------*/
277/*
278 * \brief Return a (0-based) global block row numbering for a given matrix.
279 *
280 * The numbering is built or updated if not previously used, or if the
281 * previous call considered a different matrix or halo, and is simply
282 * returned otherwise.
283 * In other words, this works as a matrix global numbering cache.
284 *
285 * \param[in] m associated matrix
286 * \param[in] halo associated halo
287 *
288 * \return pointer to requested global numbering
289 */
290/*----------------------------------------------------------------------------*/
291
292const cs_gnum_t *
294 const cs_halo_t *halo);
295
296#endif /* cplusplus */
298
299/*----------------------------------------------------------------------------*/
300/*
301 * \brief Return matrix associated with a matrix assembler.
302 *
303 * Coefficients are not assigned at this stage.
304 *
305 * \param[in] f pointer to associated field
306 * \param[in] type matrix type
307 *
308 * \return pointer to associated matrix structure
309 */
310/*----------------------------------------------------------------------------*/
311
314 cs_matrix_type_t type);
315
316/*----------------------------------------------------------------------------*/
317/*
318 * \brief Assign coefficients to a matrix using a matrix assembler.
319 *
320 * \param[in] f pointer to associated field
321 * \param[in] type matrix type
322 * \param[in] symmetric is matrix symmetric ?
323 * \param[in] diag_block_size block sizes for diagonal, or nullptr
324 * \param[in] extra_diag_block_size block sizes for extra diagonal, or nullptr
325 * \param[in] da diagonal values (nullptr if zero)
326 * \param[in] xa extradiagonal values (nullptr if zero)
327 * casts as:
328 * xa[n_edges] if symmetric,
329 * xa[n_edges][2] if non symmetric
330 *
331 * \return pointer to associated matrix structure
332 */
333/*----------------------------------------------------------------------------*/
334
337 cs_matrix_type_t type,
338 bool symmetric,
339 cs_lnum_t diag_block_size,
340 cs_lnum_t extra_diag_block_size,
341 const cs_real_t *da,
342 const cs_real_t *xa);
343
344/*----------------------------------------------------------------------------
345 * Release of destroy matrix depending on whether is is cached or not.
346 *
347 * Matrices built by assembler are destroyed.
348 *
349 * parameters:
350 * matrix <-> pointer to matrix structure pointer
351 *----------------------------------------------------------------------------*/
352
353void
355
356/*----------------------------------------------------------------------------*/
357
359
360#endif /* __CS_MATRIX_DEFAULT_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:342
#define END_C_DECLS
Definition: cs_defs.h:555
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:114
cs_matrix_fill_type_t
Definition: cs_matrix.h:76
cs_matrix_type_t
Definition: cs_matrix.h:58
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:948
int cs_matrix_get_tuning_runs(void)
Definition: cs_matrix_default.cpp:844
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:648
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:886
cs_matrix_t * cs_matrix_msr(void)
Definition: cs_matrix_default.cpp:603
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:750
void cs_matrix_finalize(void)
Definition: cs_matrix_default.cpp:484
void cs_matrix_update_mesh(void)
Definition: cs_matrix_default.cpp:534
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:417
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:994
void cs_matrix_release(cs_matrix_t **m)
Definition: cs_matrix_default.cpp:1129
void cs_matrix_initialize(void)
Definition: cs_matrix_default.cpp:463
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:862
cs_matrix_t * cs_matrix_csr(void)
Definition: cs_matrix_default.cpp:616
void cs_matrix_default_set_tuned(cs_matrix_t *m)
Definition: cs_matrix_default.cpp:787
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:576
cs_matrix_t * cs_matrix_native(void)
Definition: cs_matrix_default.cpp:629
void cs_matrix_set_tuning_runs(int n_min_products)
Definition: cs_matrix_default.cpp:828
Field descriptor.
Definition: cs_field.h:156
Definition: cs_halo.h:78