utestAlgorithmBuilder.cpp 4.31 KB
Newer Older
1
// See LICENCE file at project root
2 3
#include "FUTester.hpp"

BRAMAS Berenger's avatar
BRAMAS Berenger committed
4
#include "Core/FAlgorithmBuilder.hpp"
5

BRAMAS Berenger's avatar
BRAMAS Berenger committed
6
#include "Containers/FOctree.hpp"
7

BRAMAS Berenger's avatar
BRAMAS Berenger committed
8 9 10 11 12
#include "Components/FSimpleLeaf.hpp"
#include "Components/FTestParticleContainer.hpp"
#include "Components/FTestCell.hpp"
#include "Components/FTestKernels.hpp"
#include "Components/FBasicKernels.hpp"
13 14 15


/** This class test the core algorithm builder */
16
#ifndef SCALFMM_USE_MPI
17
class TestBuilder : public FUTester<TestBuilder> {
18 19 20
#else
class TestBuilder : public FUTesterMpi<TestBuilder> {
#endif
21
    void Test(){
22
        typedef double FReal;
23
        typedef FTestCell                   CellClass;
24
        typedef FTestParticleContainer<FReal>      ContainerClass;
25

26 27
        typedef FSimpleLeaf<FReal, ContainerClass >                     LeafClass;
        typedef FOctree<FReal, CellClass, ContainerClass , LeafClass >  OctreeClass;
28 29 30 31
        typedef FTestKernels< CellClass, ContainerClass >         KernelClass;

        const int height = 5;
        const FReal dim = 1.0;
32
        const FPoint<FReal> center(0.0,0.0,0.0);
33 34 35 36 37

        OctreeClass tree(height, 2, dim, center);
        KernelClass kernel;

        {
38
            FAlgorithmBuilder<FReal>::SimulationProperties properties = FAlgorithmBuilder<FReal>::BuildKernelSimulationProperties(height,center,dim,false);
39 40 41 42 43
            uassert(properties.centerOfBox.getX() == center.getX() && properties.centerOfBox.getY() == center.getY() &&
                    properties.centerOfBox.getZ() == center.getZ() );
            uassert(properties.dimOfBox == dim);
            uassert(properties.height == height);

44 45 46 47 48 49 50
            FAbstractAlgorithm*const algo = FAlgorithmBuilder<FReal>::BuildAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(&tree, &kernel,
#ifndef SCALFMM_USE_MPI
                                                                                                                                                     0,
#else
                                                                                                                                                     MPI_COMM_WORLD,
#endif
                                                                                                                                                     false);
51
#ifndef SCALFMM_USE_MPI
COULAUD Olivier's avatar
COULAUD Olivier committed
52 53
            uassert(dynamic_cast<FFmmAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>*>(algo) != nullptr ||
                    dynamic_cast<FFmmAlgorithmThread<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>*>(algo) != nullptr);
54
#else
COULAUD Olivier's avatar
COULAUD Olivier committed
55
            uassert(dynamic_cast<FFmmAlgorithmThreadProc<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>*>(algo) != nullptr);
56 57 58 59
#endif
            delete algo;
        }
        {
60
            FAlgorithmBuilder<FReal>::SimulationProperties properties = FAlgorithmBuilder<FReal>::BuildKernelSimulationProperties(height,center,dim,true);
61
            uassert(properties.dimOfBox != dim);
62
            uassert(properties.height      != height);
63

64 65 66 67 68 69 70
            FAbstractAlgorithm*const algo = FAlgorithmBuilder<FReal>::BuildAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>(&tree, &kernel,
 #ifndef SCALFMM_USE_MPI
                                                                                                                                                      0,
 #else
                                                                                                                                                      MPI_COMM_WORLD,
 #endif
                                                                                                                                                      true);
71
#ifndef SCALFMM_USE_MPI
72
            uassert(dynamic_cast<FFmmAlgorithmPeriodic<FReal,OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>*>(algo) != nullptr );
73
#else
74
            uassert(dynamic_cast<FFmmAlgorithmThreadProcPeriodic<FReal, OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass>*>(algo) != nullptr);
75 76 77 78 79 80 81 82 83 84 85
#endif

            delete algo;
        }

    }

    // set test
    void SetTests(){
        AddTest(&TestBuilder::Test,"Test Algo Creation");
    }
86 87 88 89 90 91

#ifdef SCALFMM_USE_MPI
public:
    TestBuilder(int argc,char ** argv) : FUTesterMpi(argc,argv){
    }
#endif
92 93 94
};

// You must do this
95
#ifndef SCALFMM_USE_MPI
96
TestClass(TestBuilder)
97 98 99
#else
TestClassMpi(TestBuilder)
#endif
100 101