Code_Saturne
CFD tool
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
fvm_box.h
Go to the documentation of this file.
1 #ifndef __FVM_BOX_H__
2 #define __FVM_BOX_H__
3 
4 /*============================================================================
5  * Handle boxes aligned with Cartesian axes.
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  * Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "fvm_defs.h"
35 #include "fvm_morton.h"
36 
37 /*----------------------------------------------------------------------------*/
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #if 0
42 } /* Fake brace to */
43 #endif
44 #endif /* __cplusplus */
45 
46 /*============================================================================
47  * Macro and type definitions
48  *============================================================================*/
49 
50 /* Collection of boxes */
51 
53 
54 /* Distribution on octree or quadtree */
55 
56 typedef struct _fvm_box_distrib_t fvm_box_distrib_t;
57 
58 /*============================================================================
59  * Public function definitions
60  *============================================================================*/
61 
62 /*----------------------------------------------------------------------------
63  * Create a set of boxes and initialize it.
64  *
65  * parameters:
66  * dim <-- spatial dimension
67  * normalize <-- 1 if boxes are to be normalized, 0 otherwize
68  * allow_projection <-- if 1, project to lower dimension if all boxes
69  * are cut by the median plane of the set.
70  * n_boxes <-- number of elements to create
71  * box_gnum <-- global numbering of boxes
72  * extents <-- coordinate extents (size: n_boxes*dim*2, as
73  * xmin1, ymin1, .. xmax1, ymax1, ..., xmin2, ...)
74  * comm <-- associated MPI communicator
75  *
76  * returns:
77  * a new allocated pointer to a fvm_box_set_t structure.
78  *---------------------------------------------------------------------------*/
79 
80 #if defined(HAVE_MPI)
82 fvm_box_set_create(int dim,
83  int normalize,
84  int allow_projection,
85  cs_lnum_t n_boxes,
86  const cs_gnum_t *box_gnum,
87  const cs_coord_t *box_extents,
88  MPI_Comm comm);
89 #else
91 fvm_box_set_create(int dim,
92  int normalize,
93  int allow_projection,
94  cs_lnum_t n_boxes,
95  const cs_gnum_t *box_gnum,
96  const cs_coord_t *box_extents);
97 
98 #endif
99 
100 /*----------------------------------------------------------------------------
101  * Destroy a fvm_box_set_t structure.
102  *
103  * parameters:
104  * boxes <-> pointer to pointer to the fvm_box_set_t structure to delete
105  *----------------------------------------------------------------------------*/
106 
107 void
109 
110 /*----------------------------------------------------------------------------
111  * Return the dimension associated with a set of boxes.
112  *
113  * parameters:
114  * boxes <-- pointer to set of boxes
115  *
116  * returns:
117  * associated spatial dimension
118  *---------------------------------------------------------------------------*/
119 
120 int
121 fvm_box_set_get_dim(const fvm_box_set_t *boxes);
122 
123 /*----------------------------------------------------------------------------
124  * Return the local number of boxes in a set.
125  *
126  * parameters:
127  * boxes <-- pointer to set of boxes
128  *
129  * returns:
130  * local number of boxes
131  *---------------------------------------------------------------------------*/
132 
133 cs_lnum_t
134 fvm_box_set_get_size(const fvm_box_set_t *boxes);
135 
136 /*----------------------------------------------------------------------------
137  * Return the global number of boxes in a set.
138  *
139  * parameters:
140  * boxes <-- pointer to set of boxes
141  *
142  * returns:
143  * local number of boxes
144  *---------------------------------------------------------------------------*/
145 
146 cs_gnum_t
148 
149 /*----------------------------------------------------------------------------
150  * Return extents associated with a set of boxes.
151  *
152  * The extents array is organized in the following fashion:
153  * {x_min_0, y_min_0, ..., x_max_0, y_max_0, ...
154  * x_min_n, y_min_n, ..., x_max_n, y_max_n, ...}
155  *
156  * Its size is thus: n_boxes * dim * 2.
157  *
158  * parameters:
159  * boxes <-- pointer to set of boxes
160  *
161  * returns:
162  * pointer to extents array
163  *---------------------------------------------------------------------------*/
164 
165 const cs_coord_t *
167 
168 /*----------------------------------------------------------------------------
169  * Return global numbers associated with a set of boxes.
170  *
171  * parameters:
172  * boxes <-- pointer to set of boxes
173  *
174  * returns:
175  * pointer to global box numbers array
176  *---------------------------------------------------------------------------*/
177 
178 const cs_gnum_t *
180 
181 /*----------------------------------------------------------------------------
182  * Build a Morton_index to get a well-balanced distribution of the boxes.
183  *
184  * parameters:
185  * boxes <-- pointer to associated fvm_box_set_t structure
186  * distrib <-> pointer to a fvm_box_distrib_t structure
187  * n_leaves <-- number of leaves with weight > 0
188  * leaf_codes <-- Morton code for each leaf
189  * weight <-- number of boxes related to each leaf
190  *---------------------------------------------------------------------------*/
191 
192 void
194  fvm_box_distrib_t *distrib,
195  cs_lnum_t n_leaves,
196  fvm_morton_code_t *leaf_codes,
197  cs_lnum_t *weight);
198 
199 /*----------------------------------------------------------------------------
200  * Redistribute boxes over the ranks according to the Morton index to
201  * assume a better balanced distribution of the boxes.
202  *
203  * parameters:
204  * box_distrib <-- data structure on box distribution
205  * box_set <-> pointer to the structure to redistribute
206  *---------------------------------------------------------------------------*/
207 
208 void
210  fvm_box_set_t *boxes);
211 
212 /*----------------------------------------------------------------------------
213  * Dump a fvm_box_set_t structure.
214  *
215  * parameters:
216  * box_set <-- pointer to the fvm_box_t structure
217  * verbosity <-- verbosity level (0 or 1)
218  *----------------------------------------------------------------------------*/
219 
220 void
221 fvm_box_set_dump(const fvm_box_set_t *boxes,
222  int verbosity);
223 
224 #if defined(HAVE_MPI)
225 
226 /*----------------------------------------------------------------------------
227  * Create a fvm_box_distrib_t structure.
228  *
229  * parameters:
230  * n_boxes <-- number of boxes
231  * n_g_boxes <-- global number of boxes
232  * max_level <-- max level reached locally in the related tree
233  * comm <-- MPI comm. on which distribution takes place
234  *
235  * returns:
236  * a pointer to a new allocated fvm_box_distrib_t structure.
237  *---------------------------------------------------------------------------*/
238 
240 fvm_box_distrib_create(cs_lnum_t n_boxes,
241  cs_gnum_t n_g_boxes,
242  int max_level,
243  MPI_Comm comm);
244 
245 /*----------------------------------------------------------------------------
246  * Destroy a fvm_box_distrib_t structure.
247  *
248  * parameters:
249  * distrib <-> pointer to pointer to the structure to destroy
250  *---------------------------------------------------------------------------*/
251 
252 void
253 fvm_box_distrib_destroy(fvm_box_distrib_t **distrib);
254 
255 /*----------------------------------------------------------------------------
256  * Delete redundancies in box distribution
257  *
258  * parameters:
259  * distrib <-> pointer to the fvm_box_distrib_t structure
260  *---------------------------------------------------------------------------*/
261 
262 void
263 fvm_box_distrib_clean(fvm_box_distrib_t *distrib);
264 
265 /*----------------------------------------------------------------------------
266  * Display a histogramm on leaves associated to the boxes and
267  * several other pieces of information (min, max, ...)
268  *
269  * parameters:
270  * distrib <-- pointer to the fvm_box_distrib_t structure
271  * comm <-- associated MPI communicator
272  *---------------------------------------------------------------------------*/
273 
274 void
275 fvm_box_distrib_dump_statistics(const fvm_box_distrib_t *distrib,
276  MPI_Comm comm);
277 
278 #endif /* defined(HAVE_MPI) */
279 
280 /*----------------------------------------------------------------------------*/
281 
282 #ifdef __cplusplus
283 }
284 #endif /* __cplusplus */
285 
286 #endif /* __FVM_BOX_H__ */
fvm_box_set_t * fvm_box_set_create(int dim, int normalize, int allow_projection, cs_lnum_t n_boxes, const cs_gnum_t *box_gnum, const cs_coord_t *box_extents)
Definition: fvm_box.c:223
struct _fvm_box_distrib_t fvm_box_distrib_t
Definition: fvm_box.h:56
double cs_coord_t
Definition: cs_defs.h:261
const cs_gnum_t * fvm_box_set_get_g_num(fvm_box_set_t *boxes)
Definition: fvm_box.c:500
void fvm_box_set_redistribute(const fvm_box_distrib_t *box_distrib, fvm_box_set_t *boxes)
Definition: fvm_box.c:568
const cs_coord_t * fvm_box_set_get_extents(fvm_box_set_t *boxes)
Definition: fvm_box.c:482
Definition: fvm_morton.h:65
int fvm_box_set_get_dim(const fvm_box_set_t *boxes)
Definition: fvm_box.c:413
int cs_lnum_t
Definition: cs_defs.h:260
void fvm_box_set_destroy(fvm_box_set_t **boxes)
Definition: fvm_box.c:387
cs_lnum_t fvm_box_set_get_size(const fvm_box_set_t *boxes)
Definition: fvm_box.c:434
unsigned cs_gnum_t
Definition: cs_defs.h:255
Definition: fvm_box_priv.h:81
void fvm_box_set_dump(const fvm_box_set_t *boxes, int verbosity)
Definition: fvm_box.c:690
cs_gnum_t fvm_box_set_get_global_size(const fvm_box_set_t *boxes)
Definition: fvm_box.c:455
void fvm_box_set_build_morton_index(const fvm_box_set_t *boxes, fvm_box_distrib_t *distrib, cs_lnum_t n_leaves, fvm_morton_code_t *leaf_codes, cs_lnum_t *weight)
Definition: fvm_box.c:519