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