9.2
general documentation
cs_order.h
Go to the documentation of this file.
1#ifndef CS_ORDER_H
2#define CS_ORDER_H
3
4/*============================================================================
5 * Functions related to the ordering of local arrays.
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/*----------------------------------------------------------------------------
31 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "base/cs_defs.h"
35
36/*=============================================================================
37 * Macro definitions
38 *============================================================================*/
39
40/*============================================================================
41 * Type definitions
42 *============================================================================*/
43
44/*=============================================================================
45 * Static global variables
46 *============================================================================*/
47
48/*=============================================================================
49 * Public function prototypes
50 *============================================================================*/
51
52/*----------------------------------------------------------------------------*/
53/*
54 * \brief Test if an array of global numbers is ordered.
55 *
56 * \param[in] list optional list (0 to n-1 numbering) of selected entities
57 * (or null if all nb_ent are selected). This list may
58 * contain element numbers in any order
59 * \param[in] number array of all entity numbers (number of entity i given
60 * by number[i] or number[list[i]]) if list exists
61 * \param[in] nb_ent number of entities considered
62 *
63 * \return 1 if ordered, 0 otherwise.
64 */
65/*----------------------------------------------------------------------------*/
66
67int
68cs_order_gnum_test(const cs_lnum_t list[],
69 const cs_gnum_t number[],
70 size_t nb_ent);
71
72/*----------------------------------------------------------------------------*/
73/*
74 * \brief Return an ordering table associated with an array of global numbers.
75 *
76 * \param[in] list optional list (0 to n-1 numbering) of selected entities
77 * (or null if all nb_ent are selected). This list may
78 * contain element numbers in any order
79 * \param[in] number array of all entity numbers (number of entity i given
80 * by number[i] or number[list[i]]) if list exists
81 * (if null, a default 0 to n-1 numbering is considered)
82 * \param[in] nb_ent number of entities considered
83 *
84 * \return pointer to list of nb_ent entities (0 to n-1 numbering) ordered by
85 * increasing associated number. The calling code is responsible for
86 * freeing this array when it is not needed anymore.
87 */
88/*----------------------------------------------------------------------------*/
89
91cs_order_gnum(const cs_lnum_t list[],
92 const cs_gnum_t number[],
93 size_t nb_ent);
94
95/*----------------------------------------------------------------------------*/
96/*
97 * \brief Return a lexicographical ordering table associated with a strided
98 * array of global numbers.
99 *
100 * \param[in] list optional list (0 to n-1 numbering) of selected entities
101 * (or null if all nb_ent are selected). This list may
102 * contain element numbers in any order
103 * \param[in] number array of all entity numbers (number of entity i
104 * given by number[i] or number[list[i]]) if list
105 * exists (if null, a default 0 to n-1 numbering is
106 * considered)
107 * \param[in] stride stride of number array (number of values to compare)
108 * \param[in] nb_ent number of entities considered
109 *
110 * \return pointer to list of nb_ent entities (0 to n-1 numbering) ordered by
111 * increasing associated number. The calling code is responsible for
112 * freeing this array when it is not needed anymore.
113 */
114/*----------------------------------------------------------------------------*/
115
116cs_lnum_t *
117cs_order_gnum_s(const cs_lnum_t list[],
118 const cs_gnum_t number[],
119 size_t stride,
120 size_t nb_ent);
121
122/*----------------------------------------------------------------------------*/
123/*
124 * \brief Return a lexicographical ordering table associated with an indexed
125 * array of global numbers.
126 *
127 * \param[in] list optional list (0 to n-1 numbering) of selected entities
128 * (or null if all nb_ent are selected). This list may
129 * contain element numbers in any order
130 * \param[in] number array of all entity numbers (numbers of entity i start
131 * at index[i] or _index[i] (reduced index) if list exists).
132 * If list = null, a default 0 to n-1 numbering is considered)
133 * \param[in] index number of values to compare for each entity
134 * \param[in] nb_ent number of entities considered
135 *
136 * \return pointer to list of nb_ent entities (0 to n-1 numbering) ordered by
137 * increasing associated number. The calling code is responsible for
138 * freeing this array when it is not needed anymore.
139 */
140/*----------------------------------------------------------------------------*/
141
142cs_lnum_t *
143cs_order_gnum_i(const cs_lnum_t list[],
144 const cs_gnum_t number[],
145 const cs_lnum_t index[],
146 size_t nb_ent);
147
148/*----------------------------------------------------------------------------*/
149/*
150 * \brief Compute an ordering table associated with an array of global numbers.
151 *
152 * \param[in] list optional list (0 to n-1 numbering) of selected entities
153 * (or null if all nb_ent are selected). This list may
154 * contain element numbers in any order
155 * \param[in] number array of all entity numbers (number of entity i given
156 * by number[i] or number[list[i]]) if list exists
157 * (if null, a default 0 to n-1 numbering is considered)
158 * \param[out] order pointer to pre-allocated ordering table
159 * \param[in] nb_ent number of entities considered
160 */
161/*----------------------------------------------------------------------------*/
162
163void
165 const cs_gnum_t number[],
166 cs_lnum_t order[],
167 size_t nb_ent);
168
169/*----------------------------------------------------------------------------*/
170/*
171 * \brief Compute a lexicographical ordering table associated with an array of
172 * strided global numbers.
173 *
174 * \param[in] list optional list (0 to n-1 numbering) of selected entities
175 * (or null if all nb_ent are selected). This list may
176 * contain element numbers in any order
177 * \param[in] number array of all entity numbers (numbers of entity i start
178 * at number[i*stride] or number[list[i]*stride])
179 * if list exists (if null, a default 0 to n-1 numbering is
180 * considered)
181 * \param[in] stride stride of number array (number of values to compare)
182 * \param[out] order pointer to pre-allocated ordering table
183 * \param[in] nb_ent number of entities considered
184 */
185/*----------------------------------------------------------------------------*/
186
187void
189 const cs_gnum_t number[],
190 size_t stride,
191 cs_lnum_t order[],
192 size_t nb_ent);
193
194/*----------------------------------------------------------------------------*/
195/*
196 * \brief Compute a lexicographical ordering table associated with an indexed
197 * array of global numbers.
198 *
199 * \param[in] list optional list (0 to n-1 numbering) of selected entities
200 * (or null if all nb_ent are selected). This list may
201 * contain element numbers in any order
202 * \param[in] number array of all entity numbers (numbers of entity i start
203 * at index[i] or _index[i] (reduced index) if list
204 * exists). If list = null, a default 0 to n-1 numbering
205 * is considered)
206 * \param[in] index number of values to compare for each entity (from 0)
207 * \param[out] order pointer to pre-allocated ordering table
208 * \param[in] nb_ent number of entities considered
209 */
210/*----------------------------------------------------------------------------*/
211
212void
214 const cs_gnum_t number[],
215 const cs_lnum_t index[],
216 cs_lnum_t order[],
217 size_t nb_ent);
218
219/*----------------------------------------------------------------------------*/
220/*
221 * \brief Compute an ordering table associated with an array of local numbers.
222 *
223 * \param[in] list optional list (0 to n-1 numbering) of selected entities
224 * (or null if all nb_ent are selected). This list may
225 * contain element numbers in any order
226 * \param[in] number array of all entity numbers (number of entity i given
227 * by number[i] or number[list[i]]) if list exists
228 * (if null, a default 0 to n-1 numbering is considered)
229 * \param[out] order pointer to pre-allocated ordering table
230 * \param[in] nb_ent number of entities considered
231 */
232/*----------------------------------------------------------------------------*/
233
234void
236 const cs_lnum_t number[],
237 cs_lnum_t order[],
238 size_t nb_ent);
239
240/*----------------------------------------------------------------------------*/
241/*
242 * \brief Compute a lexicographical ordering table associated with an array of
243 * strided local numbers.
244 *
245 * \param[in] list optional list (0 to n-1 numbering) of selected entities
246 * (or null if all nb_ent are selected). This list may
247 * contain element numbers in any order
248 * \param[in] number array of all entity numbers (numbers of entity i start
249 * at number[i*stride] or number[list[i]*stride])
250 * if list exists (if null, a default 0 to n-1 numbering is
251 * considered)
252 * \param[in] stride stride of number array (number of values to compare)
253 * \param[out] order pointer to pre-allocated ordering table
254 * \param[in] nb_ent number of entities considered
255 */
256/*----------------------------------------------------------------------------*/
257
258void
260 const cs_lnum_t number[],
261 size_t stride,
262 cs_lnum_t order[],
263 size_t nb_ent);
264
265/*----------------------------------------------------------------------------*/
266/*
267 * \brief Compute an ordering table associated with an array of local values.
268 *
269 * \param[in] list optional list (0 to n-1 numbering) of selected entities
270 * (or null if all nb_ent are selected). This list may
271 * contain element numbers in any order
272 * \param[in] val array of all entity values (value of entity i given
273 * by value[i] or value[list[i]]) if list exists
274 * (if null, a default 0 to n-1 numbering is considered)
275 * \param[out] order pointer to pre-allocated ordering table
276 * \param[in] nb_ent number of entities considered
277 */
278/*----------------------------------------------------------------------------*/
279
280void
282 const cs_real_t val[],
283 cs_lnum_t order[],
284 size_t nb_ent);
285
286/*----------------------------------------------------------------------------*/
287/*
288 * \brief Build local renumbering array based on ordering of entities.
289 *
290 * \param[in] order 0 to n-1 ordering of entities by increasing attribute
291 * \param[in] nb_ent number of entities considered
292 *
293 * \return pointer to renumbering array (0 to n-1 numbering) indicating the
294 * new index of renumbered entities; The calling code is responsible
295 * for freeing this array when it is not needed anymore.
296 */
297/*----------------------------------------------------------------------------*/
298
299cs_lnum_t *
300cs_order_renumbering(const cs_lnum_t order[],
301 size_t nb_ent);
302
303/*----------------------------------------------------------------------------*/
304/*
305 * \brief Reorder data based on ordering array.
306 *
307 * \param[in] n_elts number of elements
308 * \param[in] elt_size element size
309 * \param[in] order reordering array
310 * \param[in,out] data data
311 *
312 * \return new size of data
313 */
314/*----------------------------------------------------------------------------*/
315
316void
318 size_t elt_size,
319 const cs_lnum_t order[],
320 void *data);
321
322/*----------------------------------------------------------------------------*/
323/*
324 * \brief Build a sorted array containing a single occurence of each global
325 * number in a given array.
326 *
327 * Global numbers under a given "base" value are excluded.
328 *
329 * The caller is responsible for freeing the returned array.
330 *
331 * \param[in] n_ent size of input array
332 * \param[in] base base id; numbers lower than this are dropped
333 * \param[in] number array containing of all referenced entity numbers
334 * \param[out] n_single array number of single occurences >= base
335 * \param[out] single sorted array of unique numbers >= base
336 */
337/*----------------------------------------------------------------------------*/
338
339void
340cs_order_single_gnum(size_t n_ent,
341 const cs_gnum_t base,
342 const cs_gnum_t number[],
343 size_t *n_single,
344 cs_gnum_t *single[]);
345
346/*----------------------------------------------------------------------------*/
347
348#endif /* CS_ORDER_H */
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
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 cs_order_lnum_allocated(const cs_lnum_t list[], const cs_lnum_t number[], cs_lnum_t order[], size_t nb_ent)
Compute an ordering table associated with an array of local numbers.
Definition: cs_order.cpp:1163
void cs_order_gnum_allocated_i(const cs_lnum_t list[], const cs_gnum_t number[], const cs_lnum_t index[], cs_lnum_t order[], size_t nb_ent)
Compute a lexicographical ordering table associated with an indexed array of global numbers.
Definition: cs_order.cpp:1078
cs_lnum_t * cs_order_gnum_i(const cs_lnum_t list[], const cs_gnum_t number[], const cs_lnum_t index[], size_t nb_ent)
Return a lexicographical ordering table associated with an indexed array of global numbers.
Definition: cs_order.cpp:929
cs_lnum_t * cs_order_gnum(const cs_lnum_t list[], const cs_gnum_t number[], size_t nb_ent)
Return an ordering table associated with an array of global numbers.
Definition: cs_order.cpp:852
void cs_order_reorder_data(cs_lnum_t n_elts, size_t elt_size, const cs_lnum_t order[], void *data)
Reorder data based on ordering array.
Definition: cs_order.cpp:1381
void cs_order_real_allocated(const cs_lnum_t list[], const cs_real_t val[], cs_lnum_t order[], size_t nb_ent)
Compute an ordering table associated with an array of local values.
Definition: cs_order.cpp:1292
void cs_order_single_gnum(size_t n_ent, const cs_gnum_t base, const cs_gnum_t number[], size_t *n_single, cs_gnum_t *single[])
Build a sorted array containing a single occurence of each global number in a given array.
Definition: cs_order.cpp:1421
void cs_order_gnum_allocated_s(const cs_lnum_t list[], const cs_gnum_t number[], size_t stride, cs_lnum_t order[], size_t nb_ent)
Compute a lexicographical ordering table associated with an array of strided global numbers.
Definition: cs_order.cpp:1024
int cs_order_gnum_test(const cs_lnum_t list[], const cs_gnum_t number[], size_t nb_ent)
Test if an array of global numbers is ordered.
Definition: cs_order.cpp:789
void cs_order_lnum_allocated_s(const cs_lnum_t list[], const cs_lnum_t number[], size_t stride, cs_lnum_t order[], size_t nb_ent)
Compute a lexicographical ordering table associated with an array of strided local numbers.
Definition: cs_order.cpp:1232
cs_lnum_t * cs_order_gnum_s(const cs_lnum_t list[], const cs_gnum_t number[], size_t stride, size_t nb_ent)
Return a lexicographical ordering table associated with a strided array of global numbers.
Definition: cs_order.cpp:890
cs_lnum_t * cs_order_renumbering(const cs_lnum_t order[], size_t nb_ent)
Build local renumbering array based on ordering of entities.
Definition: cs_order.cpp:1332
void cs_order_gnum_allocated(const cs_lnum_t list[], const cs_gnum_t number[], cs_lnum_t order[], size_t nb_ent)
Compute an ordering table associated with an array of global numbers.
Definition: cs_order.cpp:959