Code_Saturne
CFD tool
cs_join_util.h
Go to the documentation of this file.
1 #ifndef __CS_JOIN_UTIL_H__
2 #define __CS_JOIN_UTIL_H__
3 
4 /*============================================================================
5  * Manipulation of low-level structures for joining operations
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 #include <fvm_periodicity.h>
46 
47 /*----------------------------------------------------------------------------
48  * Local library headers
49  *---------------------------------------------------------------------------*/
50 
51 #include "cs_base.h"
52 #include "cs_selector.h"
53 
54 /*---------------------------------------------------------------------------*/
55 
57 
58 /*============================================================================
59  * Macro and type definitions
60  *============================================================================*/
61 
62 typedef enum {
63 
67 
69 
70 typedef enum {
71 
79 
81 
82 /*----------------------------------------------------------------------------
83  * Set of user parameters to control the join operation
84  *----------------------------------------------------------------------------*/
85 
86 typedef struct {
87 
88  int num; /* number associated to the current join operation */
89  int perio_type; /* FVM_PERIODICITY_NULL for non-periodic joinings,
90  periodicity type for periodic joinings. */
91 
92  double perio_matrix[3][4]; /* Periodicity matrix for periodic joinings */
93 
94  /* Octree - Quadtree search algorithm */
95  /* ---------------------------------- */
96 
97  int tree_max_level; /* Deepest level reachable during tree building */
98  int tree_n_max_boxes; /* Max. number of boxes which can be related to
99  a leaf of the tree if level != tree_max_level */
100 
101  float tree_max_box_ratio; /* Stop building tree when:
102  ( n_linked_boxes
103  > tree_max_box_ratio * n_init_boxes) */
104  float tree_max_box_ratio_distrib; /* In parallel, tree_max_box_ratio for
105  initial coarse tree used to
106  determine load-distribution */
107 
108  /* Geometric parameters */
109  /* -------------------- */
110 
111  /* parameter used to compute the tolerance associated to each vertex.
112  Also used for finding equivalent vertices during edge intersections */
113 
114  float fraction;
115 
116  /* maximum angle between normals of two faces considered to
117  be in the same plane (for face split) */
118 
119  float plane; /* in degree */
120  double plane_criteria; /* cos(plane in rad)*cos(plane in rad) */
121 
122  /* Coef. used to modify the tolerance associated to each vertex before the
123  merge operation.
124  If coef = 0.0 => no vertex merge
125  If coef < 1.0 => reduce vertex merge
126  If coef = 1.0 => no change
127  If coef > 1.0 => increase vertex merge */
128 
130 
131  /* Coef. used to compute a limit on staightfoward merge between
132  two vertices before the merge step. It should be a small value. */
133 
135 
136  /* Maximum number of equivalence breaks */
137 
139 
140  /* Tolerance computation mode: tcm
141  1: (default) tol = min. edge length related to a vertex * fraction
142  2: tolerance is computed like in mode 1 with in addition, the
143  multiplication by a coef. which is equal to the max sin(e1, e2)
144  where e1 and e2 are two edges sharing the same vertex V for which
145  we want to compute the tolerance
146  11: like 1 but only in taking into account only the selected faces
147  12: like 2 but only in taking into account only the selected faces */
148 
149  int tcm;
150 
151  /* Intersection computation mode: icm
152  1: (default) Original algorithm. Try to clip intersection on extremity
153  2: New intersection algorithm. Avoid to clip intersection on extremity
154  */
155 
156  int icm;
157 
158  /* Maximum number of sub-faces when splitting a face */
159 
161 
162  /* Verbosity:
163  O : no information printed
164  1 : general information printed
165  2 : more information printed
166  5 and beyond : highest level (DEBUG LEVEL) */
167 
169 
170  /* Visualization level:
171  O : no visualization output
172  1 : visualization output of joined faces
173  2 : faces modified by joining
174  */
175 
177 
179 
180 /*----------------------------------------------------------------------------
181  * Set of variables to synchronize single elements
182  *---------------------------------------------------------------------------*/
183 
184 typedef struct {
185 
186  int n_elts;
187  int n_ranks;
188  int *ranks;
189  int *index;
190  int *array;
191 
193 
194 /*----------------------------------------------------------------------------
195  * Structure used to store the result of the extraction of entities
196  * implied in the joining operation
197  *---------------------------------------------------------------------------*/
198 
199 typedef struct {
200 
201  cs_int_t n_init_b_faces; /* Number of border faces before joining */
202  cs_int_t n_init_i_faces; /* Number of interior faces before joining */
203  cs_int_t n_init_vertices; /* Number of vertices before joining */
204 
205  cs_int_t n_faces; /* Number of border faces selected
206  for the joining operation */
207  cs_gnum_t n_g_faces; /* Global number of border faces selected
208  for the joining operation */
209  cs_int_t *faces; /* List of selected border faces */
210 
211  cs_gnum_t *compact_face_gnum; /* Global face numbering defined
212  on the selected faces */
213  cs_gnum_t *compact_rank_index; /* Distribution of the selected faces
214  over the ranks */
215 
216  cs_int_t n_vertices; /* Number of vertices selected
217  for the joining operation */
218  cs_gnum_t n_g_vertices; /* Global number of selected vertices */
219  cs_int_t *vertices; /* List of selected vertices */
220 
221  /* Adjacent faces of the current face selection: border and interior */
222 
225 
228 
229  /* Keep the status of all faces of the related cs_mesh_t */
230 
233 
234  /* For periodicity handling: list of periodic vertex couples */
235 
238 
239  /*
240  Single elements (Only possible in parallel). It appears
241  when the domain splitting has a poor quality and elements
242  on the joining interface are prisms or tetraedrals
243  s = single / c = coupled
244  */
245 
247 
252 
254 
255 /*----------------------------------------------------------------------------
256  * Highest level structure to manage the joining algorithm
257  *---------------------------------------------------------------------------*/
258 
259 typedef struct {
260 
261  cs_join_param_t param; /* Set of parameters used to control
262  the joining operations */
263 
264  cs_join_select_t *selection; /* Store entities implied in the joining
265  operation */
266 
267  char *criteria; /* Criteria used to select border faces
268  implied in the joining operation */
269 
270 } cs_join_t;
271 
272 /*----------------------------------------------------------------------------
273  * Structure used to store information about a block distribution
274  *---------------------------------------------------------------------------*/
275 
276 typedef struct {
277 
278  cs_gnum_t n_g_elts; /* Global number of elements to distribute */
279  cs_gnum_t first_gnum; /* Global number of the element in the local block */
280 
281  int n_ranks; /* Number of processes in the communicator used
282  to define the current distribution */
283  int local_rank; /* Id of the current process in the communicator
284  used to define the current distribution */
285 
286  size_t size; /* Size of block for the given set of parameters */
287  size_t local_size; /* Number of global elements to treat on the local
288  rank according to the distribution */
289 
291 
292 /*=============================================================================
293  * Global variables
294  *===========================================================================*/
295 
296 extern int cs_glob_join_count;
297 extern int cs_glob_n_joinings;
299 
300 extern FILE *cs_glob_join_log;
301 
302 /*============================================================================
303  * Public function prototypes
304  *===========================================================================*/
305 
306 /*----------------------------------------------------------------------------
307  * Create and initialize a cs_join_t structure.
308  *
309  * parameters:
310  * join_number <-- number related to the joining operation
311  * sel_criteria <-- boundary face selection criteria
312  * fraction <-- value of the fraction parameter
313  * plane <-- value of the plane parameter
314  * perio_type <-- periodicity type (FVM_PERIODICITY_NULL if none)
315  * perio_matrix <-- periodicity transformation matrix
316  * verbosity <-- level of verbosity required
317  * visualization <-- level of visualization required
318  *
319  * returns:
320  * a pointer to a new allocated cs_join_t structure
321  *---------------------------------------------------------------------------*/
322 
323 cs_join_t *
324 cs_join_create(int join_number,
325  const char *sel_criteria,
326  float fraction,
327  float plane,
328  fvm_periodicity_type_t perio_type,
329  double perio_matrix[3][4],
330  int verbosity,
331  int visualization);
332 
333 /*----------------------------------------------------------------------------
334  * Destroy a cs_join_t structure.
335  *
336  * parameters:
337  * join <-> pointer to the cs_join_t structure to destroy
338  *---------------------------------------------------------------------------*/
339 
340 void
341 cs_join_destroy(cs_join_t **join);
342 
343 /*----------------------------------------------------------------------------
344  * Create and initialize a cs_join_select_t structure.
345  *
346  * parameters:
347  * selection_criteria <-- pointer to a cs_mesh_select_t structure
348  * verbosity <-- level of verbosity required
349  *
350  * returns:
351  * pointer to a newly created cs_join_select_t structure
352  *---------------------------------------------------------------------------*/
353 
355 cs_join_select_create(const char *selection_criteria,
356  int verbosity);
357 
358 /*----------------------------------------------------------------------------
359  * Define a set of parameters to control a contiguous distribution by block.
360  *
361  * parameters:
362  * n_g_elts <-- global number of elements to treat
363  * n_ranks <-- number of ranks in the MPI communicator related to the
364  * cs_join_block_info_t structure to create
365  * local_rank <-- rank in the MPI communicator related to the
366  * cs_join_block_info_t structure to create
367  *
368  * returns:
369  * a newly defined cs_join_block_info_t structure
370  *---------------------------------------------------------------------------*/
371 
374  int n_ranks,
375  int local_rank);
376 
377 /*----------------------------------------------------------------------------
378  * Extract vertices from a selection of faces.
379  *
380  * parameters:
381  * n_select_faces <-- number of selected faces
382  * select_faces <-- list of faces selected
383  * f2v_idx <-- "face -> vertex" connect. index
384  * f2v_lst <-- "face -> vertex" connect. list
385  * n_vertices <-- number of vertices
386  * n_sel_vertices <-> pointer to the number of selected vertices
387  * sel_vertices <-> pointer to the list of selected vertices
388  *---------------------------------------------------------------------------*/
389 
390 void
391 cs_join_extract_vertices(cs_int_t n_select_faces,
392  const cs_int_t *select_faces,
393  const cs_int_t *f2v_idx,
394  const cs_int_t *f2v_lst,
395  cs_int_t n_vertices,
396  cs_int_t *n_select_vertices,
397  cs_int_t *select_vertices[]);
398 
399 /*----------------------------------------------------------------------------
400  * Eliminate redundancies found between two lists of elements.
401  * Delete elements in elts[] and keep elements in the reference list.
402  *
403  * parameters:
404  * n_elts <-> number of elements in the list to clean
405  * elts <-> list of elements in the list to clean
406  * n_ref_elts <-- number of elements in the reference list
407  * ref_elts <-- list of reference elements
408  *---------------------------------------------------------------------------*/
409 
410 void
412  cs_int_t *elts[],
413  cs_int_t n_ref_elts,
414  cs_int_t ref_elts[]);
415 
416 /*----------------------------------------------------------------------------
417  * Build vertex -> vertex index for a selection of faces.
418  *
419  * "v2v_idx" is already allocated to the number of vertices in the mesh.
420  * At this stage, it is just a counter.
421  *
422  * parameters:
423  * n_faces <-- number of selected faces
424  * faces <-- list of selected faces
425  * f2v_idx <-- face -> vertex connectivity index
426  * f2v_lst <-- face -> vertex connectivity list
427  * v2v_idx <-> index to build (already allocated and may be used again)
428  *---------------------------------------------------------------------------*/
429 
430 void
432  const cs_int_t faces[],
433  const cs_int_t f2v_idx[],
434  const cs_int_t f2v_lst[],
435  cs_int_t v2v_idx[]);
436 
437 /*----------------------------------------------------------------------------
438  * Build vertex -> vertex list for a selection of faces.
439  * "count" and "v2v_lst" are already allocated to the number of vertices in
440  * the mesh.
441  *
442  * parameters:
443  * n_faces <-- number of selected faces
444  * faces <-- list of selected faces
445  * f2v_idx <-- face -> vertex connectivity index
446  * f2v_lst <-- face -> vertex connectivity list
447  * count <-> array used to count the number of values already added
448  * v2v_idx <-- vertex -> vertex connect. index
449  * v2v_lst <-> vertex -> vertex connect. list to build (can be used again)
450  *---------------------------------------------------------------------------*/
451 
452 void
454  const cs_int_t faces[],
455  const cs_int_t f2v_idx[],
456  const cs_int_t f2v_lst[],
457  cs_int_t count[],
458  const cs_int_t v2v_idx[],
459  cs_int_t v2v_lst[]);
460 
461 /*---------------------------------------------------------------------------*/
462 
464 
465 #endif /* __CS_JOIN_UTIL_H__ */
int n_ranks
Definition: cs_join_util.h:281
double plane_criteria
Definition: cs_join_util.h:120
float merge_tol_coef
Definition: cs_join_util.h:129
int n_max_equiv_breaks
Definition: cs_join_util.h:138
Definition: cs_join_util.h:259
Definition: cs_join_util.h:184
cs_int_t n_init_vertices
Definition: cs_join_util.h:203
cs_join_sync_t * c_edges
Definition: cs_join_util.h:251
Definition: cs_join_util.h:276
void cs_join_build_edges_lst(cs_int_t n_faces, const cs_int_t faces[], const cs_int_t f2v_idx[], const cs_int_t f2v_lst[], cs_int_t count[], const cs_int_t v2v_idx[], cs_int_t v2v_lst[])
Definition: cs_join_util.c:2547
int max_sub_faces
Definition: cs_join_util.h:160
fvm_periodicity_type_t
Definition: fvm_periodicity.h:57
int n_ranks
Definition: cs_join_util.h:187
int * index
Definition: cs_join_util.h:189
cs_join_type_t
Definition: cs_join_util.h:62
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
cs_gnum_t n_g_faces
Definition: cs_join_util.h:207
cs_int_t n_faces
Definition: cs_join_util.h:205
cs_int_t * i_adj_faces
Definition: cs_join_util.h:227
Definition: cs_join_util.h:74
cs_int_t n_init_b_faces
Definition: cs_join_util.h:201
float tree_max_box_ratio_distrib
Definition: cs_join_util.h:104
cs_int_t n_vertices
Definition: cs_join_util.h:216
float pre_merge_factor
Definition: cs_join_util.h:134
cs_int_t * faces
Definition: cs_join_util.h:209
FILE * cs_glob_join_log
Definition: cs_join_util.c:74
int cs_int_t
Definition: cs_defs.h:263
void cs_join_clean_selection(cs_int_t *n_elts, cs_int_t *elts[], cs_int_t n_ref_elts, cs_int_t ref_elts[])
Definition: cs_join_util.c:2437
cs_int_t n_couples
Definition: cs_join_util.h:236
int tree_max_level
Definition: cs_join_util.h:97
cs_join_sync_t * s_vertices
Definition: cs_join_util.h:248
Definition: cs_join_util.h:73
int cs_glob_join_count
Definition: cs_join_util.c:70
int local_rank
Definition: cs_join_util.h:283
cs_int_t * vertices
Definition: cs_join_util.h:219
int perio_type
Definition: cs_join_util.h:89
cs_gnum_t * per_v_couples
Definition: cs_join_util.h:237
cs_join_select_t * selection
Definition: cs_join_util.h:264
cs_gnum_t n_g_elts
Definition: cs_join_util.h:278
void cs_join_build_edges_idx(cs_int_t n_faces, const cs_int_t faces[], const cs_int_t f2v_idx[], const cs_int_t f2v_lst[], cs_int_t v2v_idx[])
Definition: cs_join_util.c:2481
char * criteria
Definition: cs_join_util.h:267
float tree_max_box_ratio
Definition: cs_join_util.h:101
Definition: cs_join_util.h:199
cs_join_state_t * b_face_state
Definition: cs_join_util.h:231
Definition: cs_join_util.h:66
cs_int_t n_init_i_faces
Definition: cs_join_util.h:202
Definition: cs_join_util.h:78
Definition: cs_join_util.h:72
cs_join_param_t param
Definition: cs_join_util.h:261
size_t size
Definition: cs_join_util.h:286
int cs_glob_n_joinings
Definition: cs_join_util.c:71
float plane
Definition: cs_join_util.h:119
unsigned cs_gnum_t
Definition: cs_defs.h:255
int * ranks
Definition: cs_join_util.h:188
Definition: cs_join_util.h:64
int tcm
Definition: cs_join_util.h:149
cs_int_t * b_adj_faces
Definition: cs_join_util.h:226
Definition: cs_join_util.h:75
cs_join_sync_t * s_edges
Definition: cs_join_util.h:250
cs_join_state_t
Definition: cs_join_util.h:70
cs_join_t ** cs_glob_join_array
Definition: cs_join_util.c:72
int verbosity
Definition: cs_join_util.h:168
cs_join_select_t * cs_join_select_create(const char *selection_criteria, int verbosity)
Definition: cs_join_util.c:1999
#define END_C_DECLS
Definition: cs_defs.h:366
void cs_join_destroy(cs_join_t **join)
Definition: cs_join_util.c:1963
cs_gnum_t * compact_face_gnum
Definition: cs_join_util.h:211
int num
Definition: cs_join_util.h:88
cs_gnum_t n_g_vertices
Definition: cs_join_util.h:218
cs_join_sync_t * c_vertices
Definition: cs_join_util.h:249
Definition: cs_join_util.h:77
cs_gnum_t first_gnum
Definition: cs_join_util.h:279
int n_elts
Definition: cs_join_util.h:186
Definition: cs_join_util.h:86
Definition: cs_join_util.h:76
size_t local_size
Definition: cs_join_util.h:287
cs_join_block_info_t cs_join_get_block_info(cs_gnum_t n_g_elts, int n_ranks, int local_rank)
Definition: cs_join_util.c:2319
cs_int_t n_b_adj_faces
Definition: cs_join_util.h:223
int tree_n_max_boxes
Definition: cs_join_util.h:98
cs_int_t n_i_adj_faces
Definition: cs_join_util.h:224
float fraction
Definition: cs_join_util.h:114
bool do_single_sync
Definition: cs_join_util.h:246
Definition: cs_join_util.h:65
cs_gnum_t * compact_rank_index
Definition: cs_join_util.h:213
int icm
Definition: cs_join_util.h:156
int * array
Definition: cs_join_util.h:190
cs_join_t * cs_join_create(int join_number, const char *sel_criteria, float fraction, float plane, fvm_periodicity_type_t perio_type, double perio_matrix[3][4], int verbosity, int visualization)
Definition: cs_join_util.c:1873
void cs_join_extract_vertices(cs_int_t n_select_faces, const cs_int_t *select_faces, const cs_int_t *f2v_idx, const cs_int_t *f2v_lst, cs_int_t n_vertices, cs_int_t *n_select_vertices, cs_int_t *select_vertices[])
Definition: cs_join_util.c:2374
int visualization
Definition: cs_join_util.h:176
cs_join_state_t * i_face_state
Definition: cs_join_util.h:232