DASH  0.3.0
dash::halo::RegionCoords< NumDimensions > Class Template Reference

N-Dimensional region coordinates and associated indices for all possible Halo/Boundary regions of a HaloBlock. More...

#include <Region.h>

Public Types

using Coords_t = std::array< uint8_t, NumDimensions >
 
using CoordsVec_t = std::vector< Self_t >
 
using RegIndDepVec_t = std::vector< region_index_t >
 
using RegIndexDim_t = std::pair< region_index_t, region_index_t >
 

Public Member Functions

 RegionCoords ()
 Default Constructor. More...
 
template<typename... Values>
 RegionCoords (region_coord_t value, Values... values)
 Constructor allows custom coordinate values and calculates the fitting region index. More...
 
 RegionCoords (region_index_t index)
 Constructor takes a region index to set up the region coordinates. More...
 
constexpr region_index_t index () const
 
dim_t level ()
 returns the number of coordinates unequal to the center (1) for all dimensions More...
 
constexpr bool operator== (const Self_t &other) const
 
constexpr bool operator!= (const Self_t &other) const
 
constexpr const std::array< region_coord_t, NumDimensions > & values () const
 Return value with all dimensions as array of NumDimensions elements. More...
 
region_coord_t dim (dim_t dimension) const
 The value in the given dimension. More...
 
constexpr region_coord_t operator[] (size_t dimension) const
 Subscript operator, access to value in dimension given by index. More...
 
region_coord_t & operator[] (size_t dimension)
 Subscript assignment operator, access to value in dimension given by index. More...
 
constexpr bool operator== (const self_t &other) const
 Equality comparison operator. More...
 
constexpr bool operator!= (const self_t &other) const
 Equality comparison operator. More...
 
constexpr dim_t rank () const
 The number of dimensions of the value. More...
 

Static Public Member Functions

static constexpr region_index_t center_index ()
 
static Coords_t center_coords ()
 
static constexpr RegIndexDim_t index (dim_t dim)
 Returns a region index for a given dimension and RegionPos. More...
 
static constexpr region_index_t index (dim_t dim, RegionPos pos)
 Returns a region index for a given dimension and RegionPos. More...
 
template<typename StencilPointT >
static constexpr region_index_t index (const StencilPointT &stencil)
 Returns a region index for a given dimension and RegionPos. More...
 
static region_index_t index (const Coords_t &coords)
 Returns the region index for a given RegionCoords. More...
 
static Coords_t coords (const region_index_t index)
 
static dim_t relevant_dim (const Coords_t &coords)
 Returns the highest dimension with region values != 1. More...
 
static dim_t level (const Coords_t &coords)
 auto max = stencil.max(); level = 0 -> center (1,1) level = 1 -> main regions (e.g. More...
 
static RegIndDepVec_t boundary_dependencies (region_index_t index)
 
static constexpr dim_t ndim ()
 The number of dimensions of the value. More...
 

Detailed Description

template<dim_t NumDimensions>
class dash::halo::RegionCoords< NumDimensions >

N-Dimensional region coordinates and associated indices for all possible Halo/Boundary regions of a HaloBlock.

The center (all values = 1) is the local NArray memory block used by the HaloBlock.

Example for 2-D

.----—..----—..----—. | 0 || 1 || 2 <-|– region index | (0,0) || (0,1) || (0,2)<|– region coordinates | NW || N || NE <|– north east (only for explanation) '----—''----—''----—' .----—..----—..----—. | 3 || 4 || 5 | | (1,0) || (1,1) || (1,2) | | W || C || E | '----—''----—''----—' .----—..----—..----—. | 6 || 7 || 8 | | (2,0) || (2,1) || (2,2) | | SW || S || SE | '----—''----—''----—'

Definition at line 40 of file Region.h.

Constructor & Destructor Documentation

◆ RegionCoords() [1/3]

template<dim_t NumDimensions>
dash::halo::RegionCoords< NumDimensions >::RegionCoords ( )
inline

Default Constructor.

All region coordinate values are 1 and pointing to the center.

Definition at line 61 of file Region.h.

61  {
62  for(dim_t i = 0; i < NumDimensions; ++i) {
63  this->_values[i] = 1;
64  }
65  }
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39

◆ RegionCoords() [2/3]

template<dim_t NumDimensions>
template<typename... Values>
dash::halo::RegionCoords< NumDimensions >::RegionCoords ( region_coord_t  value,
Values...  values 
)
inline

Constructor allows custom coordinate values and calculates the fitting region index.

Definition at line 72 of file Region.h.

73  : Base_t::Dimensional(value, values...) {
74  }
constexpr const std::array< region_coord_t, NumDimensions > & values() const
Return value with all dimensions as array of NumDimensions elements.
Definition: Dimensional.h:142

◆ RegionCoords() [3/3]

template<dim_t NumDimensions>
dash::halo::RegionCoords< NumDimensions >::RegionCoords ( region_index_t  index)
inline

Constructor takes a region index to set up the region coordinates.

Definition at line 79 of file Region.h.

79  {
80  this->_values = Self_t::coords(index);
81  }
constexpr region_index_t index() const
Definition: Region.h:97
static Coords_t coords(const region_index_t index)
Definition: Region.h:181

Member Function Documentation

◆ coords()

template<dim_t NumDimensions>
static Coords_t dash::halo::RegionCoords< NumDimensions >::coords ( const region_index_t  index)
inlinestatic
Parameters
indexregion index
Returns
region coordinates

Definition at line 181 of file Region.h.

References dash::index().

181  {
182  Coords_t coords{};
183  region_index_t index_tmp =index;
184  for(auto i = (NumDimensions - 1); i >= 1; --i) {
185  auto res = std::div(static_cast<long>(index_tmp), static_cast<long>(REGION_INDEX_BASE));
186  coords[i] = res.rem;
187  index_tmp = res.quot;
188  }
189  coords[0] = index_tmp;
190 
191  return coords;
192  }
constexpr region_index_t index() const
Definition: Region.h:97
static Coords_t coords(const region_index_t index)
Definition: Region.h:181

◆ dim()

region_coord_t dash::Dimensional< region_coord_t , NumDimensions >::dim ( dim_t  dimension) const
inlineinherited

The value in the given dimension.

Parameters
dimensionThe dimension
Returns
The value in the given dimension

Definition at line 152 of file Dimensional.h.

152  {
153  DASH_ASSERT_LT(
154  dimension, NumDimensions,
155  "Dimension for Dimensional::extent() must be lower than " <<
156  NumDimensions);
157  return _values[dimension];
158  }

◆ index() [1/5]

template<dim_t NumDimensions>
constexpr region_index_t dash::halo::RegionCoords< NumDimensions >::index ( ) const
inline
Returns
region index

Definition at line 97 of file Region.h.

References dash::halo::RegionCoords< NumDimensions >::index().

Referenced by dash::halo::RegionCoords< NumDimensions >::index(), and dash::halo::RegionSpec< NumDimensions >::operator[]().

97 { return index(this->_values); }
constexpr region_index_t index() const
Definition: Region.h:97

◆ index() [2/5]

template<dim_t NumDimensions>
static constexpr RegIndexDim_t dash::halo::RegionCoords< NumDimensions >::index ( dim_t  dim)
inlinestatic

Returns a region index for a given dimension and RegionPos.

Definition at line 102 of file Region.h.

102  {
103  RegIndexDim_t index_dim = std::make_pair(0,0);
104 
105  for(dim_t d = 0; d < NumDimensions; ++d)
106  if(dim == d) {
107  index_dim.first = index_dim.first * REGION_INDEX_BASE;
108  index_dim.second = 2 + index_dim.second * REGION_INDEX_BASE;
109  }
110  else {
111  index_dim.first = 1 + index_dim.first * REGION_INDEX_BASE;
112  index_dim.second = 1 + index_dim.second * REGION_INDEX_BASE;
113  }
114 
115  return index_dim;
116  }
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
region_coord_t dim(dim_t dimension) const
The value in the given dimension.
Definition: Dimensional.h:152

◆ index() [3/5]

template<dim_t NumDimensions>
static constexpr region_index_t dash::halo::RegionCoords< NumDimensions >::index ( dim_t  dim,
RegionPos  pos 
)
inlinestatic

Returns a region index for a given dimension and RegionPos.

Definition at line 121 of file Region.h.

121  {
122  region_coord_t coord = (pos == RegionPos::PRE) ? 0 : 2;
123 
124  region_index_t index = 0;
125  for(dim_t d = 0; d < NumDimensions; ++d)
126  if(dim == d)
127  index = coord + index * REGION_INDEX_BASE;
128  else
129  index = 1 + index * REGION_INDEX_BASE;
130 
131  return index;
132  }
constexpr region_index_t index() const
Definition: Region.h:97
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
region_coord_t dim(dim_t dimension) const
The value in the given dimension.
Definition: Dimensional.h:152

◆ index() [4/5]

template<dim_t NumDimensions>
template<typename StencilPointT >
static constexpr region_index_t dash::halo::RegionCoords< NumDimensions >::index ( const StencilPointT &  stencil)
inlinestatic

Returns a region index for a given dimension and RegionPos.

Definition at line 138 of file Region.h.

References dash::index().

138  {
139  region_index_t index = 0;
140  for(dim_t d = 0; d < NumDimensions; ++d) {
141  if(stencil[d] < 0) {
142  index *= REGION_INDEX_BASE;
143  continue;
144  }
145 
146  if(stencil[d] > 0) {
147  index = 2 + index * REGION_INDEX_BASE;
148  continue;
149  }
150 
151  index = 1 + index * REGION_INDEX_BASE;
152  }
153 
154  return index;
155  }
constexpr region_index_t index() const
Definition: Region.h:97
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39

◆ index() [5/5]

template<dim_t NumDimensions>
static region_index_t dash::halo::RegionCoords< NumDimensions >::index ( const Coords_t &  coords)
inlinestatic

Returns the region index for a given RegionCoords.

Returns
region index

Definition at line 162 of file Region.h.

References dash::index().

162  {
163  region_index_t index = coords[0];
164  for(dim_t d = 1; d < NumDimensions; ++d) {
165  // in case a wrong region coordinate was set
166  if(coords[d] > 2) {
167  index = coords[d] + index * REGION_INDEX_BASE;
168  } else {
169  index = coords[d] + index * REGION_INDEX_BASE;
170  }
171  }
172 
173  return index;
174  }
constexpr region_index_t index() const
Definition: Region.h:97
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
static Coords_t coords(const region_index_t index)
Definition: Region.h:181

◆ level() [1/2]

template<dim_t NumDimensions>
static dim_t dash::halo::RegionCoords< NumDimensions >::level ( const Coords_t &  coords)
inlinestatic

auto max = stencil.max(); level = 0 -> center (1,1) level = 1 -> main regions (e.g.

2D: (0,1) (2,1) (1,0) (1,2) level = 2 e.g. 2D corner regions or 3D edge regions ... for dimensions higher than 2D relevant

Definition at line 213 of file Region.h.

213  {
214  dim_t level = 0;
215  for(auto d = 0; d < NumDimensions; ++d) {
216  if(coords[d] != 1)
217  ++level;
218  }
219  return level;
220  }
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
dim_t level()
returns the number of coordinates unequal to the center (1) for all dimensions
Definition: Region.h:231
static Coords_t coords(const region_index_t index)
Definition: Region.h:181

◆ level() [2/2]

template<dim_t NumDimensions>
dim_t dash::halo::RegionCoords< NumDimensions >::level ( )
inline

returns the number of coordinates unequal to the center (1) for all dimensions

level = 0 -> center (1,1) level = 1 -> main regions (e.g. 2D: (0,1) (2,1) (1,0) (1,2) level = 2 e.g. 2D corner regions or 3D edge regions ... for dimensions higher than 2D relevant

Definition at line 231 of file Region.h.

References dash::index(), and dash::halo::RegionCoords< NumDimensions >::level().

Referenced by dash::halo::RegionCoords< NumDimensions >::level().

231 { return level(this->_values); }
dim_t level()
returns the number of coordinates unequal to the center (1) for all dimensions
Definition: Region.h:231

◆ ndim()

static constexpr dim_t dash::Dimensional< region_coord_t , NumDimensions >::ndim ( )
inlinestaticinherited

The number of dimensions of the value.

Definition at line 207 of file Dimensional.h.

207  {
208  return NumDimensions;
209  }

◆ operator!=()

constexpr bool dash::Dimensional< region_coord_t , NumDimensions >::operator!= ( const self_t other) const
inlineinherited

Equality comparison operator.

Definition at line 193 of file Dimensional.h.

193  {
194  return !(*this == other);
195  }

◆ operator==()

constexpr bool dash::Dimensional< region_coord_t , NumDimensions >::operator== ( const self_t other) const
inlineinherited

Equality comparison operator.

Definition at line 186 of file Dimensional.h.

186  {
187  return this == &other || _values == other._values;
188  }

◆ operator[]() [1/2]

constexpr region_coord_t dash::Dimensional< region_coord_t , NumDimensions >::operator[] ( size_t  dimension) const
inlineinherited

Subscript operator, access to value in dimension given by index.

Alias for dim.

Parameters
dimensionThe dimension
Returns
The value in the given dimension

Definition at line 167 of file Dimensional.h.

167  {
168  return _values[dimension];
169  }

◆ operator[]() [2/2]

region_coord_t & dash::Dimensional< region_coord_t , NumDimensions >::operator[] ( size_t  dimension)
inlineinherited

Subscript assignment operator, access to value in dimension given by index.

Alias for dim.

Parameters
dimensionThe dimension
Returns
A reference to the value in the given dimension

Definition at line 179 of file Dimensional.h.

179  {
180  return _values[dimension];
181  }

◆ rank()

constexpr dim_t dash::Dimensional< region_coord_t , NumDimensions >::rank ( ) const
inlineinherited

The number of dimensions of the value.

Definition at line 200 of file Dimensional.h.

200  {
201  return NumDimensions;
202  }

◆ relevant_dim()

template<dim_t NumDimensions>
static dim_t dash::halo::RegionCoords< NumDimensions >::relevant_dim ( const Coords_t &  coords)
inlinestatic

Returns the highest dimension with region values != 1.

Definition at line 197 of file Region.h.

197  {
198  dim_t dim = 1;
199  for(auto d = 1; d < NumDimensions; ++d) {
200  if(coords[d] != 1)
201  dim = d + 1;
202  }
203 
204  return dim;
205  }
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
region_coord_t dim(dim_t dimension) const
The value in the given dimension.
Definition: Dimensional.h:152
static Coords_t coords(const region_index_t index)
Definition: Region.h:181

◆ values()

constexpr const std::array<region_coord_t , NumDimensions>& dash::Dimensional< region_coord_t , NumDimensions >::values ( ) const
inlineinherited

Return value with all dimensions as array of NumDimensions elements.

Definition at line 142 of file Dimensional.h.

142  {
143  return _values;
144  }

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