utestFmb.cpp 5.72 KB
Newer Older
1
2
3
4
5
6
// [--License--]


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

7
8
9
#include "../Src/Kernels/FComputeCell.hpp"
#include "../Src/Kernels/FElecForcesKernels.hpp"

10
11
12
13
14
15
16
17
18
19
20
21
#include "../Src/Fmb/FFmbKernels.hpp"
#include "../Src/Fmb/FFmbComponents.hpp"

#include "../Src/Files/FFmaBinLoader.hpp"
#include "../Src/Files/FTreeIO.hpp"

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

#include "FUTester.hpp"


typedef FmbParticle             ParticleClass;
22
typedef FComputeCell            CellClass;
23
24
typedef FVector<ParticleClass>  ContainerClass;

25
26
27
//typedef FFmbKernels<ParticleClass, CellClass, ContainerClass >          KernelClass;
typedef FElecForcesKernels<ParticleClass, CellClass, ContainerClass >          KernelClass;

28
29
30
31
32
33
34
35
36
37
typedef FSimpleLeaf<ParticleClass, ContainerClass >                     LeafClass;
typedef FOctree<ParticleClass, CellClass, ContainerClass , LeafClass >  OctreeClass;

typedef FFmmAlgorithm<OctreeClass, ParticleClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass;

class TestFmb : public FUTester<TestFmb> {

    void TestTree(){
        const int NbLevels      = 5;
        const int SizeSubLevels = 3;
38
39
        const int DevP = 12;
        FComputeCell::Init(DevP);
40

41
        FFmaBinLoader<ParticleClass> loader("../Data/utestFmb.bin.fma");
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
        if(!loader.isOpen()){
            Print("Cannot open particles file.");
            return;
        }

        OctreeClass testTree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
        {
            ParticleClass particleToFill;
            for(int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart){
                loader.fillParticle(particleToFill);
                testTree.insert(particleToFill);
            }
        }


57
        KernelClass kernels(DevP,NbLevels,loader.getBoxWidth());
58
59
60
        FmmClass algo(&testTree,&kernels);
        algo.execute();

61
        FTreeIO::Save<OctreeClass, CellClass, ParticleClass, FTreeIO::Copier<CellClass, ParticleClass> >("../UTests/data/fmb.data", testTree);
62
63

        OctreeClass goodTree(NbLevels, SizeSubLevels, loader.getBoxWidth(), loader.getCenterOfBox());
64
        FTreeIO::Load<OctreeClass, CellClass, ParticleClass, FTreeIO::Copier<CellClass, ParticleClass> >("../Data/utestFmb.data", goodTree);
65
66
67
68
69
70
71
72
73
74
75
76

        Print("Check the particles...");

        { // Check that each particle has been summed with all other
            typename OctreeClass::Iterator testOctreeIterator(&testTree);
            typename OctreeClass::Iterator goodOctreeIterator(&goodTree);

            testOctreeIterator.gotoBottomLeft();
            goodOctreeIterator.gotoBottomLeft();

            do{
                if(testOctreeIterator.getCurrentGlobalIndex() != goodOctreeIterator.getCurrentGlobalIndex()){
77
                    assert(false);
78
79
80
81
                    break;
                }

                if(testOctreeIterator.getCurrentListSrc()->getSize() != goodOctreeIterator.getCurrentListSrc()->getSize()){
82
                    assert(false);
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
                    break;
                }

                typename ContainerClass::BasicIterator goodIter(*goodOctreeIterator.getCurrentListTargets());
                typename ContainerClass::BasicIterator testIter(*testOctreeIterator.getCurrentListTargets());

                while( goodIter.hasNotFinished() ){
                    assert( memcmp(&goodIter.data(), &testIter.data(), sizeof(ParticleClass)) == 0);

                    goodIter.gotoNext();
                    testIter.gotoNext();
                }


                if(!testOctreeIterator.moveRight()){
                    if(goodOctreeIterator.moveRight()){
99
                        assert(false);
100
101
102
103
                    }
                    break;
                }
                if(!goodOctreeIterator.moveRight()){
104
                    assert(false);
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
                    break;
                }

            } while(true);
        }
        Print("Check the leaves...");
        { // Ceck if there is number of NbPart summed at level 1
            typename OctreeClass::Iterator testOctreeIterator(&testTree);
            typename OctreeClass::Iterator goodOctreeIterator(&goodTree);

            testOctreeIterator.gotoBottomLeft();
            goodOctreeIterator.gotoBottomLeft();

            for(int idxLevel = NbLevels - 1 ; idxLevel > 1 ; --idxLevel ){
                do{
                    if(testOctreeIterator.getCurrentGlobalIndex() != goodOctreeIterator.getCurrentGlobalIndex()){
121
                        assert(false);
122
123
124
125
                        break;
                    }

                    assert( memcmp(testOctreeIterator.getCurrentCell()->getLocal(),
126
                                   goodOctreeIterator.getCurrentCell()->getLocal(), CellClass::GetExp() * sizeof(FComplexe)) == 0);
127
128

                    assert( memcmp(testOctreeIterator.getCurrentCell()->getMultipole(),
129
                                   goodOctreeIterator.getCurrentCell()->getMultipole(),CellClass::GetExp() * sizeof(FComplexe)) == 0);
130
131
132

                    if(!testOctreeIterator.moveRight()){
                        if(goodOctreeIterator.moveRight()){
133
                            assert(false);
134
135
136
137
                        }
                        break;
                    }
                    if(!goodOctreeIterator.moveRight()){
138
                        assert(false);
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
                        break;
                    }

                } while(true);

                testOctreeIterator.moveUp();
                testOctreeIterator.gotoLeft();

                goodOctreeIterator.moveUp();
                goodOctreeIterator.gotoLeft();
            }
        }
        Print("Over...");
    }


    // set test
    void SetTests(){
        AddTest(&TestFmb::TestTree,"Test Simu and compare tree");
    }
};



// You must do this
TestClass(TestFmb)


// [--END--]