src/mesh/cs_join_mesh.h Source File

| programmer's documentation

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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-2013 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
47 BEGIN_C_DECLS
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
310 cs_join_mesh_minmax_tol(cs_join_param_t param,
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_ranks <-- number of ranks in the MPI communicator
321 * send_rank_index <-- 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(int n_ranks,
330 const cs_lnum_t send_rank_index[],
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 /*----------------------------------------------------------------------------
337 * Synchronize vertices definition over the ranks.
338 *
339 * For vertices with the same global number but a different tolerance,
340 * we keep the smallest tolerance.
341 *
342 * parameters:
343 * mesh <-> pointer to the cs_join_mesh_t structure to synchronize
344 *---------------------------------------------------------------------------*/
345
346 void
347 cs_join_mesh_sync_vertices(cs_join_mesh_t *mesh);
348
349 #endif /* defined(HAVE_MPI) */
350
351 /*----------------------------------------------------------------------------
352 * Destroy a cs_join_edges_t structure.
353 *
354 * parameters:
355 * edges <-> pointer to pointer to cs_join_edges_t structure to destroy
356 *---------------------------------------------------------------------------*/
357
358 void
359 cs_join_mesh_destroy_edges(cs_join_edges_t **edges);
360
361 /*----------------------------------------------------------------------------
362 * Order a cs_join_mesh_t structure according to its global face numbering
363 *
364 * Delete redundancies.
365 *
366 * parameters:
367 * mesh <-> pointer to a cs_join_mesh_t structure to order
368 *---------------------------------------------------------------------------*/
369
370 void
371 cs_join_mesh_face_order(cs_join_mesh_t *mesh);
372
373 /*----------------------------------------------------------------------------
374 * Synchronize vertices definition over the rank. For a vertex with the same
375 * global number but a not equal tolerance, we keep the minimal tolerance.
376 *
377 * parameters:
378 * mesh <-> pointer to the cs_join_mesh_t structure to synchronize
379 *---------------------------------------------------------------------------*/
380
381 void
382 cs_join_mesh_sync_vertices(cs_join_mesh_t *mesh);
383
384 /*----------------------------------------------------------------------------
385 * Delete vertices which appear several times (same global number) and
386 * vertices which are not used in face definition.
387 *
388 * parameters:
389 * mesh <-> pointer to cs_join_mesh_t structure to clean
390 *---------------------------------------------------------------------------*/
391
392 void
393 cs_join_mesh_vertex_clean(cs_join_mesh_t *mesh);
394
395 /*----------------------------------------------------------------------------
396 * Clean the given cs_join_mesh_t structure, removing degenerate edges.
397 *
398 * parameters:
399 * mesh <-> pointer to the cs_join_mesh_t structure to clean
400 * verbosity <-- level of display
401 *---------------------------------------------------------------------------*/
402
403 void
404 cs_join_mesh_clean(cs_join_mesh_t *mesh,
405 int verbosity);
406
407 /*----------------------------------------------------------------------------
408 * Define a list of edges associated to a cs_join_mesh_t structure.
409 *
410 * parameters:
411 * mesh <-- pointer to a cs_join_mesh_t structure
412 *
413 * returns:
414 * a pointer to the new defined cs_join_edges_t structure.
415 *---------------------------------------------------------------------------*/
416
417 cs_join_edges_t *
418 cs_join_mesh_define_edges(const cs_join_mesh_t *mesh);
419
420 /*----------------------------------------------------------------------------
421 * Get the edge number relative to a couple of vertex numbers.
422 *
423 * edge_num > 0 if couple is in the same order as the edge->def
424 * edge_num < 0 otherwise
425 *
426 * parameters:
427 * v1_num <-- vertex number for the first vertex
428 * v2_num <-- vertex number for the second vertex
429 * edges <-- pointer to a cs_join_edges_t structure
430 *
431 * returns:
432 * an edge number relative to the couple of vertices
433 *---------------------------------------------------------------------------*/
434
435 cs_int_t
436 cs_join_mesh_get_edge(cs_lnum_t v1_num,
437 cs_lnum_t v2_num,
438 const cs_join_edges_t *edges);
439
440 /*----------------------------------------------------------------------------
441 * Re-organize the cs_join_mesh_t structure after a renumbering of
442 * the vertices following the merge operation + a new description of each
443 * face.
444 *
445 * parameters:
446 * mesh <-> pointer to the cs_join_mesh_t structure to update
447 * edges <-- pointer to a cs_join_edges_t structure
448 * edge_index <-- index on edges for the new vertices
449 * edge_new_vtx_lst <-- list of new vertices for each edge
450 * n_new_vertices <-- new local number of vertices after merge
451 * old2new <-- array storing the relation between old/new vertex id
452 *---------------------------------------------------------------------------*/
453
454 void
455 cs_join_mesh_update(cs_join_mesh_t *mesh,
456 const cs_join_edges_t *edges,
457 const cs_lnum_t edge_index[],
458 const cs_lnum_t edge_new_vtx_lst[],
459 cs_lnum_t n_new_vertices,
460 const cs_lnum_t old2new[]);
461
462 /*----------------------------------------------------------------------------
463 * Compute for each face of the cs_join_mesh_t structure the face normal.
464 * || face_normal || = 1 (divided by the area of the face)
465 *
466 * The caller is responsible for freeing the returned array.
467 *
468 * parameters:
469 * mesh <-- pointer to a cs_join_mesh_t structure
470 *
471 * Pi+1
472 * *---------* B : barycenter of the polygon
473 * / . . \
474 * / . . \ Pi : vertices of the polygon
475 * / . . \
476 * / . . Ti \ Ti : triangle
477 * *.........B.........* Pi
478 * Pn-1 \ . . /
479 * \ . . /
480 * \ . . /
481 * \ . T0 . /
482 * *---------*
483 * P0
484 *
485 *
486 * returns:
487 * an array with the face normal for each face of the mesh
488 *---------------------------------------------------------------------------*/
489
490 cs_real_t *
491 cs_join_mesh_get_face_normal(const cs_join_mesh_t *mesh);
492
493 /*----------------------------------------------------------------------------
494 * Allocate and define an "edge -> face" connectivity
495 *
496 * parameters:
497 * mesh <-- pointer to a cs_join_mesh_t structure
498 * edges <-- pointer to a cs_join_edges_t structure
499 * edge_face_idx --> pointer to the edge -> face connect. index
500 * edge_face_lst --> pointer to the edge -> face connect. list
501 *---------------------------------------------------------------------------*/
502
503 void
504 cs_join_mesh_get_edge_face_adj(const cs_join_mesh_t *mesh,
505 const cs_join_edges_t *edges,
506 cs_lnum_t *edge_face_idx[],
507 cs_lnum_t *edge_face_lst[]);
508
509 /*----------------------------------------------------------------------------
510 * Dump a cs_join_vertex_t structure into a file.
511 *
512 * parameters:
513 * f <-- handle to output file
514 * vertex <-- cs_join_vertex_t structure to dump
515 *---------------------------------------------------------------------------*/
516
517 void
518 cs_join_mesh_dump_vertex(FILE *f,
519 const cs_join_vertex_t vertex);
520
521 /*----------------------------------------------------------------------------
522 * Dump a cs_join_mesh_t structure into a file.
523 *
524 * parameters:
525 * f <-- handle to output file
526 * mesh <-- pointer to cs_join_mesh_t structure to dump
527 *---------------------------------------------------------------------------*/
528
529 void
530 cs_join_mesh_dump(FILE *f,
531 const cs_join_mesh_t *mesh);
532
533 /*----------------------------------------------------------------------------
534 * Dump a list of cs_join_edge_t structures.
535 *
536 * parameters:
537 * f <-- handle to output file
538 * edges <-- cs_join_edges_t structure to dump
539 * mesh <-- associated cs_join_mesh_t structure
540 *---------------------------------------------------------------------------*/
541
542 void
543 cs_join_mesh_dump_edges(FILE *f,
544 const cs_join_edges_t *edges,
545 const cs_join_mesh_t *mesh);
546
547 /*---------------------------------------------------------------------------*/
548
549 END_C_DECLS
550
551 #endif /* __CS_JOIN_MESH_H__ */