/* Metropolis Monte Carlo simulation of 2D hard dumbbells confined in a circle Cameron F. Abrams Written for the course CHE 800-002, Molecular Simulation Spring 0304 compile using "gcc -o hdb hdb.c -lm -lgsl" (assumes the GNU Scientific Library is installed) runs as "./hdisk -N -rho \ -R \ -nc \ -seed \ -dw \ -dr \ -da \ -r_0 \ -s " You must have the GNU Scientific Library installed; see the coursenotes to learn how to do this. Drexel University, Department of Chemical Engineering Philadelphia (c) 2004 */ #include #include #include #include void out_fig ( FILE * fp, double * rx, double * ry, int n, double R2 ) { int i; double R = sqrt(R2); int iR = (int)(R*300); fprintf(fp,"#FIG 3.2\n" "Landscape\n" "Center\n" "Inches\n" "Letter\n" "100.00\n" "Single\n" "-2\n" "1200 2\n"); fprintf(fp,"1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 %i %i %i %i %i %i %i %i\n",iR,iR,iR,iR,iR,iR,2*iR,iR); for (i=0;iR2) reject=1; for (j=0;(!reject)&&(j 1.0) { fprintf(stderr,"# Error: please select a weight between 0 and 1\n"); exit(-1); } s2=s2*s2; r_02=r_02*r_02; /* If N was not set by the user, calculate it based on the given values of density and radius */ if (N==-1) { N = (int)(rho*M_PI*R2); if (N%2) N--; } /* Otherwise, recompute the radius. */ else { if (N%2) N--; R2 = ((double)N)/rho/M_PI; } fprintf(stdout,"# R = %.5lf; rho = %.5lf; N = %i; r_0 = %.5lf; s = %.5lf\n", sqrt(R2),rho,N,sqrt(r_02),sqrt(s2)); /* Seed the random number generator */ gsl_rng_set(r,Seed); /* allocate the position arrays */ rx = (double*)malloc(N*sizeof(double)); ry = (double*)malloc(N*sizeof(double)); /* generate initial positions that fit inside circle with radius R and guarantee no particles overlap. */ init(rx,ry,N,R2,s2,r_02,r,fig_out); nDispAcc = nRotAcc = 0; nDispAttempt = nRotAttempt = 0; for (c=0;cR2); if (reject) noob++; } /* Second, check for overlaps with other particles */ for (j=0;(!reject)&&(j