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