Go to the documentation of this file.
21 #ifndef THUNDEREGG_ORTHANT_H
22 #define THUNDEREGG_ORTHANT_H
49 unsigned char val = num_orthants;
52 static constexpr
size_t num_orthants = 1 << D;
58 explicit Orthant(
const unsigned char val_in)
238 std::array<Side<D>, D> retval;
239 for (
size_t i = 0; i < D; i++) {
241 if (!((1 << i) & val)) {
255 std::array<Side<D>, D> retval;
256 for (
size_t i = 0; i < D; i++) {
258 if ((1 << i) & val) {
276 bool is_bit_set = val & (0x1 << idx);
277 return is_bit_set == remainder;
279 bool isHigherOnAxis(
size_t axis)
const {
return val & (0b1 << axis); }
280 bool isLowerOnAxis(
size_t axis)
const {
return !(val & (0b1 << axis)); }
290 size_t upper_mask = (~0x0U) << axis;
291 return Orthant<D - 1>(((val >> 1) & upper_mask) | (val & ~upper_mask));
312 unsigned int lower_mask = ~((~0x0U) << bit_to_insert);
313 unsigned int upper_mask = (~0x0U) << (bit_to_insert + 1);
316 for (
size_t i = 0; i < Orthant<D>::num_orthants / 2; i++) {
317 size_t value = (i << 1) & upper_mask;
318 value |= i & lower_mask;
319 value |= set_bit << bit_to_insert;
364 os <<
"Orthant<0>::null()";
366 os <<
"Orthant<0> invalid value: " << o.
getIndex();
384 os <<
"Orthant<1>::lower()";
386 os <<
"Orthant<1>::upper()";
388 os <<
"Orthant<1>::null()";
390 os <<
"Orthant<1> invalid value: " << o.
getIndex();
408 os <<
"Orthant<2>::sw()";
410 os <<
"Orthant<2>::se()";
412 os <<
"Orthant<2>::nw()";
414 os <<
"Orthant<2>::ne()";
416 os <<
"Orthant<2>::null()";
418 os <<
"Orthant<2> invalid value: " << o.
getIndex();
436 os <<
"Orthant<3>::bsw()";
438 os <<
"Orthant<3>::bse()";
440 os <<
"Orthant<3>::bnw()";
442 os <<
"Orthant<3>::bne()";
444 os <<
"Orthant<3>::tsw()";
446 os <<
"Orthant<3>::tse()";
448 os <<
"Orthant<3>::tnw()";
450 os <<
"Orthant<3>::tne()";
452 os <<
"Orthant<3>::null()";
454 os <<
"Orthant<3> invalid value: " << o.
getIndex();
459 to_json(tpl::nlohmann::json& j,
const Orthant<0>& o);
461 to_json(tpl::nlohmann::json& j,
const Orthant<1>& o);
463 to_json(tpl::nlohmann::json& j,
const Orthant<2>& o);
465 to_json(tpl::nlohmann::json& j,
const Orthant<3>& o);
467 from_json(
const tpl::nlohmann::json& j, Orthant<0>& o);
469 from_json(
const tpl::nlohmann::json& j, Orthant<1>& o);
471 from_json(
const tpl::nlohmann::json& j, Orthant<2>& o);
473 from_json(
const tpl::nlohmann::json& j, Orthant<3>& o);
static Orthant< 2 > ne()
North-East quadrant of square.
Definition: Orthant.h:92
Orthant< D > getNbrOnSide(Side< D > s) const
Return the octant that neighbors this octant on a particular side.
Definition: Orthant.h:224
Orthant< D - 1 > collapseOnAxis(size_t axis) const
From the point of view of an axis, get orthant that this orthant lies on in the D-1 dimension.
Definition: Orthant.h:288
auto getAxisIndex() const -> typename std::enable_if< D<=3 &&D >=1 &&M==D - 1 &&N==N, size_t >::type
Get the axis index of this side.
Definition: Face.h:458
An enum-style class that represents the octants of a cube.
Definition: Orthant.h:43
bool operator<(const Orthant< D > &other) const
Less Tan operator.
Definition: Orthant.h:347
Orthant()
Default constructor that initializes the value to null().
Definition: Orthant.h:64
static Orthant< 3 > bne()
Bottom-North-East octant of cube.
Definition: Orthant.h:108
static Orthant< 2 > se()
South-East quadrant of square.
Definition: Orthant.h:84
size_t getIndex() const
Get the integer value of the octant.
Definition: Orthant.h:216
static Orthant< 3 > bnw()
Bottom-North-West octant of cube.
Definition: Orthant.h:104
bool operator!=(const Iterator &b) const
Check the iterators don't reference the same value.
Definition: Orthant.h:190
const Orthant< D > & operator++()
Increment the Orthant value.
Definition: Orthant.h:158
const Orthant< D > * operator->() const
Get a pointer to the Orthant object.
Definition: Orthant.h:174
Iterator end()
Returns an iterator with Orthant<D>::null()
Definition: Orthant.h:203
static Orthant< 3 > tnw()
Top-North-West octant of cube.
Definition: Orthant.h:120
bool operator==(const Orthant< D > &other) const
Equals operator.
Definition: Orthant.h:331
auto isLowerOnAxis() const -> typename std::enable_if< D<=3 &&D >=1 &&M==D - 1 &&N==N, bool >::type
Return if this side is lower on it's axis.
Definition: Face.h:468
static Range getValues()
Get a range of values that can be iterated over.
Definition: Orthant.h:210
bool operator!=(const Orthant< D > &other) const
Not Equals operator.
Definition: Orthant.h:339
const Orthant< D > & operator*() const
Get a reference to the Orthant object.
Definition: Orthant.h:168
The ThunderEgg namespace.
Definition: BiLinearGhostFiller.h:31
static std::array< Orthant, num_orthants/2 > getValuesOnSide(Side< D > s)
Get an array of all Orthant<D> values that lie on a particular side of the cube.
Definition: Orthant.h:308
size_t getIndex() const
Get the index for this Face.
Definition: Face.h:452
static Orthant< 3 > bse()
Bottom-South-East octant of cube.
Definition: Orthant.h:100
std::array< Side< D >, D > getInteriorSides() const
Get the sides of the octant that are on the interior of the cube.
Definition: Orthant.h:236
static Orthant< 1 > lower()
Lower half of line.
Definition: Orthant.h:72
Iterator(Orthant< D > o_in)
Construct a new Iterator object with the given Orthant value.
Definition: Orthant.h:150
std::array< Side< D >, D > getExteriorSides() const
Get the sides of the octant that are on the exterior of the cube.
Definition: Orthant.h:253
static Orthant< 3 > tne()
Top-North-East octant of cube.
Definition: Orthant.h:124
static Orthant< 2 > nw()
North-West quadrant of square.
Definition: Orthant.h:88
static Orthant< 3 > tsw()
Top-South-West octant of cube.
Definition: Orthant.h:112
Input iterator for Orthant values.
Definition: Orthant.h:136
Iterator begin()
Returns an iterator with the lowest Orthant value.
Definition: Orthant.h:197
static Orthant< 3 > tse()
Top-South-East octant of cube.
Definition: Orthant.h:116
Range class for Orthant.
Definition: Orthant.h:130
static Orthant< 3 > bsw()
Bottom-South-West octant of cube.
Definition: Orthant.h:96
std::ostream & operator<<(std::ostream &os, const Side< 1 > &s)
ostream operator that prints a string representation of side enum.
Orthant(const unsigned char val_in)
Create new Orthant<D> with given value.
Definition: Orthant.h:58
bool isOnSide(Side< D > s) const
Return whether or not the octant lies on a particular side of a cube.
Definition: Orthant.h:272
Enum-style class for the faces of an n-dimensional cube.
Definition: Face.h:41
static Orthant< 1 > upper()
Upper half of line.
Definition: Orthant.h:76
static Orthant< 2 > sw()
South-West quadrant of square.
Definition: Orthant.h:80
bool operator==(const Iterator &b) const
Check the iterators reference the same value.
Definition: Orthant.h:182