My Project
programmer's 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-2019 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  * diag_block_size <-- Block sizes for diagonal, or NULL
95  * extra_diag_block_size <-- Block sizes for extra diagonal, or NULL
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  * a_conv <-- Associated matrix (convection)
102  * a_diff <-- Associated matrix (diffusion)
103  *
104  * returns:
105  * base grid structure
106  *----------------------------------------------------------------------------*/
107 
108 cs_grid_t *
110  const int *diag_block_size,
111  const int *extra_diag_block_size,
112  const cs_lnum_2_t *face_cell,
113  const cs_real_t *cell_cen,
114  const cs_real_t *cell_vol,
115  const cs_real_t *face_normal,
116  const cs_matrix_t *a,
117  const cs_matrix_t *a_conv,
118  const cs_matrix_t *a_diff);
119 
120 /*----------------------------------------------------------------------------
121  * Destroy a grid structure.
122  *
123  * parameters:
124  * grid <-> Pointer to grid structure pointer
125  *----------------------------------------------------------------------------*/
126 
127 void
128 cs_grid_destroy(cs_grid_t **grid);
129 
130 /*----------------------------------------------------------------------------
131  * Free a grid structure's associated quantities.
132  *
133  * The quantities required to compute a coarser grid with relaxation from a
134  * given grid are not needed after that stage, so may be freed.
135  *
136  * parameters:
137  * g <-> Pointer to grid structure
138  *----------------------------------------------------------------------------*/
139 
140 void
142 
143 /*----------------------------------------------------------------------------
144  * Get grid information.
145  *
146  * parameters:
147  * g <-- Grid structure
148  * level --> Level in multigrid hierarchy (or NULL)
149  * symmetric --> Symmetric matrix coefficients indicator (or NULL)
150  * db_size --> Size of the diagonal block (or NULL)
151  * eb_size --> Size of the extra diagonal block (or NULL)
152  * n_ranks --> number of ranks with data (or NULL)
153  * n_rows --> Number of local rows (or NULL)
154  * n_cols_ext --> Number of columns including ghosts (or NULL)
155  * n_entries --> Number of entries (or NULL)
156  * n_g_rows --> Number of global rows (or NULL)
157  *----------------------------------------------------------------------------*/
158 
159 void
160 cs_grid_get_info(const cs_grid_t *g,
161  int *level,
162  bool *symmetric,
163  int *db_size,
164  int *eb_size,
165  int *n_ranks,
166  cs_lnum_t *n_rows,
167  cs_lnum_t *n_cols_ext,
168  cs_lnum_t *n_entries,
169  cs_gnum_t *n_g_rows);
170 
171 /*----------------------------------------------------------------------------
172  * Get number of rows corresponding to a grid.
173  *
174  * parameters:
175  * g <-- Grid structure
176  *
177  * returns:
178  * number of rows of grid structure
179  *----------------------------------------------------------------------------*/
180 
181 cs_lnum_t
182 cs_grid_get_n_rows(const cs_grid_t *g);
183 
184 /*----------------------------------------------------------------------------
185  * Get number of extended (local + ghost) columns corresponding to a grid.
186  *
187  * parameters:
188  * g <-- Grid structure
189  *
190  * returns:
191  * number of extended columns of grid structure
192  *----------------------------------------------------------------------------*/
193 
194 cs_lnum_t
196 
197 /*----------------------------------------------------------------------------
198  * Get maximum number of extended (local + ghost) columns corresponding to
199  * a grid, both with and without merging between ranks
200  *
201  * parameters:
202  * g <-- Grid structure
203  *
204  * returns:
205  * maximum number of extended columns of grid structure, with or without
206  * merging
207  *----------------------------------------------------------------------------*/
208 
209 cs_lnum_t
211 
212 /*----------------------------------------------------------------------------
213  * Get global number of rows corresponding to a grid.
214  *
215  * parameters:
216  * g <-- Grid structure
217  *
218  * returns:
219  * global number of rows of grid structure
220  *----------------------------------------------------------------------------*/
221 
222 cs_gnum_t
224 
225 /*----------------------------------------------------------------------------
226  * Get grid's associated matrix information.
227  *
228  * parameters:
229  * g <-- Grid structure
230  *
231  * returns:
232  * pointer to matrix structure
233  *----------------------------------------------------------------------------*/
234 
235 const cs_matrix_t *
236 cs_grid_get_matrix(const cs_grid_t *g);
237 
238 #if defined(HAVE_MPI)
239 
240 /*----------------------------------------------------------------------------
241  * Get the MPI subcommunicator for a given grid.
242  *
243  * parameters:
244  * g <-- Grid structure
245  *
246  * returns:
247  * MPI communicator
248  *----------------------------------------------------------------------------*/
249 
250 MPI_Comm
251 cs_grid_get_comm(const cs_grid_t *g);
252 
253 #endif
254 
255 /*----------------------------------------------------------------------------
256  * Create coarse grid from fine grid.
257  *
258  * parameters:
259  * f <-- Fine grid structure
260  * verbosity <-- Verbosity level
261  * coarsening_type <-- Coarsening criteria type
262  * aggregation_limit <-- Maximum allowed fine rows per coarse row
263  * relaxation_parameter <-- P0/P1 relaxation factor
264  *
265  * returns:
266  * coarse grid structure
267  *----------------------------------------------------------------------------*/
268 
269 cs_grid_t *
270 cs_grid_coarsen(const cs_grid_t *f,
271  int verbosity,
272  int coarsening_type,
273  int aggregation_limit,
274  double relaxation_parameter);
275 
276 /*----------------------------------------------------------------------------
277  * Compute coarse row variable values from fine row values
278  *
279  * parameters:
280  * f <-- Fine grid structure
281  * c <-- Fine grid structure
282  * f_var <-- Variable defined on fine grid rows
283  * c_var --> Variable defined on coarse grid rows
284  *
285  * returns:
286  * coarse grid structure
287  *----------------------------------------------------------------------------*/
288 
289 void
291  const cs_grid_t *c,
292  const cs_real_t *f_var,
293  cs_real_t *c_var);
294 
295 /*----------------------------------------------------------------------------
296  * Compute fine row integer values from coarse row values
297  *
298  * parameters:
299  * c <-- Fine grid structure
300  * f <-- Fine grid structure
301  * c_num --> Variable defined on coarse grid rows
302  * f_num <-- Variable defined on fine grid rows
303  *----------------------------------------------------------------------------*/
304 
305 void
307  const cs_grid_t *f,
308  int *c_num,
309  int *f_num);
310 
311 /*----------------------------------------------------------------------------
312  * Compute fine row variable values from coarse row values
313  *
314  * parameters:
315  * c <-- Fine grid structure
316  * f <-- Fine grid structure
317  * c_var --> Variable defined on coarse grid rows
318  * f_var <-- Variable defined on fine grid rows
319  *----------------------------------------------------------------------------*/
320 
321 void
323  const cs_grid_t *f,
324  cs_real_t *c_var,
325  cs_real_t *f_var);
326 
327 /*----------------------------------------------------------------------------
328  * Project coarse grid row numbers to base grid.
329  *
330  * If a global coarse grid row number is larger than max_num, its
331  * value modulo max_num is used.
332  *
333  * parameters:
334  * g <-- Grid structure
335  * n_base_rows <-- Number of rows in base grid
336  * max_num <-- Values of c_row_num = global_num % max_num
337  * c_row_num --> Global coarse row number (modulo max_num)
338  *----------------------------------------------------------------------------*/
339 
340 void
342  cs_lnum_t n_base_rows,
343  int max_num,
344  int c_row_num[]);
345 
346 /*----------------------------------------------------------------------------
347  * Project coarse grid row rank to base grid.
348  *
349  * parameters:
350  * g <-- Grid structure
351  * n_base_rows <-- Number of rows in base grid
352  * f_row_rank --> Global coarse row rank projected to fine rows
353  *----------------------------------------------------------------------------*/
354 
355 void
357  cs_lnum_t n_base_rows,
358  int f_row_rank[]);
359 
360 /*----------------------------------------------------------------------------
361  * Project variable from coarse grid to base grid
362  *
363  * parameters:
364  * g <-- Grid structure
365  * n_base_rows <-- Number of rows in base grid
366  * c_var <-- Row variable on coarse grid
367  * f_var --> Row variable projected to fine grid
368  *----------------------------------------------------------------------------*/
369 
370 void
372  cs_lnum_t n_base_rows,
373  const cs_real_t c_var[],
374  cs_real_t f_var[]);
375 
376 /*----------------------------------------------------------------------------
377  * Compute diagonal dominance metric and project it to base grid
378  *
379  * parameters:
380  * g <-- Grid structure
381  * n_base_rows <-- Number of rows in base grid
382  * diag_dom --> Diagonal dominance metric (on fine grid)
383  *----------------------------------------------------------------------------*/
384 
385 void
387  cs_lnum_t n_base_rows,
388  cs_real_t diag_dom[]);
389 
390 /*----------------------------------------------------------------------------
391  * Return the merge_stride if merging is active.
392  *
393  * returns:
394  * grid merge stride if merging is active, 1 otherwise
395  *----------------------------------------------------------------------------*/
396 
397 int
399 
400 /*----------------------------------------------------------------------------
401  * Finalize global info related to multigrid solvers
402  *----------------------------------------------------------------------------*/
403 
404 void
405 cs_grid_finalize(void);
406 
407 /*----------------------------------------------------------------------------
408  * Dump grid structure
409  *
410  * parameters:
411  * g <-- grid structure that should be dumped
412  *----------------------------------------------------------------------------*/
413 
414 void
415 cs_grid_dump(const cs_grid_t *g);
416 
417 /*=============================================================================
418  * Public function prototypes
419  *============================================================================*/
420 
421 /*----------------------------------------------------------------------------
422  * Query the global multigrid parameters for parallel grid merging.
423  *
424  * parameters:
425  * rank_stride --> number of ranks over which merging
426  * takes place, or NULL
427  * rows_mean_threshold --> mean number of rows under which merging
428  * should be applied, or NULL
429  * rows_glob_threshold --> global number of rows under which merging
430  * should be applied, or NULL
431  * min_ranks --> number of active ranks under which
432  * no merging takes place, or NULL
433  *----------------------------------------------------------------------------*/
434 
435 void
436 cs_grid_get_merge_options(int *rank_stride,
437  int *rows_mean_threshold,
438  cs_gnum_t *rows_glob_threshold,
439  int *min_ranks);
440 
441 /*----------------------------------------------------------------------------
442  * Set global multigrid parameters for parallel grid merging.
443  *
444  * parameters:
445  * rank_stride <-- number of ranks over which merging
446  * takes place
447  * rows_mean_threshold <-- mean number of rows under which merging
448  * should be applied
449  * rows_glob_threshold <-- global number of rows under which merging
450  * should be applied
451  * min_ranks <-- number of active ranks under which
452  * no merging takes place
453  *----------------------------------------------------------------------------*/
454 
455 void
456 cs_grid_set_merge_options(int rank_stride,
457  int rows_mean_threshold,
458  cs_gnum_t rows_glob_threshold,
459  int min_ranks);
460 
461 /*----------------------------------------------------------------------------
462  * Set matrix tuning behavior for multigrid coarse meshes.
463  *
464  * The finest mesh (level 0) is handled by the default tuning options,
465  * so only coarser meshes are considered here.
466  *
467  * parameters:
468  * fill_type <-- associated matrix fill type
469  * max_level <-- maximum level for which tuning is active
470  *----------------------------------------------------------------------------*/
471 
472 void
474  int max_level);
475 
476 /*----------------------------------------------------------------------------
477  * Force matrix variant selection for multigrid coarse meshes.
478  *
479  * The finest mesh (level 0) is handled by the default options,
480  * so only coarser meshes are considered here.
481  *
482  * parameters:
483  * fill_type <-- associated matrix fill type
484  * level <-- level for which variant is assiged
485  * mv <-- matrix variant to assign (NULL to unassign)
486  *----------------------------------------------------------------------------*/
487 
488 void
490  int level,
491  const cs_matrix_variant_t *mv);
492 
493 /*----------------------------------------------------------------------------
494  * Log the current settings for multigrid parallel merging.
495  *----------------------------------------------------------------------------*/
496 
497 void
499 
500 /*----------------------------------------------------------------------------*/
501 
503 
504 #endif /* __CS_GRID_H__ */
cs_grid_project_row_rank
void cs_grid_project_row_rank(const cs_grid_t *g, cs_lnum_t n_base_rows, int f_row_rank[])
cs_grid_get_merge_stride
int cs_grid_get_merge_stride(void)
cs_grid_prolong_row_num
void cs_grid_prolong_row_num(const cs_grid_t *c, const cs_grid_t *f, int *c_num, int *f_num)
cs_fuel_incl::a
double precision, save a
Definition: cs_fuel_incl.f90:146
cs_grid_get_info
void cs_grid_get_info(const cs_grid_t *g, int *level, bool *symmetric, int *db_size, int *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)
cs_grid_free_quantities
void cs_grid_free_quantities(cs_grid_t *g)
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
cs_grid_coarsening_t
cs_grid_coarsening_t
Definition: cs_grid.h:54
cs_grid_get_matrix
const cs_matrix_t * cs_grid_get_matrix(const cs_grid_t *g)
cs_grid_create_from_shared
cs_grid_t * cs_grid_create_from_shared(cs_lnum_t n_faces, const int *diag_block_size, const int *extra_diag_block_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, const cs_matrix_t *a_conv, const cs_matrix_t *a_diff)
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
CS_GRID_COARSENING_DEFAULT
Definition: cs_grid.h:56
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_matrix_t
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:90
CS_GRID_COARSENING_SPD_PW
Definition: cs_grid.h:59
cs_grid_destroy
void cs_grid_destroy(cs_grid_t **grid)
cs_grid_project_diag_dom
void cs_grid_project_diag_dom(const cs_grid_t *g, cs_lnum_t n_base_rows, cs_real_t diag_dom[])
cs_grid_t
struct _cs_grid_t cs_grid_t
Definition: cs_grid.h:67
cs_matrix_variant_t
struct _cs_matrix_variant_t cs_matrix_variant_t
Definition: cs_matrix.h:94
cs_grid_set_matrix_tuning
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:6416
cs_grid_coarsen
cs_grid_t * cs_grid_coarsen(const cs_grid_t *f, int verbosity, int coarsening_type, int aggregation_limit, double relaxation_parameter)
cs_grid_get_n_rows
cs_lnum_t cs_grid_get_n_rows(const cs_grid_t *g)
cs_grid_dump
void cs_grid_dump(const cs_grid_t *g)
cs_halo.h
cs_gnum_t
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_grid_prolong_row_var
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)
cs_grid_get_merge_options
void cs_grid_get_merge_options(int *rank_stride, int *rows_mean_threshold, cs_gnum_t *rows_glob_threshold, int *min_ranks)
Query the global multigrid parameters for parallel grid merging.
Definition: cs_grid.c:6346
cs_grid_get_n_g_rows
cs_gnum_t cs_grid_get_n_g_rows(const cs_grid_t *g)
cs_grid_project_row_num
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_project_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_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
CS_GRID_COARSENING_CONV_DIFF_DX
Definition: cs_grid.h:60
cs_grid_coarsening_type_name
const char * cs_grid_coarsening_type_name[]
cs_lnum_2_t
int cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:308
cs_matrix_fill_type_t
cs_matrix_fill_type_t
Definition: cs_matrix.h:67
CS_GRID_COARSENING_SPD_DX
Definition: cs_grid.h:57
cs_matrix.h
CS_GRID_COARSENING_SPD_MX
Definition: cs_grid.h:58
cs_grid_set_merge_options
void cs_grid_set_merge_options(int rank_stride, int rows_mean_threshold, cs_gnum_t rows_glob_threshold, int min_ranks)
Set global multigrid parameters for parallel grid merging behavior.
Definition: cs_grid.c:6388
cs_grid_restrict_row_var
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)
cs_grid_finalize
void cs_grid_finalize(void)
cs_grid_get_n_cols_max
cs_lnum_t cs_grid_get_n_cols_max(const cs_grid_t *g)
cs_base.h
cs_grid_log_merge_options
void cs_grid_log_merge_options(void)
Log the current settings for multigrid parallel merging.
Definition: cs_grid.c:6499
cs_grid_set_matrix_variant
void cs_grid_set_matrix_variant(cs_matrix_fill_type_t fill_type, int level, const cs_matrix_variant_t *mv)
Force matrix variant selection for multigrid coarse meshes.
Definition: cs_grid.c:6456
cs_grid_get_n_cols_ext
cs_lnum_t cs_grid_get_n_cols_ext(const cs_grid_t *g)