9.2
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-2026 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
209 char *vtx_r_gen;
211 /* Status flags */
212
228} cs_mesh_t;
229
230/*============================================================================
231 * Static global variables
232 *============================================================================*/
233
234extern cs_mesh_t *cs_glob_mesh; /* Pointer to main mesh structure */
235
236/*=============================================================================
237 * Public function prototypes
238 *============================================================================*/
239
240/*----------------------------------------------------------------------------
241 * Create an empty mesh structure
242 *
243 * returns:
244 * pointer to created mesh structure
245 *----------------------------------------------------------------------------*/
246
247cs_mesh_t *
248cs_mesh_create(void);
249
250/*----------------------------------------------------------------------------
251 * Destroy a mesh structure
252 *
253 * mesh <-> pointer to a mesh structure
254 *
255 * returns:
256 * null pointer
257 *----------------------------------------------------------------------------*/
258
259cs_mesh_t *
261
262/*----------------------------------------------------------------------------
263 * Reinitialize mesh structure.
264 *
265 * returns:
266 * pointer to created mesh structure
267 *----------------------------------------------------------------------------*/
268
269void
271
272/*----------------------------------------------------------------------------
273 * Update (compactify) an array of global numbers.
274 *
275 * parameters:
276 * n_elts <-> number of local elements
277 * elt_gnum <-> global element numbers
278 *
279 * return:
280 * associated global number of elements
281 *----------------------------------------------------------------------------*/
282
285 cs_gnum_t *elt_gnum);
286
287/*----------------------------------------------------------------------------
288 * Remove arrays and structures that mey be rebuilt.
289 *
290 * mesh <-> pointer to a mesh structure
291 * free_halos <-- if true, free halos and parallel/periodic interface
292 * structures
293 *----------------------------------------------------------------------------*/
294
295void
297 bool free_halos);
298
299/*----------------------------------------------------------------------------
300 * Remove boundary arrays and structures that may be rebuilt.
301 *
302 * mesh <-> pointer to a mesh structure
303 *----------------------------------------------------------------------------*/
304
305void
307
308/*----------------------------------------------------------------------------
309 * Discard free (isolated) faces from a mesh.
310 *
311 * This should always be done before using the mesh for computation.
312 *
313 * parameters:
314 * mesh <-> pointer to mesh structure
315 *----------------------------------------------------------------------------*/
316
317void
319
320/*----------------------------------------------------------------------------
321 * Discard free (isolated) vertices from a mesh.
322 *
323 * This is recommended before using the mesh for computation.
324 *
325 * parameters:
326 * mesh <-> pointer to mesh structure
327 *----------------------------------------------------------------------------*/
328
329void
331
332/*----------------------------------------------------------------------------*/
341/*----------------------------------------------------------------------------*/
342
343void
345
346/*----------------------------------------------------------------------------
347 * Generate or update list of mesh boundary cells.
348 *
349 * parameters:
350 * mesh <-> pointer to a cs_mesh_t structure
351 *----------------------------------------------------------------------------*/
352
353void
355
356/*----------------------------------------------------------------------------
357 * Compute or update mesh structure members that depend on other members,
358 * but whose results may be reused, such as global number of elements
359 * (cells, vertices, interior and boundary faces) and sync cell family.
360 *
361 * parameters:
362 * mesh <-> pointer to a cs_mesh_t structure
363 *----------------------------------------------------------------------------*/
364
365void
367
368/*----------------------------------------------------------------------------
369 * Creation and initialization of mesh face and vertex interfaces.
370 *
371 * parameters:
372 * mesh <-> pointer to mesh structure
373 * mb <-> pointer to mesh builder (in case of periodicity)
374 *----------------------------------------------------------------------------*/
375
376void
379
380/*----------------------------------------------------------------------------*/
394/*----------------------------------------------------------------------------*/
395
396void
399 cs_halo_type_t halo_type,
400 int verbosity,
401 bool rebuild_vtx_interace);
402
403/*----------------------------------------------------------------------------
404 * Get the global number of ghost cells.
405 *
406 * parameters:
407 * mesh <-- pointer to a mesh structure
408 *
409 * returns:
410 * Global number of ghost cells
411 *---------------------------------------------------------------------------*/
412
415
416/*----------------------------------------------------------------------------
417 * Update a scalar array in case of parallelism and/or periodicity.
418 *
419 * Note: this function is only present so that a C equivalent to the
420 * Fortran wrappers is available. In C code, directly using
421 * cs_halo_sync_var() is preferred.
422 *
423 * parameters:
424 * var <-> scalar array
425 *----------------------------------------------------------------------------*/
426
427void
429
430/*----------------------------------------------------------------------------
431 * Order family numbers and remove duplicates
432 *
433 * parameters
434 * mesh <-> pointer to mesh structure
435 *----------------------------------------------------------------------------*/
436
437void
439
440/*----------------------------------------------------------------------------
441 * Create group classes based on a mesh's family definitions.
442 *
443 * parameters:
444 * mesh <-- pointer to mesh structure
445 *
446 * returns:
447 * pointer to group classes structure based on mesh's family definitions
448 *----------------------------------------------------------------------------*/
449
452
453/*----------------------------------------------------------------------------
454 * Define group classes for a mesh based on its family definitions.
455 *
456 * parameters:
457 * mesh <-> pointer to mesh structure
458 *----------------------------------------------------------------------------*/
459
460void
462
463/*----------------------------------------------------------------------------
464 * Assign selectors to global mesh.
465 *
466 * Should be called once the mesh is fully built.
467 *----------------------------------------------------------------------------*/
468
469void
471
472/*----------------------------------------------------------------------------
473 * Assign cell selector to global mesh.
474 *
475 * Should be called once the mesh is fully built.
476 *----------------------------------------------------------------------------*/
477
478void
480
481/*----------------------------------------------------------------------------
482 * Assign boundary selector to global mesh.
483 *
484 * Should be called once the mesh is fully built.
485 *----------------------------------------------------------------------------*/
486
487void
489
490/*----------------------------------------------------------------------------
491 * Assign internal selector to global mesh.
492 *
493 * Should be called once the mesh is fully built.
494 *----------------------------------------------------------------------------*/
495
496void
498
499/*----------------------------------------------------------------------------
500 * Update selector and associated structures.
501 *
502 * parameters:
503 * mesh <-> pointer to a mesh structure
504 *----------------------------------------------------------------------------*/
505
506void
508
509/*----------------------------------------------------------------------------*/
510/*
511 * \brief Complete mesh numbering substructures.
512 *
513 * If mesh numbering structures from upstream renumbering operations have
514 * not been defined yet for some mesh entities, assign defaults.
515 *
516 * \param[in, out] mesh pointer to global mesh structure
517 */
518/*----------------------------------------------------------------------------*/
519
520void
522
523/*----------------------------------------------------------------------------
524 * Get global lists of periodic face couples.
525 *
526 * In parallel, each face couple may appear on only one rank.
527 *
528 * The caller is responsible for freeing the arrays allocated and returned
529 * by this function once they are no onger needed.
530 *
531 * parameters:
532 * mesh <-- pointer to mesh structure
533 * n_perio_face_couples --> global number of periodic couples per
534 * periodicity (size: mesh->n_init_perio)
535 * perio_face_couples --> arrays of global periodic couple face numbers,
536 * for each periodicity
537 *----------------------------------------------------------------------------*/
538
539void
541 cs_lnum_t **n_perio_face_couples,
542 cs_gnum_t ***perio_face_couples);
543
544/*----------------------------------------------------------------------------
545 * Build global cell numbering array extended to ghost cell values.
546 *
547 * If the blank_perio flag is nonzero, periodic ghost cell numbers
548 * are set to zero instead of the value of the matching cell.
549 *
550 * The caller is responsible for freeing the returned array when it
551 * is no longer useful.
552 *
553 * parameters:
554 * mesh <-- pointer to mesh structure
555 * blank_perio <-- flag to zeroe periodic cell values
556 *----------------------------------------------------------------------------*/
557
558cs_gnum_t *
560 int blank_perio);
561
562/*----------------------------------------------------------------------------
563 * Mark interior faces with the number of their associated periodic
564 * transform id.
565 *
566 * parameters:
567 * mesh <-- pointer to mesh structure
568 * perio_num --> periodicity number associated with each face, signed for
569 * direct/reverse transform, 0 for non-periodic faces
570 * (size: mesh->n_i_faces)
571 *----------------------------------------------------------------------------*/
572
573void
575 int perio_num[]);
576
577/*----------------------------------------------------------------------------*/
588/*----------------------------------------------------------------------------*/
589
590void
592 int cell_b_flag[]);
593
594/*----------------------------------------------------------------------------
595 * Print information on a mesh structure.
596 *
597 * This includes printing element counts by cs_mesh_print_element_counts.
598 *
599 * parameters:
600 * mesh <-- pointer to mesh structure.
601 * name <-- associated name.
602 *----------------------------------------------------------------------------*/
603
604void
606 const char *name);
607
608/*----------------------------------------------------------------------------
609 * Print element counts on a mesh structure.
610 *
611 * parameters:
612 * mesh <-- pointer to mesh structure.
613 * name <-- associated name.
614 *----------------------------------------------------------------------------*/
615
616void
618 const char *name);
619
620/*----------------------------------------------------------------------------
621 * Compute global face connectivity size.
622 *
623 * Faces on simple parallel boundaries are counted only once, but periodic
624 * faces are counted twice.
625 *
626 * parameters:
627 * mesh <-- pointer to a cs_mesh_t structure
628 * g_i_face_vertices_size --> global interior face connectivity size, or NULL
629 * g_b_face_vertices_size --> global boundary face connectivity size, or NULL
630 *----------------------------------------------------------------------------*/
631
632void
634 cs_gnum_t *g_i_face_vertices_size,
635 cs_gnum_t *g_b_face_vertices_size);
636
637/*----------------------------------------------------------------------------
638 * Print statistics about mesh selectors usage to log.
639 *
640 * parameters:
641 * mesh <-- pointer to a mesh structure
642 *----------------------------------------------------------------------------*/
643
644void
646
647/*----------------------------------------------------------------------------
648 * Dump of a mesh structure.
649 *
650 * parameters:
651 * mesh <-> pointer to mesh structure.
652 *----------------------------------------------------------------------------*/
653
654void
656
657/*----------------------------------------------------------------------------*/
672/*----------------------------------------------------------------------------*/
673
674void
676 const cs_e2n_sum_t e2n,
677 int block_size,
678 int *n_groups,
679 int *n_blocks);
680
681/*----------------------------------------------------------------------------*/
706/*----------------------------------------------------------------------------*/
707
708void
710 const cs_e2n_sum_t e2n,
711 int group_id,
712 int block_id,
713 int block_count,
714 int block_size,
715 cs_lnum_t *s_id,
716 cs_lnum_t *e_id);
717
718/*----------------------------------------------------------------------------*/
719
721
722#endif /* CS_MESH_H */
#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:342
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:317
#define END_C_DECLS
Definition: cs_defs.h:529
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_halo_type_t
Definition: cs_halo.h:53
struct _cs_interface_set_t cs_interface_set_t
Definition: cs_interface.h:57
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:1917
void cs_mesh_init_cell_selector(void)
Definition: cs_mesh.cpp:3195
void cs_mesh_discard_free_vertices(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2380
void cs_mesh_get_face_perio_num(const cs_mesh_t *mesh, int perio_num[])
Definition: cs_mesh.cpp:3478
void cs_mesh_print_element_counts(const cs_mesh_t *mesh, const char *name)
Definition: cs_mesh.cpp:3679
void cs_mesh_discard_refinement_info(cs_mesh_t *mesh)
Discard mesh refinement info.
Definition: cs_mesh.cpp:2410
void cs_mesh_update_b_cells(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2524
void cs_mesh_clean_families(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2993
void cs_mesh_update_auxiliary(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2594
void cs_mesh_init_b_selector(void)
Definition: cs_mesh.cpp:3219
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:4025
void cs_mesh_selector_stats(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3707
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:2697
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:4081
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:3527
fvm_group_class_set_t * cs_mesh_create_group_classes(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3115
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:3754
void cs_mesh_reinit(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2069
void cs_mesh_init_i_selector(void)
Definition: cs_mesh.cpp:3243
void cs_mesh_complete_numbering(cs_mesh_t *mesh)
Complete mesh numbering substructures.
Definition: cs_mesh.cpp:3320
cs_gnum_t cs_mesh_n_g_ghost_cells(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2970
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:3349
cs_mesh_t * cs_glob_mesh
cs_mesh_t * cs_mesh_destroy(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2052
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:3268
cs_gnum_t * cs_mesh_get_cell_gnum(const cs_mesh_t *mesh, int blank_perio)
Definition: cs_mesh.cpp:3401
void cs_mesh_sync_var_scal(cs_real_t *var)
Definition: cs_mesh.cpp:3300
void cs_mesh_init_selectors(void)
Definition: cs_mesh.cpp:3176
void cs_mesh_print_info(const cs_mesh_t *mesh, const char *name)
Definition: cs_mesh.cpp:3614
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:2434
void cs_mesh_init_group_classes(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3161
cs_e2n_sum_t
Definition: cs_parall.h:52
struct _fvm_group_class_set_t fvm_group_class_set_t
Definition: fvm_group.h:56
struct _fvm_periodicity_t fvm_periodicity_t
Definition: fvm_periodicity.h:63
struct _fvm_selector_t fvm_selector_t
Definition: fvm_selector.h:51
Definition: mesh.f90:26
Definition: cs_halo.h:74
Definition: cs_mesh_builder.h:57
Definition: cs_mesh.h:85
int save_if_modified
Definition: cs_mesh.h:223
int modified
Definition: cs_mesh.h:222
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:221
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:218
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:209
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
char * b_face_r_c_idx
Definition: cs_mesh.h:207
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:213
int * family_item
Definition: cs_mesh.h:190
cs_gnum_t n_g_b_faces_all
Definition: cs_mesh.h:216
Definition: cs_numbering.h:91
Definition: cs_range_set.h:53