7.2
general documentation
cs_cdo_quantities.h
Go to the documentation of this file.
1 #ifndef __CS_CDO_QUANTITIES_H__
2 #define __CS_CDO_QUANTITIES_H__
3 
4 /*============================================================================
5  * Manage geometrical quantities needed in CDO schemes
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_cdo_connect.h"
36 #include "cs_flag.h"
37 #include "cs_math.h"
38 #include "cs_mesh.h"
39 #include "cs_mesh_quantities.h"
40 
41 /*----------------------------------------------------------------------------*/
42 
44 
45 /*============================================================================
46  * Macro definitions
47  *============================================================================*/
48 
49 /*============================================================================
50  * Type definitions
51  *============================================================================*/
52 
67 typedef enum {
68 
72 
74 
94 typedef enum {
95 
96  /* Set of geometrical quantities related to CDO schemes */
97 
98  CS_CDO_QUANTITIES_EB_SCHEME = 1<<0, /* = 1 */
99  CS_CDO_QUANTITIES_FB_SCHEME = 1<<1, /* = 2 */
101  CS_CDO_QUANTITIES_VB_SCHEME = 1<<3, /* = 8 */
102  CS_CDO_QUANTITIES_VCB_SCHEME = 1<<4, /* = 16 */
103 
105 
106 
107 /* Structure storing information about variation of entities across the
108  mesh for a given type of entity (cell, face and edge) */
109 
110 typedef struct {
111 
112  /* Measure is either a volume for cells, a surface for faces or a length
113  for edges */
114 
115  double meas_min; /* Min. value of the entity measure */
116  double meas_max; /* Max. value of the entity measure */
117  double h_min; /* Estimation of the min. value of the diameter */
118  double h_max; /* Estimation of the max. value of the diameter */
119 
121 
122 /* For primal vector quantities (edge or face) */
123 
124 typedef struct {
125 
126  double meas; /* length or area */
127  double unitv[3]; /* unitary vector: tangent or normal to the element */
128  double center[3];
129 
130 } cs_quant_t;
131 
132 typedef struct { /* Specific mesh quantities */
133 
134  /* Keep the information about the removal of boundary faces in case of 2D
135  computations */
136 
138 
139  /* Global mesh quantities */
140 
141  double vol_tot;
142 
143  /* Cell-based quantities */
144  /* ===================== */
145 
146  cs_lnum_t n_cells; /* Local number of cells */
147  cs_gnum_t n_g_cells; /* Global number of cells */
148  cs_real_t *cell_centers; /* May be shared according to options */
149  const cs_real_t *cell_vol; /* Shared with cs_mesh_quantities_t */
150 
152 
153  /* Face-based quantities */
154  /* ===================== */
155 
156  cs_lnum_t n_faces; /* n_i_faces + n_b_faces */
157  cs_lnum_t n_i_faces; /* Local number of interior faces */
158  cs_lnum_t n_b_faces; /* Local number of border faces */
159  cs_gnum_t n_g_faces; /* Global number of faces */
160 
161  /* Remark: cs_quant_t structure attached to a face (interior or border) can
162  be built on-the-fly calling the function cs_quant_set_face(f_id, cdoq).
163  See \ref cs_quant_set_face for more details.
164 
165  In order to reduce the memory consumption one shares face quantities with
166  the ones defined in the legacy part and stored in the cs_mesh_quantities_t
167  structure that's why a distinction is made between interior and border
168  faces.
169 
170  cs_nvec3_t structure associated to a face can also be built on-the-fly
171  using cs_quant_set_face_nvec(f_id, cdoq).
172  See \ref cs_quant_set_face_nvec for more details.
173  */
174 
175  const cs_real_t *i_face_normal; /* Shared with cs_mesh_quantities_t */
176  const cs_real_t *i_face_center; /* Shared with cs_mesh_quantities_t */
177  const cs_real_t *i_face_surf; /* Shared with cs_mesh_quantities_t */
178 
179  const cs_real_t *b_face_normal; /* Shared with cs_mesh_quantities_t */
180  const cs_real_t *b_face_center; /* Shared with cs_mesh_quantities_t */
181  const cs_real_t *b_face_surf; /* Shared with cs_mesh_quantities_t */
182 
183  /* Remark: cs_nvec3_t structure attached to a dual edge can be built
184  on-the-fly to access to its length and its unit tangential vector using
185  the function cs_quant_set_dedge_nvec(shift, cdoq)
186 
187  One recalls that a dual edge is associated to a primal face and is shared
188  with two cells for an interior face and shared with one cell for a
189  boundary face. Scan this quantity with the c2f connectivity.
190  */
191 
192  cs_real_t *dedge_vector; /* Allocation to 3*c2f->idx[n_faces] */
193 
194  cs_real_t *pvol_fc; /* Portion of volume surrounding a face
195  * in each cell. This is a pyramid of
196  * base the face and apex the cell center
197  * Scanned with the c2f adjacency.
198  * Not always allocated.
199  */
201 
202  /* Edge-based quantities */
203  /* ===================== */
204 
205  cs_lnum_t n_edges; /* Local number of edges */
206  cs_gnum_t n_g_edges; /* Global number of edges */
207 
208  cs_real_t *edge_vector; /* Allocation to 3*n_edges
209  Norm of the vector is equal to the
210  distance between two vertices.
211  Unit vector is the tangential direction
212  attached to the edge */
213 
214  /* For each edge e belonging to a cell c, the dual face is built from the
215  contributions of two triangles s(x_c, x_f, x_e) and s(x_c, x_f', x_e) with
216  the faces f and f' belonging to F_e \cap F_c
217  Scan this quantity with the c2e connectivity */
218 
219  cs_real_t *dface_normal; /* Vector-valued normal for each dual face
220  * inside a cell associated to an edge */
221  cs_real_t *pvol_ec; /* Portion of volume surrounding an edge
222  * in each cell. Scanned with the c2e
223  * adjacency.
224  * Not always allocated. */
225 
227 
228  /* Vertex-based quantities */
229  /* ======================= */
230 
231  cs_lnum_t n_vertices; /* Local number of vertices */
232  cs_gnum_t n_g_vertices; /* Global number of vertices */
233 
234  cs_real_t *dcell_vol; /* Dual volume related to each vertex.
235  * Scanned with the c2v adjacency.
236  * Not always allocated. */
237 
238  const cs_real_t *vtx_coord; /* Shared with the cs_mesh_t structure */
239 
241 
242 /*============================================================================
243  * Global variables
244  *============================================================================*/
245 
246 /*============================================================================
247  * Public function prototypes
248  *============================================================================*/
249 
250 /*----------------------------------------------------------------------------*/
260 /*----------------------------------------------------------------------------*/
261 
262 static inline double
264  const cs_real_t *xb)
265 {
266  const double xab[3] = {xb[0] - qa.center[0],
267  xb[1] - qa.center[1],
268  xb[2] - qa.center[2]};
269  const double cp[3] = {qa.unitv[1]*xab[2] - qa.unitv[2]*xab[1],
270  qa.unitv[2]*xab[0] - qa.unitv[0]*xab[2],
271  qa.unitv[0]*xab[1] - qa.unitv[1]*xab[0]};
272 
273  return 0.5 * qa.meas * cs_math_3_norm(cp);
274 }
275 
276 /*----------------------------------------------------------------------------*/
282 /*----------------------------------------------------------------------------*/
283 
284 long long
286 
287 /*----------------------------------------------------------------------------*/
294 /*----------------------------------------------------------------------------*/
295 
296 void
297 cs_cdo_quantities_set(cs_flag_t option_flag);
298 
299 /*----------------------------------------------------------------------------*/
305 /*----------------------------------------------------------------------------*/
306 
307 void
309 
310 /*----------------------------------------------------------------------------*/
322 /*----------------------------------------------------------------------------*/
323 
326  const cs_mesh_quantities_t *mq,
327  const cs_cdo_connect_t *topo);
328 
329 /*----------------------------------------------------------------------------*/
337 /*----------------------------------------------------------------------------*/
338 
341 
342 /*----------------------------------------------------------------------------*/
349 /*----------------------------------------------------------------------------*/
350 
351 void
353 
354 /*----------------------------------------------------------------------------*/
361 /*----------------------------------------------------------------------------*/
362 
363 void
365 
366 /*----------------------------------------------------------------------------*/
378 /*----------------------------------------------------------------------------*/
379 
380 void
382  const cs_adjacency_t *c2f,
383  cs_real_t **p_pvol_fc);
384 
385 /*----------------------------------------------------------------------------*/
396 /*----------------------------------------------------------------------------*/
397 
398 void
400  const cs_adjacency_t *c2e,
401  cs_real_t **p_pvol_ec);
402 
403 /*----------------------------------------------------------------------------*/
411 /*----------------------------------------------------------------------------*/
412 
413 void
415  const cs_adjacency_t *c2v,
416  cs_real_t *dual_vol);
417 
418 /*----------------------------------------------------------------------------*/
430 /*----------------------------------------------------------------------------*/
431 
432 void
434  const cs_cdo_quantities_t *cdoq,
435  cs_lnum_t f_id,
436  cs_real_t tef[]);
437 
438 /*----------------------------------------------------------------------------*/
450 /*----------------------------------------------------------------------------*/
451 
452 void
454  const cs_cdo_quantities_t *cdoq,
455  cs_lnum_t bf_id,
456  cs_real_t tef[]);
457 
458 /*----------------------------------------------------------------------------*/
470 /*----------------------------------------------------------------------------*/
471 
472 void
474  const cs_cdo_quantities_t *cdoq,
475  cs_lnum_t f_id,
476  cs_real_t wvf[]);
477 
478 /*----------------------------------------------------------------------------*/
490 /*----------------------------------------------------------------------------*/
491 
492 void
494  const cs_cdo_quantities_t *cdoq,
495  cs_lnum_t bf_id,
496  cs_real_t wvf[]);
497 
498 /*----------------------------------------------------------------------------*/
508 /*----------------------------------------------------------------------------*/
509 
510 inline static const cs_real_t *
512  const cs_cdo_quantities_t *cdoq)
513 {
514  if (f_id < cdoq->n_i_faces) /* Interior face */
515  return cdoq->i_face_normal + 3*f_id;
516  else /* Border face */
517  return cdoq->b_face_normal + 3*(f_id - cdoq->n_i_faces);
518 }
519 
520 /*----------------------------------------------------------------------------*/
529 /*----------------------------------------------------------------------------*/
530 
531 inline static const cs_real_t *
533  const cs_cdo_quantities_t *cdoq)
534 {
535  if (f_id < cdoq->n_i_faces) /* Interior face */
536  return cdoq->i_face_center + 3*f_id;
537  else /* Border face */
538  return cdoq->b_face_center + 3*(f_id - cdoq->n_i_faces);
539 }
540 
541 /*----------------------------------------------------------------------------*/
550 /*----------------------------------------------------------------------------*/
551 
554  const cs_cdo_quantities_t *cdoq);
555 
556 /*----------------------------------------------------------------------------*/
566 /*----------------------------------------------------------------------------*/
567 
570  const cs_cdo_quantities_t *cdoq);
571 
572 /*----------------------------------------------------------------------------*/
581 /*----------------------------------------------------------------------------*/
582 
585  const cs_cdo_quantities_t *cdoq);
586 
587 /*----------------------------------------------------------------------------*/
596 /*----------------------------------------------------------------------------*/
597 
600  const cs_cdo_quantities_t *cdoq);
601 
602 /*----------------------------------------------------------------------------*/
610 /*----------------------------------------------------------------------------*/
611 
612 void
613 cs_quant_dump(FILE *f,
614  cs_lnum_t num,
615  const cs_quant_t q);
616 
617 /*----------------------------------------------------------------------------*/
618 
620 
621 #endif /* __CS_CDO_QUANTITIES_H__ */
const cs_real_t * b_face_center
Definition: cs_cdo_quantities.h:180
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:301
cs_real_t * dedge_vector
Definition: cs_cdo_quantities.h:192
Definition: cs_cdo_quantities.h:102
double center[3]
Definition: cs_cdo_quantities.h:128
cs_gnum_t n_g_cells
Definition: cs_cdo_quantities.h:147
void cs_cdo_quantities_compute_dual_volumes(const cs_cdo_quantities_t *cdoq, const cs_adjacency_t *c2v, cs_real_t *dual_vol)
Compute the dual volume surrounding each vertex.
Definition: cs_cdo_quantities.c:1481
cs_cdo_quantities_t * cs_cdo_quantities_build(const cs_mesh_t *m, const cs_mesh_quantities_t *mq, const cs_cdo_connect_t *topo)
Build a cs_cdo_quantities_t structure. Some quantities are shared with the cs_mesh_quantities_t struc...
Definition: cs_cdo_quantities.c:1053
cs_real_t * cell_centers
Definition: cs_cdo_quantities.h:148
cs_cdo_quantities_t * cs_cdo_quantities_free(cs_cdo_quantities_t *q)
Destroy a cs_cdo_quantities_t structure.
Definition: cs_cdo_quantities.c:1193
const cs_real_t * i_face_normal
Definition: cs_cdo_quantities.h:175
void cs_quant_dump(FILE *f, cs_lnum_t num, const cs_quant_t q)
Dump a cs_quant_t structure.
Definition: cs_cdo_quantities.c:1809
void cs_cdo_quantities_compute_pvol_ec(const cs_cdo_quantities_t *cdoq, const cs_adjacency_t *c2e, cs_real_t **p_pvol_ec)
Compute the portion of volume surrounding each edge of a cell The computed quantity is scanned with t...
Definition: cs_cdo_quantities.c:1423
cs_cdo_quantities_cell_center_algo_t
Type of algorithm used to compute the cell centers.
Definition: cs_cdo_quantities.h:67
cs_quant_info_t edge_info
Definition: cs_cdo_quantities.h:226
Definition: cs_mesh_adjacencies.h:68
cs_real_t * dcell_vol
Definition: cs_cdo_quantities.h:234
void cs_cdo_quantities_set_algo_ccenter(cs_cdo_quantities_cell_center_algo_t algo)
Set the type of algorithm to use for computing the cell center.
Definition: cs_cdo_quantities.c:1033
double h_max
Definition: cs_cdo_quantities.h:118
double meas_min
Definition: cs_cdo_quantities.h:115
void cs_cdo_quantities_set(cs_flag_t option_flag)
Set which quantities have to be computed. Additionnal quantities are added to cs_cdo_quantities_flag ...
Definition: cs_cdo_quantities.c:1019
#define BEGIN_C_DECLS
Definition: cs_defs.h:510
cs_lnum_t n_edges
Definition: cs_cdo_quantities.h:205
double meas
Definition: cs_cdo_quantities.h:126
Definition: cs_cdo_quantities.h:110
cs_cdo_quantities_bit_t
Bit values for setting which quantities to compute.
Definition: cs_cdo_quantities.h:94
double h_min
Definition: cs_cdo_quantities.h:117
Definition: cs_cdo_connect.h:61
Definition: cs_field_pointer.h:100
double vol_tot
Definition: cs_cdo_quantities.h:141
static double cs_compute_area_from_quant(const cs_quant_t qa, const cs_real_t *xb)
Compute the area of the triangle of base given by q (related to a segment) with apex located at xa...
Definition: cs_cdo_quantities.h:263
static const cs_real_t * cs_quant_get_face_center(cs_lnum_t f_id, const cs_cdo_quantities_t *cdoq)
Retrieve the face center for a primal face (interior or border)
Definition: cs_cdo_quantities.h:532
Definition: cs_cdo_quantities.h:69
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
Definition: cs_cdo_quantities.h:132
Definition: cs_defs.h:368
Definition: cs_mesh.h:84
cs_lnum_t n_faces
Definition: cs_cdo_quantities.h:156
cs_real_t * edge_vector
Definition: cs_cdo_quantities.h:208
void cs_cdo_quantities_compute_b_wvf(const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *cdoq, cs_lnum_t bf_id, cs_real_t wvf[])
Compute the weight related to each vertex of a face. This weight ensures a 2nd order approximation if...
Definition: cs_cdo_quantities.c:1645
const cs_real_t * i_face_surf
Definition: cs_cdo_quantities.h:177
void cs_cdo_quantities_compute_pvol_fc(const cs_cdo_quantities_t *cdoq, const cs_adjacency_t *c2f, cs_real_t **p_pvol_fc)
Compute the portion of volume surrounding each face of a cell. This volume corresponds to a pyramid w...
Definition: cs_cdo_quantities.c:1367
cs_real_t * dface_normal
Definition: cs_cdo_quantities.h:219
const cs_real_t * cell_vol
Definition: cs_cdo_quantities.h:149
void cs_cdo_quantities_dump(const cs_cdo_quantities_t *cdoq)
Dump a cs_cdo_quantities_t structure.
Definition: cs_cdo_quantities.c:1284
bool remove_boundary_faces
Definition: cs_cdo_quantities.h:137
Definition: cs_mesh_quantities.h:89
static const cs_real_t * cs_quant_get_face_vector_area(cs_lnum_t f_id, const cs_cdo_quantities_t *cdoq)
Retrieve the face vector which the face_area * face_normal for a primal face (interior or border) ...
Definition: cs_cdo_quantities.h:511
cs_quant_info_t face_info
Definition: cs_cdo_quantities.h:200
static cs_real_t cs_math_3_norm(const cs_real_t v[3])
Compute the euclidean norm of a vector of dimension 3.
Definition: cs_math.h:403
cs_lnum_t n_b_faces
Definition: cs_cdo_quantities.h:158
cs_gnum_t n_g_edges
Definition: cs_cdo_quantities.h:206
double meas_max
Definition: cs_cdo_quantities.h:116
cs_nvec3_t cs_quant_set_dedge_nvec(cs_lnum_t shift, const cs_cdo_quantities_t *cdoq)
Get the two normalized vector associated to a dual edge.
Definition: cs_cdo_quantities.c:1789
void cs_cdo_quantities_summary(const cs_cdo_quantities_t *quant)
Summarize generic information about the cdo mesh quantities.
Definition: cs_cdo_quantities.c:1233
const cs_real_t * i_face_center
Definition: cs_cdo_quantities.h:176
cs_lnum_t n_vertices
Definition: cs_cdo_quantities.h:231
cs_gnum_t n_g_faces
Definition: cs_cdo_quantities.h:159
Definition: cs_cdo_quantities.h:124
long long cs_cdo_quantities_get_time_perfo(void)
Retrieve the time elapsed to build the cs_cdo_quantities_t structure.
Definition: cs_cdo_quantities.c:1004
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:316
void cs_cdo_quantities_compute_b_tef(const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *cdoq, cs_lnum_t bf_id, cs_real_t tef[])
Compute the area of the triangles with basis each edge of the face and apex the face center...
Definition: cs_cdo_quantities.c:1554
const cs_real_t * b_face_normal
Definition: cs_cdo_quantities.h:179
double unitv[3]
Definition: cs_cdo_quantities.h:127
void cs_cdo_quantities_compute_i_wvf(const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *cdoq, cs_lnum_t f_id, cs_real_t wvf[])
Compute the weight related to each vertex of a face. This weight ensures a 2nd order approximation if...
Definition: cs_cdo_quantities.c:1596
cs_lnum_t n_i_faces
Definition: cs_cdo_quantities.h:157
const cs_real_t * b_face_surf
Definition: cs_cdo_quantities.h:181
cs_real_t * pvol_ec
Definition: cs_cdo_quantities.h:221
#define END_C_DECLS
Definition: cs_defs.h:511
unsigned short int cs_flag_t
Definition: cs_defs.h:324
cs_lnum_t n_cells
Definition: cs_cdo_quantities.h:146
cs_quant_t cs_quant_set_face(cs_lnum_t f_id, const cs_cdo_quantities_t *cdoq)
Define a cs_quant_t structure for a primal face (interior or border)
Definition: cs_cdo_quantities.c:1691
const cs_real_t * vtx_coord
Definition: cs_cdo_quantities.h:238
cs_nvec3_t cs_quant_set_edge_nvec(cs_lnum_t e_id, const cs_cdo_quantities_t *cdoq)
Get the normalized vector associated to a primal edge.
Definition: cs_cdo_quantities.c:1768
Definition: cs_cdo_quantities.h:71
Definition: cs_cdo_quantities.h:100
Definition: cs_cdo_quantities.h:70
void cs_cdo_quantities_compute_i_tef(const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *cdoq, cs_lnum_t f_id, cs_real_t tef[])
Compute the area of the triangles with basis each edge of the face and apex the face center...
Definition: cs_cdo_quantities.c:1512
cs_nvec3_t cs_quant_set_face_nvec(cs_lnum_t f_id, const cs_cdo_quantities_t *cdoq)
Retrieve the face surface and its unit normal vector for a primal face (interior or border) ...
Definition: cs_cdo_quantities.c:1743
cs_gnum_t n_g_vertices
Definition: cs_cdo_quantities.h:232
Definition: cs_cdo_quantities.h:101
Definition: cs_cdo_quantities.h:98
cs_quant_info_t cell_info
Definition: cs_cdo_quantities.h:151
cs_real_t * pvol_fc
Definition: cs_cdo_quantities.h:194
Definition: cs_cdo_quantities.h:99