Block-Structured AMR Software Framework
amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER > Struct Template Reference

#include <AMReX_Array.H>

Public Member Functions

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * begin () const noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * end () const noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * begin () noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * end () noexcept
 
template<typename O = ORDER, std::enable_if_t< std::is_same_v< O, Order::F >, int > = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & operator() (int i, int j) const noexcept
 
template<typename O = ORDER, std::enable_if_t< std::is_same_v< O, Order::F >, int > = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & operator() (int i, int j) noexcept
 
template<typename O = ORDER, std::enable_if_t< std::is_same_v< O, Order::C >, int > = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & operator() (int i, int j) const noexcept
 
template<typename O = ORDER, std::enable_if_t< std::is_same_v< O, Order::C >, int > = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & operator() (int i, int j) noexcept
 
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINEsum () const noexcept
 
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINEsum (int axis, int loc) const noexcept
 
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINEproduct () const noexcept
 
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINEproduct (int axis, int loc) const noexcept
 

Static Public Member Functions

AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE unsigned int size () noexcept
 
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int xlo () noexcept
 
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int xhi () noexcept
 
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE unsigned int xlen () noexcept
 
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int ylo () noexcept
 
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int yhi () noexcept
 
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE unsigned int ylen () noexcept
 

Public Attributes

arr [(XHI-XLO+1) *(YHI-YLO+1)]
 

Detailed Description

template<class T, int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
struct amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >

A GPU-compatible two-dimensional array.

Template Parameters
XLOIndex for lower bound in x dimension. Can be other than 0.
XHIIndex for upper bound in x dimension.
YLOIndex for lower bound in y dimension. Can be other than 0.
YHIIndex for upper bound in y dimension.
ORDEREither Order::C (C/C++ row-major order) or Order::F (Fortran column-major order, which is the default if not given)

Member Function Documentation

◆ begin() [1/2]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T* amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::begin ( ) const
inlinenoexcept

Returns a const pointer address to the first element of the Array2D object, as if the object is treated as one-dimensional.

◆ begin() [2/2]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T* amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::begin ( )
inlinenoexcept

Returns a pointer address to the first element of the Array2D object, as if the object is treated as one-dimensional.

◆ end() [1/2]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T* amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::end ( ) const
inlinenoexcept

Returns a const pointer address right after the last element of the Array2D object, as if the object is treated as one-dimensional.

◆ end() [2/2]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T* amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::end ( )
inlinenoexcept

Returns a pointer address right after the last element of the Array2D object, as if the object is treated as one-dimensional.

◆ operator()() [1/4]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
template<typename O = ORDER, std::enable_if_t< std::is_same_v< O, Order::F >, int > = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::operator() ( int  i,
int  j 
) const
inlinenoexcept

The elements of an Array2D object are accessed using parentheses, e.g. array(i,j), instead of using square brackets. If the order is not specified, Fortran column-major order is assumed (the index i moves the fastest)

◆ operator()() [2/4]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
template<typename O = ORDER, std::enable_if_t< std::is_same_v< O, Order::C >, int > = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T& amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::operator() ( int  i,
int  j 
) const
inlinenoexcept

The elements of an Array2D object are accessed using parentheses, e.g. array(i,j), instead of using square brackets. When the order is manually specified as Order::C, row-major order is used (the index j moves the fastest).

◆ operator()() [3/4]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
template<typename O = ORDER, std::enable_if_t< std::is_same_v< O, Order::F >, int > = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::operator() ( int  i,
int  j 
)
inlinenoexcept

The elements of an Array2D object are accessed using parentheses, e.g. array(i,j), instead of using square brackets. If the order is not specified, Fortran column-major order is assumed (the index i moves the fastest)

◆ operator()() [4/4]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
template<typename O = ORDER, std::enable_if_t< std::is_same_v< O, Order::C >, int > = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T& amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::operator() ( int  i,
int  j 
)
inlinenoexcept

The elements of an Array2D object are accessed using parentheses, e.g. array(i,j), instead of using square brackets. When the order is manually specified as Order::C, row-major order is used (the index j moves the fastest).

◆ product() [1/2]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::product ( ) const
inlineconstexprnoexcept

When called without any arguments, returns the product of all elements in the Array2D object.

◆ product() [2/2]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::product ( int  axis,
int  loc 
) const
inlineconstexprnoexcept

When called with two arguments, performs a product reduction over the specified axis, for a particular location index loc.

Parameters
axisThe dimension to reduce (0 for x dimension, 1 for y dimension)
locThe appropriate location index

This can be used, for instance, to calculate the product over the x dimension of an Array2D object that was instantiated as

Array2D<amrex::Real, 1, M, 1, N> array; 

One could instantiate an Array1D object to hold the results with,

Array1D<amrex::Real, 1, N> vec; 

and then perform the product for each element of the resulting vector.

for (int j = 1; j <= N; ++j) {
    vec(j) = array.sum(0,j)
}

In this example, the axis is 0 and the location index is j.

◆ size()

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE unsigned int amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::size ( )
inlinestaticconstexprnoexcept

Returns the total number of elements of the Array2D object as an unsigned integer.

◆ sum() [1/2]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::sum ( ) const
inlineconstexprnoexcept

When called without any arguments, returns the sum of all elements in the Array2D object.

◆ sum() [2/2]

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::sum ( int  axis,
int  loc 
) const
inlineconstexprnoexcept

When called with two arguments, performs a sum reduction over the specified axis, for a particular location index loc.

Parameters
axisThe dimension to reduce (0 for x dimension, 1 for y dimension)
locThe appropriate location index

This can be used, for instance, to calculate the sum over the y dimension of an Array2D object that was instantiated as

Array2D<amrex::Real, 1, M, 1, N> array; 

One could instantiate an Array1D object to hold the results,

Array1D<amrex::Real, 1, M> vec; 

and then perform the summation for each element of the resulting vector.

for (int i = 1; i <= M; ++i) {
    vec(i) = array.sum(1,i)
}

In this example, the axis is 1 and the location index is i.

◆ xhi()

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::xhi ( )
inlinestaticconstexprnoexcept

Returns the index of the upper bound of the Array2D object in the x direction.

◆ xlen()

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE unsigned int amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::xlen ( )
inlinestaticconstexprnoexcept

Returns the number of elements of the Array2D object in the x direction as an unsigned integer.

◆ xlo()

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::xlo ( )
inlinestaticconstexprnoexcept

Returns the index of the lower bound of the Array2D object in the x direction. Can be other than 0.

◆ yhi()

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::yhi ( )
inlinestaticconstexprnoexcept

Returns the index of the upper bound of the Array2D object in the y direction.

◆ ylen()

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE unsigned int amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::ylen ( )
inlinestaticconstexprnoexcept

Returns the number of elements of the Array2D object in the y direction as an unsigned integer.

◆ ylo()

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::ylo ( )
inlinestaticconstexprnoexcept

Returns the index of the lower bound of the Array2D object in the y direction. Can be other than 0.

Member Data Documentation

◆ arr

template<class T , int XLO, int XHI, int YLO, int YHI, class ORDER = Order::F>
T amrex::Array2D< T, XLO, XHI, YLO, YHI, ORDER >::arr[(XHI-XLO+1) *(YHI-YLO+1)]

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