8.2
general documentation
cs_grid.h
Go to the documentation of this file.
1 #ifndef __CS_GRID_H__
2 #define __CS_GRID_H__
3 
4 /*============================================================================
5  * Grid connectivity and data used for multigrid coarsening
6  * and associated matrix construction.
7  *============================================================================*/
8 
9 /*
10  This file is part of code_saturne, a general-purpose CFD tool.
11 
12  Copyright (C) 1998-2024 EDF S.A.
13 
14  This program is free software; you can redistribute it and/or modify it under
15  the terms of the GNU General Public License as published by the Free Software
16  Foundation; either version 2 of the License, or (at your option) any later
17  version.
18 
19  This program is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22  details.
23 
24  You should have received a copy of the GNU General Public License along with
25  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
26  Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 */
28 
29 /*----------------------------------------------------------------------------*/
30 
31 /*----------------------------------------------------------------------------
32  * Local headers
33  *----------------------------------------------------------------------------*/
34 
35 #include "cs_base.h"
36 
37 #include "cs_dispatch.h"
38 #include "cs_halo.h"
39 #include "cs_matrix.h"
40 
41 /*----------------------------------------------------------------------------*/
42 
44 
45 /*============================================================================
46  * Macro definitions
47  *============================================================================*/
48 
49 /*============================================================================
50  * Type definitions
51  *============================================================================*/
52 
53 /* Aggregation algorithm */
54 
55 typedef enum {
56 
65 
66 /* Structure associated with opaque grid object */
67 
68 typedef struct _cs_grid_t cs_grid_t;
69 
70 /*============================================================================
71  * Global variables
72  *============================================================================*/
73 
74 /* Names for coarsening options */
75 
76 extern const char *cs_grid_coarsening_type_name[];
77 
78 /*============================================================================
79  * Semi-private function prototypes
80  *
81  * The following functions are intended to be used by the multigrid layer
82  * (cs_multigrid.c), not directly by the user, so they are no more
83  * documented than private static functions)
84  *============================================================================*/
85 
86 /*----------------------------------------------------------------------------
87  * Create base grid by mapping from shared mesh values.
88  *
89  * Note that as arrays given as arguments are shared by the created grid
90  * (which can only access them, not modify them), the grid should be
91  * destroyed before those arrays.
92  *
93  * parameters:
94  * n_faces <-- Local number of faces
95  * db_size <-- Block sizes for diagonal
96  * eb_size <-- Block sizes for extra-diagonal
97  * face_cell <-- Face -> cells connectivity
98  * a <-- Associated matrix
99  * conv_diff <-- Convection-diffusion mode
100  *
101  * returns:
102  * base grid structure
103  *----------------------------------------------------------------------------*/
104 
105 cs_grid_t *
107  cs_lnum_t db_size,
108  cs_lnum_t eb_size,
109  const cs_lnum_2_t *face_cell,
110  const cs_matrix_t *a,
111  bool conv_diff);
112 
113 /*----------------------------------------------------------------------------
114  * Create base grid by mapping from parent (possibly shared) matrix.
115  *
116  * Note that as arrays given as arguments are shared by the created grid
117  * (which can only access them, not modify them), the grid should be
118  * destroyed before those arrays.
119  *
120  * parameters:
121  * a <-- associated matrix
122  * n_ranks <-- number of active ranks (<= 1 to restrict to local values)
123  *
124  * returns:
125  * base grid structure
126  *----------------------------------------------------------------------------*/
127 
128 cs_grid_t *
130  int n_ranks);
131 
132 /*----------------------------------------------------------------------------
133  * Destroy a grid structure.
134  *
135  * parameters:
136  * grid <-> Pointer to grid structure pointer
137  *----------------------------------------------------------------------------*/
138 
139 void
141 
142 /*----------------------------------------------------------------------------
143  * Free a grid structure's associated quantities.
144  *
145  * The quantities required to compute a coarser grid with relaxation from a
146  * given grid are not needed after that stage, so may be freed.
147  *
148  * parameters:
149  * g <-> Pointer to grid structure
150  *----------------------------------------------------------------------------*/
151 
152 void
154 
155 /*----------------------------------------------------------------------------
156  * Get grid information.
157  *
158  * parameters:
159  * g <-- Grid structure
160  * level --> Level in multigrid hierarchy (or NULL)
161  * symmetric --> Symmetric matrix coefficients indicator (or NULL)
162  * db_size --> Size of the diagonal block (or NULL)
163  * eb_size --> Size of the extra diagonal block (or NULL)
164  * n_ranks --> number of ranks with data (or NULL)
165  * n_rows --> Number of local rows (or NULL)
166  * n_cols_ext --> Number of columns including ghosts (or NULL)
167  * n_entries --> Number of entries (or NULL)
168  * n_g_rows --> Number of global rows (or NULL)
169  *----------------------------------------------------------------------------*/
170 
171 void
173  int *level,
174  bool *symmetric,
175  cs_lnum_t *db_size,
176  cs_lnum_t *eb_size,
177  int *n_ranks,
178  cs_lnum_t *n_rows,
179  cs_lnum_t *n_cols_ext,
180  cs_lnum_t *n_entries,
181  cs_gnum_t *n_g_rows);
182 
183 /*----------------------------------------------------------------------------
184  * Get memory allocation mode corresponding to a grid.
185  *
186  * parameters:
187  * g <-- Grid structure
188  *
189  * returns:
190  * memory allocation typt
191  *----------------------------------------------------------------------------*/
192 
195 
196 /*----------------------------------------------------------------------------
197  * Get number of rows corresponding to a grid.
198  *
199  * parameters:
200  * g <-- Grid structure
201  *
202  * returns:
203  * number of rows of grid structure
204  *----------------------------------------------------------------------------*/
205 
206 cs_lnum_t
208 
209 /*----------------------------------------------------------------------------
210  * Get number of extended (local + ghost) columns corresponding to a grid.
211  *
212  * parameters:
213  * g <-- Grid structure
214  *
215  * returns:
216  * number of extended columns of grid structure
217  *----------------------------------------------------------------------------*/
218 
219 cs_lnum_t
221 
222 /*----------------------------------------------------------------------------
223  * Get maximum number of extended (local + ghost) columns corresponding to
224  * a grid, both with and without merging between ranks
225  *
226  * parameters:
227  * g <-- Grid structure
228  *
229  * returns:
230  * maximum number of extended columns of grid structure, with or without
231  * merging
232  *----------------------------------------------------------------------------*/
233 
234 cs_lnum_t
236 
237 /*----------------------------------------------------------------------------
238  * Get global number of rows corresponding to a grid.
239  *
240  * parameters:
241  * g <-- Grid structure
242  *
243  * returns:
244  * global number of rows of grid structure
245  *----------------------------------------------------------------------------*/
246 
247 cs_gnum_t
249 
250 /*----------------------------------------------------------------------------
251  * Get grid's associated matrix information.
252  *
253  * parameters:
254  * g <-- Grid structure
255  *
256  * returns:
257  * pointer to matrix structure
258  *----------------------------------------------------------------------------*/
259 
260 const cs_matrix_t *
262 
263 #if defined(HAVE_MPI)
264 
265 /*----------------------------------------------------------------------------
266  * Get the MPI subcommunicator for a given grid.
267  *
268  * parameters:
269  * g <-- Grid structure
270  *
271  * returns:
272  * MPI communicator
273  *----------------------------------------------------------------------------*/
274 
275 MPI_Comm
276 cs_grid_get_comm(const cs_grid_t *g);
277 
278 /*----------------------------------------------------------------------------
279  * Get the MPI subcommunicator for a given merge stride.
280  *
281  * parameters:
282  * parent <-- parent MPI communicator
283  * merge_stride <-- associated merge stride
284  *
285  * returns:
286  * MPI communicator
287  *----------------------------------------------------------------------------*/
288 
289 MPI_Comm
290 cs_grid_get_comm_merge(MPI_Comm parent,
291  int merge_stride);
292 
293 #endif
294 
295 /*----------------------------------------------------------------------------
296  * Create coarse grid from fine grid.
297  *
298  * parameters:
299  * f <-- Fine grid structure
300  * alloc_mode <-- Memory allocation mode
301  * coarsening_type <-- Coarsening criteria type
302  * aggregation_limit <-- Maximum allowed fine rows per coarse rows
303  * verbosity <-- Verbosity level
304  * merge_stride <-- Associated merge stride
305  * merge_rows_mean_threshold <-- mean number of rows under which
306  * merging should be applied
307  * merge_rows_glob_threshold <-- global number of rows under which
308  * merging should be applied
309  * relaxation_parameter <-- P0/P1 relaxation factor
310  *
311  * returns:
312  * coarse grid structure
313  *----------------------------------------------------------------------------*/
314 
315 cs_grid_t *
317  cs_alloc_mode_t alloc_mode,
318  cs_grid_coarsening_t coarsening_type,
319  int aggregation_limit,
320  int verbosity,
321  int merge_stride,
322  int merge_rows_mean_threshold,
323  cs_gnum_t merge_rows_glob_threshold,
324  double relaxation_parameter);
325 
326 /*----------------------------------------------------------------------------
327  * Create coarse grid with only one row per rank from fine grid.
328  *
329  * parameters:
330  * f <-- Fine grid structure
331  * alloc_mode <-- Memory allocation mode
332  * merge_stride <-- Associated merge stride
333  * verbosity <-- Verbosity level
334  *
335  * returns:
336  * coarse grid structure
337  *----------------------------------------------------------------------------*/
338 
339 cs_grid_t *
341  cs_alloc_mode_t alloc_mode,
342  int merge_stride,
343  int verbosity);
344 
345 /*----------------------------------------------------------------------------
346  * Project coarse grid row numbers to base grid.
347  *
348  * If a global coarse grid row number is larger than max_num, its
349  * value modulo max_num is used.
350  *
351  * parameters:
352  * g <-- Grid structure
353  * n_base_rows <-- Number of rows in base grid
354  * max_num <-- Values of c_row_num = global_num % max_num
355  * c_row_num --> Global coarse row number (modulo max_num)
356  *----------------------------------------------------------------------------*/
357 
358 void
360  cs_lnum_t n_base_rows,
361  int max_num,
362  int c_row_num[]);
363 
364 /*----------------------------------------------------------------------------
365  * Project coarse grid row rank to base grid.
366  *
367  * parameters:
368  * g <-- Grid structure
369  * n_base_rows <-- Number of rows in base grid
370  * f_row_rank --> Global coarse row rank projected to fine rows
371  *----------------------------------------------------------------------------*/
372 
373 void
375  cs_lnum_t n_base_rows,
376  int f_row_rank[]);
377 
378 /*----------------------------------------------------------------------------
379  * Project variable from coarse grid to base grid
380  *
381  * parameters:
382  * g <-- Grid structure
383  * n_base_rows <-- Number of rows in base grid
384  * c_var <-- Row variable on coarse grid
385  * f_var --> Row variable projected to fine grid
386  *----------------------------------------------------------------------------*/
387 
388 void
390  cs_lnum_t n_base_rows,
391  const cs_real_t c_var[],
392  cs_real_t f_var[]);
393 
394 /*----------------------------------------------------------------------------
395  * Compute diagonal dominance metric and project it to base grid
396  *
397  * parameters:
398  * g <-- Grid structure
399  * n_base_rows <-- Number of rows in base grid
400  * diag_dom --> Diagonal dominance metric (on fine grid)
401  *----------------------------------------------------------------------------*/
402 
403 void
405  cs_lnum_t n_base_rows,
406  cs_real_t diag_dom[]);
407 
408 /*----------------------------------------------------------------------------
409  * Finalize global info related to multigrid solvers
410  *----------------------------------------------------------------------------*/
411 
412 void
414 
415 /*----------------------------------------------------------------------------
416  * Dump grid structure
417  *
418  * parameters:
419  * g <-- grid structure that should be dumped
420  *----------------------------------------------------------------------------*/
421 
422 void
424 
426 
427 #ifdef __cplusplus
428 
429 /*----------------------------------------------------------------------------
430  * Compute coarse row variable values from fine row values
431  *
432  * parameters:
433  * ctx <-> Reference to dispatch context
434  * f <-- Fine grid structure
435  * c <-- Fine grid structure
436  * f_var <-- Variable defined on fine grid rows
437  * c_var --> Variable defined on coarse grid rows
438  *
439  * returns:
440  * coarse grid structure
441  *----------------------------------------------------------------------------*/
442 
443 void
444 cs_grid_restrict_row_var(cs_dispatch_context &ctx,
445  const cs_grid_t *f,
446  const cs_grid_t *c,
447  const cs_real_t *f_var,
448  cs_real_t *c_var);
449 
450 /*----------------------------------------------------------------------------
451  * Compute fine row variable values from coarse row values
452  *
453  * parameters:
454  * ctx <-> Reference to dispatch context
455  * c <-- Fine grid structure
456  * f <-- Fine grid structure
457  * increment <-- if true, add value to f_var; otherwise, overwrite it
458  * c_var <-- Variable defined on coarse grid rows
459  * f_var <-> Variable defined on fine grid rows
460  *----------------------------------------------------------------------------*/
461 
462 void
463 cs_grid_prolong_row_var(cs_dispatch_context &ctx,
464  const cs_grid_t *c,
465  const cs_grid_t *f,
466  bool increment,
467  cs_real_t *c_var,
468  cs_real_t *f_var);
469 
470 #endif
471 
473 
474 /*=============================================================================
475  * Public function prototypes
476  *============================================================================*/
477 
478 /*----------------------------------------------------------------------------
479  * Set matrix tuning behavior for multigrid coarse meshes.
480  *
481  * The finest mesh (level 0) is handled by the default tuning options,
482  * so only coarser meshes are considered here.
483  *
484  * parameters:
485  * fill_type <-- associated matrix fill type
486  * max_level <-- maximum level for which tuning is active
487  *----------------------------------------------------------------------------*/
488 
489 void
491  int max_level);
492 
493 /*----------------------------------------------------------------------------*/
494 
496 
497 #endif /* __CS_GRID_H__ */
cs_alloc_mode_t
Definition: bft_mem.h:50
#define BEGIN_C_DECLS
Definition: cs_defs.h:528
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:340
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:310
#define END_C_DECLS
Definition: cs_defs.h:529
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
void cs_grid_restrict_row_var(cs_dispatch_context &ctx, const cs_grid_t *f, const cs_grid_t *c, const cs_real_t *f_var, cs_real_t *c_var)
Definition: cs_grid.cpp:6646
void cs_grid_prolong_row_var(cs_dispatch_context &ctx, const cs_grid_t *c, const cs_grid_t *f, bool increment, cs_real_t *c_var, cs_real_t *f_var)
Definition: cs_grid.cpp:6760
void cs_grid_project_row_num(const cs_grid_t *g, cs_lnum_t n_base_rows, int max_num, int c_row_num[])
cs_grid_t * cs_grid_coarsen_to_single(const cs_grid_t *f, cs_alloc_mode_t alloc_mode, int merge_stride, int verbosity)
void cs_grid_dump(const cs_grid_t *g)
cs_lnum_t cs_grid_get_n_cols_ext(const cs_grid_t *g)
cs_grid_coarsening_t
Definition: cs_grid.h:55
@ CS_GRID_COARSENING_SPD_MX
Definition: cs_grid.h:59
@ CS_GRID_COARSENING_DEFAULT
Definition: cs_grid.h:57
@ CS_GRID_COARSENING_CONV_DIFF_DX
Definition: cs_grid.h:61
@ CS_GRID_COARSENING_SPD_DX
Definition: cs_grid.h:58
@ CS_GRID_COARSENING_SPD_PW
Definition: cs_grid.h:60
const char * cs_grid_coarsening_type_name[]
cs_alloc_mode_t cs_grid_get_alloc_mode(const cs_grid_t *g)
void cs_grid_project_var(const cs_grid_t *g, cs_lnum_t n_base_rows, const cs_real_t c_var[], cs_real_t f_var[])
cs_gnum_t cs_grid_get_n_g_rows(const cs_grid_t *g)
void cs_grid_set_matrix_tuning(cs_matrix_fill_type_t fill_type, int max_level)
Set matrix tuning behavior for multigrid coarse meshes.
Definition: cs_grid.cpp:6604
cs_lnum_t cs_grid_get_n_rows(const cs_grid_t *g)
cs_grid_t * cs_grid_create_from_parent(const cs_matrix_t *a, int n_ranks)
void cs_grid_project_diag_dom(const cs_grid_t *g, cs_lnum_t n_base_rows, cs_real_t diag_dom[])
struct _cs_grid_t cs_grid_t
Definition: cs_grid.h:68
cs_lnum_t cs_grid_get_n_cols_max(const cs_grid_t *g)
cs_grid_t * cs_grid_coarsen(const cs_grid_t *f, cs_alloc_mode_t alloc_mode, cs_grid_coarsening_t coarsening_type, int aggregation_limit, int verbosity, int merge_stride, int merge_rows_mean_threshold, cs_gnum_t merge_rows_glob_threshold, double relaxation_parameter)
const cs_matrix_t * cs_grid_get_matrix(const cs_grid_t *g)
void cs_grid_project_row_rank(const cs_grid_t *g, cs_lnum_t n_base_rows, int f_row_rank[])
void cs_grid_destroy(cs_grid_t **grid)
void cs_grid_finalize(void)
cs_grid_t * cs_grid_create_from_shared(cs_lnum_t n_faces, cs_lnum_t db_size, cs_lnum_t eb_size, const cs_lnum_2_t *face_cell, const cs_matrix_t *a, bool conv_diff)
void cs_grid_get_info(const cs_grid_t *g, int *level, bool *symmetric, cs_lnum_t *db_size, cs_lnum_t *eb_size, int *n_ranks, cs_lnum_t *n_rows, cs_lnum_t *n_cols_ext, cs_lnum_t *n_entries, cs_gnum_t *n_g_rows)
void cs_grid_free_quantities(cs_grid_t *g)
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:110
cs_matrix_fill_type_t
Definition: cs_matrix.h:72