testFmmAlgorithmPeriodic.cpp 7.04 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 69 70 71 72 73 74 75
    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;
76 77 78 79 80 81

    FTic counter;

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

BRAMAS Berenger's avatar
BRAMAS Berenger committed
82 83 84 85
    FRandomLoader loader(NbParticles);
    //FPerLeafLoader loader(NbLevels);

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

89
    OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
90 91 92 93 94 95 96 97

    {
        FPoint particlePosition;
        for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
            loader.fillParticle(&particlePosition);
            tree.insert(particlePosition);
        }
    }
98 99 100 101 102 103 104 105 106 107 108

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

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

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

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

122 123 124 125
        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";
126 127
            }
            // we also count the number of particles.
128 129
            counterNbPart += leaf->getSrc()->getNbParticles();
        });
130

BRAMAS Berenger's avatar
BRAMAS Berenger committed
131 132 133
        if( counterNbPart != loader.getNumberOfParticles()){
            std::cout << "Problem global nb part, counter = " << counterNbPart << " created = " <<
                         loader.getNumberOfParticles() << std::endl;
134 135
        }
    }
136 137 138 139 140
    {
        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";
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 149 150
        tree.forEachLeaf([&](LeafClass* leaf){
            for(int idxPart = 0 ; idxPart < leaf->getSrc()->getNbParticles() ; ++idxPart ){
                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 165 166
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    return 0;
}


167