core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1// core — shared types and conventions (see suite/docs/CONVENTIONS.md).
2//
3// Pillars: axis order is x-fastest (linear index I = x + y*nx + z*nx*ny), and SDF sign is
4// negative-inside-solid (enforced in peclet::core::geom, not here). This header is C++17-clean so
5// it can be pulled into CUDA translation units; C++20-only constructs live in host-only headers.
6#ifndef PECLET_CORE_COMMON_TYPES_HPP
7#define PECLET_CORE_COMMON_TYPES_HPP
8
9#include <array>
10#include <cstdint>
11
12namespace peclet::core {
13
15using Index = std::int64_t;
16
18using Real = double;
19
21template <int Dim>
22using IVec = std::array<Index, Dim>;
23
25template <int Dim>
26using Vec = std::array<Real, Dim>;
27
29template <typename Label = Index>
30struct Range {
31 std::size_t begin = 0;
32 std::size_t end = 0;
34};
35
37inline Index wrap(Index x, Index n) {
38 return ((x % n) + n) % n;
39}
40
43template <int Dim, int Axis>
44struct NestedLoop {
45 template <typename Func>
46 static void run(IVec<Dim>& idx, const IVec<Dim>& bgn, const IVec<Dim>& end, Func&& func) {
47 for (idx[Axis] = bgn[Axis]; idx[Axis] < end[Axis]; ++idx[Axis]) {
49 }
50 }
51};
52
53template <int Dim>
54struct NestedLoop<Dim, 0> {
55 template <typename Func>
56 static void run(IVec<Dim>& idx, const IVec<Dim>& bgn, const IVec<Dim>& end, Func&& func) {
57 for (idx[0] = bgn[0]; idx[0] < end[0]; ++idx[0]) {
58 func(const_cast<const IVec<Dim>&>(idx));
59 }
60 }
61};
62
64template <int Dim, typename Func>
65inline void forEachInBox(const IVec<Dim>& bgn, const IVec<Dim>& end, Func&& func) {
66 IVec<Dim> idx{};
68}
69
70} // namespace peclet::core
71
72#endif // PECLET_CORE_COMMON_TYPES_HPP
Index wrap(Index x, Index n)
Periodic wrap of a coordinate into [0, n): wrap(x, n) = (x % n + n) % n.
Definition types.hpp:37
std::array< Real, Dim > Vec
Multi-dimensional real vector.
Definition types.hpp:26
void forEachInBox(const IVec< Dim > &bgn, const IVec< Dim > &end, Func &&func)
Iterate the box [bgn, end) calling func(const IVec<Dim>&).
Definition types.hpp:65
std::array< Index, Dim > IVec
Multi-dimensional integer index / coordinate (x-fastest order by convention).
Definition types.hpp:22
Kokkos::View< T *, MemSpace > View
1D device array.
Definition view.hpp:26
double Real
Default host floating type. Device kernels may use float; conversions happen at the boundary.
Definition types.hpp:18
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).
Definition types.hpp:15
static void run(IVec< Dim > &idx, const IVec< Dim > &bgn, const IVec< Dim > &end, Func &&func)
Definition types.hpp:56
Compile-time-unrolled nested loop over [bgn, end) in row-major (axis 0 fastest) order.
Definition types.hpp:44
static void run(IVec< Dim > &idx, const IVec< Dim > &bgn, const IVec< Dim > &end, Func &&func)
Definition types.hpp:46
Half-open range [begin, end) carrying a label (e.g. a block id). Ported from pbs::IndxRange.
Definition types.hpp:30
std::size_t end
Definition types.hpp:32
std::size_t begin
Definition types.hpp:31