21 #include <debug/Crash.hpp> 22 #include <ios/Logger.hpp> 23 #include <math/Arithmetic.hpp> 24 #include <metaprogramming/CRTP.hpp> 25 #include <utility/Bits.hpp> 26 #include <utility/Flags.hpp> 27 #include <utility/Position.hpp> 30 #define PROVIDE_COORDS_TYPES 32 typedef std::array<Coord,NDims> Coords; 34 typedef std::array<Coord,2
*NDims> Neigh; 52 constexpr
int moveOffset[2]=
61 constexpr
int GRID_DEFAULT_FLAGS=
62 combineFlags<GridFlag::HASHED>;
101 template <
typename Tb,
111 const auto& maxHashability=
113 if(
static_cast<decltype(maxHashability)>(volume)>maxHashability)
114 CRASH<<
"Cannot hash a volume of "<<volume<<
", max allowed: "<<(
int)maxHashability;
130 fillVolumeHashTable(coordsOfPointsHashTable,
141 fillVolumeHashTable(neighsOfPointsHashTable,
177 coordsOfPointsHashTable[i];
189 neighsOfPointsHashTable[i][oriDir];
193 static constexpr
char hashingTag[]=
201 template <
typename T,
205 class GridHashable<T,
242 static constexpr
char hashingTag[]=
251 template <
typename T,
256 class GridShiftableBC;
261 template <
typename T,
265 class GridShiftableBC<T,
278 Coords _shiftOfBC{0};
289 if(_shiftOfBC[dir]!=0)
290 CRASH<<
"Shift of shiftedFace "<<dir<<
"must be zero, it is"<<_shiftOfBC[dir];
300 safeModulo(shift[mu],
CRTP_THIS.side(mu));
316 return _shiftOfBC[mu];
324 const Coord nBCpassed)
330 const Coord muOffset=
331 this->shiftOfBC(perpDir)*moveOffset[ori]*nBCpassed;
334 const Coord rawMuDest=
335 in[perpDir]+muOffset;
339 safeModulo(rawMuDest,
CRTP_THIS.side(perpDir));
352 template <
typename T,
356 class GridShiftableBC<T,
367 constexpr
int shiftedFace()
374 constexpr
int shiftOfBC(
int mu)
384 Coord getShiftedCoordPerpToMove(
const Coords& in,
388 const Coord nBCpassed)
398 template <
int NDims=4,
412 getFlag<Flags,GridFlag::SHIFTED_BC>>
434 forAllDims([&](
int mu)
444 static constexpr
int flags=
448 static constexpr
bool isHashing=
449 getFlag<flags,GridFlag::HASHED>;
452 static constexpr
bool isShiftingBC=
453 getFlag<flags,GridFlag::SHIFTED_BC>;
456 static constexpr
int nDims=
460 static constexpr
int nOriDirs=
472 Side side(
const int mu)
488 void assertPointIsInRange(
const Idx& i)
492 if(i<0
or i>=volume())
493 CRASH<<
"Cannot access to element "<<i;
497 void assertOriDirIsInRange(
const int& oriDir)
501 if(oriDir<0
or oriDir>=2*NDims)
502 CRASH<<
"Cannot use oriented dir "<<oriDir<<
"out of range [0,"<<2*NDims<<
"]";
506 void assertCoordsAreInRange(
const Coords& cs)
510 forAllDims([&](
int mu)
521 CRASH<<
"Cannot have dimension "<<mu<<
" equal to "<<c<<
", negative or larger than "<<m;
526 template <
typename F>
527 static void forAllDims(F&& f)
529 for(
int mu=0;mu<nDims;mu++)
534 template <
typename F>
535 static void forAllOriDirs(F&& f)
537 for(
int oriDir=0;oriDir<nOriDirs;oriDir++)
542 template <
typename F>
543 void forAllPoints(F&& f)
547 for(Idx i=0;i<volume();i++)
552 static Orientation oriOfOriDir(
const int oriDir)
570 int dimOfOriDir(
const int oriDir)
const 578 int oriDirOfOriAndDim(
const Orientation ori,
const int dim)
const 584 void setSides(
const Sides& extSides)
591 if constexpr(isHashing)
592 this->fillHashTables();
596 Coords computeCoordsOfPoint(Idx i)
const 598 assertPointIsInRange(i);
603 for(
int mu=nDims-1;mu>=0;mu--)
627 Idx pointOfCoords(
const Coords& cs)
const 629 assertCoordsAreInRange(cs);
635 forAllDims([&](
int mu)
653 Coords shiftedCoords(
const Coords& in,
655 const Coord amount=1)
671 moveOffset[ori]*amount;
679 safeModulo(rawDest,side(moveDir));
682 const Coord nBCpassed=
683 ((rawDest<0)?(-rawDest+side(moveDir)):rawDest)/side(moveDir);
685 forAllDims([&](
int mu)
689 this->getShiftedCoordPerpToMove(in,ori,moveDir,mu,nBCpassed);
700 Idx computeNeighOfPoint(
const Idx i,
704 assertPointIsInRange(i);
705 assertOriDirIsInRange(oriDir);
708 pointOfCoords(shiftedCoords(
this->coordsOfPoint(i),oriDir));
712 Grid(
const Sides& sides={})
722 Grid(
const Side(&sides)[NDims])
726 #undef PROVIDE_COORDS Idx neighOfPoint(const Idx i, const int oriDir) const
Return the neighbor in the given oriented dir, computing it.
Orientation
Value to identifiy orientations.
#define CRTP_THIS
Access to the inheriting class.
void fillHashTables() const
Fill all the HashTables (dummy version)
int shiftedFace() const
Gets the shifting face.
#define CRASH
Initialize the crasher.
void fillVolumeHashTable(Tb &tb, F f)
Fills the required hashtable with the function.
#define PROVIDE_CRTP_CAST_OPERATOR(CLASS)
void setShiftBC(const int dir, const Coords &shift)
Set shift for boundary.
Coords coordsOfPoint(Idx i) const
Get the coords of given point, computing it.
void fillCoordsOfPointsHashTables()
Set the hash table of coordinates of all points.
void fillHashTables()
Fill all the HashTables.
#define PROVIDE_COORDS_TYPES
Provide the type needed to deal with grids.
Coord getShiftedCoordPerpToMove(const Coords &in, const int ori, const int moveDir, const int perpDir, const Coord nBCpassed) const
Returns the shifted coord due to boundary passing.
Idx neighOfPoint(const Idx i, const int oriDir) const
Return the neighbor in the given oriented dir.
const Coords & coordsOfPoint(Idx i) const
Get the coords of given point.
std::vector< Coords > coordsOfPointsHashTable
Hashed coords of all points.
Coord shiftOfBC(int mu) const
Gets the shifting of the given direction.
void fillNeighsOfPointsHashTables()
Set the hash table of neighbors.
A grid of points spanning an hypercubic grid.
std::vector< Neigh > neighsOfPointsHashTable
Hashed neighbors.
#define GRID_DEBUG
Flag to enable Grid debug.