Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

void forces(double *x, double *xm,int N, double box, double *f, double * E)

{
int i,k,j;
double xr[3],r06i,r2i,r02i,r2,r2m,ff,ffm;
double rc=3.0 ;
double Erc_offs;
r2=rc*rc;
r2i=1./r2;
r02i=r0*r0*r2i;
r06i=r02i*r02i*r02i;
Erc_offs=eps*4*r06i*(r06i-1);
for(i=0;i<N-1;i++)
{
for(k=i+1;k<N;k++)
{
r2=0.;
for(j=0;j<3;j++)
{
xr[j]=x[3*i+j]-x[3*k+j];
xr[j]-=round(xr[j]/box)*box;
r2+=xr[j]*xr[j];
}
if(r2<rc2)
{
r2i=1./r2;
r02i=r0*r0*r2i;
r06i=r02i*r02i*r02i;
ff=eps*48*r2i*r06i*(r06i-0.5);
for(j=0;j<3;j++)
{
f[3*i+j]+=ff*xr[j];
f[3*k+j]-=ff*xr[j];
}

E[0]+=eps*4*r06i*(r06i-1)-Erc_offs;
}
}
}
}

You might also like