Changeset 715 in Sophya


Ignore:
Timestamp:
Feb 5, 2000, 6:21:53 PM (26 years ago)
Author:
ansari
Message:

amelioration programme test FFT, Reza 5/2/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/Tests/tfft.cc

    r705 r715  
    33
    44#include "fftpserver.h"
     5#include "fftmserver.h"
    56#include "sambainit.h"
    67
     
    1415}
    1516
     17// Max Matrix print elts
     18static int nprt = 2;
     19static int nprtfc = 8;
     20
    1621template <class T>
    17 void TestFFTS(T seuil, FFTServerInterface & ffts)
    18 {
    19  
    20   int num=16;
     22void TestFFTPack(T seuil, int num)
     23{
    2124  int i;
    22 
    2325  T fact = 1./num;
    2426
     
    2628  TVector< T > in(num), ino(num), bk(num),dif(num);
    2729  TVector< complex<T> > outc(num);
     30
     31  cout << " DBG/1 outc " << outc.NElts()  << endl;
     32  outc.ReSize(32);
     33  cout << " DBG/2 outc " << outc.NElts()  << endl;
     34  outc.ReSize(10);
     35  cout << " DBG/3 outc " << outc.NElts()  << endl;
     36  outc.ReSize(48);
     37  cout << " DBG/4 outc " << outc.NElts()  << endl;
     38
     39  for (int i=0; i<num ; i++){
     40    ino[i] = in[i] = 0.5 + cos(2*M_PI*(double)i/(double)num)
     41                         + 2*sin(4*M_PI*(double)i/(double)num);
     42    inc[i] = complex<T> (in[i], 0.);
     43  }
    2844 
    29  
    30   for (int i=0; i<num ; i++){
    31     ino[i] = in[i] = cos(2*M_PI*i/8.) + sin(2*M_PI*i/4.);
    32     inc[i] = complex<T> (in[i], 0.);
    33   }
    34  
    35 
    36   cout << " Testing FFTServer " << ffts.getInfo() << endl;
    3745
    3846  cout << "Input / L = " << num << endl;
    39   in.Print(0,0,num,0,num);
     47  in.Print(0,0,nprt,0,nprt);
    4048  cout << endl;
    4149
     
    4452  cout << " Testing FFTPackServer "  << endl;
    4553  fftp.fftf(in.NElts(), in.Data());
    46   in /= (num/2.);
     54  //  in /= (num/2.);
    4755  cout << " fftp.fftf(in.NElts(), in.Data()) FORWARD: " << endl;
    48   in.Print(0,0,num,0,num);
     56  in.Print(0,0,nprtfc,0,nprtfc);
    4957  cout << endl;
    5058  fftp.fftb(in.NElts(), in.Data());
    5159  cout << " fftp.fftb(in.NElts(), in.Data()) BACKWARD: " << endl;
    52   in.Print(0,0,num,0,num);
    53   cout << endl;
    54 
    55   in = ino;
     60  in.Print(0,0,nprt,0,nprt);
     61  cout << endl;
     62  dif = ino-in;
     63  cout << " dif , NElts= " << dif.NElts() << endl;
     64  dif.Print(0,0,nprt,0,nprt);
     65
     66  int ndiff = 0;
     67  T maxdif=0., vdif;
     68  for(i=0; i<num; i++) {
     69    vdif = fabs(dif(i));
     70    if (vdif > seuil)  ndiff++;
     71    if (vdif > maxdif) maxdif = vdif;
     72  }
     73  cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff
     74       << " MaxDiff= " << maxdif << endl;
     75
     76}
     77
     78template <class T>
     79void TestFFTS(T seuil, FFTServerInterface & ffts, int num)
     80{
     81
     82  cout <<" ===>  TestFFTS " << ffts.getInfo() << " ArrSz= " << num << endl; 
     83  int i;
     84
     85  T fact = 1.;
     86
     87  TVector< complex<T> > inc(num), bkc(num), difc(num);
     88  TVector< T > in(num), ino(num), bk(num),dif(num);
     89  TVector< complex<T> > outc(num);
     90
     91  for (int i=0; i<num ; i++){
     92    ino[i] = in[i] = 0.5 + cos(2*M_PI*(double)i/(double)num)
     93                         + 2*sin(4*M_PI*(double)i/(double)num);
     94    inc[i] = complex<T> (in[i], 0.);
     95  }
     96 
     97
     98  cout << " Testing FFTServer " << ffts.getInfo() << endl;
     99
     100  cout << "Input / L = " << num << endl;
     101  in.Print(0,0,nprt,0,nprt);
     102  cout << endl;
     103
     104  int ndiff = 0;
    56105
    57106  cout << "\n ----  Testing FFT(T, complex<T>) ---- " << endl;
    58 
    59107  ffts.FFTForward(in, outc);
    60   cout << " outc , NElts= " << outc.NElts() << endl;
    61   outc.Print(0,0,num,0,num);
     108  cout << " FourierCoefs , NElts= " << outc.NElts() << endl;
     109  outc.Print(0,0,nprtfc,0,nprtfc);
    62110
    63111  ffts.FFTBackward(outc, bk);
    64   cout << " bk , NElts= " << bk.NElts() << endl;
    65   bk.Print(0,0,num,0,num);
     112  cout << " Backward , NElts= " << bk.NElts() << endl;
     113  bk.Print(0,0,nprt,0,nprt);
    66114 
    67115  dif = bk*fact - in;
    68   cout << " dif , NElts= " << dif.NElts() << endl;
    69   dif.Print(0,0,num,0,num);
    70 
    71   int ndiff = 0;
    72   for(i=0; i<num; i++)
    73     if (fabs(dif(i)) > seuil)  ndiff++;
    74 
    75   cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff << endl;
     116  cout << " Difference , NElts= " << dif.NElts() << endl;
     117  dif.Print(0,0,nprt,0,nprt);
     118
     119  ndiff = 0;
     120  T maxdif=0., vdif;
     121  for(i=0; i<num; i++) {
     122    vdif = fabs(dif(i));
     123    if (vdif > seuil)  ndiff++;
     124    if (vdif > maxdif) maxdif = vdif;
     125  }
     126  cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff
     127       << " MaxDiff= " << maxdif << endl;
    76128 
    77129  cout << "\n ----  Testing FFT(complex<T>, complex<T>) ---- " << endl;
    78130  ffts.FFTForward(inc, outc);
    79   cout << " outc , NElts= " << outc.NElts() << endl;
    80   outc.Print(0,0,num,0,num);
     131  cout << " FourierCoef , NElts= " << outc.NElts() << endl;
     132  outc.Print(0,0,nprtfc,0,nprtfc);
    81133
    82134  ffts.FFTBackward(outc, bkc);
    83   cout << " bkc , NElts= " << bkc.NElts() << endl;
    84   bkc.Print(0,0,num,0,num);
     135  cout << " Backward , NElts= " << bkc.NElts() << endl;
     136  bkc.Print(0,0,nprt,0,nprt);
    85137 
    86138  difc = bkc*complex<T>(fact,0.) - inc;
    87   cout << " difc , NElts= " << difc.NElts() << endl;
    88   difc.Print(0,0,num,0,num);
    89 
    90   int ndiffc = 0;
    91   for(i=0; i<num; i++)
    92     if (fabs(module(difc(i))) > seuil)  ndiffc++;
    93   cout << " Difference, Seuil= " << seuil << " NDiffC= " << ndiffc << endl;
    94 }
    95 
    96 
    97 int main(int narg, char* arg)
     139  cout << " Difference , NElts= " << difc.NElts() << endl;
     140  difc.Print(0,0,nprt,0,nprt);
     141
     142  ndiff = 0;
     143  maxdif=0., vdif;
     144  for(i=0; i<num; i++) {
     145    vdif = fabs(module(difc(i)));
     146    if (vdif > seuil)  ndiff++;
     147    if (vdif > maxdif) maxdif = vdif;
     148  }
     149  cout << " Difference, Seuil= " << seuil << " NDiff= " << ndiff
     150       << " MaxDiff= " << maxdif << endl;
     151}
     152
     153
     154
     155
     156
     157int main(int narg, char* arg[])
    98158{
    99159
    100160  PeidaInit();
    101161  InitTim();   // Initializing the CPU timer
    102   FFTPackServer ffts;
    103 
     162
     163  if (narg < 4) {
     164    cout << "tfft/ args error - \n  Usage tfft size p/P/M f/d [NPrtFC NPrt] \n"
     165         << " p=FFTPackTest  P=FFTPack, M=FFTMayer, f=float, d=double " << endl;
     166    exit(0);
     167  }
     168
     169  FFTPackServer fftp;
     170  FFTMayerServer fftm;
     171
     172  int sz = atoi(arg[1]);
     173  if (narg > 4) nprtfc = atoi(arg[4]);
     174  if (narg > 5) nprt = atoi(arg[4]);
     175
     176  if (sz < 2) sz = 2;
     177  FFTServerInterface * ffts;
     178  if (*arg[2] == 'M')  ffts = fftm.Clone();
     179  else ffts = fftp.Clone();
     180
     181  float fs = 1.e-4;
     182  double ds = 1.e-6;
    104183
    105184  try {
    106   float fs = 1.e-6;
    107   double ds = 1.e-12;
    108   cout << "\n ======================================== \n"
    109        << "    ------ Testing FFTS for float ----- \n"
    110        << " ======================================== " << endl;
    111   TestFFTS(fs, ffts);
    112   cout << "\n ======================================== \n"
    113        << "    ------ Testing FFTS for double ----- \n"
    114        << " ======================================== " << endl;
    115   TestFFTS(ds, ffts);
     185    if (*arg[3] == 'd') {
     186      cout << "\n ========================================== \n"
     187           << "    ------ Testing FFTServer for double ----- \n"
     188           << " ============================================ " << endl;
     189      if (*arg[2] == 'p') TestFFTPack(ds, sz);
     190      else TestFFTS(ds, *ffts, sz);
     191    }
     192    else {
     193      cout << "\n ========================================= \n"
     194           << "    ------ Testing FFTServer for float ----- \n"
     195           << " =========================================== " << endl;
     196      if (*arg[2] == 'p') TestFFTPack(fs, sz);
     197      else TestFFTS(fs, *ffts, sz);
     198    }
    116199  }
    117200  catch(PThrowable exc ) {
    118     cerr << "TestFFT-main() , Catched exception: " << exc.Msg() << endl;
     201    cerr << "TestFFT-main() , Catched exception: \n" << exc.Msg() << endl;
    119202  }
    120203  catch(std::exception ex) {
    121204    cerr << "TestFFT-main() , Catched exception ! " << (string)(ex.what()) << endl;
    122205  }
     206
    123207  /*
    124208  catch(...) {
     
    127211  */
    128212  PrtTim("End of tfft ");
    129 }
     213  delete ffts;
     214}
Note: See TracChangeset for help on using the changeset viewer.