9.2
general documentation
cs_paramedmem_coupling_utils.h
Go to the documentation of this file.
1#ifndef CS_PARAMEDMEM_UTILS_HXX
2#define CS_PARAMEDMEM_UTILS_HXX
3
4/*============================================================================
5 * MEDCoupling ParaMESH/ParaFIELD wrapper functions.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 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 * Local headers
30 *----------------------------------------------------------------------------*/
31
34
35#if defined(HAVE_PARAMEDMEM)
36
38// Disable this warning on LLVM based compilers
39DISABLE_WARNING_LLVM(-Winconsistent-missing-override)
40#include <MEDCouplingField.hxx>
41#include <MEDCouplingFieldDouble.hxx>
43
44#if defined(HAVE_PARAMEDMEM_CFEMDEC)
45#include <CFEMDEC.hxx>
46#endif
47#if defined(HAVE_PARAMEDMEM_IKDECWO)
48#include <InterpKernelDECWithOverlap.hxx>
49#else
50#include <InterpKernelDEC.hxx>
51#endif
52#include <ParaFIELD.hxx>
53#include <ParaMESH.hxx>
54
55using namespace MEDCoupling;
56#endif
57
58/*----------------------------------------------------------------------------*/
59
60/*============================================================================
61 * Structure definitions
62 *============================================================================*/
63
64/*----------------------------------------------------------------------------
65 * MEDCoupling writer/reader structure
66 *----------------------------------------------------------------------------*/
67
69 /* Coupling Name */
70 std::string _name; /* Coupling name */
71
72#if defined(HAVE_MPI)
73 /* Current app name */
75#endif
76
77#if defined(HAVE_PARAMEDMEM)
78
80
81 ParaMESH *para_mesh; /* Associated ParaMESH structure. */
82
83#if defined(HAVE_PARAMEDMEM_IKDECWO)
84 InterpKernelDECWithOverlap *dec; /* Data Exchange Channel with Overlap */
85#else
86 InterpKernelDEC *dec; /* Data Exchange Channel */
87#endif
88#if defined(HAVE_PARAMEDMEM_CFEMDEC)
89 CFEMDEC *cdec; /* Data Exchange Channel with FE interpolation*/
90#endif
91
92 std::vector<ParaFIELD *> fields;
93
94 /* Current attached local field id */
95 const ParaFIELD *_curr_field;
96
97#else
98
99 void *para_mesh;
100 void *dec;
101 void *fields;
102
103#endif
104
105 /* Current attached local field id */
106
107#if defined(HAVE_MPI)
108 MPI_Comm comm;
109#else
110 int comm;
111#endif
112
114
115private:
116 void
117 _error_without_paramedmem() const
118 {
119#if !defined(HAVE_PARAMEDMEM)
120
121 bft_error(__FILE__,
122 __LINE__,
123 0,
124 _("Error: %s cannot be called without "
125 "MEDCoupling MPI support."),
126 __func__);
127#endif
128 };
129
130#if defined(HAVE_PARAMEDMEM)
131
132 /*--------------------------------------------------------------------------*/
137 /*----------------------------------------------------------------------------*/
138
139 DataArrayIdType *
140 _computeGlobalNodeIds(const cs_mesh_t *parent_mesh) const;
141
142 /*----------------------------------------------------------------------------*/
147 /*----------------------------------------------------------------------------*/
148
149 void
150 _creare_paraMesh(const cs_mesh_t *parent_mesh);
151
152 /*----------------------------------------------------------------------------*/
157 /*--------------------------------------------------------------------------*/
158
159 void
160 _attachLocalField(const ParaFIELD *field);
161
162 /*--------------------------------------------------------------------------*/
170 /*--------------------------------------------------------------------------*/
171
172 MEDCouplingFieldDouble *
173 _get_field(const char *name) const;
174
175 /*--------------------------------------------------------------------------*/
182 /*--------------------------------------------------------------------------*/
183
184 void
185 _generate_coupling_mesh(const char *select_criteria, int elt_dim);
186
187 /*--------------------------------------------------------------------------*/
195 /*--------------------------------------------------------------------------*/
196
197 void
198 _generate_coupling_mesh_from_ids(cs_lnum_t n_elts,
199 const cs_lnum_t elt_ids[],
200 int elt_dim);
201
202#endif /* HAVE_PARAMEDMEM */
203
204public:
205 /*--------------------------------------------------------------------------*/
212 /*--------------------------------------------------------------------------*/
213
214 void
215 add_mesh_from_criteria(const char *sel_crit, int elt_dim);
216
217 /*--------------------------------------------------------------------------*/
223 /*--------------------------------------------------------------------------*/
224
225 void
226 add_mesh_from_zone(const cs_zone_t *zone);
227
228 /*--------------------------------------------------------------------------*/
236 /*--------------------------------------------------------------------------*/
237
238 void
239 add_mesh_from_ids(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], int elt_dim);
240
241 /*--------------------------------------------------------------------------*/
247 /*--------------------------------------------------------------------------*/
248
249 std::string
250 getName() const
251 {
252 return _name;
253 }
254
255 /*--------------------------------------------------------------------------*/
261 /*--------------------------------------------------------------------------*/
262
265 {
266 cs_lnum_t retval = 0;
267
268#if !defined(HAVE_PARAMEDMEM)
269
270 this->_error_without_paramedmem();
271
272#else
273
274 retval = this->mesh->n_elts;
275
276#endif
277
278 return retval;
279 }
280
281 /*--------------------------------------------------------------------------*/
287 /*--------------------------------------------------------------------------*/
288
289 const cs_lnum_t *
291 {
292 const cs_lnum_t *retval = nullptr;
293
294#if !defined(HAVE_PARAMEDMEM)
295
296 this->_error_without_paramedmem();
297
298#else
299
300 retval = this->mesh->elt_list;
301
302#endif
303
304 return retval;
305 }
306
307 /*--------------------------------------------------------------------------*/
313 /*--------------------------------------------------------------------------*/
314
317 {
318 cs_lnum_t retval = 0;
319
320#if !defined(HAVE_PARAMEDMEM)
321
322 this->_error_without_paramedmem();
323
324#else
325
326 retval = cs_medcoupling_mesh_get_n_vertices(this->mesh);
327
328#endif
329
330 return retval;
331 }
332
333 /*--------------------------------------------------------------------------*/
339 /*--------------------------------------------------------------------------*/
340
341 const cs_lnum_t *
343 {
344 const cs_lnum_t *retval = nullptr;
345
346#if !defined(HAVE_PARAMEDMEM)
347
348 this->_error_without_paramedmem();
349
350#else
351
352 retval = this->mesh->vtx_list;
353
354#endif
355
356 return retval;
357 }
358
359 /*--------------------------------------------------------------------------*/
371 /*--------------------------------------------------------------------------*/
372
373 int
374 add_field(const char *name,
375 int dim,
376 cs_medcpl_field_nature_t field_nature,
377 cs_medcpl_space_discr_t space_discr,
378 cs_medcpl_time_discr_t time_discr);
379
380 /*--------------------------------------------------------------------------*/
390 /*--------------------------------------------------------------------------*/
391
392 int
393 add_field(const cs_field_t *f,
396
397 /*--------------------------------------------------------------------------*/
409 /*--------------------------------------------------------------------------*/
410
411 void
412 set_values(const char *name,
413 const double values[],
414 const bool use_list_elt = true);
415
416 /*--------------------------------------------------------------------------*/
427 /*--------------------------------------------------------------------------*/
428
429 void
430 get_values(const char *name,
431 double values[],
432 const bool use_list_elt = true) const;
433
434 /*--------------------------------------------------------------------------*/
438 /*--------------------------------------------------------------------------*/
439
440 void
441 send_data() const;
442
443 /*--------------------------------------------------------------------------*/
454 /*--------------------------------------------------------------------------*/
455
456 void
457 send_data(const char *name,
458 const double *vals,
459 const bool use_list_elt = true);
460
461 /*--------------------------------------------------------------------------*/
465 /*--------------------------------------------------------------------------*/
466
467 void
468 recv_data();
469
470 /*--------------------------------------------------------------------------*/
480 /*--------------------------------------------------------------------------*/
481
482 void
483 recv_data(const char *name, double *vals, const bool use_list_elt = true);
484
485 /*--------------------------------------------------------------------------*/
489 /*--------------------------------------------------------------------------*/
490
491 void
492 sync_dec();
493
494 /*--------------------------------------------------------------------------*/
500 /*--------------------------------------------------------------------------*/
501
502 void
503 attach_field_by_id(int field_id);
504
505 /*--------------------------------------------------------------------------*/
511 /*--------------------------------------------------------------------------*/
512
513 void
514 attach_field_by_name(const char *name);
515
516 /*--------------------------------------------------------------------------*/
520 /*--------------------------------------------------------------------------*/
521
522 void
523 log() const;
524};
525
526/*----------------------------------------------------------------------------*/
527
528#endif /* CS_PARAMEDMEM_UTILS_HXX */
void bft_error(const char *const file_name, const int line_num, const int sys_error_code, const char *const format,...)
Calls the error handler (set by bft_error_handler_set() or default).
Definition: bft_error.cpp:187
Field descriptor.
Definition: cs_field.h:275
#define DISABLE_WARNING_PUSH
Definition: cs_defs.h:168
#define _(String)
Definition: cs_defs.h:61
#define DISABLE_WARNING_LLVM(warningName)
Definition: cs_defs.h:171
#define DISABLE_WARNING_POP
Definition: cs_defs.h:170
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
cs_lnum_t cs_medcoupling_mesh_get_n_vertices(cs_medcoupling_mesh_t *m)
Return a cs_medcoupling_mesh_t structure's number of vertices.
Definition: cs_medcoupling_mesh.cxx:1099
cs_medcpl_field_nature_t
Definition: cs_paramedmem_coupling.h:68
cs_medcpl_time_discr_t
Definition: cs_paramedmem_coupling.h:62
cs_medcpl_space_discr_t
Definition: cs_paramedmem_coupling.h:56
Definition: field.f90:27
Definition: mesh.f90:26
Definition: cs_paramedmem_coupling_utils.h:68
void recv_data()
Recieve values of field attached to DEC.
Definition: cs_paramedmem_coupling.cxx:1531
void set_values(const char *name, const double values[], const bool use_list_elt=true)
Assign values based on parent mesh location to associated ParaFIELD objects.
Definition: cs_paramedmem_coupling.cxx:1258
void add_mesh_from_ids(cs_lnum_t n_elts, const cs_lnum_t elt_ids[], int elt_dim)
Define coupled mesh based on a cs_zone_t pointer.
Definition: cs_paramedmem_coupling.cxx:1011
const cs_lnum_t * get_elt_list() const
Get indirection list for elements in coupled mesh.
Definition: cs_paramedmem_coupling_utils.h:290
ple_coupling_mpi_set_info_t apps[2]
Definition: cs_paramedmem_coupling_utils.h:74
void * dec
Definition: cs_paramedmem_coupling_utils.h:100
void get_values(const char *name, double values[], const bool use_list_elt=true) const
Copy values from associated ParaFIELD object to array defined parent mesh location.
Definition: cs_paramedmem_coupling.cxx:1318
bool dec_synced
Definition: cs_paramedmem_coupling_utils.h:113
void attach_field_by_id(int field_id)
Attach a field to the DEC for send operation using its index.
Definition: cs_paramedmem_coupling.cxx:1622
void log() const
Log ParaMEDMEM coupling setup information.
Definition: cs_paramedmem_coupling.cxx:1684
void * fields
Definition: cs_paramedmem_coupling_utils.h:101
const cs_lnum_t * get_vertex_list() const
Get indirection list for vertices in coupled mesh.
Definition: cs_paramedmem_coupling_utils.h:342
int add_field(const char *name, int dim, cs_medcpl_field_nature_t field_nature, cs_medcpl_space_discr_t space_discr, cs_medcpl_time_discr_t time_discr)
Add a coupled field.
Definition: cs_paramedmem_coupling.cxx:1047
void add_mesh_from_zone(const cs_zone_t *zone)
Define coupled mesh based on a cs_zone_t pointer.
Definition: cs_paramedmem_coupling.cxx:966
void add_mesh_from_criteria(const char *sel_crit, int elt_dim)
Define coupled mesh based on a selection criteria.
Definition: cs_paramedmem_coupling.cxx:943
std::string getName() const
Get name of the coupling.
Definition: cs_paramedmem_coupling_utils.h:250
void * para_mesh
Definition: cs_paramedmem_coupling_utils.h:99
void sync_dec()
Sync the coupling's the DEC.
Definition: cs_paramedmem_coupling.cxx:1396
std::string _name
Definition: cs_paramedmem_coupling_utils.h:70
MPI_Comm comm
Definition: cs_paramedmem_coupling_utils.h:108
void send_data() const
Send values of field attached to DEC.
Definition: cs_paramedmem_coupling.cxx:1443
cs_lnum_t get_n_elts() const
Get number of elements of coupled mesh.
Definition: cs_paramedmem_coupling_utils.h:264
cs_lnum_t get_n_vertices() const
Get number of vertices of coupled mesh.
Definition: cs_paramedmem_coupling_utils.h:316
void attach_field_by_name(const char *name)
Attach a field to the DEC for send operation using its name.
Definition: cs_paramedmem_coupling.cxx:1645
Definition: cs_medcoupling_mesh.hxx:67
cs_lnum_t n_elts
Definition: cs_medcoupling_mesh.hxx:74
cs_lnum_t * vtx_list
Definition: cs_medcoupling_mesh.hxx:79
cs_lnum_t * elt_list
Definition: cs_medcoupling_mesh.hxx:75
Definition: cs_mesh.h:85
Definition: cs_zone.h:51