8.3
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-2024 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 "cs_defs.h"
35
36#include "fvm_group.h"
37#include "fvm_selector.h"
38#include "fvm_periodicity.h"
39
40#include "cs_base.h"
41#include "cs_halo.h"
42#include "cs_interface.h"
43#include "cs_numbering.h"
44#include "cs_parall.h"
45#include "cs_range_set.h"
46
47#include "cs_mesh_builder.h"
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 * Discard free (isolated) faces from a mesh.
299 *
300 * This should always be done before using the mesh for computation.
301 *
302 * parameters:
303 * mesh <-> pointer to mesh structure
304 *----------------------------------------------------------------------------*/
305
306void
308
309/*----------------------------------------------------------------------------
310 * Discard free (isolated) vertices from a mesh.
311 *
312 * This is recommended before using the mesh for computation.
313 *
314 * parameters:
315 * mesh <-> pointer to mesh structure
316 *----------------------------------------------------------------------------*/
317
318void
320
321/*----------------------------------------------------------------------------*/
330/*----------------------------------------------------------------------------*/
331
332void
334
335/*----------------------------------------------------------------------------
336 * Generate or update list of mesh boundary cells.
337 *
338 * parameters:
339 * mesh <-> pointer to a cs_mesh_t structure
340 *----------------------------------------------------------------------------*/
341
342void
344
345/*----------------------------------------------------------------------------
346 * Compute or update mesh structure members that depend on other members,
347 * but whose results may be reused, such as global number of elements
348 * (cells, vertices, interior and boundary faces) and sync cell family.
349 *
350 * parameters:
351 * mesh <-> pointer to a cs_mesh_t structure
352 *----------------------------------------------------------------------------*/
353
354void
356
357/*----------------------------------------------------------------------------
358 * Creation and initialization of mesh face and vertex interfaces.
359 *
360 * parameters:
361 * mesh <-> pointer to mesh structure
362 * mb <-> pointer to mesh builder (in case of periodicity)
363 *----------------------------------------------------------------------------*/
364
365void
368
369/*----------------------------------------------------------------------------*/
383/*----------------------------------------------------------------------------*/
384
385void
388 cs_halo_type_t halo_type,
389 int verbosity,
390 bool rebuild_vtx_interace);
391
392/*----------------------------------------------------------------------------
393 * Get the global number of ghost cells.
394 *
395 * parameters:
396 * mesh <-- pointer to a mesh structure
397 *
398 * returns:
399 * Global number of ghost cells
400 *---------------------------------------------------------------------------*/
401
404
405/*----------------------------------------------------------------------------
406 * Update a scalar array in case of parallelism and/or periodicity.
407 *
408 * Note: this function is only present so that a C equivalent to the
409 * Fortran wrappers is available. In C code, directly using
410 * cs_halo_sync_var() is preferred.
411 *
412 * parameters:
413 * var <-> scalar array
414 *----------------------------------------------------------------------------*/
415
416void
418
419/*----------------------------------------------------------------------------
420 * Update a scalar array in case of parallelism and/or periodicity,
421 * using an extended halo.
422 *
423 * Note: this function is only present so that a C equivalent to the
424 * Fortran wrappers is available. In C code, directly using the
425 * cs_halo_sync_var() is preferred.
426 *
427 * parameters:
428 * var <-> scalar array
429 *----------------------------------------------------------------------------*/
430
431void
433
434/*----------------------------------------------------------------------------
435 * Update a vector array in case of parallelism and/or periodicity.
436 *
437 * parameters:
438 * var <-> interleaved vector (of dimension 3)
439 *----------------------------------------------------------------------------*/
440
441void
443
444/*----------------------------------------------------------------------------
445 * Update a symmetric tensor array in case of parallelism and/or periodicity.
446 *
447 * parameters:
448 * var <-> symmetric interleaved tensor (of dimension 6)
449 *----------------------------------------------------------------------------*/
450
451void
453
454/*----------------------------------------------------------------------------
455 * Order family numbers and remove duplicates
456 *
457 * parameters
458 * mesh <-> pointer to mesh structure
459 *----------------------------------------------------------------------------*/
460
461void
463
464/*----------------------------------------------------------------------------
465 * Create group classes based on a mesh's family definitions.
466 *
467 * parameters:
468 * mesh <-- pointer to mesh structure
469 *
470 * returns:
471 * pointer to group classes structure based on mesh's family definitions
472 *----------------------------------------------------------------------------*/
473
476
477/*----------------------------------------------------------------------------
478 * Define group classes for a mesh based on its family definitions.
479 *
480 * parameters:
481 * mesh <-> pointer to mesh structure
482 *----------------------------------------------------------------------------*/
483
484void
486
487/*----------------------------------------------------------------------------
488 * Assign selectors to global mesh.
489 *
490 * Should be called once the mesh is fully built.
491 *----------------------------------------------------------------------------*/
492
493void
495
496/*----------------------------------------------------------------------------
497 * Update selector and associated structures.
498 *
499 * parameters:
500 * mesh <-> pointer to a mesh structure
501 *----------------------------------------------------------------------------*/
502
503void
505
506/*----------------------------------------------------------------------------
507 * Get global lists of periodic face couples.
508 *
509 * In parallel, each face couple may appear on only one rank.
510 *
511 * The caller is responsible for freeing the arrays allocated and returned
512 * by this function once they are no onger needed.
513 *
514 * parameters:
515 * mesh <-- pointer to mesh structure
516 * n_perio_face_couples --> global number of periodic couples per
517 * periodicity (size: mesh->n_init_perio)
518 * perio_face_couples --> arrays of global periodic couple face numbers,
519 * for each periodicity
520 *----------------------------------------------------------------------------*/
521
522void
524 cs_lnum_t **n_perio_face_couples,
525 cs_gnum_t ***perio_face_couples);
526
527/*----------------------------------------------------------------------------
528 * Build global cell numbering array extended to ghost cell values.
529 *
530 * If the blank_perio flag is nonzero, periodic ghost cell numbers
531 * are set to zero instead of the value of the matching cell.
532 *
533 * The caller is responsible for freeing the returned array when it
534 * is no longer useful.
535 *
536 * parameters:
537 * mesh <-- pointer to mesh structure
538 * blank_perio <-- flag to zeroe periodic cell values
539 *----------------------------------------------------------------------------*/
540
541cs_gnum_t *
543 int blank_perio);
544
545/*----------------------------------------------------------------------------
546 * Mark interior faces with the number of their associated periodic
547 * transform id.
548 *
549 * parameters:
550 * mesh <-- pointer to mesh structure
551 * perio_num --> periodicity number associated with each face, signed for
552 * direct/reverse transform, 0 for non-periodic faces
553 * (size: mesh->n_i_faces)
554 *----------------------------------------------------------------------------*/
555
556void
558 int perio_num[]);
559
560/*----------------------------------------------------------------------------*/
571/*----------------------------------------------------------------------------*/
572
573void
575 int cell_b_flag[]);
576
577/*----------------------------------------------------------------------------
578 * Print information on a mesh structure.
579 *
580 * parameters:
581 * mesh <-- pointer to mesh structure.
582 * name <-- associated name.
583 *----------------------------------------------------------------------------*/
584
585void
587 const char *name);
588
589/*----------------------------------------------------------------------------
590 * Compute global face connectivity size.
591 *
592 * Faces on simple parallel boundaries are counted only once, but periodic
593 * faces are counted twice.
594 *
595 * parameters:
596 * mesh <-- pointer to a cs_mesh_t structure
597 * g_i_face_vertices_size --> global interior face connectivity size, or NULL
598 * g_b_face_vertices_size --> global boundary face connectivity size, or NULL
599 *----------------------------------------------------------------------------*/
600
601void
603 cs_gnum_t *g_i_face_vertices_size,
604 cs_gnum_t *g_b_face_vertices_size);
605
606/*----------------------------------------------------------------------------
607 * Print statistics about mesh selectors usage to log.
608 *
609 * parameters:
610 * mesh <-- pointer to a mesh structure
611 *----------------------------------------------------------------------------*/
612
613void
615
616/*----------------------------------------------------------------------------
617 * Dump of a mesh structure.
618 *
619 * parameters:
620 * mesh <-> pointer to mesh structure.
621 *----------------------------------------------------------------------------*/
622
623void
625
626/*----------------------------------------------------------------------------*/
641/*----------------------------------------------------------------------------*/
642
643void
645 const cs_e2n_sum_t e2n,
646 int block_size,
647 int *n_groups,
648 int *n_blocks);
649
650/*----------------------------------------------------------------------------*/
675/*----------------------------------------------------------------------------*/
676
677void
679 const cs_e2n_sum_t e2n,
680 int group_id,
681 int block_id,
682 int block_count,
683 int block_size,
684 cs_lnum_t *s_id,
685 cs_lnum_t *e_id);
686
687/*----------------------------------------------------------------------------*/
688
690
691#endif /* __CS_MESH_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
double cs_real_t
Floating-point value.
Definition: cs_defs.h:342
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:352
uint64_t cs_gnum_t
global mesh entity number
Definition: cs_defs.h:325
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:361
#define END_C_DECLS
Definition: cs_defs.h:543
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335
cs_halo_type_t
Definition: cs_halo.h:56
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:2233
cs_mesh_t * cs_mesh_create(void)
Definition: cs_mesh.cpp:1942
void cs_mesh_discard_free_vertices(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2370
void cs_mesh_get_face_perio_num(const cs_mesh_t *mesh, int perio_num[])
Definition: cs_mesh.cpp:3419
void cs_mesh_discard_refinement_info(cs_mesh_t *mesh)
Discard mesh refinement info.
Definition: cs_mesh.cpp:2400
void cs_mesh_update_b_cells(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2513
void cs_mesh_clean_families(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2954
void cs_mesh_update_auxiliary(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2556
void cs_mesh_sync_var_scal_ext(cs_real_t *var)
Definition: cs_mesh.cpp:3220
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:3943
void cs_mesh_selector_stats(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3631
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:2659
void cs_mesh_sync_var_sym_tens(cs_real_6_t *var)
Definition: cs_mesh.cpp:3259
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:3999
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:3468
fvm_group_class_set_t * cs_mesh_create_group_classes(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3076
void cs_mesh_discard_free_faces(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2289
void cs_mesh_dump(const cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3678
void cs_mesh_reinit(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2093
cs_gnum_t cs_mesh_n_g_ghost_cells(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2931
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:3290
cs_mesh_t * cs_glob_mesh
cs_mesh_t * cs_mesh_destroy(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:2076
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:2199
void cs_mesh_update_selectors(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3181
cs_gnum_t * cs_mesh_get_cell_gnum(const cs_mesh_t *mesh, int blank_perio)
Definition: cs_mesh.cpp:3342
void cs_mesh_sync_var_scal(cs_real_t *var)
Definition: cs_mesh.cpp:3199
void cs_mesh_sync_var_vect(cs_real_t *var)
Definition: cs_mesh.cpp:3236
void cs_mesh_init_selectors(void)
Definition: cs_mesh.cpp:3137
void cs_mesh_print_info(const cs_mesh_t *mesh, const char *name)
Definition: cs_mesh.cpp:3553
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:2423
void cs_mesh_init_group_classes(cs_mesh_t *mesh)
Definition: cs_mesh.cpp:3122
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:77
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