8.3
general 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-2024 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
55typedef 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
65typedef 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
75typedef 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
106typedef 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/*----------------------------------------------------------------------------
133 * Allocate and initialize a new cs_join_mesh_t structure.
134 *
135 * parameters:
136 * name <-- name of the mesh
137 *
138 * returns:
139 * a pointer to a cs_join_mesh_t structure.
140 *---------------------------------------------------------------------------*/
141
142cs_join_mesh_t *
143cs_join_mesh_create(const char *name);
144
145/*----------------------------------------------------------------------------
146 * Get a cs_join_mesh_t structure with the given list of global faces inside.
147 *
148 * Exchange between ranks to get the connectivity associated to each
149 * face of the global numbering list.
150 *
151 * parameters:
152 * mesh_name <-- name of the created mesh
153 * n_elts <-- number of elements in the global list
154 * glob_sel <-- list of global elements (ordered)
155 * gnum_rank_index <-- index on ranks for the global elements
156 * local_mesh <-- pointer to the local part of the distributed
157 * cs_join_mesh_t structure on selected elements
158 *
159 * returns:
160 * a pointer to a new allocated cs_join_mesh_t structure
161 *---------------------------------------------------------------------------*/
162
163cs_join_mesh_t *
164cs_join_mesh_create_from_glob_sel(const char *mesh_name,
165 cs_lnum_t n_elts,
166 const cs_gnum_t glob_sel[],
167 const cs_gnum_t gnum_rank_index[],
168 const cs_join_mesh_t *local_mesh);
169
170/*----------------------------------------------------------------------------
171 * Allocate and define a cs_join_mesh_t structure relative to an extraction
172 * of selected faces.
173 *
174 * The selection must be ordered.
175 *
176 * parameters:
177 * mesh_name <-- name of the name to create
178 * subset_size <-- number of selected faces in the subset
179 * selection <-- list of selected faces. Numbering in parent mesh
180 * parent_mesh <-- parent cs_join_mesh_t structure
181 *
182 * returns:
183 * a pointer to a cs_join_mesh_t structure
184 *---------------------------------------------------------------------------*/
185
186cs_join_mesh_t *
187cs_join_mesh_create_from_subset(const char *mesh_name,
188 cs_lnum_t subset_size,
189 const cs_lnum_t selection[],
190 const cs_join_mesh_t *parent_mesh);
191
192/*----------------------------------------------------------------------------
193 * Define a cs_join_mesh_t structure from a selection of faces and its
194 * related vertices.
195 *
196 * parameters:
197 * name <-- mesh name of the resulting cs_join_mesh_t structure
198 * param <-- set of user-defined parameters for the joining
199 * selection <-> selected entities
200 * b_f2v_idx <-- border "face -> vertex" connectivity index
201 * b_f2v_lst <-- border "face -> vertex" connectivity
202 * i_f2v_idx <-- interior "face -> vertex" connectivity index
203 * i_f2v_lst <-- interior "face -> vertex" connectivity
204 * n_vertices <-- number of vertices in the parent mesh
205 * vtx_coord <-- vertex coordinates in parent mesh
206 * vtx_gnum <-- global numbering of vertices
207 *
208 * returns:
209 * a pointer to a cs_join_mesh_t structure
210 *---------------------------------------------------------------------------*/
211
212cs_join_mesh_t *
213cs_join_mesh_create_from_select(const char *name,
214 const cs_join_param_t param,
215 cs_join_select_t *selection,
216 const cs_lnum_t b_f2v_idx[],
217 const cs_lnum_t b_f2v_lst[],
218 const cs_lnum_t i_f2v_idx[],
219 const cs_lnum_t i_f2v_lst[],
220 const cs_lnum_t n_vertices,
221 const cs_real_t vtx_coord[],
222 const cs_gnum_t vtx_gnum[]);
223
224/*----------------------------------------------------------------------------
225 * Destroy a cs_join_mesh_t structure.
226 *
227 * parameters:
228 * mesh <-> pointer to pointer to cs_join_mesh_t structure to destroy
229 *---------------------------------------------------------------------------*/
230
231void
232cs_join_mesh_destroy(cs_join_mesh_t **mesh);
233
234/*----------------------------------------------------------------------------
235 * Re-initialize an existing cs_join_mesh_t structure.
236 *
237 * parameters:
238 * mesh <-> pointer to a cs_join_mesh_t structure
239 *---------------------------------------------------------------------------*/
240
241void
242cs_join_mesh_reset(cs_join_mesh_t *mesh);
243
244/*----------------------------------------------------------------------------
245 * Copy a cs_join_mesh_t structure into another.
246 *
247 * parameters:
248 * mesh <-> pointer to a cs_join_mesh_t structure to fill
249 * ref_mesh <-- pointer to the reference
250 *---------------------------------------------------------------------------*/
251
252void
253cs_join_mesh_copy(cs_join_mesh_t **mesh,
254 const cs_join_mesh_t *ref_mesh);
255
256/*----------------------------------------------------------------------------
257 * Compute the global min/max tolerance defined on vertices and display it
258 *
259 * parameters:
260 * param <-- user-defined parameters for the joining algorithm
261 * mesh <-- pointer to a cs_join_mesh_t structure
262 *---------------------------------------------------------------------------*/
263
264void
266 cs_join_mesh_t *mesh);
267
268#if defined(HAVE_MPI)
269
270/*----------------------------------------------------------------------------
271 * Get the connectivity of a list of global elements distributed over the
272 * ranks.
273 *
274 * parameters:
275 * n_send <-- number of face/rank couples to send
276 * send_rank <-- index on ranks for the face distribution
277 * send_faces <-- list of face ids to send
278 * send_mesh <-- pointer to the sending cs_join_mesh_t structure
279 * recv_mesh <-> pointer to the receiving cs_join_mesh_t structure
280 * comm <-- mpi communicator on which take places comm.
281 *---------------------------------------------------------------------------*/
282
283void
284cs_join_mesh_exchange(cs_lnum_t n_send,
285 const int send_rank[],
286 const cs_lnum_t send_faces[],
287 const cs_join_mesh_t *send_mesh,
288 cs_join_mesh_t *recv_mesh,
289 MPI_Comm comm);
290
291#endif /* defined(HAVE_MPI) */
292
293/*----------------------------------------------------------------------------
294 * Destroy a cs_join_edges_t structure.
295 *
296 * parameters:
297 * edges <-> pointer to pointer to cs_join_edges_t structure to destroy
298 *---------------------------------------------------------------------------*/
299
300void
301cs_join_mesh_destroy_edges(cs_join_edges_t **edges);
302
303/*----------------------------------------------------------------------------
304 * Order a cs_join_mesh_t structure according to its global face numbering
305 *
306 * Delete redundancies.
307 *
308 * parameters:
309 * mesh <-> pointer to a cs_join_mesh_t structure to order
310 *---------------------------------------------------------------------------*/
311
312void
313cs_join_mesh_face_order(cs_join_mesh_t *mesh);
314
315/*----------------------------------------------------------------------------
316 * Synchronize vertices definition over the rank. For a vertex with the same
317 * global number but a not equal tolerance, we keep the minimal tolerance.
318 *
319 * parameters:
320 * mesh <-> pointer to the cs_join_mesh_t structure to synchronize
321 *---------------------------------------------------------------------------*/
322
323void
325
326/*----------------------------------------------------------------------------
327 * Delete vertices which appear several times (same global number) and
328 * vertices which are not used in face definition.
329 *
330 * parameters:
331 * mesh <-> pointer to cs_join_mesh_t structure to clean
332 *---------------------------------------------------------------------------*/
333
334void
335cs_join_mesh_vertex_clean(cs_join_mesh_t *mesh);
336
337/*----------------------------------------------------------------------------
338 * Clean the given cs_join_mesh_t structure, removing degenerate edges.
339 *
340 * parameters:
341 * mesh <-> pointer to the cs_join_mesh_t structure to clean
342 * verbosity <-- level of display
343 *---------------------------------------------------------------------------*/
344
345void
346cs_join_mesh_clean(cs_join_mesh_t *mesh,
347 int verbosity);
348
349/*----------------------------------------------------------------------------
350 * Define a list of edges associated to a cs_join_mesh_t structure.
351 *
352 * parameters:
353 * mesh <-- pointer to a cs_join_mesh_t structure
354 *
355 * returns:
356 * a pointer to the new defined cs_join_edges_t structure.
357 *---------------------------------------------------------------------------*/
358
359cs_join_edges_t *
360cs_join_mesh_define_edges(const cs_join_mesh_t *mesh);
361
362/*----------------------------------------------------------------------------
363 * Get the edge number relative to a couple of vertex numbers.
364 *
365 * edge_num > 0 if couple is in the same order as the edge->def
366 * edge_num < 0 otherwise
367 *
368 * parameters:
369 * v1_num <-- vertex number for the first vertex
370 * v2_num <-- vertex number for the second vertex
371 * edges <-- pointer to a cs_join_edges_t structure
372 *
373 * returns:
374 * an edge number relative to the couple of vertices
375 *---------------------------------------------------------------------------*/
376
379 cs_lnum_t v2_num,
380 const cs_join_edges_t *edges);
381
382/*----------------------------------------------------------------------------
383 * Re-organize the cs_join_mesh_t structure after a renumbering of
384 * the vertices following the merge operation + a new description of each
385 * face.
386 *
387 * parameters:
388 * mesh <-> pointer to the cs_join_mesh_t structure to update
389 * edges <-- pointer to a cs_join_edges_t structure
390 * edge_index <-- index on edges for the new vertices
391 * edge_new_vtx_lst <-- list of new vertices for each edge
392 * n_new_vertices <-- new local number of vertices after merge
393 * old2new <-- array storing the relation between old/new vertex id
394 *---------------------------------------------------------------------------*/
395
396void
397cs_join_mesh_update(cs_join_mesh_t *mesh,
398 const cs_join_edges_t *edges,
399 const cs_lnum_t edge_index[],
400 const cs_lnum_t edge_new_vtx_lst[],
401 cs_lnum_t n_new_vertices,
402 const cs_lnum_t old2new[]);
403
404/*----------------------------------------------------------------------------
405 * Compute for each face of the cs_join_mesh_t structure the face normal.
406 * || face_normal || = 1 (divided by the area of the face)
407 *
408 * The caller is responsible for freeing the returned array.
409 *
410 * parameters:
411 * mesh <-- pointer to a cs_join_mesh_t structure
412 *
413 * Pi+1
414 * *---------* B : barycenter of the polygon
415 * / . . \
416 * / . . \ Pi : vertices of the polygon
417 * / . . \
418 * / . . Ti \ Ti : triangle
419 * *.........B.........* Pi
420 * Pn-1 \ . . /
421 * \ . . /
422 * \ . . /
423 * \ . T0 . /
424 * *---------*
425 * P0
426 *
427 *
428 * returns:
429 * an array with the face normal for each face of the mesh
430 *---------------------------------------------------------------------------*/
431
432cs_real_t *
433cs_join_mesh_get_face_normal(const cs_join_mesh_t *mesh);
434
435/*----------------------------------------------------------------------------
436 * Allocate and define an "edge -> face" connectivity
437 *
438 * parameters:
439 * mesh <-- pointer to a cs_join_mesh_t structure
440 * edges <-- pointer to a cs_join_edges_t structure
441 * edge_face_idx --> pointer to the edge -> face connect. index
442 * edge_face_lst --> pointer to the edge -> face connect. list
443 *---------------------------------------------------------------------------*/
444
445void
446cs_join_mesh_get_edge_face_adj(const cs_join_mesh_t *mesh,
447 const cs_join_edges_t *edges,
448 cs_lnum_t *edge_face_idx[],
449 cs_lnum_t *edge_face_lst[]);
450
451/*----------------------------------------------------------------------------
452 * Dump a cs_join_vertex_t structure into a file.
453 *
454 * parameters:
455 * f <-- handle to output file
456 * vertex <-- cs_join_vertex_t structure to dump
457 *---------------------------------------------------------------------------*/
458
459void
461 const cs_join_vertex_t vertex);
462
463/*----------------------------------------------------------------------------
464 * Dump a cs_join_mesh_t structure into a file.
465 *
466 * parameters:
467 * f <-- handle to output file
468 * mesh <-- pointer to cs_join_mesh_t structure to dump
469 *---------------------------------------------------------------------------*/
470
471void
472cs_join_mesh_dump(FILE *f,
473 const cs_join_mesh_t *mesh);
474
475/*----------------------------------------------------------------------------
476 * Dump a list of cs_join_edge_t structures.
477 *
478 * parameters:
479 * f <-- handle to output file
480 * edges <-- cs_join_edges_t structure to dump
481 * mesh <-- associated cs_join_mesh_t structure
482 *---------------------------------------------------------------------------*/
483
484void
486 const cs_join_edges_t *edges,
487 const cs_join_mesh_t *mesh);
488
489/*---------------------------------------------------------------------------*/
490
492
493#endif /* __CS_JOIN_MESH_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
double cs_real_t
Floating-point value.
Definition: cs_defs.h:342
uint64_t cs_gnum_t
global mesh entity number
Definition: cs_defs.h:325
#define END_C_DECLS
Definition: cs_defs.h:543
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335
void cs_join_mesh_clean(cs_join_mesh_t *mesh, int verbosity)
Definition: cs_join_mesh.cpp:2609
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.cpp:1509
cs_lnum_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.cpp:3000
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.cpp:3051
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.cpp:1594
void cs_join_mesh_dump(FILE *f, const cs_join_mesh_t *mesh)
Definition: cs_join_mesh.cpp:3554
void cs_join_mesh_dump_vertex(FILE *f, const cs_join_vertex_t vertex)
Definition: cs_join_mesh.cpp:3533
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.cpp:1767
void cs_join_mesh_vertex_clean(cs_join_mesh_t *mesh)
Definition: cs_join_mesh.cpp:2502
void cs_join_mesh_minmax_tol(cs_join_param_t param, cs_join_mesh_t *mesh)
Definition: cs_join_mesh.cpp:1975
cs_real_t * cs_join_mesh_get_face_normal(const cs_join_mesh_t *mesh)
Definition: cs_join_mesh.cpp:3265
void cs_join_mesh_dump_edges(FILE *f, const cs_join_edges_t *edges, const cs_join_mesh_t *mesh)
Definition: cs_join_mesh.cpp:3675
cs_join_edges_t * cs_join_mesh_define_edges(const cs_join_mesh_t *mesh)
Definition: cs_join_mesh.cpp:2657
void cs_join_mesh_destroy(cs_join_mesh_t **mesh)
Definition: cs_join_mesh.cpp:1867
void cs_join_mesh_sync_vertices(cs_join_mesh_t *mesh)
void cs_join_mesh_copy(cs_join_mesh_t **mesh, const cs_join_mesh_t *ref_mesh)
Definition: cs_join_mesh.cpp:1918
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.cpp:3389
void cs_join_mesh_destroy_edges(cs_join_edges_t **edges)
Definition: cs_join_mesh.cpp:2249
void cs_join_mesh_face_order(cs_join_mesh_t *mesh)
Definition: cs_join_mesh.cpp:2278
cs_join_mesh_t * cs_join_mesh_create(const char *name)
Definition: cs_join_mesh.cpp:1460
void cs_join_mesh_reset(cs_join_mesh_t *mesh)
Definition: cs_join_mesh.cpp:1891
cs_join_state_t
Definition: cs_join_util.h:63
Definition: mesh.f90:26
Definition: cs_join_util.h:115