utestOctree.cpp 4.26 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
#include "FUTester.hpp"

BRAMAS Berenger's avatar
BRAMAS Berenger committed
18 19 20 21
#include "Containers/FOctree.hpp"
#include "Containers/FBlockAllocator.hpp"
#include "Containers/FVector.hpp"
#include "Components/FSimpleLeaf.hpp"
22

BRAMAS Berenger's avatar
BRAMAS Berenger committed
23 24
#include "Utils/FAssert.hpp"
#include "Utils/FPoint.hpp"
25

BRAMAS Berenger's avatar
BRAMAS Berenger committed
26 27
#include "Components/FBasicParticleContainer.hpp"
#include "Components/FBasicCell.hpp"
28

BRAMAS Berenger's avatar
BRAMAS Berenger committed
29
#include "Utils/FTic.hpp"
30 31 32 33 34 35 36 37 38 39

/**
  In this test we create a lot of different octree by using various height and subheigt
  then we insert particle in all leaf and we test that all leaves
  and all cells has been created.
  */


/** this class test the octree container */
class TestOctree : public FUTester<TestOctree> {
40
    typedef double FReal;
41
    typedef FBasicCell                   CellClass;
42
    typedef FBasicParticleContainer<FReal,0,FReal>      ContainerClass;
43

44 45
    typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
    typedef FOctree<FReal, CellClass, ContainerClass , LeafClass , FBasicBlockAllocator<CellClass> >  OctreeClass;
46 47 48 49 50 51 52 53 54 55

    // test size
    void TestAll(){
        const FReal BoxWidth = 1.0;
        const FReal BoxCenter = 0.5;

        // We try for many levels
        for(int idxHeight = 2 ; idxHeight < 8 ; ++idxHeight){

            // Compute the number of leaves for a tree of this height
berenger-bramas's avatar
berenger-bramas committed
56
            const int NbSmallBoxesPerSide = (1 << (idxHeight-1));
57 58 59 60 61 62 63 64
            const FReal SmallBoxWidth = BoxWidth / FReal(NbSmallBoxesPerSide);
            const FReal SmallBoxWidthDiv2 = SmallBoxWidth / 2;

            const int NbPart = NbSmallBoxesPerSide * NbSmallBoxesPerSide * NbSmallBoxesPerSide;

            // For each level we try many sub-levels
            for(int idxSub = 1 ; idxSub < idxHeight ; ++idxSub){

65
                OctreeClass tree(idxHeight, idxSub, BoxWidth, FPoint<FReal>(BoxCenter,BoxCenter,BoxCenter));
66 67 68 69 70

                // fill the tree
                for(int idxX = 0 ; idxX < NbSmallBoxesPerSide ; ++idxX){
                    for(int idxY = 0 ; idxY < NbSmallBoxesPerSide ; ++idxY){
                        for(int idxZ = 0 ; idxZ < NbSmallBoxesPerSide ; ++idxZ){
71
                            const FPoint<FReal> pos(FReal(idxX)*SmallBoxWidth + SmallBoxWidthDiv2,
72 73
                                                       FReal(idxY)*SmallBoxWidth + SmallBoxWidthDiv2,
                                                       FReal(idxZ)*SmallBoxWidth + SmallBoxWidthDiv2);
74
                            tree.insert(pos);
75 76 77 78 79 80 81 82 83 84 85 86
                        }
                    }
                }

                // test all cells
                OctreeClass::Iterator octreeIterator(&tree);
                octreeIterator.gotoBottomLeft();
                int nbCell = NbPart;
                for(int idxLevel = idxHeight - 1 ; idxLevel >= 1 ; --idxLevel ){
                    MortonIndex currentIndex = 0;
                    do{
                        // Morton index must increase one by one
87
                        uassert( currentIndex == octreeIterator.getCurrentGlobalIndex());
88 89 90
                        ++currentIndex;
                    } while(octreeIterator.moveRight());
                    // Then number of cells must be divided by 8 at each level
91
                    uassert(currentIndex == nbCell);
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
                    nbCell /= 8;

                    octreeIterator.moveUp();
                    octreeIterator.gotoLeft();
                }
            }
        }
    }

    // set test
    void SetTests(){
        AddTest(&TestOctree::TestAll,"Test Octree");
    }
};

// You must do this
TestClass(TestOctree)