testCompareIOTree.cpp 7.86 KB
Newer Older
1
// ===================================================================================
2 3 4 5
// Copyright ScalFmm 2016 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.
6
//
7
// This software is governed by the CeCILL-C and LGPL licenses and
8
// abiding by the rules of distribution of free software.
9 10 11
// An extension to the license is given to allow static linking of scalfmm
// inside a proprietary application (no matter its license).
// See the main license file for more details.
12
//
13 14 15
// 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
16 17 18
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
19 20 21 22 23 24 25
// ===================================================================================

#include <iostream>

#include <cstdio>
#include <cstdlib>

26 27
#include "../../Src/Utils/FTic.hpp"
#include "../../Src/Utils/FParameters.hpp"
28

29 30
#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Containers/FVector.hpp"
31

32
#include "../../Src/Files/FTreeIO.hpp"
33

34 35
#include "../../Src/Kernels/Spherical/FSphericalCell.hpp"
#include "../../Src/Components/FSimpleLeaf.hpp"
36

37 38
#include "../../Src/Components/FSimpleLeaf.hpp"
#include "../../Src/Kernels/P2P/FP2PParticleContainer.hpp"
39

40 41
#include "../../Src/Utils/FParameterNames.hpp"

42 43
// Simply create particles and try the kernels
int main(int argc, char ** argv){
44 45 46 47 48 49 50 51

    FHelpDescribeAndExit(argc, argv,
                         "Load octrees that have been saved and compare everything from leaves to cells.\n"
                         "Using the Spherical Harmonics old kernel.",
                         FParameterDefinitions::SHDevelopment, FParameterDefinitions::InputFileOne,
                         FParameterDefinitions::InputFileTwow
                         );

52
    typedef double FReal;
53
    typedef FSphericalCell<FReal>                 CellClass;
54
    typedef FP2PParticleContainer<FReal>         ContainerClass;
55

56 57
    typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
    typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
58 59 60
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable has to be used to compare two trees.\n";
    //////////////////////////////////////////////////////////////
61
    const int DevP = FParameters::getValue(argc,argv,FParameterDefinitions::SHDevelopment.options, 8);
62 63 64

    // -----------------------------------------------------
    CellClass::Init(DevP, true);
65 66
    OctreeClass tree1(5, 3, 0, FPoint<FReal>());
    OctreeClass tree2(5, 3, 0, FPoint<FReal>());
67 68

    // -----------------------------------------------------
69 70
    const char* const filename1 = FParameters::getStr(argc,argv,FParameterDefinitions::InputFileOne.options, "tree.data");
    const char* const filename2 = FParameters::getStr(argc,argv,FParameterDefinitions::InputFileOne.options, "dtree.data");
71 72
    std::cout << "Compare tree " << filename1 << " and " << filename2 << std::endl;

73 74
    FTreeIO<FReal>::Load<OctreeClass, CellClass, LeafClass, ContainerClass >(filename1, tree1);
    FTreeIO<FReal>::Load<OctreeClass, CellClass, LeafClass, ContainerClass >(filename2, tree2);
75 76 77 78

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

82
        OctreeClass::Iterator octreeIterator2(&tree2);
83 84 85 86 87 88 89 90 91 92
        octreeIterator2.gotoBottomLeft();

        int nbLeaves = 0;

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

93
            if( octreeIterator1.getCurrentListSrc()->getNbParticles() != octreeIterator2.getCurrentListSrc()->getNbParticles()){
94
                std::cout << "Number of particles different on leaf " << octreeIterator1.getCurrentGlobalIndex() <<
95 96
                             " tree1 " << octreeIterator1.getCurrentListSrc()->getNbParticles() <<
                             " tree2 " << octreeIterator2.getCurrentListSrc()->getNbParticles() << std::endl;
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
            }

            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
119
        OctreeClass::Iterator octreeIterator1(&tree1);
120 121
        octreeIterator1.gotoBottomLeft();

122
        OctreeClass::Iterator octreeIterator2(&tree2);
123 124 125 126
        octreeIterator2.gotoBottomLeft();

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

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

136
                FReal cumul = 0;
137
                for(int idx = 0; idx < FSphericalCell<FReal>::GetPoleSize(); ++idx){
138 139 140 141 142 143 144 145
                    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;
146
                for(int idx = 0; idx < FSphericalCell<FReal>::GetLocalSize(); ++idx){
147 148 149 150 151 152 153
                    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;
                }
154

155 156 157 158
                nbCells += 1;
                if( octreeIterator1.moveRight() ){
                    if( !octreeIterator2.moveRight() ){
                        std::cout << "Not the same number of leaf, tree2 end before tree1\n";
159 160
                        break;
                    }
161 162 163 164 165 166 167 168 169
                }
                else {
                    if( octreeIterator2.moveRight() ){
                        std::cout << "Not the same number of leaf, tree1 end before tree2\n";
                    }
                    break;
                }
            } while(true);

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
            octreeIterator1.moveUp();
            octreeIterator1.gotoLeft();

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

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

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

    return 0;
}