testOctreeFuncteur.cpp 2.8 KB
Newer Older
1
// See LICENCE file at project root
2 3 4 5 6 7 8

#include <iostream>

#include <cstdio>
#include <cstdlib>
#include <time.h>

9 10
#include "Utils/FTic.hpp"
#include "Utils/FParameters.hpp"
11

12 13
#include "Containers/FOctree.hpp"
#include "Containers/FVector.hpp"
14

15 16
#include "Utils/FAssert.hpp"
#include "Utils/FPoint.hpp"
17

18 19 20
#include "Components/FBasicParticleContainer.hpp"
#include "Components/FBasicCell.hpp"
#include "Components/FSimpleLeaf.hpp"
21

22
#include "Files/FRandomLoader.hpp"
23

24
#include "Utils/FParameterNames.hpp"
25

26 27 28 29 30
/**
* In this file we show how to use octree's functeur
*/

int main(int argc, char ** argv){
31 32 33 34
    FHelpDescribeAndExit(argc, argv,
                         "Show how to use an octree functeur (only the code is interesting)",
                         FParameterDefinitions::NbParticles);

35
    typedef double FReal;
36
    typedef FBasicCell CellClass;
37
    typedef FBasicParticleContainer<FReal,0,FReal>      ContainerClass;
38 39
    typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
    typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
40 41 42 43 44
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable is useless to execute.\n";
    std::cout << ">> It is only interesting to wath the code to understand\n";
    std::cout << ">> how to use the Octree\n";
    //////////////////////////////////////////////////////////////
45
    const FSize NbPart = FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, FSize(2000));
46 47
    FTic counter;

48
    FRandomLoader<FReal> loader(NbPart, 1, FPoint<FReal>(0.5,0.5,0.5), 1);
49 50 51 52 53 54
    OctreeClass tree(10, 3, loader.getBoxWidth(), loader.getCenterOfBox());

    // -----------------------------------------------------
    std::cout << "Creating and inserting " << NbPart << " particles ..." << std::endl;
    counter.tic();

55
    {
56
        FPoint<FReal> particlePosition;
57
        for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
58 59 60 61
            loader.fillParticle(&particlePosition);
            tree.insert(particlePosition);
        }
    }
62 63 64 65 66 67 68 69

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

    // Call a function on each leaf
    long nbParticles = 0;
    tree.forEachLeaf([&](LeafClass* leaf){
70
        nbParticles += leaf->getSrc()->getNbParticles();
71 72 73 74 75
    });
    std::cout << "There are " << nbParticles << " particles " << std::endl;

    // Call a function on each cell
    long nbCells = 0;
76
    tree.forEachCell([&nbCells](CellClass* /*cell*/){
77 78 79 80
        nbCells += 1;
    });
    std::cout << "There are " << nbCells << " cells " << std::endl;

81
    // To get cell and particles at leaf level
82
    tree.forEachCellLeaf([&](CellClass* /*cell*/, LeafClass* /*leaf*/){
83 84
    });

85 86 87 88 89
    return 0;
}