testCompareIOTree.cpp 7.29 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 19 20 21
// ===================================================================================

#include <iostream>

#include <cstdio>
#include <cstdlib>

22 23
#include "../../Src/Utils/FTic.hpp"
#include "../../Src/Utils/FParameters.hpp"
24

25 26
#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Containers/FVector.hpp"
27 28


29 30
#include "../../Src/Files/FFmaLoader.hpp"
#include "../../Src/Files/FTreeIO.hpp"
31

32 33 34
#include "../../Src/Kernels/Spherical/FSphericalCell.hpp"
#include "../../Src/Kernels/Spherical/FSphericalParticle.hpp"
#include "../../Src/Components/FSimpleLeaf.hpp"
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52



// Simply create particles and try the kernels
int main(int argc, char ** argv){
    typedef FSphericalParticle             ParticleClass;
    typedef FSphericalCell                 CellClass;
    typedef FVector<ParticleClass>         ContainerClass;

    typedef FSimpleLeaf<ParticleClass, ContainerClass >                     LeafClass;
    typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass >  OctreeClass;
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable has to be used to compare two trees.\n";
    //////////////////////////////////////////////////////////////
    const int DevP = FParameters::getValue(argc,argv,"-p", 8);

    // -----------------------------------------------------
    CellClass::Init(DevP, true);
53 54
    OctreeClass tree1(5, 3, 0, FPoint());
    OctreeClass tree2(5, 3, 0, FPoint());
55 56 57 58 59 60 61 62 63 64 65 66

    // -----------------------------------------------------
    const char* const filename1 = FParameters::getStr(argc,argv,"-f1", "tree.data");
    const char* const filename2 = FParameters::getStr(argc,argv,"-f1", "dtree.data");
    std::cout << "Compare tree " << filename1 << " and " << filename2 << std::endl;

    FTreeIO::Load<OctreeClass, CellClass, ParticleClass, ContainerClass >(filename1, tree1);
    FTreeIO::Load<OctreeClass, CellClass, ParticleClass, ContainerClass >(filename2, tree2);

    // -----------------------------------------------------
    std::cout << "Check Result\n";
    { // Check that each particle has been summed with all other
67
        OctreeClass::Iterator octreeIterator1(&tree1);
68 69
        octreeIterator1.gotoBottomLeft();

70
        OctreeClass::Iterator octreeIterator2(&tree2);
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        octreeIterator2.gotoBottomLeft();

        int nbLeaves = 0;

        do{
            if( octreeIterator1.getCurrentGlobalIndex() != octreeIterator2.getCurrentGlobalIndex()){
                std::cout << "Index is different\n";
                break;
            }

            if( octreeIterator1.getCurrentListSrc()->getSize() != octreeIterator2.getCurrentListSrc()->getSize()){
                std::cout << "Number of particles different on leaf " << octreeIterator1.getCurrentGlobalIndex() <<
                             " tree1 " << octreeIterator1.getCurrentListSrc()->getSize() <<
                             " tree2 " << octreeIterator2.getCurrentListSrc()->getSize() << std::endl;
            }

            nbLeaves += 1;

            if( octreeIterator1.moveRight() ){
                if( !octreeIterator2.moveRight() ){
                    std::cout << "Not the same number of leaf, tree2 end before tree1\n";
                    break;
                }
            }
            else {
                if( octreeIterator2.moveRight() ){
                    std::cout << "Not the same number of leaf, tree1 end before tree2\n";
                }
                break;
            }

        } while(true);

        std::cout << "There are " << nbLeaves << " leaves ...\n";
    }
    { // Ceck if there is number of NbPart summed at level 1
107
        OctreeClass::Iterator octreeIterator1(&tree1);
108 109
        octreeIterator1.gotoBottomLeft();

110
        OctreeClass::Iterator octreeIterator2(&tree2);
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
        octreeIterator2.gotoBottomLeft();

        for(int idxLevel = tree1.getHeight() - 1 ; idxLevel > 1 ; --idxLevel ){
            int nbCells = 0;
            if( idxLevel == 2 ){
                do{
                    if( octreeIterator1.getCurrentGlobalIndex() != octreeIterator2.getCurrentGlobalIndex()){
                        std::cout << "Index is different\n";
                        break;
                    }

                    const CellClass*const cell1 = octreeIterator1.getCurrentCell();
                    const CellClass*const cell2 = octreeIterator2.getCurrentCell();

                    FReal cumul = 0;
                    for(int idx = 0; idx < FSphericalCell::GetPoleSize(); ++idx){
                        cumul += FMath::Abs( cell1->getMultipole()[idx].getImag() - cell2->getMultipole()[idx].getImag() );
                        cumul += FMath::Abs( cell1->getMultipole()[idx].getReal() - cell2->getMultipole()[idx].getReal() );
                    }
                    if( cumul > 0.00001 || FMath::IsNan(cumul)){
                        std::cout << "Pole Data are different. Cumul " << cumul << " at level " << idxLevel
                                  << " index is " << octreeIterator1.getCurrentGlobalIndex() << std::endl;
                    }
                    cumul = 0;
                    for(int idx = 0; idx < FSphericalCell::GetLocalSize(); ++idx){
                        cumul += FMath::Abs( cell1->getLocal()[idx].getImag() - cell2->getLocal()[idx].getImag() );
                        cumul += FMath::Abs( cell1->getLocal()[idx].getReal() - cell2->getLocal()[idx].getReal() );
                    }
                    if( cumul > 0.00001 || FMath::IsNan(cumul)){
                        std::cout << "Local Data are different. Cumul " << cumul << " at level " << idxLevel
                                  << " index is " << octreeIterator1.getCurrentGlobalIndex() << std::endl;
                    }

                    nbCells += 1;
                    if( octreeIterator1.moveRight() ){
                        if( !octreeIterator2.moveRight() ){
                            std::cout << "Not the same number of leaf, tree2 end before tree1\n";
                            break;
                        }
                    }
                    else {
                        if( octreeIterator2.moveRight() ){
                            std::cout << "Not the same number of leaf, tree1 end before tree2\n";
                        }
                        break;
                    }
                } while(true);
            }
            octreeIterator1.moveUp();
            octreeIterator1.gotoLeft();

            octreeIterator2.moveUp();
            octreeIterator2.gotoLeft();

            std::cout << "There are " << nbCells << " cells at level " << idxLevel << " ...\n";
        }
    }

    std::cout << "Done\n";

    return 0;
}