9.1
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-2025 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
53
54/*=============================================================================
55 * Macro definitions
56 *============================================================================*/
57
58/*============================================================================
59 * Type definitions
60 *============================================================================*/
61
62/* Internal coupling structure definition */
63
64typedef struct {
65
66 /* Id */
67 int id;
68
69 /* Locator + tag for exchanging variables */
70 ple_locator_t *locator;
71 int *c_tag;
72
73 /* Selection criteria for coupled domains */
76
79
80 /* Associated zone ids */
81
84
85 cs_lnum_t n_local; /* Number of faces */
86 cs_lnum_t *faces_local; /* Coupling boundary faces, numbered 0..n-1 */
87
88 cs_lnum_t n_distant; /* Number of faces in faces_distant */
89 cs_lnum_t *faces_distant; /* Distant boundary faces associated with locator */
90
91 /* Face i is coupled in this entity if coupled_faces[i] = true */
93
94 /* IJ vectors */
96
98
99/*============================================================================
100 * Public function prototypes
101 *============================================================================*/
102
103/*----------------------------------------------------------------------------*/
109/*----------------------------------------------------------------------------*/
110
111int
113
114/*----------------------------------------------------------------------------*/
123/*----------------------------------------------------------------------------*/
124
125void
126cs_internal_coupling_add(const char criteria_cells[],
127 const char criteria_faces[]);
128
129/*----------------------------------------------------------------------------*/
136/*----------------------------------------------------------------------------*/
137
138void
139cs_internal_coupling_add_volume(const char criteria_cells[]);
140
141/*----------------------------------------------------------------------------*/
148/*----------------------------------------------------------------------------*/
149
150void
152
153/*----------------------------------------------------------------------------*/
161/*----------------------------------------------------------------------------*/
162
163void
165 const int zone_ids[]);
166
167/*----------------------------------------------------------------------------*/
183/*----------------------------------------------------------------------------*/
184
185void
187 const char *interior_name,
188 const char *exterior_name);
189
190/*----------------------------------------------------------------------------*/
196/*----------------------------------------------------------------------------*/
197
198void
199cs_internal_coupling_bcs(int bc_type[]);
200
201/*----------------------------------------------------------------------------*/
205/*----------------------------------------------------------------------------*/
206
207void
209
210/*----------------------------------------------------------------------------*/
218/*----------------------------------------------------------------------------*/
219
221cs_internal_coupling_by_id(int coupling_id);
222
223/*----------------------------------------------------------------------------*/
233/*----------------------------------------------------------------------------*/
234
235void
237 int stride,
238 cs_real_t distant[],
239 cs_real_t local[]);
240
241/*----------------------------------------------------------------------------*/
250/*----------------------------------------------------------------------------*/
251
252void
254 int stride,
255 const cs_real_t tab[],
256 cs_real_t local[]);
257
258/*----------------------------------------------------------------------------*/
267/*----------------------------------------------------------------------------*/
268
269void
271 int stride,
272 const cs_real_t tab[],
273 cs_real_t local[]);
274
275/*----------------------------------------------------------------------------*/
279/*----------------------------------------------------------------------------*/
280
281void
283
284/*----------------------------------------------------------------------------*/
288/*----------------------------------------------------------------------------*/
289
290void
292
293/*----------------------------------------------------------------------------
294 * Addition to matrix-vector product in case of internal coupling.
295 *
296 * parameters:
297 * exclude_diag <-- extra diagonal flag
298 * f <-- associated field pointer
299 * x <-- vector x in m * x = y
300 * y <-> vector y in m * x = y
301 *----------------------------------------------------------------------------*/
302
303void
305 const cs_field_t *f,
306 const cs_real_t *x,
307 cs_real_t *y);
308
309/*----------------------------------------------------------------------------
310 * Add coupling term coordinates to matrix assembler.
311 *
312 * parameters:
313 * coupling_id
314 * r_g_id <-- global row ids (per cell)
315 * ma <-> matrix assembler
316 *----------------------------------------------------------------------------*/
317
318void
320 const cs_gnum_t *r_g_id,
322
323/*----------------------------------------------------------------------------
324 * Add coupling terms to matrix values assembly.
325 *
326 * parameters:
327 * f <-- associated field
328 * db_size <-- diagonal block size
329 * eb_size <-- extra-diagonal block size
330 * r_g_id <-- global row ids (per cell)
331 * mav <-> matrix values assembler
332 *----------------------------------------------------------------------------*/
333
334void
336 cs_lnum_t db_size,
337 cs_lnum_t eb_size,
338 const cs_gnum_t r_g_id[],
340
341/*----------------------------------------------------------------------------
342 * Return pointers to coupling components
343 *
344 * parameters:
345 * cpl <-- pointer to coupling entity
346 * n_local --> null or pointer to component n_local
347 * faces_local --> null or pointer to component faces_local
348 * n_distant --> null or pointer to component n_distant
349 * faces_distant --> null or pointer to component faces_distant
350 *----------------------------------------------------------------------------*/
351
352void
354 cs_lnum_t *n_local,
355 const cs_lnum_t *faces_local[],
356 cs_lnum_t *n_distant,
357 const cs_lnum_t *faces_distant[]);
358
359/*----------------------------------------------------------------------------
360 * Log information about a given internal coupling entity
361 *
362 * parameters:
363 * cpl <-- pointer to coupling entity
364 *----------------------------------------------------------------------------*/
365
366void
368
369/*----------------------------------------------------------------------------
370 * Print informations about all coupling entities
371 *
372 * parameters:
373 * cpl <-- pointer to coupling entity
374 *----------------------------------------------------------------------------*/
375
376void
378
379/*----------------------------------------------------------------------------
380 * Add preprocessing operations required by coupling volume using given
381 * criteria.
382 *
383 * The volume is separated from the rest of the domain with inserted
384 * boundaries.
385 *
386 * parameters:
387 * mesh <-> pointer to mesh structure to modify
388 *----------------------------------------------------------------------------*/
389
390void
392
393/*----------------------------------------------------------------------------
394 * Define face to face mappings for internal couplings.
395 *
396 * parameters:
397 * mesh <-> pointer to mesh structure to modify
398 *----------------------------------------------------------------------------*/
399
400void
402
403/*----------------------------------------------------------------------------
404 * Define coupling entity using given criteria.
405 *
406 * parameters:
407 * f_id <-- id of the field
408 *----------------------------------------------------------------------------*/
409
410void
412
413/*----------------------------------------------------------------------------*/
421/*----------------------------------------------------------------------------*/
422
423void
425 const cs_real_t *hbnd);
426
427/*----------------------------------------------------------------------------*/
437/*----------------------------------------------------------------------------*/
438
439void
440cs_ic_field_dist_data_by_face_id(const int field_id,
441 int stride,
442 const cs_real_t tab_distant[],
443 cs_real_t tab_local[]);
444
445/*----------------------------------------------------------------------------*/
446
448
449#if defined(__cplusplus)
450
451/*=============================================================================
452 * Public C++ functions
453 *============================================================================*/
454
455/*----------------------------------------------------------------------------*/
478/*----------------------------------------------------------------------------*/
479
480void
482(
484 const cs_field_bc_coeffs_t *bc_coeffs,
485 const cs_internal_coupling_t *cpl,
486 const bool compute_diffusion_coeffs,
487 cs_halo_type_t halo_type,
488 int w_stride,
489 double clip_coeff,
490 bool hyd_p_flag,
491 cs_real_t f_ext[][3],
492 cs_real_t viscel[][6],
493 const cs_real_t weighb[],
494 cs_real_t *df_limiter,
495 const cs_real_t *var,
496 const cs_real_t *c_weight
497);
498
499/*----------------------------------------------------------------------------*/
513/*----------------------------------------------------------------------------*/
514
515template <cs_lnum_t stride>
516void
518(
520 const cs_field_bc_coeffs_t *bc_coeffs_v,
521 const cs_internal_coupling_t *cpl,
522 cs_halo_type_t halo_type,
523 double clip_coeff,
524 cs_real_t *df_limiter,
525 const cs_real_t var[][stride],
526 const cs_real_t *c_weight
527);
528
529/*----------------------------------------------------------------------------*/
530
531#endif // __cplusplus
532
533#endif /* CS_INTERNAL_COUPLING_H */
Definition: cs_dispatch.h:1711
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:374
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:342
#define END_C_DECLS
Definition: cs_defs.h:555
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
cs_halo_type_t
Definition: cs_halo.h:57
void cs_internal_coupling_preprocess(cs_mesh_t *mesh)
Definition: cs_internal_coupling.cpp:1532
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:1190
void cs_internal_coupling_log(const cs_internal_coupling_t *cpl)
Definition: cs_internal_coupling.cpp:1459
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:789
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:852
void cs_internal_coupling_initialize(void)
Initialize internal coupling related structures.
Definition: cs_internal_coupling.cpp:1442
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:946
void cs_internal_coupling_finalize(void)
Destruction of all internal coupling related structures.
Definition: cs_internal_coupling.cpp:901
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:1061
void cs_internal_coupling_bcs(int bc_type[])
Impose wall BCs to internal coupled faces if not yet defined.
Definition: cs_internal_coupling.cpp:876
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:1263
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:807
void cs_internal_coupling_update_bc_coeffs_strided(cs_dispatch_context &ctx, const cs_field_bc_coeffs_t *bc_coeffs_v, 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:1911
int cs_internal_coupling_n_couplings(void)
Return number of defined internal couplings.
Definition: cs_internal_coupling.cpp:713
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:1645
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:972
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:1021
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:923
void cs_internal_coupling_map(cs_mesh_t *mesh)
Definition: cs_internal_coupling.cpp:1553
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:758
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_ic_field_set_exchcoeff(const cs_field_t *f, const cs_real_t *hbnd)
Update internal coupling coefficients of the field of the given id using given boundary exchange coef...
Definition: cs_internal_coupling.cpp:1599
void cs_internal_coupling_dump(void)
Definition: cs_internal_coupling.cpp:1505
void cs_internal_coupling_add_entity(int f_id)
Definition: cs_internal_coupling.cpp:1573
void cs_internal_coupling_setup(void)
Setup internal coupling related parameters.
Definition: cs_internal_coupling.cpp:1393
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, bool hyd_p_flag, cs_real_t f_ext[][3], cs_real_t viscel[][6], const cs_real_t weighb[], cs_real_t *df_limiter, const cs_real_t *var, const cs_real_t *c_weight)
Compute scalar boundary condition coefficients for internal coupling.
Definition: cs_internal_coupling.cpp:1713
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:730
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
Field boundary condition descriptor (for variables)
Definition: cs_field.h:120
Field descriptor.
Definition: cs_field.h:156
Definition: cs_internal_coupling.h:64
ple_locator_t * locator
Definition: cs_internal_coupling.h:70
cs_lnum_t * faces_local
Definition: cs_internal_coupling.h:86
cs_lnum_t * faces_distant
Definition: cs_internal_coupling.h:89
int n_volume_zones
Definition: cs_internal_coupling.h:82
bool * coupled_faces
Definition: cs_internal_coupling.h:92
int * c_tag
Definition: cs_internal_coupling.h:71
int id
Definition: cs_internal_coupling.h:67
char * interior_faces_group_name
Definition: cs_internal_coupling.h:77
cs_real_3_t * ci_cj_vect
Definition: cs_internal_coupling.h:95
char * exterior_faces_group_name
Definition: cs_internal_coupling.h:78
char * cells_criteria
Definition: cs_internal_coupling.h:74
cs_lnum_t n_distant
Definition: cs_internal_coupling.h:88
cs_lnum_t n_local
Definition: cs_internal_coupling.h:85
char * faces_criteria
Definition: cs_internal_coupling.h:75
int * volume_zone_ids
Definition: cs_internal_coupling.h:83
Definition: cs_mesh.h:85
Definition: cs_zone.h:55