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