testOctreeIter.cpp 4.37 KB
Newer Older
1
// ===================================================================================
2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.  
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info". 
// "http://www.gnu.org/licenses".
15
// ===================================================================================
16 17 18

#include <iostream>

19 20
#include <cstdio>
#include <cstdlib>
21 22 23
#include <time.h>


24
#include "../../Src/Utils/FParameters.hpp"
25

26 27 28
#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Containers/FVector.hpp"
#include "../../Src/Components/FSimpleLeaf.hpp"
29

BRAMAS Berenger's avatar
BRAMAS Berenger committed
30
#include "../../Src/Utils/FAssert.hpp"
BRAMAS Berenger's avatar
BRAMAS Berenger committed
31
#include "../../Src/Utils/FPoint.hpp"
32

33
#include "../../Src/Components/FBasicParticleContainer.hpp"
34
#include "../../Src/Components/FBasicCell.hpp"
35

36
#include "../../Src/Utils/FTic.hpp"
berenger-bramas's avatar
berenger-bramas committed
37

38 39
/**
* In this file we show how to use octree with iteration
berenger-bramas's avatar
berenger-bramas committed
40
* This is a good example to understand FOctree::Iterator.
41
*/
berenger-bramas's avatar
berenger-bramas committed
42

43
int main(int argc, char ** argv){
44 45 46
    typedef FBasicParticleContainer<0>     ContainerClass;
    typedef FSimpleLeaf< ContainerClass >                     LeafClass;
    typedef FOctree< FBasicCell, ContainerClass , LeafClass >  OctreeClass;
47 48 49 50 51 52
    ///////////////////////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 octree iterator.\n";
    //////////////////////////////////////////////////////////////

53 54 55 56 57
    const int NbLevels = FParameters::getValue(argc,argv,"-h", 9);
    const int NbSubLevels = FParameters::getValue(argc,argv,"-sh", 3);
    const int NbPart = FParameters::getValue(argc,argv,"-nb", 2000000);

    FTic counterTime;
58

BRAMAS Berenger's avatar
BRAMAS Berenger committed
59
    srand48 ( 1 ); // volontary set seed to constant
60
    // -----------------------------------------------------
61

BRAMAS Berenger's avatar
BRAMAS Berenger committed
62
    OctreeClass tree(NbLevels, NbSubLevels, 1.0, FPoint(0.5,0.5,0.5));
63

64 65 66 67
    // -----------------------------------------------------
    std::cout << "Creating and inserting " << NbPart << " particles ..." << std::endl;
    counterTime.tic();
    {
68
        FPoint particle;
69
        for(long idxPart = 0 ; idxPart < NbPart ; ++idxPart){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
70
            particle.setPosition(FReal(drand48()),FReal(drand48()),FReal(drand48()));
71 72 73 74 75
            tree.insert(particle);
        }
    }
    counterTime.tac();
    std::cout << "Done  " << "(" << counterTime.elapsed() << "s)." << std::endl;
76

77 78
    // -----------------------------------------------------
    {
79
        std::cout << "Itering on Cells ..." << std::endl;
berenger-bramas's avatar
berenger-bramas committed
80
        counterTime.tic();
81 82 83 84 85 86 87 88

        OctreeClass::Iterator octreeIterator(&tree);
        octreeIterator.gotoBottomLeft();
        for(int idxLevel = NbLevels - 1 ; idxLevel >= 1 ; --idxLevel ){
            int counter = 0;
            do{
                ++counter;
                //counter += octreeIterator.getCurrentList()->getSize();
89
            } while(octreeIterator.moveRight());           
90 91 92
            octreeIterator.moveUp();
            octreeIterator.gotoLeft();
            std::cout << "Cells at this level " << counter << " ...\n";
93
        }
berenger-bramas's avatar
berenger-bramas committed
94 95
        counterTime.tac();
        std::cout << "Done  " << "(" << counterTime.elapsed() << "s)." << std::endl;
96 97 98 99 100
    }
    // -----------------------------------------------------
    {
        std::cout << "Itering on particles fast ..." << std::endl;
        counterTime.tic();
101

102 103 104 105 106 107 108 109 110 111
        OctreeClass::Iterator octreeIterator(&tree);
        octreeIterator.gotoBottomLeft();

        OctreeClass::Iterator avoidGoLeft(octreeIterator);

        for(int idx = 0 ; idx < NbLevels - 1; ++idx ){
            do{
            } while(octreeIterator.moveRight());
            avoidGoLeft.moveUp();
            octreeIterator = avoidGoLeft;
112
        }
113 114 115 116
        counterTime.tac();
        std::cout << "Done  " << "(" << counterTime.elapsed() << "s)." << std::endl;
    }
    // -----------------------------------------------------
117

118
    return 0;
119 120 121
}


122