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