Discrete Space

The DiscreteSpace object is the basis of structured grid management in turboWAVE. While DiscreteSpace provides topology and indexing, MetricSpace adds edge lengths, wall areas, and cell volumes, which define a specific grid geometry.

There is a tight coupling between certain concepts associated with particles and the DiscreteSpace object. As a result some of the lowest level particle objects appear in this scope.

Boundary Conditions

namespace bc

boundary conditions

Enums

enum class par

boundary conditions for particles

Values:

enumerator none
enumerator periodic
enumerator reflecting
enumerator absorbing
enumerator emitting
enumerator axisymmetric
enum class fld

boundary conditions for fields

Values:

enumerator none
enumerator periodic
enumerator normalFluxFixed
enumerator dirichletWall
enumerator neumannWall
enumerator dirichletCell
enumerator natural

Functions

inline std::map<std::string, par> par_map()

Maps input file identifiers to particle B.C. enumeration identifiers.

inline std::map<std::string, fld> fld_map()

Maps input file identifiers to field B.C. enumeration identifiers.

Grid Axes

namespace grid

Types and maps for working with grid axes.

Enums

enum geometry

Values:

enumerator cartesian
enumerator cylindrical
enumerator spherical
enum axis

Values:

enumerator t
enumerator x
enumerator y
enumerator z
enumerator mass
enumerator px
enumerator py
enumerator pz
enumerator g
enumerator gbx
enumerator gby
enumerator gbz
enum side

Values:

enumerator low
enumerator high

Functions

inline std::map<std::string, axis> axis_map()
inline std::string pretty_axis_label(const tw::grid::axis &axis)
inline tw::Int naxis(const tw::grid::axis &axis)
inline axis enumaxis(tw::Int ax)

Particle Primitives

struct Primitive

Abstraction for location on a grid.

Public Members

float x[3]

This is the relative position in a cell referenced to the interval [-0.5,0.5). The components can represent arbitrary coordinates.

tw::Int cell

encoded index of the reference cell

struct Particle

Data describing any kind of particle.

Public Functions

Particle(const tw::vec3 &p, const Primitive &q, const float number, const float aux1, const float aux2) noexcept

Constructor, parameters shadow the member variables.

inline void Assert(tw::Int beg, tw::Int end)

Assertions verifying that the primitive is minimized and in bounds.

Public Members

Primitive q

abstraction for the spatial coordinate

tw::vec3 p

momentum , always known in Cartesian coordinates

float number

number = particles per macroparticle divided by n_0(c/wp)^3

float aux1

auxiliary, typically node of origin

float aux2

auxiliary, typically particle tag

Friends

inline friend bool operator<(const Particle &p1, const Particle &p2)

Used to define the ordering of particles for std::sort

struct ParticleRef

Used to create sorting map within a thread for subsets of particle lists.

struct TransferParticle

Used to pack data for message passing of particles To avoid inconsistencies arising from FP comparisons on different nodes the destination information is computed on the source domain and packaged with the particle The position is kept as a double precision global coordinate until final call to AddParticle

Public Members

tw::Int dst[4]

dst[0] is rank of starting domain upon construction; gets set to destination domain later. dst[1..3] are -1, 0, or 1, giving direction of movement or no movement.

struct weights_3D

This holds the coefficients used to spread the particle cloud across 3x3x3 grid cells. Due to assumptions of separability this only requires storing 3x3 coefficients.

Public Members

tw::Float w[3][3]

The weights are packed in a 3x3 matrix. The first index (row) selects a cell from a 3-cell strip along a given axis, the second index (column) selects the axis, and the value is the weight factor in the cell.

tw::Int cell

Encoded representation of the cell in which the particle center resides.

DiscreteSpace Object

struct DiscreteSpace : public Testable

This object is an indexing and interpolation scheme for a structured grid. Consider first the topological indices, defined as follows.

Let ax be an axis index, numbered from 1 to 3. Consider a one dimensional strip of cells lined up along axis ax. Suppose this axis uses L ghost cell layers. Then, for any such strip,

  • Interior cells are labeled [1,...,dim[ax]]

  • Lower ghost cells are labeled [1-L,...,0]

  • Upper ghost cells are labeled [dim[ax]+1,...,dim[ax]+L].

The topological indices are independent of all storage patterns, In other words, no matter what storage pattern is used, toplogical index (i0,j0,k0) will always refer to the same cell.

Storage patterns are dictated by a cell encoding. This associates the topological indices with a single integer that maps to ascending memory addresses. The default encoding is used to sort particles. Superclasses can add a secondary encoding to resolve higher dimensional storage patterns. For example, Field adds another encoding to define how its components are packed.

Subclassed by Field, MetricSpace, Module

Public Functions

DiscreteSpace()

Create an empty DiscreteSpace

DiscreteSpace(tw::Int xDim, tw::Int yDim, tw::Int zDim, const tw::vec3 &corner, const tw::vec3 &size, tw::Int ghostCellLayers = 2)

Create a DiscreteSpace with purely local coordinates.

void Resize(const tw::Int dim[4], const tw::Int gdim[4], const tw::Int dom[4], const tw::vec3 &gcorner, const tw::vec3 &gsize, tw::Int ghostCellLayers = 2)

Change the topology and coordinates.

void Resize(Task &task, const tw::vec3 &gcorner, const tw::vec3 &gsize, tw::Int ghostCellLayers = 2)

Change the coordinates, inheriting the Task topology.

inline void SetupTimeInfo(tw::Float dt0)

Change the time step. Use Simulation::UpdateTimestep to do this for all modules.

inline tw::Int EncodeCell(tw::Int i, tw::Int j, tw::Int k) const

Encode the cell with topological indices (i,j,k)

inline void DecodeCell(const tw::Int &cell, tw::Int ijk[4]) const

Decode cell to produce topological indices (ijk[1],ijk[2],ijk[3]). This assumes z-packed encoding, i.e., decodingStride[3]=1.

inline void DecodeCell(const tw::Int &cell, tw::Int *i, tw::Int *j, tw::Int *k) const

Decode cell to produce topological indices (i,j,k). This assumes z-packed encoding, i.e., decodingStride[3]=1.

inline void DecodeCell(const Primitive &q, tw::Int ijk[4]) const

Decode q to produce topological indices (ijk[1],ijk[2],ijk[3]). This assumes z-packed encoding, i.e., decodingStride[3]=1.

inline void DecodeCell(const Primitive &q, tw::Int *i, tw::Int *j, tw::Int *k) const

Decode q to produce topological indices (i,j,k). This assumes z-packed encoding, i.e., decodingStride[3]=1.

inline void MinimizePrimitive(Primitive &q) const

Change the reference cell to the one containing the particle centroid. This leaves x[ax] within the normal range [-.5,.5) except when the particle has left the extended domain. In the latter case the reference cell is pegged to the current extended domain, leaving x[ax] out of normal range.

Protected Attributes

tw::Float dt

timestep

tw::Float dth

half timestep

tw::Float dti

inverse timestep

tw::vec3 corner

position where all coordinates are minimized on the local domain

tw::vec3 size

length of the local domain along each axis

tw::vec3 globalCorner

position where all coordinates are minimized on the global domain

tw::vec3 globalSize

length of the global domain along each axis

tw::vec3 spacing

center-to-center cell separation along each axis (uniform grids only)

tw::vec3 freq

inverse of spacing component by component (uniform grids only)

tw::Int dim[4]

dim[1..3] are the number of cells along each axis. When a Field is derived, dim[0] becomes the number of components.

tw::Int num[4]

num is similar to dim, except ghost cells are included.

tw::Int encodingStride[4]

Parameters of the default cell encoding. For the encoding see EncodeCell. The encodingStride is 0 along an ignorable axis resulting in a many-one mapping, i.e., ghost cells and the one interior cell map to the same cell for the ignorable axis.

tw::Int decodingStride[4]

The decodingStride differs from the encodingStride only in that ignorable axes have unit strides. See DecodeCell for the decoding.

tw::Int lfg[4]

indices of lower far ghost cells

tw::Int ufg[4]

indices of upper far ghost cells

tw::Int lng[4]

indices of lower near ghost cells

tw::Int ung[4]

indices of upper near ghost cells

tw::Int layers[4]

number of ghost cell layers, layers[0] holds maximum layers

tw::Int ignorable[4]

1 if axis is ignorable, 0 otherwise