8.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-2023 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_base.h"
35 #include "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 
92 typedef struct {
93 
94  cs_real_t *cell_cen; /* Cell center coordinates */
95  cs_real_t *cell_f_cen; /* Cell fluid center coordinates */
96  cs_real_t *cell_s_cen; /* Cell solid center coordinates */
97  cs_real_t *cell_vol; /* Cell volume */
98  cs_real_t *cell_f_vol; /* Cell fluid volume */
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 *i_f_face_normal;/* Fluid surface normal of interior faces.
105  (L2 norm equals area of the face) */
106  cs_real_t *b_f_face_normal;/* Fluid surface normal of border faces.
107  (L2 norm equals area of the face) */
108  cs_real_t *c_w_face_normal;/* Solid surface normal immersed in the cells.
109  (L2 norm equals area of the face) */
110  cs_real_t *i_face_cog; /* Center of gravity of interior faces */
111  cs_real_t *b_face_cog; /* Center of gravity of border faces */
112 
113  cs_real_t *b_f_face_cog; /* Center of gravity of fluid border faces */
114  cs_real_t *c_w_face_cog; /* Center of gravity of solid face
115  immersed in the cells */
116 
117  cs_real_t *i_face_surf; /* Surface of interior faces. */
118  cs_real_t *b_face_surf; /* Surface of boundary faces. */
119 
120  cs_real_t *i_f_face_surf; /* Fluid surface of interior faces. */
121  cs_real_t *b_f_face_surf; /* Fluid surface of boundary faces. */
122  cs_real_t *c_w_face_surf; /* Solid surface of cells. */
123 
124  cs_nreal_3_t *i_face_u_normal; /* Unit normal of interior faces. */
125  cs_nreal_3_t *b_face_u_normal; /* Unit normal of boundary faces. */
126 
127  cs_real_2_t *i_f_face_factor;/* Fluid surface factor of interior faces. */
128  cs_real_t *b_f_face_factor;/* Fluid surface factor of boundary faces. */
129 
130  cs_real_t *dijpf; /* Vector I'J' for interior faces */
131  cs_real_t *diipb; /* Vector II' for border faces */
132  cs_real_t *dofij; /* Vector OF for interior faces */
133  cs_real_t *diipf; /* Vector II' for interior faces */
134  cs_real_t *djjpf; /* Vector JJ' for interior faces */
135 
136  cs_real_t *i_dist; /* Distance between the centers of the two
137  cells sharing an interior face */
138  cs_real_t *b_dist; /* Distance between the cell center and
139  the center of gravity of border faces */
140  cs_real_t *c_w_dist_inv; /* Distance between the centers of the cell
141  and the solid face */
142 
143  cs_real_t *weight; /* Interior faces weighting factor */
144  cs_real_t *i_f_weight; /* Interior faces weighting factor
145  with new cell center of gravity */
146 
147  cs_real_t min_vol; /* Minimum cell volume */
148  cs_real_t max_vol; /* Maximum cell volume */
149  cs_real_t tot_vol; /* Total volume */
150 
151  cs_real_t min_f_vol; /* Minimum cell volume */
152  cs_real_t max_f_vol; /* Maximum cell volume */
153  cs_real_t tot_f_vol; /* Total volume */
154 
155  cs_real_t *corr_grad_lin_det; /* Determinant of geometrical matrix
156  linear gradient correction */
157  cs_real_33_t *corr_grad_lin; /* Geometrical matrix
158  linear gradient correction */
159 
160  int *b_sym_flag; /* Symmetry flag for boundary faces */
161  int has_disable_flag; /* Is the cell disabled?
162  0: unactivated
163  1: activated */
164  int *c_disable_flag; /* Is the cell disabled?
165  used for fluid solid and porous models */
166  unsigned *bad_cell_flag; /* Flag (mask) for bad cells detected */
167 
169 
170 /*============================================================================
171  * Global variables
172  *============================================================================*/
173 
174 /* Pointer to mesh quantities structure associated to the main mesh */
175 
177 
178 /* Flag (mask) to activate bad cells correction */
179 extern unsigned cs_glob_mesh_quantities_flag;
180 
181 /*=============================================================================
182  * Public function prototypes
183  *============================================================================*/
184 
185 /*----------------------------------------------------------------------------*/
193 /*----------------------------------------------------------------------------*/
194 
195 static inline int
197  cs_lnum_t cell_id)
198 {
199  return (1 - (mq->has_disable_flag
200  *mq->c_disable_flag[mq->has_disable_flag * cell_id]));
201 }
202 
203 /*----------------------------------------------------------------------------*/
213 /*----------------------------------------------------------------------------*/
214 
215 int
216 cs_mesh_quantities_cell_cen_choice(int algo_choice);
217 
218 /*----------------------------------------------------------------------------*/
229 /*----------------------------------------------------------------------------*/
230 
231 int
232 cs_mesh_quantities_face_cog_choice(int algo_choice);
233 
234 /*----------------------------------------------------------------------------*/
240 /*----------------------------------------------------------------------------*/
241 
244 
245 /*----------------------------------------------------------------------------*/
253 /*----------------------------------------------------------------------------*/
254 
257 
258 /*----------------------------------------------------------------------------*/
264 /*----------------------------------------------------------------------------*/
265 
266 void
268 
269 /*----------------------------------------------------------------------------*/
276 /*----------------------------------------------------------------------------*/
277 
278 void
281 
282 /*----------------------------------------------------------------------------*/
289 /*----------------------------------------------------------------------------*/
290 
291 void
294 
295 /*----------------------------------------------------------------------------
296  * Compute fluid mesh quantities
297  *
298  * parameters:
299  * mesh <-- pointer to a cs_mesh_t structure
300  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
301  *----------------------------------------------------------------------------*/
302 
303 void
305  cs_mesh_quantities_t *mesh_quantities);
306 
307 /*----------------------------------------------------------------------------
308  * Compute the total, min, and max fluid volumes of cells
309  *
310  * parameters:
311  * mesh <-- pointer to mesh structure
312  * mesh_quantities <-> pointer to a mesh quantities structure
313  *----------------------------------------------------------------------------*/
314 
315 void
317  cs_mesh_quantities_t *mesh_quantities);
318 
319 /*----------------------------------------------------------------------------
320  * Compute fluid section mesh quantities at the initial step
321  *
322  * parameters:
323  * mesh <-- pointer to a cs_mesh_t structure
324  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
325  *----------------------------------------------------------------------------*/
326 
327 void
329  cs_mesh_quantities_t *mesh_quantities);
330 
331 /*----------------------------------------------------------------------------*/
340 /*----------------------------------------------------------------------------*/
341 
342 void
344  const cs_real_3_t *cen_points,
346 
347 /*----------------------------------------------------------------------------
348  * Compute mesh quantities
349  *
350  * parameters:
351  * mesh <-- pointer to a cs_mesh_t structure
352  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
353  *----------------------------------------------------------------------------*/
354 
355 void
357  cs_mesh_quantities_t *mesh_quantities);
358 
359 /*----------------------------------------------------------------------------
360  * Compute internal and border face normal.
361  *
362  * parameters:
363  * mesh <-- pointer to a cs_mesh_t structure
364  * p_i_face_normal <-> pointer to the internal face normal array
365  * p_b_face_normal <-> pointer to the border face normal array
366  *----------------------------------------------------------------------------*/
367 
368 void
370  cs_real_t *p_i_face_normal[],
371  cs_real_t *p_b_face_normal[]);
372 
373 /*----------------------------------------------------------------------------
374  * Compute interior face centers and normals.
375  *
376  * The corresponding arrays are allocated by this function, and it is the
377  * caller's responsibility to free them when they are no longer needed.
378  *
379  * parameters:
380  * mesh <-- pointer to a cs_mesh_t structure
381  * p_i_face_cog <-> pointer to the interior face center array
382  * p_i_face_normal <-> pointer to the interior face normal array
383  *----------------------------------------------------------------------------*/
384 
385 void
387  cs_real_t *p_i_face_cog[],
388  cs_real_t *p_i_face_normal[]);
389 
390 /*----------------------------------------------------------------------------
391  * Compute border face centers and normals.
392  *
393  * The corresponding arrays are allocated by this function, and it is the
394  * caller's responsibility to free them when they are no longer needed.
395  *
396  * parameters:
397  * mesh <-- pointer to a cs_mesh_t structure
398  * p_b_face_cog <-> pointer to the border face center array
399  * p_b_face_normal <-> pointer to the border face normal array
400  *----------------------------------------------------------------------------*/
401 
402 void
404  cs_real_t *p_b_face_cog[],
405  cs_real_t *p_b_face_normal[]);
406 
407 /*----------------------------------------------------------------------------*/
427 /*----------------------------------------------------------------------------*/
428 
429 void
431  const cs_real_t i_face_norm[],
432  const cs_real_t i_face_cog[],
433  const cs_real_t b_face_norm[],
434  const cs_real_t b_face_cog[],
435  cs_real_t cell_cen[]);
436 
437 /*----------------------------------------------------------------------------
438  * Compute cell volumes.
439  *
440  * The corresponding array is allocated by this function, and it is the
441  * caller's responsability to free it when they are no longer needed.
442  *
443  * parameters:
444  * mesh <-- pointer to a cs_mesh_t structure
445  *
446  * return:
447  * pointer to newly allocated cell volumes array
448  *----------------------------------------------------------------------------*/
449 
450 cs_real_t *
452 
453 /*----------------------------------------------------------------------------
454  * Check that no negative volumes are present, and exit on error otherwise.
455  *
456  * parameters:
457  * mesh <-- pointer to mesh structure
458  * mesh_quantities <-- pointer to mesh quantities structure
459  * allow_error <-- 1 if errors are allowed, 0 otherwise
460  *----------------------------------------------------------------------------*/
461 
462 void
464  const cs_mesh_quantities_t *mesh_quantities,
465  int allow_error);
466 
467 /*----------------------------------------------------------------------------*/
480 /*----------------------------------------------------------------------------*/
481 
482 cs_real_6_t *
484  cs_real_t tolerance);
485 
486 /*----------------------------------------------------------------------------
487  * Return the number of times mesh quantities have been computed.
488  *
489  * returns:
490  * number of times mesh quantities have been computed
491  *----------------------------------------------------------------------------*/
492 
493 int
495 
496 /*----------------------------------------------------------------------------*/
506 /*----------------------------------------------------------------------------*/
507 
508 void
510  const cs_mesh_quantities_t *mq,
511  int n_passes,
512  cs_real_t b_thickness[]);
513 
514 /*----------------------------------------------------------------------------*/
523 /*----------------------------------------------------------------------------*/
524 
525 void
527  const cs_mesh_quantities_t *mq,
528  int n_passes,
529  cs_real_t b_thickness[]);
530 
531 /*----------------------------------------------------------------------------*/
535 /*----------------------------------------------------------------------------*/
536 
537 void
539 
540 /*----------------------------------------------------------------------------
541  * Dump a cs_mesh_quantities_t structure
542  *
543  * parameters:
544  * mesh <-- pointer to a cs_mesh_t structure
545  * mesh_quantities <-- pointer to a cs_mesh_quantities_t structure
546  *----------------------------------------------------------------------------*/
547 
548 void
550  const cs_mesh_quantities_t *mesh_quantities);
551 
552 /*----------------------------------------------------------------------------*/
553 
555 
556 #endif /* __CS_MESH_QUANTITIES_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:514
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
cs_nreal_t cs_nreal_3_t[3]
Definition: cs_defs.h:360
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:334
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition: cs_defs.h:333
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:336
#define END_C_DECLS
Definition: cs_defs.h:515
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:343
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
void cs_mesh_quantities_sup_vectors(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:4602
unsigned cs_glob_mesh_quantities_flag
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.c:4637
void cs_mesh_quantities_log_setup(void)
Log mesh quantities options to setup file.
Definition: cs_mesh_quantities.c:5231
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:196
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.c:3053
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.c:5189
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.c:4993
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.c:3291
int cs_mesh_quantities_compute_count(void)
Definition: cs_mesh_quantities.c:5081
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.c:4935
cs_mesh_quantities_t * cs_mesh_quantities_create(void)
Create a mesh quantities structure.
Definition: cs_mesh_quantities.c:2917
int cs_mesh_quantities_cell_cen_choice(int algo_choice)
Query or modification of the option for computing cell centers.
Definition: cs_mesh_quantities.c:2878
cs_real_t * cs_mesh_quantities_cell_volume(const cs_mesh_t *mesh)
Definition: cs_mesh_quantities.c:4894
void cs_mesh_quantities_fluid_compute(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:4500
void cs_mesh_quantities_fluid_vol_reductions(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:4516
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.c:4760
int cs_mesh_quantities_face_cog_choice(int algo_choice)
Query or modification of the option for computing face centers.
Definition: cs_mesh_quantities.c:2900
void cs_mesh_init_fluid_sections(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:4556
void cs_mesh_quantities_compute(const cs_mesh_t *m, cs_mesh_quantities_t *mq)
Compute mesh quantities.
Definition: cs_mesh_quantities.c:4337
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.c:2995
void cs_mesh_quantities_dump(const cs_mesh_t *mesh, const cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:5276
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.c:4684
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.c:5099
cs_mesh_quantities_t * cs_mesh_quantities_destroy(cs_mesh_quantities_t *mq)
Destroy a mesh quantities structure.
Definition: cs_mesh_quantities.c:2977
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.c:4717
Definition: mesh.f90:26
Definition: cs_mesh_quantities.h:92
int * b_sym_flag
Definition: cs_mesh_quantities.h:160
cs_real_t * cell_f_cen
Definition: cs_mesh_quantities.h:95
cs_real_t * b_face_cog
Definition: cs_mesh_quantities.h:111
cs_real_t * i_f_weight
Definition: cs_mesh_quantities.h:144
cs_real_t * c_w_face_surf
Definition: cs_mesh_quantities.h:122
cs_real_t * i_face_surf
Definition: cs_mesh_quantities.h:117
cs_real_t max_f_vol
Definition: cs_mesh_quantities.h:152
cs_real_t * b_dist
Definition: cs_mesh_quantities.h:138
int has_disable_flag
Definition: cs_mesh_quantities.h:161
cs_real_2_t * i_f_face_factor
Definition: cs_mesh_quantities.h:127
cs_real_t * b_face_surf
Definition: cs_mesh_quantities.h:118
cs_real_t * i_dist
Definition: cs_mesh_quantities.h:136
cs_real_t * i_f_face_surf
Definition: cs_mesh_quantities.h:120
cs_real_t * dofij
Definition: cs_mesh_quantities.h:132
cs_real_t * c_w_face_normal
Definition: cs_mesh_quantities.h:108
cs_real_t max_vol
Definition: cs_mesh_quantities.h:148
cs_real_t * cell_vol
Definition: cs_mesh_quantities.h:97
cs_real_t * weight
Definition: cs_mesh_quantities.h:143
cs_real_t * diipf
Definition: cs_mesh_quantities.h:133
cs_real_t * i_face_cog
Definition: cs_mesh_quantities.h:110
cs_real_t * b_face_normal
Definition: cs_mesh_quantities.h:102
cs_real_33_t * corr_grad_lin
Definition: cs_mesh_quantities.h:157
cs_real_t * b_f_face_cog
Definition: cs_mesh_quantities.h:113
cs_real_t * c_w_face_cog
Definition: cs_mesh_quantities.h:114
cs_real_t tot_vol
Definition: cs_mesh_quantities.h:149
int * c_disable_flag
Definition: cs_mesh_quantities.h:164
cs_nreal_3_t * i_face_u_normal
Definition: cs_mesh_quantities.h:124
cs_real_t * cell_s_cen
Definition: cs_mesh_quantities.h:96
cs_real_t tot_f_vol
Definition: cs_mesh_quantities.h:153
cs_real_t * cell_cen
Definition: cs_mesh_quantities.h:94
cs_real_t * dijpf
Definition: cs_mesh_quantities.h:130
cs_real_t * diipb
Definition: cs_mesh_quantities.h:131
cs_real_t min_f_vol
Definition: cs_mesh_quantities.h:151
cs_real_t * i_f_face_normal
Definition: cs_mesh_quantities.h:104
cs_real_t * b_f_face_surf
Definition: cs_mesh_quantities.h:121
cs_real_t * b_f_face_factor
Definition: cs_mesh_quantities.h:128
cs_real_t * cell_f_vol
Definition: cs_mesh_quantities.h:98
cs_real_t min_vol
Definition: cs_mesh_quantities.h:147
cs_real_t * c_w_dist_inv
Definition: cs_mesh_quantities.h:140
cs_nreal_3_t * b_face_u_normal
Definition: cs_mesh_quantities.h:125
cs_real_t * corr_grad_lin_det
Definition: cs_mesh_quantities.h:155
cs_real_t * b_f_face_normal
Definition: cs_mesh_quantities.h:106
cs_real_t * i_face_normal
Definition: cs_mesh_quantities.h:100
cs_real_t * djjpf
Definition: cs_mesh_quantities.h:134
unsigned * bad_cell_flag
Definition: cs_mesh_quantities.h:166
Definition: cs_mesh.h:85