testFmmAlgorithmProc.cpp 5.71 KB
Newer Older
1 2 3 4 5 6 7
// /!\ Please, you must read the license at the bottom of this page

#include <iostream>

#include <stdio.h>
#include <stdlib.h>

8
#include "../Src/Utils/FTic.hpp"
9

10 11
#include "../Src/Containers/FOctree.hpp"
#include "../Src/Containers/FList.hpp"
12

13
#include "../Src/Components/FSimpleLeaf.hpp"
14

15
#include "../Src/Utils/F3DPosition.hpp"
16

17 18 19 20 21
#include "../Src/Components/FFmaParticle.hpp"
#include "../Src/Components/FTestParticle.hpp"
#include "../Src/Components/FTestCell.hpp"
#include "../Src/Components/FTestKernels.hpp"
#include "../Src/Extenssions/FExtendPhysicalValue.hpp"
22

23
#include "../Src/Core/FFmmAlgorithmThreadProc.hpp"
berenger-bramas's avatar
berenger-bramas committed
24 25
#include "../Src/Core/FFmmAlgorithmThread.hpp"

26

27
#include "../Src/Files/FFmaLoader.hpp"
28

29
#include "../Src/Components/FBasicKernels.hpp"
30

31
// Compile by : g++ testFmmAlgorithmProc.cpp ../Src/Utils/FAssertable.cpp ../Src/Utils/FDebug.cpp ../Src/Utils/FTrace.cpp -lgomp -fopenmp -O2 -o testFmmAlgorithmProc.exe
32 33 34 35 36 37 38

/** This program show an example of use of
  * the fmm basic algo
  * it also check that each particles is impacted each other particles
  */


39 40 41 42 43 44 45 46 47 48
/** Fmb class has to extend {FExtendForces,FExtendPotential,FExtendPhysicalValue}
  * Because we use fma loader it needs {FFmaParticle}
  */
class TestParticle : public FTestParticle, public FExtendPhysicalValue {
public:
};

class FTestCellPar : public FTestCell{
public :
    void addCell(const FTestCellPar& other){
berenger-bramas's avatar
berenger-bramas committed
49
        //setDataUp(this->getDataUp() + other.getDataUp());
50 51 52 53 54
        setDataDown(this->getDataDown() + other.getDataDown());
    }
};


55 56 57 58 59 60 61 62
// Simply create particles and try the kernels
int main(int argc, char ** argv){
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
    //////////////////////////////////////////////////////////////

    const int NbLevels = 10;//10;
    const int SizeSubLevels = 3;//3
63 64
    const char* const defaultFilename = "testLoaderFMA.fma"; //../../Data/ "testLoaderFMA.fma" "testFMAlgorithm.fma" Sphere.fma
    const char* filename;
65 66
    FTic counter;

67 68 69 70 71 72 73 74 75
    if(argc == 1){
        std::cout << "You have to give a .fma file in argument.\n";
        std::cout << "The program will try a default file : " << defaultFilename << "\n";
        filename = defaultFilename;
    }
    else{
        filename = argv[1];
        std::cout << "Opening : " << filename << "\n";
    }
76

77 78 79 80 81
    FFmaLoader<TestParticle> loader(filename);
    if(!loader.isValide()){
        std::cout << "Loader Error, " << filename << " is missing\n";
        return 1;
    }
82 83 84 85

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

86
    std::cout << "Creating " << loader.getNumberOfParticles() << " particles ..." << std::endl;
87
    counter.tic();
88 89

    TestParticle* particles = new TestParticle[loader.getNumberOfParticles()];
90
    TestParticle* particlesValide = new TestParticle[loader.getNumberOfParticles()];
91 92 93

    for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
        loader.fillParticle(&particles[idxPart]);
94
        particlesValide[idxPart] = particles[idxPart];
95 96 97 98 99 100 101 102
    }

    counter.tac();
    std::cout << "Done  " << "(" << counter.elapsed() << "s)." << std::endl;

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

103
    FOctree<TestParticle, FTestCellPar, FSimpleLeaf, NbLevels, SizeSubLevels> tree(loader.getBoxWidth(),loader.getCenterOfBox());
104

berenger-bramas's avatar
berenger-bramas committed
105 106
    FOctree<TestParticle, FTestCellPar, FSimpleLeaf, NbLevels, SizeSubLevels> treeValide(loader.getBoxWidth(),loader.getCenterOfBox());

107 108 109 110 111
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    std::cout << "Inserting particles ..." << std::endl;
    counter.tic();
112
    for(long idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
113
        tree.insert(&particles[idxPart]);
114
        treeValide.insert(&particlesValide[idxPart]);
115 116 117 118 119 120 121 122 123 124
    }
    counter.tac();
    std::cout << "Done  " << "(" << counter.elapsed() << "s)." << std::endl;

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    std::cout << "Working on particles ..." << std::endl;
    counter.tic();

125
    FTestKernels<TestParticle, FTestCellPar, NbLevels> kernels;
berenger-bramas's avatar
berenger-bramas committed
126

127
    FFmmAlgorithmThreadProc<FTestKernels, TestParticle, FTestCellPar, FSimpleLeaf, NbLevels, SizeSubLevels> algo(&tree,&kernels,argc,argv);
128 129
    algo.execute();

berenger-bramas's avatar
berenger-bramas committed
130 131 132
    FFmmAlgorithmThread<FTestKernels, TestParticle, FTestCellPar, FSimpleLeaf, NbLevels, SizeSubLevels> algoValide(&treeValide,&kernels);
    algoValide.execute();

133 134 135 136 137 138
    counter.tac();
    std::cout << "Done  " << "(" << counter.elapsed() << "s)." << std::endl;

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

berenger-bramas's avatar
berenger-bramas committed
139
    algo.ValidateFMMAlgoProc(&treeValide);
140 141 142 143 144 145

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////
    std::cout << "Deleting particles ..." << std::endl;
    counter.tic();
    delete [] particles;
146
    delete [] particlesValide;
147 148 149 150 151 152 153 154 155 156
    counter.tac();
    std::cout << "Done  " << "(" << counter.elapsed() << "s)." << std::endl;
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    return 0;
}


// [--LICENSE--]