00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00017 int on_which_process(mdp_lattice &a,
00018 int x0=0, int x1=0, int x2=0, int x3=0, int x4=0,
00019 int x5=0, int x6=0, int x7=0, int x8=0, int x9=0);
00020
00021
00035 class mdp_site {
00036 private:
00037 mdp_lattice *ptr;
00038 public:
00039 mdp_int idx;
00040 #ifdef BLOCKSITE
00041 int block[BLOCKSITE];
00042 #endif
00043 mdp_site() {
00044
00045 ptr=0;
00046 idx=0;
00047 }
00050 mdp_site(const mdp_lattice &a) {
00051 on(a);
00052 }
00053 void on(const mdp_lattice &a) {
00054 ptr=(mdp_lattice*) &a;
00055 idx=(*ptr).start[ME][0];
00056 #ifdef BLOCKSITE
00057 for(int k=0; k<BLOCKSITE; k++) block[k]=0;
00058 #endif
00059 }
00061 inline mdp_lattice &lattice() {
00062 return *ptr;
00063 }
00064 inline mdp_site(mdp_int i, mdp_lattice* ptr2) {
00065 idx=i;
00066 ptr=ptr2;
00067 #ifdef BLOCKSITE
00068 for(int k=0; k<BLOCKSITE; k++) block[k]=0;
00069 #endif
00070 }
00071 #ifdef BLOCKSITE
00072 inline mdp_site(mdp_int i, mdp_lattice* ptr2, int b[], int sign=0, int mu=0) {
00073 idx=i;
00074 ptr=ptr2;
00075 for(int k=0; k<BLOCKSITE; k++) block[k]=b[k];
00076 block[mu]+=sign;
00077 }
00078 #endif
00079 mdp_site(const mdp_site &x) {
00080 idx=x.idx;
00081 ptr=x.ptr;
00082 #ifdef BLOCKSITE
00083 for(int k=0; k<BLOCKSITE; k++) block[k]=x.block[k];
00084 #endif
00085 }
00086 inline mdp_site operator=(mdp_int i) {
00087 idx=lattice().start[ME][0]+i;
00088 return mdp_site(idx, ptr);
00089 }
00090 inline mdp_site operator=(mdp_site x) {
00091 if(ptr==x.ptr) idx=x.idx;
00092 else set_global(x.global_index());
00093 #ifdef BLOCKSITE
00094 for(int k=0; k<BLOCKSITE; k++) block[k]=x.block[k];
00095 return mdp_site(idx, ptr, block);
00096 #endif
00097 return mdp_site(idx, ptr);
00098 }
00099 inline int operator==(mdp_site x) {
00100 if((idx==NOWHERE) || (x.idx==NOWHERE)) return false;
00101 return (global_index()==x.global_index());
00102 }
00103 inline int operator!=(mdp_site x) {
00104 if((idx==NOWHERE) || (x.idx==NOWHERE)) return true;
00105 return (global_index()!=x.global_index());
00106 }
00107 inline void start(int np=0) {
00108 #ifdef BLOCKSITE
00109 for(int k=0; k<BLOCKSITE; k++) block[k]=0;
00110 #endif
00111 idx=lattice().start[ME][np];
00112 }
00113 inline void next() {
00114 idx++;
00115 }
00118 inline int is_in() {
00119 if((idx>=lattice().start[ME][0]) &&
00120 (idx<lattice().stop[ME][1])) return 1;
00121 else return 0;
00122 }
00126 inline int is_here() {
00127 if((idx>=0) && (idx<lattice().nvol)) return 1;
00128 else return 0;
00129 }
00131 inline int parity() {
00132 return lattice().parity[idx];
00133 }
00136 inline int is_in_boundary() {
00137 return (lattice().wh[idx]!=ME);
00138 }
00142 inline mdp_int local_index() {
00143 return idx;
00144 }
00146 inline mdp_int global_index() {
00147 return lattice().gl[idx];
00148 }
00150 inline void set_local(mdp_int idx2) {
00151 idx=idx2;
00152 }
00154 inline void set_global(mdp_int idx_gl) {
00155 mdp_int idx2=lattice().local(idx_gl);
00156 if(idx2==NOWHERE)
00157 error("set_global() trying to access a site that is not here");
00158 idx=idx2;
00159 }
00161 inline mdp_site operator+ (int mu) {
00162 mdp_int idx2=lattice().up[idx][mu];
00163 if(idx2==NOWHERE) {
00164 cout << ME << " " << (*this)(0) << (*this)(1)
00165 << (*this)(2) << (*this)(3) << " " << mu << endl;
00166 error("You cannot exit from your portion of the lattice");
00167 }
00168 #ifdef BLOCKSITE
00169 if((mu<BLOCKSITE) && (lattice().co[idx][mu]==lattice().nx[mu]-1))
00170 return mdp_site(idx2, ptr, block,1,mu);
00171 return mdp_site(idx2, ptr, block);
00172 #endif
00173 return mdp_site(idx2, ptr);
00174 }
00176 inline mdp_site operator- (int mu) {
00177 mdp_int idx2=lattice().dw[idx][mu];
00178 if(idx2==NOWHERE)
00179 error("You cannot exit from your portion of the lattice");
00180 #ifdef BLOCKSITE
00181 if((mu<BLOCKSITE) && (lattice().co[idx][mu]==0))
00182 return mdp_site(idx2, ptr, block, -1,mu);
00183 return mdp_site(idx2, ptr, block);
00184 #endif
00185 return mdp_site(idx2, ptr);
00186 }
00189 inline mdp_site hop(int i, int mu) {
00190 mdp_site y(lattice());
00191 y=(*this);
00192 while(i!=0) {
00193 if(i<0) {y=y-mu; i++;}
00194 if(i>0) {y=y+mu; i--;}
00195 }
00196 return y;
00197 }
00199 inline mdp_site operator= (mdp_vector v) {
00200 set(v.x[0],v.x[1],v.x[2],v.x[3],v.x[4],
00201 v.x[5],v.x[6],v.x[7],v.x[8],v.x[9]);
00202 return *this;
00203 }
00206 inline mdp_site operator+ (mdp_vector v) {
00207 int mu,step;
00208 mdp_site y=*this;
00209 for(mu=0; mu<lattice().ndim; mu++) {
00210 if(v.x[mu]>0) for(step=0; step<v.x[mu]; step++) y=y+mu;
00211 else for(step=0; step<-v.x[mu]; step++) y=y-mu;
00212 }
00213 return y;
00214 }
00217 inline mdp_site operator- (mdp_vector v) {
00218 int mu,step;
00219 mdp_site y=*this;
00220 for(mu=0; mu<lattice().ndim; mu++) {
00221 if(v.x[mu]>0) for(step=0; step<v.x[mu]; step++) y=y-mu;
00222 else for(step=0; step<-v.x[mu]; step++) y=y+mu;
00223 }
00224 return y;
00225 }
00227 inline int operator() (int mu) {
00228 return lattice().co[idx][mu];
00229 }
00230 void operator= (int *x) {
00231 int ndim=lattice().ndim;
00232 idx=x[0];
00233 for(int mu=1; mu<ndim; mu++) idx=idx*lattice().nx[mu]+x[mu];
00234 idx=lattice().local(idx);
00235 if(idx==NOWHERE) {
00236 bool print=mdp.print;
00237 mdp.print=true;
00238 mdp << "Warning message from ME=" << ME << ":\n";
00239 mdp << "You assigned a site that is not here!\n";
00240 mdp.print=print;
00241 }
00242 }
00246 void set(int x0, int x1=0, int x2=0, int x3=0, int x4=0,
00247 int x5=0, int x6=0, int x7=0, int x8=0, int x9=0) {
00248 int ndim=lattice().ndim;
00249 idx=x0;
00250 if(ndim>1) idx=idx*lattice().nx[1]+x1;
00251 if(ndim>2) idx=idx*lattice().nx[2]+x2;
00252 if(ndim>3) idx=idx*lattice().nx[3]+x3;
00253 if(ndim>4) idx=idx*lattice().nx[4]+x4;
00254 if(ndim>5) idx=idx*lattice().nx[5]+x5;
00255 if(ndim>6) idx=idx*lattice().nx[6]+x6;
00256 if(ndim>7) idx=idx*lattice().nx[7]+x7;
00257 if(ndim>8) idx=idx*lattice().nx[8]+x8;
00258 if(ndim>9) idx=idx*lattice().nx[9]+x9;
00259 idx=lattice().local(idx);
00260 if(idx==NOWHERE) {
00261 bool print=mdp.print;
00262 mdp.print=true;
00263 mdp << "Warning message from ME=" << ME << ":\n";
00264 mdp << "You assigned a site that is not here!\n";
00265 mdp.print=print;
00266 }
00267 }
00268 int operator==(int *x) {
00269 int ndim=lattice().ndim;
00270 int is_it=1;
00271 for(int mu=0; mu<ndim; mu++)
00272 if(x[mu]!=lattice().co[idx][mu]) is_it=0;
00273 return is_it;
00274 }
00275 int operator!=(int *x) {
00276 return !(*this == x);
00277 }
00279 int is_equal(int x0, int x1=0, int x2=0, int x3=0, int x4=0,
00280 int x5=0, int x6=0, int x7=0, int x8=0, int x9=0) {
00281 int ndim=lattice().ndim;
00282 int is_it=1;
00283 if((ndim>0) && (x0!=lattice().co[idx][0])) is_it=0;
00284 if((ndim>1) && (x1!=lattice().co[idx][1])) is_it=0;
00285 if((ndim>2) && (x2!=lattice().co[idx][2])) is_it=0;
00286 if((ndim>3) && (x3!=lattice().co[idx][3])) is_it=0;
00287 if((ndim>4) && (x4!=lattice().co[idx][4])) is_it=0;
00288 if((ndim>5) && (x5!=lattice().co[idx][5])) is_it=0;
00289 if((ndim>6) && (x6!=lattice().co[idx][6])) is_it=0;
00290 if((ndim>7) && (x7!=lattice().co[idx][7])) is_it=0;
00291 if((ndim>8) && (x8!=lattice().co[idx][8])) is_it=0;
00292 if((ndim>9) && (x9!=lattice().co[idx][9])) is_it=0;
00293 return is_it;
00294 }
00298 inline friend mdp_int site2binary(mdp_site x) {
00299 int mu, a=0;
00300 for(mu=0; mu<x.lattice().ndim; mu++) {
00301 #ifdef CHECK_ALL
00302 if(fabs(0.5-x(mu))>1) error("site2binary");
00303 #endif
00304 a+=(0x1 << mu)*x(mu);
00305 }
00306 return a;
00307 }
00311 friend int on_which_process(mdp_lattice &a, int x0, int x1, int x2, int x3,
00312 int x4, int x5, int x6, int x7, int x8, int x9) {
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 }