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