testFmbAlgorithm.cpp 5.13 KB
Newer Older
berenger-bramas's avatar
berenger-bramas committed
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"
berenger-bramas's avatar
berenger-bramas committed
9

10 11
#include "../Src/Containers/FOctree.hpp"
#include "../Src/Containers/FList.hpp"
berenger-bramas's avatar
berenger-bramas committed
12

13
#include "../Src/Components/FFmaParticle.hpp"
14 15
#include "../Src/Extensions/FExtendForces.hpp"
#include "../Src/Extensions/FExtendPotential.hpp"
berenger-bramas's avatar
berenger-bramas committed
16

17 18
#include "../Src/Components/FBasicCell.hpp"
#include "../Src/Fmb/FExtendFmbCell.hpp"
berenger-bramas's avatar
berenger-bramas committed
19

20 21 22
#include "../Src/Core/FFmmAlgorithm.hpp"
#include "../Src/Core/FFmmAlgorithmThread.hpp"
#include "../Src/Core/FFmmAlgorithmThreadUs.hpp"
berenger-bramas's avatar
berenger-bramas committed
23

24
#include "../Src/Components/FSimpleLeaf.hpp"
25 26
#include "../Src/Components/FBasicKernels.hpp"

27

28
#include "../Src/Fmb/FFmbKernels.hpp"
berenger-bramas's avatar
berenger-bramas committed
29

berenger-bramas's avatar
berenger-bramas committed
30

31
#include "../Src/Files/FFmaLoader.hpp"
berenger-bramas's avatar
berenger-bramas committed
32

33
// With openmp : g++ testFmbAlgorithm.cpp ../Src/Utils/FDebug.cpp ../Src/Utils/FTrace.cpp -lgomp -fopenmp -O2 -o testFmbAlgorithm.exe
34
// icpc -openmp -openmp-lib=compat testFmbAlgorithm.cpp ../Src/Utils/FAssertable.cpp ../Src/Utils/FDebug.cpp -O2 -o testFmbAlgorithm.exe
berenger-bramas's avatar
berenger-bramas committed
35 36 37

/** This program show an example of use of
  * the fmm basic algo
38
  * it also check that eachh particles is little or longer
berenger-bramas's avatar
berenger-bramas committed
39 40 41 42
  * related that each other
  */


43
/** Fmb class has to extend {FExtendForces,FExtendPotential,FExtendPhysicalValue}
44
  * Because we use fma loader it needs {FFmaParticle}
berenger-bramas's avatar
berenger-bramas committed
45
  */
46
class FmbParticle : public FFmaParticle, public FExtendForces, public FExtendPotential {
berenger-bramas's avatar
berenger-bramas committed
47 48 49
public:
};

berenger-bramas's avatar
berenger-bramas committed
50 51 52
/** Custom cell
  *
  */
berenger-bramas's avatar
berenger-bramas committed
53
class FmbCell : public FBasicCell, public FExtendFmbCell {
berenger-bramas's avatar
berenger-bramas committed
54 55 56 57
public:
};


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

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

70 71 72 73 74 75 76 77 78
    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";
    }
berenger-bramas's avatar
berenger-bramas committed
79

80
    FFmaLoader<FmbParticle> loader(filename);
81 82 83 84
    if(!loader.isValide()){
        std::cout << "Loader Error, " << filename << " is missing\n";
        return 1;
    }
berenger-bramas's avatar
berenger-bramas committed
85

86
    // -----------------------------------------------------
berenger-bramas's avatar
berenger-bramas committed
87

88
    FOctree<FmbParticle, FmbCell, FSimpleLeaf, NbLevels, SizeSubLevels> tree(loader.getBoxWidth(),loader.getCenterOfBox());
berenger-bramas's avatar
berenger-bramas committed
89

90
    // -----------------------------------------------------
berenger-bramas's avatar
berenger-bramas committed
91

92
    std::cout << "Creating & Inserting " << loader.getNumberOfParticles() << " particles ..." << std::endl;
93
    counter.tic();
berenger-bramas's avatar
berenger-bramas committed
94

95
    for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
96 97 98
        FmbParticle particleToFill;
        loader.fillParticle(particleToFill);
        tree.insert(particleToFill);
99
    }
berenger-bramas's avatar
berenger-bramas committed
100

101
    counter.tac();
102
    std::cout << "Done  " << "(@Creating and Inserting Particles = " << counter.elapsed() << "s)." << std::endl;
berenger-bramas's avatar
berenger-bramas committed
103

104
    // -----------------------------------------------------
berenger-bramas's avatar
berenger-bramas committed
105

106
    std::cout << "Working on particles ..." << std::endl;
107
    counter.tic();
berenger-bramas's avatar
berenger-bramas committed
108

berenger-bramas's avatar
berenger-bramas committed
109
    FFmbKernels<FmbParticle, FmbCell, NbLevels> kernels(loader.getBoxWidth());
110 111
    //FBasicKernels<FmbParticle, FmbCell, NbLevels> kernels;
    //FFmmAlgorithm FFmmAlgorithmThread FFmmAlgorithmThreadUs
112
    FFmmAlgorithmThread<FFmbKernels, FmbParticle, FmbCell, FSimpleLeaf, NbLevels, SizeSubLevels> algo(&tree,&kernels);
113
    algo.execute();
berenger-bramas's avatar
berenger-bramas committed
114

115
    counter.tac();
116
    std::cout << "Done  " << "(@Algorithm = " << counter.elapsed() << "s)." << std::endl;
berenger-bramas's avatar
berenger-bramas committed
117

118 119 120
    { // get sum forces&potential
        FReal potential = 0;
        F3DPosition forces;
121
        FOctree<FmbParticle, FmbCell, FSimpleLeaf, NbLevels, SizeSubLevels>::Iterator octreeIterator(&tree);
122 123
        octreeIterator.gotoBottomLeft();
        do{
124
            FList<FmbParticle>::ConstBasicIterator iter(*octreeIterator.getCurrentListTargets());
125
            while( iter.isValide() ){
126 127
                potential += iter.value().getPotential() * iter.value().getPhysicalValue();
                forces += iter.value().getForces();
berenger-bramas's avatar
berenger-bramas committed
128

129 130
                //printf("x = %e y = %e z = %e \n",iter.value()->getPosition().getX(),iter.value()->getPosition().getY(),iter.value()->getPosition().getZ());
                //printf("\t fx = %e fy = %e fz = %e \n",iter.value()->getForces().getX(),iter.value()->getForces().getY(),iter.value()->getForces().getZ());
131

132 133
                //printf("\t\t Sum Forces ( %e , %e , %e)\n",
                //forces.getX(),forces.getY(),forces.getZ());
134

135
                iter.gotoNext();
136 137
            }
        } while(octreeIterator.moveRight());
berenger-bramas's avatar
berenger-bramas committed
138

139 140 141
        std::cout << "Foces Sum  x = " << forces.getX() << " y = " << forces.getY() << " z = " << forces.getZ() << std::endl;
        std::cout << "Potential = " << potential << std::endl;
    }
berenger-bramas's avatar
berenger-bramas committed
142

143
    // -----------------------------------------------------
berenger-bramas's avatar
berenger-bramas committed
144

berenger-bramas's avatar
berenger-bramas committed
145

146
    return 0;
berenger-bramas's avatar
berenger-bramas committed
147 148 149 150
}


// [--LICENSE--]