8.0
general documentation
Loading...
Searching...
No Matches
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-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_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
66
74
75
97
98typedef enum {
99
100 /* Set of geometrical quantities related to CDO schemes */
101
108
110
111
112/* Structure storing information about variation of entities across the
113 mesh for a given type of entity (cell, face and edge) */
114
115typedef struct {
116
117 /* Measure is either a volume for cells, a surface for faces or a length
118 for edges */
119
120 double meas_min; /* Min. value of the entity measure */
121 double meas_max; /* Max. value of the entity measure */
122 double h_min; /* Estimation of the min. value of the diameter */
123 double h_max; /* Estimation of the max. value of the diameter */
124
126
127/* For primal vector quantities (edge or face) */
128
129typedef struct {
130
131 double meas; /* length or area */
132 double unitv[3]; /* unitary vector: tangent or normal to the element */
133 double center[3];
134
135} cs_quant_t;
136
137typedef struct { /* Specific mesh quantities */
138
139 /* Keep the information about the removal of boundary faces in case of 2D
140 computations */
141
143
144 /* Global mesh quantities */
145
146 double vol_tot;
147
148 /* Cell-based quantities */
149 /* ===================== */
150
151 cs_lnum_t n_cells; /* Local number of cells */
152 cs_gnum_t n_g_cells; /* Global number of cells */
153 cs_real_t *cell_centers; /* May be shared according to options */
154 const cs_real_t *cell_vol; /* Shared with cs_mesh_quantities_t */
155
157
158 /* Face-based quantities */
159 /* ===================== */
160
161 cs_lnum_t n_faces; /* n_i_faces + n_b_faces */
162 cs_lnum_t n_i_faces; /* Local number of interior faces */
163 cs_lnum_t n_b_faces; /* Local number of border faces */
164 cs_gnum_t n_g_faces; /* Global number of faces */
165
166 /* Remark: cs_quant_t structure attached to a face (interior or border) can
167 be built on-the-fly calling the function cs_quant_set_face(f_id, cdoq).
168 See \ref cs_quant_set_face for more details.
169
170 In order to reduce the memory consumption one shares face quantities with
171 the ones defined in the legacy part and stored in the cs_mesh_quantities_t
172 structure that's why a distinction is made between interior and border
173 faces.
174
175 cs_nvec3_t structure associated to a face can also be built on-the-fly
176 using cs_quant_set_face_nvec(f_id, cdoq).
177 See \ref cs_quant_set_face_nvec for more details.
178 */
179
180 const cs_real_t *i_face_normal; /* Shared with cs_mesh_quantities_t */
181 const cs_real_t *i_face_center; /* Shared with cs_mesh_quantities_t */
182 const cs_real_t *i_face_surf; /* Shared with cs_mesh_quantities_t */
183
184 const cs_real_t *b_face_normal; /* Shared with cs_mesh_quantities_t */
185 const cs_real_t *b_face_center; /* Shared with cs_mesh_quantities_t */
186 const cs_real_t *b_face_surf; /* Shared with cs_mesh_quantities_t */
187
188 /* Remark: cs_nvec3_t structure attached to a dual edge can be built
189 on-the-fly to access to its length and its unit tangential vector using
190 the function cs_quant_set_dedge_nvec(shift, cdoq)
191
192 One recalls that a dual edge is associated to a primal face and is shared
193 with two cells for an interior face and shared with one cell for a
194 boundary face. Scan this quantity with the c2f connectivity.
195 */
196
197 cs_real_t *dedge_vector; /* Allocation to 3*c2f->idx[n_faces] */
198
199 cs_real_t *pvol_fc; /* Portion of volume surrounding a face
200 * in each cell. This is a pyramid of
201 * base the face and apex the cell center
202 * Scanned with the c2f adjacency.
203 * Not always allocated.
204 */
206
207 /* Edge-based quantities */
208 /* ===================== */
209
210 cs_lnum_t n_edges; /* Local number of edges */
211 cs_gnum_t n_g_edges; /* Global number of edges */
212
213 cs_real_t *edge_vector; /* Allocation to 3*n_edges
214 Norm of the vector is equal to the
215 distance between two vertices.
216 Unit vector is the tangential direction
217 attached to the edge */
218
219 /* For each edge e belonging to a cell c, the dual face is built from the
220 contributions of two triangles s(x_c, x_f, x_e) and s(x_c, x_f', x_e) with
221 the faces f and f' belonging to F_e \cap F_c
222 Scan this quantity with the c2e connectivity */
223
224 cs_real_t *dface_normal; /* Vector-valued normal for each dual face
225 * inside a cell associated to an edge */
226 cs_real_t *pvol_ec; /* Portion of volume surrounding an edge
227 * in each cell. Scanned with the c2e
228 * adjacency.
229 * Not always allocated. */
230
232
233 /* Vertex-based quantities */
234 /* ======================= */
235
236 cs_lnum_t n_vertices; /* Local number of vertices */
237 cs_gnum_t n_g_vertices; /* Global number of vertices */
238
239 cs_real_t *pvol_vc; /* Part of the dual cell associated to a
240 * vertex in each cell. These quantities
241 * are scanned thanks to the c2v
242 * adjancency structure */
243
244 const cs_real_t *vtx_coord; /* Coordinates of the mesh vertices.
245 * Shared with the cs_mesh_t structure */
246
247 /* Dual volume related to the dual cell associated in a one-to-one pairing to
248 * each vertex. This quantity has been synchronized in case of parallel
249 * computing. Size of the array = n_vertices. Not always allocated */
250
252
254
255/*============================================================================
256 * Global variables
257 *============================================================================*/
258
259/*============================================================================
260 * Public function prototypes
261 *============================================================================*/
262
263/*----------------------------------------------------------------------------*/
273/*----------------------------------------------------------------------------*/
274
275static inline double
277 const cs_real_t *xb)
278{
279 const double xab[3] = {xb[0] - qa.center[0],
280 xb[1] - qa.center[1],
281 xb[2] - qa.center[2]};
282 const double cp[3] = {qa.unitv[1]*xab[2] - qa.unitv[2]*xab[1],
283 qa.unitv[2]*xab[0] - qa.unitv[0]*xab[2],
284 qa.unitv[0]*xab[1] - qa.unitv[1]*xab[0]};
285
286 return 0.5 * qa.meas * cs_math_3_norm(cp);
287}
288
289/*----------------------------------------------------------------------------*/
295/*----------------------------------------------------------------------------*/
296
297long long
299
300/*----------------------------------------------------------------------------*/
307/*----------------------------------------------------------------------------*/
308
309void
311
312/*----------------------------------------------------------------------------*/
318/*----------------------------------------------------------------------------*/
319
320void
322
323/*----------------------------------------------------------------------------*/
335/*----------------------------------------------------------------------------*/
336
339 const cs_mesh_quantities_t *mq,
340 const cs_cdo_connect_t *topo);
341
342/*----------------------------------------------------------------------------*/
350/*----------------------------------------------------------------------------*/
351
354
355/*----------------------------------------------------------------------------*/
361/*----------------------------------------------------------------------------*/
362
363void
365
366/*----------------------------------------------------------------------------*/
372/*----------------------------------------------------------------------------*/
373
374void
376
377/*----------------------------------------------------------------------------*/
388/*----------------------------------------------------------------------------*/
389
390const cs_real_t *
392 const cs_adjacency_t *c2f);
393
394/*----------------------------------------------------------------------------*/
406/*----------------------------------------------------------------------------*/
407
408void
410 const cs_adjacency_t *c2f,
411 cs_real_t **p_pvol_fc);
412
413/*----------------------------------------------------------------------------*/
426/*----------------------------------------------------------------------------*/
427
428const cs_real_t *
430 const cs_adjacency_t *c2e);
431
432/*----------------------------------------------------------------------------*/
443/*----------------------------------------------------------------------------*/
444
445void
447 const cs_adjacency_t *c2e,
448 cs_real_t **p_pvol_ec);
449
450/*----------------------------------------------------------------------------*/
463/*----------------------------------------------------------------------------*/
464
465const cs_real_t *
467 const cs_cdo_connect_t *connect);
468
469/*----------------------------------------------------------------------------*/
482/*----------------------------------------------------------------------------*/
483
484void
486 const cs_cdo_connect_t *connect,
487 cs_real_t **p_dual_vol);
488
489/*----------------------------------------------------------------------------*/
501/*----------------------------------------------------------------------------*/
502
503void
505 const cs_cdo_quantities_t *cdoq,
506 cs_lnum_t f_id,
507 cs_real_t tef[]);
508
509/*----------------------------------------------------------------------------*/
521/*----------------------------------------------------------------------------*/
522
523void
525 const cs_cdo_quantities_t *cdoq,
526 cs_lnum_t bf_id,
527 cs_real_t tef[]);
528
529/*----------------------------------------------------------------------------*/
541/*----------------------------------------------------------------------------*/
542
543void
545 const cs_cdo_quantities_t *cdoq,
546 cs_lnum_t f_id,
547 cs_real_t wvf[]);
548
549/*----------------------------------------------------------------------------*/
561/*----------------------------------------------------------------------------*/
562
563void
565 const cs_cdo_quantities_t *cdoq,
566 cs_lnum_t bf_id,
567 cs_real_t wvf[]);
568
569/*----------------------------------------------------------------------------*/
579/*----------------------------------------------------------------------------*/
580
581inline static const cs_real_t *
583 const cs_cdo_quantities_t *cdoq)
584{
585 if (f_id < cdoq->n_i_faces) /* Interior face */
586 return cdoq->i_face_normal + 3*f_id;
587 else /* Border face */
588 return cdoq->b_face_normal + 3*(f_id - cdoq->n_i_faces);
589}
590
591/*----------------------------------------------------------------------------*/
600/*----------------------------------------------------------------------------*/
601
602inline static const cs_real_t *
604 const cs_cdo_quantities_t *cdoq)
605{
606 if (f_id < cdoq->n_i_faces) /* Interior face */
607 return cdoq->i_face_center + 3*f_id;
608 else /* Border face */
609 return cdoq->b_face_center + 3*(f_id - cdoq->n_i_faces);
610}
611
612/*----------------------------------------------------------------------------*/
621/*----------------------------------------------------------------------------*/
622
625 const cs_cdo_quantities_t *cdoq);
626
627/*----------------------------------------------------------------------------*/
637/*----------------------------------------------------------------------------*/
638
641 const cs_cdo_quantities_t *cdoq);
642
643/*----------------------------------------------------------------------------*/
652/*----------------------------------------------------------------------------*/
653
656 const cs_cdo_quantities_t *cdoq);
657
658/*----------------------------------------------------------------------------*/
667/*----------------------------------------------------------------------------*/
668
671 const cs_cdo_quantities_t *cdoq);
672
673/*----------------------------------------------------------------------------*/
681/*----------------------------------------------------------------------------*/
682
683void
684cs_quant_dump(FILE *f,
685 cs_lnum_t num,
686 const cs_quant_t q);
687
688/*----------------------------------------------------------------------------*/
689
691
692#endif /* __CS_CDO_QUANTITIES_H__ */
cs_cdo_quantities_bit_t
Bit values for setting which quantities to compute.
Definition cs_cdo_quantities.h:98
@ CS_CDO_QUANTITIES_CB_SCHEME
Definition cs_cdo_quantities.h:107
@ CS_CDO_QUANTITIES_EB_SCHEME
Definition cs_cdo_quantities.h:102
@ CS_CDO_QUANTITIES_HHO_SCHEME
Definition cs_cdo_quantities.h:104
@ CS_CDO_QUANTITIES_FB_SCHEME
Definition cs_cdo_quantities.h:103
@ CS_CDO_QUANTITIES_VCB_SCHEME
Definition cs_cdo_quantities.h:106
@ CS_CDO_QUANTITIES_VB_SCHEME
Definition cs_cdo_quantities.h:105
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:603
void cs_cdo_quantities_dump(const cs_cdo_quantities_t *cdoq)
Dump a cs_cdo_quantities_t structure.
Definition cs_cdo_quantities.c:1294
const cs_real_t * cs_cdo_quantities_get_pvol_fc(cs_cdo_quantities_t *cdoq, const cs_adjacency_t *c2f)
Compute or retrieve the portion of volume surrounding each face of a cell. This volume corresponds to...
Definition cs_cdo_quantities.c:1378
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:1818
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:582
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:1042
const cs_real_t * cs_cdo_quantities_get_dual_volumes(cs_cdo_quantities_t *cdoq, const cs_cdo_connect_t *connect)
Compute or retrieve the dual volume surrounding each vertex. The parallel operation (sum reduction) i...
Definition cs_cdo_quantities.c:1555
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:1916
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:1028
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:1895
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:1772
cs_cdo_quantities_t * cs_cdo_quantities_free(cs_cdo_quantities_t *cdoq)
Destroy a cs_cdo_quantities_t structure.
Definition cs_cdo_quantities.c:1203
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:1013
const cs_real_t * cs_cdo_quantities_get_pvol_ec(cs_cdo_quantities_t *cdoq, const cs_adjacency_t *c2e)
Compute or retrieve the portion of volume surrounding each edge of a cell. This volume corresponds to...
Definition cs_cdo_quantities.c:1464
void cs_cdo_quantities_summary(const cs_cdo_quantities_t *quant)
Summarize generic information about the cdo mesh quantities.
Definition cs_cdo_quantities.c:1244
void cs_cdo_quantities_compute_dual_volumes(const cs_cdo_quantities_t *cdoq, const cs_cdo_connect_t *connect, cs_real_t **p_dual_vol)
Compute the dual volume surrounding each vertex. The parallel operation (sum reduction) is performed ...
Definition cs_cdo_quantities.c:1584
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:1870
cs_cdo_quantities_cell_center_algo_t
Type of algorithm used to compute the cell centers.
Definition cs_cdo_quantities.h:67
@ CS_CDO_QUANTITIES_BARYC_CENTER
Definition cs_cdo_quantities.h:70
@ CS_CDO_QUANTITIES_SATURNE_CENTER
Definition cs_cdo_quantities.h:71
@ CS_CDO_QUANTITIES_MEANV_CENTER
Definition cs_cdo_quantities.h:69
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:1639
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 ...
Definition cs_cdo_quantities.c:1492
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:1936
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:1062
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:1681
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:1723
void cs_cdo_quantities_compute_pvol_fc(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:1406
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:276
#define BEGIN_C_DECLS
Definition cs_defs.h:509
double cs_real_t
Floating-point value.
Definition cs_defs.h:319
#define END_C_DECLS
Definition cs_defs.h:510
int cs_lnum_t
local mesh entity id
Definition cs_defs.h:313
unsigned short int cs_flag_t
Definition cs_defs.h:321
@ cp
Definition cs_field_pointer.h:100
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:424
Definition cs_mesh_adjacencies.h:68
Definition cs_cdo_connect.h:61
Definition cs_cdo_quantities.h:137
cs_gnum_t n_g_edges
Definition cs_cdo_quantities.h:211
const cs_real_t * b_face_surf
Definition cs_cdo_quantities.h:186
const cs_real_t * i_face_center
Definition cs_cdo_quantities.h:181
const cs_real_t * b_face_center
Definition cs_cdo_quantities.h:185
cs_lnum_t n_i_faces
Definition cs_cdo_quantities.h:162
cs_lnum_t n_faces
Definition cs_cdo_quantities.h:161
cs_lnum_t n_b_faces
Definition cs_cdo_quantities.h:163
cs_quant_info_t edge_info
Definition cs_cdo_quantities.h:231
cs_real_t * dual_vol
Definition cs_cdo_quantities.h:251
cs_gnum_t n_g_vertices
Definition cs_cdo_quantities.h:237
cs_lnum_t n_cells
Definition cs_cdo_quantities.h:151
cs_real_t * pvol_ec
Definition cs_cdo_quantities.h:226
cs_quant_info_t face_info
Definition cs_cdo_quantities.h:205
const cs_real_t * i_face_normal
Definition cs_cdo_quantities.h:180
const cs_real_t * b_face_normal
Definition cs_cdo_quantities.h:184
cs_gnum_t n_g_cells
Definition cs_cdo_quantities.h:152
double vol_tot
Definition cs_cdo_quantities.h:146
const cs_real_t * vtx_coord
Definition cs_cdo_quantities.h:244
cs_lnum_t n_vertices
Definition cs_cdo_quantities.h:236
cs_gnum_t n_g_faces
Definition cs_cdo_quantities.h:164
cs_real_t * cell_centers
Definition cs_cdo_quantities.h:153
cs_lnum_t n_edges
Definition cs_cdo_quantities.h:210
cs_real_t * pvol_fc
Definition cs_cdo_quantities.h:199
cs_real_t * pvol_vc
Definition cs_cdo_quantities.h:239
const cs_real_t * cell_vol
Definition cs_cdo_quantities.h:154
cs_quant_info_t cell_info
Definition cs_cdo_quantities.h:156
cs_real_t * dface_normal
Definition cs_cdo_quantities.h:224
bool remove_boundary_faces
Definition cs_cdo_quantities.h:142
const cs_real_t * i_face_surf
Definition cs_cdo_quantities.h:182
cs_real_t * edge_vector
Definition cs_cdo_quantities.h:213
cs_real_t * dedge_vector
Definition cs_cdo_quantities.h:197
Definition cs_mesh_quantities.h:92
Definition cs_mesh.h:85
Definition cs_defs.h:367
Definition cs_cdo_quantities.h:115
double meas_max
Definition cs_cdo_quantities.h:121
double meas_min
Definition cs_cdo_quantities.h:120
double h_min
Definition cs_cdo_quantities.h:122
double h_max
Definition cs_cdo_quantities.h:123
Definition cs_cdo_quantities.h:129
double meas
Definition cs_cdo_quantities.h:131
double center[3]
Definition cs_cdo_quantities.h:133
double unitv[3]
Definition cs_cdo_quantities.h:132