~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to include/base/cs_join_set.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

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