7.0
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-2021 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 
82 typedef enum {
83 
84  /* Set of geometrical quantities related to CDO schemes */
85 
86  CS_CDO_QUANTITIES_EB_SCHEME = 1<<0, /* = 1 */
87  CS_CDO_QUANTITIES_FB_SCHEME = 1<<1, /* = 2 */
88  CS_CDO_QUANTITIES_HHO_SCHEME = 1<<2, /* = 4 */
89  CS_CDO_QUANTITIES_VB_SCHEME = 1<<3, /* = 8 */
90  CS_CDO_QUANTITIES_VCB_SCHEME = 1<<4, /* = 16 */
91 
92  /* How to compute the cell center
93  ------------------------------ */
94 
95  CS_CDO_QUANTITIES_MEANV_CENTER = 1<<7, /* = 128 */
96  CS_CDO_QUANTITIES_BARYC_CENTER = 1<<8, /* = 256 */
98 
100 
101 
102 /* Structure storing information about variation of entities across the
103  mesh for a given type of entity (cell, face and edge) */
104 typedef struct {
105 
106  /* Measure is either a volume for cells, a surface for faces or a length
107  for edges */
108  double meas_min; /* Min. value of the entity measure */
109  double meas_max; /* Max. value of the entity measure */
110  double h_min; /* Estimation of the min. value of the diameter */
111  double h_max; /* Estimation of the max. value of the diameter */
112 
114 
115 /* For primal vector quantities (edge or face) */
116 typedef struct {
117 
118  double meas; /* length or area */
119  double unitv[3]; /* unitary vector: tangent or normal to the element */
120  double center[3];
121 
122 } cs_quant_t;
123 
124 typedef struct { /* Specific mesh quantities */
125 
126  /* Flag storing which quantities to compute and how to define the cell
127  * center */
129 
130  /* Global mesh quantities */
131  double vol_tot;
132 
133  /* Cell-based quantities */
134  /* ===================== */
135 
136  cs_lnum_t n_cells; /* Local number of cells */
137  cs_gnum_t n_g_cells; /* Global number of cells */
138  cs_real_t *cell_centers; /* May be shared according to options */
139  const cs_real_t *cell_vol; /* Shared with cs_mesh_quantities_t */
140 
142 
143  /* Face-based quantities */
144  /* ===================== */
145 
146  cs_lnum_t n_faces; /* n_i_faces + n_b_faces */
147  cs_gnum_t n_g_faces; /* Global number of faces */
148 
149  /* cs_quant_t structure attached to a face (interior or border) can be built
150  on-the-fly: cs_quant_get(flag, f_id, quant). In order to reduce the memory
151  consumption one shares face quantities with the ones defined in the legacy
152  part and stored in the cs_mesh_quantities_t structure */
153 
154  cs_lnum_t n_i_faces; /* Local number of interior faces */
155  const cs_real_t *i_face_normal; /* Shared with cs_mesh_quantities_t */
156  const cs_real_t *i_face_center; /* Shared with cs_mesh_quantities_t */
157  const cs_real_t *i_face_surf; /* Shared with cs_mesh_quantities_t */
158 
159  cs_lnum_t n_b_faces; /* Local number of border faces */
160  const cs_real_t *b_face_normal; /* Shared with cs_mesh_quantities_t */
161  const cs_real_t *b_face_center; /* Shared with cs_mesh_quantities_t */
162  const cs_real_t *b_face_surf; /* Shared with cs_mesh_quantities_t */
163 
164  /* cs_nvec3_t structure attached to a dual edge can be built on-the-fly to
165  access to its length and its unit tangential vector. One
166  recalls that a dual edge is associated to a primal face and is shared with
167  two cells if the face lies inside the domain and shared with one cell if
168  the face lies on the domain boundary.
169  Scan this quantity with the c2f connectivity
170  */
171 
172  cs_real_t *dedge_vector; /* Allocation to 3*c2f->idx[n_faces] */
173 
174  cs_real_t *pvol_fc; /* Portion of volume surrounding a face
175  * in each cell. This is a pyramid of
176  * base the face and apex the cell center
177  * Scanned with the c2f adjacency.
178  * Not always allocated.
179  */
181 
182  /* Edge-based quantities */
183  /* ===================== */
184 
185  cs_lnum_t n_edges; /* Local number of edges */
186  cs_gnum_t n_g_edges; /* Global number of edges */
187 
188  cs_real_t *edge_vector; /* Allocation to 3*n_edges
189  Norm of the vector is equal to the
190  distance between two vertices.
191  Unit vector is the tangential direction
192  attached to the edge */
193 
194  /* For each edge e belonging to a cell c, the dual face is built from the
195  contributions of two triangles s(x_c, x_f, x_e) and s(x_c, x_f', x_e) with
196  the faces f and f' belonging to F_e \cap F_c
197  Scan this quantity with the c2e connectivity */
198 
199  cs_real_t *dface_normal; /* Vector-valued normal for each dual face
200  * inside a cell associated to an edge */
201  cs_real_t *pvol_ec; /* Portion of volume surrounding an edge
202  * in each cell. Scanned with the c2e
203  * adjacency.
204  * Not always allocated. */
205 
207 
208  /* Vertex-based quantities */
209  /* ======================= */
210 
211  cs_lnum_t n_vertices; /* Local number of vertices */
212  cs_gnum_t n_g_vertices; /* Global number of vertices */
213 
214  cs_real_t *dcell_vol; /* Dual volume related to each vertex.
215  * Scanned with the c2v adjacency.
216  * Not always allocated.
217  */
218  const cs_real_t *vtx_coord; /* Shared with the cs_mesh_t structure */
219 
221 
222 /*============================================================================
223  * Global variables
224  *============================================================================*/
225 
226 /*============================================================================
227  * Public function prototypes
228  *============================================================================*/
229 
230 /*----------------------------------------------------------------------------*/
240 /*----------------------------------------------------------------------------*/
241 
242 static inline double
243 cs_compute_area_from_quant(const cs_quant_t qa,
244  const cs_real_t *xb)
245 {
246  const double xab[3] = {xb[0] - qa.center[0],
247  xb[1] - qa.center[1],
248  xb[2] - qa.center[2]};
249  const double cp[3] = {qa.unitv[1]*xab[2] - qa.unitv[2]*xab[1],
250  qa.unitv[2]*xab[0] - qa.unitv[0]*xab[2],
251  qa.unitv[0]*xab[1] - qa.unitv[1]*xab[0]};
252 
253  return 0.5 * qa.meas * cs_math_3_norm(cp);
254 }
255 
256 /*----------------------------------------------------------------------------*/
263 /*----------------------------------------------------------------------------*/
264 
265 void
266 cs_cdo_quantities_set(cs_flag_t option_flag);
267 
268 /*----------------------------------------------------------------------------*/
275 /*----------------------------------------------------------------------------*/
276 
277 void
279 
280 /*----------------------------------------------------------------------------*/
292 /*----------------------------------------------------------------------------*/
293 
296  const cs_mesh_quantities_t *mq,
297  const cs_cdo_connect_t *topo);
298 
299 /*----------------------------------------------------------------------------*/
307 /*----------------------------------------------------------------------------*/
308 
311 
312 /*----------------------------------------------------------------------------*/
319 /*----------------------------------------------------------------------------*/
320 
321 void
323 
324 /*----------------------------------------------------------------------------*/
331 /*----------------------------------------------------------------------------*/
332 
333 void
335 
336 /*----------------------------------------------------------------------------*/
348 /*----------------------------------------------------------------------------*/
349 
350 void
352  const cs_adjacency_t *c2f,
353  cs_real_t **p_pvol_fc);
354 
355 /*----------------------------------------------------------------------------*/
366 /*----------------------------------------------------------------------------*/
367 
368 void
370  const cs_adjacency_t *c2e,
371  cs_real_t **p_pvol_ec);
372 
373 /*----------------------------------------------------------------------------*/
381 /*----------------------------------------------------------------------------*/
382 
383 void
385  const cs_adjacency_t *c2v,
386  cs_real_t *dual_vol);
387 
388 /*----------------------------------------------------------------------------*/
400 /*----------------------------------------------------------------------------*/
401 
402 void
404  const cs_cdo_quantities_t *cdoq,
405  cs_lnum_t f_id,
406  cs_real_t tef[]);
407 
408 /*----------------------------------------------------------------------------*/
420 /*----------------------------------------------------------------------------*/
421 
422 void
424  const cs_cdo_quantities_t *cdoq,
425  cs_lnum_t bf_id,
426  cs_real_t tef[]);
427 
428 /*----------------------------------------------------------------------------*/
440 /*----------------------------------------------------------------------------*/
441 
442 void
444  const cs_cdo_quantities_t *cdoq,
445  cs_lnum_t f_id,
446  cs_real_t wvf[]);
447 
448 /*----------------------------------------------------------------------------*/
460 /*----------------------------------------------------------------------------*/
461 
462 void
464  const cs_cdo_quantities_t *cdoq,
465  cs_lnum_t bf_id,
466  cs_real_t wvf[]);
467 
468 /*----------------------------------------------------------------------------*/
478 /*----------------------------------------------------------------------------*/
479 
480 inline static const cs_real_t *
481 cs_quant_get_face_vector_area(cs_lnum_t f_id,
482  const cs_cdo_quantities_t *cdoq)
483 {
484  if (f_id < cdoq->n_i_faces) /* Interior face */
485  return cdoq->i_face_normal + 3*f_id;
486  else /* Border face */
487  return cdoq->b_face_normal + 3*(f_id - cdoq->n_i_faces);
488 }
489 
490 /*----------------------------------------------------------------------------*/
499 /*----------------------------------------------------------------------------*/
500 
501 inline static const cs_real_t *
502 cs_quant_get_face_center(cs_lnum_t f_id,
503  const cs_cdo_quantities_t *cdoq)
504 {
505  if (f_id < cdoq->n_i_faces) /* Interior face */
506  return cdoq->i_face_center + 3*f_id;
507  else /* Border face */
508  return cdoq->b_face_center + 3*(f_id - cdoq->n_i_faces);
509 }
510 
511 /*----------------------------------------------------------------------------*/
520 /*----------------------------------------------------------------------------*/
521 
524  const cs_cdo_quantities_t *cdoq);
525 
526 /*----------------------------------------------------------------------------*/
536 /*----------------------------------------------------------------------------*/
537 
540  const cs_cdo_quantities_t *cdoq);
541 
542 /*----------------------------------------------------------------------------*/
551 /*----------------------------------------------------------------------------*/
552 
555  const cs_cdo_quantities_t *cdoq);
556 
557 /*----------------------------------------------------------------------------*/
566 /*----------------------------------------------------------------------------*/
567 
570  const cs_cdo_quantities_t *cdoq);
571 
572 /*----------------------------------------------------------------------------*/
580 /*----------------------------------------------------------------------------*/
581 
582 void
583 cs_quant_dump(FILE *f,
584  cs_lnum_t num,
585  const cs_quant_t q);
586 
587 /*----------------------------------------------------------------------------*/
588 
590 
591 #endif /* __CS_CDO_QUANTITIES_H__ */
const cs_real_t * b_face_center
Definition: cs_cdo_quantities.h:161
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_real_t * dedge_vector
Definition: cs_cdo_quantities.h:172
Definition: cs_cdo_quantities.h:90
double center[3]
Definition: cs_cdo_quantities.h:120
cs_gnum_t n_g_cells
Definition: cs_cdo_quantities.h:137
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:1367
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:965
cs_real_t * cell_centers
Definition: cs_cdo_quantities.h:138
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:1095
const cs_real_t * i_face_normal
Definition: cs_cdo_quantities.h:155
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:1695
Definition: cs_cdo_quantities.h:95
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:1311
cs_quant_info_t edge_info
Definition: cs_cdo_quantities.h:206
Definition: cs_mesh_adjacencies.h:67
cs_real_t * dcell_vol
Definition: cs_cdo_quantities.h:214
cs_flag_t flag
Definition: cs_cdo_quantities.h:128
double h_max
Definition: cs_cdo_quantities.h:111
double meas_min
Definition: cs_cdo_quantities.h:108
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:930
#define BEGIN_C_DECLS
Definition: cs_defs.h:495
cs_lnum_t n_edges
Definition: cs_cdo_quantities.h:185
double meas
Definition: cs_cdo_quantities.h:118
Definition: cs_cdo_quantities.h:96
Definition: cs_cdo_quantities.h:104
cs_cdo_quantities_bit_t
Bit values for setting which quantities to compute.
Definition: cs_cdo_quantities.h:82
double h_min
Definition: cs_cdo_quantities.h:110
Definition: cs_cdo_connect.h:76
Definition: cs_field_pointer.h:106
double vol_tot
Definition: cs_cdo_quantities.h:131
double cs_real_t
Floating-point value.
Definition: cs_defs.h:307
Definition: cs_cdo_quantities.h:124
Definition: cs_defs.h:353
Definition: cs_mesh.h:84
cs_lnum_t n_faces
Definition: cs_cdo_quantities.h:146
cs_real_t * edge_vector
Definition: cs_cdo_quantities.h:188
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:1531
const cs_real_t * i_face_surf
Definition: cs_cdo_quantities.h:157
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:1257
cs_nvec3_t cs_quant_set_dedge_nvec(cs_lnum_t f_shift, const cs_cdo_quantities_t *cdoq)
Get the two normalized vector associated to a dual edge.
Definition: cs_cdo_quantities.c:1675
cs_real_t * dface_normal
Definition: cs_cdo_quantities.h:199
const cs_real_t * cell_vol
Definition: cs_cdo_quantities.h:139
void cs_cdo_quantities_dump(const cs_cdo_quantities_t *cdoq)
Dump a cs_cdo_quantities_t structure.
Definition: cs_cdo_quantities.c:1175
Definition: cs_mesh_quantities.h:89
Definition: cs_cdo_quantities.h:97
cs_quant_info_t face_info
Definition: cs_cdo_quantities.h:180
cs_lnum_t n_b_faces
Definition: cs_cdo_quantities.h:159
cs_gnum_t n_g_edges
Definition: cs_cdo_quantities.h:186
double meas_max
Definition: cs_cdo_quantities.h:109
void cs_cdo_quantities_summary(const cs_cdo_quantities_t *quant)
Summarize generic information about the cdo mesh quantities.
Definition: cs_cdo_quantities.c:1131
const cs_real_t * i_face_center
Definition: cs_cdo_quantities.h:156
cs_lnum_t n_vertices
Definition: cs_cdo_quantities.h:211
cs_gnum_t n_g_faces
Definition: cs_cdo_quantities.h:147
Definition: cs_cdo_quantities.h:116
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:301
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:1440
const cs_real_t * b_face_normal
Definition: cs_cdo_quantities.h:160
double unitv[3]
Definition: cs_cdo_quantities.h:119
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:1482
cs_lnum_t n_i_faces
Definition: cs_cdo_quantities.h:154
const cs_real_t * b_face_surf
Definition: cs_cdo_quantities.h:162
cs_real_t * pvol_ec
Definition: cs_cdo_quantities.h:201
#define END_C_DECLS
Definition: cs_defs.h:496
unsigned short int cs_flag_t
Definition: cs_defs.h:309
cs_lnum_t n_cells
Definition: cs_cdo_quantities.h:136
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:1577
const cs_real_t * vtx_coord
Definition: cs_cdo_quantities.h:218
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:1654
void cs_cdo_quantities_set_algo_ccenter(cs_cdo_quantities_bit_t algo)
Set the type of algorithm to use for computing the cell center (deprecated)
Definition: cs_cdo_quantities.c:945
Definition: cs_cdo_quantities.h:88
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:1398
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:1629
cs_gnum_t n_g_vertices
Definition: cs_cdo_quantities.h:212
Definition: cs_cdo_quantities.h:89
Definition: cs_cdo_quantities.h:86
cs_quant_info_t cell_info
Definition: cs_cdo_quantities.h:141
cs_real_t * pvol_fc
Definition: cs_cdo_quantities.h:174
Definition: cs_cdo_quantities.h:87