tt.cpp

Go to the documentation of this file.
00001 /* Kernel Independent Fast Multipole Method
00002    Copyright (C) 2004 Lexing Ying, New York University
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2, or (at your option)
00007 any later version.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00012 for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; see the file COPYING.  If not, write to the Free
00016 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017 02111-1307, USA.  */
00018 
00024 #include "fmm3d.hpp"
00025 
00026 using namespace std;
00027 
00032 int optionsCreate(const char* optionsFile, map<string,string>& options)
00033 {
00034   options.clear();
00035   ifstream fileIn(optionsFile);
00036   if(fileIn.good()==false) {
00037          cerr<<"wrong option file"<<endl;        exit(1);
00038   }
00039   string name;  fileIn>>name;
00040   while(fileIn.good()) {
00041          char content[100];      fileIn.getline(content, 99);
00042          options[name] = string(content);
00043          fileIn>>name;
00044   }
00045   fileIn.close();
00046   return 0;
00047 }
00048 
00057 int main(int argc, char** argv)
00058 {
00059   srand48( (long)time(NULL) );  //srand48( 0 );
00060   iA(argc==2);
00061   map<string,string> optionsMap;
00062   optionsCreate(argv[1], optionsMap);
00063   
00065   map<string,string>::iterator mapIdx;
00066   mapIdx = optionsMap.find("-numSrc"); assert(mapIdx!=optionsMap.end());
00068   int numSrc;  { istringstream ss((*mapIdx).second);  ss >> numSrc; }
00069   mapIdx = optionsMap.find("-numTrg"); assert(mapIdx!=optionsMap.end());
00071   int numTrg;  { istringstream ss((*mapIdx).second);  ss >> numTrg; }
00072   mapIdx = optionsMap.find("-kt"); assert(mapIdx!=optionsMap.end());
00073   /* ht = Kernel Type.  See kernel3d.hpp */
00074   int kernelType;  { istringstream ss((*mapIdx).second);  ss>>kernelType; }
00075     
00076   vector<double> tmp(2);         tmp[0] = 1;     tmp[1] = 0.25; //coefs in the kernel, work for all examples
00078   Kernel3d knl(kernelType, tmp);
00079 
00081   DblNumMat srcPos(3, numSrc);
00082   for(int i=0; i<numSrc; i++) {
00083          srcPos(0,i) = (2.0*drand48()-1.0);
00084          srcPos(1,i) = (2.0*drand48()-1.0);
00085          srcPos(2,i) = (2.0*drand48()-1.0);
00086   }
00087   DblNumMat trgPos(3, numTrg);
00088   for(int i=0; i<numTrg; i++) {
00089          trgPos(0,i) = (2.0*drand48()-1.0);
00090          trgPos(1,i) = (2.0*drand48()-1.0);
00091          trgPos(2,i) = (2.0*drand48()-1.0);
00092   }
00093 
00095   int srcDOF = knl.srcDOF();
00097   int trgDOF = knl.trgDOF();
00099   DblNumVec srcDen(srcDOF * numSrc);
00100   for(int i=0; i<numSrc; i++) {
00101          for(int d=0; d<srcDOF; d++)
00102                 srcDen(d + i*srcDOF) = drand48(); //(2.0*drand48()-1.0);
00103   }
00104   /* trgVal = target values of size trgDOF *numTrg */
00105   DblNumVec trgVal(trgDOF * numTrg);
00106   
00108   clock_t clockZero, clockOne;
00109   
00110   FMM3d* fmm = new FMM3d("fmm3d_");
00111   fmm->srcPos()=&srcPos;  fmm->srcNor()=&srcPos;
00112   fmm->trgPos()=&trgPos;
00113   fmm->center() = Point3(0,0,0); // CENTER OF THE TOPLEVEL BOX
00114   fmm->rootLevel() = 0;         // 2^(-rootlvl) is the RADIUS OF THE TOPLEVEL BOX
00115   fmm->knl() = knl;
00116   
00117   clockZero = clock();
00118   iC( fmm->setup(optionsMap) );
00119   clockOne = clock();  cout<<"fmm setup used "<<double(clockOne-clockZero)/CLOCKS_PER_SEC<<"secs "<<endl;
00120   
00122   for(int i=0; i<3; i++) {
00123          clockZero = clock();
00124          iC( fmm->evaluate(srcDen, trgVal) );
00125          clockOne = clock();  cout<<"fmm eval used "<<double(clockOne-clockZero)/CLOCKS_PER_SEC<<"secs "<<endl;
00126   }
00127   
00129   clockZero = clock();
00130   double relativeError;
00131   iC( fmm->check(srcDen, trgVal, 20, relativeError) );
00132   cout << "relative error: " << relativeError << endl;
00133   clockOne = clock();  cout<<"fmm check used "<<double(clockOne-clockZero)/CLOCKS_PER_SEC<<"sec "<<endl;
00134   
00135   delete fmm;
00136   
00137   return 0;
00138 }

Generated on Sun Dec 4 19:24:39 2005 for fmm3d by  doxygen 1.4.5