Skip to content

Domain, Grid and Data Structures

This page describes the core data structures used internally by hippoLBM to represent the simulation domain, the discrete grid, and the distribution functions.

The figure below gives a schematic 2D representation of the LBM domain split across MPI subdomains. A grid is associated with each subdomain, and a set of predefined Box3D regions or identified Traversal with tags (All, Real, Inside, Extend) delimit zones such as the real cells, ghost layers, and extended areas.

LBM grid

LBMDomain

LBMDomain<Q> is the top-level structure passed to all operators (slot domain). It holds both global domain information and local subdomain information.

Global domain information:

  • bounds_: physical AABB (axis-aligned bounding box) of the full domain
  • box_: computational Box3D of the full domain including ghost layers
  • domain_size_: total number of real nodes per dimension

Local subdomain information:

  • grid_: the local LBMGrid of this MPI process
  • ghost_manager_: handles MPI ghost-cell communication
  • MPI_coord_: Cartesian coordinates of this process in the MPI grid
  • MPI_grid_size_: shape of the MPI process grid

The figure below illustrates the local/global index relationship for a 2×2 MPI decomposition. Each rank stores a local array that includes ghost_layer_ = 2 ghost layers on each side, so local owned indices start at 2. The offset_ of a subdomain is the global index of its first owned node. Interface nodes at subdomain boundaries (e.g. global i = 10) are shared between adjacent ranks and are duplicated in both local arrays.

LBM domain

Key methods

  • dx(): returns the uniform grid spacing dx_
  • grid(): returns a reference to the local LBMGrid
  • box(): returns a reference to the local computational Box3D
  • bounds(): returns a reference to the physical AABB of the full domain
  • ghost_manager(): returns a reference to the LBMGhostManager
  • size(): returns the number of real nodes per dimension (without ghost layers)

The domain operator

The domain operator initializes an LBMDomain at the start of the simulation, in the do_domain hook. It performs the MPI domain decomposition and sets up all grids and ghost layers.

1
2
3
4
5
6
do_domain:
  - domain:
     bounds:    [ [0,0,0], [0.1,0.1,0.1] ]
     cell_dims: [ 100, 100, 100 ]
     periodic:  [ false, false, false ]
     bounce_back_planes: [plan_xy_0, plan_xy_l, plan_yz_0, plan_yz_l, plan_xz_0, plan_xz_l]
Parameters' description
Slot Type Default Description
cell_dims IJK required number of cells in each dimension; the number of nodes is cell_dims + 1 along non-periodic dimensions. The spacing dx is computed from bounds and cell_dims and must be uniform
bounds AABB required physical bounding box [[xmin, ymin, zmin], [xmax, ymax, zmax]], with optional unit (e.g. m)
periodic [bool;3] required periodicity along X, Y, Z
bounce_back_planes [string] [] planes with a no-slip (bounce-back) wall: plan_xy_0, plan_xy_l, plan_xz_0, plan_xz_l, plan_yz_0, plan_yz_l. A plane's dimension must not be periodic. See Bounce-back
tolerance double 1e-6 relative tolerance of the consistency check between resolution, grid size and bounds. Increase it if floating-point round-off causes a false alarm

LBMGrid

LBMGrid is the core per-subdomain grid structure. It stores:

  • bx_: Box3D of the local grid (real cells + ghost layers)
  • ext_: Box3D of the extended grid (used for the streaming stencil)
  • offset_: Point3D offset of this subdomain within the global grid
  • ghost_layer_: number of ghost layers (default: 2)
  • dx_: uniform grid spacing (same in all directions)
  • origin_: physical origin of the global domain

Traversal zones

The grid is subdivided into nested regions controlled by the Traversal template parameter:

Traversal Description
All Full local box bx_ (real cells + ghost layers)
Real Real cells only (excludes ghost_layer_ on each side)
Inside Interior cells (excludes ghost layer + 1 additional layer)
Extend Extended box ext_: real nodes plus first-level ghost nodes that are active — nodes that belong to a neighbouring subdomain (communicated via MPI) or that correspond to periodic boundary images

The Area parameter controls whether indices are expressed in the local subdomain frame or the global domain frame:

  • Area::Local: coordinates relative to this subdomain
  • Area::Global: coordinates relative to the full domain (adds offset_)
  • Area::AsIs: no conversion — coordinates are passed through as-is, used to avoid redundant shifts when the caller already works in the target frame

Key methods

  • start<Area, Traversal>(dim) / end<Area, Traversal>(dim): bounds along a dimension
  • build_box<Area, Traversal>(): returns the corresponding Box3D
  • contains<Area, Traversal>(p): point membership test
  • convert<Area>(p): converts a point between local and global frames
  • project_to_grid<Area>(Vec3d): maps a physical position to a grid index (taking origin_ into account)
  • compute_position<Area>(i, j, k): maps grid indices to physical coordinates
  • restrict_box_to_grid<Area, Traversal>(box): clips a box to the subdomain

Fields and FieldView

LBMFields<Q> (slot fields) stores all per-node data arrays as GPU-compatible contiguous vectors:

Member Accessor Description
f_ distributions() Distribution functions \(f_i\), Q components per node, accessed via FieldView<Q>
m0_ densities() Macroscopic density \(\rho\), one scalar per node
m1_ flux() Macroscopic velocity \(\mathbf{u}\), 3 components per node, accessed via FieldView<3>
obst_ obstacles() Obstacle marker per node: FLUID_CELL = -1 for a fluid node, WALL_CELL = -2 for a solid node

FieldView<Components> is a lightweight GPU/CPU-compatible view over a field array. It exposes a single accessor f(idx, c) that computes the flat offset into the underlying double* data_ pointer depending on the memory layout selected at compile time:

  • Structure of Arrays (default): index = num_elements_ * c + idx — all values of the same component are contiguous
  • Array of Structures (#ifdef WFAOS): index = idx * Components + c — all components of the same node are contiguous
LBM fields

The SoA layout is preferred on GPU for coalesced memory access over components; AoS can be more cache-friendly for operations that process all components of a single node. FieldView<Q> is the object passed to all compute kernels.

Warning

FieldView<N> always operates on double arrays. The template parameter N only controls the number of components per element; the scalar type is fixed to double.

Lattice scheme

In LBM, the velocity space is discretized into a finite set of Q directions \(\mathbf{e}_i\), each associated with a weight \(w_i\) satisfying the isotropy conditions of the lattice. The distribution functions \(f_i\) are advected along these directions during the streaming step, and relaxed toward a local equilibrium during the collision step.

LBMScheme<Q> encodes a specific lattice: it defines the Q directions as a compile-time tuple of Direction types, each storing \((e_x, e_y, e_z, w_i, \text{iopp})\) — the velocity components, the weight, and the index of the opposite direction used in bounce-back.

Warning

Only the D3Q19 scheme is currently implemented and tested. The core structures (LBMDomain, LBMGrid, LBMFields, FieldView) are all templated on Q, so adding a new scheme (e.g. D3Q27) would be straightforward in principle — the main effort lies in implementing the boundary conditions for the new stencil.

The D3Q19 scheme (LBMScheme<19>) uses 19 discrete velocities with weights \(w_0 = 1/3\), \(w_{1-6} = 1/18\) and \(w_{7-18} = 1/36\):

D3Q19 directions
Index \(e_x\) \(e_y\) \(e_z\) \(w_i\) iopp
0 0 0 0 1/3 0
1 +1 0 0 1/18 2
2 −1 0 0 1/18 1
3 0 +1 0 1/18 4
4 0 −1 0 1/18 3
5 0 0 +1 1/18 6
6 0 0 −1 1/18 5
7 +1 +1 0 1/36 8
8 −1 −1 0 1/36 7
9 +1 −1 0 1/36 10
10 −1 +1 0 1/36 9
11 +1 0 +1 1/36 12
12 −1 0 −1 1/36 11
13 +1 0 −1 1/36 14
14 −1 0 +1 1/36 13
15 0 +1 +1 1/36 16
16 0 −1 −1 1/36 15
17 0 +1 −1 1/36 18
18 0 −1 +1 1/36 17

The stencil utility hippoLBM::stencil::for_each<LBMScheme<19>>(f) iterates over all directions at compile time, calling f.template operator()<dir<iLB>>(iLB) for each index iLB.

Point3D and Box3D

Point3D is a simple integer triplet (i, j, k) used for all discrete grid coordinates. It supports arithmetic operations (addition, subtraction) with other Point3D instances and can be implicitly converted to a floating-point Vec3d.

hippoLBM::Point3D p = {10, 5, 3};
int i = p[0]; // 10

Box3D represents an axis-aligned integer box defined by two inclusive corners inf_ and sup_. It provides:

  • get_length(dim): number of grid points along a dimension
  • number_of_points(): total number of points in the box
  • operator()(x, y, z) → flat linear index (row-major: X fastest)
  • operator()(idx) → Point3D from a flat index
  • contains(p): checks whether a point lies inside the box
  • intersect(a, b): checks whether two boxes overlap

Operator slot summary

The table below lists the main structures exchanged between operators through the onika slot system, with their canonical slot name.

C++ type Slot name Description
LBMDomain<Q> domain Top-level domain: grid, bounds, MPI decomposition, ghost manager, bounce-back planes
LBMFields<Q> fields Per-node data arrays: \(f_i\), \(\rho\), \(\mathbf{u}\), obstacle markers
LBMGridRegion grid_region Traversal index arrays built by build_traversal: real_, inside_, extend_, face planes (plane_xy_0_, plane_xz_0_, …)
LBMParameters Params LBM parameters computed by lbm_parameters: tau_, nu_, nuth_, dtLB_, celerity_, Fext_, avg_rho_
Obstacles obstacles Registered solid shapes (Ball, Wall, Quadric, RShape) used to mark the solid nodes
SimulationStatistics simulation_statistics MPI-reduced statistics computed by simulation_state