9.2
general documentation
fvm_box_tree.h
Go to the documentation of this file.
1#ifndef FVM_BOX_TREE_H
2#define FVM_BOX_TREE_H
3
4/*============================================================================
5 * Search octrees and quadtrees of boxes.
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 * Standard C library headers
34 *----------------------------------------------------------------------------*/
35
36#include <stdio.h>
37
38/*----------------------------------------------------------------------------
39 * Local headers
40 *----------------------------------------------------------------------------*/
41
42#include "fvm/fvm_box.h"
43
44/*============================================================================
45 * Macro definitions
46 *============================================================================*/
47
48/*============================================================================
49 * Type definitions
50 *============================================================================*/
51
52typedef struct _fvm_box_tree_t fvm_box_tree_t;
53
54typedef enum {
55
56 FVM_BOX_TREE_ASYNC_LEVEL, /* Boxes are placed according to tree parameters,
57 and potentially at different levels */
58 FVM_BOX_TREE_SYNC_LEVEL /* All boxes are placed for all ranks at the
59 same level */
60
62
63/*============================================================================
64 * Public function definitions
65 *============================================================================*/
66
67/*----------------------------------------------------------------------------
68 * Create a fvm_box_tree_t structure and initialize it.
69 *
70 * parameters:
71 * max_level <-- max possible level
72 * threshold <-- max number of boxes linked to an octant if
73 * max_level is not reached
74 * max_box_ratio <-- max n_linked_boxes / n_boxes ratio
75 *
76 * returns:
77 * pointer to an empty fvm_box_tree_t structure.
78 *----------------------------------------------------------------------------*/
79
81fvm_box_tree_create(int max_level,
82 int threshold,
83 float max_box_ratio);
84
85/*----------------------------------------------------------------------------
86 * Destroy a fvm_box_tree_t structure.
87 *
88 * parameters:
89 * bt <-- pointer to pointer to fvm_box_tree_t structure to destroy
90 *----------------------------------------------------------------------------*/
91
92void
94
95/*----------------------------------------------------------------------------
96 * Get the deepest level allowed by the tree structure.
97 *
98 * parameters:
99 * bt <-- pointer to fvm_box_tree_t structure.
100 *
101 * returns:
102 * deepest allowed level of the tree
103 *----------------------------------------------------------------------------*/
104
105int
107
108/*----------------------------------------------------------------------------
109 * Assign a set of boxes to an empty fvm_box_tree_t structure.
110 *
111 * The box tree structure must have been created using to fvm_tree_create().
112 *
113 * The depth of the tree is adjusted so that a maximum of max_n_elts boxes
114 * will be assigned to each leaf, unless this would require going beyond
115 * the tree's maximum level.
116 *
117 * If max_level = -1, the highest level reachable is FVM_TREE_MAX_LEVEL but
118 * there is no defined target level.
119 *
120 * parameters:
121 * bt <-> pointer to fvm_box_tree_t structure.
122 * boxes <-- pointer to the associated box set structure
123 * build_type <-- layout variant for building the tree structure
124 *----------------------------------------------------------------------------*/
125
126void
128 const fvm_box_set_t *boxes,
129 fvm_box_tree_sync_t build_type);
130
131#if defined(HAVE_MPI)
132
133/*----------------------------------------------------------------------------
134 * Compute an index based on Morton encoding to ensure a good distribution
135 * of boxes among the participating ranks.
136 *
137 * parameters:
138 * bt <-> pointer to fvm_box_tree_t structure.
139 * boxes <-- pointer to the associated box set structure
140 *
141 * returns:
142 * pointer to newly created fvm_box_distrib_t structure.
143 *----------------------------------------------------------------------------*/
144
145fvm_box_distrib_t *
147 const fvm_box_set_t *boxes);
148
149#endif /* defined(HAVE_MPI) */
150
151/*----------------------------------------------------------------------------
152 * Build an indexed list on boxes to list intersections.
153 *
154 * The index and box_g_num arrays are allocated by this function,
155 * and it is the caller's responsibility to free them.
156 *
157 * Upon return, box_index[i] points to the first position in box_g_num
158 * relative to boxes intersecting box i of the boxes set, while
159 * box_g_num contains the global numbers associated with those boxes.
160 *
161 * parameters:
162 * bt <-- pointer to box tree structure to query
163 * boxes <-- pointer to a associated box set
164 * box_index --> pointer to the index array on bounding boxes
165 * box_g_num --> pointer to the list of intersecting bounding boxes
166 *----------------------------------------------------------------------------*/
167
168void
170 const fvm_box_set_t *boxes,
171 cs_lnum_t *box_index[],
172 cs_gnum_t *box_g_num[]);
173
174/*----------------------------------------------------------------------------
175 * Get global box tree statistics.
176 *
177 * All fields returned are optional: if their argument is set to NULL,
178 * the corresponding information will not be returned.
179 *
180 * For each field not set to NULL, 3 values are always returned:
181 * the mean on all ranks (rounded to the closest integer), the minimum,
182 * and the maximum value respectively.
183 *
184 * In serial mode, the mean, minimum, and maximum will be identical for most
185 * fields, but all 3 values are returned nonetheless.
186 *
187 * Note that the theoretical memory use includes that of the associated
188 * box set.
189 *
190 * parameters:
191 * bt <-- pointer to box tree structure
192 * depth --> tree depth (max level used)
193 * n_leaves --> number of leaves in the tree
194 * n_boxes --> number of boxes in the tree
195 * n_threshold_leaves --> number of leaves where n_boxes > threshold
196 * n_leaf_boxes --> number of boxes for a leaf
197 * mem_used --> theoretical used memory
198 * mem_allocated --> theoretical allocated memory
199 *
200 * returns:
201 * the spatial dimension associated with the box tree layout (3, 2, or 1)
202 *----------------------------------------------------------------------------*/
203
204int
206 int depth[3],
207 cs_lnum_t n_leaves[3],
208 cs_lnum_t n_boxes[3],
209 cs_lnum_t n_threshold_leaves[3],
210 cs_lnum_t n_leaf_boxes[3],
211 size_t mem_used[3],
212 size_t mem_allocated[3]);
213
214/*----------------------------------------------------------------------------
215 * Display local statistics about a fvm_box_tree_t structure.
216 *
217 * parameters:
218 * bt <-- pointer to box tree structure
219 *----------------------------------------------------------------------------*/
220
221void
223
224/*----------------------------------------------------------------------------
225 * Dump an fvm_box_tree_t structure.
226 *
227 * parameters:
228 * bt <-- pointer to box tree structure
229 *----------------------------------------------------------------------------*/
230
231void
233
234/*----------------------------------------------------------------------------*/
235
236#endif /* FVM_BOX_TREE_H */
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
fvm_box_distrib_t * fvm_box_tree_get_distrib(fvm_box_tree_t *bt, const fvm_box_set_t *boxes)
Definition: fvm_box_tree.cpp:2203
void fvm_box_tree_get_intersects(fvm_box_tree_t *bt, const fvm_box_set_t *boxes, cs_lnum_t *box_index[], cs_gnum_t *box_g_num[])
Definition: fvm_box_tree.cpp:2344
fvm_box_tree_sync_t
Definition: fvm_box_tree.h:54
@ FVM_BOX_TREE_ASYNC_LEVEL
Definition: fvm_box_tree.h:56
@ FVM_BOX_TREE_SYNC_LEVEL
Definition: fvm_box_tree.h:58
fvm_box_tree_t * fvm_box_tree_create(int max_level, int threshold, float max_box_ratio)
Definition: fvm_box_tree.cpp:1960
void fvm_box_tree_dump(fvm_box_tree_t *bt)
Definition: fvm_box_tree.cpp:2738
void fvm_box_tree_destroy(fvm_box_tree_t **bt)
Definition: fvm_box_tree.cpp:2028
int fvm_box_tree_get_stats(const fvm_box_tree_t *bt, int depth[3], cs_lnum_t n_leaves[3], cs_lnum_t n_boxes[3], cs_lnum_t n_threshold_leaves[3], cs_lnum_t n_leaf_boxes[3], size_t mem_used[3], size_t mem_allocated[3])
Definition: fvm_box_tree.cpp:2429
int fvm_box_tree_get_max_level(const fvm_box_tree_t *bt)
Definition: fvm_box_tree.cpp:2054
void fvm_box_tree_set_boxes(fvm_box_tree_t *bt, const fvm_box_set_t *boxes, fvm_box_tree_sync_t build_type)
Definition: fvm_box_tree.cpp:2078
struct _fvm_box_tree_t fvm_box_tree_t
Definition: fvm_box_tree.h:52
void fvm_box_tree_dump_statistics(const fvm_box_tree_t *bt)
Definition: fvm_box_tree.cpp:2600