chombo-discharge
Loading...
Searching...
No Matches
Source
Particle
CD_ParticleMap.H
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3
*
4
* SPDX-License-Identifier: GPL-3.0-or-later
5
*/
6
13
#ifndef CD_PARTICLEMAP_H
14
#define CD_PARTICLEMAP_H
15
16
// Std includes
17
#include <cstdint>
18
#include <utility>
19
#include <unordered_map>
20
#include <map>
21
22
// Our includes
23
#include <CD_NamespaceHeader.H>
24
25
// Compile-time sanity checks (optional but nice)
26
static_assert
(
sizeof
(uint32_t) == 4,
"uint32_t must be 32 bits"
);
27
static_assert
(
sizeof
(uint64_t) == 8,
"uint64_t must be 64 bits"
);
28
static_assert
(
sizeof
(size_t) == 8,
"size_t must be 64 bits"
);
29
36
static
inline
uint64_t
37
encodePair(uint32_t a_level, uint32_t a_gridIndex)
noexcept
38
{
39
return
(std::uint64_t(a_level) << 32) | std::uint64_t(a_gridIndex);
40
}
41
47
static
inline
std::pair<uint32_t, uint32_t>
48
decodePair(uint64_t key)
noexcept
49
{
50
return
{uint32_t(key >> 32), uint32_t(key)};
51
}
52
56
struct
PairHash
57
{
63
std::size_t
64
operator()
(
const
std::pair<uint32_t, uint32_t>& p)
const
noexcept
65
{
66
return
encodePair(p.first, p.second);
67
}
68
};
69
74
template
<
typename
T>
75
using
ParticleMap
= std::unordered_map<std::pair<uint32_t, uint32_t>, T,
PairHash
>;
76
77
#include <CD_NamespaceFooter.H>
78
79
#endif
ParticleMap
std::unordered_map< std::pair< uint32_t, uint32_t >, T, PairHash > ParticleMap
Underlying particle map when gathering/scattering particles.
Definition
CD_ParticleMap.H:75
PairHash
Simple pair-hashing struct for interfacing into unordered_map.
Definition
CD_ParticleMap.H:57
PairHash::operator()
std::size_t operator()(const std::pair< uint32_t, uint32_t > &p) const noexcept
Hash operator.
Definition
CD_ParticleMap.H:64
Generated by
1.9.8