TestMonteCarlo.cpp 1.63 KB
Newer Older
1
#include "TestMonteCarlo.hpp"
2
3


niklas.baumgarten's avatar
niklas.baumgarten committed
4
5
6
class TestMonteCarlo : public TestWithParam<std::string> {
protected:
    int pLevel = 2;
niklas.baumgarten's avatar
niklas.baumgarten committed
7

niklas.baumgarten's avatar
niklas.baumgarten committed
8
    int level = 3;
niklas.baumgarten's avatar
niklas.baumgarten committed
9

niklas.baumgarten's avatar
niklas.baumgarten committed
10
    int dM = 1e6;
11

niklas.baumgarten's avatar
niklas.baumgarten committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    MeshesCreator meshesCreator;

    PDESolverCreator pdeSolverCreator;

    MonteCarlo mc;

    TestMonteCarlo(const std::string &meshName, int commSplit = 0) :
        meshesCreator(MeshesCreator("Interval").
            WithCommSplit(commSplit).
            WithDistribute("RCB").
            WithoutOverlap().
            WithPLevel(pLevel).
            WithLevel(level)),
        pdeSolverCreator(PDESolverCreator().
            WithProblem(GetParam()).
            WithQuantity("GeneratorValue").
            WithModel("DummyPDESolver")),
niklas.baumgarten's avatar
niklas.baumgarten committed
29
        mc(MonteCarlo(level, dM, true, meshesCreator, pdeSolverCreator)) {
niklas.baumgarten's avatar
niklas.baumgarten committed
30
31
32
33
34
        mc.Method();
    }

    void TearDown() {
        PPM->Barrier(0);
35
        PPM->ClearCommunicators();
niklas.baumgarten's avatar
niklas.baumgarten committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    }
};

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

INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, TestMonteCarloInterval, Values(
    "StochasticDummyScalarGeneratorProblem"
));

TEST_P(TestMonteCarloInterval, TestMethodOnlyFine) {
niklas.baumgarten's avatar
niklas.baumgarten committed
50
51
52
53
//    EXPECT_NEAR(mc.avgs.Q, 0.0, sqrt(1.0 / dM));
//    EXPECT_NEAR(mc.avgs.Y, 0.0, sqrt(1.0 / dM));
//    EXPECT_NEAR(mc.vars.Q, 1.0, sqrt(10.0 / dM));
//    EXPECT_NEAR(mc.vars.Y, 1.0, sqrt(10.0 / dM));
niklas.baumgarten's avatar
niklas.baumgarten committed
54
}
55
56
57
58
59
60
61
62

int main(int argc, char **argv) {
    return MppTest(
        MppTestBuilder(argc, argv).
            WithParallelListeners().
            WithScreenLogging().
            WithPPM()
    ).RUN_ALL_MPP_TESTS();
63
}