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