![]() |
|
00001 00009 #include <stdlib.h> 00010 #include <stdio.h> 00011 #include <string.h> 00012 #include <math.h> 00013 #include <time.h> 00014 00015 #include "fields_fastsum.h" 00016 00017 int main(int argc, char **argv) 00018 { 00019 int j,k,t; 00020 int N; 00021 int n; 00022 int m; 00023 int p; 00024 fields_fastsum_plan my_plan; 00025 double *direct; 00026 double time; 00027 double error=0.0; 00028 double norm_direct; 00029 double norm_diff; 00030 double sum_error_direct; 00031 double sum_error_diff; 00032 double eps_I; 00033 double eps_B; 00034 FILE *fid1, *fid2; 00035 00036 if (argc!=7) 00037 { 00038 printf("\nfastsum_test N n m p eps_I eps_B\n\n"); 00039 printf(" N number of nodes \n"); 00040 printf(" n expansion degree \n"); 00041 printf(" m cut-off parameter \n"); 00042 printf(" p degree of smoothness \n"); 00043 printf(" eps_I inner boundary \n"); 00044 printf(" eps_B outer boundary \n\n"); 00045 exit(-1); 00046 } 00047 else 00048 { 00049 N=atoi(argv[1]); 00050 n=atoi(argv[2]); 00051 m=atoi(argv[3]); 00052 p=atoi(argv[4]); 00053 eps_I=atof(argv[5]); 00054 eps_B=atof(argv[6]); 00055 } 00056 printf("N=%d, n=%d, m=%d, p=%d, eps_I=%g, eps_B=%g \n",N,n,m,p,eps_I,eps_B); 00057 00058 fields_fastsum_init(&my_plan, N, 0, n, m, p, eps_I, eps_B); 00059 00061 fid1=fopen("r.dat","r"); 00062 fid2=fopen("q.dat","r"); 00063 for (k=0; k<N; k++) 00064 { 00065 for (t=0; t<3; t++) 00066 { 00067 fscanf(fid1,"%le",&my_plan.r[k*3+t]); 00068 } 00069 fscanf(fid2,"%le",&my_plan.q[k]); 00070 } 00071 fclose(fid1); 00072 fclose(fid2); 00073 00075 printf("direct computation: "); fflush(NULL); 00076 time=nfft_second(); 00077 fields_fastsum_exact(&my_plan); 00078 time=nfft_second()-time; 00079 printf("%fsec\n",time); 00080 00082 direct = (double *)malloc(3*my_plan.N_total*(sizeof(complex))); 00083 for (j=0; j<my_plan.N_total; j++) 00084 for (t=0; t < 3; t++) 00085 direct[j*3+t]=my_plan.E[j*3+t]; 00086 00088 printf("fast computation: "); fflush(NULL); 00089 time=nfft_second(); 00090 fields_fastsum_precompute(&my_plan); 00091 fields_fastsum_trafo(&my_plan); 00092 time=nfft_second()-time; 00093 printf("%fsec\n",time); 00094 00096 error=0.0; 00097 sum_error_direct = 0.0; 00098 sum_error_diff = 0.0; 00099 for (j=0; j<my_plan.N_total; j++) 00100 { 00101 norm_direct = 0.0; 00102 norm_diff = 0.0; 00103 for (t=0; t < 3; t++) { 00104 norm_direct += direct[j*3+t] * direct[j*3+t]; 00105 norm_diff += (my_plan.E[j*3+t] - direct[j*3+t]) * (my_plan.E[j*3+t] - direct[j*3+t]); 00106 } 00107 sum_error_direct += norm_direct; 00108 sum_error_diff += norm_diff; 00109 norm_direct = sqrt(norm_direct); 00110 norm_diff = sqrt(norm_diff); 00111 if (fabs(norm_diff)/fabs(norm_direct)>error) 00112 error=fabs(norm_diff)/fabs(norm_direct); 00113 } 00114 printf("max relative error: %e\n",error); 00115 printf("error epsilon_2(slow,fast) (p.7): %e\n", sqrt(sum_error_diff)/sqrt(sum_error_direct)); 00116 00118 fid1=fopen("E.dat","w+"); 00119 fid2=fopen("E_direct.dat","w+"); 00120 if (fid1==NULL) 00121 { 00122 printf("Fehler!\n"); 00123 exit(-1); 00124 } 00125 for (j=0; j<N; j++) 00126 { 00127 for (t=0; t < 3; t++) { 00128 fprintf(fid1," % .16e",my_plan.E[j*3+t]); 00129 fprintf(fid2," % .16e",direct[j*3+t]); 00130 } 00131 fprintf(fid1,"\n"); 00132 fprintf(fid2,"\n"); 00133 } 00134 fclose(fid1); 00135 fclose(fid2); 00136 00138 fields_fastsum_finalize(&my_plan); 00139 00140 return 0; 00141 }