9.2
general documentation
cs_coupling.h
Go to the documentation of this file.
1#ifndef CS_COUPLING_H
2#define CS_COUPLING_H
3
4/*============================================================================
5 * Common functionnality for various coupling types.
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 * Standard C library headers
32 *----------------------------------------------------------------------------*/
33
34/*----------------------------------------------------------------------------
35 * PLE library headers
36 *----------------------------------------------------------------------------*/
37
38#include <ple_coupling.h>
39
40/*----------------------------------------------------------------------------
41 * Local headers
42 *----------------------------------------------------------------------------*/
43
44#include "base/cs_base.h"
45
46/*=============================================================================
47 * Macro definitions
48 *============================================================================*/
49
50/*============================================================================
51 * Type definitions
52 *============================================================================*/
53
54/*=============================================================================
55 * Global variable definitions
56 *============================================================================*/
57
58/*============================================================================
59 * Public function prototypes
60 *============================================================================*/
61
62#if defined(HAVE_MPI)
63
64/*----------------------------------------------------------------------------
65 * Discover other applications in the same MPI root communicator.
66 *
67 * parameters:
68 * app_name <-- name of this instance of code_saturne.
69 * forced_app_type <-- name of app type, or NULL
70 *----------------------------------------------------------------------------*/
71
72void
73cs_coupling_discover_mpi_apps(const char *app_name,
74 const char *forced_app_type);
75
76/*----------------------------------------------------------------------------
77 * Finalize MPI coupling helper structures.
78 *----------------------------------------------------------------------------*/
79
80void
82
83/*----------------------------------------------------------------------------
84 * Return info on other applications in the same MPI root communicator.
85 *
86 * returns:
87 * info on other applications structure.
88 *----------------------------------------------------------------------------*/
89
90const ple_coupling_mpi_set_t *
92
93#endif /* HAVE_MPI */
94
95/*----------------------------------------------------------------------------
96 * Return the optional synchronization flag for external couplings.
97 *
98 * See cs_coupling_set_sync_flag() for details.
99 *
100 * returns:
101 * synchronization flag to apply to couplings
102 *----------------------------------------------------------------------------*/
103
104int
106
107/*----------------------------------------------------------------------------
108 * Define an optional synchronization flag for external couplings.
109 *
110 * This flag is used by all couplings based on the PLE (Parallel Location
111 * and Exchange) group synchronization mechanism, which include couplings
112 * with SYRTHES, code_saturne, and neptune_cfd.
113 *
114 * It is defined by a mask, so for example flags f1, f2, and f3 may be
115 * combined using the "f1 | f2 | f2" syntax.
116 *
117 * Note also that for code_saturne, in the case of a variable time step,
118 * the reference time step is synchronized at the beginning of each
119 * iteration, but the actual time step is recomputed later.
120 *
121 * Possible flags are:
122 * PLE_COUPLING_TS_MIN Use smallest time step
123 * PLE_COUPLING_TS_LEADER Prescribe time step for the group
124 * (only one member may set this flag)
125 * PLE_COUPLING_UNSTEADY Inform others that this instance is
126 * using an unsteady solution approach
127 * PLE_COUPLING_STEADY Inform others that this instance is
128 * using a steady solution approach
129 * PLE_COUPLING_USER_1 User definable flag
130 * PLE_COUPLING_USER_2 User definable flag
131 * PLE_COUPLING_USER_3 User definable flag
132 * PLE_COUPLING_USER_4 User definable flag
133 *
134 * To force stopping, PLE_COUPLING_STOP may be set. In this case,
135 * the calculation will stop at the first synchronization, even if
136 * this function is called again with another flag.
137 *
138 * parameters:
139 * flag <-- synchronization flag to apply to couplings
140 *----------------------------------------------------------------------------*/
141
142void
144
145/*----------------------------------------------------------------------------
146 * Return the time step multiplier for external couplings.
147 *
148 * See cs_coupling_set_ts_multiplier() for details.
149 *
150 * returns:
151 * time step multiplier for external couplings
152 *----------------------------------------------------------------------------*/
153
154double
156
157/*----------------------------------------------------------------------------
158 * Define a time step multiplier for external couplings.
159 *
160 * The apparent time step for the current instance times (as viewed by
161 * coupled codes) is equal to the true time step times this multiplier.
162 *
163 * If the synchronization flag contains "time step min" (PLE_COUPLING_TS_MIN),
164 * the apparent time step is used to determine which code has the smallest
165 * time step.
166 *
167 * parameters:
168 * m <-- time step multipier to aply to couplings
169 *----------------------------------------------------------------------------*/
170
171void
173
174/*----------------------------------------------------------------------------
175 * Synchronize with applications in the same PLE coupling group.
176 *
177 * This function should be called before starting a new time step. The
178 * current time step id is that of the last finished time step, or 0 at
179 * initialization.
180 *
181 * Default synchronization flags indicating a new iteration or end of
182 * calculation are set automatically, but the user may set additional flags
183 * to this function if necessary.
184 *
185 * parameters:
186 * flags <-- optional additional synchronization flags
187 * current_ts_id <-- current time step id
188 * max_ts_id <-> maximum time step id
189 * ts <-> suggested time step value
190 *----------------------------------------------------------------------------*/
191
192void
193cs_coupling_sync_apps(int flags,
194 int current_ts_id,
195 int *max_ts_id,
196 double *ts);
197
198/*----------------------------------------------------------------------------
199 * Indicate is synchronization with applications in the same
200 * PLE group is active.
201 *
202 * return:
203 * true if synchronization is required, false otherwise
204 *----------------------------------------------------------------------------*/
205
206bool
208
209/*----------------------------------------------------------------------------
210 * Compute extents of a mesh representation
211 *
212 * parameters:
213 * mesh <-- pointer to mesh representation structure
214 * n_max_extents <-- maximum number of sub-extents (such as element extents)
215 * to compute, or -1 to query
216 * tolerance <-- addition to local extents of each element:
217 * extent = base_extent * (1 + tolerance)
218 * extents <-> extents associated with mesh:
219 * x_min, y_min, ..., x_max, y_max, ... (size: 2*dim)
220 *
221 * returns:
222 * the number of extents computed
223 *----------------------------------------------------------------------------*/
224
227 ple_lnum_t n_max_extents,
228 double tolerance,
229 double extents[]);
230
231/*----------------------------------------------------------------------------
232 * Find elements in a given mesh containing points: updates the
233 * location[] and distance[] arrays associated with a set of points
234 * for points that are in an element of this mesh, or closer to one
235 * than to previously encountered elements.
236 *
237 * Location is relative to the id of a given element + 1 in
238 * concatenated sections of same element dimension.
239 *
240 * parameters:
241 * mesh <-- pointer to mesh representation structure
242 * tolerance_base <-- associated base tolerance (used for bounding
243 * box check only, not for location test)
244 * tolerance_fraction <-- associated fraction of element bounding boxes
245 * added to tolerance
246 * n_points <-- number of points to locate
247 * point_coords <-- point coordinates
248 * point_tag <-- optional point tag (size: n_points)
249 * location <-> number of element containing or closest to each
250 * point (size: n_points)
251 * distance <-> distance from point to element indicated by
252 * location[]: < 0 if unlocated, 0 - 1 if inside,
253 * and > 1 if outside a volume element, or absolute
254 * distance to a surface element (size: n_points)
255 *----------------------------------------------------------------------------*/
256
257void
259 float tolerance_base,
260 float tolerance_fraction,
261 ple_lnum_t n_points,
262 const ple_coord_t point_coords[],
263 const int point_tag[],
264 ple_lnum_t location[],
265 float distance[]);
266
267/*----------------------------------------------------------------------------
268 * Find elements in a given mesh containing points: updates the
269 * location[] and distance[] arrays associated with a set of points
270 * for points that are in an element of this mesh, or closer to one
271 * than to previously encountered elements.
272 *
273 * Location is relative to parent element numbers.
274 *
275 * parameters:
276 * mesh <-- pointer to mesh representation structure
277 * tolerance_base <-- associated base tolerance (used for bounding
278 * box check only, not for location test)
279 * tolerance_fraction <-- associated fraction of element bounding boxes
280 * added to tolerance
281 * n_points <-- number of points to locate
282 * point_coords <-- point coordinates
283 * point_tag <-- optional point tag (size: n_points)
284 * location <-> number of element containing or closest to each
285 * point (size: n_points)
286 * distance <-> distance from point to element indicated by
287 * location[]: < 0 if unlocated, 0 - 1 if inside,
288 * and > 1 if outside a volume element, or absolute
289 * distance to a surface element (size: n_points)
290 *----------------------------------------------------------------------------*/
291
292void
294 float tolerance_base,
295 float tolerance_fraction,
296 ple_lnum_t n_points,
297 const ple_coord_t point_coords[],
298 const int point_tag[],
299 ple_lnum_t location[],
300 float distance[]);
301
302/*----------------------------------------------------------------------------*/
303
304#endif /* CS_COUPLING_H */
ple_lnum_t cs_coupling_mesh_extents(const void *mesh, ple_lnum_t n_max_extents, double tolerance, double extents[])
Compute extents of a mesh representation.
Definition: cs_coupling.cpp:542
void cs_coupling_point_in_mesh(const void *mesh, float tolerance_base, float tolerance_fraction, ple_lnum_t n_points, const ple_coord_t point_coords[], const int point_tag[], ple_lnum_t location[], float distance[])
Find elements in a given mesh containing points: updates the location[] and distance[] arrays associa...
Definition: cs_coupling.cpp:598
void cs_coupling_set_ts_multiplier(double m)
Define a time step multiplier for external couplings.
Definition: cs_coupling.cpp:324
void cs_coupling_set_sync_flag(int flag)
Define an optional synchronization flag for external couplings.
Definition: cs_coupling.cpp:285
void cs_coupling_sync_apps(int flags, int current_ts_id, int *max_ts_id, double *ts)
Synchronize with applications in the same PLE coupling group.
Definition: cs_coupling.cpp:349
const ple_coupling_mpi_set_t * cs_coupling_get_mpi_apps(void)
Return info on other applications in the same MPI root communicator.
Definition: cs_coupling.cpp:225
void cs_coupling_point_in_mesh_p(const void *mesh, float tolerance_base, float tolerance_fraction, ple_lnum_t n_points, const ple_coord_t point_coords[], const int point_tag[], ple_lnum_t location[], float distance[])
Find elements in a given mesh containing points: updates the location[] and distance[] arrays associa...
Definition: cs_coupling.cpp:646
int cs_coupling_get_sync_flag(void)
Return the optional synchronization flag for external couplings.
Definition: cs_coupling.cpp:243
void cs_coupling_discover_mpi_apps(const char *app_name, const char *forced_app_type)
Discover other applications in the same MPI root communicator.
Definition: cs_coupling.cpp:114
double cs_coupling_get_ts_multiplier(void)
Return the time step multiplier for external couplings.
Definition: cs_coupling.cpp:303
bool cs_coupling_is_sync_active(void)
Indicate is synchronization with applications in the same PLE group is active.
Definition: cs_coupling.cpp:484
void cs_coupling_finalize(void)
Finalize MPI coupling helper structures.
Definition: cs_coupling.cpp:210
Definition: mesh.f90:26
int ple_lnum_t
double ple_coord_t