testFmmAdaptiveAlgorithmAdvanced.cpp 9.49 KB
Newer Older
1
// ===================================================================================
2 3 4 5
// Copyright ScalFmm 2016 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.
6
//
7
// This software is governed by the CeCILL-C and LGPL licenses and
8
// abiding by the rules of distribution of free software.
9 10 11
// An extension to the license is given to allow static linking of scalfmm
// inside a proprietary application (no matter its license).
// See the main license file for more details.
12 13 14 15
//
// 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
16 17 18
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
19 20
// ===================================================================================

21 22
// Keep in private GIT
// @SCALFMM_PRIVATE
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include <iostream>
#include <cstdio>


#include "../../Src/Utils/FParameters.hpp"
#include "../../Src/Utils/FTic.hpp"

#include "../../Src/Containers/FOctree.hpp"
#include "../../Src/Containers/FVector.hpp"

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

#include "../../Src/Utils/FPoint.hpp"

#include "../../Src/Components/FTestParticleContainer.hpp"
#include "../../Src/Components/FTestCell.hpp"
#include "../../Src/Components/FTestKernels.hpp"

#include "../../Src/Core/FFmmAlgorithm.hpp"
#include "../../Src/Core/FFmmAlgorithmThread.hpp"
#include "../../Src/Core/FFmmAlgorithmTask.hpp"

#include "../../Src/Components/FBasicKernels.hpp"

#include "../../Src/Files/FRandomLoader.hpp"
48
#include "../../Src/Files/FFmaGenericLoader.hpp"
49

50 51 52
#include "../../Src/Adaptive/FAdaptiveCell.hpp"
#include "../../Src/Adaptive/FAdaptiveKernelWrapper.hpp"
#include "../../Src/Adaptive/FAbstractAdaptiveKernel.hpp"
53
#include "../../Src/Adaptive/FAdaptiveTestKernel.hpp"
54

55 56
#include "../../Src/Utils/FParameterNames.hpp"

57 58 59 60 61 62 63

/** 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){
64
    const FParameterNames PrintTree =  { {"-print-trees"}, "Print the details of the trees."};
65 66 67
    FHelpDescribeAndExit(argc, argv,
                         "Test the adaptive FMM.",
                         FParameterDefinitions::NbParticles, FParameterDefinitions::OctreeHeight,
68
                         FParameterDefinitions::OctreeSubHeight,PrintTree);
69

70
    typedef double FReal;
71
    typedef FTestCell                   CellClass;
72 73
    typedef FTestParticleContainer<FReal>      ContainerClass;
    typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
74
    typedef FAdaptiveTestKernel< CellClass, ContainerClass >         KernelClass;
75 76
    typedef FAdaptiveCell< CellClass, ContainerClass >         CellWrapperClass;
    typedef FAdaptiveKernelWrapper< KernelClass, CellClass, ContainerClass >         KernelWrapperClass;
77
    typedef FOctree< FReal, CellWrapperClass, ContainerClass , LeafClass >  OctreeClass;
78 79
    typedef FFmmAlgorithm<OctreeClass, CellWrapperClass, ContainerClass, KernelWrapperClass, LeafClass >     FmmClass;

80
    typedef FTestCell                   CellClassTest;
81 82 83
    typedef FTestParticleContainer<FReal>      ContainerClassTest;
    typedef FSimpleLeaf<FReal, ContainerClassTest >                     LeafClassTest;
    typedef FOctree<FReal, CellClassTest, ContainerClassTest , LeafClassTest >  OctreeClassTest;
84 85 86
    typedef FTestKernels< CellClassTest, ContainerClassTest >         KernelClassTest;
    typedef FFmmAlgorithm<OctreeClassTest, CellClass, ContainerClassTest, KernelClassTest, LeafClassTest >     FmmClassTest;

87 88 89 90
    ///////////////////////What we do/////////////////////////////
    std::cout << ">> This executable has to be used to test the FMM algorithm.\n";
    //////////////////////////////////////////////////////////////

91 92
    const int NbLevels      = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeHeight.options, 7);
    const int SizeSubLevels = FParameters::getValue(argc,argv,FParameterDefinitions::OctreeSubHeight.options, 3);
93 94 95 96 97
    FTic counter;

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

98 99
    //FRandomLoader<FReal> loader(FParameters::getValue(argc,argv,FParameterDefinitions::NbParticles.options, 2000000), 1, FPoint<FReal>(0.5,0.5,0.5), 1);
    FFmaGenericLoader<FReal> loader(FParameters::getStr(argc,argv,FParameterDefinitions::InputFile.options,"../Data/noDist/prolate50-ref.fma"));
100
    OctreeClass tree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
101
    OctreeClassTest treeTest(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
102 103 104 105

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

106
    std::cout << "Creating & Inserting " << loader.getNumberOfParticles() << " particles ..." << std::endl;
107 108 109 110
    std::cout << "\tHeight : " << NbLevels << " \t sub-height : " << SizeSubLevels << std::endl;
    counter.tic();

    {
111
        FPoint<FReal> particlePosition;
112
        for(FSize idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
113 114 115
            FReal pv;
            loader.fillParticle(&particlePosition, &pv);
            //loader.fillParticle(&particlePosition);
116
            tree.insert(particlePosition);
117
            treeTest.insert(particlePosition);
118 119 120 121 122 123 124 125 126 127 128 129
        }
    }

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

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

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

130
    KernelWrapperClass kernels(4);            // FTestKernels FBasicKernels
131 132 133 134 135 136
    FmmClass algo(&tree,&kernels);  //FFmmAlgorithm FFmmAlgorithmThread
    algo.execute();

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

137 138 139 140
    KernelClassTest kernelsTest;            // FTestKernels FBasicKernels
    FmmClassTest algoTest(&treeTest,&kernelsTest);  //FFmmAlgorithm FFmmAlgorithmThread
    algoTest.execute();

141 142 143 144 145
    //////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    tree.forEachCellLeaf([&](CellWrapperClass*, LeafClass* leaf){
        long long int*const particlesAttributes = leaf->getTargets()->getDataDown();
146
        for(FSize idxPart = 0 ; idxPart < leaf->getTargets()->getNbParticles() ; ++idxPart){
147
            if(particlesAttributes[idxPart] != (loader.getNumberOfParticles()-1)){
148
                std::cout << "Incorrect " << particlesAttributes[idxPart] << " instead of " << (loader.getNumberOfParticles()-1) << "\n";
149 150 151 152
            }
        }
    });

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

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

    tree.forEachCellWithLevel([&](CellWrapperClass* cell, int level){
        if(cell->hasDevelopment()){
            FAssertLF(cell->isAdaptive());
            CellClass* testcell = cell->getRealCell();
            FAssertLF(testcell);
            CellClassTest* testcelltest = treeTest.getCell(testcell->getMortonIndex(), level);
            FAssertLF(testcelltest);
            if(testcell->getDataUp() != testcelltest->getDataUp()){
                std::cout << "Error at index " << testcell->getMortonIndex() << " level " << level << " up is " << testcell->getDataUp()
                             << " should be " << testcelltest->getDataUp() << "\n";
            }
168 169 170 171
            if(testcell->getDataDown() != testcelltest->getDataDown()){
                std::cout << "Error at index " << testcell->getMortonIndex() << " level " << level << " up is " << testcell->getDataDown()
                             << " should be " << testcelltest->getDataDown() << "\n";
            }
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
        }
    });


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

    if(FParameters::existParameter(argc, argv, PrintTree.options)){
        int previousLevel = 0;
        tree.forEachCellWithLevel([&](CellWrapperClass* cell, int level){
            if(cell->hasDevelopment()){
                if(previousLevel != level){
                    previousLevel = level;
                    std::cout << "\n" << level << "] ";
                }
                FAssertLF(cell->isAdaptive());
                CellClass* testcell = cell->getRealCell();
                std::cout << "Idx:" << testcell->getMortonIndex() << " Up " << testcell->getDataUp() << "\t";
            }
        });
        std::cout << "\n";

        previousLevel = 0;
        treeTest.forEachCellWithLevel([&](CellClassTest* cell, int level){
            if(previousLevel != level){
                previousLevel = level;
                std::cout << "\n" << level << "] ";
            }
            std::cout << "Idx:" << cell->getMortonIndex() << " Up " << cell->getDataUp() << "\t";
        });
        std::cout << "\n";
    }

205 206 207 208 209 210
    return 0;
}