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_base.h"
41 #include "cs_mesh.h"
42 #include "cs_parameters.h"
43 
44 /*----------------------------------------------------------------------------*/
45 
47 
48 /*=============================================================================
49  * Macro definitions
50  *============================================================================*/
51 
52 /*============================================================================
53  * Type definitions
54  *============================================================================*/
55 
56 
57 /* Internal coupling structure definition */
58 
59 typedef struct {
60 
61  /* Locator + tag for exchanging variables */
62  ple_locator_t *locator;
63  int *c_tag;
64 
65  /* Selection criterias for coupled domains */
68 
69  cs_lnum_t n_local; /* Number of faces */
70  cs_lnum_t *faces_local; /* Coupling boundary faces, numbered 0..n-1 */
71 
72  cs_lnum_t n_distant; /* Number of faces in faces_distant */
73  cs_lnum_t *faces_distant; /* Distant boundary faces associated with locator */
74 
75  /* face i is coupled in this entity if coupled_faces[i] = true */
77 
78  /* Geometrical weights around coupling interface */
80 
81  /* IJ vectors */
83 
84  /* OF vectors */
86 
87  /* Gradient reconstruction */
90 
91  /* User information */
92  char *namesca;
93 
95 
96 /*============================================================================
97  * Public function prototypes
98  *============================================================================*/
99 
100 /*----------------------------------------------------------------------------*/
106 /*----------------------------------------------------------------------------*/
107 
108 void
109 cs_internal_coupling_bcs(int bc_type[]);
110 
111 /*----------------------------------------------------------------------------
112  * Destruction of all internal coupling related structures.
113  *----------------------------------------------------------------------------*/
114 
115 void
117 
118 /*----------------------------------------------------------------------------
119  * Return the coupling associated with a given coupling_id.
120  *
121  * parameters:
122  * coupling_id <-> id associated with a coupling entity
123  *----------------------------------------------------------------------------*/
124 
126 cs_internal_coupling_by_id(int coupling_id);
127 
128 /*----------------------------------------------------------------------------
129  * Exchange quantities from distant to local (update local using distant)
130  *
131  * parameters:
132  * cpl <-- pointer to coupling entity
133  * stride <-- Stride (e.g. 1 for double, 3 for interleaved coordinates)
134  * distant <-- Distant values, size coupling->n_distant
135  * local --> Local values, size coupling->n_local
136  *----------------------------------------------------------------------------*/
137 
138 void
140  int stride,
141  cs_real_t distant[],
142  cs_real_t local[]);
143 
144 /*----------------------------------------------------------------------------
145  * Exchange variable between groups using cell id
146  *
147  * parameters:
148  * cpl <-- pointer to coupling entity
149  * stride <-- number of values (non interlaced) by entity
150  * tab <-- variable exchanged
151  * local --> local data
152  *----------------------------------------------------------------------------*/
153 
154 void
156  int stride,
157  const cs_real_t tab[],
158  cs_real_t local[]);
159 
160 /*----------------------------------------------------------------------------
161  * Exchange variable between groups using face id
162  *
163  * parameters:
164  * cpl <-- pointer to coupling entity
165  * stride <-- number of values (non interlaced) by entity
166  * tab <-- variable exchanged
167  * local --> local data
168  *----------------------------------------------------------------------------*/
169 
170 void
172  int stride,
173  const cs_real_t tab[],
174  cs_real_t local[]);
175 
176 /*----------------------------------------------------------------------------
177  * Modify LSQ COCG matrix to include internal coupling
178  *
179  * parameters:
180  * cpl <-- pointer to coupling entity
181  * cocg <-> cocg matrix modified
182  *----------------------------------------------------------------------------*/
183 
184 void
186  cs_real_33_t cocg[]);
187 
188 /*----------------------------------------------------------------------------
189  * Modify LSQ COCG matrix to include internal coupling
190  * when diffusivity is a tensor
191  *
192  * parameters:
193  * cpl <-- pointer to coupling entity
194  * c_weight <-- weigthing coefficients
195  * cocg <-> cocg matrix modified
196  *----------------------------------------------------------------------------*/
197 
198 void
200  const cs_real_t *c_weight,
201  cs_real_33_t cocg[]);
202 
203 /*----------------------------------------------------------------------------
204  * Modify iterative COCG matrix to include internal coupling
205  *
206  * parameters:
207  * cpl <-- pointer to coupling entity
208  * cocg <-> cocg matrix modified
209  *----------------------------------------------------------------------------*/
210 
211 void
213  cs_real_33_t cocg[]);
214 
215 /*----------------------------------------------------------------------------
216  * Initialize internal coupling related structures.
217  *
218  *----------------------------------------------------------------------------*/
219 
220 void
222 
223 /*----------------------------------------------------------------------------
224  * Add internal coupling rhs contribution for LSQ gradient calculation
225  *
226  * parameters:
227  * cpl <-- pointer to coupling entity
228  * c_weight <-- weighted gradient coefficient variable, or NULL
229  * w_stride <-- stride of weighting coefficient
230  * rhsv <-> rhs contribution modified
231  *----------------------------------------------------------------------------*/
232 
233 void
235  const cs_real_t c_weight[],
236  const int w_stride,
237  cs_real_4_t rhsv[]);
238 
239 /*----------------------------------------------------------------------------
240  * Add internal coupling rhs contribution for iterative gradient calculation
241  *
242  * parameters:
243  * cpl <-- pointer to coupling entity
244  * c_weight <-- weighted gradient coefficient variable, or NULL
245  * grad <-- pointer to gradient
246  * pvar <-- pointer to variable
247  * rhs <-> pointer to rhs contribution
248  *----------------------------------------------------------------------------*/
249 
250 void
252  const cs_real_t c_weight[],
253  cs_real_3_t *restrict grad,
254  const cs_real_t pvar[],
255  cs_real_3_t rhs[]);
256 
257 /*----------------------------------------------------------------------------
258  * Add internal coupling contribution for reconstruction of the gradient of a
259  * scalar.
260  *
261  * parameters:
262  * cpl <-- pointer to coupling entity
263  * r_grad <-- pointer to reconstruction gradient
264  * grad <-> pointer to gradient to be reconstructed
265  *----------------------------------------------------------------------------*/
266 
267 void
269  cs_real_3_t *restrict r_grad,
270  cs_real_3_t grad[]);
271 
272 /*----------------------------------------------------------------------------
273  * Modify matrix-vector product in case of internal coupling
274  *
275  * parameters:
276  * exclude_diag <-- extra diagonal flag
277  * matrix <-- matrix m in m * x = y
278  * x <-- vector x in m * x = y
279  * y <-> vector y in m * x = y
280  *----------------------------------------------------------------------------*/
281 
282 void
284  void *input,
285  const cs_real_t *restrict x,
286  cs_real_t *restrict y);
287 
288 /*----------------------------------------------------------------------------
289  * Add contribution from coupled faces (internal coupling) to polynomial
290  * preconditionning.
291  *
292  * This function is common to most solvers
293  *
294  * parameters:
295  * input <-- input
296  * ad <-> diagonal part of linear equation matrix
297  *----------------------------------------------------------------------------*/
298 
299 void
301  cs_real_t *ad);
302 
303 /*----------------------------------------------------------------------------
304  * Return pointers to coupling components
305  *
306  * parameters:
307  * cpl <-- pointer to coupling entity
308  * n_local --> NULL or pointer to component n_local
309  * faces_local --> NULL or pointer to component faces_local
310  * n_distant --> NULL or pointer to component n_distant
311  * faces_distant --> NULL or pointer to component faces_distant
312  *----------------------------------------------------------------------------*/
313 
314 void
316  cs_lnum_t *n_local,
317  cs_lnum_t *faces_local[],
318  cs_lnum_t *n_distant,
319  cs_lnum_t *faces_distant[]);
320 
321 /*----------------------------------------------------------------------------
322  * Log information about a given internal coupling entity
323  *
324  * parameters:
325  * cpl <-- pointer to coupling entity
326  *----------------------------------------------------------------------------*/
327 
328 void
330 
331 /*----------------------------------------------------------------------------
332  * Print informations about all coupling entities
333  *
334  * parameters:
335  * cpl <-- pointer to coupling entity
336  *----------------------------------------------------------------------------*/
337 
338 void
340 
341 /*----------------------------------------------------------------------------
342  * Update components hint_* and hext_* using hbord
343  * in the coupling entity associated with given field_id
344  *
345  * parameters:
346  * field_id <-- id of the field
347  * hbord <-- array used to update hint_* and hext_*
348  *----------------------------------------------------------------------------*/
349 
350 void
351 cs_ic_set_exchcoeff(const int field_id,
352  const cs_real_t *hbord);
353 
354 /*----------------------------------------------------------------------------
355  * Define coupling volume using given criterias. Then, this volume will be
356  * seperated from the rest of the domain with thin walls.
357  *
358  * parameters:
359  * mesh <-> pointer to mesh structure to modify
360  * criteria_cells <-- string criteria for the first group of cells
361  *----------------------------------------------------------------------------*/
362 
363 void
365  const char criteria_cells[]);
366 
367 /*----------------------------------------------------------------------------
368  * Define coupling volume using given criterias. Then, this volume has been
369  * seperated from the rest of the domain with a thin wall.
370  *
371  * parameters:
372  * mesh <-> pointer to mesh structure to modify
373  *----------------------------------------------------------------------------*/
374 
375 void
377 
378 /*----------------------------------------------------------------------------
379  * Define coupling volume using given criteria.
380  *
381  * Then, this volume must be seperated from the rest of the domain with a wall.
382  *
383  * parameters:
384  * mesh <-> pointer to mesh structure to modify
385  * criteria_cells <-- selection criteria for the first group of cells
386  * criteria_faces <-- selection criteria for faces to be joined
387  *----------------------------------------------------------------------------*/
388 
389 void
391  const char criteria_cells[],
392  const char criteria_faces[]);
393 
394 /*----------------------------------------------------------------------------
395  * Define coupling entity using given criterias
396  *
397  * parameters:
398  * f_id <-- id of the field
399  *----------------------------------------------------------------------------*/
400 
401 void
403 
404 /*----------------------------------------------------------------------------
405  * Add contribution from coupled faces (internal coupling) to initialisation
406  * for iterative scalar gradient calculation
407  *
408  * parameters:
409  * cpl <-- pointer to coupling entity
410  * c_weight <-- weighted gradient coefficient variable, or NULL
411  * pvar <-- variable
412  * grad <-> gradient
413  *----------------------------------------------------------------------------*/
414 
415 void
417  const cs_real_t c_weight[],
418  const cs_real_t pvar[],
419  cs_real_3_t *restrict grad);
420 
421 /*----------------------------------------------------------------------------*/
422 
424 
425 #endif /* __CS_INTERNAL_COUPLING_H__ */
void cs_internal_coupling_initial_contribution(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], const cs_real_t pvar[], cs_real_3_t *restrict grad)
Definition: cs_internal_coupling.c:857
cs_real_3_t * offset_vect
Definition: cs_internal_coupling.h:85
ple_locator_t * locator
Definition: cs_internal_coupling.h:62
#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:1378
void cs_internal_coupling_reconstruct(const cs_internal_coupling_t *cpl, cs_real_3_t *restrict r_grad, cs_real_3_t grad[])
Definition: cs_internal_coupling.c:1039
void cs_matrix_preconditionning_add_coupling_contribution(void *input, cs_real_t *ad)
Definition: cs_internal_coupling.c:1948
void cs_internal_coupling_iter_rhs(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[])
Definition: cs_internal_coupling.c:937
Definition: cs_internal_coupling.h:59
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:1261
#define BEGIN_C_DECLS
Definition: cs_defs.h:451
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:1493
void cs_internal_coupling_it_cocg_contribution(const cs_internal_coupling_t *cpl, cs_real_33_t cocg[])
Definition: cs_internal_coupling.c:1320
cs_real_33_t * cocg_it
Definition: cs_internal_coupling.h:89
void cs_internal_coupling_add(cs_mesh_t *mesh, const char criteria_cells[], const char criteria_faces[])
Definition: cs_internal_coupling.c:1830
cs_real_3_t * ci_cj_vect
Definition: cs_internal_coupling.h:82
void cs_internal_coupling_finalize(void)
Definition: cs_internal_coupling.c:1356
void cs_internal_coupling_bcs(int bc_type[])
Impose wall BCs to internal coupled faces if not yet defined.
Definition: cs_internal_coupling.c:827
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:1858
cs_lnum_t n_local
Definition: cs_internal_coupling.h:69
void cs_internal_coupling_add_volumes_finalize(cs_mesh_t *mesh)
Definition: cs_internal_coupling.c:1808
void cs_internal_coupling_log(const cs_internal_coupling_t *cpl)
Definition: cs_internal_coupling.c:1727
Definition: cs_mesh.h:63
void cs_internal_coupling_spmv_contribution(bool exclude_diag, void *input, const cs_real_t *restrict x, cs_real_t *restrict y)
Definition: cs_internal_coupling.c:1538
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:1419
bool * coupled_faces
Definition: cs_internal_coupling.h:76
cs_lnum_t * faces_local
Definition: cs_internal_coupling.h:70
cs_lnum_t * faces_distant
Definition: cs_internal_coupling.h:73
void cs_internal_coupling_lsq_rhs(const cs_internal_coupling_t *cpl, const cs_real_t c_weight[], const int w_stride, cs_real_4_t rhsv[])
Definition: cs_internal_coupling.c:1100
cs_real_t * g_weight
Definition: cs_internal_coupling.h:79
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:309
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
char * cells_criteria
Definition: cs_internal_coupling.h:66
#define END_C_DECLS
Definition: cs_defs.h:452
void cs_internal_coupling_dump(void)
Definition: cs_internal_coupling.c:1754
void cs_internal_coupling_initialize(void)
Definition: cs_internal_coupling.c:1612
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:1467
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:315
void cs_ic_set_exchcoeff(const int field_id, const cs_real_t *hbord)
Definition: cs_internal_coupling.c:1887
cs_real_33_t * cocgb_s_lsq
Definition: cs_internal_coupling.h:88
int * c_tag
Definition: cs_internal_coupling.h:63
void cs_internal_coupling_lsq_cocg_contribution(const cs_internal_coupling_t *cpl, cs_real_33_t cocg[])
Definition: cs_internal_coupling.c:1217
void cs_internal_coupling_add_volume(cs_mesh_t *mesh, const char criteria_cells[])
Definition: cs_internal_coupling.c:1779
char * faces_criteria
Definition: cs_internal_coupling.h:67
cs_internal_coupling_t * cs_internal_coupling_by_id(int coupling_id)
Definition: cs_internal_coupling.c:1517
cs_lnum_t n_distant
Definition: cs_internal_coupling.h:72
Definition: mesh.f90:26
char * namesca
Definition: cs_internal_coupling.h:92