00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00026 class mdp_site {
00027 private:
00028 mdp_lattice *ptr;
00029 public:
00030 long idx;
00031 #ifdef BLOCKSITE
00032 int block[BLOCKSITE];
00033 #endif
00034 mdp_site() {
00035
00036 ptr=0;
00037 idx=0;
00038 }
00041 mdp_site(const mdp_lattice &a) {
00042 on(a);
00043 }
00044 void on(const mdp_lattice &a) {
00045 ptr=(mdp_lattice*) &a;
00046 idx=(*ptr).start[ME][0];
00047 #ifdef BLOCKSITE
00048 for(int k=0; k<BLOCKSITE; k++) block[k]=0;
00049 #endif
00050 }
00052 inline mdp_lattice &lattice() {
00053 return *ptr;
00054 }
00055 inline mdp_site(long i, mdp_lattice* ptr2) {
00056 idx=i;
00057 ptr=ptr2;
00058 #ifdef BLOCKSITE
00059 for(int k=0; k<BLOCKSITE; k++) block[k]=0;
00060 #endif
00061 }
00062 #ifdef BLOCKSITE
00063 inline mdp_site(long i, mdp_lattice* ptr2, int b[], int sign=0, int mu=0) {
00064 idx=i;
00065 ptr=ptr2;
00066 for(int k=0; k<BLOCKSITE; k++) block[k]=b[k];
00067 block[mu]+=sign;
00068 }
00069 #endif
00070 mdp_site(const mdp_site &x) {
00071 idx=x.idx;
00072 ptr=x.ptr;
00073 #ifdef BLOCKSITE
00074 for(int k=0; k<BLOCKSITE; k++) block[k]=x.block[k];
00075 #endif
00076 }
00077 inline mdp_site operator=(long i) {
00078 idx=lattice().start[ME][0]+i;
00079 return mdp_site(idx, ptr);
00080 }
00081 inline mdp_site operator=(mdp_site x) {
00082 if(ptr==x.ptr) idx=x.idx;
00083 else set_global(x.global_index());
00084 #ifdef BLOCKSITE
00085 for(int k=0; k<BLOCKSITE; k++) block[k]=x.block[k];
00086 return mdp_site(idx, ptr, block);
00087 #endif
00088 return mdp_site(idx, ptr);
00089 }
00090 inline int operator==(mdp_site x) {
00091 if((idx==NOWHERE) || (x.idx==NOWHERE)) return FALSE;
00092 return (global_index()==x.global_index());
00093 }
00094 inline int operator!=(mdp_site x) {
00095 if((idx==NOWHERE) || (x.idx==NOWHERE)) return TRUE;
00096 return (global_index()!=x.global_index());
00097 }
00098 inline void start(int np=0) {
00099 #ifdef BLOCKSITE
00100 for(int k=0; k<BLOCKSITE; k++) block[k]=0;
00101 #endif
00102 idx=lattice().start[ME][np];
00103 }
00104 inline void next() {
00105 idx++;
00106 }
00109 inline int is_in() {
00110 if((idx>=lattice().start[ME][0]) &&
00111 (idx<lattice().stop[ME][1])) return 1;
00112 else return 0;
00113 }
00117 inline int is_here() {
00118 if((idx>=0) && (idx<lattice().nvol)) return 1;
00119 else return 0;
00120 }
00122 inline int parity() {
00123 return lattice().parity[idx];
00124 }
00127 inline int is_in_boundary() {
00128 return (lattice().wh[idx]!=ME);
00129 }
00133 inline long local_index() {
00134 return idx;
00135 }
00137 inline long global_index() {
00138 return lattice().gl[idx];
00139 }
00141 inline void set_local(long idx2) {
00142 idx=idx2;
00143 }
00145 inline void set_global(long idx_gl) {
00146 long idx2=lattice().local(idx_gl);
00147 if(idx2==NOWHERE)
00148 error("set_global() trying to access a site that is not here");
00149 idx=idx2;
00150 }
00152 inline mdp_site operator+ (int mu) {
00153 long idx2=lattice().up[idx][mu];
00154 if(idx2==NOWHERE) {
00155 cout << ME << " " << (*this)(0) << (*this)(1)
00156 << (*this)(2) << (*this)(3) << " " << mu << endl;
00157 error("You cannot exit from your portion of the lattice");
00158 }
00159 #ifdef BLOCKSITE
00160 if((mu<BLOCKSITE) && (lattice().co[idx][mu]==lattice().nx[mu]-1))
00161 return mdp_site(idx2, ptr, block,1,mu);
00162 return mdp_site(idx2, ptr, block);
00163 #endif
00164 return mdp_site(idx2, ptr);
00165 }
00167 inline mdp_site operator- (int mu) {
00168 long idx2=lattice().dw[idx][mu];
00169 if(idx2==NOWHERE)
00170 error("You cannot exit from your portion of the lattice");
00171 #ifdef BLOCKSITE
00172 if((mu<BLOCKSITE) && (lattice().co[idx][mu]==0))
00173 return mdp_site(idx2, ptr, block, -1,mu);
00174 return mdp_site(idx2, ptr, block);
00175 #endif
00176 return mdp_site(idx2, ptr);
00177 }
00180 inline mdp_site hop(int i, int mu) {
00181 mdp_site y(lattice());
00182 y=(*this);
00183 while(i!=0) {
00184 if(i<0) {y=y-mu; i++;}
00185 if(i>0) {y=y+mu; i--;}
00186 }
00187 return y;
00188 }
00190 inline mdp_site operator= (mdp_vector v) {
00191 set(v.x[0],v.x[1],v.x[2],v.x[3],v.x[4],
00192 v.x[5],v.x[6],v.x[7],v.x[8],v.x[9]);
00193 return *this;
00194 }
00197 inline mdp_site operator+ (mdp_vector v) {
00198 int mu,step;
00199 mdp_site y=*this;
00200 for(mu=0; mu<lattice().ndim; mu++) {
00201 if(v.x[mu]>0) for(step=0; step<v.x[mu]; step++) y=y+mu;
00202 else for(step=0; step<-v.x[mu]; step++) y=y-mu;
00203 }
00204 return y;
00205 }
00208 inline mdp_site operator- (mdp_vector v) {
00209 int mu,step;
00210 mdp_site y=*this;
00211 for(mu=0; mu<lattice().ndim; mu++) {
00212 if(v.x[mu]>0) for(step=0; step<v.x[mu]; step++) y=y-mu;
00213 else for(step=0; step<-v.x[mu]; step++) y=y+mu;
00214 }
00215 return y;
00216 }
00218 inline int operator() (int mu) {
00219 return lattice().co[idx][mu];
00220 }
00221 void operator= (int *x) {
00222 int ndim=lattice().ndim;
00223 idx=x[0];
00224 for(int mu=1; mu<ndim; mu++) idx=idx*lattice().nx[mu]+x[mu];
00225 idx=lattice().local(idx);
00226 if(idx==NOWHERE) {
00227 bool print=mdp.print;
00228 mdp.print=true;
00229 mdp << "Warning message from ME=" << ME << ":\n";
00230 mdp << "You assigned a site that is not here!\n";
00231 mdp.print=print;
00232 }
00233 }
00237 void set(int x0, int x1=0, int x2=0, int x3=0, int x4=0,
00238 int x5=0, int x6=0, int x7=0, int x8=0, int x9=0) {
00239 int ndim=lattice().ndim;
00240 idx=x0;
00241 if(ndim>1) idx=idx*lattice().nx[1]+x1;
00242 if(ndim>2) idx=idx*lattice().nx[2]+x2;
00243 if(ndim>3) idx=idx*lattice().nx[3]+x3;
00244 if(ndim>4) idx=idx*lattice().nx[4]+x4;
00245 if(ndim>5) idx=idx*lattice().nx[5]+x5;
00246 if(ndim>6) idx=idx*lattice().nx[6]+x6;
00247 if(ndim>7) idx=idx*lattice().nx[7]+x7;
00248 if(ndim>8) idx=idx*lattice().nx[8]+x8;
00249 if(ndim>9) idx=idx*lattice().nx[9]+x9;
00250 idx=lattice().local(idx);
00251 if(idx==NOWHERE) {
00252 bool print=mdp.print;
00253 mdp.print=true;
00254 mdp << "Warning message from ME=" << ME << ":\n";
00255 mdp << "You assigned a site that is not here!\n";
00256 mdp.print=print;
00257 }
00258 }
00259 int operator==(int *x) {
00260 int ndim=lattice().ndim;
00261 int is_it=1;
00262 for(int mu=0; mu<ndim; mu++)
00263 if(x[mu]!=lattice().co[idx][mu]) is_it=0;
00264 return is_it;
00265 }
00266 int operator!=(int *x) {
00267 return !(*this == x);
00268 }
00270 int is_equal(int x0, int x1=0, int x2=0, int x3=0, int x4=0,
00271 int x5=0, int x6=0, int x7=0, int x8=0, int x9=0) {
00272 int ndim=lattice().ndim;
00273 int is_it=1;
00274 if((ndim>0) && (x0!=lattice().co[idx][0])) is_it=0;
00275 if((ndim>1) && (x1!=lattice().co[idx][1])) is_it=0;
00276 if((ndim>2) && (x2!=lattice().co[idx][2])) is_it=0;
00277 if((ndim>3) && (x3!=lattice().co[idx][3])) is_it=0;
00278 if((ndim>4) && (x4!=lattice().co[idx][4])) is_it=0;
00279 if((ndim>5) && (x5!=lattice().co[idx][5])) is_it=0;
00280 if((ndim>6) && (x6!=lattice().co[idx][6])) is_it=0;
00281 if((ndim>7) && (x7!=lattice().co[idx][7])) is_it=0;
00282 if((ndim>8) && (x8!=lattice().co[idx][8])) is_it=0;
00283 if((ndim>9) && (x9!=lattice().co[idx][9])) is_it=0;
00284 return is_it;
00285 }
00289 inline friend long site2binary(mdp_site x) {
00290 int mu, a=0;
00291 for(mu=0; mu<x.lattice().ndim; mu++) {
00292 #ifdef CHECK_ALL
00293 if(fabs(0.5-x(mu))>1) error("site2binary");
00294 #endif
00295 a+=(0x1 << mu)*x(mu);
00296 }
00297 return a;
00298 }
00302 friend int on_which_process(mdp_lattice &a,
00303 int x0=0,
00304 int x1=0,
00305 int x2=0,
00306 int x3=0,
00307 int x4=0,
00308 int x5=0,
00309 int x6=0,
00310 int x7=0,
00311 int x8=0,
00312 int x9=0) {
00313 int x[10];
00314 x[0]=x0;
00315 if(a.ndim>1) x[1]=x1;
00316 if(a.ndim>2) x[2]=x2;
00317 if(a.ndim>3) x[3]=x3;
00318 if(a.ndim>4) x[4]=x4;
00319 if(a.ndim>5) x[5]=x5;
00320 if(a.ndim>6) x[6]=x6;
00321 if(a.ndim>7) x[7]=x7;
00322 if(a.ndim>8) x[8]=x8;
00323 if(a.ndim>9) x[9]=x9;
00324 return (*(a.where))(x, a.ndim, a.nx);
00325 }
00326 };
00327
00328 #ifdef MDP_LATTICE
00329
00331 inline mdp_prng &mdp_lattice::random(mdp_site x) {
00332 if(local_random_generator) {
00333 if(!x.is_in()) error("request the random generator of a non local site");
00334 return random_obj[x.idx-start[ME][0]];
00335 }
00336 return mdp_random;
00337 }
00338
00339 #endif
00340
00344 inline int in_block(mdp_site x) {
00345 #ifdef TWISTED_BOUNDARY
00346 static int mu;
00347 for(mu=0; mu<x.lattice().ndim; mu++)
00348 if(x.block[mu]!=0) return FALSE;
00349 #endif
00350 return TRUE;
00351 };
00352
00353 ostream& operator<<(ostream& os, mdp_site &x) {
00354 for(int i=0; i<x.lattice().ndim; i++) {
00355 if(i==0) os << "(" << x(i);
00356 else os << "," << x(i);
00357 }
00358 os << ")";
00359 return os;
00360 }