7.1
general documentation
cs_matrix_priv.h
Go to the documentation of this file.
1 #ifndef __CS_MATRIX_PRIV_H__
2 #define __CS_MATRIX_PRIV_H__
3 
4 /*============================================================================
5  * Private types for sparse matrix representation and operations.
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2021 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 "cs_defs.h"
35 
36 #include "cs_matrix.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
41 
44 /*============================================================================
45  * Macro definitions
46  *============================================================================*/
47 
48 /*============================================================================
49  * Type definitions
50  *============================================================================*/
51 
52 /* Formats currently supported:
53  *
54  * - Native
55  * - Compressed Sparse Row (CSR)
56  * - Modified Compressed Sparse Row (MSR), with separate diagonal
57  */
58 
59 /*----------------------------------------------------------------------------
60  * Function pointer types
61  *----------------------------------------------------------------------------*/
62 
63 typedef void
64 (cs_matrix_set_coeffs_t) (cs_matrix_t *matrix,
65  bool symmetric,
66  bool copy,
67  cs_lnum_t n_edges,
68  const cs_lnum_2_t *restrict edges,
69  const cs_real_t *restrict da,
70  const cs_real_t *restrict xa);
71 
72 typedef void
73 (cs_matrix_release_coeffs_t) (cs_matrix_t *matrix);
74 
75 typedef void
76 (cs_matrix_destroy_struct_t) (void **ms);
77 
78 typedef void
79 (cs_matrix_destroy_coeffs_t) (cs_matrix_t *matrix);
80 
81 typedef void
82 (cs_matrix_copy_diagonal_t) (const cs_matrix_t *matrix,
83  cs_real_t *restrict da);
84 
85 typedef const cs_real_t *
86 (cs_matrix_get_diagonal_t)(const cs_matrix_t *matrix);
87 
89 (cs_matrix_assembler_values_create_t) (cs_matrix_t *matrix,
90  const cs_lnum_t *diag_block_size,
91  const cs_lnum_t *extra_diag_block_size);
92 
93 /*----------------------------------------------------------------------------
94  * Function pointer for matrix-veector product (y = A.x).
95  *
96  * parameters:
97  * matrix <-- pointer to matrix structure
98  * exclude_diag <-- if true, compute (A-D).x instead of A.x
99  * sync <-- if true, synchronize ghost values
100  * x <-- x input vector (may be synchronized by this function)
101  * y <-- y output vector
102  *----------------------------------------------------------------------------*/
103 
104 typedef void
105 (cs_matrix_vector_product_t) (const cs_matrix_t *matrix,
106  bool exclude_diag,
107  bool sync,
108  cs_real_t *restrict x,
109  cs_real_t *restrict y);
110 
111 /*----------------------------------------------------------------------------
112  * Matrix types
113  *----------------------------------------------------------------------------*/
114 
115 /* Native matrix structure representation */
116 /*----------------------------------------*/
117 
118 /* Note: the members of this structure are already available through the top
119  * matrix structure, but are replicated here in case of future removal
120  * from the top structure (which would require computation/assignment of
121  * matrix coefficients in another form) */
122 
123 typedef struct _cs_matrix_struct_native_t {
124 
125  cs_lnum_t n_rows; /* Local number of rows */
126  cs_lnum_t n_cols_ext; /* Local number of columns + ghosts */
127  cs_lnum_t n_edges; /* Local number of graph edges
128  (for extra-diagonal terms) */
129 
130  /* Pointers to shared arrays */
131 
132  const cs_lnum_2_t *edges; /* Edges (symmetric row <-> column)
133  connectivity */
134 
135 } cs_matrix_struct_native_t;
136 
137 /* Native matrix coefficients */
138 /*----------------------------*/
139 
140 typedef struct _cs_matrix_coeff_native_t {
141 
142  bool symmetric; /* Symmetry indicator */
143  int max_db_size; /* Current max allocated diag block size */
144  int max_eb_size; /* Current max allocated extradiag block size */
145 
146  /* Pointers to possibly shared arrays */
147 
148  const cs_real_t *da; /* Diagonal terms */
149  const cs_real_t *xa; /* Extra-diagonal terms */
150 
151  /* Pointers to private arrays (NULL if shared) */
152 
153  cs_real_t *_da; /* Diagonal terms */
154  cs_real_t *_xa; /* Extra-diagonal terms */
155 
156 } cs_matrix_coeff_native_t;
157 
158 /* CSR (Compressed Sparse Row) matrix structure representation */
159 /*-------------------------------------------------------------*/
160 
161 typedef struct _cs_matrix_struct_csr_t {
162 
163  cs_lnum_t n_rows; /* Local number of rows */
164  cs_lnum_t n_cols_ext; /* Local number of columns + ghosts */
165 
166  /* Pointers to structure arrays and info (row_index, col_id) */
167 
168  bool have_diag; /* Has non-zero diagonal */
169  bool direct_assembly; /* True if each value corresponds to
170  a unique face ; false if multiple
171  faces contribute to the same
172  value (i.e. we have split faces) */
173 
174  const cs_lnum_t *row_index; /* Pointer to row index (0 to n-1) */
175  const cs_lnum_t *col_id; /* Pointer to column id (0 to n-1) */
176 
177  cs_lnum_t *_row_index; /* Row index (0 to n-1), if owner */
178  cs_lnum_t *_col_id; /* Column id (0 to n-1), if owner */
179 
180 } cs_matrix_struct_csr_t;
181 
182 /* CSR matrix coefficients representation */
183 /*----------------------------------------*/
184 
185 typedef struct _cs_matrix_coeff_csr_t {
186 
187  /* Pointers to possibly shared arrays */
188 
189  const cs_real_t *val; /* Matrix coefficients */
190 
191  /* Pointers to private arrays (NULL if shared) */
192 
193  cs_real_t *_val; /* Diagonal matrix coefficients */
194 
195  /* Pointers to auxiliary arrays used for queries */
196 
197  const cs_real_t *d_val; /* Pointer to diagonal matrix
198  coefficients, if queried */
199  cs_real_t *_d_val; /* Diagonal matrix coefficients,
200  if queried */
201 
202 } cs_matrix_coeff_csr_t;
203 
204 /* MSR matrix coefficients representation */
205 /*----------------------------------------*/
206 
207 typedef struct _cs_matrix_coeff_msr_t {
208 
209  int max_db_size; /* Current max allocated block size */
210  int max_eb_size; /* Current max allocated extradiag
211  block size */
212 
213  /* Pointers to possibly shared arrays */
214 
215  const cs_real_t *d_val; /* Diagonal matrix coefficients */
216  const cs_real_t *x_val; /* Extra-diagonal matrix coefficients */
217 
218  /* Pointers to private arrays (NULL if shared) */
219 
220  cs_real_t *_d_val; /* Diagonal matrix coefficients */
221  cs_real_t *_x_val; /* Extra-diagonal matrix coefficients */
222 
223 } cs_matrix_coeff_msr_t;
224 
225 /* Matrix structure (representation-independent part) */
226 /*----------------------------------------------------*/
227 
228 struct _cs_matrix_structure_t {
229 
230  cs_matrix_type_t type; /* Matrix storage and definition type */
231 
232  cs_lnum_t n_rows; /* Local number of rows */
233  cs_lnum_t n_cols_ext; /* Local number of columns + ghosts */
234 
235  void *structure; /* Matrix structure */
236 
237  /* Pointers to shared arrays from mesh structure
238  (face->cell connectivity for coefficient assignment,
239  local->local cell numbering for future info or renumbering,
240  and halo) */
241 
242  const cs_halo_t *halo; /* Parallel or periodic halo */
243  const cs_numbering_t *numbering; /* Vectorization or thread-related
244  numbering information */
245 
246  const cs_matrix_assembler_t *assembler; /* Associated matrix assembler */
247 };
248 
249 /* Structure associated with Matrix (representation-independent part) */
250 /*--------------------------------------------------------------------*/
251 
252 struct _cs_matrix_t {
253 
254  cs_matrix_type_t type; /* Matrix storage and definition type */
255 
256  const char *type_name; /* Pointer to matrix type name string */
257  const char *type_fname; /* Pointer to matrix type
258  full name string */
259 
260  cs_lnum_t n_rows; /* Local number of rows */
261  cs_lnum_t n_cols_ext; /* Local number of columns + ghosts */
262 
263  cs_matrix_fill_type_t fill_type; /* Matrix fill type */
264 
265  bool symmetric; /* true if coefficients are symmetric */
266 
267  cs_lnum_t db_size[4]; /* Diag Block size, including padding:
268  0: useful block size
269  1: vector block extents
270  2: matrix line extents
271  3: matrix line*column extents */
272 
273  cs_lnum_t eb_size[4]; /* Extradiag block size, including padding:
274  0: useful block size
275  1: vector block extents
276  2: matrix line extents
277  3: matrix line*column extents */
278 
279  /* Pointer to shared structure */
280 
281  const void *structure; /* Possibly shared matrix structure */
282  void *_structure; /* Private matrix structure */
283 
284  /* Pointers to arrays possibly shared from mesh structure
285  (graph edges: face->cell connectivity for coefficient assignment,
286  rows: local->local cell numbering for future info or renumbering,
287  and halo) */
288 
289  const cs_halo_t *halo; /* Parallel or periodic halo */
290  const cs_numbering_t *numbering; /* Vectorization or thread-related
291  numbering information */
292 
293  const cs_matrix_assembler_t *assembler; /* Associated matrix assembler */
294 
295  /* Pointer to shared arrays from coefficient assignment from
296  "native" type. This should be removed in the future, but requires
297  removing the dependency to the native structure in the multigrid
298  code first. */
299 
300  const cs_real_t *xa; /* Extra-diagonal terms */
301 
302  /* Pointer to private data */
303 
304  void *coeffs; /* Matrix coefficients */
305 
306  /* Function pointers */
307 
308  cs_matrix_set_coeffs_t *set_coefficients;
309  cs_matrix_release_coeffs_t *release_coefficients;
310  cs_matrix_copy_diagonal_t *copy_diagonal;
311  cs_matrix_get_diagonal_t *get_diagonal;
312 
313  cs_matrix_destroy_struct_t *destroy_structure;
314  cs_matrix_destroy_coeffs_t *destroy_coefficients;
315 
316  cs_matrix_assembler_values_create_t *assembler_values_create;
317 
318  /* Function pointer arrays, with CS_MATRIX_N_FILL_TYPES variants:
319  fill_type*2 + exclude_diagonal_flag */
320 
321  cs_matrix_vector_product_t *vector_multiply[CS_MATRIX_N_FILL_TYPES][2];
322 
323 };
324 
325 /* Structure used for tuning variants */
326 /*------------------------------------*/
327 
328 struct _cs_matrix_variant_t {
329 
330  char name[2][32]; /* Variant names */
331 
332  cs_matrix_type_t type; /* Matrix storage and definition type */
333  cs_matrix_fill_type_t fill_type; /* Matrix storage and definition type */
334 
335  /* Function pointer arrays, with and without exclude_diagonal_flag */
336 
337  cs_matrix_vector_product_t *vector_multiply[2];
338 };
339 
342 /*=============================================================================
343  * Semi-private function prototypes
344  *============================================================================*/
345 
346 /*----------------------------------------------------------------------------*/
347 
349 
350 #endif /* __CS_MATRIX_PRIV_H__ */
#define restrict
Definition: cs_defs.h:142
struct _cs_matrix_assembler_values_t cs_matrix_assembler_values_t
Definition: cs_matrix_assembler.h:65
#define BEGIN_C_DECLS
Definition: cs_defs.h:510
Definition: cs_matrix.h:83
Definition: cs_halo.h:77
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
void matrix(const int *iconvp, const int *idiffp, const int *ndircp, const int *isym, const cs_real_t *thetap, const int *imucpp, const cs_real_t coefbp[], const cs_real_t cofbfp[], const cs_real_t rovsdt[], const cs_real_t i_massflux[], const cs_real_t b_massflux[], const cs_real_t i_visc[], const cs_real_t b_visc[], const cs_real_t xcpp[], cs_real_t da[], cs_real_t xa[])
Definition: cs_matrix_building.c:111
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:93
cs_matrix_type_t
Definition: cs_matrix.h:55
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:328
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:316
#define END_C_DECLS
Definition: cs_defs.h:511
struct _cs_matrix_assembler_t cs_matrix_assembler_t
Definition: cs_matrix_assembler.h:61
Definition: cs_numbering.h:83
cs_matrix_fill_type_t
Definition: cs_matrix.h:70