Changeset 705 in Sophya for trunk


Ignore:
Timestamp:
Jan 21, 2000, 5:57:26 PM (26 years ago)
Author:
ansari
Message:

modifs Test FFTServer - Reza 21/01/2000

File:
1 edited

Legend:

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

    r460 r705  
    22#include <iostream.h>
    33
    4 #include "fftserver.h"
    5 #include "nobjmgr.h"
     4#include "fftpserver.h"
     5#include "sambainit.h"
    66
    7 extern "C" {
    8   void tfft(vector<string>& args);
     7#include "timing.h"
     8
     9
     10template <class T>
     11inline T module(complex<T> c)
     12{
     13  return (sqrt(c.real()*c.real()+c.imag()*c.imag()));
     14}
     15
     16template <class T>
     17void TestFFTS(T seuil, FFTServerInterface & ffts)
     18{
     19 
     20  int num=16;
     21  int i;
     22
     23  T fact = 1./num;
     24
     25  TVector< complex<T> > inc(num), bkc(num), difc(num);
     26  TVector< T > in(num), ino(num), bk(num),dif(num);
     27  TVector< complex<T> > outc(num);
     28 
     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.);
    933  }
     34 
     35
     36  cout << " Testing FFTServer " << ffts.getInfo() << endl;
     37
     38  cout << "Input / L = " << num << endl;
     39  in.Print(0,0,num,0,num);
     40  cout << endl;
     41
     42  cout << " >>>> Testing FFTPackServer "  << endl;
     43  FFTPackServer fftp;
     44  cout << " Testing FFTPackServer "  << endl;
     45  fftp.fftf(in.NElts(), in.Data());
     46  in /= (num/2.);
     47  cout << " fftp.fftf(in.NElts(), in.Data()) FORWARD: " << endl;
     48  in.Print(0,0,num,0,num);
     49  cout << endl;
     50  fftp.fftb(in.NElts(), in.Data());
     51  cout << " fftp.fftb(in.NElts(), in.Data()) BACKWARD: " << endl;
     52  in.Print(0,0,num,0,num);
     53  cout << endl;
     54
     55  in = ino;
     56
     57  cout << "\n ----  Testing FFT(T, complex<T>) ---- " << endl;
     58
     59  ffts.FFTForward(in, outc);
     60  cout << " outc , NElts= " << outc.NElts() << endl;
     61  outc.Print(0,0,num,0,num);
     62
     63  ffts.FFTBackward(outc, bk);
     64  cout << " bk , NElts= " << bk.NElts() << endl;
     65  bk.Print(0,0,num,0,num);
     66 
     67  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;
     76 
     77  cout << "\n ----  Testing FFT(complex<T>, complex<T>) ---- " << endl;
     78  ffts.FFTForward(inc, outc);
     79  cout << " outc , NElts= " << outc.NElts() << endl;
     80  outc.Print(0,0,num,0,num);
     81
     82  ffts.FFTBackward(outc, bkc);
     83  cout << " bkc , NElts= " << bkc.NElts() << endl;
     84  bkc.Print(0,0,num,0,num);
     85 
     86  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
    1096
    1197int main(int narg, char* arg)
    1298{
    13 vector<string> a;
    14 string str = "nopiapp";
    15 a.push_back(str);
    1699
    17 cout << "Appel de tfft ( " << a[0] << " ) " << endl;
    18 tfft(a);
    19 exit(0);
     100  PeidaInit();
     101  InitTim();   // Initializing the CPU timer
     102  FFTPackServer ffts;
     103
     104
     105  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);
     116  }
     117  catch(PThrowable exc ) {
     118    cerr << "TestFFT-main() , Catched exception: " << exc.Msg() << endl;
     119  }
     120  catch(std::exception ex) {
     121    cerr << "TestFFT-main() , Catched exception ! " << (string)(ex.what()) << endl;
     122  }
     123  /*
     124  catch(...) {
     125    cerr << "TestFFT-main() , Catched ... exception ! " << endl;
     126  }
     127  */
     128  PrtTim("End of tfft ");
    20129}
    21 
    22 void tfft(vector<string>& args)
    23 {
    24  
    25   int num=30;
    26   double tper = 2./num;
    27   /*  Vector* inp = new Vector(num);
    28   Vector* outp = new Vector(num);
    29 
    30   Vector& in = (*inp);
    31   Vector& out = (*outp);*/
    32 
    33   complex<double>* in = new complex<double>[num];
    34  
    35  
    36   for (int i=0; i<num ; i++){ in[i] = complex<double> (cos(i*3.141596*tper),cos(3.*i*3.141596*tper));}
    37   cout << "Input / L = " << num << endl;
    38   for (int i=0; i<num ; i++){
    39     if (i%8 == 0) cout << "\n" << i << "-" << i+7 << " : " ;
    40     cout << in[i] << " " ;
    41     }
    42   cout << endl;
    43 
    44   FFTServer ffts;
    45   ffts.fftf(num,in);
    46 
    47   cout << "Output / L = " << num << endl;
    48   for (int i=0; i<num ; i++){
    49     if (i%8 == 0) cout << "\n" << i << "-" << i+7 << " : " ;
    50     cout << in[i] << " " ;
    51     }
    52   cout << endl;
    53 
    54   /* if (args[0] == "nopiapp")  return;
    55    NamedObjMgr omg;
    56    string nom;
    57    nom = "vin";
    58    omg.AddObj(&in, nom);
    59    nom = "vout";
    60    omg.AddObj(&out, nom);*/
    61 
    62 }
Note: See TracChangeset for help on using the changeset viewer.