programmer's documentation
cs_internal_coupling.h
Go to the documentation of this file.
1 #ifndef __CS_INTERNAL_COUPLING_H__
2 #define __CS_INTERNAL_COUPLING_H__
3 
4 /*============================================================================
5  * Internal coupling: coupling for one instance of Code_Saturne
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2018 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  * PLE library headers
32  *----------------------------------------------------------------------------*/
33 
34 #include <ple_locator.h>
35 
36 /*----------------------------------------------------------------------------
37  * Local headers
38  *----------------------------------------------------------------------------*/
39 
40 #include "cs_defs.h"
41 
42 #include "cs_base.h"
43 #include "cs_matrix_assembler.h"
44 #include "cs_mesh.h"
45 #include "cs_parameters.h"
46 
47 /*----------------------------------------------------------------------------*/
48 
50 
51 /*=============================================================================
52  * Macro definitions
53  *============================================================================*/
54 
55 /*============================================================================
56  * Type definitions
57  *============================================================================*/
58 
59 
60 /* Internal coupling structure definition */
61 
62 typedef struct {
63 
64  /* Locator + tag for exchanging variables */
65  ple_locator_t *locator;
66  int *c_tag;
67 
68  /* Selection criteria for coupled domains */
71 
72  cs_lnum_t n_local; /* Number of faces */
73  cs_lnum_t *faces_local; /* Coupling boundary faces, numbered 0..n-1 */
74 
75  cs_lnum_t n_distant; /* Number of faces in faces_distant */
76  cs_lnum_t *faces_distant; /* Distant boundary faces associated with locator */
77 
78  /* face i is coupled in this entity if coupled_faces[i] = true */
80 
81  /* Geometrical weights around coupling interface */
83 
84  /* IJ vectors */
86 
87  /* OF vectors */
89 
90  /* Gradient reconstruction */
93 
94  /* User information */
95  char *namesca;
96 
98 
99 /*============================================================================
100  * Public function prototypes
101  *============================================================================*/
102 
103 /*----------------------------------------------------------------------------*/
109 /*----------------------------------------------------------------------------*/
110 
111 int
113 
114 /*----------------------------------------------------------------------------
115  * Define coupling volume using given criteria.
116  *
117  * Then, this volume must be seperated from the rest of the domain with a wall.
118  *
119  * parameters:
120  * mesh <-> pointer to mesh structure to modify
121  * criteria_cells <-- selection criteria for the first group of cells
122  * criteria_faces <-- selection criteria for faces to be joined
123  *----------------------------------------------------------------------------*/
124 
125 void
127  const char criteria_cells[],
128  const char criteria_faces[]);
129 
130 /*----------------------------------------------------------------------------
131  * Define coupling volume using given criteria. Then, this volume will be
132  * seperated from the rest of the domain with thin walls.
133  *
134  * parameters:
135  * mesh <-> pointer to mesh structure to modify
136  * criteria_cells <-- string criteria for the first group of cells
137  *----------------------------------------------------------------------------*/
138 
139 void
141  const char criteria_cells[]);
142 
143 /*----------------------------------------------------------------------------*/
149 /*----------------------------------------------------------------------------*/
150 
151 void
152 cs_internal_coupling_bcs(int bc_type[]);
153 
154 /*----------------------------------------------------------------------------
155  * Destruction of all internal coupling related structures.
156  *----------------------------------------------------------------------------*/
157 
158 void
160 
161 /*----------------------------------------------------------------------------
162  * Return the coupling associated with a given coupling_id.
163  *
164  * parameters:
165  * coupling_id <-> id associated with a coupling entity
166  *----------------------------------------------------------------------------*/
167 
169 cs_internal_coupling_by_id(int coupling_id);
170 
171 /*----------------------------------------------------------------------------
172  * Exchange quantities from distant to local (update local using distant)
173  *
174  * parameters:
175  * cpl <-- pointer to coupling entity
176  * stride <-- Stride (e.g. 1 for double, 3 for interleaved coordinates)
177  * distant <-- Distant values, size coupling->n_distant
178  * local --> Local values, size coupling->n_local
179  *----------------------------------------------------------------------------*/
180 
181 void
183  int stride,
184  cs_real_t distant[],
185  cs_real_t local[]);
186 
187 /*----------------------------------------------------------------------------
188  * Exchange variable between groups using cell id
189  *
190  * parameters:
191  * cpl <-- pointer to coupling entity
192  * stride <-- number of values (non interlaced) by entity
193  * tab <-- variable exchanged
194  * local --> local data
195  *----------------------------------------------------------------------------*/
196 
197 void
199  int stride,
200  const cs_real_t tab[],
201  cs_real_t local[]);
202 
203 /*----------------------------------------------------------------------------
204  * Exchange variable between groups using face id
205  *
206  * parameters:
207  * cpl <-- pointer to coupling entity
208  * stride <-- number of values (non interlaced) by entity
209  * tab <-- variable exchanged
210  * local --> local data
211  *----------------------------------------------------------------------------*/
212 
213 void
215  int stride,
216  const cs_real_t tab[],
217  cs_real_t local[]);
218 
219 /*----------------------------------------------------------------------------
220  * Modify LSQ COCG matrix to include internal coupling
221  *
222  * parameters:
223  * cpl <-- pointer to coupling entity
224  * cocg <-> cocg matrix modified
225  *----------------------------------------------------------------------------*/
226 
227 void
229  cs_real_33_t cocg[]);
230 
231 /*----------------------------------------------------------------------------
232  * Modify LSQ COCG matrix to include internal coupling
233  * when diffusivity is a tensor
234  *
235  * parameters:
236  * cpl <-- pointer to coupling entity
237  * c_weight <-- weigthing coefficients
238  * cocg <-> cocg matrix modified
239  *----------------------------------------------------------------------------*/
240 
241 void
243  const cs_real_t *c_weight,
244  cs_real_33_t cocg[]);
245 
246 /*----------------------------------------------------------------------------
247  * Modify iterative COCG matrix to include internal coupling
248  *
249  * parameters:
250  * cpl <-- pointer to coupling entity
251  * cocg <-> cocg matrix modified
252  *----------------------------------------------------------------------------*/
253 
254 void
256  cs_real_33_t cocg[]);
257 
258 /*----------------------------------------------------------------------------*/
262 /*----------------------------------------------------------------------------*/
263 
264 void
266 
267 /*----------------------------------------------------------------------------*/
271 /*----------------------------------------------------------------------------*/
272 
273 void
275 
276 /*----------------------------------------------------------------------------*/
285 /*----------------------------------------------------------------------------*/
286 
287 void
289  const cs_internal_coupling_t *cpl,
290  const cs_real_t c_weight[],
291  const int w_stride,
292  cs_real_4_t rhsv[]);
293 
294 /*----------------------------------------------------------------------------*/
304 /*----------------------------------------------------------------------------*/
305 
306 void
308  const cs_internal_coupling_t *cpl,
309  const cs_real_t c_weight[],
310  const int w_stride,
311  const cs_real_3_t pvar[],
312  cs_real_33_t rhs[]);
313 
314 /*----------------------------------------------------------------------------*/
324 /*----------------------------------------------------------------------------*/
325 
326 void
328  const cs_internal_coupling_t *cpl,
329  const cs_real_t c_weight[],
330  const int w_stride,
331  const cs_real_6_t pvar[],
332  cs_real_63_t rhs[]);
333 
334 /*----------------------------------------------------------------------------*/
345 /*----------------------------------------------------------------------------*/
346 
347 void
349  const cs_internal_coupling_t *cpl,
350  const cs_real_t c_weight[],
351  cs_real_3_t *restrict grad,
352  const cs_real_t pvar[],
353  cs_real_3_t rhs[]);
354 
355 /*----------------------------------------------------------------------------*/
366 /*----------------------------------------------------------------------------*/
367 
368 void
370  const cs_internal_coupling_t *cpl,
371  const cs_real_t c_weight[],
372  cs_real_33_t *restrict grad,
373  const cs_real_3_t pvar[],
374  cs_real_33_t rhs[]);
375 
376 /*----------------------------------------------------------------------------*/
387 /*----------------------------------------------------------------------------*/
388 
389 void
391  const cs_internal_coupling_t *cpl,
392  const cs_real_t c_weight[],
393  cs_real_63_t *restrict grad,
394  const cs_real_6_t pvar[],
395  cs_real_63_t rhs[]);
396 
397 /*----------------------------------------------------------------------------*/
406 /*----------------------------------------------------------------------------*/
407 
408 void
410  const cs_internal_coupling_t *cpl,
411  cs_real_3_t *restrict r_grad,
412  cs_real_3_t grad[]);
413 
414 /*----------------------------------------------------------------------------*/
423 /*----------------------------------------------------------------------------*/
424 
425 void
427  const cs_internal_coupling_t *cpl,
428  cs_real_33_t *restrict r_grad,
429  cs_real_33_t grad[]);
430 
431 /*----------------------------------------------------------------------------*/
440 /*----------------------------------------------------------------------------*/
441 
442 void
444  const cs_internal_coupling_t *cpl,
445  cs_real_63_t *restrict r_grad,
446  cs_real_63_t grad[]);
447 
448 /*----------------------------------------------------------------------------
449  * Addition to matrix-vector product in case of internal coupling.
450  *
451  * parameters:
452  * exclude_diag <-- extra diagonal flag
453  * f <-- associated field pointer
454  * x <-- vector x in m * x = y
455  * y <-> vector y in m * x = y
456  *----------------------------------------------------------------------------*/
457 
458 void
460  const cs_field_t *f,
461  const cs_real_t *restrict x,
462  cs_real_t *restrict y);
463 
464 /*----------------------------------------------------------------------------
465  * Add coupling term coordinates to matrix assembler.
466  *
467  * parameters:
468  * coupling_id
469  * r_g_id <-- global row ids (per cell)
470  * ma <-> matrix assembler
471  *----------------------------------------------------------------------------*/
472 
473 void
475  const cs_gnum_t *r_g_id,
477 
478 /*----------------------------------------------------------------------------
479  * Add coupling terms to matrix values assembly.
480  *
481  * parameters:
482  * f <-- associated field
483  * db_size <-- diagonal block size
484  * eb_size <-- extra-diagonal block size
485  * r_g_id <-- global row ids (per cell)
486  * mav <-> matrix values assembler
487  *----------------------------------------------------------------------------*/
488 
489 void
491  cs_lnum_t db_size,
492  cs_lnum_t eb_size,
493  const cs_gnum_t r_g_id[],
495 
496 /*----------------------------------------------------------------------------
497  * Return pointers to coupling components
498  *
499  * parameters:
500  * cpl <-- pointer to coupling entity
501  * n_local --> NULL or pointer to component n_local
502  * faces_local --> NULL or pointer to component faces_local
503  * n_distant --> NULL or pointer to component n_distant
504  * faces_distant --> NULL or pointer to component faces_distant
505  *----------------------------------------------------------------------------*/
506 
507 void
509  cs_lnum_t *n_local,
510  cs_lnum_t *faces_local[],
511  cs_lnum_t *n_distant,
512  cs_lnum_t *faces_distant[]);
513 
514 /*----------------------------------------------------------------------------
515  * Log information about a given internal coupling entity
516  *
517  * parameters:
518  * cpl <-- pointer to coupling entity
519  *----------------------------------------------------------------------------*/
520 
521 void
523 
524 /*----------------------------------------------------------------------------
525  * Print informations about all coupling entities
526  *
527  * parameters:
528  * cpl <-- pointer to coupling entity
529  *----------------------------------------------------------------------------*/
530 
531 void
533 
534 /*----------------------------------------------------------------------------
535  * Update components hint_* and hext_* using hbord
536  * in the coupling entity associated with given field_id
537  *
538  * parameters:
539  * field_id <-- id of the field
540  * hbord <-- array used to update hint_* and hext_*
541  *----------------------------------------------------------------------------*/
542 
543 void
544 cs_ic_set_exchcoeff(const int field_id,
545  const cs_real_t *hbord);
546 
547 /*----------------------------------------------------------------------------
548  * Add preprocessing operations required by coupling volume using given
549  * criteria.
550  *
551  * The volume is seperated from the rest of the domain with inserted
552  * boundaries.
553  *
554  * parameters:
555  * mesh <-> pointer to mesh structure to modify
556  *----------------------------------------------------------------------------*/
557 
558 void
560 
561 /*----------------------------------------------------------------------------
562  * Define face to face mappings for internal couplings.
563  *
564  * parameters:
565  * mesh <-> pointer to mesh structure to modify
566  *----------------------------------------------------------------------------*/
567 
568 void
570 
571 /*----------------------------------------------------------------------------
572  * Define coupling entity using given criteria.
573  *
574  * parameters:
575  * f_id <-- id of the field
576  *----------------------------------------------------------------------------*/
577 
578 void
580 
581 /*----------------------------------------------------------------------------*/
591 /*----------------------------------------------------------------------------*/
592 
593 void
595  const cs_internal_coupling_t *cpl,
596  const cs_real_t c_weight[],
597  const cs_real_t pvar[],
598  cs_real_3_t *restrict grad);
599 
600 /*----------------------------------------------------------------------------*/
610 /*----------------------------------------------------------------------------*/
611 
612 void
614  const cs_internal_coupling_t *cpl,
615  const cs_real_t c_weight[],
616  const cs_real_3_t pvar[],
617  cs_real_33_t *restrict grad);
618 
619 
620 /*----------------------------------------------------------------------------*/
630 /*----------------------------------------------------------------------------*/
631 
632 void
634  const cs_internal_coupling_t *cpl,
635  const cs_real_t c_weight[],
636  const cs_real_6_t pvar[],
637  cs_real_63_t *restrict grad);
638 
639 
640 /*----------------------------------------------------------------------------*/
641 
643 
644 #endif /* __CS_INTERNAL_COUPLING_H__ */
cs_real_3_t * offset_vect
Definition: cs_internal_coupling.h:88
void cs_internal_coupling_iterative_tensor_gradient(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], cs_real_63_t *restrict grad, const cs_real_6_t pvar[], cs_real_63_t rhs[])
Add internal coupling rhs contribution for iterative tensor gradient calculation. ...
Definition: cs_internal_coupling.c:1390
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:281
ple_locator_t * locator
Definition: cs_internal_coupling.h:65
#define restrict
Definition: cs_defs.h:122
void cs_internal_coupling_exchange_by_face_id(const cs_internal_coupling_t *cpl, int stride, const cs_real_t tab[], cs_real_t local[])
Definition: cs_internal_coupling.c:2083
int cs_internal_coupling_n_couplings(void)
Return number of defined internal couplings.
Definition: cs_internal_coupling.c:818
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:311
Field descriptor.
Definition: cs_field.h:124
struct _cs_matrix_assembler_values_t cs_matrix_assembler_values_t
Definition: cs_matrix_assembler.h:66
Definition: cs_internal_coupling.h:62
void cs_internal_coupling_lsq_cocg_weighted(const cs_internal_coupling_t *cpl, const cs_real_t *c_weight, cs_real_33_t cocg[])
Definition: cs_internal_coupling.c:1971
#define BEGIN_C_DECLS
Definition: cs_defs.h:461
void cs_internal_coupling_coupled_faces(const cs_internal_coupling_t *cpl, cs_lnum_t *n_local, cs_lnum_t *faces_local[], cs_lnum_t *n_distant, cs_lnum_t *faces_distant[])
Definition: cs_internal_coupling.c:2196
void cs_internal_coupling_it_cocg_contribution(const cs_internal_coupling_t *cpl, cs_real_33_t cocg[])
Definition: cs_internal_coupling.c:2028
cs_real_33_t * cocg_it
Definition: cs_internal_coupling.h:92
void cs_internal_coupling_add(cs_mesh_t *mesh, const char criteria_cells[], const char criteria_faces[])
Definition: cs_internal_coupling.c:835
void cs_internal_coupling_matrix_add_values(const cs_field_t *f, cs_lnum_t db_size, cs_lnum_t eb_size, const cs_gnum_t r_g_id[], cs_matrix_assembler_values_t *mav)
Definition: cs_internal_coupling.c:2413
void cs_internal_coupling_preprocess(cs_mesh_t *mesh)
Definition: cs_internal_coupling.c:2761
cs_real_3_t * ci_cj_vect
Definition: cs_internal_coupling.h:85
void cs_internal_coupling_setup(void)
Setup internal coupling related parameters.
Definition: cs_internal_coupling.c:2540
void cs_internal_coupling_iterative_scalar_gradient(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], cs_real_3_t *restrict grad, const cs_real_t pvar[], cs_real_3_t rhs[])
Add internal coupling rhs contribution for iterative gradient calculation.
Definition: cs_internal_coupling.c:1176
void cs_internal_coupling_finalize(void)
Definition: cs_internal_coupling.c:2061
void cs_internal_coupling_bcs(int bc_type[])
Impose wall BCs to internal coupled faces if not yet defined.
Definition: cs_internal_coupling.c:895
void cs_internal_coupling_initialize_tensor_gradient(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], const cs_real_6_t pvar[], cs_real_63_t *restrict grad)
Add contribution from coupled faces (internal coupling) to initialisation for iterative symmetric ten...
Definition: cs_internal_coupling.c:1090
void cs_internal_coupling_reconstruct_vector_gradient(const cs_internal_coupling_t *cpl, cs_real_33_t *restrict r_grad, cs_real_33_t grad[])
Add internal coupling contribution for reconstruction of the gradient of a vector.
Definition: cs_internal_coupling.c:1556
cs_real_t cs_real_4_t[4]
vector of 4 floating-point values
Definition: cs_defs.h:310
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
void cs_internal_coupling_add_entity(int f_id)
Definition: cs_internal_coupling.c:2799
cs_lnum_t n_local
Definition: cs_internal_coupling.h:72
void cs_internal_coupling_log(const cs_internal_coupling_t *cpl)
Definition: cs_internal_coupling.c:2707
void cs_internal_coupling_initialize_vector_gradient(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], const cs_real_3_t pvar[], cs_real_33_t *restrict grad)
Add contribution from coupled faces (internal coupling) to initialisation for iterative vector gradie...
Definition: cs_internal_coupling.c:1006
Definition: cs_mesh.h:63
void cs_internal_coupling_exchange_by_cell_id(const cs_internal_coupling_t *cpl, int stride, const cs_real_t tab[], cs_real_t local[])
Definition: cs_internal_coupling.c:2122
bool * coupled_faces
Definition: cs_internal_coupling.h:79
void cs_internal_coupling_lsq_tensor_gradient(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], const int w_stride, const cs_real_6_t pvar[], cs_real_63_t rhs[])
Add internal coupling rhs contribution for LSQ gradient calculation.
cs_lnum_t * faces_local
Definition: cs_internal_coupling.h:73
cs_lnum_t * faces_distant
Definition: cs_internal_coupling.h:76
cs_real_t * g_weight
Definition: cs_internal_coupling.h:82
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:309
void cs_internal_coupling_lsq_vector_gradient(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], const int w_stride, const cs_real_3_t pvar[], cs_real_33_t rhs[])
Add internal coupling rhs contribution for LSQ gradient calculation.
Definition: cs_internal_coupling.c:1802
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
void cs_internal_coupling_initialize_scalar_gradient(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], const cs_real_t pvar[], cs_real_3_t *restrict grad)
Add contribution from coupled faces (internal coupling) to initialisation for iterative scalar gradie...
Definition: cs_internal_coupling.c:925
char * cells_criteria
Definition: cs_internal_coupling.h:69
#define END_C_DECLS
Definition: cs_defs.h:462
void cs_internal_coupling_map(cs_mesh_t *mesh)
Definition: cs_internal_coupling.c:2781
void cs_internal_coupling_dump(void)
Definition: cs_internal_coupling.c:2734
void cs_internal_coupling_lsq_scalar_gradient(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], const int w_stride, cs_real_4_t rhsv[])
Add internal coupling rhs contribution for LSQ gradient calculation.
Definition: cs_internal_coupling.c:1680
struct _cs_matrix_assembler_t cs_matrix_assembler_t
Definition: cs_matrix_assembler.h:62
void cs_internal_coupling_initialize(void)
Initialize internal coupling related structures.
Definition: cs_internal_coupling.c:2618
void cs_internal_coupling_exchange_var(const cs_internal_coupling_t *cpl, int stride, cs_real_t distant[], cs_real_t local[])
Definition: cs_internal_coupling.c:2170
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:315
void cs_internal_coupling_reconstruct_tensor_gradient(const cs_internal_coupling_t *cpl, cs_real_63_t *restrict r_grad, cs_real_63_t grad[])
Add internal coupling contribution for reconstruction of the gradient of a symmetric tensor...
Definition: cs_internal_coupling.c:1618
void cs_ic_set_exchcoeff(const int field_id, const cs_real_t *hbord)
Definition: cs_internal_coupling.c:2828
cs_real_t cs_real_63_t[6][3]
Definition: cs_defs.h:321
cs_real_33_t * cocgb_s_lsq
Definition: cs_internal_coupling.h:91
void cs_internal_coupling_spmv_contribution(bool exclude_diag, const cs_field_t *f, const cs_real_t *restrict x, cs_real_t *restrict y)
Definition: cs_internal_coupling.c:2241
int * c_tag
Definition: cs_internal_coupling.h:66
void cs_internal_coupling_lsq_cocg_contribution(const cs_internal_coupling_t *cpl, cs_real_33_t cocg[])
Definition: cs_internal_coupling.c:1930
void cs_internal_coupling_iterative_vector_gradient(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], cs_real_33_t *restrict grad, const cs_real_3_t pvar[], cs_real_33_t rhs[])
Add internal coupling rhs contribution for iterative vector gradient calculation. ...
Definition: cs_internal_coupling.c:1282
void cs_internal_coupling_add_volume(cs_mesh_t *mesh, const char criteria_cells[])
Definition: cs_internal_coupling.c:864
void cs_internal_coupling_matrix_add_ids(int coupling_id, const cs_gnum_t *r_g_id, cs_matrix_assembler_t *ma)
Definition: cs_internal_coupling.c:2342
char * faces_criteria
Definition: cs_internal_coupling.h:70
cs_internal_coupling_t * cs_internal_coupling_by_id(int coupling_id)
Definition: cs_internal_coupling.c:2220
cs_lnum_t n_distant
Definition: cs_internal_coupling.h:75
Definition: mesh.f90:26
char * namesca
Definition: cs_internal_coupling.h:95
void cs_internal_coupling_reconstruct_scalar_gradient(const cs_internal_coupling_t *cpl, cs_real_3_t *restrict r_grad, cs_real_3_t grad[])
Add internal coupling contribution for reconstruction of the gradient of a scalar.