My Project
programmer's 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-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 */
57 typedef 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) */
74 typedef 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) */
86 typedef 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 
92 } cs_quant_t;
93 
94 typedef 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 
192 static 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 
214 void
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 
256 void
258 
259 /*----------------------------------------------------------------------------*/
266 /*----------------------------------------------------------------------------*/
267 
268 void
270 
271 /*----------------------------------------------------------------------------*/
279 /*----------------------------------------------------------------------------*/
280 
281 void
283  const cs_adjacency_t *c2v,
284  cs_real_t *dual_vol);
285 
286 /*----------------------------------------------------------------------------*/
298 /*----------------------------------------------------------------------------*/
299 
300 void
302  const cs_cdo_quantities_t *cdoq,
303  cs_lnum_t f_id,
304  cs_real_t tef[]);
305 
306 /*----------------------------------------------------------------------------*/
318 /*----------------------------------------------------------------------------*/
319 
320 void
322  const cs_cdo_quantities_t *cdoq,
323  cs_lnum_t bf_id,
324  cs_real_t tef[]);
325 
326 /*----------------------------------------------------------------------------*/
338 /*----------------------------------------------------------------------------*/
339 
340 void
342  const cs_cdo_quantities_t *cdoq,
343  cs_lnum_t f_id,
344  cs_real_t wvf[]);
345 
346 /*----------------------------------------------------------------------------*/
358 /*----------------------------------------------------------------------------*/
359 
360 void
362  const cs_cdo_quantities_t *cdoq,
363  cs_lnum_t bf_id,
364  cs_real_t wvf[]);
365 
366 /*----------------------------------------------------------------------------*/
376 /*----------------------------------------------------------------------------*/
377 
378 inline 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 
399 inline 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 
480 void
481 cs_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_t::n_cells
cs_lnum_t n_cells
Definition: cs_cdo_quantities.h:102
f_id
void const int * f_id
Definition: cs_gui.h:292
cs_cdo_quantities_set_algo_ccenter
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_math_3_norm
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
cs_cdo_quantities_t::edge_info
cs_quant_info_t edge_info
Definition: cs_cdo_quantities.h:158
cs_quant_info_t::meas_max
double meas_max
Definition: cs_cdo_quantities.h:79
cs_quant_set_face_nvec
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
CS_CDO_QUANTITIES_SATURNE_CENTER
Definition: cs_cdo_quantities.h:66
cs_cdo_quantities_compute_dual_volumes
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
cs_cdo_quantities_t::dedge_vector
cs_real_t * dedge_vector
Definition: cs_cdo_quantities.h:131
cs_cdo_quantities_t::b_face_center
const cs_real_t * b_face_center
Definition: cs_cdo_quantities.h:122
cs_cdo_quantities_t::n_edges
cs_lnum_t n_edges
Definition: cs_cdo_quantities.h:143
cs_cdo_quantities_t::i_face_normal
const cs_real_t * i_face_normal
Definition: cs_cdo_quantities.h:116
CS_CDO_QUANTITIES_N_CENTER_ALGOS
Definition: cs_cdo_quantities.h:68
cs_quant_info_t
Definition: cs_cdo_quantities.h:74
cs_quant_t::center
double center[3]
Definition: cs_cdo_quantities.h:90
cs_cdo_quantities_t::dcell_vol
cs_real_t * dcell_vol
Definition: cs_cdo_quantities.h:166
cs_cdo_quantities_build
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
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
cs_cdo_quantities_free
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_cdo_quantities_t::cell_centers
cs_real_t * cell_centers
Definition: cs_cdo_quantities.h:104
cs_quant_t::meas
double meas
Definition: cs_cdo_quantities.h:88
cs_quant_get_face_center
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
cs_quant_dump
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_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
CS_CDO_QUANTITIES_BARYC_CENTER
Definition: cs_cdo_quantities.h:63
cs_mesh_quantities.h
cs_mesh_quantities_t
Definition: cs_mesh_quantities.h:90
cs_compute_area_from_quant
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
cs_cdo_quantities_t::vol_tot
double vol_tot
Definition: cs_cdo_quantities.h:97
cs_quant_info_t::h_max
double h_max
Definition: cs_cdo_quantities.h:81
cs_cdo_quantities_compute_b_wvf
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
cs_mesh.h
cs_math.h
cs_cdo_quantities_t::i_face_center
const cs_real_t * i_face_center
Definition: cs_cdo_quantities.h:117
cs_gnum_t
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_quant_t::unitv
double unitv[3]
Definition: cs_cdo_quantities.h:89
cs_cdo_quantities_compute_i_wvf
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
cs_cdo_quantities_t::n_faces
cs_lnum_t n_faces
Definition: cs_cdo_quantities.h:125
cs_cdo_quantities_t
Definition: cs_cdo_quantities.h:94
cs_cdo_quantities_summary
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_cdo_quantities_t::edge_vector
cs_real_t * edge_vector
Definition: cs_cdo_quantities.h:146
cs_quant_get_face_vector_area
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_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_cdo_connect_t
Definition: cs_cdo_connect.h:74
cs_cdo_quantities_t::i_face_surf
const cs_real_t * i_face_surf
Definition: cs_cdo_quantities.h:118
cs_quant_set_face
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
cs_cdo_quantities_t::face_info
cs_quant_info_t face_info
Definition: cs_cdo_quantities.h:138
cs_adjacency_t
Definition: cs_mesh_adjacencies.h:90
cs_quant_set_dedge_nvec
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
cs_flag.h
cs_quant_set_edge_nvec
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
cs_cdo_quantities_t::cell_vol
cs_real_t * cell_vol
Definition: cs_cdo_quantities.h:105
cs_cdo_quantities_t::n_g_faces
cs_gnum_t n_g_faces
Definition: cs_cdo_quantities.h:126
cs_cdo_quantities_t::n_g_edges
cs_gnum_t n_g_edges
Definition: cs_cdo_quantities.h:144
cs_cdo_connect.h
cs_cdo_quantities_dump
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_cdo_quantities_t::vtx_coord
const cs_real_t * vtx_coord
Definition: cs_cdo_quantities.h:168
cs_cdo_quantities_compute_b_tef
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
cs_cdo_quantities_t::cell_info
cs_quant_info_t cell_info
Definition: cs_cdo_quantities.h:110
cs_cdo_quantities_algo_ccenter_t
cs_cdo_quantities_algo_ccenter_t
Definition: cs_cdo_quantities.h:57
cs_cdo_quantities_t::n_i_faces
cs_lnum_t n_i_faces
Definition: cs_cdo_quantities.h:115
cs_cdo_quantities_t::b_face_normal
const cs_real_t * b_face_normal
Definition: cs_cdo_quantities.h:121
cs_cdo_quantities_t::n_b_faces
cs_lnum_t n_b_faces
Definition: cs_cdo_quantities.h:120
cp
Definition: cs_field_pointer.h:106
cs_cdo_quantities_t::n_vertices
cs_lnum_t n_vertices
Definition: cs_cdo_quantities.h:163
cs_flag_t
unsigned short int cs_flag_t
Definition: cs_defs.h:304
cs_quant_t
Definition: cs_cdo_quantities.h:86
cs_cdo_quantities_compute_i_tef
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
cs_quant_info_t::h_min
double h_min
Definition: cs_cdo_quantities.h:80
cs_cdo_quantities_t::sface_normal
cs_real_t * sface_normal
Definition: cs_cdo_quantities.h:155
cs_nvec3_t
Definition: cs_defs.h:343
cs_cdo_quantities_t::b_face_surf
const cs_real_t * b_face_surf
Definition: cs_cdo_quantities.h:123
cs_mesh_t
Definition: cs_mesh.h:63
cs_base.h
CS_CDO_QUANTITIES_MEANV_CENTER
Definition: cs_cdo_quantities.h:60
cs_quant_info_t::meas_min
double meas_min
Definition: cs_cdo_quantities.h:78
cs_cdo_quantities_t::n_g_vertices
cs_gnum_t n_g_vertices
Definition: cs_cdo_quantities.h:164
cs_cdo_quantities_t::cell_flag
cs_flag_t * cell_flag
Definition: cs_cdo_quantities.h:106
cs_cdo_quantities_t::n_g_cells
cs_gnum_t n_g_cells
Definition: cs_cdo_quantities.h:103