NFFT Logo 3.1.1 API Reference

func_rec_2d.c

00001 #include <math.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include "util.h"
00005 #include "nfft3.h"
00006 
00007 
00008 
00009 double norm2( int k0, int k1)
00010 {
00011   return sqrt(k0*k0+k1*k1);
00012 }
00013 
00014 void func_rec_2d( int my_N,
00015                   int M,
00016                   int iter,
00017                   int my_M,
00018                   double border_eps,
00019                   double mu, double c, char *fout_name) 
00020 {
00021 
00022   int j,j0,j1,k,k0,k1,l;                      /* nodes, freqencies iterations       */
00023   nfct_plan  my_cplan, my_other_cplan;        /* plans for the two dimensional nfct */
00024   infct_plan my_icplan;                       /* plan for the two dimensional infct */
00025 
00026   FILE *fp_in, *fp_out;                       /* input/output file                  */
00027   double min_x, max_x, min_y, max_y;
00028 
00029 
00030   printf( "N=%d  M=%d  iter=%d  rec_M=%d  b_eps=%f  mu=%f  c=%f  fout=%s\n", 
00031       my_N, M, iter, my_M, border_eps, mu, c, fout_name);
00032 
00033   nfct_init_2d(&my_cplan, my_N, my_N, M);
00034 
00035   /* initialise my_icplan, specific */
00036   infct_init_advanced( &my_icplan, &my_cplan, CGNE | PRECOMPUTE_DAMP);
00037 
00038 
00039   /* init nodes */
00040   if( (fp_in = fopen( "input.dat", "r")) == NULL)
00041   {
00042     fprintf( stderr, "%s\n", "Can't open inputfile");
00043     exit( 1);
00044   }
00045       
00046   
00047   fscanf( fp_in, "%le %le %le", &my_cplan.x[0], &my_cplan.x[1], &my_icplan.y[0]);
00048   min_x = max_x = my_cplan.x[0];
00049   min_y = max_y = my_cplan.x[1];
00050 
00051   j=0;
00052   for( j = 1; j < my_cplan.M_total; j++)
00053   {
00054       fscanf(fp_in, "%le %le %le", &my_cplan.x[2*j+0],
00055                                    &my_cplan.x[2*j+1],
00056                                    &my_icplan.y[j]);
00057 
00058       min_x = (my_cplan.x[2*j+0] < min_x) ? my_cplan.x[2*j+0] : min_x;
00059       max_x = (my_cplan.x[2*j+0] > max_x) ? my_cplan.x[2*j+0] : max_x;
00060 
00061       min_y = (my_cplan.x[2*j+1] < min_y) ? my_cplan.x[2*j+1] : min_y;
00062       max_y = (my_cplan.x[2*j+1] > max_y) ? my_cplan.x[2*j+1] : max_y;
00063   }
00064 
00065   fclose(fp_in);
00066 
00067   // scale input
00068   double diff_x = 1.0/(0.5-2*border_eps) * (max_x - min_x);
00069   double diff_y = 1.0/(0.5-2*border_eps) * (max_y - min_y);
00070   for( j = 0; j < my_cplan.M_total; j++)
00071   {
00072     my_cplan.x[2*j+0] = border_eps + (my_cplan.x[2*j+0] - min_x) / diff_x;
00073     my_cplan.x[2*j+1] = border_eps + (my_cplan.x[2*j+1] - min_y) / diff_y;
00074   }
00075 
00076   /* precompute psi */
00077   if(my_cplan.nfct_flags & PRE_PSI)
00078     nfct_precompute_psi( &my_cplan);
00079 
00080 
00082   if(my_icplan.flags & PRECOMPUTE_DAMP)
00083     {
00084       for(k0=0;k0<my_cplan.N[0];k0++)
00085         for(k1=0;k1<my_cplan.N[1];k1++)
00086         {
00087           my_icplan.w_hat[k0*my_cplan.N[1]+k1]=
00088             nfft_modified_multiquadric( mu, c, norm2(k0, k1));
00089         }
00090       
00091 //      for(k0=0;k0<my_cplan.N[0];k0++)
00092 //        my_icplan.w_hat[k0*my_cplan.N[1]+my_cplan.N[1]-1]=0;
00093 //      for(k1=0;k1<my_cplan.N[1];k1++)
00094 //        my_icplan.w_hat[(my_cplan.N[0]-1)*my_cplan.N[1]+k1]=0;    
00095     }
00096 
00097 
00098   /* init some guess */
00099   for( k = 0; k < my_cplan.N_total; k++)
00100     my_icplan.f_hat_iter[k] = 0.0;
00101 
00102   /* inverse trafo */  
00103   infct_before_loop( &my_icplan);
00104   for(l=0; l < iter; l++)
00105   { 
00106       infct_loop_one_step( &my_icplan);
00107       //fprintf( stderr, "%e\n", my_icplan.dot_r_iter);
00108   }
00109 
00110 
00111 
00112   nfct_init_2d( &my_other_cplan, my_N, my_N, my_M * my_M);
00113   
00114   // nodes on grid
00115   for( j0 = 0; j0 < my_M; j0++) 
00116     for( j1 = 0; j1 < my_M; j1++)
00117     {
00118       my_other_cplan.x[2*(j0 * my_M + j1) + 0] = 
00119   border_eps + ((double)((double)j0*((0.5-2*border_eps)/my_M)));
00120       my_other_cplan.x[2*(j0 * my_M + j1) + 1] = 
00121   border_eps + ((double)((double)j1*((0.5-2*border_eps)/my_M)));
00122     }
00123 
00124 
00125   /* precompute psi */
00126   if( my_other_cplan.nfct_flags & PRE_PSI)
00127     nfct_precompute_psi( &my_other_cplan);
00128 
00129   NFFT_SWAP_double( my_icplan.f_hat_iter, my_other_cplan.f_hat);
00130   nfct_trafo( &my_other_cplan);
00131   NFFT_SWAP_double( my_icplan.f_hat_iter, my_other_cplan.f_hat);
00132 
00133   
00134   if( (fp_out = fopen( fout_name, "w")) == NULL)
00135   {
00136     fprintf( stderr, "%s\n", "Can't open outputfile");
00137     exit( 2);
00138   }
00139     
00140   for( j = 0; j < my_other_cplan.M_total; j++)
00141   {
00142     fprintf( fp_out, "%f  %f  %f\n", my_other_cplan.x[2*j], 
00143                                      my_other_cplan.x[2*j+1],
00144                                      my_other_cplan.f[j]);
00145   }
00146 
00147   fclose( fp_out);
00148 
00149   infct_finalize( &my_icplan);  
00150   nfct_finalize( &my_cplan);
00151   nfct_finalize( &my_other_cplan);
00152 }
00153 
00154 
00155 
00156 int main(int argc, char **argv)
00157 {
00158   func_rec_2d( atoi( argv[1]), /* N_0 */
00159                atoi( argv[2]), /* M   */
00160                atoi( argv[3]), /* iterations */
00161                atoi( argv[4]), /* rec_M */
00162                atof( argv[5]), /* border_eps */
00163                atof( argv[6]), /* mu (multiquadric damping factors) */
00164                atof( argv[7]), /*  c (multiquadric damping factors) */
00165                      argv[8]   /* output filename */
00166                );
00167 
00168   return 1;
00169 }

Generated on 17 Aug 2009 by Doxygen 1.5.3