WaveBlocksND
Public Member Functions | Private Attributes | List of all members
waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex > Class Template Reference

A shape enumeration is a complete, ordered list of all lattice nodes that are part of the basis shape. More...

#include <shape_enum.hpp>

Public Member Functions

 ShapeEnum ()=default
 
 ShapeEnum (std::vector< ShapeSlice< D, MultiIndex > > &&slices, std::size_t n_entries, MultiIndex limits)
 
 ShapeEnum (const ShapeEnum &that)=default
 
 ShapeEnum (ShapeEnum &&that)
 
ShapeEnumoperator= (const ShapeEnum &that)=default
 
ShapeEnumoperator= (ShapeEnum &&that)
 
const ShapeSlice< D, MultiIndex > & slice (int islice) const
 Returns a reference to a slice. More...
 
ShapeSlice< D, MultiIndex > & slice (int islice)
 
const std::vector< ShapeSlice< D, MultiIndex > > & slices () const
 Returns a reference to the array containing all slices. More...
 
MultiIndex at (std::size_t ordinal) const
 
std::size_t n_entries () const
 Retrieves the number of nodes. More...
 
int n_slices () const
 Retrieves the number of slices. More...
 
const MultiIndex & limits () const
 Retrieves the minimum bounding box which contains all nodes. More...
 
int limit (dim_t axis) const
 Retrieves the \( d \)-th entry of the minimum bounding box \( K \). More...
 
bool operator== (const ShapeEnum &that) const
 Checks whether both enumerations are equals by comparison of every node. More...
 
bool operator!= (const ShapeEnum &that) const
 

Private Attributes

ShapeSlice< D, MultiIndex > lower_
 
ShapeSlice< D, MultiIndex > upper_
 
std::vector< ShapeSlice< D, MultiIndex > > slices_
 
std::size_t n_entries_
 
MultiIndex limits_
 

Detailed Description

template<dim_t D, class MultiIndex>
class waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >

A shape enumeration is a complete, ordered list of all lattice nodes that are part of the basis shape.

Definition

A \( D \)-dimensional shape enumeration \( \mathfrak{K} \) is a set of ordered D-dimensional integer-tuples (aka node).

Rationale

A basis shape description just tells, whether it contains a specific node. But we need to associate coefficients \(c_{\underline{k}}\) and basis functions \(\phi_{\underline{k}}\) with shape nodes \(\underline{k}\). We can use a hashtable to map \(\underline{k}\) to \(c_{\underline{k}}\), \(\phi_{\underline{k}}\). But it is simpler to enumerate all nodes in a shape. This means, if a multi-index \(\underline{k}\) maps to ordinal \(i\), we find \(\phi_{\underline{k}}\) at the position \(i\) on the array \(\{\phi\}\). This way, we can keep coefficients and basis function values in an array, ordered according to the shape enumeration.

Slicing

Many algorithms, notable evaluation of a hagedorn wavepacket, use recursive formulas in the form \( \phi_{\underline{k}} = f(\phi_{\underline{k}-\underline{e}^1}, \ldots, \phi_{\underline{k}-\underline{e}^D}) \), where \( \phi_{\underline{k}} \) is a value associated with the node \( \underline{k} \) and where \( \underline{e}^d \) is the unit vector in direction \( d \). Thus, it is beneficial to organize a shape into slices. The \( s \)-th slice of a shape \( \mathfrak{K} \) contains all nodes \( \underline{k} \in \mathfrak{K} \) that satisfy \( \sum_{d=1}^{D} k_d = s \).

The \( s \)-th slice contains all multi-indices \( \boldsymbol{k} \in \mathfrak{K} \) that satisfy \( \displaystyle\sum_{d=1}^{D} k_d = s \).

To determine, to which slice a multi-index belongs, use:

#include <numeric>
int islice = std::accumulate(index.begin(), index.end(), int(0));

Nodes in the same slice are ordered lexically. This ordering enables simple and efficient union and intersect operations on shape enumerations.

Usage

#include "waveblocks/shape_commons.hpp"
#include "waveblocks/tiny_multi_index.hpp"
#include "waveblocks/shape_enumerator.hpp"
#include "waveblocks/shape_enum.hpp"
using namespace waveblocks;

Create a shape description (see AbstractShape).

const dim_t D = 5;
LimitedHyperbolicCutShape<D> shape(7.0, {2,2,4,4,4});

Select an appropriate data type to represent an integer tuple.

typedef TinyMultiIndex<std::size_t,D> MultiIndex;

Pass the shape description to the ShapeEnumerator and you get a ShapeEnum:

ShapeEnumerator<D, MultiIndex> enumerator;
std::shared_ptr< ShapeEnum<D, MultiIndex> > enumeration = enumerator.enumerate(shape);

Select a slice:

const ShapeSlice<D, MultiIndex>& slice = enumeration->slice(slice_index);

Get the \( i \)-th node of the slice:

MultiIndex index = slice[i];

Get ordinal of a node \( \underline{k} \):

std::size_t ordinal = slice.offset() + slice.find(k);

If you aren't sure, whether the slice contains a node, use:

std::size_t ordinal;
if (slice.try_find(k, ordinal)) {
ordinal += slice.offset();
// do something
}

Constructor & Destructor Documentation

template<dim_t D, class MultiIndex>
waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::ShapeEnum ( )
default
template<dim_t D, class MultiIndex>
waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::ShapeEnum ( std::vector< ShapeSlice< D, MultiIndex > > &&  slices,
std::size_t  n_entries,
MultiIndex  limits 
)
inline
template<dim_t D, class MultiIndex>
waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::ShapeEnum ( const ShapeEnum< D, MultiIndex > &  that)
default
template<dim_t D, class MultiIndex>
waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::ShapeEnum ( ShapeEnum< D, MultiIndex > &&  that)
inline

Member Function Documentation

template<dim_t D, class MultiIndex>
MultiIndex waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::at ( std::size_t  ordinal) const
inline
template<dim_t D, class MultiIndex>
int waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::limit ( dim_t  axis) const
inline

Retrieves the \( d \)-th entry of the minimum bounding box \( K \).

The minimum bounding box of \( \mathfrak{K} \) is defined by

\[ K_d = \max\left\{k_d | k \in \mathfrak{K} \right\} \]

Parameters
axisThe axis \( d \).
Returns
The limit \( K_d \).
template<dim_t D, class MultiIndex>
const MultiIndex& waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::limits ( ) const
inline

Retrieves the minimum bounding box which contains all nodes.

The minimum bounding box \( K \) of \( \mathfrak{K} \) is defined by

\[ K_d = \max\left\{k_d | k \in \mathfrak{K} \right\} \]

template<dim_t D, class MultiIndex>
std::size_t waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::n_entries ( ) const
inline

Retrieves the number of nodes.

template<dim_t D, class MultiIndex>
int waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::n_slices ( ) const
inline

Retrieves the number of slices.

template<dim_t D, class MultiIndex>
bool waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::operator!= ( const ShapeEnum< D, MultiIndex > &  that) const
inline
template<dim_t D, class MultiIndex>
ShapeEnum& waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::operator= ( const ShapeEnum< D, MultiIndex > &  that)
default
template<dim_t D, class MultiIndex>
ShapeEnum& waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::operator= ( ShapeEnum< D, MultiIndex > &&  that)
inline
template<dim_t D, class MultiIndex>
bool waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::operator== ( const ShapeEnum< D, MultiIndex > &  that) const
inline

Checks whether both enumerations are equals by comparison of every node.

template<dim_t D, class MultiIndex>
const ShapeSlice<D, MultiIndex>& waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::slice ( int  islice) const
inline

Returns a reference to a slice.

This function does not fail if an invalid slice index is passed. If the slice index is negative, then this function returns an empty slice with offset 0. If the slice index is equals or larger then the number of slices, this function returns an empty slice with offset equals to the basis shape size.

Parameters
[in]isliceOrdinal of the requested slice.
Returns
Reference to slice.
template<dim_t D, class MultiIndex>
ShapeSlice<D, MultiIndex>& waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::slice ( int  islice)
inline
template<dim_t D, class MultiIndex>
const std::vector< ShapeSlice<D, MultiIndex> >& waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::slices ( ) const
inline

Returns a reference to the array containing all slices.

Member Data Documentation

template<dim_t D, class MultiIndex>
MultiIndex waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::limits_
private
template<dim_t D, class MultiIndex>
ShapeSlice<D,MultiIndex> waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::lower_
private
template<dim_t D, class MultiIndex>
std::size_t waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::n_entries_
private
template<dim_t D, class MultiIndex>
std::vector< ShapeSlice<D, MultiIndex> > waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::slices_
private
template<dim_t D, class MultiIndex>
ShapeSlice<D,MultiIndex> waveblocks::wavepackets::shapes::ShapeEnum< D, MultiIndex >::upper_
private

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