ExaFMM 1
Fast-multipole Method for exascale systems
unit_test/poisson.cxx
Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2011 by Rio Yokota, Simon Layton, Lorena Barba
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 #include "serialfmm.h"
00023 #ifdef VTK
00024 #include "vtk.h"
00025 #endif
00026 
00027 int main() {
00028   const int k = 4;
00029   const int level = 4;
00030   const int numGrid = k * (1 << level);
00031   const int numBodies = numGrid * numGrid * numGrid;
00032   const real L = 10;
00033   std::cout << "N             : " << numBodies << std::endl;
00034   IMAGES = 0;
00035   THETA = 1 / sqrt(4);
00036   Bodies bodies(numBodies);
00037   Bodies jbodies;
00038   Cells cells, jcells;
00039   SerialFMM<Laplace> FMM;
00040   FMM.initialize();
00041   FMM.printNow = true;
00042   assert( NCRIT == k*k*k );
00043 
00044   FMM.startTimer("Set bodies   ");
00045   real dV = 8. / numBodies;
00046   for( B_iter B=bodies.begin(); B!=bodies.end(); ++B ) {
00047     int i = B-bodies.begin();
00048     int ix = i / numGrid / numGrid;
00049     int iy = (i % (numGrid*numGrid)) / numGrid;
00050     int iz = i % numGrid;
00051     B->X[0] = ix * (2. / numGrid) - 1 + 1. / numGrid;
00052     B->X[1] = iy * (2. / numGrid) - 1 + 1. / numGrid;
00053     B->X[2] = iz * (2. / numGrid) - 1 + 1. / numGrid;
00054     B->SRC = -(4 * L * L * norm(B->X) - 6 * L) * exp(-L * norm(B->X)) * dV * .25 / M_PI;
00055     B->TRG = 0;
00056   }
00057   vect X0 = 0;
00058   FMM.setX0(X0);
00059   FMM.setR0(1);
00060   FMM.stopTimer("Set bodies   ",FMM.printNow);
00061   FMM.eraseTimer("Set bodies   ");
00062 
00063   FMM.bottomup(bodies,cells);
00064   jcells = cells;
00065   FMM.startTimer("Downward     ");
00066   FMM.downward(cells,jcells);
00067   FMM.stopTimer("Downward     ",FMM.printNow);
00068   FMM.eraseTimer("Downward     ");
00069 
00070   real diff1 = 0, norm1 = 0;
00071   for( B_iter B=bodies.begin(); B!=bodies.end(); ++B ) {
00072     real exact = exp(-L * norm(B->X));
00073     diff1 += (B->TRG[0] - exact) * (B->TRG[0] - exact);
00074     norm1 += exact * exact;
00075   }
00076   std::cout << "Error         : " << std::sqrt(diff1/norm1) << std::endl;
00077 
00078   FMM.finalize();
00079 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines