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