From: Alex Schmidt Date: Tue, 26 Jun 2012 11:06:08 +0000 (+1000) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/385a5a6cbcab9001633efd700b2ffdeaf1aaaf6d ... --- diff --git a/neigh.cpp b/neigh.cpp new file mode 100644 index 0000000..a25d1e7 --- /dev/null +++ b/neigh.cpp @@ -0,0 +1,28 @@ +#include "neigh.h" + +neigh::neigh(const int& dimension, const int& length) +{ + nfield = new int[ipow(dimension,length)*2*dimension]; + + for (int ipos = 0; ipos < ipow(length,dimension); ipos++) + { + for (int idir = 0; idir < 2*dimension; idir++) + { + if ( idir < dimension ) //pos direction + { + if ( ( ipos/ipow(length,idir%dimension) ) % length == length-1 ) + nfield[ipos*2*dimension + idir] = ipos - ipow(length,idir%dimension)*(length-1); + else + nfield[ipos*2*dimension + idir] = ipos + ipow(length,idir%dimension); + } + else //negative dir + { + if ( ( ipos/ipow(length,idir%dimension) ) % length == 0 ) + nfield[ipos*2*dimension + idir] = ipos + ipow(length,idir%dimension)*(length-1); + else + nfield[ipos*2*dimension + idir] = ipos - ipow(length,idir%dimension); + } + + } + } +} diff --git a/neigh.h b/neigh.h new file mode 100644 index 0000000..73ffe62 --- /dev/null +++ b/neigh.h @@ -0,0 +1,18 @@ +#ifndef NEIGH_H +#define NEIGH_H + +class neigh +{ + private: + int *nfield; + static int ipow(const int& x, const int& p){ + if (p == 0) return 1; + if (p == 1) return x; + return x * ipow(x, p-1); + } + public: + neigh(const int& length, const int& dimension); + int& operator[] (int i) {return nfield[i];} +}; + +#endif