1 #ifndef MPI_DirectionalGridEnvironment_H
2 #define MPI_DirectionalGridEnvironment_H
5 #include "MPI_GridEnvironment.h"
29 template<tUCInt N,tUCInt D=1>
44 static constexpr tUCInt N_DIRECTIONS=2*D+1;
47 std::map<tUCInt,tMPICoreId> mDirectionalNeighbors;
107 mem+=mDirectionalNeighbors.size()*(
sizeof(tUCInt)+
sizeof(tMPICoreId));
121 inline static CORE_UniquePointer<SelfClass>
New(
const std::array<tMPICoreId,N>& nCoresPerDirection,
122 int& argc,
char * argv[],
const tBoolean& isOpenMPEnabled) {
124 CORE_UniquePointer<SelfClass> p(
new SelfClass(argc,argv,isOpenMPEnabled),
130 std::array<tMPIBoolean,N> isPeriodicPerDirection;
131 for(
auto& p: isPeriodicPerDirection) p=
false;
136 std::vector<tBoolean> Vs;
137 functions_array::parse(gridP,Vs);
138 for(
int i=Vs.size();i<N;i++) {
141 auto iVs=Vs.cbegin();
142 for(
auto& p:isPeriodicPerDirection) {
148 MPI_Cart_create(MPI_COMM_WORLD,
149 (
int) N,nCoresPerDirection.data(),isPeriodicPerDirection.data(),
153 if (p->getWorld()==MPI_COMM_NULL) {
192 return functions_numeric::pow<tUCInt,N>(N_DIRECTIONS);
202 functions_array::reset(dir);
203 dir[f/2]=(f%2==0)?-1:1;
211 std::array<tCInt,N> dir;
219 std::array<tCInt,N> dir;
220 functions_array::reset(dir);
221 tMPICoreId* iNeighbors=&neighbors[0];
251 std::map<tUCInt,tMPICoreId>::const_iterator iNeighbors=mDirectionalNeighbors.find(dirIndex);
252 if (iNeighbors==mDirectionalNeighbors.end())
return NULL_CORE;
253 return iNeighbors->second;
260 return mDirectionalNeighbors;
268 mDirectionalNeighbors=neighbors;
279 inline static void GetDirection(
const tUCInt& index,std::array<tCInt,N>& dir) {
280 GetLevelDirection<1>(index,dir.data());
288 return GetLevelDirectionIndex<1>(dir.data());
315 template<tUCInt i> requires (i==N)
316 inline static tMPICoreId GetLevelDirectionIndex(
const tCInt* dir) {
322 template<tUCInt i> requires (i<N)
323 inline static tMPICoreId GetLevelDirectionIndex(
const tCInt* dir) {
324 return (*dir)+D+N_DIRECTIONS*GetLevelDirectionIndex<i+1>(dir+1);
329 template<tUCInt i> requires (i==N)
330 inline static void GetLevelDirection(
const tUCInt& index,tCInt* dir) {
337 template<tUCInt i> requires (i<N)
338 inline static void GetLevelDirection(
const tUCInt& index,tCInt* dir) {
339 (*dir)=index%N_DIRECTIONS;
341 GetLevelDirection<i+1>(index/N_DIRECTIONS,dir+1);
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
static tBoolean ReadOption(int nArgs, char *argv[], const tBoolean &isCaseSensitive, const tString &optionName, tString &optionValue)
read the only the option with optionName in command line
Definition: CORE_OptionsList.cpp:260
This class is a grid Environment of templated dimension N=1,2,3.
Definition: MPI_DirectionalGridEnvironment.h:30
static tUCInt GetFaceDirectionalIndex(const tUCInt &f, std::array< tCInt, N > &dir)
get the face index in direction
Definition: MPI_DirectionalGridEnvironment.h:201
tMPICoreId getDirectionalNeighbor(const std::array< tCInt, N > &dir) const
get the neighbor core in the dierction dir
Definition: MPI_DirectionalGridEnvironment.h:240
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: MPI_DirectionalGridEnvironment.h:105
static tUCInt GetFaceDirectionalIndex(const tUCInt &f)
get the face index in direction
Definition: MPI_DirectionalGridEnvironment.h:210
static tUCInt GetMaximumDirectionalNeighborsNumber()
get the maximum direction number : (2*D+1)^N when D is the neighbor Depth (D=0,1,2)
Definition: MPI_DirectionalGridEnvironment.h:191
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: MPI_DirectionalGridEnvironment.h:93
static tUCInt GetDirectionIndex(const std::array< tCInt, N > &dir)
get the direction index from dir index=dir[0]+1+3*(dir[1]+1+3*(dir[2]+1)) in {0,27}
Definition: MPI_DirectionalGridEnvironment.h:287
virtual void initialize()
initialize the environment
Definition: MPI_DirectionalGridEnvironment.h:303
tMPICoreId getDirectionalNeighbor(const tUCInt &dirIndex) const
get the neighbor core
Definition: MPI_DirectionalGridEnvironment.h:250
static CORE_UniquePointer< SelfClass > New(const std::array< tMPICoreId, N > &nCoresPerDirection, int &argc, char *argv[], const tBoolean &isOpenMPEnabled)
create a new cart environment
Definition: MPI_DirectionalGridEnvironment.h:121
void setDirectionalNeighbors(const std::map< tUCInt, tMPICoreId > &neighbors)
set neighbors grids per face
Definition: MPI_DirectionalGridEnvironment.h:267
constexpr tUCInt GetNeighborsDepth()
get the depth of neighbors
Definition: MPI_DirectionalGridEnvironment.h:185
static void GetDirection(const tUCInt &index, std::array< tCInt, N > &dir)
get the direction dir from index: index=dir[0]+1+D*(dir[1]+1+3*(dir[2]+1)) in {0,27}
Definition: MPI_DirectionalGridEnvironment.h:279
MPI_DirectionalGridEnvironment(int &argc, char *argv[], const tBoolean &isOpenMPEnabled)
create a root environment
Definition: MPI_DirectionalGridEnvironment.h:73
const std::map< tUCInt, tMPICoreId > & getDirectionalNeighbors() const
get the neighbor cores in all directions
Definition: MPI_DirectionalGridEnvironment.h:259
virtual ~MPI_DirectionalGridEnvironment(void)
destroy
Definition: MPI_DirectionalGridEnvironment.h:81
MPI_DirectionalGridEnvironment()
create a root environment
Definition: MPI_DirectionalGridEnvironment.h:58
void getFaceNeighbors(std::array< tMPICoreId, 2 *N > &neighbors) const
get the coreId in canonical face
Definition: MPI_DirectionalGridEnvironment.h:218
This class is a grid Environment of templated dimension N=1,2,3.
Definition: MPI_GridEnvironment.h:34
virtual void initialize()
initialize the environment
Definition: MPI_GridEnvironment.h:388
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: MPI_GridEnvironment.h:112