-1
$\begingroup$

I basically want to make a C code for the same but I am not able to figure out how to index the array to store correlation values in terms of distance, because the distance can be non integer in the 2d Potts model. If anyone has done the spin-spin pair correlation please answer me? To make it more clear i have posted my correlation code. I beleive this is somewhat the way @LonelyProf who commented on it asked me to do. Could you please check where Iam going wrong in building this code.

void correlation(int trial,int step)
{
   FILE *fp;
   char basenm[256];
   sprintf(basenm,"corr_potts_q_%lf_r_%lf_trial_%d_T_%lf_N_%d_MCstep_%d.txt",q,R,trial,T,N,step);
   fp=fopen(basenm,"w");
   double dr=0.1,r2;
   int dx,dy,hL=N/2.;
   int NBIN=(hL/dr)+1,bin;
   double c1[NBIN],c2[NBIN],c3[NBIN],c[NBIN];
  for(int t=1;t<=(q+R);t++) 
   { 
     for(int i=0;i<N-1;i++)
      {
         for(int j=0;j<N-1;j++)
          {
            for(int k=i+1;k<N;k++)
             {
               for(int l=j+1;l<N;l++)
                {
                  dx=i-k;
                  dy=j-l;
                  if(dx>hL)dx-=N;
                  else
                    if(dx<-hL)dx+=N;
                  if(dy>hL)dy-=N;
                  else
                     if(dy<-hL)dy+=N;
                  r2=dx*dx+dy*dy;
                  bin=(int)sqrt(r2)/dr;
          //printf("%d \n",bin);
                  c3[bin]=c3[bin]+codelta(t,potts[i][j])*codelta(t,potts[k][l]);
                  c1[bin]=c2[bin]+codelta(t,potts[i][j]);
                  c2[bin]=c2[bin]+codelta(t,potts[k][l]);
                 //printf("%lf %lf %lf \n",c3[bin],c1[bin],c2[bin]);               
                }

             }

          }


      }


  } 
  for(int i=0;i<NBIN;i++)
     { 
       c3[i]=c3[i]/(N*N);
       c2[i]=c2[i]/(N*N);
       c1[i]=c1[i]/(N*N); 
       c[i]=c3[i]-c1[i]*c2[i];
       c[i]=c[i]/(q+R);
        printf("%lf %lf %lf \n",i*dr,(c3[i]-c1[i]*c2[i]/q+R),c[i]);
     //  fprintf(fp,"%d %lf \n",i,c[i]);
     }

 fclose(fp);

}

By the way q+R is the number of states in potts model and N is the length of lattice .I believe rest of it is understandable.

$\endgroup$
  • $\begingroup$ I've provided an answer, because I believe that I understand what you are asking. However, I see that others are voting to close your question, on the grounds that it is unclear. You might like to edit your question, to make it more clear (for example, explaining what the problem with non-integer distances is). I also note that physics.stackexchange.com/questions/169442/… is closely related, although not an exact duplicate. $\endgroup$ – user197851 Jun 20 '19 at 10:25
  • $\begingroup$ The question is clear. People who do not understand it because do not have experience of computational physics could simply skip it, instead of voting for closing. $\endgroup$ – GiorgioP Jun 20 '19 at 11:03
  • 1
    $\begingroup$ @GiorgioP The question has nothing to do with physics. It asks how to store the computed data in the computer. $\endgroup$ – Norbert Schuch Jun 20 '19 at 11:12
  • 2
    $\begingroup$ I'm voting to close this question as off-topic because it's about writing/debugging code and not physics. $\endgroup$ – Kyle Kanos Jun 20 '19 at 11:39
  • 1
    $\begingroup$ @GiorgioP I don't care about the answer posted; people answer blatantly off topic questions all the time. The existence of an answer does not make the question suddenly on topic. An off topic question is off topic, regardless of posted answers. That is always the case on this (and all SE) sites. $\endgroup$ – Kyle Kanos Jun 21 '19 at 0:49
1
$\begingroup$

There's an almost-duplicate question here which you should read because it contains several useful points. The gist of that answer is that you can make life easy for yourself by only considering correlations in the horizontal and vertical directions (for which, of course, you have equally spaced lattice points). However I want to go a bit further in answering your specific point. Throughout, I'm assuming rotational invariance (so, no symmetry-breaking external fields, for instance).

It's simplest to explain if we assume that you accumulate the correlations with full 2D indexing; i.e. calculate $\langle \sigma(\vec{r}_0) \sigma(\vec{r}_0+\vec{r})\rangle$ where $\sigma$ is the Potts spin value and both $\vec{r}_0$ and $\vec{r}$ are 2D lattice vectors. This quantity would be averaged over spatial origins $\vec{r}_0$, but not (initially, at least) over different directions of the displacement vector $\vec{r}$. So you accumulate it as a function of both indices which constitute $\vec{r}$. As you noted, the length of this vector can take non-integer values (e.g. $\sqrt{2}$ for next-nearest neighbour spins). Technically, the correlation function is only defined for these lattice vectors, so this issue is built into the model! However, it makes physical sense to do some averaging and interpolation, and to imagine that there is an underlying continuous correlation function that we can estimate from these results.

Obviously, it makes sense to average the correlation function over symmetry-related lattice vectors $\vec{r}$, so as to get one overall average for each distinct distance $r=|\vec{r}|$.

At small $r$, the discrete values of nearest, next-nearest, and next-next-nearest neighbour distances is unavoidable. In many cases, though, we are interested in the behaviour of the correlation function at large $r$, and here we can take advantage of the fact that the number of lattice points lying within a circular shell $r \ldots r+\Delta r$ increases with $r$ (in 2D it will be approximately proportional to the area of the shell $2\pi r \Delta r$). So it is quite common to choose a suitable "bin width" $\Delta r$ and combine (average) the results for all the lattice points $\vec{r}$ lying within each bin. So we do a discretization of the separation distance $r$, and end up with a function defined at regular intervals of $r$. The choice of bin size is a trade-off between resolution and statistics in each bin, but something of the order of one lattice spacing might be a good place to start.

With a bit of thought you can incorporate this averaging and discretization into the simulation program, and if your system size is very large, you might avoid some storage and data handling issues by doing that. But it may still be practical to do it the way I described above.

There is another approach (via 2D fast Fourier transforms) which also, in its simplest form, deals with the 2D-indexed data, and you can follow that up by averaging in the way discussed above, but this is probably not important in the context of your question.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ But does this code also works for potts model?I mean the guy who answered in that post has given a code which works with rotational symmetry of ising model. So just wanted to confirm it with you $\endgroup$ – Damn111 Jun 21 '19 at 7:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.