Code_Saturne
CFD tool
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-2012 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  * Public function prototypes
92  *============================================================================*/
93 
94 #if defined(HAVE_MPI)
95 
96 /*----------------------------------------------------------------------------
97  * Discover other applications in the same MPI root communicator.
98  *
99  * parameters:
100  * app_name <-- name of this instance of Code_Saturne.
101  *----------------------------------------------------------------------------*/
102 
103 void
104 cs_coupling_discover_mpi_apps(const char *app_name);
105 
106 /*----------------------------------------------------------------------------
107  * Finalize MPI coupling helper structures.
108  *----------------------------------------------------------------------------*/
109 
110 void
111 cs_coupling_finalize(void);
112 
113 /*----------------------------------------------------------------------------
114  * Return info on other applications in the same MPI root communicator.
115  *
116  * returns:
117  * info on other applications structure.
118  *----------------------------------------------------------------------------*/
119 
120 const ple_coupling_mpi_set_t *
121 cs_coupling_get_mpi_apps(void);
122 
123 #endif /* HAVE_MPI */
124 
125 /*----------------------------------------------------------------------------
126  * Return the optional synchronization flag for external couplings.
127  *
128  * See cs_coupling_set_sync_flag() for details.
129  *
130  * returns:
131  * synchronization flag to apply to couplings
132  *----------------------------------------------------------------------------*/
133 
134 int
136 
137 /*----------------------------------------------------------------------------
138  * Define an optional synchronization flag for external couplings.
139  *
140  * This flag is used by all couplings based on the PLE (Parallel Location
141  * and Exchange) group synchronization mechanism, which include couplings
142  * with SYRTHES 4, Code_Saturne, and NEPTUNE_CFD.
143  *
144  * It is defined by a mask, so for example flags f1, f2, and f3 may be
145  * combined using the "f1 | f2 | f2" syntax.
146  *
147  * Note also that for Code_Saturne, in the case of a variable time step,
148  * the reference time step is synchronized at the beginning of each
149  * iteration, but the actual time step is recomputed later.
150  *
151  * Possible flags are:
152  * PLE_COUPLING_TS_MIN Use smallest time step
153  * PLE_COUPLING_TS_LEADER Prescribe time step for the group
154  * (only one member may set this flag)
155  * PLE_COUPLING_UNSTEADY Inform others that this instance is
156  * using an unsteady solution approach
157  * PLE_COUPLING_STEADY Inform others that this instance is
158  * using a teady solution approach
159  * PLE_COUPLING_USER_1 User definable flag
160  * PLE_COUPLING_USER_2 User definable flag
161  * PLE_COUPLING_USER_3 User definable flag
162  * PLE_COUPLING_USER_4 User definable flag
163  *
164  * parameters:
165  * flag <-- synchronization flag to apply to couplings
166  *----------------------------------------------------------------------------*/
167 
168 void
169 cs_coupling_set_sync_flag(int flag);
170 
171 /*----------------------------------------------------------------------------
172  * Return the time step multiplier for external couplings.
173  *
174  * See cs_coupling_get_ts_multiplier() for details.
175  *
176  * returns:
177  * time step multiplier for external couplings
178  *----------------------------------------------------------------------------*/
179 
180 double
182 
183 /*----------------------------------------------------------------------------
184  * Define a time step multiplier for external couplings.
185  *
186  * The apparent time step for the current instance times (as viewed by
187  * coupled codes) is equal to the true time step times this multiplier.
188  *
189  * If the synchronization flag contains "time step min" (PLE_COUPLING_TS_MIN),
190  * the apparent time step is used to determine which code has the smallest
191  * time step.
192  *
193  * parameters:
194  * m <-- time step multipier to aply to couplings
195  *----------------------------------------------------------------------------*/
196 
197 void
199 
200 /*----------------------------------------------------------------------------
201  * Synchronize with applications in the same PLE coupling group.
202  *
203  * This function should be called before starting a new time step. The
204  * current time step id is that of the last finished time step, or 0 at
205  * initialization.
206  *
207  * Default synchronization flags indicating a new iteration or end of
208  * calculation are set automatically, but the user may set additional flags
209  * to this function if necessary.
210  *
211  * parameters:
212  * flags <-- optional additional synchronization flags
213  * current_ts_id <-- current time step id
214  * max_ts_id <-> maximum time step id
215  * ts <-> suggested time step value
216  *----------------------------------------------------------------------------*/
217 
218 void
219 cs_coupling_sync_apps(int flags,
220  int current_ts_id,
221  int *max_ts_id,
222  double *ts);
223 
224 /*----------------------------------------------------------------------------
225  * Compute extents of a mesh representation
226  *
227  * parameters:
228  * mesh <-- pointer to mesh representation structure
229  * n_max_extents <-- maximum number of sub-extents (such as element extents)
230  * to compute, or -1 to query
231  * tolerance <-- addition to local extents of each element:
232  * extent = base_extent * (1 + tolerance)
233  * extents <-> extents associated with mesh:
234  * x_min, y_min, ..., x_max, y_max, ... (size: 2*dim)
235  *
236  * returns:
237  * the number of extents computed
238  *----------------------------------------------------------------------------*/
239 
240 ple_lnum_t
241 cs_coupling_mesh_extents(const void *mesh,
242  ple_lnum_t n_max_extents,
243  double tolerance,
244  double extents[]);
245 
246 /*----------------------------------------------------------------------------
247  * Find elements in a given mesh containing points: updates the
248  * location[] and distance[] arrays associated with a set of points
249  * for points that are in an element of this mesh, or closer to one
250  * than to previously encountered elements.
251  *
252  * Location is relative to the id of a given element + 1 in
253  * concatenated sections of same element dimension.
254  *
255  * parameters:
256  * mesh <-- pointer to mesh representation structure
257  * tolerance <-- associated tolerance
258  * n_points <-- number of points to locate
259  * point_coords <-- point coordinates
260  * location <-> number of element containing or closest to each
261  * point (size: n_points)
262  * distance <-> distance from point to element indicated by
263  * location[]: < 0 if unlocated, 0 - 1 if inside,
264  * and > 1 if outside a volume element, or absolute
265  * distance to a surface element (size: n_points)
266  *----------------------------------------------------------------------------*/
267 
268 void
269 cs_coupling_point_in_mesh(const void *mesh,
270  double tolerance,
271  ple_lnum_t n_points,
272  const ple_coord_t point_coords[],
273  ple_lnum_t location[],
274  float distance[]);
275 
276 /*----------------------------------------------------------------------------
277  * Find elements in a given mesh containing points: updates the
278  * location[] and distance[] arrays associated with a set of points
279  * for points that are in an element of this mesh, or closer to one
280  * than to previously encountered elements.
281  *
282  * Location is relative to parent element numbers.
283  *
284  * parameters:
285  * mesh <-- pointer to mesh representation structure
286  * tolerance <-- associated tolerance
287  * n_points <-- number of points to locate
288  * point_coords <-- point coordinates
289  * location <-> number of element containing or closest to each
290  * point (size: n_points)
291  * distance <-> distance from point to element indicated by
292  * location[]: < 0 if unlocated, 0 - 1 if inside,
293  * and > 1 if outside a volume element, or absolute
294  * distance to a surface element (size: n_points)
295  *----------------------------------------------------------------------------*/
296 
297 void
299  double tolerance,
300  ple_lnum_t n_points,
301  const ple_coord_t point_coords[],
302  ple_lnum_t location[],
303  float distance[]);
304 
305 /*----------------------------------------------------------------------------
306  * Find elements in a given mesh closest to points: updates the
307  * location[] and distance[] arrays associated with a set of points
308  * for points that are closer to an element of this mesh than to previously
309  * encountered elements.
310  *
311  * This function currently only handles elements of lower dimension than
312  * the spatial dimension.
313  *
314  * Location is relative to the id of a given element + 1 in
315  * concatenated sections of same element dimension.
316  *
317  * parameters:
318  * mesh <-- pointer to mesh representation structure
319  * n_points <-- number of points to locate
320  * point_coords <-- point coordinates
321  * location <-> number of element containing or closest to each
322  * point (size: n_points)
323  * distance <-> distance from point to element indicated by
324  * location[]: < 0 if unlocated, or absolute
325  * distance to a surface element (size: n_points)
326  *----------------------------------------------------------------------------*/
327 
328 void
330  ple_lnum_t n_points,
331  const ple_coord_t point_coords[],
332  ple_lnum_t location[],
333  float distance[]);
334 
335 /*----------------------------------------------------------------------------
336  * Find elements in a given mesh closest to points: updates the
337  * location[] and distance[] arrays associated with a set of points
338  * for points that are closer to an element of this mesh than to previously
339  * encountered elements.
340  *
341  * This function currently only handles elements of lower dimension than
342  * the spatial dimension.
343  *
344  * Location is relative to parent element numbers.
345  *
346  * parameters:
347  * mesh <-- pointer to mesh representation structure
348  * n_points <-- number of points to locate
349  * point_coords <-- point coordinates
350  * location <-> number of element containing or closest to each
351  * point (size: n_points)
352  * distance <-> distance from point to element indicated by
353  * location[]: < 0 if unlocated, or absolute
354  * distance to a surface element (size: n_points)
355  *----------------------------------------------------------------------------*/
356 
357 void
359  ple_lnum_t n_points,
360  const ple_coord_t point_coords[],
361  ple_lnum_t location[],
362  float distance[]);
363 
364 /*----------------------------------------------------------------------------*/
365 
367 
368 #endif /* __CS_COUPLING_H__ */
int cs_coupling_get_sync_flag(void)
Return the optional synchronization flag for external couplings.
Definition: cs_coupling.c:276
void cs_coupling_point_closest_mesh(const void *mesh, ple_lnum_t n_points, const ple_coord_t point_coords[], ple_lnum_t location[], float distance[])
Find elements in a given mesh closest to points: updates the location[] and distance[] arrays associa...
Definition: cs_coupling.c:674
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:540
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
BEGIN_C_DECLS void cplsyn(cs_int_t *ntmabs, const cs_int_t *ntcabs, cs_real_t *dtref)
Definition: cs_coupling.c:124
void cs_coupling_point_in_mesh(const void *mesh, double tolerance, ple_lnum_t n_points, const ple_coord_t point_coords[], 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:592
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:376
int cs_int_t
Definition: cs_defs.h:263
integer, save ntcabs
Definition: optcal.f90:277
void cs_coupling_set_sync_flag(int flag)
Define an optional synchronization flag for external couplings.
Definition: cs_coupling.c:314
void cs_coupling_point_in_mesh_p(const void *mesh, double tolerance, ple_lnum_t n_points, const ple_coord_t point_coords[], 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:632
void cs_coupling_point_closest_mesh_p(const void *mesh, ple_lnum_t n_points, const ple_coord_t point_coords[], ple_lnum_t location[], float distance[])
Find elements in a given mesh closest to points: updates the location[] and distance[] arrays associa...
Definition: cs_coupling.c:713
integer, save ntmabs
Definition: optcal.f90:277
void cs_coupling_set_ts_multiplier(double m)
Define a time step multiplier for external couplings.
Definition: cs_coupling.c:351
#define END_C_DECLS
Definition: cs_defs.h:366
double cs_real_t
Definition: cs_defs.h:264
#define CS_PROCF(x, y)
Definition: cs_defs.h:379
double cs_coupling_get_ts_multiplier(void)
Return the time step multiplier for external couplings.
Definition: cs_coupling.c:330
double precision, save dtref
Definition: optcal.f90:302
Definition: mesh.f90:25