Code_Saturne
CFD tool
cs_join_mesh.h
Go to the documentation of this file.
1 #ifndef __CS_JOIN_MESH_H__
2 #define __CS_JOIN_MESH_H__
3 
4 /*============================================================================
5  * Subroutines useful to manipulate a cs_join_mesh_t structure
6  *===========================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2012 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 #include <stdio.h>
35 
36 /*----------------------------------------------------------------------------
37  * BFT library headers
38  *---------------------------------------------------------------------------*/
39 
40 /*----------------------------------------------------------------------------
41  * FVM library headers
42  *---------------------------------------------------------------------------*/
43 
44 #include <fvm_defs.h>
45 
46 /*----------------------------------------------------------------------------
47  * Local library headers
48  *---------------------------------------------------------------------------*/
49 
50 #include "cs_base.h"
51 #include "cs_join_util.h"
52 
53 /*---------------------------------------------------------------------------*/
54 
56 
57 /*============================================================================
58  * Macro and type definitions
59  *===========================================================================*/
60 
61 typedef enum {
62 
67 
69 
70 typedef struct {
71 
72  cs_join_state_t state; /* State of the vertices (perio/origin/...) */
73  cs_gnum_t gnum; /* Global vertex number */
74  double tolerance; /* Tolerance = radius of the sphere in which
75  intersection and merge is possible. */
76  double coord[3]; /* Coordinates of the vertex */
77 
79 
80 typedef struct {
81 
82  /* Edge numbering is defined by the ordering of the couples of vertices
83  in their global numbering */
84 
85  cs_int_t n_edges; /* Local number of edges */
86  cs_gnum_t n_g_edges; /* Global number of edges */
87  cs_int_t *def; /* Definition of each edge by a couple of vertex
88  numbers */
89  cs_gnum_t *gnum; /* Global numbering of edges */
90 
91  /*
92  Edge definition through the relation between vertices :
93 
94  vtx_idx: index on vertices : -> define first vertex :
95  V1
96  adj_vtx_lst: list of coupled vertices with the first vertex V1:
97  V1a, V1b, ...
98  edge_lst: list of edge numbers relative to the defined couple:
99  (V1, V1a), (V1, V1b), ...
100  */
101 
102  cs_int_t n_vertices; /* Number of vertices in index */
103  cs_int_t *vtx_idx; /* Index on first vertices */
104  cs_int_t *adj_vtx_lst; /* List of adjacent vertices */
105  cs_int_t *edge_lst; /* List of corresponding edge ids */
106 
108 
109 /* Structure defining a mesh on selected faces for the joining operation */
110 
111 typedef struct {
112 
113  char *name; /* For post-processing and dump purpose */
114 
115  /* Face connectivity */
116 
122 
123  /* Vertex data */
124 
128 
130 
131 /*============================================================================
132  * Public function prototypes
133  *===========================================================================*/
134 
135 #if defined(HAVE_MPI)
136 
137 /*----------------------------------------------------------------------------
138  * Create a MPI_Datatype for the cs_join_vertex_t structure.
139  *
140  * returns:
141  * an MPI_Datatype associated to the cs_join_vertex_t structure.
142  *---------------------------------------------------------------------------*/
143 
144 MPI_Datatype
145 cs_join_mesh_create_vtx_datatype(void);
146 
147 /*----------------------------------------------------------------------------
148  * Create a function to define an operator for MPI reduction operation
149  *
150  * parameters:
151  * in <-- input vertices
152  * inout <-> in/out vertices (vertex with the min. toelrance)
153  * len <-- size of input array
154  * datatype <-- MPI_datatype associated to cs_join_vertex_t
155  *---------------------------------------------------------------------------*/
156 
157 void
158 cs_join_mesh_mpi_vertex_min(cs_join_vertex_t *in,
159  cs_join_vertex_t *inout,
160  int *len,
161  MPI_Datatype *datatype);
162 
163 /*----------------------------------------------------------------------------
164  * Create a function to define an operator for MPI reduction operation
165  *
166  * parameters:
167  * in <-- input vertices
168  * inout <-> in/out vertices (vertex with the max. toelrance)
169  * len <-- size of input array
170  * datatype <-- MPI_datatype associated to cs_join_vertex_t
171  *---------------------------------------------------------------------------*/
172 
173 void
174 cs_join_mesh_mpi_vertex_max(cs_join_vertex_t *in,
175  cs_join_vertex_t *inout,
176  int *len,
177  MPI_Datatype *datatype);
178 
179 #endif /* HAVE_MPI */
180 
181 /*----------------------------------------------------------------------------
182  * Allocate and initialize a new cs_join_mesh_t structure.
183  *
184  * parameters:
185  * name <-- name of the mesh
186  *
187  * returns:
188  * a pointer to a cs_join_mesh_t structure.
189  *---------------------------------------------------------------------------*/
190 
192 cs_join_mesh_create(const char *name);
193 
194 /*----------------------------------------------------------------------------
195  * Get a cs_join_mesh_t structure with the given list of global faces inside.
196  *
197  * Exchange between ranks to get the connectivity associated to each
198  * face of the global numbering list.
199  *
200  * parameters:
201  * mesh_name <-- name of the created mesh
202  * n_elts <-- number of elements in the global list
203  * glob_sel <-- list of global elements (ordered)
204  * gnum_rank_index <-- index on ranks for the global elements
205  * local_mesh <-- pointer to the local part of the distributed
206  * cs_join_mesh_t structure on selected elements
207  *
208  * returns:
209  * a pointer to a new allocated cs_join_mesh_t structure
210  *---------------------------------------------------------------------------*/
211 
213 cs_join_mesh_create_from_glob_sel(const char *mesh_name,
214  cs_int_t n_elts,
215  const cs_gnum_t glob_sel[],
216  const cs_gnum_t gnum_rank_index[],
217  const cs_join_mesh_t *local_mesh);
218 
219 /*----------------------------------------------------------------------------
220  * Allocate and define a cs_join_mesh_t structure relative to an extraction
221  * of selected faces.
222  *
223  * The selection must be ordered.
224  *
225  * parameters:
226  * mesh_name <-- name of the name to create
227  * subset_size <-- number of selected faces in the subset
228  * selection <-- list of selected faces. Numbering in parent mesh
229  * parent_mesh <-- parent cs_join_mesh_t structure
230  *
231  * returns:
232  * a pointer to a cs_join_mesh_t structure
233  *---------------------------------------------------------------------------*/
234 
236 cs_join_mesh_create_from_subset(const char *mesh_name,
237  cs_int_t subset_size,
238  const cs_int_t selection[],
239  const cs_join_mesh_t *parent_mesh);
240 
241 /*----------------------------------------------------------------------------
242  * Define a cs_join_mesh_t structure from a selection of faces and its
243  * related vertices.
244  *
245  * parameters:
246  * name <-- mesh name of the resulting cs_join_mesh_t structure
247  * param <-- set of user-defined parameters for the joining
248  * selection <-> selected entities
249  * b_f2v_idx <-- border "face -> vertex" connectivity index
250  * b_f2v_lst <-- border "face -> vertex" connectivity
251  * i_f2v_idx <-- interior "face -> vertex" connectivity index
252  * i_f2v_lst <-- interior "face -> vertex" connectivity
253  * n_vertices <-- number of vertices in the parent mesh
254  * vtx_coord <-- vertex coordinates in parent mesh
255  * vtx_gnum <-- global numbering of vertices
256  *
257  * returns:
258  * a pointer to a cs_join_mesh_t structure
259  *---------------------------------------------------------------------------*/
260 
262 cs_join_mesh_create_from_select(const char *name,
263  const cs_join_param_t param,
264  cs_join_select_t *selection,
265  const cs_int_t b_f2v_idx[],
266  const cs_int_t b_f2v_lst[],
267  const cs_int_t i_f2v_idx[],
268  const cs_int_t i_f2v_lst[],
269  const cs_int_t n_vertices,
270  const cs_real_t vtx_coord[],
271  const cs_gnum_t vtx_gnum[]);
272 
273 /*----------------------------------------------------------------------------
274  * Destroy a cs_join_mesh_t structure.
275  *
276  * parameters:
277  * mesh <-> pointer to pointer to cs_join_mesh_t structure to destroy
278  *---------------------------------------------------------------------------*/
279 
280 void
282 
283 /*----------------------------------------------------------------------------
284  * Re-initialize an existing cs_join_mesh_t structure.
285  *
286  * parameters:
287  * mesh <-> pointer to a cs_join_mesh_t structure
288  *---------------------------------------------------------------------------*/
289 
290 void
292 
293 /*----------------------------------------------------------------------------
294  * Copy a cs_join_mesh_t structure into another.
295  *
296  * parameters:
297  * mesh <-> pointer to a cs_join_mesh_t structure to fill
298  * ref_mesh <-- pointer to the reference
299  *---------------------------------------------------------------------------*/
300 
301 void
303  const cs_join_mesh_t *ref_mesh);
304 
305 /*----------------------------------------------------------------------------
306  * Compute the global min/max tolerance defined on vertices and display it
307  *
308  * parameters:
309  * param <-- user-defined parameters for the joining algorithm
310  * mesh <-- pointer to a cs_join_mesh_t structure
311  *---------------------------------------------------------------------------*/
312 
313 void
316 
317 #if defined(HAVE_MPI)
318 
319 /*----------------------------------------------------------------------------
320  * Get the connectivity of a list of global elements distributed over the
321  * ranks.
322  *
323  * parameters:
324  * n_ranks <-- number of ranks in the MPI communicator
325  * send_rank_index <-- index on ranks for the face distribution
326  * send_faces <-- list of face ids to send
327  * send_mesh <-- pointer to the sending cs_join_mesh_t structure
328  * recv_mesh <-> pointer to the receiving cs_join_mesh_t structure
329  * comm <-- mpi communicator on which take places comm.
330  *---------------------------------------------------------------------------*/
331 
332 void
333 cs_join_mesh_exchange(int n_ranks,
334  const cs_int_t send_rank_index[],
335  const cs_int_t send_faces[],
336  const cs_join_mesh_t *send_mesh,
337  cs_join_mesh_t *recv_mesh,
338  MPI_Comm comm);
339 
340 /*----------------------------------------------------------------------------
341  * Synchronize vertices definition over the ranks.
342  *
343  * For vertices with the same global number but a different tolerance,
344  * we keep the smallest tolerance.
345  *
346  * parameters:
347  * mesh <-> pointer to the cs_join_mesh_t structure to synchronize
348  *---------------------------------------------------------------------------*/
349 
350 void
352 
353 #endif /* defined(HAVE_MPI) */
354 
355 /*----------------------------------------------------------------------------
356  * Destroy a cs_join_edges_t structure.
357  *
358  * parameters:
359  * edges <-> pointer to pointer to cs_join_edges_t structure to destroy
360  *---------------------------------------------------------------------------*/
361 
362 void
364 
365 /*----------------------------------------------------------------------------
366  * Order a cs_join_mesh_t structure according to its global face numbering
367  *
368  * Delete redundancies.
369  *
370  * parameters:
371  * mesh <-> pointer to a cs_join_mesh_t structure to order
372  *---------------------------------------------------------------------------*/
373 
374 void
376 
377 /*----------------------------------------------------------------------------
378  * Synchronize vertices definition over the rank. For a vertex with the same
379  * global number but a not equal tolerance, we keep the minimal tolerance.
380  *
381  * parameters:
382  * mesh <-> pointer to the cs_join_mesh_t structure to synchronize
383  *---------------------------------------------------------------------------*/
384 
385 void
387 
388 /*----------------------------------------------------------------------------
389  * Delete vertices which appear several times (same global number) and
390  * vertices which are not used in face definition.
391  *
392  * parameters:
393  * mesh <-> pointer to cs_join_mesh_t structure to clean
394  *---------------------------------------------------------------------------*/
395 
396 void
398 
399 /*----------------------------------------------------------------------------
400  * Clean the given cs_join_mesh_t structure, removing degenerate edges.
401  *
402  * parameters:
403  * mesh <-> pointer to the cs_join_mesh_t structure to clean
404  * verbosity <-- level of display
405  *---------------------------------------------------------------------------*/
406 
407 void
409  int verbosity);
410 
411 /*----------------------------------------------------------------------------
412  * Define a list of edges associated to a cs_join_mesh_t structure.
413  *
414  * parameters:
415  * mesh <-- pointer to a cs_join_mesh_t structure
416  *
417  * returns:
418  * a pointer to the new defined cs_join_edges_t structure.
419  *---------------------------------------------------------------------------*/
420 
423 
424 /*----------------------------------------------------------------------------
425  * Get the edge number relative to a couple of vertex numbers.
426  *
427  * edge_num > 0 if couple is in the same order as the edge->def
428  * edge_num < 0 otherwise
429  *
430  * parameters:
431  * v1_num <-- vertex number for the first vertex
432  * v2_num <-- vertex number for the second vertex
433  * edges <-- pointer to a cs_join_edges_t structure
434  *
435  * returns:
436  * an edge number relative to the couple of vertices
437  *---------------------------------------------------------------------------*/
438 
439 cs_int_t
441  cs_int_t v2_num,
442  const cs_join_edges_t *edges);
443 
444 /*----------------------------------------------------------------------------
445  * Re-organize the cs_join_mesh_t structure after a renumbering of
446  * the vertices following the merge operation + a new description of each
447  * face.
448  *
449  * parameters:
450  * mesh <-> pointer to the cs_join_mesh_t structure to update
451  * edges <-- pointer to a cs_join_edges_t structure
452  * edge_index <-- index on edges for the new vertices
453  * edge_new_vtx_lst <-- list of new vertices for each edge
454  * n_new_vertices <-- new local number of vertices after merge
455  * old2new <-- array storing the relation between old/new vertex id
456  *---------------------------------------------------------------------------*/
457 
458 void
460  const cs_join_edges_t *edges,
461  const cs_int_t edge_index[],
462  const cs_int_t edge_new_vtx_lst[],
463  cs_int_t n_new_vertices,
464  const cs_int_t old2new[]);
465 
466 /*----------------------------------------------------------------------------
467  * Compute for each face of the cs_join_mesh_t structure the face normal.
468  * || face_normal || = 1 (divided by the area of the face)
469  *
470  * The caller is responsible for freeing the returned array.
471  *
472  * parameters:
473  * mesh <-- pointer to a cs_join_mesh_t structure
474  *
475  * Pi+1
476  * *---------* B : barycenter of the polygon
477  * / . . \
478  * / . . \ Pi : vertices of the polygon
479  * / . . \
480  * / . . Ti \ Ti : triangle
481  * *.........B.........* Pi
482  * Pn-1 \ . . /
483  * \ . . /
484  * \ . . /
485  * \ . T0 . /
486  * *---------*
487  * P0
488  *
489  *
490  * returns:
491  * an array with the face normal for each face of the mesh
492  *---------------------------------------------------------------------------*/
493 
494 cs_real_t *
496 
497 /*----------------------------------------------------------------------------
498  * Allocate and define an "edge -> face" connectivity
499  *
500  * parameters:
501  * mesh <-- pointer to a cs_join_mesh_t structure
502  * edges <-- pointer to a cs_join_edges_t structure
503  * edge_face_idx --> pointer to the edge -> face connect. index
504  * edge_face_lst --> pointer to the edge -> face connect. list
505  *---------------------------------------------------------------------------*/
506 
507 void
509  const cs_join_edges_t *edges,
510  cs_int_t *edge_face_idx[],
511  cs_int_t *edge_face_lst[]);
512 
513 /*----------------------------------------------------------------------------
514  * Dump a cs_join_vertex_t structure into a file.
515  *
516  * parameters:
517  * f <-- handle to output file
518  * vertex <-- cs_join_vertex_t structure to dump
519  *---------------------------------------------------------------------------*/
520 
521 void
523  const cs_join_vertex_t vertex);
524 
525 /*----------------------------------------------------------------------------
526  * Dump a cs_join_mesh_t structure into a file.
527  *
528  * parameters:
529  * f <-- handle to output file
530  * mesh <-- pointer to cs_join_mesh_t structure to dump
531  *---------------------------------------------------------------------------*/
532 
533 void
534 cs_join_mesh_dump(FILE *f,
535  const cs_join_mesh_t *mesh);
536 
537 /*----------------------------------------------------------------------------
538  * Dump a list of cs_join_edge_t structures.
539  *
540  * parameters:
541  * f <-- handle to output file
542  * edges <-- cs_join_edges_t structure to dump
543  * mesh <-- associated cs_join_mesh_t structure
544  *---------------------------------------------------------------------------*/
545 
546 void
548  const cs_join_edges_t *edges,
549  const cs_join_mesh_t *mesh);
550 
551 /*---------------------------------------------------------------------------*/
552 
554 
555 #endif /* __CS_JOIN_MESH_H__ */
void cs_join_mesh_destroy(cs_join_mesh_t **mesh)
Definition: cs_join_mesh.c:1934
cs_gnum_t * face_gnum
Definition: cs_join_mesh.h:119
cs_int_t cs_join_mesh_get_edge(cs_int_t v1_num, cs_int_t v2_num, const cs_join_edges_t *edges)
Definition: cs_join_mesh.c:3271
cs_join_face_type_t
Definition: cs_join_mesh.h:61
size_t len
Definition: mei_scanner.c:639
void cs_join_mesh_copy(cs_join_mesh_t **mesh, const cs_join_mesh_t *ref_mesh)
Definition: cs_join_mesh.c:1985
cs_int_t n_edges
Definition: cs_join_mesh.h:85
cs_real_t * cs_join_mesh_get_face_normal(const cs_join_mesh_t *mesh)
Definition: cs_join_mesh.c:3535
cs_int_t * face_vtx_idx
Definition: cs_join_mesh.h:120
void cs_join_mesh_dump(FILE *f, const cs_join_mesh_t *mesh)
Definition: cs_join_mesh.c:3824
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
Definition: cs_join_mesh.h:80
Definition: cs_join_mesh.h:66
cs_int_t * edge_lst
Definition: cs_join_mesh.h:105
cs_gnum_t n_g_vertices
Definition: cs_join_mesh.h:126
cs_gnum_t gnum
Definition: cs_join_mesh.h:73
cs_gnum_t n_g_edges
Definition: cs_join_mesh.h:86
int cs_int_t
Definition: cs_defs.h:263
cs_int_t n_faces
Definition: cs_join_mesh.h:117
cs_join_edges_t * cs_join_mesh_define_edges(const cs_join_mesh_t *mesh)
Definition: cs_join_mesh.c:2928
cs_int_t * def
Definition: cs_join_mesh.h:87
cs_join_mesh_t * cs_join_mesh_create_from_select(const char *name, const cs_join_param_t param, cs_join_select_t *selection, const cs_int_t b_f2v_idx[], const cs_int_t b_f2v_lst[], const cs_int_t i_f2v_idx[], const cs_int_t i_f2v_lst[], const cs_int_t n_vertices, const cs_real_t vtx_coord[], const cs_gnum_t vtx_gnum[])
Definition: cs_join_mesh.c:1836
cs_join_state_t state
Definition: cs_join_mesh.h:72
cs_int_t * adj_vtx_lst
Definition: cs_join_mesh.h:104
void cs_join_mesh_clean(cs_join_mesh_t *mesh, int verbosity)
Definition: cs_join_mesh.c:2881
cs_join_mesh_t * cs_join_mesh_create_from_subset(const char *mesh_name, cs_int_t subset_size, const cs_int_t selection[], const cs_join_mesh_t *parent_mesh)
Definition: cs_join_mesh.c:1663
void cs_join_mesh_minmax_tol(cs_join_param_t param, cs_join_mesh_t *mesh)
Definition: cs_join_mesh.c:2042
Definition: cs_join_util.h:199
double tolerance
Definition: cs_join_mesh.h:74
cs_int_t * vtx_idx
Definition: cs_join_mesh.h:103
Definition: cs_join_mesh.h:111
cs_int_t * face_vtx_lst
Definition: cs_join_mesh.h:121
void cs_join_mesh_face_order(cs_join_mesh_t *mesh)
Definition: cs_join_mesh.c:2515
cs_join_vertex_t * vertices
Definition: cs_join_mesh.h:127
cs_join_mesh_t * cs_join_mesh_create_from_glob_sel(const char *mesh_name, cs_int_t n_elts, const cs_gnum_t glob_sel[], const cs_gnum_t gnum_rank_index[], const cs_join_mesh_t *local_mesh)
Definition: cs_join_mesh.c:1580
void cs_join_mesh_dump_edges(FILE *f, const cs_join_edges_t *edges, const cs_join_mesh_t *mesh)
Definition: cs_join_mesh.c:3944
unsigned cs_gnum_t
Definition: cs_defs.h:255
Definition: cs_join_mesh.h:64
Definition: cs_join_mesh.h:63
void cs_join_mesh_dump_vertex(FILE *f, const cs_join_vertex_t vertex)
Definition: cs_join_mesh.c:3803
cs_gnum_t * gnum
Definition: cs_join_mesh.h:89
cs_join_state_t
Definition: cs_join_util.h:70
cs_join_mesh_t * cs_join_mesh_create(const char *name)
Definition: cs_join_mesh.c:1531
void cs_join_mesh_reset(cs_join_mesh_t *mesh)
Definition: cs_join_mesh.c:1958
Definition: cs_join_mesh.h:65
#define END_C_DECLS
Definition: cs_defs.h:366
double cs_real_t
Definition: cs_defs.h:264
cs_int_t n_vertices
Definition: cs_join_mesh.h:125
void cs_join_mesh_destroy_edges(cs_join_edges_t **edges)
Definition: cs_join_mesh.c:2486
void cs_join_mesh_sync_vertices(cs_join_mesh_t *mesh)
Definition: cs_join_util.h:86
void cs_join_mesh_vertex_clean(cs_join_mesh_t *mesh)
Definition: cs_join_mesh.c:2774
cs_int_t n_vertices
Definition: cs_join_mesh.h:102
char * name
Definition: cs_join_mesh.h:113
void cs_join_mesh_update(cs_join_mesh_t *mesh, const cs_join_edges_t *edges, const cs_int_t edge_index[], const cs_int_t edge_new_vtx_lst[], cs_int_t n_new_vertices, const cs_int_t old2new[])
Definition: cs_join_mesh.c:3321
cs_gnum_t n_g_faces
Definition: cs_join_mesh.h:118
Definition: mesh.f90:25
Definition: cs_join_mesh.h:70
void cs_join_mesh_get_edge_face_adj(const cs_join_mesh_t *mesh, const cs_join_edges_t *edges, cs_int_t *edge_face_idx[], cs_int_t *edge_face_lst[])
Definition: cs_join_mesh.c:3659