programmer's documentation
cs_cdo_local.h
Go to the documentation of this file.
1 #ifndef __CS_CDO_LOCAL_H__
2 #define __CS_CDO_LOCAL_H__
3 
4 /*============================================================================
5  * Routines to handle low-level routines related to CDO local quantities:
6  * - local matrices (stored in dense format),
7  * - local quantities related to a cell.
8  *============================================================================*/
9 
10 /*
11  This file is part of Code_Saturne, a general-purpose CFD tool.
12 
13  Copyright (C) 1998-2018 EDF S.A.
14 
15  This program is free software; you can redistribute it and/or modify it under
16  the terms of the GNU General Public License as published by the Free Software
17  Foundation; either version 2 of the License, or (at your option) any later
18  version.
19 
20  This program is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23  details.
24 
25  You should have received a copy of the GNU General Public License along with
26  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
27  Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 */
29 
30 /*----------------------------------------------------------------------------
31  * Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "cs_cdo.h"
35 #include "cs_cdo_connect.h"
36 #include "cs_cdo_quantities.h"
37 #include "cs_cdo_toolbox.h"
38 
39 /*----------------------------------------------------------------------------*/
40 
42 
43 /*============================================================================
44  * Macro definitions
45  *============================================================================*/
46 
47 #define CS_CDO_LOCAL_PV (1 << 0) // 1: cache related to vertices
48 #define CS_CDO_LOCAL_PVQ (1 << 1) // 2: cache related to vertex quantities
49 #define CS_CDO_LOCAL_PE (1 << 2) // 4: cache related to edges
50 #define CS_CDO_LOCAL_PEQ (1 << 3) // 8: cache related to edge quantities
51 #define CS_CDO_LOCAL_DFQ (1 << 4) // 16: cache related to dual face quant.
52 #define CS_CDO_LOCAL_PF (1 << 5) // 32: cache related to face
53 #define CS_CDO_LOCAL_PFQ (1 << 6) // 64: cache related to face quantities
54 #define CS_CDO_LOCAL_DEQ (1 << 7) // 128: cache related to dual edge quant.
55 #define CS_CDO_LOCAL_EV (1 << 8) // 256: cache related to e2v connect.
56 #define CS_CDO_LOCAL_FE (1 << 9) // 512: cache related to f2e connect.
57 #define CS_CDO_LOCAL_FEQ (1 << 10) //1024: cache related to f2e quantities
58 #define CS_CDO_LOCAL_EF (1 << 11) //2048: cache related to e2f connect.
59 #define CS_CDO_LOCAL_EFQ (1 << 12) //4096: cache related to e2f quantities
60 #define CS_CDO_LOCAL_HFQ (1 << 13) //8192: cache related to the face pyramid
61 
62 /*============================================================================
63  * Type definitions
64  *============================================================================*/
65 
66 /* Structure which belongs to one thread */
67 typedef struct {
68 
69  /* Temporary buffers */
70  short int *ids; // local ids
71  double *values; // local values
72  cs_real_3_t *vectors; // local 3-dimensional vectors
73 
74  /* Structures used to build specific terms composing the algebraic system */
75  cs_locmat_t *hdg; // local hodge matrix for diffusion (may be NULL)
76  cs_locmat_t *loc; // local square matrix of size n_cell_dofs;
77  cs_locmat_t *aux; // auxiliary local square matrix of size n_cell_dofs;
78 
79  /* Specific members for the weakly enforcement of Dirichlet BCs (diffusion) */
80  double eig_ratio; // ratio of the eigenvalues of the diffusion tensor
81  double eig_max; // max. value among eigenvalues
82 
83  /* Store the cellwise value for the diffusion, time and reaction properties */
84  cs_real_33_t pty_mat; // If not isotropic
85  double pty_val; // If isotropic
86 
88 
89 /* Structure used to store a local system (cell-wise for instance) */
90 typedef struct {
91 
92  int n_dofs; // Number of Degrees of Freedom (DoFs) in this cell
93  cs_locmat_t *mat; // cellwise view of the system matrix
94  double *rhs; // cellwise view of the right-hand side
95  double *source; // cellwise view of the source term array
96  double *val_n; /* values of the unkown at the time t_n (the
97  last computed) */
98 
100 
101 /* Structure used to store local information about the boundary conditions */
102 typedef struct {
103 
104  short int n_bc_faces; // Number of border faces associated to a cell
105  short int *bf_ids; // List of face ids in the cell numbering
106  cs_flag_t *face_flag; // size n_bc_faces
107 
108  short int n_dofs; // Number of Degrees of Freedom (DoFs) in this cell
109  cs_flag_t *dof_flag; // size = number of DoFs
110 
111  /* Dirichlet BCs */
112  short int n_dirichlet; // Number of DoFs attached to a Dirichlet BC
113  double *dir_values; // Values of the Dirichlet BCs (size = n_dofs)
114 
115  /* Neumann BCs */
116  short int n_nhmg_neuman; /* Number of DoFs related to a non-homogeneous
117  Neumann boundary (BC) */
118  double *neu_values; // Values of the Neumnn BCs (size = n_dofs)
119 
120  /* Robin BCs */
121  short int n_robin; // Number of DoFs attached to a Robin BC
122  double *rob_values; // Values of the Robin BCs (size = 2*n_dofs)
123 
124 } cs_cell_bc_t;
125 
126 /* Structure used to get a better memory locality. Map existing structure
127  into a more compact one dedicated to a cell.
128  Arrays are allocated to n_max_vbyc or to n_max_ebyc.
129  Cell-wise numbering is based on the c2e and c2v connectivity.
130 */
131 
132 typedef struct {
133 
134  cs_flag_t flag; // indicate which quantities have to be defined
135  short int *kbuf; // buffer storing ids in a compact way
136 
137  /* Sizes used to allocate buffers */
138  short int n_max_vbyc;
139  short int n_max_ebyc;
140  short int n_max_fbyc;
141 
142  /* Cell information */
143  cs_lnum_t c_id; // id of related cell
144  cs_real_3_t xc; // coordinates of the cell center
145  double vol_c; // volume of the current cell
146 
147  /* Vertex information */
148  short int n_vc; // local number of vertices in a cell
149  cs_lnum_t *v_ids; // vertex ids on this rank
150  double *xv; // local vertex coordinates (copy)
151  double *wvc; // weight |vol_dc(v) cap vol_c|/|vol_c for each cell vtx
152 
153  /* Edge information */
154  short int n_ec; // local number of edges in a cell
155  cs_lnum_t *e_ids; // edge ids on this rank
156  cs_quant_t *edge; // local edge quantities (xe, length and unit vector)
157  cs_nvec3_t *dface; // local dual face quantities (area and unit normal)
158 
159  /* Face information */
160  short int n_fc; // local number of faces in a cell
161  cs_lnum_t *f_ids; // face ids on this rank
162  short int *f_sgn; // incidence number between f and c
163  double *hfc; // height of the pyramid of basis f and apex c
164  cs_quant_t *face; // local face quantities (xf, area and unit normal)
165  cs_nvec3_t *dedge; // local dual edge quantities (length and unit vector)
166 
167  /* Local e2v connectivity: size 2*n_ec (allocated to 2*n_max_ebyc) */
168  short int *e2v_ids; // cell-wise edge -> vertices connectivity
169  short int *e2v_sgn; // cell-wise edge -> vertices orientation (-1 or +1)
170 
171  /* Local f2e connectivity: size = 2*n_max_ebyc */
172  short int *f2e_idx; // size n_fc + 1
173  short int *f2e_ids; // size 2*n_max_ebyc
174  double *tef; // |tef| area of the triangle of base |e| and apex xf
175 
176  /* Local e2f connectivity: size 2*n_ec (allocated to 2*n_max_ebyc) */
177  short int *e2f_ids; // cell-wise edge -> faces connectivity
178  cs_nvec3_t *sefc; // portion of dual faces (2 triangles by edge)
179 
181 
182 /* Structure used to get a better memory locality. Map existing structure
183  into a more compact one dedicated to a face.
184  Arrays are allocated to n_max_vbyf (= n_max_ebyf).
185  Face-wise numbering is based on the f2e connectivity.
186 */
187 
188 typedef struct {
189 
190  short int n_max_vbyf; // = n_max_ebyf
191 
192  cs_lnum_t c_id; // id of related cell
193  cs_real_3_t xc; // pointer to the coordinates of the cell center
194 
195  /* Face information */
196  cs_lnum_t f_id; // local mesh face id
197  short int f_sgn; // incidence number between f and c
198  cs_quant_t face; // local face quantities (xf, area and unit normal)
199  cs_nvec3_t dedge; // local dual edge quantities (length and unit vector)
200 
201  /* Vertex information */
202  short int n_vf; // local number of vertices on this face
203  cs_lnum_t *v_ids; // vertex ids on this rank or in the cellwise numbering
204  double *xv; // local vertex coordinates (copy)
205  double *wvf; // weight related to each vertex
206 
207  /* Edge information */
208  short int n_ef; // local number of edges in on this face (= n_vf)
209  cs_lnum_t *e_ids; // edge ids on this rank or in the cellwise numbering
210  cs_quant_t *edge; // local edge quantities (xe, length and unit vector)
211  double *tef; // area of the triangle of base e and apex xf
212 
213  /* Local e2v connectivity: size 2*n_ec (allocated to 2*n_max_ebyf) */
214  short int *e2v_ids; // face-wise edge -> vertices connectivity
215 
217 
218 /*============================================================================
219  * Global variables
220  *============================================================================*/
221 
224 
225 /*============================================================================
226  * Public function prototypes
227  *============================================================================*/
228 
229 /*----------------------------------------------------------------------------*/
237 /*----------------------------------------------------------------------------*/
238 
240 cs_cell_sys_create(int n_max_ent);
241 
242 /*----------------------------------------------------------------------------*/
248 /*----------------------------------------------------------------------------*/
249 
250 void
252 
253 /*----------------------------------------------------------------------------*/
261 /*----------------------------------------------------------------------------*/
262 
263 void
264 cs_cell_sys_dump(const char msg[],
265  const cs_lnum_t c_id,
266  const cs_cell_sys_t *csys);
267 
268 /*----------------------------------------------------------------------------*/
277 /*----------------------------------------------------------------------------*/
278 
279 cs_cell_bc_t *
280 cs_cell_bc_create(int n_max_dofbyc,
281  int n_max_fbyc);
282 
283 /*----------------------------------------------------------------------------*/
289 /*----------------------------------------------------------------------------*/
290 
291 void
293 
294 /*----------------------------------------------------------------------------*/
304 /*----------------------------------------------------------------------------*/
305 
308  const cs_cdo_connect_t *connect);
309 
310 /*----------------------------------------------------------------------------*/
316 /*----------------------------------------------------------------------------*/
317 
318 void
320 
321 /*----------------------------------------------------------------------------*/
327 /*----------------------------------------------------------------------------*/
328 
329 void
331 
332 /*----------------------------------------------------------------------------*/
338 /*----------------------------------------------------------------------------*/
339 
340 void
342 
343 /*----------------------------------------------------------------------------*/
350 /*----------------------------------------------------------------------------*/
351 
352 void
354 
355 /*----------------------------------------------------------------------------*/
360 /*----------------------------------------------------------------------------*/
361 
362 void
364 
365 /*----------------------------------------------------------------------------*/
373 /*----------------------------------------------------------------------------*/
374 
376 cs_cdo_local_get_cell_mesh(int mesh_id);
377 
378 /*----------------------------------------------------------------------------*/
386 /*----------------------------------------------------------------------------*/
387 
389 cs_cdo_local_get_face_mesh(int mesh_id);
390 
391 /*----------------------------------------------------------------------------*/
399 /*----------------------------------------------------------------------------*/
400 
402 cs_cell_mesh_create(const cs_cdo_connect_t *connect);
403 
404 /*----------------------------------------------------------------------------*/
410 /*----------------------------------------------------------------------------*/
411 
412 void
414 
415 /*----------------------------------------------------------------------------*/
426 /*----------------------------------------------------------------------------*/
427 
428 void
430  cs_flag_t level,
431  const cs_cdo_connect_t *connect,
432  const cs_cdo_quantities_t *quant,
433  cs_cell_mesh_t *cm);
434 
435 /*----------------------------------------------------------------------------*/
443 /*----------------------------------------------------------------------------*/
444 
446 cs_face_mesh_create(short int n_max_vbyf);
447 
448 /*----------------------------------------------------------------------------*/
454 /*----------------------------------------------------------------------------*/
455 
456 void
458 
459 /*----------------------------------------------------------------------------*/
469 /*----------------------------------------------------------------------------*/
470 
471 void
473  cs_lnum_t f_id,
474  const cs_cdo_connect_t *connect,
475  const cs_cdo_quantities_t *quant,
476  cs_face_mesh_t *fm);
477 
478 /*----------------------------------------------------------------------------*/
488 /*----------------------------------------------------------------------------*/
489 
490 void
492  short int f,
493  cs_face_mesh_t *fm);
494 
495 /*----------------------------------------------------------------------------*/
496 
498 
499 #endif /* __CS_CDO_LOCAL_H__ */
cs_lnum_t * e_ids
Definition: cs_cdo_local.h:209
cs_face_mesh_t * cs_face_mesh_create(short int n_max_vbyf)
Allocate a cs_face_mesh_t structure.
Definition: cs_cdo_local.c:1098
void cs_cdo_local_initialize(const cs_cdo_connect_t *connect)
Allocate global structures related to a cs_cell_mesh_t and cs_face_mesh_t structures.
Definition: cs_cdo_local.c:427
void cs_cell_mesh_build(cs_lnum_t c_id, cs_flag_t level, const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *quant, cs_cell_mesh_t *cm)
Define a cs_cell_mesh_t structure for a given cell id. According to the requested level...
Definition: cs_cdo_local.c:825
double pty_val
Definition: cs_cdo_local.h:85
double * dir_values
Definition: cs_cdo_local.h:113
short int * e2f_ids
Definition: cs_cdo_local.h:177
double * tef
Definition: cs_cdo_local.h:174
double vol_c
Definition: cs_cdo_local.h:145
void cs_cell_mesh_free(cs_cell_mesh_t **p_cm)
Free a cs_cell_mesh_t structure.
Definition: cs_cdo_local.c:774
cs_lnum_t * f_ids
Definition: cs_cdo_local.h:161
cs_lnum_t f_id
Definition: cs_cdo_local.h:196
short int * ids
Definition: cs_cdo_local.h:70
double * wvc
Definition: cs_cdo_local.h:151
short int n_max_vbyf
Definition: cs_cdo_local.h:190
double * tef
Definition: cs_cdo_local.h:211
double * source
Definition: cs_cdo_local.h:95
short int n_dofs
Definition: cs_cdo_local.h:108
cs_cell_bc_t * cs_cell_bc_create(int n_max_dofbyc, int n_max_fbyc)
Allocate a cs_cell_bc_t structure.
Definition: cs_cdo_local.c:201
cs_locmat_t * hdg
Definition: cs_cdo_local.h:75
cs_cell_builder_t * cs_cell_builder_create(cs_space_scheme_t scheme, const cs_cdo_connect_t *connect)
Allocate and initialize a cs_cell_builder_t structure according to to the type of discretization whic...
Definition: cs_cdo_local.c:280
short int n_max_vbyc
Definition: cs_cdo_local.h:138
#define BEGIN_C_DECLS
Definition: cs_defs.h:451
short int * e2v_sgn
Definition: cs_cdo_local.h:169
cs_nvec3_t * dface
Definition: cs_cdo_local.h:157
short int n_dirichlet
Definition: cs_cdo_local.h:112
void cs_cdo_local_finalize(void)
Free global structures related to cs_cell_mesh_t and cs_face_mesh_t structures.
Definition: cs_cdo_local.c:462
double * val_n
Definition: cs_cdo_local.h:96
double * hfc
Definition: cs_cdo_local.h:163
short int n_vf
Definition: cs_cdo_local.h:202
cs_flag_t * dof_flag
Definition: cs_cdo_local.h:109
Definition: cs_cdo_local.h:132
double eig_ratio
Definition: cs_cdo_local.h:80
void cs_cell_builder_free(cs_cell_builder_t **p_cb)
Free a cs_cell_builder_t structure.
Definition: cs_cdo_local.c:398
Definition: cs_cdo_connect.h:56
short int * f2e_ids
Definition: cs_cdo_local.h:173
cs_lnum_t * v_ids
Definition: cs_cdo_local.h:203
double * xv
Definition: cs_cdo_local.h:150
short int n_ef
Definition: cs_cdo_local.h:208
cs_locmat_t * mat
Definition: cs_cdo_local.h:93
cs_nvec3_t * sefc
Definition: cs_cdo_local.h:178
short int n_bc_faces
Definition: cs_cdo_local.h:104
Definition: cs_cdo_quantities.h:102
cs_nvec3_t dedge
Definition: cs_cdo_local.h:199
Definition: cs_cdo.h:140
Definition: cs_cdo_local.h:90
short int n_max_ebyc
Definition: cs_cdo_local.h:139
cs_lnum_t * v_ids
Definition: cs_cdo_local.h:149
int n_dofs
Definition: cs_cdo_local.h:92
short int * f_sgn
Definition: cs_cdo_local.h:162
double * wvf
Definition: cs_cdo_local.h:205
short int n_nhmg_neuman
Definition: cs_cdo_local.h:116
double * rhs
Definition: cs_cdo_local.h:94
double eig_max
Definition: cs_cdo_local.h:81
cs_space_scheme_t
Definition: cs_cdo.h:148
Definition: cs_field_pointer.h:121
void cs_cell_mesh_dump(cs_cell_mesh_t *cm)
Dump a cs_cell_mesh_t structure.
Definition: cs_cdo_local.c:664
cs_lnum_t c_id
Definition: cs_cdo_local.h:143
cs_cell_mesh_t * cs_cdo_local_get_cell_mesh(int mesh_id)
Get a pointer to a cs_cell_mesh_t structure corresponding to mesh id.
Definition: cs_cdo_local.c:499
short int n_max_fbyc
Definition: cs_cdo_local.h:140
void cs_face_mesh_build_from_cell_mesh(const cs_cell_mesh_t *cm, short int f, cs_face_mesh_t *fm)
Define a cs_face_mesh_t structure for a given cell from a cs_cell_mesh_t structure. v_ids and e_ids are defined in the cell numbering given by cm.
Definition: cs_cdo_local.c:1307
short int * kbuf
Definition: cs_cdo_local.h:135
short int n_fc
Definition: cs_cdo_local.h:160
short int f_sgn
Definition: cs_cdo_local.h:197
cs_face_mesh_t * cs_cdo_local_get_face_mesh(int mesh_id)
Get a pointer to a cs_face_mesh_t structure corresponding to mesh id.
Definition: cs_cdo_local.c:518
cs_lnum_t * e_ids
Definition: cs_cdo_local.h:155
cs_locmat_t * aux
Definition: cs_cdo_local.h:77
void cs_cell_sys_free(cs_cell_sys_t **p_ls)
Free a cs_cell_sys_t structure.
Definition: cs_cdo_local.c:143
Definition: cs_cdo_local.h:102
cs_nvec3_t * dedge
Definition: cs_cdo_local.h:165
cs_quant_t * edge
Definition: cs_cdo_local.h:210
cs_cell_mesh_t ** cs_cdo_local_cell_meshes
Definition: cs_cdo_local.c:66
short int * e2v_ids
Definition: cs_cdo_local.h:214
cs_locmat_t * loc
Definition: cs_cdo_local.h:76
Definition: cs_cdo_local.h:67
cs_quant_t * face
Definition: cs_cdo_local.h:164
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:309
cs_flag_t flag
Definition: cs_cdo_local.h:134
cs_quant_t face
Definition: cs_cdo_local.h:198
cs_real_3_t xc
Definition: cs_cdo_local.h:144
cs_real_33_t pty_mat
Definition: cs_cdo_local.h:84
Definition: cs_cdo_quantities.h:81
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
void cs_cell_sys_dump(const char msg[], const cs_lnum_t c_id, const cs_cell_sys_t *csys)
Dump a local system for debugging purpose.
Definition: cs_cdo_local.c:170
short int * bf_ids
Definition: cs_cdo_local.h:105
short int n_vc
Definition: cs_cdo_local.h:148
double * neu_values
Definition: cs_cdo_local.h:118
cs_real_3_t xc
Definition: cs_cdo_local.h:193
void cs_cell_mesh_reset(cs_cell_mesh_t *cm)
Initialize to invalid values a cs_cell_mesh_t structure.
Definition: cs_cdo_local.c:599
#define END_C_DECLS
Definition: cs_defs.h:452
short int * e2v_ids
Definition: cs_cdo_local.h:168
unsigned short int cs_flag_t
Definition: cs_defs.h:299
short int n_robin
Definition: cs_cdo_local.h:121
cs_cell_mesh_t * cs_cell_mesh_create(const cs_cdo_connect_t *connect)
Allocate and initialize a cs_cell_mesh_t structure.
Definition: cs_cdo_local.c:537
cs_flag_t * face_flag
Definition: cs_cdo_local.h:106
short int n_ec
Definition: cs_cdo_local.h:154
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:315
double * values
Definition: cs_cdo_local.h:71
Definition: cs_cdo_local.h:188
cs_cell_sys_t * cs_cell_sys_create(int n_max_ent)
Allocate a cs_cell_sys_t structure.
Definition: cs_cdo_local.c:110
void cs_face_mesh_build(cs_lnum_t c_id, cs_lnum_t f_id, const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *quant, cs_face_mesh_t *fm)
Define a cs_face_mesh_t structure for a given face/cell id.
Definition: cs_cdo_local.c:1171
cs_real_3_t * vectors
Definition: cs_cdo_local.h:72
short int * f2e_idx
Definition: cs_cdo_local.h:172
cs_face_mesh_t ** cs_cdo_local_face_meshes
Definition: cs_cdo_local.c:67
cs_lnum_t c_id
Definition: cs_cdo_local.h:192
Definition: cs_cdo_toolbox.h:63
void cs_cell_bc_free(cs_cell_bc_t **p_cbc)
Free a cs_cell_bc_t structure.
Definition: cs_cdo_local.c:249
double * rob_values
Definition: cs_cdo_local.h:122
double * xv
Definition: cs_cdo_local.h:204
cs_quant_t * edge
Definition: cs_cdo_local.h:156
void cs_face_mesh_free(cs_face_mesh_t **p_fm)
Free a cs_face_mesh_t structure.
Definition: cs_cdo_local.c:1138