chombo-discharge
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions
CD_ParticleSoA.H File Reference

Declaration of ParticleSoA, an arena-backed Struct-of-Arrays particle container. More...

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <limits>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include <SPACE.H>
#include <RealVect.H>
#include <IntVect.H>
#include <Box.H>
#include <CD_ParticleMemory.H>
#include <CD_NamespaceHeader.H>
#include <CD_NamespaceFooter.H>
#include <CD_ParticleSoAImplem.H>
Include dependency graph for CD_ParticleSoA.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  H5Part::Scalar< M >
 Descriptor of a single scalar payload column written to one H5Part dataset. More...
 
struct  H5Part::Vector< Ms >
 Descriptor of a SpaceDim-component vector payload column, written as name-x/name-y/name-z. More...
 
struct  NoPayload
 Empty payload: ParticleSoA<> is a position+weight+metadata point particle. More...
 
struct  ParticleTraits< NoPayload >
 Traits for the empty payload (no payload columns). More...
 
struct  detail::MemberPointerTraits< T C::* >
 Specialization that extracts the class and value type from a pointer-to-member type. More...
 
struct  detail::RepeatTuple< T, N >
 std::tuple of N copies of T (used to build the SpaceDim position columns). More...
 
struct  detail::ValueTuple< std::tuple< Ms... > >
 Specialization mapping a tuple of pointer-to-member to the tuple of value types. More...
 
struct  detail::SumSizeof< std::tuple< Ts... > >
 Specialization computing the compile-time sum of sizeof() over a value tuple. More...
 
struct  detail::AllTriviallyCopyable< std::tuple< Ts... > >
 Specialization testing that every type in a value tuple is trivially copyable. More...
 
struct  detail::MakeVoid<... >
 Stand-in for std::void_t (maps any type pack to void). More...
 
struct  detail::H5ColumnSubset< Traits, Fallback, typename >
 Primary template resolving the HDF5 payload column subset; defaults to all columns. More...
 
struct  detail::H5ColumnSubset< Traits, Fallback, Void< decltype(Traits::h5Columns)> >
 Specialization selecting the declared HDF5 payload subset when Traits::h5Columns exists. More...
 
class  ParticleSoA< P, Traits >
 Arena-backed Struct-of-Arrays particle container for a single grid patch. More...
 

Namespaces

namespace  H5Part
 Declarative descriptors for selecting which particle PAYLOAD columns are written to H5Part (visualization) files. A ParticleTraits specialization may declare an optional h5PartColumns tuple of these descriptors; DischargeIO::writeH5Part then derives the output datasets directly, eliminating hand-maintained, positionally coupled name/accessor lists.
 

Macros

#define CD_PARTICLE_REAL   double
 Compile-time precision of particle PAYLOAD data. Defaults to double; define CD_PARTICLE_REAL (e.g. to float) for mixed-precision payload columns.
 

Typedefs

using ParticleReal = CD_PARTICLE_REAL
 Floating-point type a user may use for payload columns.
 
using ParticleID = std::int64_t
 Global particle identifier type (container-owned metadata column; fixed-width for I/O).
 
using RankID = std::int32_t
 Owning-rank identifier type (container-owned metadata column; fixed-width for I/O).
 
template<typename... Ts>
using detail::Void = typename MakeVoid< Ts... >::Type
 Alias yielding void for any type pack (SFINAE helper, like std::void_t).
 

Enumerations

enum class  GhostType : std::uint8_t { Valid = 0 , SameLevel = 1 , Coarse = 2 , Fine = 3 }
 Ghost designation of a particle (container-owned metadata column). More...
 

Functions

template<typename M >
 H5Part::Scalar (const char *, M) -> Scalar< M >
 Deduction guide so that Scalar{"name", &P::m} deduces the member-pointer type.
 
template<typename... Ms>
 H5Part::Vector (const char *, Ms...) -> Vector< Ms... >
 Deduction guide so that Vector{"name", D_DECL(&P::x, &P::y, &P::z)} deduces the member-pointer types.
 
template<typename A , typename B >
constexpr bool detail::eqMember (A, B) noexcept
 Type-mismatched overload of the pointer-to-member equality (always false).
 
template<typename A >
constexpr bool detail::eqMember (A a_lhs, A a_rhs) noexcept
 Same-type overload of the pointer-to-member equality.
 
template<typename Tup , typename M >
constexpr std::size_t detail::indexOfImpl (const Tup &, M, std::index_sequence<>) noexcept
 Base case of the compile-time member-pointer index search (empty sequence).
 
template<typename Tup , typename M , std::size_t I, std::size_t... Rest>
constexpr std::size_t detail::indexOfImpl (const Tup &a_t, M a_target, std::index_sequence< I, Rest... >) noexcept
 Recursive step of the compile-time member-pointer index search.
 
template<typename Tup , typename M >
constexpr std::size_t detail::indexOf (const Tup &a_t, M a_target) noexcept
 Compile-time index of a member pointer within a tuple (tuple size if absent).
 
constexpr std::size_t detail::sumSizes () noexcept
 Base case of the variadic constexpr size sum (no arguments).
 
template<typename... Rest>
constexpr std::size_t detail::sumSizes (std::size_t a_first, Rest... a_rest) noexcept
 Variadic constexpr sum of std::size_t values.
 
template<typename Traits , std::size_t... I>
constexpr std::index_sequence< indexOf(Traits::columns, std::get< I >(Traits::h5Columns))... > detail::deriveH5Seq (std::index_sequence< I... > a_seq) noexcept
 Turn a tuple of HDF5 payload member pointers into a std::index_sequence of DERIVED payload-column indices (each via indexOf against the payload columns).
 
template<typename T >
void detail::pushBytes (unsigned char *&a_buf, const T &a_value) noexcept
 memcpy one trivially-copyable value onto a byte buffer and advance the buffer pointer.
 
template<typename T >
void detail::pullBytes (const unsigned char *&a_buf, T &a_value) noexcept
 memcpy one trivially-copyable value off a byte buffer and advance the buffer pointer.
 

Detailed Description

Declaration of ParticleSoA, an arena-backed Struct-of-Arrays particle container.

Author
Robert Marskar

ParticleSoA is the per-patch particle storage that replaces Chombo's List

. It is the single source of truth for one grid patch worth of particles; the AMR machinery (the ParticleContainer equivalent) owns a LayoutData<ParticleSoA<P>> per level.

The data model

The container stores particles column-major (Struct-of-Arrays): one contiguous array per field. ALL columns live in ONE aligned allocation (the "arena"), laid out as offset slices. Position and weight are stored in double precision – they index the grid and are summed/conserved across the whole population, so they must not lose precision to float roundoff (and must stay double even in a CH_USE_FLOAT build, hence double, not Real). Only the user payload columns may use the narrower ParticleReal.

*     [ x | pad | y | pad | z | pad | weight | pad | id | pad | rank | pad | ghost | pad | payload... ]
* 

Column base pointers are cached, so element access is as cheap as a plain array. Bulk operations over a compact (size == capacity) container are then a SINGLE contiguous span: one allocation to build, one memcpy (or a zero-copy MPI_Send of data()) to transfer.

Mandatory columns are container-owned; the user supplies only a payload

Every particle in chombo-discharge has a position, a weight, and metadata (a global id + the owning rank). ParticleSoA OWNS those columns and the user does NOT declare them:

The user defines ONLY the extra payload fields (velocity, mobility, energy, ...) as a plain struct, plus a ParticleTraits specialization listing the payload columns. The payload may be empty, so ParticleSoA<> is a ready-made point/tracer particle (position + weight + metadata, nothing else).

Defining a particle type (the complete recipe)

Step 1 – write a plain struct of the EXTRA (payload) members only. Each member becomes one SoA column and must be trivially copyable. Do NOT add position/weight/id/rank; the container already owns those. Vector fields are stored PER-COMPONENT as scalar columns – there is no RealVect column type; declare x/y/z members and promote to RealVect in downstream code if needed. Use ParticleReal for local per-particle physics (velocity, mobility, energy) where float is safe; use double for anything position-like or globally reduced (e.g. an oldPosition, which subtracts from the double position).

struct MyPayload
{
ParticleReal D_DECL(vx = 0.0, vy = 0.0, vz = 0.0); // velocity, per-component
ParticleReal mobility = 0.0;
ParticleReal energy = 0.0;
};
CD_PARTICLE_REAL ParticleReal
Floating-point type a user may use for payload columns.
Definition CD_ParticleSoA.H:156

Step 2 – specialize ParticleTraits<MyPayload> with the columns tuple (one pointer-to-member per payload column; the single source of truth for the layout):

template <>
struct ParticleTraits<MyPayload>
{
static constexpr auto columns = std::make_tuple(D_DECL(&MyPayload::vx,
&MyPayload::vy,
&MyPayload::vz),
&MyPayload::mobility,
&MyPayload::energy);
};
Traits class that a user specializes to describe the PAYLOAD columns of a particle type....
Definition CD_ParticleSoA.H:192

Step 3 (optional) – restrict which PAYLOAD columns go to HDF5 by declaring an h5Columns tuple of member pointers. Position and weight are ALWAYS checkpointed; id/rank NEVER are. If h5Columns is omitted, every payload column is checkpointed.

static constexpr auto h5Columns = std::make_tuple(&MyPayload::energy);

That is all – ParticleSoA<MyPayload> now works. Payload fields are selected by member pointer, e.g. soa.column<&MyPayload::energy>(); the column index is DERIVED from the pointer at compile time, so reordering columns keeps name-based access correct.

Precision

Position and weight are always double; see the data-model note above for why. PAYLOAD columns use whatever type the user declares – ParticleReal is a compile-time alias that defaults to double but may be set to float (define CD_PARTICLE_REAL) for half-memory, 8-wide-SIMD payload against a double-precision grid. position(i) returns a RealVect for cell lookup / Chombo interop (the one geometry type at the accessor boundary).

Note
ParticleSoA is move-only: copy construction and copy assignment are deleted so an O(N) per-column copy can never happen implicitly (matching ParticleContainer). When an independent copy is genuinely wanted, use the explicit deepCopy() (returns a new container) or deepCopyTo() (reuses an existing destination's arena).
Template Parameters
PUser payload struct (extra columns only); defaults to NoPayload.
TraitsColumn descriptor for the payload; defaults to ParticleTraits

.

Macro Definition Documentation

◆ CD_PARTICLE_REAL

#define CD_PARTICLE_REAL   double

Compile-time precision of particle PAYLOAD data. Defaults to double; define CD_PARTICLE_REAL (e.g. to float) for mixed-precision payload columns.

Note
Position and weight are NOT governed by this – they are always double; see ParticleSoA's data-model documentation.

Enumeration Type Documentation

◆ GhostType

enum class GhostType : std::uint8_t
strong

Ghost designation of a particle (container-owned metadata column).

A valid particle (the patch's own, owned particle) has GhostType::Valid. A ghost particle is a transient copy that overlaps the patch's ghosted/grown box and is owned elsewhere; the non-Valid enumerators record where it came from so the remap routines (and any per-patch consumer) know its provenance. Stored as a single byte to keep the per-particle footprint minimal.

Enumerator
Valid 

Owned, valid particle of this patch (not a ghost).

SameLevel 

Ghost from an adjacent patch on the same level.

Coarse 

Ghost from the next-coarser level (level l-1).

Fine 

Ghost from the next-finer level (level l+1).

Function Documentation

◆ deriveH5Seq()

template<typename Traits , std::size_t... I>
constexpr std::index_sequence< indexOf(Traits::columns, std::get< I >(Traits::h5Columns))... > detail::deriveH5Seq ( std::index_sequence< I... >  a_seq)
constexprnoexcept

Turn a tuple of HDF5 payload member pointers into a std::index_sequence of DERIVED payload-column indices (each via indexOf against the payload columns).

Template Parameters
TraitsPayload traits type providing columns and h5Columns.
IIndices into the h5Columns tuple.
Parameters
[in]a_seqIndex sequence [0, size(h5Columns)) selecting the h5 columns.
Returns
An index_sequence of the derived payload-column indices.

◆ eqMember() [1/2]

template<typename A >
constexpr bool detail::eqMember ( a_lhs,
a_rhs 
)
constexprnoexcept

Same-type overload of the pointer-to-member equality.

Template Parameters
ACommon type of both member pointers.
Parameters
[in]a_lhsLeft-hand member pointer.
[in]a_rhsRight-hand member pointer.
Returns
True iff the two member pointers are equal.

◆ eqMember() [2/2]

template<typename A , typename B >
constexpr bool detail::eqMember ( ,
 
)
constexprnoexcept

Type-mismatched overload of the pointer-to-member equality (always false).

Template Parameters
AType of the left-hand member pointer.
BType of the right-hand member pointer.
Returns
Always false (the two member pointers have different types).

◆ indexOf()

template<typename Tup , typename M >
constexpr std::size_t detail::indexOf ( const Tup &  a_t,
a_target 
)
constexprnoexcept

Compile-time index of a member pointer within a tuple (tuple size if absent).

Template Parameters
TupTuple-of-member-pointer type being searched.
MMember-pointer type being searched for.
Parameters
[in]a_tTuple of member pointers being searched.
[in]a_targetMember pointer being searched for.
Returns
Index of a_target in a_t, or the tuple size if absent.

◆ indexOfImpl() [1/2]

template<typename Tup , typename M >
constexpr std::size_t detail::indexOfImpl ( const Tup &  ,
,
std::index_sequence<>   
)
constexprnoexcept

Base case of the compile-time member-pointer index search (empty sequence).

Template Parameters
TupTuple-of-member-pointer type being searched.
MMember-pointer type being searched for.
Returns
The tuple size, signalling "not found".

◆ indexOfImpl() [2/2]

template<typename Tup , typename M , std::size_t I, std::size_t... Rest>
constexpr std::size_t detail::indexOfImpl ( const Tup &  a_t,
a_target,
std::index_sequence< I, Rest... >   
)
constexprnoexcept

Recursive step of the compile-time member-pointer index search.

Template Parameters
TupTuple-of-member-pointer type being searched.
MMember-pointer type being searched for.
IIndex currently inspected.
RestRemaining indices to inspect.
Parameters
[in]a_tTuple of member pointers being searched.
[in]a_targetMember pointer being searched for.
Returns
Index of a_target in a_t, or the tuple size if absent.

◆ pullBytes()

template<typename T >
void detail::pullBytes ( const unsigned char *&  a_buf,
T &  a_value 
)
inlinenoexcept

memcpy one trivially-copyable value off a byte buffer and advance the buffer pointer.

Template Parameters
TTrivially-copyable value type.
Parameters
[in,out]a_bufBuffer pointer, advanced by sizeof(T) on return.
[out]a_valueValue filled from the buffer.

◆ pushBytes()

template<typename T >
void detail::pushBytes ( unsigned char *&  a_buf,
const T &  a_value 
)
inlinenoexcept

memcpy one trivially-copyable value onto a byte buffer and advance the buffer pointer.

Template Parameters
TTrivially-copyable value type.
Parameters
[in,out]a_bufBuffer pointer, advanced by sizeof(T) on return.
[in]a_valueValue to copy into the buffer.

◆ sumSizes() [1/2]

constexpr std::size_t detail::sumSizes ( )
constexprnoexcept

Base case of the variadic constexpr size sum (no arguments).

Returns
Zero.

◆ sumSizes() [2/2]

template<typename... Rest>
constexpr std::size_t detail::sumSizes ( std::size_t  a_first,
Rest...  a_rest 
)
constexprnoexcept

Variadic constexpr sum of std::size_t values.

Template Parameters
RestTypes of the trailing arguments (all std::size_t).
Parameters
[in]a_firstFirst value to add.
[in]a_restRemaining values to add.
Returns
The sum of all arguments.