testCompareIOTree.cpp 6.9 KB
Newer Older
1
// See LICENCE file at project root
2 3 4 5 6 7

#include <iostream>

#include <cstdio>
#include <cstdlib>

8 9
#include "Utils/FTic.hpp"
#include "Utils/FParameters.hpp"
10

11 12
#include "Containers/FOctree.hpp"
#include "Containers/FVector.hpp"
13

14
#include "Files/FTreeIO.hpp"
15

16 17
#include "Kernels/Spherical/FSphericalCell.hpp"
#include "Components/FSimpleLeaf.hpp"
18

19 20
#include "Components/FSimpleLeaf.hpp"
#include "Kernels/P2P/FP2PParticleContainer.hpp"
21

22
#include "Utils/FParameterNames.hpp"
23

24 25
// Simply create particles and try the kernels
int main(int argc, char ** argv){
26 27 28 29 30 31 32 33

    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
                         );

34
    typedef double FReal;
35
    typedef FSphericalCell<FReal>                 CellClass;
36
    typedef FP2PParticleContainer<FReal>         ContainerClass;
37

38 39
    typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
    typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
40 41 42
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable has to be used to compare two trees.\n";
    //////////////////////////////////////////////////////////////
43
    const int DevP = FParameters::getValue(argc,argv,FParameterDefinitions::SHDevelopment.options, 8);
44 45 46

    // -----------------------------------------------------
    CellClass::Init(DevP, true);
47 48
    OctreeClass tree1(5, 3, 0, FPoint<FReal>());
    OctreeClass tree2(5, 3, 0, FPoint<FReal>());
49 50

    // -----------------------------------------------------
51 52
    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");
53 54
    std::cout << "Compare tree " << filename1 << " and " << filename2 << std::endl;

55 56
    FTreeIO<FReal>::Load<OctreeClass, CellClass, LeafClass, ContainerClass >(filename1, tree1);
    FTreeIO<FReal>::Load<OctreeClass, CellClass, LeafClass, ContainerClass >(filename2, tree2);
57 58 59 60

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

64
        OctreeClass::Iterator octreeIterator2(&tree2);
65 66 67 68 69 70 71 72 73 74
        octreeIterator2.gotoBottomLeft();

        int nbLeaves = 0;

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

75
            if( octreeIterator1.getCurrentListSrc()->getNbParticles() != octreeIterator2.getCurrentListSrc()->getNbParticles()){
76
                std::cout << "Number of particles different on leaf " << octreeIterator1.getCurrentGlobalIndex() <<
77 78
                             " tree1 " << octreeIterator1.getCurrentListSrc()->getNbParticles() <<
                             " tree2 " << octreeIterator2.getCurrentListSrc()->getNbParticles() << std::endl;
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
            }

            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
101
        OctreeClass::Iterator octreeIterator1(&tree1);
102 103
        octreeIterator1.gotoBottomLeft();

104
        OctreeClass::Iterator octreeIterator2(&tree2);
105 106 107 108
        octreeIterator2.gotoBottomLeft();

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

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

118
                FReal cumul = 0;
119
                for(int idx = 0; idx < FSphericalCell<FReal>::multipole_t::getSize(); ++idx){
120 121
                    cumul += FMath::Abs( cell1->getMultipoleData().get()[idx].imag() - cell2->getMultipoleData().get()[idx].imag() );
                    cumul += FMath::Abs( cell1->getMultipoleData().get()[idx].real() - cell2->getMultipoleData().get()[idx].real() );
122 123 124 125 126 127
                }
                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;
128
                for(int idx = 0; idx < FSphericalCell<FReal>::local_expansion_t::getSize(); ++idx){
129 130
                    cumul += FMath::Abs( cell1->getLocalExpansionData().get()[idx].imag() - cell2->getLocalExpansionData().get()[idx].imag() );
                    cumul += FMath::Abs( cell1->getLocalExpansionData().get()[idx].real() - cell2->getLocalExpansionData().get()[idx].real() );
131 132 133 134 135
                }
                if( cumul > 0.00001 || FMath::IsNan(cumul)){
                    std::cout << "Local Data are different. Cumul " << cumul << " at level " << idxLevel
                              << " index is " << octreeIterator1.getCurrentGlobalIndex() << std::endl;
                }
136

137 138 139 140
                nbCells += 1;
                if( octreeIterator1.moveRight() ){
                    if( !octreeIterator2.moveRight() ){
                        std::cout << "Not the same number of leaf, tree2 end before tree1\n";
141 142
                        break;
                    }
143 144 145 146 147 148 149 150 151
                }
                else {
                    if( octreeIterator2.moveRight() ){
                        std::cout << "Not the same number of leaf, tree1 end before tree2\n";
                    }
                    break;
                }
            } while(true);

152 153 154 155 156 157 158 159 160 161 162 163 164 165
            octreeIterator1.moveUp();
            octreeIterator1.gotoLeft();

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

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

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

    return 0;
}