9.2
general documentation
cs_mesh_quantities.h
Go to the documentation of this file.
1#ifndef CS_MESH_QUANTITIES_H
2#define CS_MESH_QUANTITIES_H
3
4/*============================================================================
5 * Management of mesh quantities
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_base.h"
35#include "mesh/cs_mesh.h"
36
37/*=============================================================================
38 * Macro definitions
39 *============================================================================*/
40
47/*
48 * Cell quantities correction types
49 */
50
52#define CS_BAD_CELLS_WARPED_CORRECTION (1 << 0)
53
55#define CS_BAD_CELLS_REGULARISATION (1 << 1)
56
58#define CS_CELL_FACE_CENTER_CORRECTION (1 << 2)
59
61#define CS_CELL_CENTER_CORRECTION (1 << 3)
62
64#define CS_FACE_DISTANCE_CLIP (1 << 4)
65
67#define CS_FACE_RECONSTRUCTION_CLIP (1 << 5)
68
70#define CS_CELL_VOLUME_RATIO_CORRECTION (1 << 6)
71
75#define CS_FACE_CENTER_REFINE (1 << 7)
76
78#define CS_FACE_NULL_SURFACE (1 << 8)
79
82/*============================================================================
83 * Type definition
84 *============================================================================*/
85
86/* Structure associated to mesh quantities management */
87
88typedef struct {
89
90 cs_real_3_t *cell_cen; /* Cell center coordinates */
91
92 cs_real_t *cell_vol; /* Pointer to cell volume */
93 cs_real_t *_cell_vol; /* Cell volume, if owner */
94
95 cs_real_t *i_face_normal; /* Surface normal of interior faces.
96 (L2 norm equals area of the face) */
97 cs_real_t *b_face_normal; /* Surface normal of border faces.
98 (L2 norm equals area of the face) */
99 cs_real_t *c_w_face_normal; /* Solid surface normal immersed in the cells.
100 (L2 norm equals area of the face) */
101 cs_real_3_t *i_face_cog; /* Center of gravity of interior faces */
102 cs_real_3_t *b_face_cog; /* Center of gravity of border faces */
103
104 cs_real_t *c_w_face_cog; /* Center of gravity of solid face
105 immersed in the cells */
106
107 cs_real_t *i_face_surf; /* Surface of interior faces. */
108 cs_real_t *b_face_surf; /* Surface of boundary faces. */
109
110 cs_real_t *c_w_face_surf; /* Solid surface of cells. */
111
112 cs_nreal_3_t *i_face_u_normal; /* Unit normal of interior faces. */
113 cs_nreal_3_t *b_face_u_normal; /* Unit normal of boundary faces. */
114
115 cs_real_2_t *i_f_face_factor; /* Fluid surface factor of interior faces. */
116 cs_real_t *b_f_face_factor; /* Fluid surface factor of boundary faces. */
117
118 cs_rreal_3_t *diipb; /* Vector II' for border faces */
119 cs_real_3_t *dofij; /* Vector OF for interior faces */
120 cs_rreal_3_t *diipf; /* Vector II' for interior faces */
121 cs_rreal_3_t *djjpf; /* Vector JJ' for interior faces */
122
123 cs_real_t *i_dist; /* Distance between the centers of the two
124 cells sharing an interior face */
125 cs_real_t *b_dist; /* Distance between the cell center and
126 the center of gravity of border faces */
127 cs_real_t *c_w_dist_inv; /* Distance between the centers of the cell
128 and the solid face */
129
130 cs_real_t *weight; /* Interior faces weighting factor */
131
132 cs_real_t min_vol; /* Minimum cell volume */
133 cs_real_t max_vol; /* Maximum cell volume */
134 cs_real_t tot_vol; /* Total volume */
135
136 cs_real_t *corr_grad_lin_det; /* Determinant of geometrical matrix
137 linear gradient correction */
138 cs_real_33_t *corr_grad_lin; /* Geometrical matrix
139 linear gradient correction */
140
141 int *b_sym_flag; /* Symmetry flag for boundary faces */
142 int has_disable_flag; /* Is the cell disabled?
143 0: unactivated
144 1: activated */
145 int *c_disable_flag; /* Is the cell disabled?
146 used for fluid solid and porous models */
147 unsigned *bad_cell_flag; /* Flag (mask) for bad cells detected */
148
150
151/*============================================================================
152 * Global variables
153 *============================================================================*/
154
155/* Pointers to mesh quantities structure associated to the main mesh */
158
159/* Flag (mask) to activate bad cells correction */
160extern unsigned cs_glob_mesh_quantities_flag;
161
162/*=============================================================================
163 * Templated inline functions
164 *============================================================================*/
165
166#if defined(__cplusplus)
167
168/*----------------------------------------------------------------------------*/
178/*----------------------------------------------------------------------------*/
179
182 const int *c_disable_flag,
183 const cs_real_t c_vol[])
184{
185 cs_real_t dvol;
186
187 if (c_disable_flag == nullptr)
188 dvol = 1. / c_vol[c_id];
189 else if (c_disable_flag[c_id] == 0)
190 dvol = 1. / c_vol[c_id];
191 else
192 dvol = 0.;
193
194 return dvol;
195}
196
197#endif // defined(__cplusplus)
198
199/*=============================================================================
200 * Public function prototypes
201 *============================================================================*/
202
203/*----------------------------------------------------------------------------*/
211/*----------------------------------------------------------------------------*/
212
213static inline int
215 cs_lnum_t cell_id)
216{
217 return (1 - (mq->has_disable_flag
218 *mq->c_disable_flag[mq->has_disable_flag * cell_id]));
219}
220
221/*----------------------------------------------------------------------------*/
231/*----------------------------------------------------------------------------*/
232
233int
235
236/*----------------------------------------------------------------------------*/
247/*----------------------------------------------------------------------------*/
248
249int
251
252/*----------------------------------------------------------------------------*/
258/*----------------------------------------------------------------------------*/
259
260extern "C" cs_mesh_quantities_t *
262
263/*----------------------------------------------------------------------------*/
271/*----------------------------------------------------------------------------*/
272
273extern "C" cs_mesh_quantities_t *
275
276/*----------------------------------------------------------------------------*/
282/*----------------------------------------------------------------------------*/
283
284void
286
287/*----------------------------------------------------------------------------*/
294/*----------------------------------------------------------------------------*/
295
296void
299
300/*----------------------------------------------------------------------------*/
307/*----------------------------------------------------------------------------*/
308
309void
312
313/*----------------------------------------------------------------------------
314 * Compute the total, min, and max volumes of cells
315 *
316 * parameters:
317 * mesh <-- pointer to mesh structure
318 * mesh_quantities <-> pointer to a mesh quantities structure
319 *----------------------------------------------------------------------------*/
320
321void
323 cs_mesh_quantities_t *mesh_quantities);
324
325/*----------------------------------------------------------------------------
326 * Compute fluid section mesh quantities at the initial step
327 *
328 * parameters:
329 * mesh <-- pointer to a cs_mesh_t structure
330 * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
331 *----------------------------------------------------------------------------*/
332
333void
335 cs_mesh_quantities_t *mesh_quantities);
336
337/*----------------------------------------------------------------------------*/
346/*----------------------------------------------------------------------------*/
347
348void
350 cs_real_3_t *cen_points,
352
353/*----------------------------------------------------------------------------
354 * Compute mesh quantities
355 *
356 * parameters:
357 * mesh <-- pointer to a cs_mesh_t structure
358 * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
359 *----------------------------------------------------------------------------*/
360
361void
363 cs_mesh_quantities_t *mesh_quantities);
364
365/*----------------------------------------------------------------------------
366 * Compute internal and border face normal.
367 *
368 * parameters:
369 * mesh <-- pointer to a cs_mesh_t structure
370 * p_i_face_normal <-> pointer to the internal face normal array
371 * p_b_face_normal <-> pointer to the border face normal array
372 *----------------------------------------------------------------------------*/
373
374void
376 cs_real_t *p_i_face_normal[],
377 cs_real_t *p_b_face_normal[]);
378
379/*----------------------------------------------------------------------------
380 * Compute center of gravity and surface normal associated to a set of faces
381 *
382 * parameters:
383 * n_faces <-- number of faces
384 * vtx_coord <-- vertex coordinates
385 * face_vtx_idx <-- "face -> vertices" connectivity index
386 * face_vtx <-- "face -> vertices" connectivity
387 * face_cog --> coordinates of the center of gravity of the faces
388 * face_normal --> face surface normals
389 *----------------------------------------------------------------------------*/
390
391void
393 const cs_real_t vtx_coord[][3],
394 const cs_lnum_t face_vtx_idx[],
395 const cs_lnum_t face_vtx[],
396 cs_real_t face_cog[][3],
397 cs_real_t face_normal[][3]);
398
399/*----------------------------------------------------------------------------
400 * Compute center of gravity and unit normal associated to a set of faces
401 *
402 * parameters:
403 * n_faces <-- number of faces
404 * vtx_coord <-- vertex coordinates
405 * face_vtx_idx <-- "face -> vertices" connectivity index
406 * face_vtx <-- "face -> vertices" connectivity
407 * face_cog --> coordinates of the center of gravity of the faces
408 * face_u_normal --> face unit normals
409 *----------------------------------------------------------------------------*/
410
411void
413 const cs_real_t vtx_coord[][3],
414 const cs_lnum_t face_vtx_idx[],
415 const cs_lnum_t face_vtx[],
416 cs_real_t face_cog[][3],
417 cs_nreal_t face_u_normal[][3]);
418
419/*----------------------------------------------------------------------------
420 * Compute border face centers and normals.
421 *
422 * Deprecated: use cs_mesh_quantities_compute_face_cog_sn or
423 * cs_mesh_quantities_compute_face_cog_un instead.
424 *
425 * The corresponding arrays are allocated by this function, and it is the
426 * caller's responsibility to free them when they are no longer needed.
427 *
428 * parameters:
429 * mesh <-- pointer to a cs_mesh_t structure
430 * p_b_face_cog <-> pointer to the border face center array
431 * p_b_face_normal <-> pointer to the border face normal array
432 *----------------------------------------------------------------------------*/
433
434[[deprecated(
435"Use cs_mesh_quantities_compute_face_cog_sn or "
436"cs_mesh_quantities_compute_face_cog_un instead"
437)]]
438void
440 cs_real_t *p_b_face_cog[],
441 cs_real_t *p_b_face_normal[]);
442
443/*----------------------------------------------------------------------------*/
463/*----------------------------------------------------------------------------*/
464
465void
467 const cs_real_3_t i_face_norm[],
468 const cs_real_3_t i_face_cog[],
469 const cs_real_3_t b_face_norm[],
470 const cs_real_3_t b_face_cog[],
471 cs_real_3_t cell_cen[]);
472
473/*----------------------------------------------------------------------------
474 * Compute cell volumes.
475 *
476 * The corresponding array is allocated by this function, and it is the
477 * caller's responsability to free it when they are no longer needed.
478 *
479 * parameters:
480 * mesh <-- pointer to a cs_mesh_t structure
481 *
482 * return:
483 * pointer to newly allocated cell volumes array
484 *----------------------------------------------------------------------------*/
485
486cs_real_t *
488
489/*----------------------------------------------------------------------------
490 * Check that no negative volumes are present, and exit on error otherwise.
491 *
492 * parameters:
493 * mesh <-- pointer to mesh structure
494 * mesh_quantities <-- pointer to mesh quantities structure
495 * allow_error <-- 1 if errors are allowed, 0 otherwise
496 *----------------------------------------------------------------------------*/
497
498extern "C" void
500 const cs_mesh_quantities_t *mesh_quantities,
501 int allow_error);
502
503/*----------------------------------------------------------------------------*/
516/*----------------------------------------------------------------------------*/
517
520 cs_real_t tolerance);
521
522/*----------------------------------------------------------------------------
523 * Return the number of times mesh quantities have been computed.
524 *
525 * returns:
526 * number of times mesh quantities have been computed
527 *----------------------------------------------------------------------------*/
528
529int
531
532/*----------------------------------------------------------------------------*/
542/*----------------------------------------------------------------------------*/
543
544void
546 const cs_mesh_quantities_t *mq,
547 int n_passes,
548 cs_real_t b_thickness[]);
549
550/*----------------------------------------------------------------------------*/
559/*----------------------------------------------------------------------------*/
560
561void
563 const cs_mesh_quantities_t *mq,
564 int n_passes,
565 cs_real_t b_thickness[]);
566
567/*----------------------------------------------------------------------------*/
571/*----------------------------------------------------------------------------*/
572
573void
575
576/*----------------------------------------------------------------------------
577 * Dump a cs_mesh_quantities_t structure
578 *
579 * parameters:
580 * mesh <-- pointer to a cs_mesh_t structure
581 * mesh_quantities <-- pointer to a cs_mesh_quantities_t structure
582 *----------------------------------------------------------------------------*/
583
584void
586 const cs_mesh_quantities_t *mesh_quantities);
587
588/*----------------------------------------------------------------------------*/
589
590#endif /* CS_MESH_QUANTITIES_H */
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:555
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
cs_rreal_t cs_rreal_3_t[3]
Definition: cs_defs.h:378
cs_nreal_t cs_nreal_3_t[3]
Definition: cs_defs.h:375
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:349
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition: cs_defs.h:348
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:351
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:358
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
double cs_nreal_t
Definition: cs_defs.h:336
void cs_mesh_quantities_compute_face_cog_sn(cs_lnum_t n_faces, const cs_real_t vtx_coord[][3], const cs_lnum_t face_vtx_idx[], const cs_lnum_t face_vtx[], cs_real_t face_cog[][3], cs_real_t face_normal[][3])
Definition: cs_mesh_quantities.cpp:4850
void cs_mesh_quantities_sup_vectors(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.cpp:4768
unsigned cs_glob_mesh_quantities_flag
cs_mesh_quantities_t * cs_mesh_quantities_destroy(cs_mesh_quantities_t *mq)
Destroy a mesh quantities structure.
Definition: cs_mesh_quantities.cpp:2709
void cs_mesh_quantities_face_normal(const cs_mesh_t *mesh, cs_real_t *p_i_face_normal[], cs_real_t *p_b_face_normal[])
Definition: cs_mesh_quantities.cpp:4803
void cs_mesh_quantities_log_setup(void)
Log mesh quantities options to setup file.
Definition: cs_mesh_quantities.cpp:5446
static int cs_mesh_quantities_cell_is_active(const cs_mesh_quantities_t *mq, cs_lnum_t cell_id)
Return 0 if cell is disabled, 1 otherwise.
Definition: cs_mesh_quantities.h:214
void cs_mesh_quantities_compute_preprocess(const cs_mesh_t *m, cs_mesh_quantities_t *mq)
Compute mesh quantities needed for preprocessing.
Definition: cs_mesh_quantities.cpp:2780
void cs_mesh_quantities_b_thickness_f(const cs_mesh_t *m, const cs_mesh_quantities_t *mq, int n_passes, cs_real_t b_thickness[])
Determine local boundary thickness around each boundary face.
Definition: cs_mesh_quantities.cpp:5404
void cs_mesh_quantities_compute_face_cog_un(cs_lnum_t n_faces, const cs_real_t vtx_coord[][3], const cs_lnum_t face_vtx_idx[], const cs_lnum_t face_vtx[], cs_real_t face_cog[][3], cs_nreal_t face_u_normal[][3])
Definition: cs_mesh_quantities.cpp:4879
int cs_mesh_quantities_compute_count(void)
Definition: cs_mesh_quantities.cpp:5296
CS_F_HOST_DEVICE cs_real_t cs_mq_cell_vol_inv(cs_lnum_t c_id, const int *c_disable_flag, const cs_real_t c_vol[])
Compute volume inverse for non-disabled cell, 0 otherwise.
Definition: cs_mesh_quantities.h:181
void cs_mesh_quantities_check_vol(const cs_mesh_t *mesh, const cs_mesh_quantities_t *mesh_quantities, int allow_error)
Definition: cs_mesh_quantities.cpp:5150
void cs_mesh_quantities_cell_faces_cog(const cs_mesh_t *mesh, const cs_real_3_t i_face_norm[], const cs_real_3_t i_face_cog[], const cs_real_3_t b_face_norm[], const cs_real_3_t b_face_cog[], cs_real_3_t cell_cen[])
Compute approximate cells centers as the mean of the given face centers weighted by the associated su...
Definition: cs_mesh_quantities.cpp:4956
void cs_mesh_quantities_vol_reductions(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.cpp:4680
int cs_mesh_quantities_cell_cen_choice(int algo_choice)
Query or modification of the option for computing cell centers.
Definition: cs_mesh_quantities.cpp:2619
int cs_mesh_quantities_face_cog_choice(int algo_choice)
Query or modification of the option for computing face centers.
Definition: cs_mesh_quantities.cpp:2641
void cs_mesh_init_fluid_sections(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.cpp:4720
void cs_mesh_quantities_compute(const cs_mesh_t *m, cs_mesh_quantities_t *mq)
Compute mesh quantities.
Definition: cs_mesh_quantities.cpp:4505
void cs_mesh_quantities_free_all(cs_mesh_quantities_t *mq)
Reset a mesh quantities structure to its empty initial state.
Definition: cs_mesh_quantities.cpp:2727
void cs_mesh_quantities_dump(const cs_mesh_t *mesh, const cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.cpp:5491
cs_mesh_quantities_t * cs_glob_mesh_quantities_g
cs_mesh_quantities_t * cs_mesh_quantities_create(void)
Create a mesh quantities structure.
Definition: cs_mesh_quantities.cpp:2658
void cs_mesh_quantities_b_thickness_v(const cs_mesh_t *m, const cs_mesh_quantities_t *mq, int n_passes, cs_real_t b_thickness[])
Determine local boundary thickness around each vertex.
Definition: cs_mesh_quantities.cpp:5314
cs_real_6_t * cs_mesh_quantities_cell_extents(const cs_mesh_t *m, cs_real_t tolerance)
Compute the bounding box for cells.
Definition: cs_mesh_quantities.cpp:5208
void cs_mesh_quantities_solid_compute(const cs_mesh_t *m, cs_real_3_t *cen_points, cs_mesh_quantities_t *mq)
Compute cell and faces quantities needed at the immersed boundaries.
Definition: cs_mesh_quantities.cpp:3030
cs_real_t * cs_mesh_quantities_cell_volume(const cs_mesh_t *mesh)
Definition: cs_mesh_quantities.cpp:5089
cs_mesh_quantities_t * cs_glob_mesh_quantities
void cs_mesh_quantities_b_faces(const cs_mesh_t *mesh, cs_real_t *p_b_face_cog[], cs_real_t *p_b_face_normal[])
Compute boundary face centers and normals.
Definition: cs_mesh_quantities.cpp:4912
Definition: mesh.f90:26
Definition: cs_mesh_quantities.h:88
int * b_sym_flag
Definition: cs_mesh_quantities.h:141
cs_real_3_t * b_face_cog
Definition: cs_mesh_quantities.h:102
cs_real_t * c_w_face_surf
Definition: cs_mesh_quantities.h:110
cs_real_t * i_face_surf
Definition: cs_mesh_quantities.h:107
cs_rreal_3_t * diipb
Definition: cs_mesh_quantities.h:118
cs_real_t * b_dist
Definition: cs_mesh_quantities.h:125
int has_disable_flag
Definition: cs_mesh_quantities.h:142
cs_real_3_t * cell_cen
Definition: cs_mesh_quantities.h:90
cs_real_2_t * i_f_face_factor
Definition: cs_mesh_quantities.h:115
cs_real_3_t * dofij
Definition: cs_mesh_quantities.h:119
cs_rreal_3_t * diipf
Definition: cs_mesh_quantities.h:120
cs_real_t * b_face_surf
Definition: cs_mesh_quantities.h:108
cs_real_t * i_dist
Definition: cs_mesh_quantities.h:123
cs_real_3_t * i_face_cog
Definition: cs_mesh_quantities.h:101
cs_real_t * c_w_face_normal
Definition: cs_mesh_quantities.h:99
cs_real_t max_vol
Definition: cs_mesh_quantities.h:133
cs_real_t * cell_vol
Definition: cs_mesh_quantities.h:92
cs_real_t * weight
Definition: cs_mesh_quantities.h:130
cs_real_t * _cell_vol
Definition: cs_mesh_quantities.h:93
cs_real_t * b_face_normal
Definition: cs_mesh_quantities.h:97
cs_real_33_t * corr_grad_lin
Definition: cs_mesh_quantities.h:138
cs_real_t * c_w_face_cog
Definition: cs_mesh_quantities.h:104
cs_real_t tot_vol
Definition: cs_mesh_quantities.h:134
int * c_disable_flag
Definition: cs_mesh_quantities.h:145
cs_nreal_3_t * i_face_u_normal
Definition: cs_mesh_quantities.h:112
cs_real_t * b_f_face_factor
Definition: cs_mesh_quantities.h:116
cs_real_t min_vol
Definition: cs_mesh_quantities.h:132
cs_real_t * c_w_dist_inv
Definition: cs_mesh_quantities.h:127
cs_nreal_3_t * b_face_u_normal
Definition: cs_mesh_quantities.h:113
cs_real_t * corr_grad_lin_det
Definition: cs_mesh_quantities.h:136
cs_real_t * i_face_normal
Definition: cs_mesh_quantities.h:95
unsigned * bad_cell_flag
Definition: cs_mesh_quantities.h:147
cs_rreal_3_t * djjpf
Definition: cs_mesh_quantities.h:121
Definition: cs_mesh.h:85