GLAC  1.0
neighbours.h
Go to the documentation of this file.
1 
12 #ifndef NEIGHBOURS_H
13 #define NEIGHBOURS_H
14 
15 #include "neighbourlist.h"
16 #include <vector>
17 
18 namespace Parallel {
20 {
21 private:
22  static int m_processRank;
23  static int m_numproc;
24  static int m_Nx, m_Ny, m_Nz, m_Nt; // Prosessors per dimension
25  static long m_P[4]; // Prosessor coordinate
26  static void generateNeighbourList();
27  static std::vector<NeighbourList> m_neighbourLists;
28 
29  // Contigious index finder for cubes
30  /*
31  * Neighbour list values defined as:
32  * 0: x-1 | 1: x+1
33  * 2: y-1 | 3: y+1
34  * 4: z-1 | 5: z+1
35  * 6: t-1 | 7: t+1
36  */
37 
38  // Functions for finding correct direction of neighbouring lattices
39  static inline int getXPlusOne(int Np) {
40  if (((Np + 1) % m_Nx) == 0) {
41  return (Np/m_Nx) * m_Nx;
42  } else {
43  return Np + 1;
44  }
45  }
46 
47  static inline int getXMinusOne(int Np) {
48  int x_count = (Np - 1 + m_Nx) % m_Nx;
49  int y_count = (Np/m_Nx) * m_Nx;
50  return x_count + y_count;
51  }
52 
53  static inline int getYPlusOne(int Np) {
54  if ((((Np / m_Nx) + 1) % m_Ny) == 0) {
55  int x_count = Np % m_Nx;
56  int y_count = (Np / (m_Ny*m_Nx)) * (m_Nx*m_Ny);
57  return x_count + y_count;
58  } else {
59  return Np + m_Nx;
60  }
61  }
62 
63  static inline int getYMinusOne(int Np) {
64  int x_count = Np % m_Nx;
65  int y_count = (((Np/m_Nx) - 1 + m_Ny) % m_Ny) * m_Nx;
66  int z_count = (Np/(m_Nx * m_Ny)) * (m_Nx*m_Ny);
67  return x_count + y_count + z_count;
68  }
69 
70  static inline int getZPlusOne(int Np) {
71  if (((Np/(m_Nx*m_Ny) + 1) % m_Nz) == 0) {
72  int x_count = Np % m_Nx;
73  int y_count = ((Np/m_Nx) % m_Ny) * m_Nx;
74  int t_count = ((Np/(m_Nx*m_Ny*m_Nz)) % m_Nt) * (m_Nx*m_Ny*m_Nz);
75  return x_count + y_count + t_count;
76  } else {
77  return Np + m_Nx*m_Ny;
78  }
79  }
80 
81  static inline int getZMinusOne(int Np) {
82  int x_count = Np % m_Nx;
83  int y_count = ((Np/m_Nx) % m_Ny) * m_Nx;
84  int z_count = ((Np/(m_Nx*m_Ny) - 1 + m_Nz) % m_Nz) * (m_Nx*m_Ny);
85  int t_count = (Np/(m_Nx*m_Ny*m_Nz)) * (m_Nx*m_Ny*m_Nz);
86  return x_count + y_count + z_count + t_count;
87  }
88 
89  static inline int getTPlusOne(int Np) {
90  if ((((Np/(m_Nx*m_Ny*m_Nz)) + 1) % m_Nt) == 0) {
91  int x_count = Np % m_Nx;
92  int y_count = ((Np/m_Nx) % m_Ny) * m_Nx;
93  int z_count = (Np/(m_Nx*m_Ny) % m_Nz) * (m_Nx*m_Ny);
94  return x_count + y_count + z_count;
95  } else {
96  return Np + m_Nx*m_Ny*m_Nz;
97  }
98  }
99 
100  static inline int getTMinusOne(int Np) {
101  int x_count = Np % m_Nx;
102  int y_count = ((Np/m_Nx) % m_Ny) * m_Nx;
103  int z_count = (Np/(m_Nx*m_Ny) % m_Nz) * (m_Nx*m_Ny);
104  int t_count = ((Np/(m_Nx*m_Ny*m_Nz) - 1 + m_Nt) % m_Nt) * (m_Nx*m_Ny*m_Nz);
105  return x_count + y_count + z_count + t_count;
106  }
107 public:
108  Neighbours();
109  ~Neighbours();
110 
111  static void initialize(int processRank, int numproc, int * processorsPerDim);
112 
118  static int get(int iProcDir) { return m_neighbourLists[m_processRank][iProcDir]; } // Returns neighbour list for iP processor.
119 
120  // Getters
121  static NeighbourList* getNeighbours(int Np);
122  static int getListLength() { return m_numproc; }
123  static long getProcessorDimensionPosition(int dim) { return m_P[dim]; }
124 };
125 }
126 
127 #endif // NEIGHBOURS_H
static NeighbourList * getNeighbours(int Np)
Parallel::Neighbours::getNeighbours returns a reference to the neighbour list of given process rank.
Definition: neighbours.cpp:71
Definition: neighbourlist.h:22
static int get(int iProcDir)
get returns the neighbourlist for the the calling processor/rank and the direction given py iProcDir.
Definition: neighbours.h:118
Neighbours()
Definition: neighbours.cpp:12
Parallel contains all of the relevant methods for communicating between the lattices.
Definition: communicator.h:17
static void initialize(int processRank, int numproc, int *processorsPerDim)
Parallel::Neighbours::initialize initializes.
Definition: neighbours.cpp:26
Definition: neighbours.h:19
static int getListLength()
Definition: neighbours.h:122
static long getProcessorDimensionPosition(int dim)
Definition: neighbours.h:123
~Neighbours()
Definition: neighbours.cpp:16