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