9.1
general documentation
cs_mesh.h
Go to the documentation of this file.
1#ifndef __CS_MESH_H__
2#define __CS_MESH_H__
3
4/*============================================================================
5 * Main structure associated to a mesh
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 "fvm/fvm_group.h"
37#include "fvm/fvm_selector.h"
38#include "fvm/fvm_periodicity.h"
39
40#include "base/cs_base.h"
41#include "base/cs_halo.h"
42#include "base/cs_interface.h"
43#include "base/cs_numbering.h"
44#include "base/cs_parall.h"
45#include "base/cs_range_set.h"
46
48
49/*----------------------------------------------------------------------------*/
50
52
53/*=============================================================================
54 * Macro definitions
55 *============================================================================*/
56
57/*
58 * Mesh modification type flags
59 */
60
62#define CS_MESH_MODIFIED (1 << 0)
63
65#define CS_MESH_MODIFIED_BALANCE (1 << 1)
66
67/*============================================================================
68 * Type definitions
69 *============================================================================*/
70
72/* -------------------- */
73
74typedef enum {
75
81
83/* ------------------------- */
84
85typedef struct {
86
87 /* General features */
88
95 /* Local dimensions */
96
107 /* Local structures */
108
120 /* Global dimension */
121
131 /* Global numbering */
132
138 /* Periodictity features */
139
147 /* Parallelism and/or periodic features */
148
165 /* Re-computable connectivity features */
166
170 /* Extended neighborhood features */
171
182 /* Group and family features */
183
186 char *group;
203 /* Refinement features */
204
207 char *vtx_r_gen;
209 /* Status flags */
210
226} cs_mesh_t;
227
228/*============================================================================
229 * Static global variables
230 *============================================================================*/
231
232extern cs_mesh_t *cs_glob_mesh; /* Pointer to main mesh structure */
233
234/*=============================================================================
235 * Public function prototypes
236 *============================================================================*/
237
238/*----------------------------------------------------------------------------
239 * Create an empty mesh structure
240 *
241 * returns:
242 * pointer to created mesh structure
243 *----------------------------------------------------------------------------*/
244
245cs_mesh_t *
246cs_mesh_create(void);
247
248/*----------------------------------------------------------------------------
249 * Destroy a mesh structure
250 *
251 * mesh <-> pointer to a mesh structure
252 *
253 * returns:
254 * null pointer
255 *----------------------------------------------------------------------------*/
256
257cs_mesh_t *
259
260/*----------------------------------------------------------------------------
261 * Reinitialize mesh structure.
262 *
263 * returns:
264 * pointer to created mesh structure
265 *----------------------------------------------------------------------------*/
266
267void
269
270/*----------------------------------------------------------------------------
271 * Update (compactify) an array of global numbers.
272 *
273 * parameters:
274 * n_elts <-> number of local elements
275 * elt_gnum <-> global element numbers
276 *
277 * return:
278 * associated global number of elements
279 *----------------------------------------------------------------------------*/
280
283 cs_gnum_t *elt_gnum);
284
285/*----------------------------------------------------------------------------
286 * Remove arrays and structures that mey be rebuilt.
287 *
288 * mesh <-> pointer to a mesh structure
289 * free_halos <-- if true, free halos and parallel/periodic interface
290 * structures
291 *----------------------------------------------------------------------------*/
292
293void
295 bool free_halos);
296
297/*----------------------------------------------------------------------------
298 * Remove boundary arrays and structures that may be rebuilt.
299 *
300 * mesh <-> pointer to a mesh structure
301 *----------------------------------------------------------------------------*/
302
303void
305
306/*----------------------------------------------------------------------------
307 * Discard free (isolated) faces from a mesh.
308 *
309 * This should always be done before using the mesh for computation.
310 *
311 * parameters:
312 * mesh <-> pointer to mesh structure
313 *----------------------------------------------------------------------------*/
314
315void
317
318/*----------------------------------------------------------------------------
319 * Discard free (isolated) vertices from a mesh.
320 *
321 * This is recommended before using the mesh for computation.
322 *
323 * parameters:
324 * mesh <-> pointer to mesh structure
325 *----------------------------------------------------------------------------*/
326
327void
329
330/*----------------------------------------------------------------------------*/
339/*----------------------------------------------------------------------------*/
340
341void
343
344/*----------------------------------------------------------------------------
345 * Generate or update list of mesh boundary cells.
346 *
347 * parameters:
348 * mesh <-> pointer to a cs_mesh_t structure
349 *----------------------------------------------------------------------------*/
350
351void
353
354/*----------------------------------------------------------------------------
355 * Compute or update mesh structure members that depend on other members,
356 * but whose results may be reused, such as global number of elements
357 * (cells, vertices, interior and boundary faces) and sync cell family.
358 *
359 * parameters:
360 * mesh <-> pointer to a cs_mesh_t structure
361 *----------------------------------------------------------------------------*/
362
363void
365
366/*----------------------------------------------------------------------------
367 * Creation and initialization of mesh face and vertex interfaces.
368 *
369 * parameters:
370 * mesh <-> pointer to mesh structure
371 * mb <-> pointer to mesh builder (in case of periodicity)
372 *----------------------------------------------------------------------------*/
373
374void
377
378/*----------------------------------------------------------------------------*/
392/*----------------------------------------------------------------------------*/
393
394void
397 cs_halo_type_t halo_type,
398 int verbosity,
399 bool rebuild_vtx_interace);
400
401/*----------------------------------------------------------------------------
402 * Get the global number of ghost cells.
403 *
404 * parameters:
405 * mesh <-- pointer to a mesh structure
406 *
407 * returns:
408 * Global number of ghost cells
409 *---------------------------------------------------------------------------*/
410
413
414/*----------------------------------------------------------------------------
415 * Update a scalar array in case of parallelism and/or periodicity.
416 *
417 * Note: this function is only present so that a C equivalent to the
418 * Fortran wrappers is available. In C code, directly using
419 * cs_halo_sync_var() is preferred.
420 *
421 * parameters:
422 * var <-> scalar array
423 *----------------------------------------------------------------------------*/
424
425void
427
428/*----------------------------------------------------------------------------
429 * Order family numbers and remove duplicates
430 *
431 * parameters
432 * mesh <-> pointer to mesh structure
433 *----------------------------------------------------------------------------*/
434
435void
437
438/*----------------------------------------------------------------------------
439 * Create group classes based on a mesh's family definitions.
440 *
441 * parameters:
442 * mesh <-- pointer to mesh structure
443 *
444 * returns:
445 * pointer to group classes structure based on mesh's family definitions
446 *----------------------------------------------------------------------------*/
447
450
451/*----------------------------------------------------------------------------
452 * Define group classes for a mesh based on its family definitions.
453 *
454 * parameters:
455 * mesh <-> pointer to mesh structure
456 *----------------------------------------------------------------------------*/
457
458void
460
461/*----------------------------------------------------------------------------
462 * Assign selectors to global mesh.
463 *
464 * Should be called once the mesh is fully built.
465 *----------------------------------------------------------------------------*/
466
467void
469
470/*----------------------------------------------------------------------------
471 * Assign cell selector to global mesh.
472 *
473 * Should be called once the mesh is fully built.
474 *----------------------------------------------------------------------------*/
475
476void
478
479/*----------------------------------------------------------------------------
480 * Assign boundary selector to global mesh.
481 *
482 * Should be called once the mesh is fully built.
483 *----------------------------------------------------------------------------*/
484
485void
487
488/*----------------------------------------------------------------------------
489 * Assign internal selector to global mesh.
490 *
491 * Should be called once the mesh is fully built.
492 *----------------------------------------------------------------------------*/
493
494void
496
497/*----------------------------------------------------------------------------
498 * Update selector and associated structures.
499 *
500 * parameters:
501 * mesh <-> pointer to a mesh structure
502 *----------------------------------------------------------------------------*/
503
504void
506
507/*----------------------------------------------------------------------------
508 * Get global lists of periodic face couples.
509 *
510 * In parallel, each face couple may appear on only one rank.
511 *
512 * The caller is responsible for freeing the arrays allocated and returned
513 * by this function once they are no onger needed.
514 *
515 * parameters:
516 * mesh <-- pointer to mesh structure
517 * n_perio_face_couples --> global number of periodic couples per
518 * periodicity (size: mesh->n_init_perio)
519 * perio_face_couples --> arrays of global periodic couple face numbers,
520 * for each periodicity
521 *----------------------------------------------------------------------------*/
522
523void
525 cs_lnum_t **n_perio_face_couples,
526 cs_gnum_t ***perio_face_couples);
527
528/*----------------------------------------------------------------------------
529 * Build global cell numbering array extended to ghost cell values.
530 *
531 * If the blank_perio flag is nonzero, periodic ghost cell numbers
532 * are set to zero instead of the value of the matching cell.
533 *
534 * The caller is responsible for freeing the returned array when it
535 * is no longer useful.
536 *
537 * parameters:
538 * mesh <-- pointer to mesh structure
539 * blank_perio <-- flag to zeroe periodic cell values
540 *----------------------------------------------------------------------------*/
541
542cs_gnum_t *
544 int blank_perio);
545
546/*----------------------------------------------------------------------------
547 * Mark interior faces with the number of their associated periodic
548 * transform id.
549 *
550 * parameters:
551 * mesh <-- pointer to mesh structure
552 * perio_num --> periodicity number associated with each face, signed for
553 * direct/reverse transform, 0 for non-periodic faces
554 * (size: mesh->n_i_faces)
555 *----------------------------------------------------------------------------*/
556
557void
559 int perio_num[]);
560
561/*----------------------------------------------------------------------------*/
572/*----------------------------------------------------------------------------*/
573
574void
576 int cell_b_flag[]);
577
578/*----------------------------------------------------------------------------
579 * Print information on a mesh structure.
580 *
581 * This includes printing element counts by cs_mesh_print_element_counts.
582 *
583 * parameters:
584 * mesh <-- pointer to mesh structure.
585 * name <-- associated name.
586 *----------------------------------------------------------------------------*/
587
588void
590 const char *name);
591
592/*----------------------------------------------------------------------------
593 * Print element counts on a mesh structure.
594 *
595 * parameters:
596 * mesh <-- pointer to mesh structure.
597 * name <-- associated name.
598 *----------------------------------------------------------------------------*/
599
600void
602 const char *name);
603
604/*----------------------------------------------------------------------------
605 * Compute global face connectivity size.
606 *
607 * Faces on simple parallel boundaries are counted only once, but periodic
608 * faces are counted twice.
609 *
610 * parameters:
611 * mesh <-- pointer to a cs_mesh_t structure
612 * g_i_face_vertices_size --> global interior face connectivity size, or NULL
613 * g_b_face_vertices_size --> global boundary face connectivity size, or NULL
614 *----------------------------------------------------------------------------*/
615
616void
618 cs_gnum_t *g_i_face_vertices_size,
619 cs_gnum_t *g_b_face_vertices_size);
620
621/*----------------------------------------------------------------------------
622 * Print statistics about mesh selectors usage to log.
623 *
624 * parameters:
625 * mesh <-- pointer to a mesh structure
626 *----------------------------------------------------------------------------*/
627
628void
630
631/*----------------------------------------------------------------------------
632 * Dump of a mesh structure.
633 *
634 * parameters:
635 * mesh <-> pointer to mesh structure.
636 *----------------------------------------------------------------------------*/
637
638void
640
641/*----------------------------------------------------------------------------*/
656/*----------------------------------------------------------------------------*/
657
658void
660 const cs_e2n_sum_t e2n,
661 int block_size,
662 int *n_groups,
663 int *n_blocks);
664
665/*----------------------------------------------------------------------------*/
690/*----------------------------------------------------------------------------*/
691
692void
694 const cs_e2n_sum_t e2n,
695 int group_id,
696 int block_id,
697 int block_count,
698 int block_size,
699 cs_lnum_t *s_id,
700 cs_lnum_t *e_id);
701
702/*----------------------------------------------------------------------------*/
703
705
706#endif /* __CS_MESH_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:367
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
cs_halo_type_t
Definition: cs_halo.h:57
struct _cs_interface_set_t cs_interface_set_t
Definition: cs_interface.h:61
void cs_mesh_free_rebuildable(cs_mesh_t *mesh, bool free_halos)
Definition: cs_mesh.cpp:2211
cs_mesh_t * cs_mesh_create(void)
Definition: cs_mesh.cpp:1920
void cs_mesh_init_cell_selector(void)
Definition: cs_mesh.cpp:3165
void cs_mesh_discard_free_vertices(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2379
void cs_mesh_get_face_perio_num(const cs_mesh_t *mesh, int perio_num[])
Definition: cs_mesh.cpp:3424
void cs_mesh_print_element_counts(const cs_mesh_t *mesh, const char *name)
Definition: cs_mesh.cpp:3625
void cs_mesh_discard_refinement_info(cs_mesh_t *mesh)
Discard mesh refinement info.
Definition: cs_mesh.cpp:2409
void cs_mesh_update_b_cells(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2522
void cs_mesh_clean_families(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2963
void cs_mesh_update_auxiliary(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2565
void cs_mesh_init_b_selector(void)
Definition: cs_mesh.cpp:3189
void cs_mesh_i_faces_thread_block_count(const cs_mesh_t *m, const cs_e2n_sum_t e2n, int block_size, int *n_groups, int *n_blocks)
Determine number of blocks and associated groups to be used for loops on interior faces.
Definition: cs_mesh.cpp:3965
void cs_mesh_selector_stats(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3653
void cs_mesh_free_b_rebuildable(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2270
void cs_mesh_init_halo(cs_mesh_t *mesh, cs_mesh_builder_t *mb, cs_halo_type_t halo_type, int verbosity, bool rebuild_vtx_interace)
Definition: cs_mesh.cpp:2668
void cs_mesh_i_faces_thread_block_range(const cs_mesh_t *m, const cs_e2n_sum_t e2n, int group_id, int block_id, int block_count, int block_size, cs_lnum_t *s_id, cs_lnum_t *e_id)
Compute array index bounds for a block of interior faces associated to a thread or task.
Definition: cs_mesh.cpp:4021
void cs_mesh_tag_boundary_cells(cs_mesh_t *mesh, int cell_b_flag[])
Mark cells adjacent to boundary, through faces or vertices.
Definition: cs_mesh.cpp:3473
fvm_group_class_set_t * cs_mesh_create_group_classes(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3085
void cs_mesh_discard_free_faces(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2298
void cs_mesh_dump(const cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3700
void cs_mesh_reinit(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2071
void cs_mesh_init_i_selector(void)
Definition: cs_mesh.cpp:3213
cs_gnum_t cs_mesh_n_g_ghost_cells(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2940
void cs_mesh_init_interfaces(cs_mesh_t *mesh, cs_mesh_builder_t *mb)
void cs_mesh_get_perio_faces(const cs_mesh_t *mesh, cs_lnum_t **n_perio_face_couples, cs_gnum_t ***perio_face_couples)
Definition: cs_mesh.cpp:3295
cs_mesh_t * cs_glob_mesh
cs_mesh_t * cs_mesh_destroy(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2054
cs_mesh_time_dep_t
Definition: cs_mesh.h:74
@ CS_MESH_TRANSIENT_COORDS
Definition: cs_mesh.h:77
@ CS_MESH_TRANSIENT_CONNECT
Definition: cs_mesh.h:78
@ CS_MESH_FIXED
Definition: cs_mesh.h:76
cs_gnum_t cs_mesh_compact_gnum(cs_lnum_t n_elts, cs_gnum_t *elt_gnum)
Definition: cs_mesh.cpp:2177
void cs_mesh_update_selectors(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3238
cs_gnum_t * cs_mesh_get_cell_gnum(const cs_mesh_t *mesh, int blank_perio)
Definition: cs_mesh.cpp:3347
void cs_mesh_sync_var_scal(cs_real_t *var)
Definition: cs_mesh.cpp:3270
void cs_mesh_init_selectors(void)
Definition: cs_mesh.cpp:3146
void cs_mesh_print_info(const cs_mesh_t *mesh, const char *name)
Definition: cs_mesh.cpp:3560
void cs_mesh_g_face_vertices_sizes(const cs_mesh_t *mesh, cs_gnum_t *g_i_face_vertices_size, cs_gnum_t *g_b_face_vertices_size)
Definition: cs_mesh.cpp:2432
void cs_mesh_init_group_classes(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3131
cs_e2n_sum_t
Definition: cs_parall.h:52
struct _fvm_group_class_set_t fvm_group_class_set_t
Definition: fvm_group.h:60
struct _fvm_periodicity_t fvm_periodicity_t
Definition: fvm_periodicity.h:67
struct _fvm_selector_t fvm_selector_t
Definition: fvm_selector.h:51
Definition: mesh.f90:26
Definition: cs_halo.h:78
Definition: cs_mesh_builder.h:57
Definition: cs_mesh.h:85
int save_if_modified
Definition: cs_mesh.h:221
int modified
Definition: cs_mesh.h:220
int n_transforms
Definition: cs_mesh.h:141
cs_lnum_t * cell_cells_idx
Definition: cs_mesh.h:172
cs_lnum_t * b_cells
Definition: cs_mesh.h:168
fvm_selector_t * select_cells
Definition: cs_mesh.h:199
cs_lnum_t * cell_cells_lst
Definition: cs_mesh.h:175
int verbosity
Definition: cs_mesh.h:219
cs_lnum_t * b_face_cells
Definition: cs_mesh.h:112
int * i_face_family
Definition: cs_mesh.h:192
cs_lnum_t n_i_faces
Definition: cs_mesh.h:98
cs_numbering_t * vtx_numbering
Definition: cs_mesh.h:161
cs_interface_set_t * vtx_interfaces
Definition: cs_mesh.h:155
int * b_face_family
Definition: cs_mesh.h:193
cs_gnum_t n_g_i_faces
Definition: cs_mesh.h:123
cs_lnum_t n_b_faces_all
Definition: cs_mesh.h:216
char * group
Definition: cs_mesh.h:186
cs_range_set_t * vtx_range_set
Definition: cs_mesh.h:157
int domain_num
Definition: cs_mesh.h:90
cs_numbering_t * b_face_numbering
Definition: cs_mesh.h:163
cs_numbering_t * i_face_numbering
Definition: cs_mesh.h:162
cs_lnum_t n_b_faces
Definition: cs_mesh.h:99
cs_lnum_t * i_face_vtx_idx
Definition: cs_mesh.h:114
cs_gnum_t n_g_i_c_faces
Definition: cs_mesh.h:127
cs_lnum_t * gcell_vtx_lst
Definition: cs_mesh.h:180
cs_lnum_t dim
Definition: cs_mesh.h:89
cs_gnum_t n_g_vertices
Definition: cs_mesh.h:125
bool have_r_gen
Definition: cs_mesh.h:205
cs_gnum_t n_g_b_faces
Definition: cs_mesh.h:124
cs_lnum_t n_cells_with_ghosts
Definition: cs_mesh.h:151
cs_lnum_t n_cells
Definition: cs_mesh.h:97
int have_rotation_perio
Definition: cs_mesh.h:143
int n_groups
Definition: cs_mesh.h:184
fvm_periodicity_t * periodicity
Definition: cs_mesh.h:145
int n_families
Definition: cs_mesh.h:188
char * vtx_r_gen
Definition: cs_mesh.h:207
fvm_selector_t * select_i_faces
Definition: cs_mesh.h:200
cs_gnum_t n_g_cells
Definition: cs_mesh.h:122
fvm_group_class_set_t * class_defs
Definition: cs_mesh.h:195
int * cell_family
Definition: cs_mesh.h:191
int n_init_perio
Definition: cs_mesh.h:140
cs_lnum_t n_vertices
Definition: cs_mesh.h:100
cs_halo_t * halo
Definition: cs_mesh.h:156
cs_lnum_2_t * i_face_cells
Definition: cs_mesh.h:111
cs_lnum_t * b_face_vtx_idx
Definition: cs_mesh.h:117
cs_numbering_t * cell_numbering
Definition: cs_mesh.h:160
cs_lnum_t * b_face_vtx_lst
Definition: cs_mesh.h:118
cs_lnum_t b_face_vtx_connect_size
Definition: cs_mesh.h:104
cs_gnum_t * global_vtx_num
Definition: cs_mesh.h:136
cs_gnum_t * global_i_face_num
Definition: cs_mesh.h:134
int * group_idx
Definition: cs_mesh.h:185
cs_gnum_t * global_b_face_num
Definition: cs_mesh.h:135
char * i_face_r_gen
Definition: cs_mesh.h:206
cs_lnum_t i_face_vtx_connect_size
Definition: cs_mesh.h:102
cs_halo_type_t halo_type
Definition: cs_mesh.h:149
int n_max_family_items
Definition: cs_mesh.h:189
fvm_selector_t * select_b_faces
Definition: cs_mesh.h:201
int n_domains
Definition: cs_mesh.h:91
cs_lnum_t * i_face_vtx_lst
Definition: cs_mesh.h:115
cs_lnum_t n_ghost_cells
Definition: cs_mesh.h:153
cs_lnum_t * gcell_vtx_idx
Definition: cs_mesh.h:179
cs_real_t * vtx_coord
Definition: cs_mesh.h:109
cs_lnum_t n_b_cells
Definition: cs_mesh.h:167
cs_mesh_time_dep_t time_dep
Definition: cs_mesh.h:93
cs_gnum_t * global_cell_num
Definition: cs_mesh.h:133
cs_gnum_t n_g_free_faces
Definition: cs_mesh.h:211
int * family_item
Definition: cs_mesh.h:190
cs_gnum_t n_g_b_faces_all
Definition: cs_mesh.h:214
Definition: cs_numbering.h:87
Definition: cs_range_set.h:57