/* double-buffered X-windows/WIN32 packet animator */ /* compile with; */ /* gcc g2_packet.c -L/usr/X11R6/lib -lX11 -lm -lgd -lg2 */ /* or use "makemake.sh" to generate a makefile */ /* requires g2 */ /* J.R.Schmidt (2000/2006) */ #include #include #include #include #include #ifdef WIN32 #include #define WINTYPE 0 #endif #ifdef XWIN #include #define WINTYPE 1 #endif #define PI 3.1415927 double V0, dx, x, k,dk,k0, sigma, t,firstX, firstY, secondX, secondY,norm,sigma,M,factor,L; double Amp[201], potX[200], potY[200]; _Complex double phase, psi, exponential, kp, iexpt[201][1000],iexpx[201][1000]; int n, m, p, time, T, N, type, displ,mode; int dev,dev1, white, black,red; double modulus(__complex__ double X); main (int argc, char *argv[]) { if (argc < 5 || argc > 5) { printf ("\n\tThe program needs five command line parameters\n"); printf ("\t\tusage; ./packet k0 sigma type mode\n\n"); printf ("\t\tk0 is a double precision packet central wavevector\n"); printf ("\t\tsigma is the width in Fourier space, double precision (>1) \n"); printf ("\t\ttype is an integer, 0 to show psi*psi, 1 to show Re psi\n"); printf ("\t\t mode =0 for single k-vector, mode=1 for a packet. \n"); printf ("\t\texample; ./packet 2.0 3.0 1 1\n"); exit (1); } k0 = (double) atof (argv[1]); sigma = (double) atof (argv[2]); type = (int) atoi (argv[3]); mode = (int) atoi (argv[4]); if (sigma <= 0.85 || sigma > 4.0) { printf ("Bad sigma, try again\n"); exit (1); } if (type < 0 || type > 1) { printf ("Invalid wavefunction display type, try again\n"); exit (1); } if (mode < 0 || mode > 1) { printf ("Invalid wavefunction mode, try again\n"); exit (1); } /* most calculations can be taken out of the time/position loops */ /* nymber of time steps */ time = 1000; /* step starts at x=L */ L=20.0; dx = 0.04; M=2.0; /* mass/hbar */ dk=2.0*(1.0/sigma)/100.0; factor=1.414*sigma/sqrt(PI); /* sigma only appears squared after this point */ sigma=sigma*sigma; for(n=0;n<=200;n++){ k=(double)(n-100)*dk; Amp[n]=exp(-sigma*k*k/2.0); } for(n=0;n<=200;n++){ k=k0+(double)(n-100)*dk; for(T=0;T