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 18
#include "FUTester.hpp"

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

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

26
#include "../Src/Components/FBasicParticleContainer.hpp"
27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include "../Src/Components/FBasicCell.hpp"

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

/**
  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> {
    typedef FBasicCell                   CellClass;
41
    typedef FBasicParticleContainer<0>      ContainerClass;
42

43
    typedef FSimpleLeaf< ContainerClass >                     LeafClass;
BRAMAS Berenger's avatar
BRAMAS Berenger committed
44
    typedef FOctree<CellClass, ContainerClass , LeafClass , FBasicBlockAllocator<CellClass> >  OctreeClass;
45 46 47 48 49 50 51 52 53 54

    // 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
55
            const int NbSmallBoxesPerSide = (1 << (idxHeight-1));
56 57 58 59 60 61 62 63
            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){

64
                OctreeClass tree(idxHeight, idxSub, BoxWidth, FPoint(BoxCenter,BoxCenter,BoxCenter));
65 66 67 68 69

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

                // 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
86
                        uassert( currentIndex == octreeIterator.getCurrentGlobalIndex());
87 88 89
                        ++currentIndex;
                    } while(octreeIterator.moveRight());
                    // Then number of cells must be divided by 8 at each level
90
                    uassert(currentIndex == nbCell);
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
                    nbCell /= 8;

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

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

// You must do this
TestClass(TestOctree)