include/pops/mesh/index/box2d.hpp Source FileΒΆ
|
adc_cpp 0.3.0
Model-free C++23 core for coupled hyperbolic-elliptic systems on adaptive (AMR) meshes, with MPI and GPU (Kokkos) backends
|
box2d.hpp
Go to the documentation of this file.
15#include <pops/core/foundation/types.hpp> // POPS_HD: nx/ny/length called from Geometry::dx() inside a device kernel
22// Integer division rounded down (toward -inf), consistent on both sides of zero: the only correct
23// division for NEGATIVE indices (ghost layers) during coarsen / spatial hash. C++ division truncates
24// toward zero; we subtract 1 when the remainder is non-zero and of opposite sign to the divisor (the
25// truncated quotient was then rounded up). Shared low-level building block (Box2D coarsen, BoxHash bin
45 // calls geom.x_cell(i) descends down to here. Without POPS_HD this is a __host__ from __device__ ->
46 // nvcc yields GARBAGE (often 0) with no error. Pure integer arithmetic, device-safe, host unchanged.
61 bool contains(int i, int j) const { return i >= lo[0] && i <= hi[0] && j >= lo[1] && j <= hi[1]; }
Definition amr_hierarchy.hpp:29
POPS_HD constexpr int floor_div(int a, int b)
Integer division of a by b rounded down (handles a < 0 AND b < 0). POPS_HD constexpr (kernels).
Definition box2d.hpp:28
bool empty() const
true if the box contains no cell (hi < lo in one direction).
Definition box2d.hpp:58
static Box2D from_extents(int nx, int ny)
Box [0, nx-1] x [0, ny-1] covering nx*ny cells from the index origin.
Definition box2d.hpp:42
Box2D grow(int n) const
Grows the box by n cells in ALL directions (uniform ghost layer).
Definition box2d.hpp:69
Box2D grow(int d, int n) const
Grows by n cells in the SINGLE direction d (n may be negative to shrink).
Definition box2d.hpp:71
POPS_HD int length(int d) const
Number of cells in direction d (= hi[d] - lo[d] + 1); negative if the box is empty....
Definition box2d.hpp:48
POPS_HD int nx() const
Width (direction 0). POPS_HD (called from Geometry::dx() in a device kernel).
Definition box2d.hpp:50
Box2D coarsen(int r) const
Coarsens by a ratio r via FLOOR division of each corner (handles the negative ghost indices).
Definition box2d.hpp:90
bool contains(int i, int j) const
true if cell (i, j) is inside the box (lo/hi bounds inclusive).
Definition box2d.hpp:61
POPS_HD int ny() const
Height (direction 1). POPS_HD (called from Geometry::dy() in a device kernel).
Definition box2d.hpp:52
Box2D shift(int d, int s) const
Translates the box by s cells in direction d (lo and hi shifted by the same s).
Definition box2d.hpp:78
Box2D refine(int r) const
Refines by a ratio r: each cell becomes an r x r block ([lo, hi] -> [lo*r, hi*r + r-1]).
Definition box2d.hpp:86
Box2D intersect(const Box2D &o) const
Intersection of the two boxes (possibly empty: hi < lo if they do not overlap).
Definition box2d.hpp:95
std::int64_t num_cells() const
Total number of cells (nx*ny, floored at 0 per direction): 0 if the box is empty.
Definition box2d.hpp:54
bool operator==(const Box2D &) const =default
bool contains(const Box2D &b) const
true if box b (non-empty) is entirely contained in *this.
Definition box2d.hpp:63
Base scalar types and the POPS_HD macro (host+device portability).
Generated by