My Project
programmer's 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-2019 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 "cs_base.h"
45 
46 /*----------------------------------------------------------------------------*/
47 
49 
50 /*=============================================================================
51  * Macro definitions
52  *============================================================================*/
53 
54 /*============================================================================
55  * Type definitions
56  *============================================================================*/
57 
58 /*=============================================================================
59  * Global variable definitions
60  *============================================================================*/
61 
62 /*============================================================================
63  * Public function prototypes for Fortran API
64  *============================================================================*/
65 
66 /*----------------------------------------------------------------------------
67  * Synchronize with applications in the same PLE coupling group.
68  *
69  * This function should be called before starting a new time step. The
70  * current time step id is that of the last finished time step, or 0 at
71  * initialization.
72  *
73  * Fortran Interface:
74  *
75  * subroutine cplsyn (ntcmabs, ntcabs, dtref)
76  * *****************
77  *
78  * integer ntmabs : <-> : maximum iteration number
79  * integer ntcabs : <-- : current iteration number
80  * double precision dtref : <-> : reference time step value
81  *----------------------------------------------------------------------------*/
82 
83 void CS_PROCF(cplsyn, CPLSYN)
84 (
86  const cs_int_t *ntcabs,
88  );
89 
90 /*----------------------------------------------------------------------------
91  * Indicate if there are synchronized applications in the same
92  * PLE coupling group.
93  *
94  * Fortran Interface:
95  *
96  * subroutine cplact (isync)
97  * *****************
98  *
99  * integer isync : <-- : 1 if synchronized, 0 otherwise
100  *----------------------------------------------------------------------------*/
101 
102 void CS_PROCF(cplact, CPLACT)
103 (
104  cs_int_t *isync
105 );
106 
107 /*============================================================================
108  * Public function prototypes
109  *============================================================================*/
110 
111 #if defined(HAVE_MPI)
112 
113 /*----------------------------------------------------------------------------
114  * Discover other applications in the same MPI root communicator.
115  *
116  * parameters:
117  * app_name <-- name of this instance of Code_Saturne.
118  *----------------------------------------------------------------------------*/
119 
120 void
121 cs_coupling_discover_mpi_apps(const char *app_name,
122  const char *forced_app_type);
123 
124 /*----------------------------------------------------------------------------
125  * Finalize MPI coupling helper structures.
126  *----------------------------------------------------------------------------*/
127 
128 void
130 
131 /*----------------------------------------------------------------------------
132  * Return info on other applications in the same MPI root communicator.
133  *
134  * returns:
135  * info on other applications structure.
136  *----------------------------------------------------------------------------*/
137 
138 const ple_coupling_mpi_set_t *
140 
141 #endif /* HAVE_MPI */
142 
143 /*----------------------------------------------------------------------------
144  * Return the optional synchronization flag for external couplings.
145  *
146  * See cs_coupling_set_sync_flag() for details.
147  *
148  * returns:
149  * synchronization flag to apply to couplings
150  *----------------------------------------------------------------------------*/
151 
152 int
154 
155 /*----------------------------------------------------------------------------
156  * Define an optional synchronization flag for external couplings.
157  *
158  * This flag is used by all couplings based on the PLE (Parallel Location
159  * and Exchange) group synchronization mechanism, which include couplings
160  * with SYRTHES 4, Code_Saturne, and NEPTUNE_CFD.
161  *
162  * It is defined by a mask, so for example flags f1, f2, and f3 may be
163  * combined using the "f1 | f2 | f2" syntax.
164  *
165  * Note also that for Code_Saturne, in the case of a variable time step,
166  * the reference time step is synchronized at the beginning of each
167  * iteration, but the actual time step is recomputed later.
168  *
169  * Possible flags are:
170  * PLE_COUPLING_TS_MIN Use smallest time step
171  * PLE_COUPLING_TS_LEADER Prescribe time step for the group
172  * (only one member may set this flag)
173  * PLE_COUPLING_UNSTEADY Inform others that this instance is
174  * using an unsteady solution approach
175  * PLE_COUPLING_STEADY Inform others that this instance is
176  * using a teady solution approach
177  * PLE_COUPLING_USER_1 User definable flag
178  * PLE_COUPLING_USER_2 User definable flag
179  * PLE_COUPLING_USER_3 User definable flag
180  * PLE_COUPLING_USER_4 User definable flag
181  *
182  * To force stopping, PLE_COUPLING_STOP may be set. In this case,
183  * the calculation will stop at the first synchronization, even if
184  * this function is called again with another flag.
185  *
186  * parameters:
187  * flag <-- synchronization flag to apply to couplings
188  *----------------------------------------------------------------------------*/
189 
190 void
191 cs_coupling_set_sync_flag(int flag);
192 
193 /*----------------------------------------------------------------------------
194  * Return the time step multiplier for external couplings.
195  *
196  * See cs_coupling_get_ts_multiplier() for details.
197  *
198  * returns:
199  * time step multiplier for external couplings
200  *----------------------------------------------------------------------------*/
201 
202 double
204 
205 /*----------------------------------------------------------------------------
206  * Define a time step multiplier for external couplings.
207  *
208  * The apparent time step for the current instance times (as viewed by
209  * coupled codes) is equal to the true time step times this multiplier.
210  *
211  * If the synchronization flag contains "time step min" (PLE_COUPLING_TS_MIN),
212  * the apparent time step is used to determine which code has the smallest
213  * time step.
214  *
215  * parameters:
216  * m <-- time step multipier to aply to couplings
217  *----------------------------------------------------------------------------*/
218 
219 void
221 
222 /*----------------------------------------------------------------------------
223  * Synchronize with applications in the same PLE coupling group.
224  *
225  * This function should be called before starting a new time step. The
226  * current time step id is that of the last finished time step, or 0 at
227  * initialization.
228  *
229  * Default synchronization flags indicating a new iteration or end of
230  * calculation are set automatically, but the user may set additional flags
231  * to this function if necessary.
232  *
233  * parameters:
234  * flags <-- optional additional synchronization flags
235  * current_ts_id <-- current time step id
236  * max_ts_id <-> maximum time step id
237  * ts <-> suggested time step value
238  *----------------------------------------------------------------------------*/
239 
240 void
241 cs_coupling_sync_apps(int flags,
242  int current_ts_id,
243  int *max_ts_id,
244  double *ts);
245 
246 /*----------------------------------------------------------------------------
247  * Indicate is synchronization with applications in the same
248  * PLE group is active.
249  *
250  * return:
251  * true if synchronization is required, false otherwise
252  *----------------------------------------------------------------------------*/
253 
254 bool
256 
257 /*----------------------------------------------------------------------------
258  * Compute extents of a mesh representation
259  *
260  * parameters:
261  * mesh <-- pointer to mesh representation structure
262  * n_max_extents <-- maximum number of sub-extents (such as element extents)
263  * to compute, or -1 to query
264  * tolerance <-- addition to local extents of each element:
265  * extent = base_extent * (1 + tolerance)
266  * extents <-> extents associated with mesh:
267  * x_min, y_min, ..., x_max, y_max, ... (size: 2*dim)
268  *
269  * returns:
270  * the number of extents computed
271  *----------------------------------------------------------------------------*/
272 
273 ple_lnum_t
274 cs_coupling_mesh_extents(const void *mesh,
275  ple_lnum_t n_max_extents,
276  double tolerance,
277  double extents[]);
278 
279 /*----------------------------------------------------------------------------
280  * Find elements in a given mesh containing points: updates the
281  * location[] and distance[] arrays associated with a set of points
282  * for points that are in an element of this mesh, or closer to one
283  * than to previously encountered elements.
284  *
285  * Location is relative to the id of a given element + 1 in
286  * concatenated sections of same element dimension.
287  *
288  * parameters:
289  * mesh <-- pointer to mesh representation structure
290  * tolerance_base <-- associated base tolerance (used for bounding
291  * box check only, not for location test)
292  * tolerance_fraction <-- associated fraction of element bounding boxes
293  * added to tolerance
294  * n_points <-- number of points to locate
295  * point_coords <-- point coordinates
296  * point_tag <-- optional point tag (size: n_points)
297  * location <-> number of element containing or closest to each
298  * point (size: n_points)
299  * distance <-> distance from point to element indicated by
300  * location[]: < 0 if unlocated, 0 - 1 if inside,
301  * and > 1 if outside a volume element, or absolute
302  * distance to a surface element (size: n_points)
303  *----------------------------------------------------------------------------*/
304 
305 void
306 cs_coupling_point_in_mesh(const void *mesh,
307  float tolerance_base,
308  float tolerance_fraction,
309  ple_lnum_t n_points,
310  const ple_coord_t point_coords[],
311  const int point_tag[],
312  ple_lnum_t location[],
313  float distance[]);
314 
315 /*----------------------------------------------------------------------------
316  * Find elements in a given mesh containing points: updates the
317  * location[] and distance[] arrays associated with a set of points
318  * for points that are in an element of this mesh, or closer to one
319  * than to previously encountered elements.
320  *
321  * Location is relative to parent element numbers.
322  *
323  * parameters:
324  * mesh <-- pointer to mesh representation structure
325  * tolerance_base <-- associated base tolerance (used for bounding
326  * box check only, not for location test)
327  * tolerance_fraction <-- associated fraction of element bounding boxes
328  * added to tolerance
329  * n_points <-- number of points to locate
330  * point_coords <-- point coordinates
331  * point_tag <-- optional point tag (size: n_points)
332  * location <-> number of element containing or closest to each
333  * point (size: n_points)
334  * distance <-> distance from point to element indicated by
335  * location[]: < 0 if unlocated, 0 - 1 if inside,
336  * and > 1 if outside a volume element, or absolute
337  * distance to a surface element (size: n_points)
338  *----------------------------------------------------------------------------*/
339 
340 void
342  float tolerance_base,
343  float tolerance_fraction,
344  ple_lnum_t n_points,
345  const ple_coord_t point_coords[],
346  const int point_tag[],
347  ple_lnum_t location[],
348  float distance[]);
349 
350 /*----------------------------------------------------------------------------*/
351 
353 
354 #endif /* __CS_COUPLING_H__ */
cs_coupling_discover_mpi_apps
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.c:178
ntcabs
void const cs_int_t * ntcabs
Definition: cs_coupling.h:86
cs_coupling_get_sync_flag
int cs_coupling_get_sync_flag(void)
Return the optional synchronization flag for external couplings.
Definition: cs_coupling.c:305
cs_coupling_get_ts_multiplier
double cs_coupling_get_ts_multiplier(void)
Return the time step multiplier for external couplings.
Definition: cs_coupling.c:365
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
dtref
void const cs_int_t cs_real_t * dtref
Definition: cs_coupling.h:86
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_coupling_point_in_mesh_p
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.c:744
mesh
Definition: mesh.f90:26
cs_coupling_finalize
void cs_coupling_finalize(void)
Finalize MPI coupling helper structures.
Definition: cs_coupling.c:272
cs_coupling_get_mpi_apps
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.c:287
ts
void cs_int_t cs_int_t cs_int_t cs_real_t * ts
Definition: cs_at_plugin.h:63
cs_coupling_set_ts_multiplier
void cs_coupling_set_ts_multiplier(double m)
Define a time step multiplier for external couplings.
Definition: cs_coupling.c:386
cs_coupling_is_sync_active
bool cs_coupling_is_sync_active(void)
Indicate is synchronization with applications in the same PLE group is active.
Definition: cs_coupling.c:577
CS_PROCF
void CS_PROCF(cplsyn, CPLSYN)(cs_int_t *ntmabs
cs_int_t
int cs_int_t
Fortran-compatible integer.
Definition: cs_defs.h:301
cs_coupling_point_in_mesh
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.c:696
cs_coupling_mesh_extents
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.c:640
cs_coupling_set_sync_flag
void cs_coupling_set_sync_flag(int flag)
Define an optional synchronization flag for external couplings.
Definition: cs_coupling.c:347
cs_coupling_sync_apps
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.c:411
ntmabs
void cs_int_t * ntmabs
Definition: cs_resource.h:81
cs_base.h