9.2
general documentation
fvm_neighborhood.h
Go to the documentation of this file.
1#ifndef FVM_NEIGHBORHOOD_H
2#define FVM_NEIGHBORHOOD_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 * Local headers
34 *----------------------------------------------------------------------------*/
35
36#include "fvm/fvm_defs.h"
37
38/*============================================================================
39 * Macro definitions
40 *============================================================================*/
41
42/*============================================================================
43 * Type definitions
44 *============================================================================*/
45
46typedef struct _fvm_neighborhood_t fvm_neighborhood_t;
47
48/*============================================================================
49 * Public function definitions
50 *============================================================================*/
51
52/*----------------------------------------------------------------------------
53 * Create a neighborhood_t structure and initialize it.
54 *
55 * parameters:
56 * comm <-- associated MPI communicator
57 *
58 * returns:
59 * pointer to an empty fvm_box_tree_t structure.
60 *----------------------------------------------------------------------------*/
61
62#if defined(HAVE_MPI)
63
65fvm_neighborhood_create(MPI_Comm comm);
66
67#else
68
71
72#endif
73
74/*----------------------------------------------------------------------------
75 * Destroy a neighborhood_t structure.
76 *
77 * parameters:
78 * n <-> pointer to pointer to fvm_neighborhood_t structure to destroy.
79 *----------------------------------------------------------------------------*/
80
81void
83
84/*----------------------------------------------------------------------------
85 * Set non-default algorithm parameters for neighborhood management structure.
86 *
87 * parameters:
88 * n <-> pointer to neighborhood management structure
89 * max_tree_depth <-- maximum search tree depth
90 * leaf_threshold <-- maximum number of boxes which can be related to
91 * a leaf of the tree if level < max_tree_depth
92 * max_box_ratio <-- stop adding levels to tree when
93 * (n_linked_boxes > max_box_ratio*n_init_boxes)
94 * max_box_ratio_distrib <-- maximum box ratio when computing coarse
95 * tree prior to parallel distribution
96 *---------------------------------------------------------------------------*/
97
98void
100 int max_tree_depth,
101 int leaf_threshold,
102 float max_box_ratio,
103 float max_box_ratio_distrib);
104
105/*----------------------------------------------------------------------------
106 * Retrieve pointers to of arrays from a neighborhood_t structure.
107 *
108 * Arrays remain the property of the neighborhood_t structure, and must not
109 * be modified by the caller.
110 *
111 * parameters:
112 * n <-> pointer to fvm_neighborhood_t structure.
113 * n_elts --> number of elements with neighbors in block
114 * associated with local rank
115 * elt_num --> global element numbers in local block (size: n_elts)
116 * neighbor_index --> start index of neighbors (size: n_elts + 1)
117 * neighbor_num --> global element neighbor numbers
118 * (size: neighbor_index[n_elts])
119 *----------------------------------------------------------------------------*/
120
121void
123 cs_lnum_t *n_elts,
124 cs_gnum_t **const elt_num,
125 cs_lnum_t **const neighbor_index,
126 cs_gnum_t **const neighbor_num);
127
128/*----------------------------------------------------------------------------
129 * Transfer ownership of arrays from a neighborhood_t structure to the
130 * calling program.
131 *
132 * Arrays that are transferred are removed from the structure, so its
133 * use after calling this function is limited to querying timing information
134 * until a new neighborhood is computed.
135 *
136 * parameters:
137 * n <-> pointer to fvm_neighborhood_t structure.
138 * n_elts --> number of elements with neighbors in block
139 * associated with local rank
140 * elt_num --> global element numbers in local block (size: n_elts)
141 * neighbor_index --> start index of neighbors (size: n_elts + 1)
142 * neighbor_num --> global element neighbor numbers
143 * (size: neighbor_index[n_elts])
144 *----------------------------------------------------------------------------*/
145
146void
148 cs_lnum_t *n_elts,
149 cs_gnum_t **elt_num,
150 cs_lnum_t **neighbor_index,
151 cs_gnum_t **neighbor_num);
152
153/*----------------------------------------------------------------------------
154 * Determine intersecting boxes.
155 *
156 * Box global numbers and extents may be either copied for the structure's
157 * internal use from the caller, or transferred to the neighborhood management
158 * structure: both the box_gnum and extents arguments have an "assigned"
159 * variant, in which case a pointer to a pointer is provided, and the
160 * argument's property is transferred to the neighborhod management structure.
161 * The unused variant of an argument should be set to NULL.
162 *
163 * Boxes may be distributed among processors, so their intersections are
164 * determined using a block distribution, and defined using their
165 * global numbers.
166 *
167 * All global numbers appearing in box_gnum[] will have a matching entry in
168 * the neighborhod structure. To remove global numbers entries with no
169 * neighbors from the structure, the fvm_neighborhood_prune() function
170 * may be used.
171 *
172 * parameters:
173 * n <-> pointer to neighborhood management structure
174 * dim <-- spatial dimension
175 * n_boxes <-- local number of boxes
176 * box_gnum <-- global numbering of boxes
177 * extents <-- coordinate extents (size: n_boxes*dim*2, as
178 * xmin1, ymin1, .. xmax1, ymax1, ..., xmin2, ...)
179 * box_gnum_assigned <-> as box_gnum, ownership transferred (NULL on return)
180 * extents_assigned <-> as extents, ownership transferred (NULL on return)
181 *---------------------------------------------------------------------------*/
182
183void
185 int dim,
186 cs_lnum_t n_boxes,
187 const cs_gnum_t *box_gnum,
188 const cs_coord_t *extents,
189 cs_gnum_t **box_gnum_assigned,
190 cs_coord_t **extents_assigned);
191
192/*----------------------------------------------------------------------------
193 * Prune a neighborhood (remove entries with no neighbors).
194 *
195 * parameters:
196 * n <-> pointer to neighborhood management structure
197 *----------------------------------------------------------------------------*/
198
199void
201
202/*----------------------------------------------------------------------------
203 * Get global statistics relative to the search structures used
204 * by fvm_neighborhood_by_boxes().
205 *
206 * All fields returned are optional: if their argument is set to NULL,
207 * the corresponding information will not be returned.
208 *
209 * For each field not set to NULL, 3 values are always returned:
210 * the mean on all ranks (rounded to the closest integer), the minimum,
211 * and the maximum value respectively.
212 *
213 * In serial mode, the mean, minimum, and maximum will be identical for most
214 * fields, but all 3 values are returned nonetheless.
215 *
216 * Note that the final memory use is only relative to the final search
217 * structure, and the comparison of the total (or average) with the minima
218 * and maxima may give an indication on load balancing.
219
220 * The mem_required field only takes into account the theoretical maximum
221 * memory footprint of the main search structure during its construction phase,
222 * and of that of temporary structures before load balancing in parallel mode,
223 * but does not include minor work arrays or buffers used during the algorithm.
224 *
225 * Neither of the 2 memory fields include the footprint of the arrays
226 * containing the query results.
227 *
228 * parameters:
229 * n <-- pointer to neighborhood management structure
230 * depth --> tree depth (max level used)
231 * n_leaves --> number of leaves in the tree
232 * n_boxes --> number of boxes in the tree
233 * n_threshold_leaves --> number of leaves where n_boxes > threshold
234 * n_leaf_boxes --> number of boxes for a leaf
235 * mem_final --> theoretical memory for final search structure
236 * mem_required --> theoretical maximum memory for main structures
237 * used during the algorithm
238 *
239 * returns:
240 * the spatial dimension associated with the box tree layout (3, 2, or 1)
241 *----------------------------------------------------------------------------*/
242
243int
245 int depth[3],
246 cs_lnum_t n_leaves[3],
247 cs_lnum_t n_boxes[3],
248 cs_lnum_t n_threshold_leaves[3],
249 cs_lnum_t n_leaf_boxes[3],
250 uint64_t mem_final[3],
251 uint64_t mem_required[3]);
252
253/*----------------------------------------------------------------------------
254 * Return timing information.
255 *
256 * parameters:
257 * n <-- pointer to neighborhood management structure
258 * build_wtime --> initialization Wall-clock time (or NULL)
259 * build_cpu_time --> initialization CPU time (or NULL)
260 * query_wtime --> query Wall-clock time (or NULL)
261 * query_cpu_time --> query CPU time (or NULL)
262 *----------------------------------------------------------------------------*/
263
264void
266 double *build_wtime,
267 double *build_cpu_time,
268 double *query_wtime,
269 double *query_cpu_time);
270
271/*----------------------------------------------------------------------------
272 * Dump a neighborhood management structure.
273 *
274 * parameters:
275 * n <-- pointer to neighborhood management structure
276 *----------------------------------------------------------------------------*/
277
278void
280
281/*----------------------------------------------------------------------------*/
282
283#endif /* FVM_NEIGHBORHOOD_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_neighborhood_by_boxes(fvm_neighborhood_t *n, int dim, cs_lnum_t n_boxes, const cs_gnum_t *box_gnum, const cs_coord_t *extents, cs_gnum_t **box_gnum_assigned, cs_coord_t **extents_assigned)
Definition: fvm_neighborhood.cpp:826
void fvm_neighborhood_get_times(const fvm_neighborhood_t *n, double *build_wtime, double *build_cpu_time, double *query_wtime, double *query_cpu_time)
Definition: fvm_neighborhood.cpp:1130
void fvm_neighborhood_prune(fvm_neighborhood_t *n)
Definition: fvm_neighborhood.cpp:993
void fvm_neighborhood_destroy(fvm_neighborhood_t **n)
Definition: fvm_neighborhood.cpp:665
struct _fvm_neighborhood_t fvm_neighborhood_t
Definition: fvm_neighborhood.h:46
fvm_neighborhood_t * fvm_neighborhood_create(MPI_Comm comm)
Definition: fvm_neighborhood.cpp:605
void fvm_neighborhood_transfer_data(fvm_neighborhood_t *n, cs_lnum_t *n_elts, cs_gnum_t **elt_num, cs_lnum_t **neighbor_index, cs_gnum_t **neighbor_num)
Definition: fvm_neighborhood.cpp:769
void fvm_neighborhood_get_data(const fvm_neighborhood_t *n, cs_lnum_t *n_elts, cs_gnum_t **const elt_num, cs_lnum_t **const neighbor_index, cs_gnum_t **const neighbor_num)
Definition: fvm_neighborhood.cpp:728
void fvm_neighborhood_dump(const fvm_neighborhood_t *n)
Definition: fvm_neighborhood.cpp:1158
void fvm_neighborhood_set_options(fvm_neighborhood_t *n, int max_tree_depth, int leaf_threshold, float max_box_ratio, float max_box_ratio_distrib)
Definition: fvm_neighborhood.cpp:696
int fvm_neighborhood_get_box_stats(const fvm_neighborhood_t *n, 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], uint64_t mem_final[3], uint64_t mem_required[3])
Definition: fvm_neighborhood.cpp:1078