chombo-discharge
Loading...
Searching...
No Matches
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)
26static_assert(sizeof(uint32_t) == 4, "uint32_t must be 32 bits");
27static_assert(sizeof(uint64_t) == 8, "uint64_t must be 64 bits");
28static_assert(sizeof(size_t) == 8, "size_t must be 64 bits");
29
36static inline uint64_t
37encodePair(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
47static inline std::pair<uint32_t, uint32_t>
48decodePair(uint64_t key) noexcept
49{
50 return {uint32_t(key >> 32), uint32_t(key)};
51}
52
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
74template <typename T>
75using ParticleMap = std::unordered_map<std::pair<uint32_t, uint32_t>, T, PairHash>;
76
77#include <CD_NamespaceFooter.H>
78
79#endif
std::unordered_map< std::pair< uint32_t, uint32_t >, T, PairHash > ParticleMap
Underlying particle map when gathering/scattering particles.
Definition CD_ParticleMap.H:75
Simple pair-hashing struct for interfacing into unordered_map.
Definition CD_ParticleMap.H:57
std::size_t operator()(const std::pair< uint32_t, uint32_t > &p) const noexcept
Hash operator.
Definition CD_ParticleMap.H:64