testFmmAlgorithmPeriodic.cpp 6.98 KB
Newer Older
1
// ===================================================================================
2 3 4 5 6
// 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
7 8
// abiding by the rules of distribution of free software.
//
9 10 11 12
// 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.
13
// "http://www.cecill.info".
14
// "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
#include "../../Src/Utils/FParameterNames.hpp"

46 47 48 49 50 51 52 53
/** 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){
54 55 56 57 58
    FHelpDescribeAndExit(argc, argv,
                         "Test FMM periodic algorithm by counting the nb of interactions each particle receive.",
                         FParameterDefinitions::OctreeHeight, FParameterDefinitions::OctreeSubHeight,
                         FParameterDefinitions::NbParticles, FParameterDefinitions::PeriodicityNbLevels);

59
    typedef double FReal;
60
    typedef FTestCell                   CellClass;
61
    typedef FTestParticleContainer<FReal>      ContainerClass;
62

63 64
    typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
    typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
65
    typedef FTestKernels< CellClass, ContainerClass >         KernelClass;
66

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

72 73 74 75
    const int NbLevels          = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeHeight.options, 5);
    const int SizeSubLevels     = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeSubHeight.options, 3);
    const long NbParticles      = FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, 1000);
    const int PeriodicDeep      = FParameters::getValue(argc,argv,FParameterDefinitions::PeriodicityNbLevels.options, 2);
76
    // choose in +x dir or -/+x dir or all dirs
77 78 79 80 81 82

    FTic counter;

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

83
    FRandomLoader<FReal> loader(NbParticles);
BRAMAS Berenger's avatar
BRAMAS Berenger committed
84 85 86
    //FPerLeafLoader loader(NbLevels);

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

90
    OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
91 92

    {
93
        FPoint<FReal> particlePosition;
94
        for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
95 96 97 98
            loader.fillParticle(&particlePosition);
            tree.insert(particlePosition);
        }
    }
99 100 101 102 103 104 105 106 107 108 109

    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
110
    FmmClass algo( &tree, PeriodicDeep);
111
    algo.setKernel(&kernels);
112 113 114 115 116 117 118 119
    algo.execute();

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

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

120
    { // Check that each particle has been summed with all other
121
        long long int counterNbPart = 0;
122

123
        tree.forEachCellLeaf([&](CellClass* cell, LeafClass* leaf){
124 125
            if(cell->getMultipoleData().get() != leaf->getSrc()->getNbParticles() ){
                    std::cout << "Problem P2M Data up = " << cell->getMultipoleData().get() <<
126
                                 " Size = " << leaf->getSrc()->getNbParticles() << "\n";
127 128
            }
            // we also count the number of particles.
129 130
            counterNbPart += leaf->getSrc()->getNbParticles();
        });
131

BRAMAS Berenger's avatar
BRAMAS Berenger committed
132 133 134
        if( counterNbPart != loader.getNumberOfParticles()){
            std::cout << "Problem global nb part, counter = " << counterNbPart << " created = " <<
                         loader.getNumberOfParticles() << std::endl;
135 136
        }
    }
137
    {
BRAMAS Berenger's avatar
BRAMAS Berenger committed
138 139 140
        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
141
        const long long NbParticlesEntireSystem = loader.getNumberOfParticles() * totalRepeatedBox;
142
        std::cout << "The total number of particles is "  << NbParticlesEntireSystem << "\n";
BRAMAS Berenger's avatar
BRAMAS Berenger committed
143

144
        FTreeCoordinate min, max;
145
        algo.repetitionsIntervals(&min, &max);
146
        std::cout << "Min is " << min << " Max is " << max << std::endl;
147

148
        tree.forEachLeaf([&](LeafClass* leaf){
149
            for(FSize idxPart = 0 ; idxPart < leaf->getSrc()->getNbParticles() ; ++idxPart ){
150
                if( NbParticlesEntireSystem - 1 != leaf->getSrc()->getDataDown()[idxPart]){
151
                    std::cout << "P2P probleme, should be " << NbParticlesEntireSystem - 1 <<
152
                                 " iter.data().getDataDown() "<< leaf->getSrc()->getDataDown()[idxPart] << std::endl;
153 154
                }
            }
155
        });
156 157
    }

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

160 161 162 163 164
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    return 0;
}