8.1
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-2023 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_halo.h"
38 #include "cs_matrix.h"
39 
40 /*----------------------------------------------------------------------------*/
41 
43 
44 /*============================================================================
45  * Macro definitions
46  *============================================================================*/
47 
48 /*============================================================================
49  * Type definitions
50  *============================================================================*/
51 
52 /* Aggregation algorithm */
53 
54 typedef enum {
55 
64 
65 /* Structure associated with opaque grid object */
66 
67 typedef struct _cs_grid_t cs_grid_t;
68 
69 /*============================================================================
70  * Global variables
71  *============================================================================*/
72 
73 /* Names for coarsening options */
74 
75 extern const char *cs_grid_coarsening_type_name[];
76 
77 /*============================================================================
78  * Semi-private function prototypes
79  *
80  * The following functions are intended to be used by the multigrid layer
81  * (cs_multigrid.c), not directly by the user, so they are no more
82  * documented than private static functions)
83  *============================================================================*/
84 
85 /*----------------------------------------------------------------------------
86  * Create base grid by mapping from shared mesh values.
87  *
88  * Note that as arrays given as arguments are shared by the created grid
89  * (which can only access them, not modify them), the grid should be
90  * destroyed before those arrays.
91  *
92  * parameters:
93  * n_faces <-- Local number of faces
94  * db_size <-- Block sizes for diagonal
95  * eb_size <-- Block sizes for extra-diagonal
96  * face_cell <-- Face -> cells connectivity
97  * cell_cen <-- Cell center (size: 3.n_cells_ext)
98  * cell_vol <-- Cell volume (size: n_cells_ext)
99  * face_normal <-- Internal face normals (size: 3.n_faces)
100  * a <-- Associated matrix
101  * conv_diff <-- Convection-diffusion mode
102  *
103  * returns:
104  * base grid structure
105  *----------------------------------------------------------------------------*/
106 
107 cs_grid_t *
109  cs_lnum_t db_size,
110  cs_lnum_t eb_size,
111  const cs_lnum_2_t *face_cell,
112  const cs_real_t *cell_cen,
113  const cs_real_t *cell_vol,
114  const cs_real_t *face_normal,
115  const cs_matrix_t *a,
116  bool conv_diff);
117 
118 /*----------------------------------------------------------------------------
119  * Create base grid by mapping from parent (possibly shared) matrix.
120  *
121  * Note that as arrays given as arguments are shared by the created grid
122  * (which can only access them, not modify them), the grid should be
123  * destroyed before those arrays.
124  *
125  * parameters:
126  * a <-- associated matrix
127  * n_ranks <-- number of active ranks (<= 1 to restrict to local values)
128  *
129  * returns:
130  * base grid structure
131  *----------------------------------------------------------------------------*/
132 
133 cs_grid_t *
135  int n_ranks);
136 
137 /*----------------------------------------------------------------------------
138  * Destroy a grid structure.
139  *
140  * parameters:
141  * grid <-> Pointer to grid structure pointer
142  *----------------------------------------------------------------------------*/
143 
144 void
146 
147 /*----------------------------------------------------------------------------
148  * Free a grid structure's associated quantities.
149  *
150  * The quantities required to compute a coarser grid with relaxation from a
151  * given grid are not needed after that stage, so may be freed.
152  *
153  * parameters:
154  * g <-> Pointer to grid structure
155  *----------------------------------------------------------------------------*/
156 
157 void
159 
160 /*----------------------------------------------------------------------------
161  * Get grid information.
162  *
163  * parameters:
164  * g <-- Grid structure
165  * level --> Level in multigrid hierarchy (or NULL)
166  * symmetric --> Symmetric matrix coefficients indicator (or NULL)
167  * db_size --> Size of the diagonal block (or NULL)
168  * eb_size --> Size of the extra diagonal block (or NULL)
169  * n_ranks --> number of ranks with data (or NULL)
170  * n_rows --> Number of local rows (or NULL)
171  * n_cols_ext --> Number of columns including ghosts (or NULL)
172  * n_entries --> Number of entries (or NULL)
173  * n_g_rows --> Number of global rows (or NULL)
174  *----------------------------------------------------------------------------*/
175 
176 void
178  int *level,
179  bool *symmetric,
180  cs_lnum_t *db_size,
181  cs_lnum_t *eb_size,
182  int *n_ranks,
183  cs_lnum_t *n_rows,
184  cs_lnum_t *n_cols_ext,
185  cs_lnum_t *n_entries,
186  cs_gnum_t *n_g_rows);
187 
188 /*----------------------------------------------------------------------------
189  * Get number of rows corresponding to a grid.
190  *
191  * parameters:
192  * g <-- Grid structure
193  *
194  * returns:
195  * number of rows of grid structure
196  *----------------------------------------------------------------------------*/
197 
198 cs_lnum_t
200 
201 /*----------------------------------------------------------------------------
202  * Get number of extended (local + ghost) columns corresponding to a grid.
203  *
204  * parameters:
205  * g <-- Grid structure
206  *
207  * returns:
208  * number of extended columns of grid structure
209  *----------------------------------------------------------------------------*/
210 
211 cs_lnum_t
213 
214 /*----------------------------------------------------------------------------
215  * Get maximum number of extended (local + ghost) columns corresponding to
216  * a grid, both with and without merging between ranks
217  *
218  * parameters:
219  * g <-- Grid structure
220  *
221  * returns:
222  * maximum number of extended columns of grid structure, with or without
223  * merging
224  *----------------------------------------------------------------------------*/
225 
226 cs_lnum_t
228 
229 /*----------------------------------------------------------------------------
230  * Get global number of rows corresponding to a grid.
231  *
232  * parameters:
233  * g <-- Grid structure
234  *
235  * returns:
236  * global number of rows of grid structure
237  *----------------------------------------------------------------------------*/
238 
239 cs_gnum_t
241 
242 /*----------------------------------------------------------------------------
243  * Get grid's associated matrix information.
244  *
245  * parameters:
246  * g <-- Grid structure
247  *
248  * returns:
249  * pointer to matrix structure
250  *----------------------------------------------------------------------------*/
251 
252 const cs_matrix_t *
254 
255 #if defined(HAVE_MPI)
256 
257 /*----------------------------------------------------------------------------
258  * Get the MPI subcommunicator for a given grid.
259  *
260  * parameters:
261  * g <-- Grid structure
262  *
263  * returns:
264  * MPI communicator
265  *----------------------------------------------------------------------------*/
266 
267 MPI_Comm
268 cs_grid_get_comm(const cs_grid_t *g);
269 
270 /*----------------------------------------------------------------------------
271  * Get the MPI subcommunicator for a given merge stride.
272  *
273  * parameters:
274  * parent <-- parent MPI communicator
275  * merge_stride <-- associated merge stride
276  *
277  * returns:
278  * MPI communicator
279  *----------------------------------------------------------------------------*/
280 
281 MPI_Comm
282 cs_grid_get_comm_merge(MPI_Comm parent,
283  int merge_stride);
284 
285 #endif
286 
287 /*----------------------------------------------------------------------------
288  * Create coarse grid from fine grid.
289  *
290  * parameters:
291  * f <-- Fine grid structure
292  * coarsening_type <-- Coarsening criteria type
293  * aggregation_limit <-- Maximum allowed fine rows per coarse rows
294  * verbosity <-- Verbosity level
295  * merge_stride <-- Associated merge stride
296  * merge_rows_mean_threshold <-- mean number of rows under which
297  * merging should be applied
298  * merge_rows_glob_threshold <-- global number of rows under which
299  * merging should be applied
300  * relaxation_parameter <-- P0/P1 relaxation factor
301  *
302  * returns:
303  * coarse grid structure
304  *----------------------------------------------------------------------------*/
305 
306 cs_grid_t *
308  int coarsening_type,
309  int aggregation_limit,
310  int verbosity,
311  int merge_stride,
312  int merge_rows_mean_threshold,
313  cs_gnum_t merge_rows_glob_threshold,
314  double relaxation_parameter);
315 
316 /*----------------------------------------------------------------------------
317  * Create coarse grid with only one row per rank from fine grid.
318  *
319  * parameters:
320  * f <-- Fine grid structure
321  * merge_stride <-- Associated merge stride
322  * verbosity <-- Verbosity level
323  *
324  * returns:
325  * coarse grid structure
326  *----------------------------------------------------------------------------*/
327 
328 cs_grid_t *
330  int merge_stride,
331  int verbosity);
332 
333 /*----------------------------------------------------------------------------
334  * Compute coarse row variable values from fine row values
335  *
336  * parameters:
337  * f <-- Fine grid structure
338  * c <-- Fine grid structure
339  * f_var <-- Variable defined on fine grid rows
340  * c_var --> Variable defined on coarse grid rows
341  *
342  * returns:
343  * coarse grid structure
344  *----------------------------------------------------------------------------*/
345 
346 void
348  const cs_grid_t *c,
349  const cs_real_t *f_var,
350  cs_real_t *c_var);
351 
352 /*----------------------------------------------------------------------------
353  * Compute fine row variable values from coarse row values
354  *
355  * parameters:
356  * c <-- Fine grid structure
357  * f <-- Fine grid structure
358  * c_var --> Variable defined on coarse grid rows
359  * f_var <-- Variable defined on fine grid rows
360  *----------------------------------------------------------------------------*/
361 
362 void
364  const cs_grid_t *f,
365  cs_real_t *c_var,
366  cs_real_t *f_var);
367 
368 /*----------------------------------------------------------------------------
369  * Project coarse grid row numbers to base grid.
370  *
371  * If a global coarse grid row number is larger than max_num, its
372  * value modulo max_num is used.
373  *
374  * parameters:
375  * g <-- Grid structure
376  * n_base_rows <-- Number of rows in base grid
377  * max_num <-- Values of c_row_num = global_num % max_num
378  * c_row_num --> Global coarse row number (modulo max_num)
379  *----------------------------------------------------------------------------*/
380 
381 void
383  cs_lnum_t n_base_rows,
384  int max_num,
385  int c_row_num[]);
386 
387 /*----------------------------------------------------------------------------
388  * Project coarse grid row rank to base grid.
389  *
390  * parameters:
391  * g <-- Grid structure
392  * n_base_rows <-- Number of rows in base grid
393  * f_row_rank --> Global coarse row rank projected to fine rows
394  *----------------------------------------------------------------------------*/
395 
396 void
398  cs_lnum_t n_base_rows,
399  int f_row_rank[]);
400 
401 /*----------------------------------------------------------------------------
402  * Project variable from coarse grid to base grid
403  *
404  * parameters:
405  * g <-- Grid structure
406  * n_base_rows <-- Number of rows in base grid
407  * c_var <-- Row variable on coarse grid
408  * f_var --> Row variable projected to fine grid
409  *----------------------------------------------------------------------------*/
410 
411 void
413  cs_lnum_t n_base_rows,
414  const cs_real_t c_var[],
415  cs_real_t f_var[]);
416 
417 /*----------------------------------------------------------------------------
418  * Compute diagonal dominance metric and project it to base grid
419  *
420  * parameters:
421  * g <-- Grid structure
422  * n_base_rows <-- Number of rows in base grid
423  * diag_dom --> Diagonal dominance metric (on fine grid)
424  *----------------------------------------------------------------------------*/
425 
426 void
428  cs_lnum_t n_base_rows,
429  cs_real_t diag_dom[]);
430 
431 /*----------------------------------------------------------------------------
432  * Finalize global info related to multigrid solvers
433  *----------------------------------------------------------------------------*/
434 
435 void
437 
438 /*----------------------------------------------------------------------------
439  * Dump grid structure
440  *
441  * parameters:
442  * g <-- grid structure that should be dumped
443  *----------------------------------------------------------------------------*/
444 
445 void
447 
448 /*=============================================================================
449  * Public function prototypes
450  *============================================================================*/
451 
452 /*----------------------------------------------------------------------------
453  * Set matrix tuning behavior for multigrid coarse meshes.
454  *
455  * The finest mesh (level 0) is handled by the default tuning options,
456  * so only coarser meshes are considered here.
457  *
458  * parameters:
459  * fill_type <-- associated matrix fill type
460  * max_level <-- maximum level for which tuning is active
461  *----------------------------------------------------------------------------*/
462 
463 void
465  int max_level);
466 
467 /*----------------------------------------------------------------------------*/
468 
470 
471 #endif /* __CS_GRID_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:514
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:327
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:298
#define END_C_DECLS
Definition: cs_defs.h:515
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
void cs_grid_project_row_num(const cs_grid_t *g, cs_lnum_t n_base_rows, int max_num, int c_row_num[])
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:54
@ CS_GRID_COARSENING_SPD_MX
Definition: cs_grid.h:58
@ CS_GRID_COARSENING_DEFAULT
Definition: cs_grid.h:56
@ CS_GRID_COARSENING_CONV_DIFF_DX
Definition: cs_grid.h:60
@ CS_GRID_COARSENING_SPD_DX
Definition: cs_grid.h:57
@ CS_GRID_COARSENING_SPD_PW
Definition: cs_grid.h:59
cs_grid_t * cs_grid_coarsen_to_single(const cs_grid_t *f, int merge_stride, int verbosity)
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_real_t *cell_cen, const cs_real_t *cell_vol, const cs_real_t *face_normal, const cs_matrix_t *a, bool conv_diff)
const char * cs_grid_coarsening_type_name[]
void cs_grid_prolong_row_var(const cs_grid_t *c, const cs_grid_t *f, cs_real_t *c_var, cs_real_t *f_var)
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_grid_t * cs_grid_coarsen(const cs_grid_t *f, int 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)
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.c:6545
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:67
cs_lnum_t cs_grid_get_n_cols_max(const cs_grid_t *g)
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)
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_restrict_row_var(const cs_grid_t *f, const cs_grid_t *c, const cs_real_t *f_var, cs_real_t *c_var)
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