9.2
general documentation
fvm_hilbert.h
Go to the documentation of this file.
1#ifndef FVM_HILBERT_H
2#define FVM_HILBERT_H
3
4/*============================================================================
5 * Hilbert space-filling curve construction for coordinates.
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 and type definitions
40 *============================================================================*/
41
42/* Hilbert code
43 (could be switched from double to long double for extended range) */
44
45typedef double fvm_hilbert_code_t;
46
47/*============================================================================
48 * Public function definitions
49 *============================================================================*/
50
51/*----------------------------------------------------------------------------
52 * Determine the global extents associated with a set of coordinates
53 *
54 * parameters:
55 * dim <-- spatial dimension
56 * n_coords <-- local number of coordinates
57 * coords <-- entity coordinates; size: n_entities*dim (interlaced)
58 * g_extents --> global extents (size: dim*2)
59 * comm <-- associated MPI communicator
60 *---------------------------------------------------------------------------*/
61
62#if defined(HAVE_MPI)
63void
65 size_t n_coords,
66 const cs_coord_t coords[],
67 cs_coord_t g_extents[],
68 MPI_Comm comm);
69#else
70void
72 size_t n_coords,
73 const cs_coord_t coords[],
74 cs_coord_t g_extents[]);
75#endif
76
77/*----------------------------------------------------------------------------
78 * Encode an array of coordinates.
79 *
80 * The caller is responsible for freeing the returned array once it is
81 * no longer useful.
82 *
83 * parameters:
84 * dim <-- 1D, 2D or 3D
85 * extents <-- coordinate extents for normalization (size: dim*2)
86 * n_coords <-- nomber of coordinates in array
87 * coords <-- coordinates in the grid (interlaced, not normalized)
88 * h_code --> array of corresponding Hilbert codes (size: n_coords)
89 *----------------------------------------------------------------------------*/
90
91void
93 const cs_coord_t extents[],
94 cs_lnum_t n_coords,
95 const cs_coord_t coords[],
96 fvm_hilbert_code_t h_code[]);
97
98/*----------------------------------------------------------------------------
99 * Locally order a list of Hilbert ids.
100 *
101 * This variant uses an encoding into floating-point numbers. In 3D, this
102 * limits us to 19 levels for a double, though using a long double could
103 * increase this range.
104 *
105 * parameters:
106 * n_codes <-- number of Hilbert ids to order
107 * hilbert_codes <-- array of Hilbert ids to order
108 * order --> pointer to pre-allocated ordering table
109 *----------------------------------------------------------------------------*/
110
111void
113 const fvm_hilbert_code_t hilbert_codes[],
114 cs_lnum_t order[]);
115
116/*----------------------------------------------------------------------------
117 * Locally order a list of coordinates based on their Hilbert code.
118 *
119 * This variant may use a maximum depth of 32 levels, and switches
120 * to lexicographical ordering if this is not enough.
121 *
122 * parameters:
123 * dim <-- 1D, 2D or 3D
124 * extents <-- coordinate extents for normalization (size: dim*2)
125 * n_coords <-- nomber of coordinates in array
126 * coords <-- coordinates in the grid (interlaced, not normalized)
127 * order --> pointer to pre-allocated ordering table
128 *----------------------------------------------------------------------------*/
129
130void
132 const cs_coord_t extents[],
133 cs_lnum_t n_coords,
134 const cs_coord_t coords[],
135 cs_lnum_t order[]);
136
137/*----------------------------------------------------------------------------*/
146/*----------------------------------------------------------------------------*/
147
148void
149fvm_hilbert_s_to_code(double s,
150 void *elt,
151 const void *input);
152
153/*----------------------------------------------------------------------------*/
165/*----------------------------------------------------------------------------*/
166
167int
168fvm_hilbert_compare(const void *elt1,
169 const void *elt2,
170 const void *input);
171
172/*----------------------------------------------------------------------------*/
173
174#endif /* FVM_HILBERT_H */
double cs_coord_t
Definition: cs_defs.h:330
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
void fvm_hilbert_s_to_code(double s, void *elt, const void *input)
Function pointer for conversion of a double precision value in range [0, 1] to a given Hilbert code.
Definition: fvm_hilbert.cpp:597
int fvm_hilbert_compare(const void *elt1, const void *elt2, const void *input)
Function pointer for comparison of 2 Hilbert codes.
Definition: fvm_hilbert.cpp:622
void fvm_hilbert_local_order(cs_lnum_t n_codes, const fvm_hilbert_code_t hilbert_codes[], cs_lnum_t order[])
Definition: fvm_hilbert.cpp:523
double fvm_hilbert_code_t
Definition: fvm_hilbert.h:45
void fvm_hilbert_local_order_coords(int dim, const cs_coord_t extents[], cs_lnum_t n_coords, const cs_coord_t coords[], cs_lnum_t order[])
Definition: fvm_hilbert.cpp:568
void fvm_hilbert_get_coord_extents(int dim, size_t n_coords, const cs_coord_t coords[], cs_coord_t g_extents[], MPI_Comm comm)
Definition: fvm_hilbert.cpp:363
void fvm_hilbert_encode_coords(int dim, const cs_coord_t extents[], cs_lnum_t n_coords, const cs_coord_t coords[], fvm_hilbert_code_t h_code[])
Definition: fvm_hilbert.cpp:415