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  char *log_name; /* Optional log file name */
270 
271 } cs_join_t;
272 
273 /*=============================================================================
274  * Global variables
275  *===========================================================================*/
276 
277 extern int cs_glob_join_count;
278 extern int cs_glob_n_joinings;
279 extern cs_join_t **cs_glob_join_array;
280 
281 extern FILE *cs_glob_join_log;
282 
285 /*============================================================================
286  * Public function prototypes
287  *===========================================================================*/
288 
289 /*----------------------------------------------------------------------------
290  * Create and initialize a cs_join_t structure.
291  *
292  * parameters:
293  * join_number <-- number related to the joining operation
294  * sel_criteria <-- boundary face selection criteria
295  * fraction <-- value of the fraction parameter
296  * plane <-- value of the plane parameter
297  * perio_type <-- periodicity type (FVM_PERIODICITY_NULL if none)
298  * perio_matrix <-- periodicity transformation matrix
299  * verbosity <-- level of verbosity required
300  * visualization <-- level of visualization required
301  * preprocessing <-- is joining part of the preprocessing stage ?
302  *
303  * returns:
304  * a pointer to a new allocated cs_join_t structure
305  *---------------------------------------------------------------------------*/
306 
307 cs_join_t *
308 cs_join_create(int join_number,
309  const char *sel_criteria,
310  float fraction,
311  float plane,
312  fvm_periodicity_type_t perio_type,
313  double perio_matrix[3][4],
314  int verbosity,
315  int visualization,
316  bool preprocessing);
317 
318 /*----------------------------------------------------------------------------
319  * Destroy a cs_join_t structure.
320  *
321  * parameters:
322  * join <-> pointer to the cs_join_t structure to destroy
323  *---------------------------------------------------------------------------*/
324 
325 void
326 cs_join_destroy(cs_join_t **join);
327 
328 /*----------------------------------------------------------------------------
329  * Create and initialize a cs_join_select_t structure.
330  *
331  * parameters:
332  * selection_criteria <-- pointer to a cs_mesh_select_t structure
333  * verbosity <-- level of verbosity required
334  *
335  * returns:
336  * pointer to a newly created cs_join_select_t structure
337  *---------------------------------------------------------------------------*/
338 
339 cs_join_select_t *
340 cs_join_select_create(const char *selection_criteria,
341  int verbosity);
342 
343 /*----------------------------------------------------------------------------
344  * Destroy a cs_join_select_t structure.
345  *
346  * parameters:
347  * param <-- user-defined joining parameters
348  * join_select <-- pointer to pointer to structure to destroy
349  *---------------------------------------------------------------------------*/
350 
351 void
353  cs_join_select_t **join_select);
354 
355 /*----------------------------------------------------------------------------
356  * Extract vertices from a selection of faces.
357  *
358  * parameters:
359  * n_select_faces <-- number of selected faces
360  * select_faces <-- list of faces selected
361  * f2v_idx <-- "face -> vertex" connect. index
362  * f2v_lst <-- "face -> vertex" connect. list
363  * n_vertices <-- number of vertices
364  * n_sel_vertices <-> pointer to the number of selected vertices
365  * sel_vertices <-> pointer to the list of selected vertices
366  *---------------------------------------------------------------------------*/
367 
368 void
369 cs_join_extract_vertices(cs_lnum_t n_select_faces,
370  const cs_lnum_t *select_faces,
371  const cs_lnum_t *f2v_idx,
372  const cs_lnum_t *f2v_lst,
373  cs_lnum_t n_vertices,
374  cs_lnum_t *n_select_vertices,
375  cs_lnum_t *select_vertices[]);
376 
377 /*----------------------------------------------------------------------------
378  * Eliminate redundancies found between two lists of elements.
379  * Delete elements in elts[] and keep elements in the reference list.
380  *
381  * parameters:
382  * n_elts <-> number of elements in the list to clean
383  * elts <-> list of elements in the list to clean
384  * n_ref_elts <-- number of elements in the reference list
385  * ref_elts <-- list of reference elements
386  *---------------------------------------------------------------------------*/
387 
388 void
390  cs_lnum_t *elts[],
391  cs_lnum_t n_ref_elts,
392  cs_lnum_t ref_elts[]);
393 
394 /*----------------------------------------------------------------------------
395  * Build vertex -> vertex index for a selection of faces.
396  *
397  * "v2v_idx" is already allocated to the number of vertices in the mesh.
398  * At this stage, it is just a counter.
399  *
400  * parameters:
401  * n_faces <-- number of selected faces
402  * faces <-- list of selected faces
403  * f2v_idx <-- face -> vertex connectivity index
404  * f2v_lst <-- face -> vertex connectivity list
405  * v2v_idx <-> index to build (already allocated and may be used again)
406  *---------------------------------------------------------------------------*/
407 
408 void
410  const cs_lnum_t faces[],
411  const cs_lnum_t f2v_idx[],
412  const cs_lnum_t f2v_lst[],
413  cs_lnum_t v2v_idx[]);
414 
415 /*----------------------------------------------------------------------------
416  * Build vertex -> vertex list for a selection of faces.
417  * "count" and "v2v_lst" are already allocated to the number of vertices in
418  * the mesh.
419  *
420  * parameters:
421  * n_faces <-- number of selected faces
422  * faces <-- list of selected faces
423  * f2v_idx <-- face -> vertex connectivity index
424  * f2v_lst <-- face -> vertex connectivity list
425  * count <-> array used to count the number of values already added
426  * v2v_idx <-- vertex -> vertex connect. index
427  * v2v_lst <-> vertex -> vertex connect. list to build (can be used again)
428  *---------------------------------------------------------------------------*/
429 
430 void
432  const cs_lnum_t faces[],
433  const cs_lnum_t f2v_idx[],
434  const cs_lnum_t f2v_lst[],
435  cs_lnum_t count[],
436  const cs_lnum_t v2v_idx[],
437  cs_lnum_t v2v_lst[]);
438 
439 /*---------------------------------------------------------------------------*/
440 
442 
443 #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:2598
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:2490
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:2535
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:2642
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:2708
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:2171
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:2144
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