9.2
general 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-2026 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 "base/cs_defs.h"
41
42#include "base/cs_base.h"
43#include "base/cs_dispatch.h"
44#include "base/cs_field.h"
46#include "mesh/cs_mesh.h"
48#include "base/cs_parameters.h"
49
50/*=============================================================================
51 * Macro definitions
52 *============================================================================*/
53
54/*============================================================================
55 * Type definitions
56 *============================================================================*/
57
58/* Internal coupling structure definition */
59
60typedef struct {
61
62 /* Id */
63 int id;
64
65 /* Locator + tag for exchanging variables */
66 ple_locator_t *locator;
67 int *c_tag;
68
69 /* Selection criteria for coupled domains */
72
75
76 /* Associated zone ids */
77
80
81 cs_lnum_t n_local; /* Number of faces */
82 cs_lnum_t *faces_local; /* Coupling boundary faces, numbered 0..n-1 */
83
84 cs_lnum_t n_distant; /* Number of faces in faces_distant */
85 cs_lnum_t *faces_distant; /* Distant boundary faces associated with locator */
86
87 /* Face i is coupled in this entity if coupled_faces[i] = true */
89
90 /* IJ vectors */
92
94
95/*============================================================================
96 * Public function prototypes
97 *============================================================================*/
98
99/*----------------------------------------------------------------------------*/
105/*----------------------------------------------------------------------------*/
106
107int
109
110/*----------------------------------------------------------------------------*/
119/*----------------------------------------------------------------------------*/
120
121void
122cs_internal_coupling_add(const char criteria_cells[],
123 const char criteria_faces[]);
124
125/*----------------------------------------------------------------------------*/
132/*----------------------------------------------------------------------------*/
133
134void
135cs_internal_coupling_add_volume(const char criteria_cells[]);
136
137/*----------------------------------------------------------------------------*/
144/*----------------------------------------------------------------------------*/
145
146void
148
149/*----------------------------------------------------------------------------*/
157/*----------------------------------------------------------------------------*/
158
159void
161 const int zone_ids[]);
162
163/*----------------------------------------------------------------------------*/
179/*----------------------------------------------------------------------------*/
180
181void
183 const char *interior_name,
184 const char *exterior_name);
185
186/*----------------------------------------------------------------------------*/
192/*----------------------------------------------------------------------------*/
193
194void
195cs_internal_coupling_bcs(int bc_type[]);
196
197/*----------------------------------------------------------------------------*/
201/*----------------------------------------------------------------------------*/
202
203void
205
206/*----------------------------------------------------------------------------*/
214/*----------------------------------------------------------------------------*/
215
217cs_internal_coupling_by_id(int coupling_id);
218
219/*----------------------------------------------------------------------------*/
229/*----------------------------------------------------------------------------*/
230
231void
233 int stride,
234 cs_real_t distant[],
235 cs_real_t local[]);
236
237/*----------------------------------------------------------------------------*/
246/*----------------------------------------------------------------------------*/
247
248void
250 int stride,
251 const cs_real_t tab[],
252 cs_real_t local[]);
253
254/*----------------------------------------------------------------------------*/
263/*----------------------------------------------------------------------------*/
264
265void
267 int stride,
268 const cs_real_t tab[],
269 cs_real_t local[]);
270
271/*----------------------------------------------------------------------------*/
275/*----------------------------------------------------------------------------*/
276
277void
279
280/*----------------------------------------------------------------------------*/
284/*----------------------------------------------------------------------------*/
285
286void
288
289/*----------------------------------------------------------------------------
290 * Addition to matrix-vector product in case of internal coupling.
291 *
292 * parameters:
293 * exclude_diag <-- extra diagonal flag
294 * f <-- associated field pointer
295 * x <-- vector x in m * x = y
296 * y <-> vector y in m * x = y
297 *----------------------------------------------------------------------------*/
298
299void
301 const cs_field_t *f,
302 const cs_real_t *x,
303 cs_real_t *y);
304
305/*----------------------------------------------------------------------------
306 * Add coupling term coordinates to matrix assembler.
307 *
308 * parameters:
309 * coupling_id
310 * r_g_id <-- global row ids (per cell)
311 * ma <-> matrix assembler
312 *----------------------------------------------------------------------------*/
313
314void
316 const cs_gnum_t *r_g_id,
318
319/*----------------------------------------------------------------------------
320 * Add coupling terms to matrix values assembly.
321 *
322 * parameters:
323 * f <-- associated field
324 * db_size <-- diagonal block size
325 * eb_size <-- extra-diagonal block size
326 * r_g_id <-- global row ids (per cell)
327 * mav <-> matrix values assembler
328 *----------------------------------------------------------------------------*/
329
330void
332 cs_lnum_t db_size,
333 cs_lnum_t eb_size,
334 const cs_gnum_t r_g_id[],
336
337/*----------------------------------------------------------------------------
338 * Return pointers to coupling components
339 *
340 * parameters:
341 * cpl <-- pointer to coupling entity
342 * n_local --> null or pointer to component n_local
343 * faces_local --> null or pointer to component faces_local
344 * n_distant --> null or pointer to component n_distant
345 * faces_distant --> null or pointer to component faces_distant
346 *----------------------------------------------------------------------------*/
347
348void
350(
351 const cs_internal_coupling_t *cpl,
352 cs_lnum_t *n_local,
353 const cs_lnum_t *faces_local[],
354 cs_lnum_t *n_distant,
355 const cs_lnum_t *faces_distant[]
356);
357
358/*----------------------------------------------------------------------------
359 * Log information about a given internal coupling entity
360 *
361 * parameters:
362 * cpl <-- pointer to coupling entity
363 *----------------------------------------------------------------------------*/
364
365void
367
368/*----------------------------------------------------------------------------
369 * Print informations about all coupling entities
370 *
371 * parameters:
372 * cpl <-- pointer to coupling entity
373 *----------------------------------------------------------------------------*/
374
375void
377
378/*----------------------------------------------------------------------------
379 * Add preprocessing operations required by coupling volume using given
380 * criteria.
381 *
382 * The volume is separated from the rest of the domain with inserted
383 * boundaries.
384 *
385 * parameters:
386 * mesh <-> pointer to mesh structure to modify
387 *----------------------------------------------------------------------------*/
388
389void
391
392/*----------------------------------------------------------------------------
393 * Define face to face mappings for internal couplings.
394 *
395 * parameters:
396 * mesh <-> pointer to mesh structure to modify
397 *----------------------------------------------------------------------------*/
398
399void
401
402/*----------------------------------------------------------------------------
403 * Define coupling entity using given criteria.
404 *
405 * parameters:
406 * f_id <-- id of the field
407 *----------------------------------------------------------------------------*/
408
409void
411
412/*----------------------------------------------------------------------------*/
420/*----------------------------------------------------------------------------*/
421
422void
424 const cs_real_t *h_int_tot);
425
426/*----------------------------------------------------------------------------*/
436/*----------------------------------------------------------------------------*/
437
438void
439cs_ic_field_dist_data_by_face_id(const int field_id,
440 int stride,
441 const cs_real_t tab_distant[],
442 cs_real_t tab_local[]);
443
444/*=============================================================================
445 * Public C++ functions
446 *============================================================================*/
447
448/*----------------------------------------------------------------------------*/
449/*
450 * \brief Update scalar boundary condition coefficients for internal coupling.
451 *
452 * \param[in] ctx reference to dispatch context
453 * \param[in] bc_coeffs associated BC coefficients structure
454 * \param[in] cpl structure associated with internal coupling
455 * \param[in] compute_diffusion_coeffs compute diffusion coefficients or not
456 * \param[in] halo_type halo type
457 * \param[in] w_stride stride for weighting coefficient
458 * \param[in] clip_coeff clipping coefficient
459 * \param[in] hyd_p_flag flag for hydrostatic pressure
460 * \param[in] f_ext exterior force generating pressure
461 * \param[in] weighb boundary face weight for cells i in case
462 * of tensor diffusion, or nullptr
463 * \param[in] df_limiter diffusion limiter array
464 * \param[in] var gradient's base variable
465 * \param[in] c_weight weighted gradient coefficient variable,
466 * or nullptr
467 */
468/*----------------------------------------------------------------------------*/
469
470void
472(
474 const cs_field_bc_coeffs_t *bc_coeffs,
475 const cs_internal_coupling_t *cpl,
476 const bool compute_diffusion_coeffs,
477 cs_halo_type_t halo_type,
478 int w_stride,
479 double clip_coeff,
480 int hyd_p_flag,
481 cs_real_t f_ext[][3],
482 const cs_real_t *c_weight,
483 const cs_real_t weighb[],
484 cs_real_t *df_limiter,
485 const cs_real_t *var
486);
487
488/*----------------------------------------------------------------------------*/
489/*
490 * \brief Update vector boundary condition coefficients for internal coupling.
491 *
492 * \param[in] ctx reference to dispatch context
493 * \param[in] bc_coeffs boundary condition structure
494 * \param[in] cpl structure associated with internal coupling
495 * \param[in] halo_type halo type
496 * \param[in] clip_coeff clipping coefficient
497 * \param[in] df_limiter diffusion limiter array
498 * \param[in] var gradient's base variable
499 * \param[in] c_weight weighted gradient coefficient variable,
500 * or nullptr
501 */
502/*----------------------------------------------------------------------------*/
503
504template <cs_lnum_t stride>
505void
507(
509 const cs_field_bc_coeffs_t *bc_coeffs,
510 const cs_internal_coupling_t *cpl,
511 cs_halo_type_t halo_type,
512 double clip_coeff,
513 cs_real_t *df_limiter,
514 const cs_real_t var[][stride],
515 const cs_real_t *c_weight
516);
517
518/*----------------------------------------------------------------------------*/
519
520#endif /* CS_INTERNAL_COUPLING_H */
Definition: cs_dispatch.h:2288
Field boundary condition descriptor (for variables)
Definition: cs_field.h:107
Field descriptor.
Definition: cs_field.h:275
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:349
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:317
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_halo_type_t
Definition: cs_halo.h:53
void cs_internal_coupling_preprocess(cs_mesh_t *mesh)
Definition: cs_internal_coupling.cpp:1614
void cs_internal_coupling_update_bc_coeffs_strided(cs_dispatch_context &ctx, const cs_field_bc_coeffs_t *bc_coeffs, const cs_internal_coupling_t *cpl, cs_halo_type_t halo_type, double clip_coeff, cs_real_t *df_limiter, const cs_real_t var[][stride], const cs_real_t *c_weight)
Update vector boundary condition coefficients for internal coupling.
Definition: cs_internal_coupling.cpp:2057
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.cpp:1213
void cs_internal_coupling_update_bc_coeffs_s(cs_dispatch_context &ctx, const cs_field_bc_coeffs_t *bc_coeffs, const cs_internal_coupling_t *cpl, const bool compute_diffusion_coeffs, cs_halo_type_t halo_type, int w_stride, double clip_coeff, int hyd_p_flag, cs_real_t f_ext[][3], const cs_real_t *c_weight, const cs_real_t weighb[], cs_real_t *df_limiter, const cs_real_t *var)
Update scalar boundary condition coefficients for internal coupling.
Definition: cs_internal_coupling.cpp:1780
void cs_internal_coupling_log(const cs_internal_coupling_t *cpl)
Definition: cs_internal_coupling.cpp:1541
void cs_internal_coupling_add_volume_zone(const cs_zone_t *z)
Define coupling volume using a cs_zone_t. Then, this volume will be separated from the rest of the do...
Definition: cs_internal_coupling.cpp:787
void cs_internal_coupling_add_boundary_groups(cs_internal_coupling_t *cpl, const char *interior_name, const char *exterior_name)
Define internal coupling volume boundary group names.
Definition: cs_internal_coupling.cpp:850
void cs_internal_coupling_initialize(void)
Initialize internal coupling related structures.
Definition: cs_internal_coupling.cpp:1524
void cs_internal_coupling_exchange_var(const cs_internal_coupling_t *cpl, int stride, cs_real_t distant[], cs_real_t local[])
Exchange quantities from distant to local (update local using distant).
Definition: cs_internal_coupling.cpp:944
void cs_internal_coupling_finalize(void)
Destruction of all internal coupling related structures.
Definition: cs_internal_coupling.cpp:899
void cs_internal_coupling_coupled_faces(const cs_internal_coupling_t *cpl, cs_lnum_t *n_local, const cs_lnum_t *faces_local[], cs_lnum_t *n_distant, const cs_lnum_t *faces_distant[])
Definition: cs_internal_coupling.cpp:1059
void cs_internal_coupling_bcs(int bc_type[])
Impose wall BCs to internal coupled faces if not yet defined.
Definition: cs_internal_coupling.cpp:874
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.cpp:1286
void cs_internal_coupling_add_volume_zones(int n_zones, const int zone_ids[])
Define coupling volume using given cs_zone_t. Then, this volume will be separated from the rest of th...
Definition: cs_internal_coupling.cpp:805
int cs_internal_coupling_n_couplings(void)
Return number of defined internal couplings.
Definition: cs_internal_coupling.cpp:711
void cs_ic_field_dist_data_by_face_id(const int field_id, int stride, const cs_real_t tab_distant[], cs_real_t tab_local[])
Get distant data using face id at all coupling faces for a given field id.
Definition: cs_internal_coupling.cpp:1723
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[])
Exchange variable between groups using cell id.
Definition: cs_internal_coupling.cpp:970
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[])
Exchange variable between groups using face id.
Definition: cs_internal_coupling.cpp:1019
void cs_ic_field_set_exchcoeff(const cs_field_t *f, const cs_real_t *h_int_tot)
Update internal coupling coefficients of the field of the given id using given boundary exchange coef...
Definition: cs_internal_coupling.cpp:1681
cs_internal_coupling_t * cs_internal_coupling_by_id(int coupling_id)
Return the coupling associated with a given coupling_id.
Definition: cs_internal_coupling.cpp:921
void cs_internal_coupling_map(cs_mesh_t *mesh)
Definition: cs_internal_coupling.cpp:1635
void cs_internal_coupling_add_volume(const char criteria_cells[])
Define coupling volume using given criteria. Then, this volume will be separated from the rest of the...
Definition: cs_internal_coupling.cpp:756
void cs_internal_coupling_spmv_contribution(bool exclude_diag, const cs_field_t *f, const cs_real_t *x, cs_real_t *y)
void cs_internal_coupling_dump(void)
Definition: cs_internal_coupling.cpp:1587
void cs_internal_coupling_add_entity(int f_id)
Definition: cs_internal_coupling.cpp:1655
void cs_internal_coupling_setup(void)
Setup internal coupling related parameters.
Definition: cs_internal_coupling.cpp:1475
void cs_internal_coupling_add(const char criteria_cells[], const char criteria_faces[])
Define coupling volume using given selection criteria.
Definition: cs_internal_coupling.cpp:728
struct _cs_matrix_assembler_t cs_matrix_assembler_t
Definition: cs_matrix_assembler.h:61
struct _cs_matrix_assembler_values_t cs_matrix_assembler_values_t
Definition: cs_matrix_assembler.h:65
Definition: mesh.f90:26
Definition: cs_internal_coupling.h:60
ple_locator_t * locator
Definition: cs_internal_coupling.h:66
cs_lnum_t * faces_local
Definition: cs_internal_coupling.h:82
cs_lnum_t * faces_distant
Definition: cs_internal_coupling.h:85
int n_volume_zones
Definition: cs_internal_coupling.h:78
bool * coupled_faces
Definition: cs_internal_coupling.h:88
int * c_tag
Definition: cs_internal_coupling.h:67
int id
Definition: cs_internal_coupling.h:63
char * interior_faces_group_name
Definition: cs_internal_coupling.h:73
cs_real_3_t * ci_cj_vect
Definition: cs_internal_coupling.h:91
char * exterior_faces_group_name
Definition: cs_internal_coupling.h:74
char * cells_criteria
Definition: cs_internal_coupling.h:70
cs_lnum_t n_distant
Definition: cs_internal_coupling.h:84
cs_lnum_t n_local
Definition: cs_internal_coupling.h:81
char * faces_criteria
Definition: cs_internal_coupling.h:71
int * volume_zone_ids
Definition: cs_internal_coupling.h:79
Definition: cs_mesh.h:85
Definition: cs_zone.h:51