programmer's documentation
cs_paramedmem_coupling.hxx
Go to the documentation of this file.
1 #ifndef __CS_PARAMEDMEM_HXX__
2 #define __CS_PARAMEDMEM_HXX__
3 
4 /*============================================================================
5  * Coupling using ParaMEDMEM
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2018 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  * MED library headers
36  *----------------------------------------------------------------------------*/
37 
38 #if defined(HAVE_PARAMEDMEM)
39 #include <ParaFIELD.hxx>
40 #endif
41 
42 /*----------------------------------------------------------------------------
43  * Local headers
44  *----------------------------------------------------------------------------*/
45 
46 #include "cs_base.h"
47 
48 /*----------------------------------------------------------------------------*/
49 
50 #if defined(HAVE_PARAMEDMEM)
51 using namespace MEDCoupling;
52 
53 /*=============================================================================
54  * Local Macro Definitions
55  *============================================================================*/
56 
57 /*============================================================================
58  * Structure definitions
59  *============================================================================*/
60 
61 typedef struct _cs_paramedmem_coupling_t cs_paramedmem_coupling_t;
62 
63 /*============================================================================
64  * Global variable definitions
65  *============================================================================*/
66 
68 
69 /*============================================================================
70  * Public C++ function prototypes
71  *============================================================================*/
72 
73 /*----------------------------------------------------------------------------
74  * Create a paramedmem coupling based on an InterpKernelDEC.
75  *
76  * The latter is created using the the lists of ranks provided as
77  * input to this function.
78  *
79  * parameters:
80  * name <-- coupling name
81  * grp1_global_ranks <-- array of ranks of group 1
82  * grp1_size <-- size of grp1_global_ranks array
83  * grp2_global_ranks <-- array of ranks of group 2
84  * grp2_size <-- size of grp2_global_ranks array
85  *
86  * return:
87  * pointer to new coupling object
88  *----------------------------------------------------------------------------*/
89 
90 cs_paramedmem_coupling_t *
91 cs_paramedmem_interpkernel_create(const char *name,
92  int *grp1_global_ranks,
93  int grp1_size,
94  int *grp2_global_ranks,
95  int grp2_size);
96 
97 /*----------------------------------------------------------------------------
98  * Define new ParaMEDMEM coupling.
99  *
100  * arguments:
101  * name <-- name of coupling
102  * send_dec <-- send Data Exchange Channel
103  * recv_dec <-- receive Data Exchange Channel
104  *----------------------------------------------------------------------------*/
105 
106 void
107 cs_paramedmem_destroy(cs_paramedmem_coupling_t **coupling);
108 
109 /*----------------------------------------------------------------------------
110  * Define nodal mesh for ParaMEDMEM coupling from selection criteria.
111  *
112  * parameters:
113  * coupling <-- partially initialized ParaMEDMEM coupling structure
114  * name <-- name of coupling mesh
115  * select_criteria <-- selection criteria
116  * elt_dim <-- element dimension
117  * is_source <-- true if fields located on mesh are sent
118  * is_dest <-- true if fields located on mesh are received
119  *
120  * returns:
121  * id of created mesh in coupling
122  *----------------------------------------------------------------------------*/
123 
124 int
125 cs_paramedmem_define_mesh(cs_paramedmem_coupling_t *coupling,
126  const char *name,
127  const char *select_criteria,
128  int elt_dim,
129  bool is_source,
130  bool is_dest);
131 
132 /*----------------------------------------------------------------------------
133  * Initialize nodal coupled meshes.
134  *
135  * parameters:
136  * coupling <-- partially initialized ParaMEDMEM coupling structure
137  *----------------------------------------------------------------------------*/
138 
139 void
140 cs_paramedmem_init_meshes(cs_paramedmem_coupling_t *coupling);
141 
142 /*----------------------------------------------------------------------------
143  * Return the ParaMEDMEM mesh id associated with a given mesh name,
144  * or -1 if no association found.
145  *
146  * parameters:
147  * coupling <-- coupling structure
148  * mesh_name <-- mesh name
149  *
150  * returns:
151  * mesh id for this coupling, or -1 if mesh name is not associated
152  * with this coupling.
153  *----------------------------------------------------------------------------*/
154 
155 int
156 cs_paramedmem_mesh_id(cs_paramedmem_coupling_t *coupling,
157  const char *mesh_name);
158 
159 /*----------------------------------------------------------------------------
160  * Get number of associated coupled elements in coupled mesh
161  *
162  * parameters:
163  * coupling <-- ParaMEDMEM coupling structure
164  * mesh_id <-- id of coupled mesh in coupling
165  *
166  * returns:
167  * number of elements in coupled mesh
168  *----------------------------------------------------------------------------*/
169 
170 cs_lnum_t
171 cs_paramedmem_mesh_get_n_elts(const cs_paramedmem_coupling_t *coupling,
172  int mesh_id);
173 
174 /*----------------------------------------------------------------------------
175  * Get local list of coupled elements (0 to n-1 numbering) for a coupled mesh
176  *
177  * parameters:
178  * coupling <-- ParaMEDMEM coupling structure
179  * mesh_id <-- id of coupled mesh in coupling
180  *----------------------------------------------------------------------------*/
181 
182 const cs_lnum_t *
183 cs_paramedmem_mesh_get_elt_list(const cs_paramedmem_coupling_t *coupling,
184  int mesh_id);
185 
186 /*----------------------------------------------------------------------------
187  * Create a MEDCoupling field structure.
188  *
189  * parameters:
190  * coupling <-- MED coupling structure.
191  * name <-- field name.
192  * mesh_id <-- id of associated mesh in structure.
193  * dim <-- number of field components.
194  * type <-- mesh mesh (ON_NODES, ON_CELLS)
195  * td <-- time discretization type
196  * dirflag <-- 1: send, 2: receive
197  *
198  * returns
199  * field id in coupling structure
200  *----------------------------------------------------------------------------*/
201 
202 int
203 cs_paramedmem_field_add(cs_paramedmem_coupling_t *coupling,
204  const char *name,
205  int mesh_id,
206  int dim,
207  TypeOfField type,
208  TypeOfTimeDiscretization td,
209  int dirflag);
210 
211 /*----------------------------------------------------------------------------
212  * Return the ParaMEDMEM field id associated with given mesh and field names,
213  * or -1 if no association found.
214  *
215  * parameters:
216  * coupling <-- coupling structure.
217  * mesh_id <-- id of associated mesh in structure.
218  * name <-- field name.
219  *
220  * returns
221  * field id in coupling structure, or -1 if not found
222  *----------------------------------------------------------------------------*/
223 
224 int
225 cs_paramedmem_field_get_id(cs_paramedmem_coupling_t *coupling,
226  int mesh_id,
227  const char *name);
228 
229 /*----------------------------------------------------------------------------
230  * Return ParaMEDMEM::ParaFIELD object associated with a given field id.
231  *
232  * parameters:
233  * coupling <-- pointer to associated coupling
234  * field_id <-- id of associated field structure
235  *
236  * returns:
237  * pointer to ParaFIELD to which values were assigned
238  *----------------------------------------------------------------------------*/
239 
240 MEDCoupling::ParaFIELD *
241 cs_paramedmem_field_get(cs_paramedmem_coupling_t *coupling,
242  int field_id);
243 
244 /*----------------------------------------------------------------------------
245  * Write field associated with a mesh to MEDCoupling.
246  *
247  * Assigning a negative value to the time step indicates a time-independent
248  * field (in which case the time_value argument is unused).
249  *
250  * parameters:
251  * coupling <-- pointer to associated coupling
252  * field_id <-- id of associated field
253  * on_parent <-- if true, values are defined on parent mesh
254  * field_values <-- array of associated field value arrays
255  *----------------------------------------------------------------------------*/
256 
257 void
258 cs_paramedmem_field_export(cs_paramedmem_coupling_t *coupling,
259  int field_id,
260  bool on_parent,
261  const double field_values[]);
262 
263 /*----------------------------------------------------------------------------
264  * Read field associated with a mesh from MEDCoupling.
265  *
266  * Only double precision floating point values are considered.
267  *
268  * Assigning a negative value to the time step indicates a time-independent
269  * field (in which case the time_value argument is unused).
270  *
271  * parameters:
272  * coupling <-- pointer to associated coupling
273  * field_id <-- id of associated field
274  * on_parent <-- if true, values are defined on parent mesh
275  * field_values <-- array of associated field value arrays
276  *----------------------------------------------------------------------------*/
277 
278 void
279 cs_paramedmem_field_import(cs_paramedmem_coupling_t *coupling,
280  int field_id,
281  bool on_parent,
282  double field_values[]);
283 
284 /*----------------------------------------------------------------------------
285  * Synchronize DEC assciated with a given coupling.
286  *
287  * This sync function needs to be called at least once before exchanging data.
288  * dec->synchronize() creates the interpolation matrix between the two codes!
289  *
290  * parameters:
291  * coupling <-- coupling structure.
292  * dec_to_sync <-- 1 for send_dec, != 1 for recv_dec
293  *----------------------------------------------------------------------------*/
294 
295 void
296 cs_paramedmem_sync_dec(cs_paramedmem_coupling_t *coupling,
297  int dec_to_sync);
298 
299 /*----------------------------------------------------------------------------
300  * Send the values related to a coupling
301  *
302  * parameters:
303  * coupling <-> coupling structure.
304  *----------------------------------------------------------------------------*/
305 
306 void
307 cs_paramedmem_send_data(cs_paramedmem_coupling_t *coupling);
308 
309 /*----------------------------------------------------------------------------
310  * Receive the values related to a coupling
311  *
312  * parameters:
313  * coupling <-> coupling structure.
314  *----------------------------------------------------------------------------*/
315 
316 void
317 cs_paramedmem_recv_data(cs_paramedmem_coupling_t *coupling);
318 
319 /*----------------------------------------------------------------------------
320  * Link a given field to the DEC before send/recv
321  *
322  * parameters:
323  * coupling <-> coupling structure.
324  * field_id <-> associated field id
325  *----------------------------------------------------------------------------*/
326 
327 void
328 cs_paramedmem_reattach_field(cs_paramedmem_coupling_t *coupling,
329  int field_id);
330 
331 /*============================================================================
332  * Public C++ function prototypes
333  *============================================================================*/
334 
335 /*----------------------------------------------------------------------------
336  * Map MPI ranks within cs_glob_mpi_comm to their values in MPI_COMM_WORLD.
337  *
338  * The caller is responsible for freeing the returned array
339  *
340  * return:
341  * list of ranks in MPI_COMM_WORLD
342  *----------------------------------------------------------------------------*/
343 
344 int *
345 cs_paramedmem_get_mpi_comm_world_ranks(void);
346 
347 /*----------------------------------------------------------------------------*/
348 
349 #endif
350 
352 
353 #endif /* __CS_PARAMEDMEM_HXX__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:462
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
#define END_C_DECLS
Definition: cs_defs.h:463