9.1
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-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_base.h"
35#include "mesh/cs_mesh.h"
36
37/*----------------------------------------------------------------------------*/
38
40
41/*=============================================================================
42 * Macro definitions
43 *============================================================================*/
44
51/*
52 * Cell quantities correction types
53 */
54
56#define CS_BAD_CELLS_WARPED_CORRECTION (1 << 0)
57
59#define CS_BAD_CELLS_REGULARISATION (1 << 1)
60
62#define CS_CELL_FACE_CENTER_CORRECTION (1 << 2)
63
65#define CS_CELL_CENTER_CORRECTION (1 << 3)
66
68#define CS_FACE_DISTANCE_CLIP (1 << 4)
69
71#define CS_FACE_RECONSTRUCTION_CLIP (1 << 5)
72
74#define CS_CELL_VOLUME_RATIO_CORRECTION (1 << 6)
75
79#define CS_FACE_CENTER_REFINE (1 << 7)
80
82#define CS_FACE_NULL_SURFACE (1 << 8)
83
86/*============================================================================
87 * Type definition
88 *============================================================================*/
89
90/* Structure associated to mesh quantities management */
91
92typedef struct {
93
94 cs_real_3_t *cell_cen; /* Cell center coordinates */
95 cs_real_3_t *cell_s_cen; /* Cell solid center coordinates */
96
97 cs_real_t *cell_vol; /* Pointer to cell volume */
98 cs_real_t *_cell_vol; /* Cell volume, if owner */
99
100 cs_real_t *i_face_normal; /* Surface normal of interior faces.
101 (L2 norm equals area of the face) */
102 cs_real_t *b_face_normal; /* Surface normal of border faces.
103 (L2 norm equals area of the face) */
104 cs_real_t *c_w_face_normal; /* Solid surface normal immersed in the cells.
105 (L2 norm equals area of the face) */
106 cs_real_3_t *i_face_cog; /* Center of gravity of interior faces */
107 cs_real_3_t *b_face_cog; /* Center of gravity of border faces */
108
109 cs_real_t *c_w_face_cog; /* Center of gravity of solid face
110 immersed in the cells */
111
112 cs_real_t *i_face_surf; /* Surface of interior faces. */
113 cs_real_t *b_face_surf; /* Surface of boundary faces. */
114
115 cs_real_t *c_w_face_surf; /* Solid surface of cells. */
116
117 cs_nreal_3_t *i_face_u_normal; /* Unit normal of interior faces. */
118 cs_nreal_3_t *b_face_u_normal; /* Unit normal of boundary faces. */
119
120 cs_real_2_t *i_f_face_factor; /* Fluid surface factor of interior faces. */
121 cs_real_t *b_f_face_factor; /* Fluid surface factor of boundary faces. */
122
123 cs_real_3_t *dijpf; /* Vector I'J' for interior faces */
124 cs_rreal_3_t *diipb; /* Vector II' for border faces */
125 cs_real_3_t *dofij; /* Vector OF for interior faces */
126 cs_rreal_3_t *diipf; /* Vector II' for interior faces */
127 cs_rreal_3_t *djjpf; /* Vector JJ' for interior faces */
128
129 cs_real_t *i_dist; /* Distance between the centers of the two
130 cells sharing an interior face */
131 cs_real_t *b_dist; /* Distance between the cell center and
132 the center of gravity of border faces */
133 cs_real_t *c_w_dist_inv; /* Distance between the centers of the cell
134 and the solid face */
135
136 cs_real_t *weight; /* Interior faces weighting factor */
137
138 cs_real_t min_vol; /* Minimum cell volume */
139 cs_real_t max_vol; /* Maximum cell volume */
140 cs_real_t tot_vol; /* Total volume */
141
142 cs_real_t *corr_grad_lin_det; /* Determinant of geometrical matrix
143 linear gradient correction */
144 cs_real_33_t *corr_grad_lin; /* Geometrical matrix
145 linear gradient correction */
146
147 int *b_sym_flag; /* Symmetry flag for boundary faces */
148 int has_disable_flag; /* Is the cell disabled?
149 0: unactivated
150 1: activated */
151 int *c_disable_flag; /* Is the cell disabled?
152 used for fluid solid and porous models */
153 unsigned *bad_cell_flag; /* Flag (mask) for bad cells detected */
154
156
157/*============================================================================
158 * Global variables
159 *============================================================================*/
160
161/* Pointers to mesh quantities structure associated to the main mesh */
164
165/* Flag (mask) to activate bad cells correction */
166extern unsigned cs_glob_mesh_quantities_flag;
167
168/*=============================================================================
169 * Templated inline functions
170 *============================================================================*/
171
173
174#if defined(__cplusplus)
175
176/*----------------------------------------------------------------------------*/
186/*----------------------------------------------------------------------------*/
187
190 const int *c_disable_flag,
191 const cs_real_t c_vol[])
192{
193 cs_real_t dvol;
194
195 if (c_disable_flag == nullptr)
196 dvol = 1. / c_vol[c_id];
197 else if (c_disable_flag[c_id] == 0)
198 dvol = 1. / c_vol[c_id];
199 else
200 dvol = 0.;
201
202 return dvol;
203}
204
205#endif // defined(__cplusplus)
206
208
209/*=============================================================================
210 * Public function prototypes
211 *============================================================================*/
212
213/*----------------------------------------------------------------------------*/
221/*----------------------------------------------------------------------------*/
222
223static inline int
225 cs_lnum_t cell_id)
226{
227 return (1 - (mq->has_disable_flag
228 *mq->c_disable_flag[mq->has_disable_flag * cell_id]));
229}
230
231/*----------------------------------------------------------------------------*/
241/*----------------------------------------------------------------------------*/
242
243int
245
246/*----------------------------------------------------------------------------*/
257/*----------------------------------------------------------------------------*/
258
259int
261
262/*----------------------------------------------------------------------------*/
268/*----------------------------------------------------------------------------*/
269
272
273/*----------------------------------------------------------------------------*/
281/*----------------------------------------------------------------------------*/
282
285
286/*----------------------------------------------------------------------------*/
292/*----------------------------------------------------------------------------*/
293
294void
296
297/*----------------------------------------------------------------------------*/
304/*----------------------------------------------------------------------------*/
305
306void
309
310/*----------------------------------------------------------------------------*/
317/*----------------------------------------------------------------------------*/
318
319void
322
323/*----------------------------------------------------------------------------
324 * Compute the total, min, and max volumes of cells
325 *
326 * parameters:
327 * mesh <-- pointer to mesh structure
328 * mesh_quantities <-> pointer to a mesh quantities structure
329 *----------------------------------------------------------------------------*/
330
331void
333 cs_mesh_quantities_t *mesh_quantities);
334
335/*----------------------------------------------------------------------------
336 * Compute fluid section mesh quantities at the initial step
337 *
338 * parameters:
339 * mesh <-- pointer to a cs_mesh_t structure
340 * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
341 *----------------------------------------------------------------------------*/
342
343void
345 cs_mesh_quantities_t *mesh_quantities);
346
347/*----------------------------------------------------------------------------*/
356/*----------------------------------------------------------------------------*/
357
358void
360 cs_real_3_t *cen_points,
362
363/*----------------------------------------------------------------------------
364 * Compute mesh quantities
365 *
366 * parameters:
367 * mesh <-- pointer to a cs_mesh_t structure
368 * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
369 *----------------------------------------------------------------------------*/
370
371void
373 cs_mesh_quantities_t *mesh_quantities);
374
375/*----------------------------------------------------------------------------
376 * Compute internal and border face normal.
377 *
378 * parameters:
379 * mesh <-- pointer to a cs_mesh_t structure
380 * p_i_face_normal <-> pointer to the internal face normal array
381 * p_b_face_normal <-> pointer to the border face normal array
382 *----------------------------------------------------------------------------*/
383
384void
386 cs_real_t *p_i_face_normal[],
387 cs_real_t *p_b_face_normal[]);
388
389/*----------------------------------------------------------------------------
390 * Compute center of gravity and surface normal associated to a set of faces
391 *
392 * parameters:
393 * n_faces <-- number of faces
394 * vtx_coord <-- vertex coordinates
395 * face_vtx_idx <-- "face -> vertices" connectivity index
396 * face_vtx <-- "face -> vertices" connectivity
397 * face_cog --> coordinates of the center of gravity of the faces
398 * face_normal --> face surface normals
399 *----------------------------------------------------------------------------*/
400
401void
403 const cs_real_t vtx_coord[][3],
404 const cs_lnum_t face_vtx_idx[],
405 const cs_lnum_t face_vtx[],
406 cs_real_t face_cog[][3],
407 cs_real_t face_normal[][3]);
408
409/*----------------------------------------------------------------------------
410 * Compute center of gravity and unit normal associated to a set of faces
411 *
412 * parameters:
413 * n_faces <-- number of faces
414 * vtx_coord <-- vertex coordinates
415 * face_vtx_idx <-- "face -> vertices" connectivity index
416 * face_vtx <-- "face -> vertices" connectivity
417 * face_cog --> coordinates of the center of gravity of the faces
418 * face_u_normal --> face unit normals
419 *----------------------------------------------------------------------------*/
420
421void
423 const cs_real_t vtx_coord[][3],
424 const cs_lnum_t face_vtx_idx[],
425 const cs_lnum_t face_vtx[],
426 cs_real_t face_cog[][3],
427 cs_nreal_t face_u_normal[][3]);
428
429/*----------------------------------------------------------------------------
430 * Compute border face centers and normals.
431 *
432 * Deprecated: use cs_mesh_quantities_compute_face_cog_sn or
433 * cs_mesh_quantities_compute_face_cog_un instead.
434 *
435 * The corresponding arrays are allocated by this function, and it is the
436 * caller's responsibility to free them when they are no longer needed.
437 *
438 * parameters:
439 * mesh <-- pointer to a cs_mesh_t structure
440 * p_b_face_cog <-> pointer to the border face center array
441 * p_b_face_normal <-> pointer to the border face normal array
442 *----------------------------------------------------------------------------*/
443
444void
446 cs_real_t *p_b_face_cog[],
447 cs_real_t *p_b_face_normal[]);
448
449/*----------------------------------------------------------------------------*/
469/*----------------------------------------------------------------------------*/
470
471void
473 const cs_real_3_t i_face_norm[],
474 const cs_real_3_t i_face_cog[],
475 const cs_real_3_t b_face_norm[],
476 const cs_real_3_t b_face_cog[],
477 cs_real_3_t cell_cen[]);
478
479/*----------------------------------------------------------------------------
480 * Compute cell volumes.
481 *
482 * The corresponding array is allocated by this function, and it is the
483 * caller's responsability to free it when they are no longer needed.
484 *
485 * parameters:
486 * mesh <-- pointer to a cs_mesh_t structure
487 *
488 * return:
489 * pointer to newly allocated cell volumes array
490 *----------------------------------------------------------------------------*/
491
492cs_real_t *
494
495/*----------------------------------------------------------------------------
496 * Check that no negative volumes are present, and exit on error otherwise.
497 *
498 * parameters:
499 * mesh <-- pointer to mesh structure
500 * mesh_quantities <-- pointer to mesh quantities structure
501 * allow_error <-- 1 if errors are allowed, 0 otherwise
502 *----------------------------------------------------------------------------*/
503
504void
506 const cs_mesh_quantities_t *mesh_quantities,
507 int allow_error);
508
509/*----------------------------------------------------------------------------*/
522/*----------------------------------------------------------------------------*/
523
526 cs_real_t tolerance);
527
528/*----------------------------------------------------------------------------
529 * Return the number of times mesh quantities have been computed.
530 *
531 * returns:
532 * number of times mesh quantities have been computed
533 *----------------------------------------------------------------------------*/
534
535int
537
538/*----------------------------------------------------------------------------*/
548/*----------------------------------------------------------------------------*/
549
550void
552 const cs_mesh_quantities_t *mq,
553 int n_passes,
554 cs_real_t b_thickness[]);
555
556/*----------------------------------------------------------------------------*/
565/*----------------------------------------------------------------------------*/
566
567void
569 const cs_mesh_quantities_t *mq,
570 int n_passes,
571 cs_real_t b_thickness[]);
572
573/*----------------------------------------------------------------------------*/
577/*----------------------------------------------------------------------------*/
578
579void
581
582/*----------------------------------------------------------------------------
583 * Dump a cs_mesh_quantities_t structure
584 *
585 * parameters:
586 * mesh <-- pointer to a cs_mesh_t structure
587 * mesh_quantities <-- pointer to a cs_mesh_quantities_t structure
588 *----------------------------------------------------------------------------*/
589
590void
592 const cs_mesh_quantities_t *mesh_quantities);
593
594/*----------------------------------------------------------------------------*/
595
597
598#endif /* CS_MESH_QUANTITIES_H */
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:585
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
cs_rreal_t cs_rreal_3_t[3]
Definition: cs_defs.h:403
cs_nreal_t cs_nreal_3_t[3]
Definition: cs_defs.h:400
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:374
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition: cs_defs.h:373
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:376
#define END_C_DECLS
Definition: cs_defs.h:555
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:383
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
double cs_nreal_t
Definition: cs_defs.h:361
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:4897
void cs_mesh_quantities_sup_vectors(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.cpp:4815
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:2747
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:4850
void cs_mesh_quantities_log_setup(void)
Log mesh quantities options to setup file.
Definition: cs_mesh_quantities.cpp:5493
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:224
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:2818
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:5451
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:4926
int cs_mesh_quantities_compute_count(void)
Definition: cs_mesh_quantities.cpp:5343
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:189
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:5197
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:5003
void cs_mesh_quantities_vol_reductions(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.cpp:4727
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:2655
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:2677
void cs_mesh_init_fluid_sections(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.cpp:4767
void cs_mesh_quantities_compute(const cs_mesh_t *m, cs_mesh_quantities_t *mq)
Compute mesh quantities.
Definition: cs_mesh_quantities.cpp:4545
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:2765
void cs_mesh_quantities_dump(const cs_mesh_t *mesh, const cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.cpp:5538
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:2694
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:5361
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:5255
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:3068
cs_real_t * cs_mesh_quantities_cell_volume(const cs_mesh_t *mesh)
Definition: cs_mesh_quantities.cpp:5136
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:4959
Definition: mesh.f90:26
Definition: cs_mesh_quantities.h:92
int * b_sym_flag
Definition: cs_mesh_quantities.h:147
cs_real_3_t * b_face_cog
Definition: cs_mesh_quantities.h:107
cs_real_t * c_w_face_surf
Definition: cs_mesh_quantities.h:115
cs_real_t * i_face_surf
Definition: cs_mesh_quantities.h:112
cs_rreal_3_t * diipb
Definition: cs_mesh_quantities.h:124
cs_real_t * b_dist
Definition: cs_mesh_quantities.h:131
int has_disable_flag
Definition: cs_mesh_quantities.h:148
cs_real_3_t * cell_cen
Definition: cs_mesh_quantities.h:94
cs_real_2_t * i_f_face_factor
Definition: cs_mesh_quantities.h:120
cs_real_3_t * dofij
Definition: cs_mesh_quantities.h:125
cs_rreal_3_t * diipf
Definition: cs_mesh_quantities.h:126
cs_real_3_t * cell_s_cen
Definition: cs_mesh_quantities.h:95
cs_real_t * b_face_surf
Definition: cs_mesh_quantities.h:113
cs_real_t * i_dist
Definition: cs_mesh_quantities.h:129
cs_real_3_t * i_face_cog
Definition: cs_mesh_quantities.h:106
cs_real_t * c_w_face_normal
Definition: cs_mesh_quantities.h:104
cs_real_t max_vol
Definition: cs_mesh_quantities.h:139
cs_real_t * cell_vol
Definition: cs_mesh_quantities.h:97
cs_real_t * weight
Definition: cs_mesh_quantities.h:136
cs_real_t * _cell_vol
Definition: cs_mesh_quantities.h:98
cs_real_t * b_face_normal
Definition: cs_mesh_quantities.h:102
cs_real_33_t * corr_grad_lin
Definition: cs_mesh_quantities.h:144
cs_real_t * c_w_face_cog
Definition: cs_mesh_quantities.h:109
cs_real_t tot_vol
Definition: cs_mesh_quantities.h:140
int * c_disable_flag
Definition: cs_mesh_quantities.h:151
cs_nreal_3_t * i_face_u_normal
Definition: cs_mesh_quantities.h:117
cs_real_t * b_f_face_factor
Definition: cs_mesh_quantities.h:121
cs_real_t min_vol
Definition: cs_mesh_quantities.h:138
cs_real_t * c_w_dist_inv
Definition: cs_mesh_quantities.h:133
cs_nreal_3_t * b_face_u_normal
Definition: cs_mesh_quantities.h:118
cs_real_t * corr_grad_lin_det
Definition: cs_mesh_quantities.h:142
cs_real_t * i_face_normal
Definition: cs_mesh_quantities.h:100
cs_real_3_t * dijpf
Definition: cs_mesh_quantities.h:123
unsigned * bad_cell_flag
Definition: cs_mesh_quantities.h:153
cs_rreal_3_t * djjpf
Definition: cs_mesh_quantities.h:127
Definition: cs_mesh.h:85