programmer's 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-2018 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 #include "cs_internal_coupling.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
41 
42 /*=============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
52 /*
53  * Field property type
54  */
55 
57 #define CS_BAD_CELLS_WARPED_CORRECTION (1 << 0)
58 
60 #define CS_BAD_CELLS_REGULARISATION (1 << 1)
61 
63 #define CS_CELL_FACE_CENTER_CORRECTION (1 << 2)
64 
66 #define CS_CELL_CENTER_CORRECTION (1 << 3)
67 
69 #define CS_FACE_DISTANCE_CLIP (1 << 4)
70 
72 #define CS_FACE_RECONSTRUCTION_CLIP (1 << 5)
73 
75 #define CS_CELL_VOLUME_RATIO_CORRECTION (1 << 6)
76 
79 /*============================================================================
80  * Type definition
81  *============================================================================*/
82 
83 /* Structure associated to mesh quantities management */
84 
85 typedef struct {
86 
87  cs_real_t *cell_cen; /* Cell center coordinates */
88  cs_real_t *cell_vol; /* Cell volume */
89  cs_real_t *cell_f_vol; /* Cell fluid volume */
90 
91  cs_real_t *i_face_normal; /* Surface normal of interior faces.
92  (L2 norm equals area of the face) */
93  cs_real_t *b_face_normal; /* Surface normal of border faces.
94  (L2 norm equals area of the face) */
95  cs_real_t *i_f_face_normal;/* Fluid Surface normal of interior faces.
96  (L2 norm equals area of the face) */
97  cs_real_t *b_f_face_normal;/* Fluid Surface normal of border faces.
98  (L2 norm equals area of the face) */
99  cs_real_t *i_face_cog; /* Center of gravity of interior faces */
100  cs_real_t *b_face_cog; /* Center of gravity of border faces */
101 
102  cs_real_t *i_face_surf; /* Surface of interior faces. */
103  cs_real_t *b_face_surf; /* Surface of boundary faces. */
104 
105  cs_real_t *i_f_face_surf; /* Fluid surface of interior faces. */
106  cs_real_t *b_f_face_surf; /* Fluid surface of boundary faces. */
107 
108  cs_real_t *dijpf; /* Vector I'J' for interior faces */
109  cs_real_t *diipb; /* Vector II' for border faces */
110  cs_real_t *dofij; /* Vector OF for interior faces */
111  cs_real_t *diipf; /* Vector II' for interior faces */
112  cs_real_t *djjpf; /* Vector JJ' for interior faces */
113 
114  cs_real_t *i_dist; /* Distance between the cell center and
115  the center of gravity of interior faces */
116  cs_real_t *b_dist; /* Distance between the cell center and
117  the center of gravity of border faces */
118 
119  cs_real_t *weight; /* Interior faces weighting factor */
120 
121  cs_real_t min_vol; /* Minimum cell volume */
122  cs_real_t max_vol; /* Maximum cell volume */
123  cs_real_t tot_vol; /* Total volume */
124 
125  cs_real_t min_f_vol; /* Minimum cell volume */
126  cs_real_t max_f_vol; /* Maximum cell volume */
127  cs_real_t tot_f_vol; /* Total volume */
128 
129  cs_real_33_t *cocgb_s_it; /* coupling of gradient components for
130  iterative reconstruction at boundary */
131  cs_real_33_t *cocg_s_it; /* coupling of gradient components for
132  iterative reconstruction */
133  cs_real_33_t *cocgb_s_lsq; /* coupling of gradient components for
134  least-square reconstruction at boundary */
135 
136  cs_real_33_t *cocg_it; /* Interleaved cocg matrix
137  for iterative gradients */
138  cs_real_33_t *cocg_lsq; /* Interleaved cocg matrix
139  for least square gradients */
140 
141  cs_real_t *corr_grad_lin_det; /* Determinant of geometrical matrix
142  linear gradient correction */
143  cs_real_33_t *corr_grad_lin; /* Geometrical matrix
144  linear gradient correction */
145 
146  cs_int_t *b_sym_flag; /* Symmetry flag for boundary faces */
147  cs_int_t *c_solid_flag; /* Is the fluid volume 0 flag */
148  unsigned *bad_cell_flag; /* Flag (mask) for bad cells detected */
149 
151 
152 /*============================================================================
153  * Static global variables
154  *============================================================================*/
155 
156 /* Pointer to mesh quantities structure associated to the main mesh */
157 
159 
160 /* Flag (mask) to activate bad cells correction */
161 extern unsigned cs_glob_mesh_quantities_flag;
162 
163 /* Choice of the porous model */
164 extern int cs_glob_porous_model;
165 
166 /*============================================================================
167  * Public function prototypes for API Fortran
168  *============================================================================*/
169 
170 /*----------------------------------------------------------------------------
171  * Query or modification of the option for computing cell centers.
172  *
173  * This function returns 1 or 2 according to the selected algorithm.
174  *
175  * Fortran interface :
176  *
177  * SUBROUTINE ALGCEN (IOPT)
178  * *****************
179  *
180  * INTEGER IOPT : <-> : Choice of the algorithm
181  * < 0 : query
182  * 0 : computation based
183  * on faces (default choice)
184  * 1 : computation based
185  * on vertices
186  *----------------------------------------------------------------------------*/
187 
188 void
189 CS_PROCF (algcen, ALGCEN) (cs_int_t *const iopt);
190 
191 /*----------------------------------------------------------------------------
192  * Set behavior for computing the cocg matrixes for the iterative algo
193  * and for the Least square method for scalar and vector gradients.
194  *
195  * Fortran interface :
196  *
197  * subroutine comcoc (imrgra)
198  * *****************
199  *
200  * integer imrgra : <-- : gradient reconstruction option
201  *----------------------------------------------------------------------------*/
202 
203 void
204 CS_PROCF (comcoc, COMCOC) (const cs_int_t *const imrgra);
205 
206 /*----------------------------------------------------------------------------
207  * Set porous model
208  *
209  * Fortran interface :
210  *
211  * subroutine compor (iporos)
212  * *****************
213  *
214  * integer iporos : <-- : porous model
215  *----------------------------------------------------------------------------*/
216 
217 void
218 CS_PROCF (compor, COMPOR) (const cs_int_t *const iporos);
219 
220 /*=============================================================================
221  * Public function prototypes
222  *============================================================================*/
223 
224 /*----------------------------------------------------------------------------
225  * Query or modification of the option for computing cell centers.
226  *
227  * < 0 : query
228  * 0 : computation based on faces (default choice)
229  * 1 : computation based on vertices
230  *
231  * algo_choice <-- choice of algorithm to compute cell centers.
232  *
233  * returns:
234  * 1 or 2 according to the selected algorithm.
235  *----------------------------------------------------------------------------*/
236 
237 int
238 cs_mesh_quantities_cell_cen_choice(const int algo_choice);
239 
240 /*----------------------------------------------------------------------------
241  * Compute cocg for iterative gradient reconstruction for scalars.
242  *
243  * parameters:
244  * gradient_option <-- gradient option (Fortran IMRGRA)
245  *----------------------------------------------------------------------------*/
246 
247 void
248 cs_mesh_quantities_set_cocg_options(int gradient_option);
249 
250 /*----------------------------------------------------------------------------
251  * Compute Fluid volumes and fluid surface in addition to cell volume and surfaces.
252  *
253  * parameters:
254  * porous_model <-- gradient option (Fortran iporos)
255  *----------------------------------------------------------------------------*/
256 
257 void
258 cs_mesh_quantities_set_porous_model(int porous_model);
259 
260 /*----------------------------------------------------------------------------
261  * Create a mesh quantities structure.
262  *
263  * returns:
264  * pointer to created cs_mesh_quantities_t structure
265  *----------------------------------------------------------------------------*/
266 
269 
270 /*----------------------------------------------------------------------------
271  * Destroy a mesh quantities structure
272  *
273  * parameters:
274  * mesh_quantities <-- pointer to a cs_mesh_quantities_t structure
275  *
276  * returns:
277  * NULL
278  *----------------------------------------------------------------------------*/
279 
282 
283 /*----------------------------------------------------------------------------*/
289 /*----------------------------------------------------------------------------*/
290 
291 void
293 
294 /*----------------------------------------------------------------------------
295  * Compute mesh quantities needed fo preprocessing
296  *
297  * parameters:
298  * mesh <-- pointer to a cs_mesh_t structure
299  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
300  *----------------------------------------------------------------------------*/
301 
302 void
304  cs_mesh_quantities_t *mesh_quantities);
305 
306 /*----------------------------------------------------------------------------
307  * Compute mesh quantities
308  *
309  * parameters:
310  * mesh <-- pointer to a cs_mesh_t structure
311  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
312  *----------------------------------------------------------------------------*/
313 
314 void
316  cs_mesh_quantities_t *mesh_quantities);
317 
318 /*----------------------------------------------------------------------------
319  * Compute fluid mesh quantities
320  *
321  * parameters:
322  * mesh <-- pointer to a cs_mesh_t structure
323  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
324  *----------------------------------------------------------------------------*/
325 
326 void
328  cs_mesh_quantities_t *mesh_quantities);
329 
330 /*----------------------------------------------------------------------------
331  * Compute fluid section mesh quantities at the initial step
332  *
333  * parameters:
334  * mesh <-- pointer to a cs_mesh_t structure
335  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
336  *----------------------------------------------------------------------------*/
337 
338 void
340  cs_mesh_quantities_t *mesh_quantities);
341 
342 /*----------------------------------------------------------------------------
343  * Compute mesh quantities
344  *
345  * parameters:
346  * mesh <-- pointer to a cs_mesh_t structure
347  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
348  *----------------------------------------------------------------------------*/
349 
350 void
352  cs_mesh_quantities_t *mesh_quantities);
353 
354 /*----------------------------------------------------------------------------
355  * Compute internal and border face normal.
356  *
357  * parameters:
358  * mesh <-- pointer to a cs_mesh_t structure
359  * p_i_face_normal <-> pointer to the internal face normal array
360  * p_b_face_normal <-> pointer to the border face normal array
361  *----------------------------------------------------------------------------*/
362 
363 void
365  cs_real_t *p_i_face_normal[],
366  cs_real_t *p_b_face_normal[]);
367 
368 /*----------------------------------------------------------------------------
369  * Compute interior 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_i_face_cog <-> pointer to the interior face center array
377  * p_i_face_normal <-> pointer to the interior face normal array
378  *----------------------------------------------------------------------------*/
379 
380 void
382  cs_real_t *p_i_face_cog[],
383  cs_real_t *p_i_face_normal[]);
384 
385 /*----------------------------------------------------------------------------
386  * Compute border face centers and normals.
387  *
388  * The corresponding arrays are allocated by this function, and it is the
389  * caller's responsibility to free them when they are no longer needed.
390  *
391  * parameters:
392  * mesh <-- pointer to a cs_mesh_t structure
393  * p_b_face_cog <-> pointer to the border face center array
394  * p_b_face_normal <-> pointer to the border face normal array
395  *----------------------------------------------------------------------------*/
396 
397 void
399  cs_real_t *p_b_face_cog[],
400  cs_real_t *p_b_face_normal[]);
401 
402 /*----------------------------------------------------------------------------
403  * Compute cell centers.
404  *
405  * The corresponding array is allocated by this function, and it is the
406  * caller's responsibility to free it when they are no longer needed.
407  *
408  * parameters:
409  * mesh <-- pointer to a cs_mesh_t structure
410  * p_cell_cen <-> pointer to the cell centers array
411  *----------------------------------------------------------------------------*/
412 
413 void
415  cs_real_t *cell_cen[]);
416 
417 /*----------------------------------------------------------------------------
418  * Check that no negative volumes are present, and exit on error otherwise.
419  *
420  * parameters:
421  * mesh <-- pointer to mesh structure
422  * mesh_quantities <-- pointer to mesh quantities structure
423  * allow_error <-- 1 if errors are allowed, 0 otherwise
424  *----------------------------------------------------------------------------*/
425 
426 void
428  const cs_mesh_quantities_t *mesh_quantities,
429  int allow_error);
430 
431 /*----------------------------------------------------------------------------
432  * Update mesh quantities relative to extended ghost cells when the
433  * neighborhood is reduced.
434  *
435  * parameters:
436  * mesh <-- pointer to a cs_mesh_t structure
437  * mesh_quantities <-> pointer to a cs_mesh_quantities_t structure
438  *----------------------------------------------------------------------------*/
439 
440 void
442  cs_mesh_quantities_t *mesh_quantities);
443 
444 /*----------------------------------------------------------------------------
445  * Return the number of times mesh quantities have been computed.
446  *
447  * returns:
448  * number of times mesh quantities have been computed
449  *----------------------------------------------------------------------------*/
450 
451 int
453 
454 /*----------------------------------------------------------------------------*/
464 /*----------------------------------------------------------------------------*/
465 
466 void
468  const cs_mesh_quantities_t *mq,
469  int n_passes,
470  cs_real_t b_thickness[]);
471 
472 /*----------------------------------------------------------------------------*/
481 /*----------------------------------------------------------------------------*/
482 
483 void
485  const cs_mesh_quantities_t *mq,
486  int n_passes,
487  cs_real_t b_thickness[]);
488 
489 /*----------------------------------------------------------------------------
490  * Dump a cs_mesh_quantities_t structure
491  *
492  * parameters:
493  * mesh <-- pointer to a cs_mesh_t structure
494  * mesh_quantities <-- pointer to a cs_mesh_quantities_t structure
495  *----------------------------------------------------------------------------*/
496 
497 void
499  const cs_mesh_quantities_t *mesh_quantities);
500 
501 /*----------------------------------------------------------------------------
502  * Compute 3x3 matrix cocg for the scalar gradient least squares algorithm
503  * adapted for internal coupling.
504  *
505  * parameters:
506  * m <-- mesh
507  * fvq <-> mesh quantities
508  * ce <-> coupling
509  *----------------------------------------------------------------------------*/
510 
511 void
515 
516 /*----------------------------------------------------------------------------
517  * Compute 3x3 matrix cocg for the scalar gradient iterative algorithm
518  * adapted for internal coupling.
519  *
520  * parameters:
521  * m <-- mesh
522  * fvq <-> mesh quantities
523  * ce <-> coupling
524  *----------------------------------------------------------------------------*/
525 
526 void
530 
531 /*----------------------------------------------------------------------------*/
532 
534 
535 #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:3440
cs_real_33_t * cocgb_s_lsq
Definition: cs_mesh_quantities.h:133
void cs_mesh_quantities_reduce_extended(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:3492
void cs_mesh_quantities_dump(const cs_mesh_t *mesh, const cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:3659
cs_real_t * b_dist
Definition: cs_mesh_quantities.h:116
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:3525
cs_real_t * corr_grad_lin_det
Definition: cs_mesh_quantities.h:141
integer, save iporos
Definition: optcal.f90:1149
cs_real_t * cell_f_vol
Definition: cs_mesh_quantities.h:89
cs_real_t * b_face_surf
Definition: cs_mesh_quantities.h:103
cs_real_t * djjpf
Definition: cs_mesh_quantities.h:112
void cs_mesh_quantities_compute_preprocess(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:2783
cs_real_t min_f_vol
Definition: cs_mesh_quantities.h:125
cs_int_t * c_solid_flag
Definition: cs_mesh_quantities.h:147
Definition: cs_internal_coupling.h:62
cs_real_t max_f_vol
Definition: cs_mesh_quantities.h:126
#define BEGIN_C_DECLS
Definition: cs_defs.h:461
int cs_int_t
Fortran-compatible integer.
Definition: cs_defs.h:296
void cs_compute_cell_cocg_it_coupling(const cs_mesh_t *m, cs_mesh_quantities_t *fvq, cs_internal_coupling_t *ce)
Definition: cs_mesh_quantities.c:3774
cs_real_33_t * corr_grad_lin
Definition: cs_mesh_quantities.h:143
void algcen(cs_int_t *const iopt)
Definition: cs_mesh_quantities.c:2512
cs_mesh_quantities_t * cs_mesh_quantities_destroy(cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:2716
cs_real_t * diipf
Definition: cs_mesh_quantities.h:111
cs_real_t * dofij
Definition: cs_mesh_quantities.h:110
cs_real_t * b_face_cog
Definition: cs_mesh_quantities.h:100
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
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:3262
cs_real_t max_vol
Definition: cs_mesh_quantities.h:122
unsigned * bad_cell_flag
Definition: cs_mesh_quantities.h:148
Definition: cs_mesh.h:63
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:2734
cs_real_33_t * cocg_s_it
Definition: cs_mesh_quantities.h:131
cs_real_t * i_f_face_normal
Definition: cs_mesh_quantities.h:95
void cs_mesh_init_fluid_sections(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:3186
cs_real_t tot_vol
Definition: cs_mesh_quantities.h:123
cs_real_t tot_f_vol
Definition: cs_mesh_quantities.h:127
void cs_mesh_quantities_set_cocg_options(int gradient_option)
Definition: cs_mesh_quantities.c:2597
cs_real_t * dijpf
Definition: cs_mesh_quantities.h:108
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:3348
cs_real_t * cell_cen
Definition: cs_mesh_quantities.h:87
cs_mesh_quantities_t * cs_glob_mesh_quantities
cs_real_t * i_dist
Definition: cs_mesh_quantities.h:114
cs_real_t * i_face_normal
Definition: cs_mesh_quantities.h:91
Definition: cs_mesh_quantities.h:85
void cs_mesh_quantities_cell_cen(const cs_mesh_t *mesh, cs_real_t *cell_cen[])
Definition: cs_mesh_quantities.c:3382
cs_real_33_t * cocgb_s_it
Definition: cs_mesh_quantities.h:129
int cs_glob_porous_model
cs_mesh_quantities_t * cs_mesh_quantities_create(void)
Definition: cs_mesh_quantities.c:2665
int cs_mesh_quantities_cell_cen_choice(const int algo_choice)
Definition: cs_mesh_quantities.c:2572
void comcoc(const cs_int_t *const imrgra)
Definition: cs_mesh_quantities.c:2532
unsigned cs_glob_mesh_quantities_flag
cs_real_t * b_f_face_surf
Definition: cs_mesh_quantities.h:106
cs_real_t * weight
Definition: cs_mesh_quantities.h:119
cs_real_t min_vol
Definition: cs_mesh_quantities.h:121
#define END_C_DECLS
Definition: cs_defs.h:462
cs_real_33_t * cocg_it
Definition: cs_mesh_quantities.h:136
cs_real_t * i_f_face_surf
Definition: cs_mesh_quantities.h:105
void cs_compute_cell_cocg_lsq_coupling(const cs_mesh_t *m, cs_mesh_quantities_t *fvq, cs_internal_coupling_t *ce)
Definition: cs_mesh_quantities.c:3756
#define CS_PROCF(x, y)
Definition: cs_defs.h:475
void cs_mesh_quantities_fluid_compute(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:3170
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:315
cs_real_t * b_face_normal
Definition: cs_mesh_quantities.h:93
cs_real_t * diipb
Definition: cs_mesh_quantities.h:109
cs_real_t * cell_vol
Definition: cs_mesh_quantities.h:88
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:3615
void cs_mesh_quantities_compute(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:2978
void cs_mesh_quantities_sup_vectors(const cs_mesh_t *mesh, cs_mesh_quantities_t *mesh_quantities)
Definition: cs_mesh_quantities.c:3227
void compor(const cs_int_t *const iporos)
Definition: cs_mesh_quantities.c:2549
cs_real_t * i_face_surf
Definition: cs_mesh_quantities.h:102
int cs_mesh_quantities_compute_count(void)
Definition: cs_mesh_quantities.c:3507
cs_real_t * i_face_cog
Definition: cs_mesh_quantities.h:99
cs_int_t * b_sym_flag
Definition: cs_mesh_quantities.h:146
Definition: mesh.f90:26
integer(c_int), pointer, save imrgra
type of gradient reconstruction
Definition: optcal.f90:353
cs_real_33_t * cocg_lsq
Definition: cs_mesh_quantities.h:138
cs_real_t * b_f_face_normal
Definition: cs_mesh_quantities.h:97
void cs_mesh_quantities_set_porous_model(int porous_model)
Definition: cs_mesh_quantities.c:2652
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:3313