TestMonteCarlo.hpp 2.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#ifndef TESTMONTECARLO_HPP
#define TESTMONTECARLO_HPP

#include "montecarlo/MonteCarlo.hpp"
#include "pdesolver/PDESolverCreator.hpp"

#include "mesh/MeshesCreator.hpp"

#include "TestEnvironment.hpp"


niklas.baumgarten's avatar
niklas.baumgarten committed
12
constexpr double MONTECARLO_TEST_TOLERANCE = 1e-1;
13
14
15
16
17
18
19
20
21
22
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

class TestMonteCarlo : public TestWithParam<std::string> {
protected:
    int commSplit;

    int pLevel = 2;

    int level = 3;

    int dM = 1e5;

    Meshes *meshes;

    PDESolver *pdeSolver;

    MonteCarlo mc;

    TestMonteCarlo(const std::string &meshName, int commSplit = 0) :
        meshes(MeshesCreator("Interval").
            WithCommSplit(commSplit).
            WithDistribute("RCB", 0).
            WithoutOverlap(0).
            WithPLevel(pLevel).
            WithLevel(level).
            Create()),
        pdeSolver(PDESolverCreator(*meshes, 0, 0).
            WithProblem(GetParam()).
            WithQuantity("GeneratorValue").
            WithModel("DummyPDESolver").
            Create()),
        mc(MonteCarlo(Level(level), dM, true, meshes, pdeSolver)) {
        mc.Method();
    }

    void TearDown() {
        PPM->Barrier(0);
        PPM->ClearCommunicators(false);
        if (!meshes) delete meshes;
        if (!pdeSolver) delete pdeSolver;
    }
};

class TestMonteCarloInterval : public TestMonteCarlo {
protected:
    TestMonteCarloInterval(int commSplit = 0) :
        TestMonteCarlo("Interval", commSplit) {}
};

class TestMonteCarloIntervalWithSplit : public TestMonteCarloInterval {
protected:
    TestMonteCarloIntervalWithSplit() :
        TestMonteCarloInterval(1) {}
};

class TestMonteCarloIntervalWithDoubleSplit : public TestMonteCarloInterval {
protected:
    TestMonteCarloIntervalWithDoubleSplit() :
        TestMonteCarloInterval(2) {}
};

niklas.baumgarten's avatar
niklas.baumgarten committed
73
class TestMonteCarloIntervalWithFullSplit : public TestMonteCarloInterval {
74
protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
75
    TestMonteCarloIntervalWithFullSplit() :
76
77
78
79
80
        TestMonteCarloInterval(-1) {}
};

#define MONTECARLO_INTERVAL_TESTS(MonteCarloIntervalTestClass)\
\
niklas.baumgarten's avatar
niklas.baumgarten committed
81
INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, MonteCarloIntervalTestClass, Values(\
82
83
84
85
86
87
88
89
90
91
92
    "StochasticDummyScalarGeneratorProblem"\
));\
\
TEST_P(MonteCarloIntervalTestClass, TestMethodOnlyFine) {\
    EXPECT_NEAR(mc.avgs.Q, 0.0, MONTECARLO_TEST_TOLERANCE);\
    EXPECT_NEAR(mc.avgs.Y, 0.0, MONTECARLO_TEST_TOLERANCE);\
    EXPECT_NEAR(mc.vars.Q, 1.0, MONTECARLO_TEST_TOLERANCE);\
    EXPECT_NEAR(mc.vars.Y, 1.0, MONTECARLO_TEST_TOLERANCE);\
}\

#endif //TESTMONTECARLO_HPP