7.3
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-2022 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 
83 /*============================================================================
84  * Type definition
85  *============================================================================*/
86 
87 /* Structure associated to mesh quantities management */
88 
89 typedef struct {
90 
91  cs_real_t *cell_cen; /* Cell center coordinates */
92  cs_real_t *cell_f_cen; /* Cell fluid center coordinates */
93  cs_real_t *cell_vol; /* Cell volume */
94  cs_real_t *cell_f_vol; /* Cell fluid volume */
95 
96  cs_real_t *i_face_normal; /* Surface normal of interior faces.
97  (L2 norm equals area of the face) */
98  cs_real_t *b_face_normal; /* Surface normal of border faces.
99  (L2 norm equals area of the face) */
100  cs_real_t *i_f_face_normal;/* Fluid surface normal of interior faces.
101  (L2 norm equals area of the face) */
102  cs_real_t *b_f_face_normal;/* Fluid 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_t *i_face_cog; /* Center of gravity of interior faces */
107  cs_real_t *b_face_cog; /* Center of gravity of border faces */
108  cs_real_t *i_f_face_cog_0; /* Center of gravity of fluid interior faces.
109  From cell 0 perspective.
110  It allows discontinuity */
111  cs_real_t *i_f_face_cog_1; /* Center of gravity of fluid interior faces.
112  From cell 1 perspective.
113  It allows discontinuity */
114  cs_real_t *b_f_face_cog; /* Center of gravity of fluid border faces */
115  cs_real_t *c_w_face_cog; /* Center of gravity of solid face
116  immersed in the cells */
117 
118  cs_real_t *i_face_surf; /* Surface of interior faces. */
119  cs_real_t *b_face_surf; /* Surface of boundary faces. */
120 
121  cs_real_t *i_f_face_surf; /* Fluid surface of interior faces. */
122  cs_real_t *b_f_face_surf; /* Fluid surface of boundary faces. */
123  cs_real_t *c_w_face_surf; /* Solid surface of cells. */
124 
125  cs_real_2_t *i_f_face_factor;/* Fluid surface factor of interior faces. */
126  cs_real_t *b_f_face_factor;/* Fluid surface factor of boundary faces. */
127 
128  cs_real_t *dijpf; /* Vector I'J' for interior faces */
129  cs_real_t *diipb; /* Vector II' for border faces */
130  cs_real_t *dofij; /* Vector OF for interior faces */
131  cs_real_t *diipf; /* Vector II' for interior faces */
132  cs_real_t *djjpf; /* Vector JJ' for interior faces */
133 
134  cs_real_t *i_dist; /* Distance between the centers of the two
135  cells sharing an interior face */
136  cs_real_t *b_dist; /* Distance between the cell center and
137  the center of gravity of border faces */
138  cs_real_t *c_w_dist_inv; /* Distance between the centers of the cell
139  and the solid face */
140 
141  cs_real_t *weight; /* Interior faces weighting factor */
142 
143  cs_real_t min_vol; /* Minimum cell volume */
144  cs_real_t max_vol; /* Maximum cell volume */
145  cs_real_t tot_vol; /* Total volume */
146 
147  cs_real_t min_f_vol; /* Minimum cell volume */
148  cs_real_t max_f_vol; /* Maximum cell volume */
149  cs_real_t tot_f_vol; /* Total volume */
150 
151  cs_real_t *corr_grad_lin_det; /* Determinant of geometrical matrix
152  linear gradient correction */
153  cs_real_33_t *corr_grad_lin; /* Geometrical matrix
154  linear gradient correction */
155 
156  int *b_sym_flag; /* Symmetry flag for boundary faces */
157  int has_disable_flag; /* Is the cell disabled?
158  0: unactivated
159  1: activated */
160  int *c_disable_flag; /* Is the cell disabled?
161  used for fluid solid and porous models */
162  unsigned *bad_cell_flag; /* Flag (mask) for bad cells detected */
163 
165 
166 /*============================================================================
167  * Global variables
168  *============================================================================*/
169 
170 /* Pointer to mesh quantities structure associated to the main mesh */
171 
173 
174 /* Flag (mask) to activate bad cells correction */
175 extern unsigned cs_glob_mesh_quantities_flag;
176 
177 /*=============================================================================
178  * Public function prototypes
179  *============================================================================*/
180 
181 /*----------------------------------------------------------------------------*/
191 /*----------------------------------------------------------------------------*/
192 
193 int
194 cs_mesh_quantities_cell_cen_choice(int algo_choice);
195 
196 /*----------------------------------------------------------------------------*/
207 /*----------------------------------------------------------------------------*/
208 
209 int
210 cs_mesh_quantities_face_cog_choice(int algo_choice);
211 
212 /*----------------------------------------------------------------------------*/
218 /*----------------------------------------------------------------------------*/
219 
222 
223 /*----------------------------------------------------------------------------*/
231 /*----------------------------------------------------------------------------*/
232 
235 
236 /*----------------------------------------------------------------------------*/
242 /*----------------------------------------------------------------------------*/
243 
244 void
246 
247 /*----------------------------------------------------------------------------*/
254 /*----------------------------------------------------------------------------*/
255 
256 void
259 
260 /*----------------------------------------------------------------------------*/
267 /*----------------------------------------------------------------------------*/
268 
269 void
272 
273 /*----------------------------------------------------------------------------
274  * Compute fluid mesh quantities
275  *
276  * parameters:
277  * mesh <-- pointer to a cs_mesh_t structure
278  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
279  *----------------------------------------------------------------------------*/
280 
281 void
283  cs_mesh_quantities_t *mesh_quantities);
284 
285 /*----------------------------------------------------------------------------
286  * Compute the total, min, and max fluid volumes of cells
287  *
288  * parameters:
289  * mesh <-- pointer to mesh structure
290  * mesh_quantities <-> pointer to a mesh quantities structure
291  *----------------------------------------------------------------------------*/
292 
293 void
295  cs_mesh_quantities_t *mesh_quantities);
296 
297 /*----------------------------------------------------------------------------
298  * Compute fluid section mesh quantities at the initial step
299  *
300  * parameters:
301  * mesh <-- pointer to a cs_mesh_t structure
302  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
303  *----------------------------------------------------------------------------*/
304 
305 void
307  cs_mesh_quantities_t *mesh_quantities);
308 
309 /*----------------------------------------------------------------------------*/
318 /*----------------------------------------------------------------------------*/
319 
320 void
322  const cs_real_3_t *cen_points,
324 
325 /*----------------------------------------------------------------------------
326  * Compute mesh quantities
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 
333 void
335  cs_mesh_quantities_t *mesh_quantities);
336 
337 /*----------------------------------------------------------------------------
338  * Compute internal and border face normal.
339  *
340  * parameters:
341  * mesh <-- pointer to a cs_mesh_t structure
342  * p_i_face_normal <-> pointer to the internal face normal array
343  * p_b_face_normal <-> pointer to the border face normal array
344  *----------------------------------------------------------------------------*/
345 
346 void
348  cs_real_t *p_i_face_normal[],
349  cs_real_t *p_b_face_normal[]);
350 
351 /*----------------------------------------------------------------------------
352  * Compute interior face centers and normals.
353  *
354  * The corresponding arrays are allocated by this function, and it is the
355  * caller's responsibility to free them when they are no longer needed.
356  *
357  * parameters:
358  * mesh <-- pointer to a cs_mesh_t structure
359  * p_i_face_cog <-> pointer to the interior face center array
360  * p_i_face_normal <-> pointer to the interior face normal array
361  *----------------------------------------------------------------------------*/
362 
363 void
365  cs_real_t *p_i_face_cog[],
366  cs_real_t *p_i_face_normal[]);
367 
368 /*----------------------------------------------------------------------------
369  * Compute border face centers and normals.
370  *
371  * The corresponding arrays are allocated by this function, and it is the
372  * caller's responsibility to free them when they are no longer needed.
373  *
374  * parameters:
375  * mesh <-- pointer to a cs_mesh_t structure
376  * p_b_face_cog <-> pointer to the border face center array
377  * p_b_face_normal <-> pointer to the border face normal array
378  *----------------------------------------------------------------------------*/
379 
380 void
382  cs_real_t *p_b_face_cog[],
383  cs_real_t *p_b_face_normal[]);
384 
385 /*----------------------------------------------------------------------------*/
405 /*----------------------------------------------------------------------------*/
406 
407 void
409  const cs_real_t i_face_norm[],
410  const cs_real_t i_face_cog[],
411  const cs_real_t b_face_norm[],
412  const cs_real_t b_face_cog[],
413  cs_real_t cell_cen[]);
414 
415 /*----------------------------------------------------------------------------
416  * Compute cell volumes.
417  *
418  * The corresponding array is allocated by this function, and it is the
419  * caller's responsability to free it when they are no longer needed.
420  *
421  * parameters:
422  * mesh <-- pointer to a cs_mesh_t structure
423  *
424  * return:
425  * pointer to newly allocated cell volumes array
426  *----------------------------------------------------------------------------*/
427 
428 cs_real_t *
430 
431 /*----------------------------------------------------------------------------
432  * Check that no negative volumes are present, and exit on error otherwise.
433  *
434  * parameters:
435  * mesh <-- pointer to mesh structure
436  * mesh_quantities <-- pointer to mesh quantities structure
437  * allow_error <-- 1 if errors are allowed, 0 otherwise
438  *----------------------------------------------------------------------------*/
439 
440 void
442  const cs_mesh_quantities_t *mesh_quantities,
443  int allow_error);
444 
445 /*----------------------------------------------------------------------------*/
458 /*----------------------------------------------------------------------------*/
459 
460 cs_real_6_t *
462  cs_real_t tolerance);
463 
464 /*----------------------------------------------------------------------------
465  * Return the number of times mesh quantities have been computed.
466  *
467  * returns:
468  * number of times mesh quantities have been computed
469  *----------------------------------------------------------------------------*/
470 
471 int
473 
474 /*----------------------------------------------------------------------------*/
484 /*----------------------------------------------------------------------------*/
485 
486 void
488  const cs_mesh_quantities_t *mq,
489  int n_passes,
490  cs_real_t b_thickness[]);
491 
492 /*----------------------------------------------------------------------------*/
501 /*----------------------------------------------------------------------------*/
502 
503 void
505  const cs_mesh_quantities_t *mq,
506  int n_passes,
507  cs_real_t b_thickness[]);
508 
509 /*----------------------------------------------------------------------------*/
513 /*----------------------------------------------------------------------------*/
514 
515 void
517 
518 /*----------------------------------------------------------------------------
519  * Dump a cs_mesh_quantities_t structure
520  *
521  * parameters:
522  * mesh <-- pointer to a cs_mesh_t structure
523  * mesh_quantities <-- pointer to a cs_mesh_quantities_t structure
524  *----------------------------------------------------------------------------*/
525 
526 void
528  const cs_mesh_quantities_t *mesh_quantities);
529 
530 /*----------------------------------------------------------------------------*/
531 
533 
534 #endif /* __CS_MESH_QUANTITIES_H__ */
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:4248
void cs_mesh_quantities_dump(const cs_mesh_t *mesh, const cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:4589
int has_disable_flag
Definition: cs_mesh_quantities.h:157
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition: cs_defs.h:334
cs_real_t * b_dist
Definition: cs_mesh_quantities.h:136
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:337
void cs_mesh_quantities_compute(const cs_mesh_t *m, cs_mesh_quantities_t *mq)
Compute mesh quantities.
Definition: cs_mesh_quantities.c:3661
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:4412
cs_real_t * corr_grad_lin_det
Definition: cs_mesh_quantities.h:151
int * c_disable_flag
Definition: cs_mesh_quantities.h:160
cs_real_t * cell_f_vol
Definition: cs_mesh_quantities.h:94
cs_real_t * b_face_surf
Definition: cs_mesh_quantities.h:119
cs_real_t * cs_mesh_quantities_cell_volume(const cs_mesh_t *mesh)
Definition: cs_mesh_quantities.c:4207
cs_real_t * djjpf
Definition: cs_mesh_quantities.h:132
cs_real_t * b_f_face_cog
Definition: cs_mesh_quantities.h:114
cs_real_t min_f_vol
Definition: cs_mesh_quantities.h:147
cs_real_t max_f_vol
Definition: cs_mesh_quantities.h:148
#define BEGIN_C_DECLS
Definition: cs_defs.h:512
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:2954
cs_real_33_t * corr_grad_lin
Definition: cs_mesh_quantities.h:153
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:4306
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:2572
cs_real_t * diipf
Definition: cs_mesh_quantities.h:131
cs_real_t * dofij
Definition: cs_mesh_quantities.h:130
cs_real_t * b_face_cog
Definition: cs_mesh_quantities.h:107
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
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:3956
cs_real_t max_vol
Definition: cs_mesh_quantities.h:144
unsigned * bad_cell_flag
Definition: cs_mesh_quantities.h:162
Definition: cs_mesh.h:85
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:2665
cs_real_t * i_f_face_normal
Definition: cs_mesh_quantities.h:100
void cs_mesh_init_fluid_sections(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:3875
void cs_mesh_quantities_fluid_vol_reductions(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:3835
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:2550
cs_real_t tot_vol
Definition: cs_mesh_quantities.h:145
cs_real_t * c_w_face_normal
Definition: cs_mesh_quantities.h:104
cs_real_t * c_w_face_surf
Definition: cs_mesh_quantities.h:123
cs_real_t tot_f_vol
Definition: cs_mesh_quantities.h:149
cs_real_t * dijpf
Definition: cs_mesh_quantities.h:128
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:4036
cs_real_t * cell_cen
Definition: cs_mesh_quantities.h:91
cs_mesh_quantities_t * cs_glob_mesh_quantities
cs_real_t * i_dist
Definition: cs_mesh_quantities.h:134
cs_real_t * i_face_normal
Definition: cs_mesh_quantities.h:96
Definition: cs_mesh_quantities.h:89
cs_real_2_t * i_f_face_factor
Definition: cs_mesh_quantities.h:125
cs_mesh_quantities_t * cs_mesh_quantities_destroy(cs_mesh_quantities_t *mq)
Destroy a mesh quantities structure.
Definition: cs_mesh_quantities.c:2647
cs_mesh_quantities_t * cs_mesh_quantities_create(void)
Create a mesh quantities structure.
Definition: cs_mesh_quantities.c:2589
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:335
cs_real_t * i_f_face_cog_0
Definition: cs_mesh_quantities.h:108
cs_real_t * cell_f_cen
Definition: cs_mesh_quantities.h:92
unsigned cs_glob_mesh_quantities_flag
void cs_mesh_quantities_log_setup(void)
Log mesh quantities options to setup file.
Definition: cs_mesh_quantities.c:4544
cs_real_t * b_f_face_surf
Definition: cs_mesh_quantities.h:122
cs_real_t * weight
Definition: cs_mesh_quantities.h:141
cs_real_t * b_f_face_factor
Definition: cs_mesh_quantities.h:126
cs_real_t min_vol
Definition: cs_mesh_quantities.h:143
#define END_C_DECLS
Definition: cs_defs.h:513
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:4079
cs_real_t * i_f_face_surf
Definition: cs_mesh_quantities.h:121
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:2720
void cs_mesh_quantities_fluid_compute(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:3819
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:344
cs_real_t * b_face_normal
Definition: cs_mesh_quantities.h:98
int * b_sym_flag
Definition: cs_mesh_quantities.h:156
cs_real_t * diipb
Definition: cs_mesh_quantities.h:129
cs_real_t * cell_vol
Definition: cs_mesh_quantities.h:93
cs_real_t * c_w_dist_inv
Definition: cs_mesh_quantities.h:138
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:4502
void cs_mesh_quantities_sup_vectors(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:3921
cs_real_t * c_w_face_cog
Definition: cs_mesh_quantities.h:115
cs_real_t * i_face_surf
Definition: cs_mesh_quantities.h:118
int cs_mesh_quantities_compute_count(void)
Definition: cs_mesh_quantities.c:4394
cs_real_t * i_face_cog
Definition: cs_mesh_quantities.h:106
cs_real_t * i_f_face_cog_1
Definition: cs_mesh_quantities.h:111
Definition: mesh.f90:26
cs_real_t * b_f_face_normal
Definition: cs_mesh_quantities.h:102
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:4003