9.0
general documentation
Loading...
Searching...
No Matches
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
50
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
85
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 cs_real_t *cell_vol; /* Cell volume */
97
98 cs_real_t *i_face_normal; /* Surface normal of interior faces.
99 (L2 norm equals area of the face) */
100 cs_real_t *b_face_normal; /* Surface normal of border faces.
101 (L2 norm equals area of the face) */
102 cs_real_t *c_w_face_normal; /* Solid surface normal immersed in the cells.
103 (L2 norm equals area of the face) */
104 cs_real_3_t *i_face_cog; /* Center of gravity of interior faces */
105 cs_real_3_t *b_face_cog; /* Center of gravity of border faces */
106
107 cs_real_t *c_w_face_cog; /* Center of gravity of solid face
108 immersed in the cells */
109
110 cs_real_t *i_face_surf; /* Surface of interior faces. */
111 cs_real_t *b_face_surf; /* Surface of boundary faces. */
112
113 cs_real_t *c_w_face_surf; /* Solid surface of cells. */
114
115 cs_nreal_3_t *i_face_u_normal; /* Unit normal of interior faces. */
116 cs_nreal_3_t *b_face_u_normal; /* Unit normal of boundary faces. */
117
118 cs_real_2_t *i_f_face_factor; /* Fluid surface factor of interior faces. */
119 cs_real_t *b_f_face_factor; /* Fluid surface factor of boundary faces. */
120
121 cs_real_3_t *dijpf; /* Vector I'J' for interior faces */
122 cs_rreal_3_t *diipb; /* Vector II' for border faces */
123 cs_real_3_t *dofij; /* Vector OF for interior faces */
124 cs_rreal_3_t *diipf; /* Vector II' for interior faces */
125 cs_rreal_3_t *djjpf; /* Vector JJ' for interior faces */
126
127 cs_real_t *i_dist; /* Distance between the centers of the two
128 cells sharing an interior face */
129 cs_real_t *b_dist; /* Distance between the cell center and
130 the center of gravity of border faces */
131 cs_real_t *c_w_dist_inv; /* Distance between the centers of the cell
132 and the solid face */
133
134 cs_real_t *weight; /* Interior faces weighting factor */
135
136 cs_real_t min_vol; /* Minimum cell volume */
137 cs_real_t max_vol; /* Maximum cell volume */
138 cs_real_t tot_vol; /* Total volume */
139
140 cs_real_t *corr_grad_lin_det; /* Determinant of geometrical matrix
141 linear gradient correction */
142 cs_real_33_t *corr_grad_lin; /* Geometrical matrix
143 linear gradient correction */
144
145 int *b_sym_flag; /* Symmetry flag for boundary faces */
146 int has_disable_flag; /* Is the cell disabled?
147 0: unactivated
148 1: activated */
149 int *c_disable_flag; /* Is the cell disabled?
150 used for fluid solid and porous models */
151 unsigned *bad_cell_flag; /* Flag (mask) for bad cells detected */
152
154
155/*============================================================================
156 * Global variables
157 *============================================================================*/
158
159/* Pointers to mesh quantities structure associated to the main mesh */
162
163/* Flag (mask) to activate bad cells correction */
164extern unsigned cs_glob_mesh_quantities_flag;
165
166/*=============================================================================
167 * Templated inline functions
168 *============================================================================*/
169
171
172#if defined(__cplusplus)
173
174/*----------------------------------------------------------------------------*/
184/*----------------------------------------------------------------------------*/
185
187cs_mq_cell_vol_inv(cs_lnum_t c_id,
188 const int *c_disable_flag,
189 const cs_real_t c_vol[])
190{
191 cs_real_t dvol;
192
193 if (c_disable_flag == nullptr)
194 dvol = 1. / c_vol[c_id];
195 else if (c_disable_flag[c_id] == 0)
196 dvol = 1. / c_vol[c_id];
197 else
198 dvol = 0.;
199
200 return dvol;
201}
202
203#endif // defined(__cplusplus)
204
206
207/*=============================================================================
208 * Public function prototypes
209 *============================================================================*/
210
211/*----------------------------------------------------------------------------*/
219/*----------------------------------------------------------------------------*/
220
221static inline int
223 cs_lnum_t cell_id)
224{
225 return (1 - (mq->has_disable_flag
226 *mq->c_disable_flag[mq->has_disable_flag * cell_id]));
227}
228
229/*----------------------------------------------------------------------------*/
239/*----------------------------------------------------------------------------*/
240
241int
243
244/*----------------------------------------------------------------------------*/
255/*----------------------------------------------------------------------------*/
256
257int
259
260/*----------------------------------------------------------------------------*/
266/*----------------------------------------------------------------------------*/
267
270
271/*----------------------------------------------------------------------------*/
279/*----------------------------------------------------------------------------*/
280
283
284/*----------------------------------------------------------------------------*/
290/*----------------------------------------------------------------------------*/
291
292void
294
295/*----------------------------------------------------------------------------*/
302/*----------------------------------------------------------------------------*/
303
304void
307
308/*----------------------------------------------------------------------------*/
315/*----------------------------------------------------------------------------*/
316
317void
320
321/*----------------------------------------------------------------------------
322 * Compute the total, min, and max volumes of cells
323 *
324 * parameters:
325 * mesh <-- pointer to mesh structure
326 * mesh_quantities <-> pointer to a mesh quantities structure
327 *----------------------------------------------------------------------------*/
328
329void
331 cs_mesh_quantities_t *mesh_quantities);
332
333/*----------------------------------------------------------------------------
334 * Compute fluid section mesh quantities at the initial step
335 *
336 * parameters:
337 * mesh <-- pointer to a cs_mesh_t structure
338 * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
339 *----------------------------------------------------------------------------*/
340
341void
343 cs_mesh_quantities_t *mesh_quantities);
344
345/*----------------------------------------------------------------------------*/
354/*----------------------------------------------------------------------------*/
355
356void
358 const cs_real_3_t *cen_points,
360
361/*----------------------------------------------------------------------------
362 * Compute mesh quantities
363 *
364 * parameters:
365 * mesh <-- pointer to a cs_mesh_t structure
366 * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
367 *----------------------------------------------------------------------------*/
368
369void
371 cs_mesh_quantities_t *mesh_quantities);
372
373/*----------------------------------------------------------------------------
374 * Compute internal and border face normal.
375 *
376 * parameters:
377 * mesh <-- pointer to a cs_mesh_t structure
378 * p_i_face_normal <-> pointer to the internal face normal array
379 * p_b_face_normal <-> pointer to the border face normal array
380 *----------------------------------------------------------------------------*/
381
382void
384 cs_real_t *p_i_face_normal[],
385 cs_real_t *p_b_face_normal[]);
386
387/*----------------------------------------------------------------------------
388 * Compute interior face centers and normals.
389 *
390 * The corresponding arrays are allocated by this function, and it is the
391 * caller's responsibility to free them when they are no longer needed.
392 *
393 * parameters:
394 * mesh <-- pointer to a cs_mesh_t structure
395 * p_i_face_cog <-> pointer to the interior face center array
396 * p_i_face_normal <-> pointer to the interior face normal array
397 *----------------------------------------------------------------------------*/
398
399void
401 cs_real_t *p_i_face_cog[],
402 cs_real_t *p_i_face_normal[]);
403
404/*----------------------------------------------------------------------------
405 * Compute border face centers and normals.
406 *
407 * The corresponding arrays are allocated by this function, and it is the
408 * caller's responsibility to free them when they are no longer needed.
409 *
410 * parameters:
411 * mesh <-- pointer to a cs_mesh_t structure
412 * p_b_face_cog <-> pointer to the border face center array
413 * p_b_face_normal <-> pointer to the border face normal array
414 *----------------------------------------------------------------------------*/
415
416void
418 cs_real_t *p_b_face_cog[],
419 cs_real_t *p_b_face_normal[]);
420
421/*----------------------------------------------------------------------------*/
441/*----------------------------------------------------------------------------*/
442
443void
445 const cs_real_t i_face_norm[],
446 const cs_real_t i_face_cog[],
447 const cs_real_t b_face_norm[],
448 const cs_real_t b_face_cog[],
449 cs_real_t cell_cen[]);
450
451/*----------------------------------------------------------------------------
452 * Compute cell volumes.
453 *
454 * The corresponding array is allocated by this function, and it is the
455 * caller's responsability to free it when they are no longer needed.
456 *
457 * parameters:
458 * mesh <-- pointer to a cs_mesh_t structure
459 *
460 * return:
461 * pointer to newly allocated cell volumes array
462 *----------------------------------------------------------------------------*/
463
464cs_real_t *
466
467/*----------------------------------------------------------------------------
468 * Check that no negative volumes are present, and exit on error otherwise.
469 *
470 * parameters:
471 * mesh <-- pointer to mesh structure
472 * mesh_quantities <-- pointer to mesh quantities structure
473 * allow_error <-- 1 if errors are allowed, 0 otherwise
474 *----------------------------------------------------------------------------*/
475
476void
478 const cs_mesh_quantities_t *mesh_quantities,
479 int allow_error);
480
481/*----------------------------------------------------------------------------*/
494/*----------------------------------------------------------------------------*/
495
498 cs_real_t tolerance);
499
500/*----------------------------------------------------------------------------
501 * Return the number of times mesh quantities have been computed.
502 *
503 * returns:
504 * number of times mesh quantities have been computed
505 *----------------------------------------------------------------------------*/
506
507int
509
510/*----------------------------------------------------------------------------*/
520/*----------------------------------------------------------------------------*/
521
522void
524 const cs_mesh_quantities_t *mq,
525 int n_passes,
526 cs_real_t b_thickness[]);
527
528/*----------------------------------------------------------------------------*/
537/*----------------------------------------------------------------------------*/
538
539void
541 const cs_mesh_quantities_t *mq,
542 int n_passes,
543 cs_real_t b_thickness[]);
544
545/*----------------------------------------------------------------------------
546 * Compute quantities associated to a list of faces (border or internal)
547 *
548 * parameters:
549 * n_faces <-- number of faces
550 * vtx_coord <-- vertex coordinates
551 * face_vtx_idx <-- "face -> vertices" connectivity index
552 * face_vtx <-- "face -> vertices" connectivity
553 * face_cog --> coordinates of the center of gravity of the faces
554 * face_normal --> face surface normals
555 *----------------------------------------------------------------------------*/
556
557void
559 const cs_real_t vtx_coord[][3],
560 const cs_lnum_t face_vtx_idx[],
561 const cs_lnum_t face_vtx[],
562 cs_real_t face_cog[][3],
563 cs_real_t face_normal[][3]);
564
565/*----------------------------------------------------------------------------*/
569/*----------------------------------------------------------------------------*/
570
571void
573
574/*----------------------------------------------------------------------------
575 * Dump a cs_mesh_quantities_t structure
576 *
577 * parameters:
578 * mesh <-- pointer to a cs_mesh_t structure
579 * mesh_quantities <-- pointer to a cs_mesh_quantities_t structure
580 *----------------------------------------------------------------------------*/
581
582void
584 const cs_mesh_quantities_t *mesh_quantities);
585
586/*----------------------------------------------------------------------------*/
587
589
590#endif /* __CS_MESH_QUANTITIES_H__ */
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition cs_defs.h:368
#define BEGIN_C_DECLS
Definition cs_defs.h:542
#define CS_F_HOST_DEVICE
Definition cs_defs.h:561
cs_rreal_t cs_rreal_3_t[3]
Definition cs_defs.h:388
cs_nreal_t cs_nreal_3_t[3]
Definition cs_defs.h:385
double cs_real_t
Floating-point value.
Definition cs_defs.h:342
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition cs_defs.h:358
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_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition cs_defs.h:359
void cs_mesh_quantities_sup_vectors(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition cs_mesh_quantities.cpp:4709
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:2953
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:4744
void cs_mesh_quantities_log_setup(void)
Log mesh quantities options to setup file.
Definition cs_mesh_quantities.cpp:5366
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:222
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:3023
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:5296
void cs_mesh_quantities_solid_compute(const cs_mesh_t *m, const 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:3254
int cs_mesh_quantities_compute_count(void)
Definition cs_mesh_quantities.cpp:5188
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:5042
void cs_mesh_quantities_vol_reductions(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition cs_mesh_quantities.cpp:4621
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:2862
void cs_mesh_quantities_cell_faces_cog(const cs_mesh_t *mesh, const cs_real_t i_face_norm[], const cs_real_t i_face_cog[], const cs_real_t b_face_norm[], const cs_real_t b_face_cog[], cs_real_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:4867
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:2884
void cs_mesh_init_fluid_sections(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition cs_mesh_quantities.cpp:4661
void cs_mesh_quantities_compute(const cs_mesh_t *m, cs_mesh_quantities_t *mq)
Compute mesh quantities.
Definition cs_mesh_quantities.cpp:4455
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:2971
void cs_mesh_quantities_compute_face_quantities(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:5344
void cs_mesh_quantities_dump(const cs_mesh_t *mesh, const cs_mesh_quantities_t *mesh_quantities)
Definition cs_mesh_quantities.cpp:5411
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:2901
void cs_mesh_quantities_i_faces(const cs_mesh_t *mesh, cs_real_t *p_i_face_cog[], cs_real_t *p_i_face_normal[])
Definition cs_mesh_quantities.cpp:4791
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:5206
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:5100
cs_real_t * cs_mesh_quantities_cell_volume(const cs_mesh_t *mesh)
Definition cs_mesh_quantities.cpp:5001
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[])
Definition cs_mesh_quantities.cpp:4824
Definition mesh.f90:26
Definition cs_mesh_quantities.h:92
int * b_sym_flag
Definition cs_mesh_quantities.h:145
cs_real_3_t * b_face_cog
Definition cs_mesh_quantities.h:105
cs_real_t * c_w_face_surf
Definition cs_mesh_quantities.h:113
cs_real_t * i_face_surf
Definition cs_mesh_quantities.h:110
cs_rreal_3_t * diipb
Definition cs_mesh_quantities.h:122
cs_real_t * b_dist
Definition cs_mesh_quantities.h:129
int has_disable_flag
Definition cs_mesh_quantities.h:146
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:118
cs_real_3_t * dofij
Definition cs_mesh_quantities.h:123
cs_rreal_3_t * diipf
Definition cs_mesh_quantities.h:124
cs_real_3_t * cell_s_cen
Definition cs_mesh_quantities.h:95
cs_real_t * b_face_surf
Definition cs_mesh_quantities.h:111
cs_real_t * i_dist
Definition cs_mesh_quantities.h:127
cs_real_3_t * i_face_cog
Definition cs_mesh_quantities.h:104
cs_real_t * c_w_face_normal
Definition cs_mesh_quantities.h:102
cs_real_t max_vol
Definition cs_mesh_quantities.h:137
cs_real_t * cell_vol
Definition cs_mesh_quantities.h:96
cs_real_t * weight
Definition cs_mesh_quantities.h:134
cs_real_t * b_face_normal
Definition cs_mesh_quantities.h:100
cs_real_33_t * corr_grad_lin
Definition cs_mesh_quantities.h:142
cs_real_t * c_w_face_cog
Definition cs_mesh_quantities.h:107
cs_real_t tot_vol
Definition cs_mesh_quantities.h:138
int * c_disable_flag
Definition cs_mesh_quantities.h:149
cs_nreal_3_t * i_face_u_normal
Definition cs_mesh_quantities.h:115
cs_real_t * b_f_face_factor
Definition cs_mesh_quantities.h:119
cs_real_t min_vol
Definition cs_mesh_quantities.h:136
cs_real_t * c_w_dist_inv
Definition cs_mesh_quantities.h:131
cs_nreal_3_t * b_face_u_normal
Definition cs_mesh_quantities.h:116
cs_real_t * corr_grad_lin_det
Definition cs_mesh_quantities.h:140
cs_real_t * i_face_normal
Definition cs_mesh_quantities.h:98
cs_real_3_t * dijpf
Definition cs_mesh_quantities.h:121
unsigned * bad_cell_flag
Definition cs_mesh_quantities.h:151
cs_rreal_3_t * djjpf
Definition cs_mesh_quantities.h:125
Definition cs_mesh.h:85