My Project
programmer's 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-2019 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/* Information useful to get simpler algo. */
50#define CS_CDO_ORTHO (1 << 0) // Orthogonality condition is checked
51
52/*============================================================================
53 * Type definitions
54 *============================================================================*/
55
56/* Type of algorithm used to compute the cell center */
57typedef enum {
58
59 /* Center is computed as the mean of cell vertices */
61
62 /* Center is computed as the real cell barycenter */
64
65 /* Use the cell center computed in cs_mesh_quantities.c (Default behavior) */
67
69
71
72/* Structure storing information about variation of entities across the
73 mesh for a given type of entity (cell, face and edge) */
74typedef struct {
75
76 /* Measure is either a volume for cells, a surface for faces or a length
77 for edges */
78 double meas_min; /* Min. value of the entity measure */
79 double meas_max; /* Max. value of the entity measure */
80 double h_min; /* Estimation of the min. value of the diameter */
81 double h_max; /* Estimation of the max. value of the diameter */
82
84
85/* For primal vector quantities (edge or face) */
86typedef struct {
87
88 double meas; /* length or area */
89 double unitv[3]; /* unitary vector: tangent or normal to the element */
90 double center[3];
91
93
94typedef struct { /* Specific mesh quantities */
95
96 /* Global mesh quantities */
97 double vol_tot;
98
99 /* Cell-based quantities */
100 /* ===================== */
101
102 cs_lnum_t n_cells; /* Local number of cells */
103 cs_gnum_t n_g_cells; /* Global number of cells */
106 cs_flag_t *cell_flag; /* Flag attached to cell to associate
107 metadata like boundary cell or
108 orthogonality */
109
111
112 /* Face-based quantities */
113 /* ===================== */
114
115 cs_lnum_t n_i_faces; /* Local number of interior faces */
116 const cs_real_t *i_face_normal; /* Shared with cs_mesh_quantities_t */
117 const cs_real_t *i_face_center; /* Shared with cs_mesh_quantities_t */
118 const cs_real_t *i_face_surf; /* Shared with cs_mesh_quantities_t */
119
120 cs_lnum_t n_b_faces; /* Local number of border faces */
121 const cs_real_t *b_face_normal; /* Shared with cs_mesh_quantities_t */
122 const cs_real_t *b_face_center; /* Shared with cs_mesh_quantities_t */
123 const cs_real_t *b_face_surf; /* Shared with cs_mesh_quantities_t */
124
125 cs_lnum_t n_faces; /* n_i_faces + n_b_faces */
126 cs_gnum_t n_g_faces; /* Global number of faces */
127
128 /* cs_quant_t structure attached to a face (interior or border) is build
129 on-the-fly cs_quant_get(flag, f_id, quant) */
130
132
133 /* cs_nvec3_t structure attached to a dual edge is build on-the-fly
134 Dual edge quantities (length and unit vector)
135 Scan with the c2f connectivity
136 */
137
139
140 /* Edge-based quantities */
141 /* ===================== */
142
143 cs_lnum_t n_edges; /* Local number of edges */
144 cs_gnum_t n_g_edges; /* Global number of edges */
145
146 cs_real_t *edge_vector; /* norm of the vector is equal to the
147 distance between two vertices.
148 unit vector is the tangential direction
149 attached to the edge */
150
151 /* For each edge belonging to a cell, two contributions coming from 2
152 triangles s(x_cell, x_face, x_edge) for face in Face_edge are considered.
153 Scan with the c2e connectivity */
154
155 cs_real_t *sface_normal; /* 2 triangle-face normals by edge in a
156 cell */
157
159
160 /* Vertex-based quantities */
161 /* ======================= */
162
163 cs_lnum_t n_vertices; /* Local number of vertices */
164 cs_gnum_t n_g_vertices; /* Global number of vertices */
165
166 cs_real_t *dcell_vol; /* Dual volume related to each vertex.
167 Scan with the c2v connectivity */
168 const cs_real_t *vtx_coord; /* Shared with the cs_mesh_t structure */
169
171
172/*============================================================================
173 * Global variables
174 *============================================================================*/
175
176/*============================================================================
177 * Public function prototypes
178 *============================================================================*/
179
180/*----------------------------------------------------------------------------*/
190/*----------------------------------------------------------------------------*/
191
192static inline double
194 const cs_real_t *xb)
195{
196 const double xab[3] = {xb[0] - qa.center[0],
197 xb[1] - qa.center[1],
198 xb[2] - qa.center[2]};
199 const double cp[3] = {qa.unitv[1]*xab[2] - qa.unitv[2]*xab[1],
200 qa.unitv[2]*xab[0] - qa.unitv[0]*xab[2],
201 qa.unitv[0]*xab[1] - qa.unitv[1]*xab[0]};
202
203 return 0.5 * qa.meas * cs_math_3_norm(cp);
204}
205
206/*----------------------------------------------------------------------------*/
212/*----------------------------------------------------------------------------*/
213
214void
216
217/*----------------------------------------------------------------------------*/
227/*----------------------------------------------------------------------------*/
228
231 const cs_mesh_quantities_t *mq,
232 const cs_cdo_connect_t *topo);
233
234/*----------------------------------------------------------------------------*/
242/*----------------------------------------------------------------------------*/
243
246
247/*----------------------------------------------------------------------------*/
254/*----------------------------------------------------------------------------*/
255
256void
258
259/*----------------------------------------------------------------------------*/
266/*----------------------------------------------------------------------------*/
267
268void
270
271/*----------------------------------------------------------------------------*/
279/*----------------------------------------------------------------------------*/
280
281void
283 const cs_adjacency_t *c2v,
284 cs_real_t *dual_vol);
285
286/*----------------------------------------------------------------------------*/
298/*----------------------------------------------------------------------------*/
299
300void
302 const cs_cdo_quantities_t *cdoq,
303 cs_lnum_t f_id,
304 cs_real_t tef[]);
305
306/*----------------------------------------------------------------------------*/
318/*----------------------------------------------------------------------------*/
319
320void
322 const cs_cdo_quantities_t *cdoq,
323 cs_lnum_t bf_id,
324 cs_real_t tef[]);
325
326/*----------------------------------------------------------------------------*/
338/*----------------------------------------------------------------------------*/
339
340void
342 const cs_cdo_quantities_t *cdoq,
343 cs_lnum_t f_id,
344 cs_real_t wvf[]);
345
346/*----------------------------------------------------------------------------*/
358/*----------------------------------------------------------------------------*/
359
360void
362 const cs_cdo_quantities_t *cdoq,
363 cs_lnum_t bf_id,
364 cs_real_t wvf[]);
365
366/*----------------------------------------------------------------------------*/
376/*----------------------------------------------------------------------------*/
377
378inline static const cs_real_t *
380 const cs_cdo_quantities_t *cdoq)
381{
382 if (f_id < cdoq->n_i_faces) /* Interior face */
383 return cdoq->i_face_normal + 3*f_id;
384 else /* Border face */
385 return cdoq->b_face_normal + 3*(f_id - cdoq->n_i_faces);
386}
387
388/*----------------------------------------------------------------------------*/
397/*----------------------------------------------------------------------------*/
398
399inline static const cs_real_t *
401 const cs_cdo_quantities_t *cdoq)
402{
403 if (f_id < cdoq->n_i_faces) /* Interior face */
404 return cdoq->i_face_center + 3*f_id;
405 else /* Border face */
406 return cdoq->b_face_center + 3*(f_id - cdoq->n_i_faces);
407}
408
409/*----------------------------------------------------------------------------*/
418/*----------------------------------------------------------------------------*/
419
422 const cs_cdo_quantities_t *cdoq);
423
424/*----------------------------------------------------------------------------*/
434/*----------------------------------------------------------------------------*/
435
438 const cs_cdo_quantities_t *cdoq);
439
440/*----------------------------------------------------------------------------*/
449/*----------------------------------------------------------------------------*/
450
453 const cs_cdo_quantities_t *cdoq);
454
455/*----------------------------------------------------------------------------*/
464/*----------------------------------------------------------------------------*/
465
468 const cs_cdo_quantities_t *cdoq);
469
470/*----------------------------------------------------------------------------*/
478/*----------------------------------------------------------------------------*/
479
480void
481cs_quant_dump(FILE *f,
482 cs_lnum_t num,
483 const cs_quant_t q);
484
485/*----------------------------------------------------------------------------*/
486
488
489#endif /* __CS_CDO_QUANTITIES_H__ */
cs_cdo_quantities_algo_ccenter_t
Definition cs_cdo_quantities.h:57
@ CS_CDO_QUANTITIES_BARYC_CENTER
Definition cs_cdo_quantities.h:63
@ CS_CDO_QUANTITIES_SATURNE_CENTER
Definition cs_cdo_quantities.h:66
@ CS_CDO_QUANTITIES_N_CENTER_ALGOS
Definition cs_cdo_quantities.h:68
@ CS_CDO_QUANTITIES_MEANV_CENTER
Definition cs_cdo_quantities.h:60
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:400
void cs_cdo_quantities_dump(const cs_cdo_quantities_t *cdoq)
Dump a cs_cdo_quantities_t structure.
Definition cs_cdo_quantities.c:1218
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:1506
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:1296
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:379
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:1122
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:1583
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:1460
void cs_cdo_quantities_set_algo_ccenter(cs_cdo_quantities_algo_ccenter_t algo)
Set the type of algorithm to use for computing the cell center.
Definition cs_cdo_quantities.c:894
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:1604
void cs_cdo_quantities_summary(const cs_cdo_quantities_t *quant)
Summarize generic information about the cdo mesh quantities.
Definition cs_cdo_quantities.c:1158
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:1558
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:1327
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:1624
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.
Definition cs_cdo_quantities.c:912
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:1369
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:1411
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:193
#define BEGIN_C_DECLS
Definition cs_defs.h:467
double cs_real_t
Floating-point value.
Definition cs_defs.h:302
#define END_C_DECLS
Definition cs_defs.h:468
int cs_lnum_t
local mesh entity id
Definition cs_defs.h:298
unsigned short int cs_flag_t
Definition cs_defs.h:304
@ cp
Definition cs_field_pointer.h:106
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:372
Definition cs_mesh_adjacencies.h:90
Definition cs_cdo_connect.h:74
Definition cs_cdo_quantities.h:94
cs_gnum_t n_g_edges
Definition cs_cdo_quantities.h:144
const cs_real_t * b_face_surf
Definition cs_cdo_quantities.h:123
cs_real_t * sface_normal
Definition cs_cdo_quantities.h:155
cs_flag_t * cell_flag
Definition cs_cdo_quantities.h:106
const cs_real_t * i_face_center
Definition cs_cdo_quantities.h:117
const cs_real_t * b_face_center
Definition cs_cdo_quantities.h:122
cs_real_t * dcell_vol
Definition cs_cdo_quantities.h:166
cs_lnum_t n_i_faces
Definition cs_cdo_quantities.h:115
cs_lnum_t n_faces
Definition cs_cdo_quantities.h:125
cs_lnum_t n_b_faces
Definition cs_cdo_quantities.h:120
cs_quant_info_t edge_info
Definition cs_cdo_quantities.h:158
cs_gnum_t n_g_vertices
Definition cs_cdo_quantities.h:164
cs_lnum_t n_cells
Definition cs_cdo_quantities.h:102
cs_real_t * cell_vol
Definition cs_cdo_quantities.h:105
cs_quant_info_t face_info
Definition cs_cdo_quantities.h:138
const cs_real_t * i_face_normal
Definition cs_cdo_quantities.h:116
const cs_real_t * b_face_normal
Definition cs_cdo_quantities.h:121
cs_gnum_t n_g_cells
Definition cs_cdo_quantities.h:103
double vol_tot
Definition cs_cdo_quantities.h:97
const cs_real_t * vtx_coord
Definition cs_cdo_quantities.h:168
cs_lnum_t n_vertices
Definition cs_cdo_quantities.h:163
cs_gnum_t n_g_faces
Definition cs_cdo_quantities.h:126
cs_real_t * cell_centers
Definition cs_cdo_quantities.h:104
cs_lnum_t n_edges
Definition cs_cdo_quantities.h:143
cs_quant_info_t cell_info
Definition cs_cdo_quantities.h:110
const cs_real_t * i_face_surf
Definition cs_cdo_quantities.h:118
cs_real_t * edge_vector
Definition cs_cdo_quantities.h:146
cs_real_t * dedge_vector
Definition cs_cdo_quantities.h:131
Definition cs_mesh_quantities.h:90
Definition cs_mesh.h:63
Definition cs_defs.h:343
Definition cs_cdo_quantities.h:74
double meas_max
Definition cs_cdo_quantities.h:79
double meas_min
Definition cs_cdo_quantities.h:78
double h_min
Definition cs_cdo_quantities.h:80
double h_max
Definition cs_cdo_quantities.h:81
Definition cs_cdo_quantities.h:86
double meas
Definition cs_cdo_quantities.h:88
double center[3]
Definition cs_cdo_quantities.h:90
double unitv[3]
Definition cs_cdo_quantities.h:89