core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
Loading...
Searching...
No Matches
peclet::core::amr::BlockOctree< Dim, Bits > Class Template Reference

Per-block adaptive octree over block-local Morton codes. More...

#include <block_octree.hpp>

Public Types

using M = morton::Morton< Dim, Bits >
 
using Code = typename M::code_type
 
using Coord = typename M::coord_type
 

Public Member Functions

 BlockOctree ()=default
 
 BlockOctree (IVec< Dim > brick, unsigned lmax, IVec< Dim > globalOrigin=IVec< Dim >{})
 Build a uniform block: a brick (in root cells) of leaves at level lmax.
 
void init (IVec< Dim > brick, unsigned lmax, IVec< Dim > globalOrigin=IVec< Dim >{})
 
void assign (IVec< Dim > brick, unsigned lmax, IVec< Dim > globalOrigin, std::vector< Code > codes, std::vector< std::uint8_t > levels)
 Replace the entire leaf set directly (used by load-balancing migration, which rebuilds a block from leaves received from other ranks).
 
Index numLeaves () const
 
unsigned lmax () const
 
const IVec< Dim > & brick () const
 
const IVec< Dim > & globalOrigin () const
 
Code code (Index i) const
 
unsigned level (Index i) const
 
const std::vector< Code > & codes () const
 
const std::vector< std::uint8_t > & levels () const
 
Index find (Code p) const
 Leaf containing Morton code p, or -1. Host wrapper over amrLocate.
 
Index find (const std::array< Coord, Dim > &fine) const
 Leaf containing fine-unit coordinates, or -1.
 
std::array< std::array< Coord, Dim >, 2 > bounds (Index i) const
 Inclusive integer bounds [lo, hi] of leaf i in fine units.
 
Index faceNeighbor (Index i, int axis, int dir) const
 The leaf across leaf i's face on axis in direction dir (±1), or -1 if it lies outside the block.
 
template<class Pred >
Index refineIf (Pred &&pred)
 Split every leaf for which pred(code, level) is true (and level > 0) into its 2^Dim children one level finer.
 
bool refineLeaf (Index i)
 Refine a single leaf by index. Returns true if it was split.
 
template<class Pred >
Index coarsenIf (Pred &&pred)
 Merge complete sibling groups (all 2^Dim children present, all at the same level) whose parent satisfies pred(parentCode, parentLevel).
 
Index balance2to1 ()
 Enforce 2:1 (graded) balance within this block: no two face-adjacent leaves differ by more than one level.
 
bool isBalanced () const
 True iff the leaves form a valid 2:1-balanced partition: every face neighbour differs by at most one level.
 

Static Public Member Functions

static constexpr unsigned bits ()
 

Static Public Attributes

static constexpr unsigned octants = M::octants
 

Detailed Description

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
class peclet::core::amr::BlockOctree< Dim, Bits >

Per-block adaptive octree over block-local Morton codes.

Bits is the per-axis code width; the default keeps codes in a built-in 64-bit integer (3D: 21 bits/axis, 2D: 32). A block must satisfy brick[i]*2^lmax <= 2^Bits.

Definition at line 78 of file block_octree.hpp.

Member Typedef Documentation

◆ M

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
using peclet::core::amr::BlockOctree< Dim, Bits >::M = morton::Morton<Dim, Bits>

Definition at line 80 of file block_octree.hpp.

◆ Code

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
using peclet::core::amr::BlockOctree< Dim, Bits >::Code = typename M::code_type

Definition at line 81 of file block_octree.hpp.

◆ Coord

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
using peclet::core::amr::BlockOctree< Dim, Bits >::Coord = typename M::coord_type

Definition at line 82 of file block_octree.hpp.

Constructor & Destructor Documentation

◆ BlockOctree() [1/2]

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
peclet::core::amr::BlockOctree< Dim, Bits >::BlockOctree ( )
default

◆ BlockOctree() [2/2]

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
peclet::core::amr::BlockOctree< Dim, Bits >::BlockOctree ( IVec< Dim >  brick,
unsigned  lmax,
IVec< Dim >  globalOrigin = IVec<Dim>{} 
)
inline

Build a uniform block: a brick (in root cells) of leaves at level lmax.

globalOrigin is the block's lower corner in the global coarse grid's root-cell coordinates (metadata used by the distributed layer; the local codes here are origin-relative and independent of it).

Definition at line 91 of file block_octree.hpp.

Member Function Documentation

◆ init()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
void peclet::core::amr::BlockOctree< Dim, Bits >::init ( IVec< Dim >  brick,
unsigned  lmax,
IVec< Dim >  globalOrigin = IVec<Dim>{} 
)
inline

◆ assign()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
void peclet::core::amr::BlockOctree< Dim, Bits >::assign ( IVec< Dim >  brick,
unsigned  lmax,
IVec< Dim >  globalOrigin,
std::vector< Code codes,
std::vector< std::uint8_t >  levels 
)
inline

Replace the entire leaf set directly (used by load-balancing migration, which rebuilds a block from leaves received from other ranks).

codes are block-local origin codes and levels their parallel levels; they need not be sorted — assign() restores the Z-order invariant. brick/lmax/globalOrigin describe the (possibly new) block geometry the codes are relative to.

Definition at line 119 of file block_octree.hpp.

References peclet::core::amr::BlockOctree< Dim, Bits >::brick(), peclet::core::amr::BlockOctree< Dim, Bits >::codes(), peclet::core::amr::BlockOctree< Dim, Bits >::globalOrigin(), peclet::core::amr::BlockOctree< Dim, Bits >::levels(), and peclet::core::amr::BlockOctree< Dim, Bits >::lmax().

Referenced by peclet::core::amr::DistributedOctree< Dim, Bits >::rebalance().

◆ numLeaves()

◆ lmax()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
unsigned peclet::core::amr::BlockOctree< Dim, Bits >::lmax ( ) const
inline

◆ bits()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
static constexpr unsigned peclet::core::amr::BlockOctree< Dim, Bits >::bits ( )
inlinestaticconstexpr

Definition at line 132 of file block_octree.hpp.

◆ brick()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
const IVec< Dim > & peclet::core::amr::BlockOctree< Dim, Bits >::brick ( ) const
inline

◆ globalOrigin()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
const IVec< Dim > & peclet::core::amr::BlockOctree< Dim, Bits >::globalOrigin ( ) const
inline

◆ code()

◆ level()

◆ codes()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
const std::vector< Code > & peclet::core::amr::BlockOctree< Dim, Bits >::codes ( ) const
inline

◆ levels()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
const std::vector< std::uint8_t > & peclet::core::amr::BlockOctree< Dim, Bits >::levels ( ) const
inline

◆ find() [1/2]

◆ find() [2/2]

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
Index peclet::core::amr::BlockOctree< Dim, Bits >::find ( const std::array< Coord, Dim > &  fine) const
inline

◆ bounds()

◆ faceNeighbor()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
Index peclet::core::amr::BlockOctree< Dim, Bits >::faceNeighbor ( Index  i,
int  axis,
int  dir 
) const
inline

The leaf across leaf i's face on axis in direction dir (±1), or -1 if it lies outside the block.

With 2:1 balance this lands in a same-, one- coarser-, or one-finer-level neighbour (the corner-most, for the finer case).

Definition at line 162 of file block_octree.hpp.

References peclet::core::amr::BlockOctree< Dim, Bits >::find().

Referenced by peclet::core::amr::BlockOctree< Dim, Bits >::balance2to1(), peclet::core::amr::BlockOctree< Dim, Bits >::isBalanced(), and peclet::core::amr::transferField().

◆ refineIf()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
template<class Pred >
Index peclet::core::amr::BlockOctree< Dim, Bits >::refineIf ( Pred &&  pred)
inline

Split every leaf for which pred(code, level) is true (and level > 0) into its 2^Dim children one level finer.

Returns the number of leaves split. A single forward pass: children of a parent occupy the parent's code range in ascending octant == ascending code order, so the sorted invariant holds without a re-sort.

Definition at line 183 of file block_octree.hpp.

References peclet::core::amr::BlockOctree< Dim, Bits >::octants.

Referenced by peclet::core::amr::DistributedOctree< Dim, Bits >::balance(), peclet::core::amr::BlockOctree< Dim, Bits >::balance2to1(), peclet::core::amr::BarnesHut< Dim, Bits >::build(), peclet::core::amr::distributedAdapt(), and peclet::core::amr::BlockOctree< Dim, Bits >::refineLeaf().

◆ refineLeaf()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
bool peclet::core::amr::BlockOctree< Dim, Bits >::refineLeaf ( Index  i)
inline

Refine a single leaf by index. Returns true if it was split.

Definition at line 210 of file block_octree.hpp.

References peclet::core::amr::BlockOctree< Dim, Bits >::refineIf().

◆ coarsenIf()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
template<class Pred >
Index peclet::core::amr::BlockOctree< Dim, Bits >::coarsenIf ( Pred &&  pred)
inline

Merge complete sibling groups (all 2^Dim children present, all at the same level) whose parent satisfies pred(parentCode, parentLevel).

Returns the number of groups merged. Siblings are consecutive in the sorted array.

Definition at line 219 of file block_octree.hpp.

References peclet::core::amr::BlockOctree< Dim, Bits >::octants.

Referenced by peclet::core::amr::adaptField(), and peclet::core::amr::distributedAdapt().

◆ balance2to1()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
Index peclet::core::amr::BlockOctree< Dim, Bits >::balance2to1 ( )
inline

Enforce 2:1 (graded) balance within this block: no two face-adjacent leaves differ by more than one level.

Iterates to a fixpoint; returns the total number of refinements performed. Detection is from the fine side — a leaf at level Lf probes one cell across each face; that point always lands inside a coarser neighbour, so any neighbour with level >= Lf+2 is found and split.

Definition at line 261 of file block_octree.hpp.

References peclet::core::amr::BlockOctree< Dim, Bits >::faceNeighbor(), and peclet::core::amr::BlockOctree< Dim, Bits >::refineIf().

Referenced by peclet::core::amr::DistributedOctree< Dim, Bits >::balance().

◆ isBalanced()

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
bool peclet::core::amr::BlockOctree< Dim, Bits >::isBalanced ( ) const
inline

True iff the leaves form a valid 2:1-balanced partition: every face neighbour differs by at most one level.

(Test/debug helper.)

Definition at line 288 of file block_octree.hpp.

References peclet::core::amr::BlockOctree< Dim, Bits >::faceNeighbor().

Member Data Documentation

◆ octants

template<int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
constexpr unsigned peclet::core::amr::BlockOctree< Dim, Bits >::octants = M::octants
staticconstexpr

The documentation for this class was generated from the following file: