/**************************************/ /* Spectral method to calculate the */ /* scalar thermal conductivity and */ /* shear viscosity. */ /* */ /* Version 1.1 Jan.22, 1999 */ /* Ju Li (MIT) */ /**************************************/ #include "smile.h" static void realft(double data[], unsigned long n, int isign); static void four1(double data[], unsigned long nn, int isign); void realft (double data[], unsigned long n, int isign) { void four1(double data[], unsigned long nn, int isign); unsigned long i,i1,i2,i3,i4,np3; double c1=0.5,c2,h1r,h1i,h2r,h2i; double wr,wi,wpr,wpi,wtemp,theta; theta=3.141592653589793/(n>>1); if (isign == 1) { c2 = -0.5; four1(data,n>>1,1); } else { c2=0.5; theta = -theta; } wtemp=sin(0.5*theta); wpr = -2.0*wtemp*wtemp; wpi=sin(theta); wr=1.0+wpr; wi=wpi; np3=n+3; for (i=2;i<=(n>>2);i++) { i4=1+(i3=np3-(i2=1+(i1=i+i-1))); h1r=c1*(data[i1]+data[i3]); h1i=c1*(data[i2]-data[i4]); h2r = -c2*(data[i2]+data[i4]); h2i=c2*(data[i1]-data[i3]); data[i1]=h1r+wr*h2r-wi*h2i; data[i2]=h1i+wr*h2i+wi*h2r; data[i3]=h1r-wr*h2r+wi*h2i; data[i4] = -h1i+wr*h2i+wi*h2r; wr=(wtemp=wr)*wpr-wi*wpi+wr; wi=wi*wpr+wtemp*wpi+wi; } if (isign == 1) { data[1] = (h1r=data[1])+data[2]; data[2] = h1r-data[2]; } else { data[1]=c1*((h1r=data[1])+data[2]); data[2]=c1*(h1r-data[2]); four1(data,n>>1,-1); } /* Added by Ju Li: factor of 2/n is */ /* multiplied for inverse realft(); */ if (isign == -1) for (i=1; i<=n; i++) data[i] *= 2./n; return; } /* end realft() */ #define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr void four1(double data[], unsigned long nn, int isign) { unsigned long n,mmax,m,j,istep,i; double wtemp,wr,wpr,wpi,wi,theta; double tempr,tempi; n=nn << 1; j=1; for (i=1;i i) { SWAP(data[j],data[i]); SWAP(data[j+1],data[i+1]); } m=n >> 1; while (m >= 2 && j > m) { j -= m; m >>= 1; } j += m; } mmax=2; while (n > mmax) { istep=mmax << 1; theta=isign*(6.28318530717959/mmax); wtemp=sin(0.5*theta); wpr = -2.0*wtemp*wtemp; wpi=sin(theta); wr=1.0; wi=0.0; for (m=1;mn/2)?n/2:SMILE_FREQ_CHANNELS; for (j=0; j<3; j++) { printf ("Loading in \"%s\"...\n", fn_flux[w][j]); fseek (current[j], -n*sizeof(double), SEEK_END); fread (&data[1], sizeof(double), n, current[j]); fclose (current[j]); printf ("raw data loaded, FFT this current...\n"); if (n>=2) realft (data, n, 1); printf ("FFT complete, getting the power spectrum...\n"); /* get rid of net drift */ data[1] = 0.; if (n>=2) data[2] = data[2]*data[2]/n; for (i=3; i<=n; i+=2) { data[i] = (data[i]*data[i]+data[i+1]*data[i+1])/n; data[i+1] = 0.; } /* divide by 2 to be the single sided integral */ for (i=0; i=2) realft (data, n, -1); printf ("complete, accumulate to counters.\n\n"); if (j==0) { /* search approx. location corr. turns negative */ for (ncorr=0; (ncorr0.); ncorr++); corr = (double *) malloc((ncorr+1)*sizeof(double)); corr--; for (i=1; i<=ncorr; i++) corr[i] = data[i]/3.; } else for (i=1; i<=ncorr; i++) corr[i] += data[i]/3.; } /* loop over principle directions */ /* look for the first point where the */ /* correlation function turns negative */ for (i=1; (i<=ncorr)&&(corr[i]>0.); i++); for (total=0.,l=1; l/kT^2V = %f W/M/K/ps,\n": " V/kT = %e Pa,\n", corr[1]/delta); fprintf (output, " the first dip in correlation function occurs at %.3f ps\n", i*delta); if (w == SMILE_HEAT) fprintf (output, " and by then the thermal conductivity is %.3f mW/m/K.\n\n", 1000*total); else fprintf (output, " and by then the shear viscosity is %.3f uPa.second.\n\n", 1000000*total); /* save the correlation function */ corr_output = fopen (fn_corr[w], "w+"); for (i=1; i<=ncorr; i++) fprintf (corr_output, "%.4f %e\n", (i-1)*delta, corr[i]); fclose (corr_output); /* save the power spectrum */ freq_output = fopen (fn_freq[w], "w+"); for (i=0; i