Code_Saturne
CFD tool
cs_join_set.h
Go to the documentation of this file.
1 #ifndef __CS_JOIN_SET_H__
2 #define __CS_JOIN_SET_H__
3 
4 /*============================================================================
5  * Subroutines useful to manage list structures
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  * Local headers
38  *---------------------------------------------------------------------------*/
39 
40 #include "cs_base.h"
41 
42 /*---------------------------------------------------------------------------*/
43 
45 
46 /*============================================================================
47  * Macro and type definitions
48  *===========================================================================*/
49 
50 typedef struct { /* Definition of a global indexed list of global elements */
51 
54 
55  cs_gnum_t *g_elts; /* Global numbering of elements */
56 
57  cs_int_t *index; /* Index on elements from */
58  cs_gnum_t *g_list; /* Global numbering of entities linked with g_elts */
59 
61 
62 typedef struct { /* Resizable array structure */
63 
67 
69 
70 /* ------------------------------------------------------------------ *
71  * Definition of a structure defining a set of equivalence between
72  * vertices for instance
73  * ------------------------------------------------------------------ */
74 
75 typedef struct {
76 
77  cs_int_t n_max_equiv; /* max. number of equiv. allocated */
78  cs_int_t n_equiv; /* number of equivalences */
79  cs_int_t *equiv_couple; /* ids of the two equivalent entities.
80  size = 2 * n_equiv */
82 
83 /*============================================================================
84  * Public function prototypes
85  *===========================================================================*/
86 
87 /*----------------------------------------------------------------------------
88  * Allocate a resizable array.
89  *
90  * parameters:
91  * max_size <-- initial number of elements to allocate
92  *
93  * returns:
94  * pointer to a new alloacted resizable array
95  *---------------------------------------------------------------------------*/
96 
99 
100 /*----------------------------------------------------------------------------
101  * Destroy a cs_join_rset_t structure.
102  *
103  * parameter:
104  * set <-- pointer to pointer to the cs_join_rset_t structure to destroy
105  *---------------------------------------------------------------------------*/
106 
107 void
109 
110 /*----------------------------------------------------------------------------
111  * Check if we need to resize the current cs_join_rset_t structure and do
112  * it if necessary.
113  *
114  * parameters:
115  * set <-- pointer to pointer to the cs_join_rset_t structure to test
116  * test_size <-- target size
117  *---------------------------------------------------------------------------*/
118 
119 void
121  cs_int_t test_size);
122 
123 /*----------------------------------------------------------------------------
124  * Create a new cs_join_eset_t structure.
125  *
126  * parameters:
127  * init_size <-- number of initial equivalences to allocate
128  *
129  * returns:
130  * a pointer to a new cs_join_eset_t structure
131  *---------------------------------------------------------------------------*/
132 
134 cs_join_eset_create(cs_int_t init_size);
135 
136 /*----------------------------------------------------------------------------
137  * Check if the requested size if allocated in the structure.
138  *
139  * Reallocate cs_join_eset_t structure if necessary.
140  *
141  * parameters:
142  * request_size <-- necessary size
143  * equiv_set <-> pointer to pointer to the cs_join_eset_t struct.
144  *---------------------------------------------------------------------------*/
145 
146 void
147 cs_join_eset_check_size(cs_int_t request_size,
148  cs_join_eset_t **equiv_set);
149 
150 /*----------------------------------------------------------------------------
151  * Destroy a cs_join_eset_t structure.
152  *
153  * parameter:
154  * equiv_set <-- pointer to pointer to the structure to destroy
155  *---------------------------------------------------------------------------*/
156 
157 void
159 
160 /*----------------------------------------------------------------------------
161  * Clean a cs_join_eset_t structure.
162  *
163  * If necessary, create a new cs_join_eset_t structure with no redundancy.
164  *
165  * parameters:
166  * eset <-- pointer to pointer to the cs_join_eset_t structure to clean
167  *---------------------------------------------------------------------------*/
168 
169 void
171 
172 /*----------------------------------------------------------------------------
173  * Create a cs_join_gset_t structure (indexed list on global numbering)
174  *
175  * parameters:
176  * n_elts <-- number of elements composing the list
177  *
178  * returns:
179  * a new allocated pointer to a cs_join_gset_t structure.
180  *---------------------------------------------------------------------------*/
181 
184 
185 /*----------------------------------------------------------------------------
186  * Build a cs_join_gset_t structure to store all the potential groups
187  * between elements.
188  *
189  * Values in g_elts are the tag values and values in g_list
190  * are position in tag array.
191  *
192  * parameters:
193  * n_elts <-- number of elements in tag array
194  * tag <-- tag array used to define a new cs_join_gset_t
195  *
196  * returns:
197  * a new allocated cs_join_gset_t structure
198  *---------------------------------------------------------------------------*/
199 
202  const cs_gnum_t tag[]);
203 
204 /*----------------------------------------------------------------------------
205  * Create a new cs_join_gset_t which holds equivalences between elements of
206  * g_list in cs_join_gset_t.
207  *
208  * For a subset of equivalences, we store their initial value in the return
209  * cs_join_gset_t structure. A subset is defined if at least two elements
210  * are equivalent.
211  *
212  * The behavior of this function is near from cs_join_gset_create_from_tag
213  * but we don't store the position in init_array but its value in init_array.
214  *
215  * parameters:
216  * set <-- pointer to a cs_join_gset_t structure
217  * init_array <-- initial values of set->g_list
218  *
219  * returns:
220  * a new allocated cs_join_gset_t structure
221  *---------------------------------------------------------------------------*/
222 
225  const cs_gnum_t init_array[]);
226 
227 /*----------------------------------------------------------------------------
228  * Copy a cs_join_gset_t structure.
229  *
230  * parameters:
231  * src <-- pointer to the cs_join_gset_t structure to copy
232  *
233  * returns:
234  * a new allocated cs_join_gset_t structure.
235  *---------------------------------------------------------------------------*/
236 
239 
240 /*----------------------------------------------------------------------------
241  * Destroy a cs_join_gset_t structure.
242  *
243  * parameters:
244  * set <-- pointer to pointer to the cs_join_gset_t structure to destroy
245  *---------------------------------------------------------------------------*/
246 
247 void
249 
250 /*----------------------------------------------------------------------------
251  * Sort a cs_join_gset_t structure according to the global numbering of
252  * the g_elts in cs_join_gset_t structure.
253  *
254  * parameters:
255  * set <-> pointer to the structure to order
256  *---------------------------------------------------------------------------*/
257 
258 void
260 
261 /*----------------------------------------------------------------------------
262  * Sort each sub-list of the g_list array in a cs_join_gset_t structure.
263  *
264  * parameters:
265  * p_set <-> pointer to the structure to sort
266  *---------------------------------------------------------------------------*/
267 
268 void
270 
271 /*----------------------------------------------------------------------------
272  * Invert a cs_join_gset_t structure.
273  *
274  * parameters:
275  * set <-- pointer to the cs_join_gset_t structure to work with
276  *
277  * returns:
278  * the new allocated and inverted set structure
279  *---------------------------------------------------------------------------*/
280 
283 
284 /*----------------------------------------------------------------------------
285  * Delete redudancies in a cs_join_gset_t structure.
286  *
287  * The output set has an ordered sub-list for each element in the set.
288  *
289  * parameters:
290  * set <-> pointer to the structure to clean
291  *---------------------------------------------------------------------------*/
292 
293 void
295 
296 /*----------------------------------------------------------------------------
297  * Delete redudancies in g_list array of a cs_join_gset_t structure.
298  *
299  * parameters:
300  * set <-> pointer to the structure to clean
301  * linked_array <-> array for which redundancies are scanned
302  *---------------------------------------------------------------------------*/
303 
304 void
306  cs_gnum_t linked_array[]);
307 
308 /*----------------------------------------------------------------------------
309  * Concatenate the two g_elts and g_list arrays.
310  *
311  * Order the new concatenated array and delete redundant elements.
312  * We get a single ordered array.
313  *
314  * parameters:
315  * set <-- pointer to the structure to work with
316  * n_elts --> number of elements in the new set
317  * new_array --> pointer to the new created array
318  *---------------------------------------------------------------------------*/
319 
320 void
322  cs_int_t *n_elts,
323  cs_gnum_t *new_array[]);
324 
325 /*----------------------------------------------------------------------------
326  * Compress a g_list such as for each element "e" in g_elts:
327  * - there is no redundancy for the linked elements of set->g_list
328  * - there is no element in set->g_list < e except if this element is not
329  * present in g_elts
330  *
331  * g_list and g_elts need to be ordered before calling this function.
332  *
333  * parameters:
334  * set <-> pointer to the structure to work with
335  *---------------------------------------------------------------------------*/
336 
337 void
339 
340 /*----------------------------------------------------------------------------
341  * Delete redundancies in set->g_elts.
342  *
343  * Merge sub-arrays associated to a common set->g_elts[i].
344  *
345  * parameters:
346  * set <-- pointer to the structure to work with
347  * order_tag <-- 0: set->g_elts is not ordered, 1: ordered
348  *---------------------------------------------------------------------------*/
349 
350 void
352  int order_tag);
353 
354 #if defined(HAVE_MPI)
355 
356 /*----------------------------------------------------------------------------
357  * Synchronize a cs_join_gset_t structure and distribute the resulting set
358  * over the rank thanks to a round-robin distribution. Elements in sync_set
359  * are ordered and there is no redundancy but list may have redundancies.
360  * Use cs_join_gset_clean() to remove redundancies in g_list.
361  *
362  * parameters:
363  * loc_set <-> pointer to the local structure to work with
364  * comm <-- mpi_comm on which synchro. and distribution take place
365  *
366  * returns:
367  * a synchronized and distributed cs_join_gset_t structure.
368  *---------------------------------------------------------------------------*/
369 
371 cs_join_gset_robin_sync(cs_join_gset_t *loc_set,
372  MPI_Comm comm);
373 
374 /*----------------------------------------------------------------------------
375  * Update a local cs_join_gset_t structure from a distributed and
376  * synchronized cs_join_gset_t structure. Round-robin distribution is used
377  * to store synchronized elements.
378  *
379  * parameters:
380  * sync_set <-- pointer to the structure which holds a synchronized block
381  * loc_set <-> pointer to a local structure holding elements to update
382  * comm <-- comm on which synchronization and distribution take place
383  *---------------------------------------------------------------------------*/
384 
385 void
386 cs_join_gset_robin_update(const cs_join_gset_t *sync_set,
387  cs_join_gset_t *loc_set,
388  MPI_Comm comm);
389 
390 /*----------------------------------------------------------------------------
391  * Synchronize a cs_join_gset_t structure and distribute the resulting set
392  * over the rank by block
393  *
394  * parameters:
395  * max_gnum <-- max global number in global element numbering
396  * loc_set <-> pointer to the local structure to work with
397  * comm <-- mpi_comm on which synchro. and distribution take place
398  *
399  * returns:
400  * a synchronized and distributed cs_join_gset_t structure.
401  *---------------------------------------------------------------------------*/
402 
404 cs_join_gset_block_sync(cs_gnum_t max_gnum,
405  cs_join_gset_t *loc_set,
406  MPI_Comm comm);
407 
408 /*----------------------------------------------------------------------------
409  * Update a local cs_join_gset_t structure from a distributed and
410  * synchronized cs_join_gset_t structure.
411  *
412  * loc_set should not have redundant elements.
413  *
414  * parameters:
415  * max_gnum <-- max global number in global element numbering
416  * sync_set <-- pointer to the structure which holds a synchronized block
417  * loc_set <-> pointer to a local structure holding elements to update
418  * comm <-- comm on which synchronization and distribution take place
419  *---------------------------------------------------------------------------*/
420 
421 void
422 cs_join_gset_block_update(cs_gnum_t max_gnum,
423  const cs_join_gset_t *sync_set,
424  cs_join_gset_t *loc_set,
425  MPI_Comm comm);
426 
427 #endif /* HAVE_MPI */
428 
429 /*----------------------------------------------------------------------------
430  * Dump an array (int or double).
431  *
432  * This function is called according to the verbosity.
433  *
434  * parameters:
435  * f <-- handle to output file
436  * type <-- type of the array to display
437  * header <-- header to display in front of the array
438  * n_elts <-- number of elements to display
439  * array <-- array to display
440  *---------------------------------------------------------------------------*/
441 
442 void
443 cs_join_dump_array(FILE *f,
444  const char *type,
445  const char *header,
446  int n_elts,
447  const void *array);
448 
449 /*----------------------------------------------------------------------------
450  * Dump a cs_join_gset_t structure.
451  *
452  * parameters:
453  * f <-- handle to output file
454  * set <-- pointer to the cs_join_gset_t structure to dump
455  *---------------------------------------------------------------------------*/
456 
457 void
458 cs_join_gset_dump(FILE *f,
459  const cs_join_gset_t *set);
460 
461 /*---------------------------------------------------------------------------*/
462 
464 
465 #endif /* __CS_JOIN_SET_H__ */
Definition: cs_join_set.h:50
cs_join_gset_t * cs_join_gset_create_from_tag(cs_int_t n_elts, const cs_gnum_t tag[])
Definition: cs_join_set.c:578
void cs_join_gset_compress(cs_join_gset_t *set)
Definition: cs_join_set.c:1367
cs_join_gset_t * cs_join_gset_invert(const cs_join_gset_t *set)
Definition: cs_join_set.c:1017
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
cs_int_t * array
Definition: cs_join_set.h:66
cs_gnum_t n_g_elts
Definition: cs_join_set.h:53
void cs_join_gset_destroy(cs_join_gset_t **set)
Definition: cs_join_set.c:895
cs_int_t n_elts
Definition: cs_join_set.h:65
void cs_join_dump_array(FILE *f, const char *type, const char *header, int n_elts, const void *array)
Definition: cs_join_set.c:2348
int cs_int_t
Definition: cs_defs.h:263
cs_int_t * equiv_couple
Definition: cs_join_set.h:79
void cs_join_gset_merge_elts(cs_join_gset_t *set, int order_tag)
Definition: cs_join_set.c:1453
void cs_join_gset_clean(cs_join_gset_t *set)
Definition: cs_join_set.c:1143
cs_int_t n_max_elts
Definition: cs_join_set.h:64
cs_int_t n_equiv
Definition: cs_join_set.h:78
cs_int_t n_elts
Definition: cs_join_set.h:52
void cs_join_gset_sort_sublist(cs_join_gset_t *set)
Definition: cs_join_set.c:993
cs_gnum_t * g_list
Definition: cs_join_set.h:58
cs_join_gset_t * cs_join_gset_create(cs_int_t n_elts)
Definition: cs_join_set.c:540
void cs_join_rset_destroy(cs_join_rset_t **set)
Definition: cs_join_set.c:302
Definition: cs_join_set.h:75
cs_join_rset_t * cs_join_rset_create(cs_int_t max_size)
Definition: cs_join_set.c:276
unsigned cs_gnum_t
Definition: cs_defs.h:255
cs_gnum_t * g_elts
Definition: cs_join_set.h:55
cs_int_t * index
Definition: cs_join_set.h:57
cs_join_gset_t * cs_join_gset_copy(const cs_join_gset_t *src)
Definition: cs_join_set.c:862
void cs_join_eset_destroy(cs_join_eset_t **equiv_set)
Definition: cs_join_set.c:414
void cs_join_gset_sort_elts(cs_join_gset_t *set)
Definition: cs_join_set.c:914
void cs_join_eset_check_size(cs_int_t request_size, cs_join_eset_t **equiv_set)
Definition: cs_join_set.c:382
#define END_C_DECLS
Definition: cs_defs.h:366
void cs_join_gset_dump(FILE *f, const cs_join_gset_t *set)
Definition: cs_join_set.c:2411
void cs_join_gset_clean_from_array(cs_join_gset_t *set, cs_gnum_t linked_array[])
Definition: cs_join_set.c:1194
void cs_join_rset_resize(cs_join_rset_t **set, cs_int_t test_size)
Definition: cs_join_set.c:320
Definition: cs_join_set.h:62
void cs_join_eset_clean(cs_join_eset_t **eset)
Definition: cs_join_set.c:432
cs_int_t n_max_equiv
Definition: cs_join_set.h:77
cs_join_eset_t * cs_join_eset_create(cs_int_t init_size)
Definition: cs_join_set.c:357
cs_join_gset_t * cs_join_gset_create_by_equiv(const cs_join_gset_t *set, const cs_gnum_t init_array[])
Definition: cs_join_set.c:711
void cs_join_gset_single_order(const cs_join_gset_t *set, cs_int_t *n_elts, cs_gnum_t *new_array[])
Definition: cs_join_set.c:1278