/* An implementation of the D1Q3 model for non-ideal systems */ #include #include #include #include #include #include "mygraph.h" int xdim,xdim_init=100; double *f0=NULL,*f1=NULL,*f2=NULL,*n=NULL,*sn=NULL,*ninit=NULL,*p=NULL; double n0=1, u0=0, Amp=0.00001, omega=1; double kappa=0.1; double *dp=NULL,*j=NULL; int dpreq=0,jreq=0; int next=0,Pause=1,done=0,Repeat=1,iterations,GalileanMeasure=0; #define Pi 3.14159265358979323846264338327950288419716939937510582097 /* This is the derivative of the potential that you put into your code. This will be the main aspect of your manipulation of the code. If you want to include a delta-function, that is clearly not quite so easily achieved in c. You can either put a delta function directly into the iteration routine using an if statment (as in if (i=22) F=0.005 else F=0) or you can still use the dV(x) macro using the (i==22?0.005:0) c-construct here. Two delta function would be given by (i==22?0.005:i==44?-0.005:0)*/ /*#define dV(x) (i==xdim/4?Amp:i==3*xdim/4?-Amp:0)*/ /* Square well */ #define dV(x) (Amp*sin(2*Pi*x/xdim)) /* cos potential */ #define P(sn,dsn,ddsn) (-kappa*(sn*ddsn-dsn*dsn)) void initmem(){ /* This is a routine that initializes the memory for the different fields*/ xdim=xdim_init; f0=realloc(f0,xdim*sizeof(double)); f1=realloc(f1,xdim*sizeof(double)); f2=realloc(f2,xdim*sizeof(double)); n=realloc(n,xdim*sizeof(double)); sn=realloc(sn,xdim*sizeof(double)); ninit=realloc(ninit,xdim*sizeof(double)); p=realloc(p,xdim*sizeof(double)); dp=realloc(dp,xdim*sizeof(double)); j=realloc(j,xdim*sizeof(double)); } void iteration(){ double a,A,F,tmp,dn,dsn,ddsn,dp,ddp; int i,ip,im; /* This routine is the actual heart of the simulation. Here we calculate the macroscopic quantities of the probability density n[i] and the current, which appears as "a" in this algorithm. */ iterations++; for (i=0;i