8.3
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-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#include "cs_defs.h"
31
32/*----------------------------------------------------------------------------
33 * Local headers
34 *----------------------------------------------------------------------------*/
35
36#include "fvm_defs.h"
37
38/*----------------------------------------------------------------------------*/
39
41
42/*============================================================================
43 * Macro and type definitions
44 *============================================================================*/
45
46/* Hilbert code
47 (could be switched from double to long double for extended range) */
48
49typedef double fvm_hilbert_code_t;
50
51/*============================================================================
52 * Public function definitions
53 *============================================================================*/
54
55/*----------------------------------------------------------------------------
56 * Determine the global extents associated with a set of coordinates
57 *
58 * parameters:
59 * dim <-- spatial dimension
60 * n_coords <-- local number of coordinates
61 * coords <-- entity coordinates; size: n_entities*dim (interlaced)
62 * g_extents --> global extents (size: dim*2)
63 * comm <-- associated MPI communicator
64 *---------------------------------------------------------------------------*/
65
66#if defined(HAVE_MPI)
67void
69 size_t n_coords,
70 const cs_coord_t coords[],
71 cs_coord_t g_extents[],
72 MPI_Comm comm);
73#else
74void
76 size_t n_coords,
77 const cs_coord_t coords[],
78 cs_coord_t g_extents[]);
79#endif
80
81/*----------------------------------------------------------------------------
82 * Encode an array of coordinates.
83 *
84 * The caller is responsible for freeing the returned array once it is
85 * no longer useful.
86 *
87 * parameters:
88 * dim <-- 1D, 2D or 3D
89 * extents <-- coordinate extents for normalization (size: dim*2)
90 * n_coords <-- nomber of coordinates in array
91 * coords <-- coordinates in the grid (interlaced, not normalized)
92 * h_code --> array of corresponding Hilbert codes (size: n_coords)
93 *----------------------------------------------------------------------------*/
94
95void
97 const cs_coord_t extents[],
98 cs_lnum_t n_coords,
99 const cs_coord_t coords[],
100 fvm_hilbert_code_t h_code[]);
101
102/*----------------------------------------------------------------------------
103 * Locally order a list of Hilbert ids.
104 *
105 * This variant uses an encoding into floating-point numbers. In 3D, this
106 * limits us to 19 levels for a double, though using a long double could
107 * increase this range.
108 *
109 * parameters:
110 * n_codes <-- number of Hilbert ids to order
111 * hilbert_codes <-- array of Hilbert ids to order
112 * order --> pointer to pre-allocated ordering table
113 *----------------------------------------------------------------------------*/
114
115void
117 const fvm_hilbert_code_t hilbert_codes[],
118 cs_lnum_t order[]);
119
120/*----------------------------------------------------------------------------
121 * Locally order a list of coordinates based on their Hilbert code.
122 *
123 * This variant may use a maximum depth of 32 levels, and switches
124 * to lexicographical ordering if this is not enough.
125 *
126 * parameters:
127 * dim <-- 1D, 2D or 3D
128 * extents <-- coordinate extents for normalization (size: dim*2)
129 * n_coords <-- nomber of coordinates in array
130 * coords <-- coordinates in the grid (interlaced, not normalized)
131 * order --> pointer to pre-allocated ordering table
132 *----------------------------------------------------------------------------*/
133
134void
136 const cs_coord_t extents[],
137 cs_lnum_t n_coords,
138 const cs_coord_t coords[],
139 cs_lnum_t order[]);
140
141/*----------------------------------------------------------------------------*/
150/*----------------------------------------------------------------------------*/
151
152void
153fvm_hilbert_s_to_code(double s,
154 void *elt,
155 const void *input);
156
157/*----------------------------------------------------------------------------*/
169/*----------------------------------------------------------------------------*/
170
171int
172fvm_hilbert_compare(const void *elt1,
173 const void *elt2,
174 const void *input);
175
176/*----------------------------------------------------------------------------*/
177
179
180#endif /* __FVM_HILBERT_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
double cs_coord_t
Definition: cs_defs.h:340
#define END_C_DECLS
Definition: cs_defs.h:543
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335
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:599
void fvm_hilbert_get_coord_extents(int dim, size_t n_coords, const cs_coord_t coords[], cs_coord_t g_extents[])
Definition: fvm_hilbert.cpp:372
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:624
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:525
double fvm_hilbert_code_t
Definition: fvm_hilbert.h:49
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:570
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:417