From 32021c8d2f5588601c24dedf8ac10ee16d414a3b Mon Sep 17 00:00:00 2001
From: berenger-bramas <berenger-bramas@2616d619-271b-44dc-8df4-d4a8f33a7222>
Date: Wed, 7 Dec 2011 15:28:06 +0000
Subject: [PATCH] Add an example/test for the periodic fmm.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@256 2616d619-271b-44dc-8df4-d4a8f33a7222
---
 Tests/testFmmAlgorithmPeriodic.cpp | 147 +++++++++++++++++++++++++++++
 1 file changed, 147 insertions(+)
 create mode 100644 Tests/testFmmAlgorithmPeriodic.cpp

diff --git a/Tests/testFmmAlgorithmPeriodic.cpp b/Tests/testFmmAlgorithmPeriodic.cpp
new file mode 100644
index 000000000..b20ae58c4
--- /dev/null
+++ b/Tests/testFmmAlgorithmPeriodic.cpp
@@ -0,0 +1,147 @@
+
+// /!\ Please, you must read the license at the bottom of this page
+
+#include <iostream>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "../Src/Utils/FParameters.hpp"
+#include "../Src/Utils/FTic.hpp"
+
+#include "../Src/Containers/FOctree.hpp"
+#include "../Src/Containers/FVector.hpp"
+
+#include "../Src/Components/FSimpleLeaf.hpp"
+
+#include "../Src/Utils/F3DPosition.hpp"
+
+#include "../Src/Components/FTestParticle.hpp"
+#include "../Src/Components/FTestCell.hpp"
+#include "../Src/Components/FTestKernels.hpp"
+
+#include "../Src/Core/FFmmAlgorithmPeriodic.hpp"
+
+#include "../Src/Components/FBasicKernels.hpp"
+
+// Compile by : g++ testFmmAlgorithm.cpp ../Src/Utils/FDebug.cpp ../Src/Utils/FTrace.cpp -lgomp -fopenmp -O2 -o testFmmAlgorithm.exe
+
+/** This program show an example of use of
+  * the fmm basic algo
+  * it also check that each particles is impacted each other particles
+  */
+
+
+
+template< class ParticleClass, class CellClass, class ContainerClass>
+class FTestPeriodicKernels : public FTestKernels<ParticleClass,CellClass,ContainerClass> {
+public:
+
+    /** Before Downward */
+    void M2L(CellClass* const FRestrict pole, const CellClass* distantNeighbors[189], FTreeCoordinate [189], const int size, const int ) {
+        // The pole is impacted by what represent other poles
+        for(int idx = 0 ; idx < size ; ++idx){
+            pole->setDataDown(pole->getDataDown() + distantNeighbors[idx]->getDataUp());
+        }
+    }
+
+
+    /** After Downward */
+    void P2P(const MortonIndex ,
+             ContainerClass* const FRestrict targets, const ContainerClass* const FRestrict sources,
+             ContainerClass* const directNeighborsParticles[26], const FTreeCoordinate [26], const int size) {
+
+        // Each particles targeted is impacted by the particles sources
+        long inc = sources->getSize();
+        if(targets == sources){
+            inc -= 1;
+        }
+        for(int idx = 0 ; idx < size ; ++idx){
+            inc += directNeighborsParticles[idx]->getSize();
+        }
+
+        typename ContainerClass::BasicIterator iter(*targets);
+        while( iter.hasNotFinished() ){
+            iter.data().setDataDown(iter.data().getDataDown() + inc);
+            iter.gotoNext();
+        }
+
+    }
+};
+
+
+// Simply create particles and try the kernels
+int main(int argc, char ** argv){
+    typedef FTestParticle               ParticleClass;
+    typedef FTestCell                   CellClass;
+    typedef FVector<ParticleClass>      ContainerClass;
+
+    typedef FSimpleLeaf<ParticleClass, ContainerClass >                     LeafClass;
+    typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass >  OctreeClass;
+    typedef FTestPeriodicKernels<ParticleClass, CellClass, ContainerClass >         KernelClass;
+
+    typedef FFmmAlgorithmPeriodic<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass >     FmmClass;
+    ///////////////////////What we do/////////////////////////////
+    std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
+    //////////////////////////////////////////////////////////////
+
+    const int NbLevels      = FParameters::getValue(argc,argv,"-h", 9);
+    const int SizeSubLevels = FParameters::getValue(argc,argv,"-sh", 3);
+    const long NbPart       = FParameters::getValue(argc,argv,"-nb", 2000000);
+    const FReal FRandMax    = FReal(RAND_MAX);
+
+    FTic counter;
+
+    srand ( 1 ); // volontary set seed to constant
+
+    //////////////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////////////
+
+    OctreeClass tree(NbLevels, SizeSubLevels, 1.0, F3DPosition(0.5,0.5,0.5));
+
+    //////////////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////////////
+
+    std::cout << "Creating & Inserting " << NbPart << " particles ..." << std::endl;
+    std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
+    counter.tic();
+
+    {
+        FTestParticle particleToFill;
+        for(int idxPart = 0 ; idxPart < NbPart ; ++idxPart){
+            particleToFill.setPosition(FReal(rand())/FRandMax,FReal(rand())/FRandMax,FReal(rand())/FRandMax);
+            tree.insert(particleToFill);
+        }
+    }
+
+    counter.tac();
+    std::cout << "Done  " << "(@Creating and Inserting Particles = " << counter.elapsed() << "s)." << std::endl;
+
+    //////////////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////////////
+
+    std::cout << "Working on particles ..." << std::endl;
+    counter.tic();
+
+    // FTestKernels FBasicKernels
+    KernelClass kernels;
+    //FFmmAlgorithm FFmmAlgorithmThread
+    FmmClass algo(&tree,&kernels);
+    algo.execute();
+
+    counter.tac();
+    std::cout << "Done  " << "(@Algorithm = " << counter.elapsed() << "s)." << std::endl;
+
+    //////////////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////////////
+
+    //ValidateFMMAlgo<OctreeClass, ParticleClass, CellClass, ContainerClass, LeafClass>(&tree);
+
+    //////////////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////////////
+
+    return 0;
+}
+
+
+// [--LICENSE--]
-- 
GitLab