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