1
/*============================================================================
3
* This file is part of the Code_Saturne Kernel, element of the
4
* Code_Saturne CFD tool.
6
* Copyright (C) 2008-2009 EDF S.A., France
8
* contact: saturne-support@edf.fr
10
* The Code_Saturne Kernel is free software; you can redistribute it
11
* and/or modify it under the terms of the GNU General Public License
12
* as published by the Free Software Foundation; either version 2 of
13
* the License, or (at your option) any later version.
15
* The Code_Saturne Kernel is distributed in the hope that it will be
16
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
17
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with the Code_Saturne Kernel; if not, write to the
22
* Free Software Foundation, Inc.,
23
* 51 Franklin St, Fifth Floor,
24
* Boston, MA 02110-1301 USA
26
*===========================================================================*/
28
#ifndef __CS_JOIN_MESH_H__
29
#define __CS_JOIN_MESH_H__
31
/*============================================================================
32
* Subroutines useful to manipulate a cs_join_mesh_t structure
33
*===========================================================================*/
35
/*----------------------------------------------------------------------------
36
* Standard C library headers
37
*---------------------------------------------------------------------------*/
41
/*----------------------------------------------------------------------------
43
*---------------------------------------------------------------------------*/
45
/*----------------------------------------------------------------------------
47
*---------------------------------------------------------------------------*/
51
/*----------------------------------------------------------------------------
52
* Local library headers
53
*---------------------------------------------------------------------------*/
56
#include "cs_join_util.h"
58
/*---------------------------------------------------------------------------*/
62
/*============================================================================
63
* Macro and type definitions
64
*===========================================================================*/
68
CS_JOIN_FACE_UNDEFINED,
70
CS_JOIN_FACE_MULTIPLE_BORDER,
73
} cs_join_face_type_t;
77
cs_join_state_t state; /* State of the vertices (perio/origin/...) */
78
fvm_gnum_t gnum; /* Global vertex number */
79
double tolerance; /* Tolerance = radius of the sphere in which
80
intersection and merge is possible. */
81
double coord[3]; /* Coordinates of the vertex */
87
/* Edge numbering is defined by the ordering of the couples of vertices
88
in their global numbering */
90
cs_int_t n_edges; /* Local number of edges */
91
fvm_gnum_t n_g_edges; /* Global number of edges */
92
cs_int_t *def; /* Definition of each edge by a couple of vertex
94
fvm_gnum_t *gnum; /* Global numbering of edges */
97
Edge definition through the relation between vertices :
99
vtx_idx: index on vertices : -> define first vertex :
101
adj_vtx_lst: list of coupled vertices with the first vertex V1:
103
edge_lst: list of edge numbers relative to the defined couple:
104
(V1, V1a), (V1, V1b), ...
107
cs_int_t n_vertices; /* Number of vertices in index */
108
cs_int_t *vtx_idx; /* Index on first vertices */
109
cs_int_t *adj_vtx_lst; /* List of adjacent vertices */
110
cs_int_t *edge_lst; /* List of corresponding edge ids */
114
/* Structure defining a mesh on selected faces for the joining operation */
118
char *name; /* For post-processing and dump purpose */
120
/* Face connectivity */
123
fvm_gnum_t n_g_faces;
124
fvm_gnum_t *face_gnum;
125
cs_int_t *face_vtx_idx;
126
cs_int_t *face_vtx_lst;
131
fvm_gnum_t n_g_vertices;
132
cs_join_vertex_t *vertices;
136
/*============================================================================
137
* Public function definitions
138
*===========================================================================*/
140
#if defined(HAVE_MPI)
142
/*----------------------------------------------------------------------------
143
* Create a MPI_Datatype for the cs_join_vertex_t structure.
146
* an MPI_Datatype associated to the cs_join_vertex_t structure.
147
*---------------------------------------------------------------------------*/
150
cs_join_mesh_create_vtx_datatype(void);
152
/*----------------------------------------------------------------------------
153
* Create a function to define an operator for MPI reduction operation
156
* in <-- input vertices
157
* inout <-> in/out vertices (vertex with the min. toelrance)
158
* len <-- size of input array
159
* datatype <-- MPI_datatype associated to cs_join_vertex_t
160
*---------------------------------------------------------------------------*/
163
cs_join_mesh_mpi_vertex_min(cs_join_vertex_t *in,
164
cs_join_vertex_t *inout,
166
MPI_Datatype *datatype);
168
/*----------------------------------------------------------------------------
169
* Create a function to define an operator for MPI reduction operation
172
* in <-- input vertices
173
* inout <-> in/out vertices (vertex with the max. toelrance)
174
* len <-- size of input array
175
* datatype <-- MPI_datatype associated to cs_join_vertex_t
176
*---------------------------------------------------------------------------*/
179
cs_join_mesh_mpi_vertex_max(cs_join_vertex_t *in,
180
cs_join_vertex_t *inout,
182
MPI_Datatype *datatype);
184
#endif /* HAVE_MPI */
186
/*----------------------------------------------------------------------------
187
* Allocate and initialize a new cs_join_mesh_t structure.
190
* name <-- name of the mesh
193
* a pointer to a cs_join_mesh_t structure.
194
*---------------------------------------------------------------------------*/
197
cs_join_mesh_create(const char *name);
199
/*----------------------------------------------------------------------------
200
* Get a cs_join_mesh_t structure with the given list of global faces inside.
202
* Exchange between ranks to get the connectivity associated to each
203
* face of the global numbering list.
206
* mesh_name <-- name of the created mesh
207
* n_elts <-- number of elements in the global list
208
* glob_sel <-- list of global elements (ordered)
209
* gnum_rank_index <-- index on ranks for the global elements
210
* local_mesh <-- pointer to the local part of the distributed
211
* cs_join_mesh_t structure on selected elements
214
* a pointer to a new allocated cs_join_mesh_t structure
215
*---------------------------------------------------------------------------*/
218
cs_join_mesh_create_from_glob_sel(const char *mesh_name,
220
const fvm_gnum_t glob_sel[],
221
const fvm_gnum_t gnum_rank_index[],
222
const cs_join_mesh_t *local_mesh);
224
/*----------------------------------------------------------------------------
225
* Allocate and define a cs_join_mesh_t structure relative to an extraction
228
* The selection must be ordered.
231
* mesh_name <-- name of the name to create
232
* subset_size <-- number of selected faces in the subset
233
* selection <-- list of selected faces. Numbering in parent mesh
234
* parent_mesh <-- parent cs_join_mesh_t structure
237
* a pointer to a cs_join_mesh_t structure
238
*---------------------------------------------------------------------------*/
241
cs_join_mesh_create_from_subset(const char *mesh_name,
242
cs_int_t subset_size,
243
const cs_int_t selection[],
244
const cs_join_mesh_t *parent_mesh);
246
/*----------------------------------------------------------------------------
247
* Define a cs_join_mesh_t structure from a selection of faces and its
251
* name <-- mesh name of the resulting cs_join_mesh_t structure
252
* param <-- set of user-defined parameters for the joining
253
* selection <-> selected entities
254
* b_f2v_idx <-- border "face -> vertex" connectivity index
255
* b_f2v_lst <-- border "face -> vertex" connectivity
256
* i_f2v_idx <-- interior "face -> vertex" connectivity index
257
* i_f2v_lst <-- interior "face -> vertex" connectivity
258
* n_vertices <-- number of vertices in the parent mesh
259
* vtx_coord <-- vertex coordinates in parent mesh
260
* vtx_gnum <-- global numbering of vertices
263
* a pointer to a cs_join_mesh_t structure
264
*---------------------------------------------------------------------------*/
267
cs_join_mesh_create_from_select(const char *name,
268
const cs_join_param_t param,
269
cs_join_select_t *selection,
270
const cs_int_t b_f2v_idx[],
271
const cs_int_t b_f2v_lst[],
272
const cs_int_t i_f2v_idx[],
273
const cs_int_t i_f2v_lst[],
274
const cs_int_t n_vertices,
275
const cs_real_t vtx_coord[],
276
const fvm_gnum_t vtx_gnum[]);
278
/*----------------------------------------------------------------------------
279
* Destroy a cs_join_mesh_t structure.
282
* mesh <-> pointer to pointer to cs_join_mesh_t structure to destroy
283
*---------------------------------------------------------------------------*/
286
cs_join_mesh_destroy(cs_join_mesh_t **mesh);
288
/*----------------------------------------------------------------------------
289
* Re-initialize an existing cs_join_mesh_t structure.
292
* mesh <-> pointer to a cs_join_mesh_t structure
293
*---------------------------------------------------------------------------*/
296
cs_join_mesh_reset(cs_join_mesh_t *mesh);
298
/*----------------------------------------------------------------------------
299
* Copy a cs_join_mesh_t structure into another.
302
* mesh <-> pointer to a cs_join_mesh_t structure to fill
303
* ref_mesh <-- pointer to the reference
304
*---------------------------------------------------------------------------*/
307
cs_join_mesh_copy(cs_join_mesh_t **mesh,
308
const cs_join_mesh_t *ref_mesh);
310
/*----------------------------------------------------------------------------
311
* Compute the global min/max tolerance defined on vertices and display it
314
* param <-- user-defined parameters for the joining algorithm
315
* mesh <-- pointer to a cs_join_mesh_t structure
316
*---------------------------------------------------------------------------*/
319
cs_join_mesh_minmax_tol(cs_join_param_t param,
320
cs_join_mesh_t *mesh);
322
#if defined(HAVE_MPI)
324
/*----------------------------------------------------------------------------
325
* Get the connectivity of a list of global elements distributed over the
329
* n_ranks <-- number of ranks in the MPI communicator
330
* send_rank_index <-- index on ranks for the face distribution
331
* send_faces <-- list of face ids to send
332
* send_mesh <-- pointer to the sending cs_join_mesh_t structure
333
* recv_mesh <-> pointer to the receiving cs_join_mesh_t structure
334
* comm <-- mpi communicator on which take places comm.
335
*---------------------------------------------------------------------------*/
338
cs_join_mesh_exchange(int n_ranks,
339
const cs_int_t send_rank_index[],
340
const cs_int_t send_faces[],
341
const cs_join_mesh_t *send_mesh,
342
cs_join_mesh_t *recv_mesh,
345
/*----------------------------------------------------------------------------
346
* Synchronize vertices definition over the ranks.
348
* For vertices with the same global number but a different tolerance,
349
* we keep the smallest tolerance.
352
* mesh <-> pointer to the cs_join_mesh_t structure to synchronize
353
*---------------------------------------------------------------------------*/
356
cs_join_mesh_sync_vertices(cs_join_mesh_t *mesh);
358
#endif /* defined(HAVE_MPI) */
360
/*----------------------------------------------------------------------------
361
* Destroy a cs_join_edges_t structure.
364
* edges <-> pointer to pointer to cs_join_edges_t structure to destroy
365
*---------------------------------------------------------------------------*/
368
cs_join_mesh_destroy_edges(cs_join_edges_t **edges);
370
/*----------------------------------------------------------------------------
371
* Order a cs_join_mesh_t structure according to its global face numbering
373
* Delete redundancies.
376
* mesh <-> pointer to a cs_join_mesh_t structure to order
377
*---------------------------------------------------------------------------*/
380
cs_join_mesh_face_order(cs_join_mesh_t *mesh);
382
/*----------------------------------------------------------------------------
383
* Synchronize vertices definition over the rank. For a vertex with the same
384
* global number but a not equal tolerance, we keep the minimal tolerance.
387
* mesh <-> pointer to the cs_join_mesh_t structure to synchronize
388
*---------------------------------------------------------------------------*/
391
cs_join_mesh_sync_vertices(cs_join_mesh_t *mesh);
393
/*----------------------------------------------------------------------------
394
* Delete vertices which appear several times (same global number) and
395
* vertices which are not used in face definition.
398
* mesh <-> pointer to cs_join_mesh_t structure to clean
399
*---------------------------------------------------------------------------*/
402
cs_join_mesh_vertex_clean(cs_join_mesh_t *mesh);
404
/*----------------------------------------------------------------------------
405
* Clean the given cs_join_mesh_t structure, removing degenerate edges.
408
* mesh <-> pointer to the cs_join_mesh_t structure to clean
409
* verbosity <-- level of display
410
*---------------------------------------------------------------------------*/
413
cs_join_mesh_clean(cs_join_mesh_t *mesh,
416
/*----------------------------------------------------------------------------
417
* Define a list of edges associated to a cs_join_mesh_t structure.
420
* mesh <-- pointer to a cs_join_mesh_t structure
423
* a pointer to the new defined cs_join_edges_t structure.
424
*---------------------------------------------------------------------------*/
427
cs_join_mesh_define_edges(const cs_join_mesh_t *mesh);
429
/*----------------------------------------------------------------------------
430
* Get the edge number relative to a couple of vertex numbers.
432
* edge_num > 0 if couple is in the same order as the edge->def
433
* edge_num < 0 otherwise
436
* v1_num <-- vertex number for the first vertex
437
* v2_num <-- vertex number for the second vertex
438
* edges <-- pointer to a cs_join_edges_t structure
441
* an edge number relative to the couple of vertices
442
*---------------------------------------------------------------------------*/
445
cs_join_mesh_get_edge(cs_int_t v1_num,
447
const cs_join_edges_t *edges);
449
/*----------------------------------------------------------------------------
450
* Re-organize the cs_join_mesh_t structure after a renumbering of
451
* the vertices following the merge operation + a new description of each
455
* mesh <-> pointer to the cs_join_mesh_t structure to update
456
* edges <-- pointer to a cs_join_edges_t structure
457
* edge_index <-- index on edges for the new vertices
458
* edge_new_vtx_lst <-- list of new vertices for each edge
459
* n_new_vertices <-- new local number of vertices after merge
460
* old2new <-- array storing the relation between old/new vertex id
461
*---------------------------------------------------------------------------*/
464
cs_join_mesh_update(cs_join_mesh_t *mesh,
465
const cs_join_edges_t *edges,
466
const cs_int_t edge_index[],
467
const cs_int_t edge_new_vtx_lst[],
468
cs_int_t n_new_vertices,
469
const cs_int_t old2new[]);
471
/*----------------------------------------------------------------------------
472
* Compute for each face of the cs_join_mesh_t structure the face normal.
473
* || face_normal || = 1 (divided by the area of the face)
475
* The caller is responsible for freeing the returned array.
478
* mesh <-- pointer to a cs_join_mesh_t structure
481
* *---------* B : barycenter of the polygon
483
* / . . \ Pi : vertices of the polygon
485
* / . . Ti \ Ti : triangle
486
* *.........B.........* Pi
496
* an array with the face normal for each face of the mesh
497
*---------------------------------------------------------------------------*/
500
cs_join_mesh_get_face_normal(const cs_join_mesh_t *mesh);
502
/*----------------------------------------------------------------------------
503
* Allocate and define an "edge -> face" connectivity
506
* mesh <-- pointer to a cs_join_mesh_t structure
507
* edges <-- pointer to a cs_join_edges_t structure
508
* edge_face_idx --> pointer to the edge -> face connect. index
509
* edge_face_lst --> pointer to the edge -> face connect. list
510
*---------------------------------------------------------------------------*/
513
cs_join_mesh_get_edge_face_adj(const cs_join_mesh_t *mesh,
514
const cs_join_edges_t *edges,
515
cs_int_t *edge_face_idx[],
516
cs_int_t *edge_face_lst[]);
518
/*----------------------------------------------------------------------------
519
* Dump a cs_join_vertex_t structure.
522
* vertex <-- cs_join_vertex_t structure to dump
523
*---------------------------------------------------------------------------*/
526
cs_join_mesh_dump_vertex(const cs_join_vertex_t vertex);
528
/*----------------------------------------------------------------------------
529
* Dump a cs_join_vertex_t structure into a file.
532
* file <-- pointer to a FILE structure
533
* vertex <-- cs_join_vertex_t structure to dump
534
*---------------------------------------------------------------------------*/
537
cs_join_mesh_dump_vertex_file(FILE *file,
538
const cs_join_vertex_t vertex);
540
/*----------------------------------------------------------------------------
541
* Dump a cs_join_mesh_t structure.
544
* mesh <-- pointer to a cs_join_mesh_t structure to dump
545
*---------------------------------------------------------------------------*/
548
cs_join_mesh_dump(const cs_join_mesh_t *mesh);
550
/*----------------------------------------------------------------------------
551
* Dump a cs_join_mesh_t structure into a file.
554
* file <-- pointer to a FILE structure
555
* mesh <-- pointer to cs_join_mesh_t structure to dump
556
*---------------------------------------------------------------------------*/
559
cs_join_mesh_dump_file(FILE *file,
560
const cs_join_mesh_t *mesh);
562
/*----------------------------------------------------------------------------
563
* Dump a list of cs_join_edge_t structures.
566
* edges <-- cs_join_edges_t structure to dump
567
* mesh <-- associated cs_join_mesh_t structure
568
*---------------------------------------------------------------------------*/
571
cs_join_mesh_dump_edges(const cs_join_edges_t *edges,
572
const cs_join_mesh_t *mesh);
574
/*---------------------------------------------------------------------------*/
578
#endif /* __CS_JOIN_MESH_H__ */