testFmmAlgorithmPeriodic.cpp 6.84 KB
Newer Older
1
// ===================================================================================
2 3 4 5 6 7 8 9
// Logiciel initial: ScalFmm Version 0.5
// Co-auteurs : Olivier Coulaud, Bérenger Bramas.
// Propriétaires : INRIA.
// Copyright © 2011-2012, diffusé sous les termes et conditions d’une licence propriétaire.
// Initial software: ScalFmm Version 0.5
// Co-authors: Olivier Coulaud, Bérenger Bramas.
// Owners: INRIA.
// Copyright © 2011-2012, spread under the terms and conditions of a proprietary license.
10
// ===================================================================================
11 12 13 14


#include <iostream>

15 16
#include <cstdio>
#include <cstdlib>
17

18 19
#include "../../Src/Utils/FParameters.hpp"
#include "../../Src/Utils/FTic.hpp"
20

21 22
#include "../../Src/Files/FRandomLoader.hpp"

23 24
#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Containers/FVector.hpp"
25

26
#include "../../Src/Components/FSimpleLeaf.hpp"
27

BRAMAS Berenger's avatar
BRAMAS Berenger committed
28
#include "../../Src/Utils/FPoint.hpp"
29

30 31 32
#include "../../Src/Components/FTestParticle.hpp"
#include "../../Src/Components/FTestCell.hpp"
#include "../../Src/Components/FTestKernels.hpp"
33

34
#include "../../Src/Core/FFmmAlgorithmPeriodic.hpp"
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

/** This program show an example of use of
  * the fmm basic algo
  * it also check that each particles is impacted each other particles
  */


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

    typedef FSimpleLeaf<ParticleClass, ContainerClass >                     LeafClass;
    typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass >  OctreeClass;
50
    typedef FTestKernels<ParticleClass, CellClass, ContainerClass >         KernelClass;
51 52 53 54 55 56

    typedef FFmmAlgorithmPeriodic<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass >     FmmClass;
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
    //////////////////////////////////////////////////////////////

57 58
    const int NbLevels          = FParameters::getValue(argc,argv,"-h", 7);
    const int SizeSubLevels     = FParameters::getValue(argc,argv,"-sh", 3);
59 60 61 62 63 64 65 66 67 68
    const long NbParticles      = FParameters::getValue(argc,argv,"-nb", 1000);
    const int PeriodicDeep      = FParameters::getValue(argc,argv,"-per", 2);
    // choose in +x dir or -/+x dir or all dirs
    int PeriodicDirs          = (FParameters::existParameter(argc,argv,"-x")?DirMinusX:0) |
                                (FParameters::existParameter(argc,argv,"+x")?DirPlusX:0) |
                                (FParameters::existParameter(argc,argv,"-y")?DirMinusY:0) |
                                (FParameters::existParameter(argc,argv,"+y")?DirPlusY:0) |
                                (FParameters::existParameter(argc,argv,"-z")?DirMinusZ:0) |
                                (FParameters::existParameter(argc,argv,"+z")?DirPlusZ:0);
    if( PeriodicDirs == 0 ) PeriodicDirs =  AllDirs;
69 70 71 72 73 74

    FTic counter;

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

75
    std::cout << "Creating & Inserting " << NbParticles << " particles ..." << std::endl;
76 77 78
    std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
    counter.tic();

79 80 81
    FRandomLoader<ParticleClass> loader(NbParticles);
    OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
    loader.fillTree(tree);
82 83 84 85 86 87 88 89 90 91 92

    counter.tac();
    std::cout << "Done  " << "(@Creating and Inserting Particles = " << counter.elapsed() << "s)." << std::endl;

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    std::cout << "Working on particles ..." << std::endl;
    counter.tic();

    KernelClass kernels;
93 94
    FmmClass algo( &tree, PeriodicDeep, PeriodicDirs);
    algo.setKernel(&kernels);
95 96 97 98 99 100 101 102
    algo.execute();

    counter.tac();
    std::cout << "Done  " << "(@Algorithm = " << counter.elapsed() << "s)." << std::endl;

    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

103
    { // Check that each particle has been summed with all other
104
        long long int counterNbPart = 0;
105

106
        OctreeClass::Iterator octreeIterator(&tree);
107 108 109
        octreeIterator.gotoBottomLeft();
        do{
            // on each leaf we should have the same number of particles
110 111
            if(octreeIterator.getCurrentCell()->getDataUp() != octreeIterator.getCurrentListSrc()->getSize() ){
                    std::cout << "Problem P2M Data up = " << octreeIterator.getCurrentCell()->getDataUp() <<
112 113 114 115 116 117
                                 " Size = " << octreeIterator.getCurrentListSrc()->getSize() << "\n";
            }
            // we also count the number of particles.
            counterNbPart += octreeIterator.getCurrentListSrc()->getSize();
        } while(octreeIterator.moveRight());

118 119
        if( counterNbPart != NbParticles){
            std::cout << "Problem global nb part, counter = " << counterNbPart << " created = " << NbParticles << std::endl;
120 121
        }
    }
122 123 124 125 126 127 128
    {
        const FTreeCoordinate repetitions = algo.repetitions();
        const int totalRepeatedBox = repetitions.getX() * repetitions.getY() * repetitions.getZ();
        std::cout << "The box is repeated " << repetitions.getX() <<" "<< repetitions.getY()<<" "<<
                     repetitions.getZ() << " there are " << totalRepeatedBox << " boxes in total\n";
        const long long NbParticlesEntireSystem = NbParticles * totalRepeatedBox;
        std::cout << "The total number of particles is "  << NbParticlesEntireSystem << "\n";
129
        FTreeCoordinate min, max;
130
        algo.repetitionsIntervals(&min, &max);
131
        std::cout << "Min is " << min << " Max is " << max << std::endl;
132

133
        OctreeClass::Iterator octreeIterator(&tree);
134 135
        octreeIterator.gotoBottomLeft();
        do{
136
            ContainerClass::BasicIterator iter(*octreeIterator.getCurrentListTargets());
137 138

            while( iter.hasNotFinished() ){
139 140
                if( NbParticlesEntireSystem - 1 != iter.data().getDataDown()){
                    std::cout << "P2P probleme, should be " << NbParticlesEntireSystem - 1 <<
141 142 143 144 145 146 147 148
                                 " iter.data().getDataDown() "<< iter.data().getDataDown() << std::endl;
                }

                iter.gotoNext();
            }
        } while(octreeIterator.moveRight());
    }

149 150 151 152 153 154 155
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    return 0;
}


156