testFmmAlgorithmPeriodic.cpp 6.34 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


#include <iostream>

20 21
#include <cstdio>
#include <cstdlib>
22

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

26 27
#include "../../Src/Files/FRandomLoader.hpp"

BRAMAS Berenger's avatar
BRAMAS Berenger committed
28 29
#include "../../Src/Files/FPerLeafLoader.hpp"

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

33
#include "../../Src/Components/FSimpleLeaf.hpp"
34

35 36
#include "../../Src/Components/FTestParticleContainer.hpp"

BRAMAS Berenger's avatar
BRAMAS Berenger committed
37
#include "../../Src/Utils/FPoint.hpp"
38

39 40
#include "../../Src/Components/FTestCell.hpp"
#include "../../Src/Components/FTestKernels.hpp"
41

42
#include "../../Src/Core/FFmmAlgorithmPeriodic.hpp"
43 44 45 46 47 48 49 50 51 52

/** 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 FTestCell                   CellClass;
53
    typedef FTestParticleContainer      ContainerClass;
54

55 56 57
    typedef FSimpleLeaf< ContainerClass >                     LeafClass;
    typedef FOctree< CellClass, ContainerClass , LeafClass >  OctreeClass;
    typedef FTestKernels< CellClass, ContainerClass >         KernelClass;
58

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

BRAMAS Berenger's avatar
BRAMAS Berenger committed
64
    const int NbLevels          = FParameters::getValue(argc,argv,"-h", 5);
65
    const int SizeSubLevels     = FParameters::getValue(argc,argv,"-sh", 3);
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
69 70 71 72 73 74

    FTic counter;

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

BRAMAS Berenger's avatar
BRAMAS Berenger committed
75 76 77 78
    FRandomLoader loader(NbParticles);
    //FPerLeafLoader loader(NbLevels);

    std::cout << "Creating & Inserting " << loader.getNumberOfParticles() << " particles ..." << std::endl;
79 80 81
    std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
    counter.tic();

82
    OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
83 84 85 86 87 88 89 90

    {
        FPoint particlePosition;
        for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
            loader.fillParticle(&particlePosition);
            tree.insert(particlePosition);
        }
    }
91 92 93 94 95 96 97 98 99 100 101

    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;
BRAMAS Berenger's avatar
BRAMAS Berenger committed
102
    FmmClass algo( &tree, PeriodicDeep);
103
    algo.setKernel(&kernels);
104 105 106 107 108 109 110 111
    algo.execute();

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

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

112
    { // Check that each particle has been summed with all other
113
        long long int counterNbPart = 0;
114

115 116 117 118
        tree.forEachCellLeaf([&](CellClass* cell, LeafClass* leaf){
            if(cell->getDataUp() != leaf->getSrc()->getNbParticles() ){
                    std::cout << "Problem P2M Data up = " << cell->getDataUp() <<
                                 " Size = " << leaf->getSrc()->getNbParticles() << "\n";
119 120
            }
            // we also count the number of particles.
121 122
            counterNbPart += leaf->getSrc()->getNbParticles();
        });
123

BRAMAS Berenger's avatar
BRAMAS Berenger committed
124 125 126
        if( counterNbPart != loader.getNumberOfParticles()){
            std::cout << "Problem global nb part, counter = " << counterNbPart << " created = " <<
                         loader.getNumberOfParticles() << std::endl;
127 128
        }
    }
129
    {
BRAMAS Berenger's avatar
BRAMAS Berenger committed
130 131 132
        const long repetitions = algo.theoricalRepetition();
        const long totalRepeatedBox = repetitions * repetitions * repetitions;
        std::cout << "The box is repeated " << repetitions << " there are " << totalRepeatedBox << " boxes in total\n";
BRAMAS Berenger's avatar
BRAMAS Berenger committed
133
        const long long NbParticlesEntireSystem = loader.getNumberOfParticles() * totalRepeatedBox;
134
        std::cout << "The total number of particles is "  << NbParticlesEntireSystem << "\n";
BRAMAS Berenger's avatar
BRAMAS Berenger committed
135

136
        FTreeCoordinate min, max;
137
        algo.repetitionsIntervals(&min, &max);
138
        std::cout << "Min is " << min << " Max is " << max << std::endl;
139

140 141 142
        tree.forEachLeaf([&](LeafClass* leaf){
            for(int idxPart = 0 ; idxPart < leaf->getSrc()->getNbParticles() ; ++idxPart ){
                if( NbParticlesEntireSystem - 1 != leaf->getSrc()->getDataDown()[idxPart]){
143
                    std::cout << "P2P probleme, should be " << NbParticlesEntireSystem - 1 <<
144
                                 " iter.data().getDataDown() "<< leaf->getSrc()->getDataDown()[idxPart] << std::endl;
145 146
                }
            }
147
        });
148 149
    }

BRAMAS Berenger's avatar
BRAMAS Berenger committed
150 151
    std::cout << "Test done..." << std::endl;

152 153 154 155 156 157 158
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    return 0;
}


159