TestPDESolver.cpp 4.78 KB
Newer Older
niklas.baumgarten's avatar
niklas.baumgarten committed
1
#include "montecarlo/PDESolver.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
2
3
4
#include "TestEnvironment.hpp"


niklas.baumgarten's avatar
niklas.baumgarten committed
5
constexpr double PDESOLVER_TEST_TOLERANCE = 1e-5;
niklas.baumgarten's avatar
niklas.baumgarten committed
6

niklas.baumgarten's avatar
niklas.baumgarten committed
7
8
9
10
11
12
struct TestParams {
    std::string model;
    std::string problem;
    std::string quantity;
    double Q;
};
niklas.baumgarten's avatar
niklas.baumgarten committed
13

niklas.baumgarten's avatar
niklas.baumgarten committed
14
class TestPDESolver : public TestWithParam<TestParams> {
niklas.baumgarten's avatar
niklas.baumgarten committed
15
protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
16
17
    Meshes *meshes;

niklas.baumgarten's avatar
niklas.baumgarten committed
18
19
    PDESolver *pdeSolver;

niklas.baumgarten's avatar
niklas.baumgarten committed
20
21
22
23
    MatrixGraphs *mGraphs;

    SampleID dummyID;

niklas.baumgarten's avatar
niklas.baumgarten committed
24
    void SetUp() override {
niklas.baumgarten's avatar
niklas.baumgarten committed
25
        dummyID.level = Level(6, 0);
niklas.baumgarten's avatar
niklas.baumgarten committed
26
27
        dummyID.coarse = false;
        dummyID.number = -1;
niklas.baumgarten's avatar
niklas.baumgarten committed
28
29
30
31
32
33
34
35
36
37
38

        if (GetParam().problem.find("1D") != std::string::npos)
            meshes = createTestMeshes("Interval_DirichletBC",
                                      dummyID.level.pLevel,
                                      dummyID.level.fine);

        if (GetParam().problem.find("2D") != std::string::npos)
            meshes = createTestMeshes("Square_DirichletBC",
                                      dummyID.level.pLevel,
                                      dummyID.level.fine);

39

niklas.baumgarten's avatar
niklas.baumgarten committed
40
41
42
43
44
        pdeSolver = PDESolverCreator(*meshes).
            WithModel(GetParam().model).
            WithProblem(GetParam().problem).Create();
        pdeSolver->SetQuantity(GetParam().quantity);
        mGraphs = pdeSolver->CreateSolutionMatrixGraph(*meshes);
niklas.baumgarten's avatar
niklas.baumgarten committed
45
46
47
    }

    void TearDown() override {
niklas.baumgarten's avatar
niklas.baumgarten committed
48
        delete mGraphs;
niklas.baumgarten's avatar
niklas.baumgarten committed
49
50
        delete pdeSolver;
        delete meshes;
niklas.baumgarten's avatar
niklas.baumgarten committed
51
52
53
    }
};

54
class TestLaplace1D : public TestPDESolver {};
niklas.baumgarten's avatar
niklas.baumgarten committed
55

56
INSTANTIATE_TEST_CASE_P(TestPDESolver, TestLaplace1D, Values(
niklas.baumgarten's avatar
niklas.baumgarten committed
57
58
59
60
61
    TestParams{"LagrangeElliptic", "Laplace1D", "L2Error", 0.0},
//    TestParams{"LagrangeElliptic", "Laplace1D", "EnergyError", 0.0},
    TestParams{"LagrangeElliptic", "Laplace1D", "FluxError", 0.0},
    TestParams{"LagrangeElliptic", "Laplace1D", "Inflow", -1.0},
    TestParams{"LagrangeElliptic", "Laplace1D", "Outflow", 1.0},
niklas.baumgarten's avatar
niklas.baumgarten committed
62

niklas.baumgarten's avatar
niklas.baumgarten committed
63
64
65
66
    TestParams{"MixedElliptic", "Laplace1D", "L2CellAverageError", 0.0},
//    TestParams{"MixedElliptic", "Laplace1D", "EnergyError", 0.0},
    TestParams{"MixedElliptic", "Laplace1D", "FluxError", 0.0},
    TestParams{"MixedElliptic", "Laplace1D", "Inflow", -1.0},
67
    TestParams{"MixedElliptic", "Laplace1D", "Outflow", 1.0}
niklas.baumgarten's avatar
niklas.baumgarten committed
68
69
70
71
72
73

//    TestParams{"HybridElliptic", "Laplace1D", "L2CellAverageError", 0.0},
//    TestParams{"HybridElliptic", "Laplace1D", "Inflow", -1.0},
//    TestParams{"HybridElliptic", "Laplace1D", "Outflow", 1.0},
//    TestParams{"HybridElliptic", "Laplace1D", "EnergyError", 0.0},
//    TestParams{"HybridElliptic", "Laplace1D", "FluxError", 0.0},
74
75
76
77
78
79
80
81
82
));

TEST_P(TestLaplace1D, TestRun) {
    SampleSolution solution(*mGraphs, dummyID);
    pdeSolver->Run(solution);
    ASSERT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
}

class TestLaplace2D : public TestPDESolver {};
niklas.baumgarten's avatar
niklas.baumgarten committed
83

84
INSTANTIATE_TEST_CASE_P(TestPDESolver, TestLaplace2D, Values(
niklas.baumgarten's avatar
niklas.baumgarten committed
85
86
87
88
89
    TestParams{"LagrangeElliptic", "Laplace2D", "L2Error", 0.0},
    TestParams{"LagrangeElliptic", "Laplace2D", "EnergyError", 0.0},
    TestParams{"LagrangeElliptic", "Laplace2D", "FluxError", 0.0},
    TestParams{"LagrangeElliptic", "Laplace2D", "Inflow", -1.0},
    TestParams{"LagrangeElliptic", "Laplace2D", "Outflow", 1.0},
niklas.baumgarten's avatar
niklas.baumgarten committed
90

niklas.baumgarten's avatar
niklas.baumgarten committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    TestParams{"MixedElliptic", "Laplace2D", "L2CellAverageError", 0.0},
    TestParams{"MixedElliptic", "Laplace2D", "EnergyError", 0.0},
    TestParams{"MixedElliptic", "Laplace2D", "FluxError", 0.0},
    TestParams{"MixedElliptic", "Laplace2D", "Inflow", -1.0},
    TestParams{"MixedElliptic", "Laplace2D", "Outflow", 1.0},

//    TestParams{"HybridElliptic", "Laplace2D", "L2CellAverageError", 0.0},
//    TestParams{"HybridElliptic", "Laplace2D", "EnergyError", 0.0},
//    TestParams{"HybridElliptic", "Laplace2D", "FluxError", 0.0},
//    TestParams{"HybridElliptic", "Laplace2D", "Inflow", -1.0},
//    TestParams{"HybridElliptic", "Laplace2D", "Outflow", 1.0},

    TestParams{"DGElliptic", "Laplace2D", "L2Error", 0.0},
    TestParams{"DGElliptic", "Laplace2D", "EnergyError", 0.0},
    TestParams{"DGElliptic", "Laplace2D", "FluxError", 0.0},
    TestParams{"DGElliptic", "Laplace2D", "Inflow", -1.0},
niklas.baumgarten's avatar
niklas.baumgarten committed
107
    TestParams{"DGElliptic", "Laplace2D", "Outflow", 1.0}
108
109
110
111
112
113
114
115
116
));

TEST_P(TestLaplace2D, TestRun) {
    SampleSolution solution(*mGraphs, dummyID);
    pdeSolver->Run(solution);
    ASSERT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
}

class TestGaussHat : public TestPDESolver {};
niklas.baumgarten's avatar
niklas.baumgarten committed
117

118
119
INSTANTIATE_TEST_CASE_P(TestPDESolver, TestGaussHat, Values(
    TestParams{"DGTransport", "GaussHat2D", "Mass", 1.0}
niklas.baumgarten's avatar
niklas.baumgarten committed
120
121
));

122
TEST_P(TestGaussHat, TestRun) {
niklas.baumgarten's avatar
niklas.baumgarten committed
123
124
    SampleSolution solution(*mGraphs, dummyID);
    pdeSolver->Run(solution);
125
126
    ASSERT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
// Todo    ASSERT_NEAR(solution.Cost, GetParam().Cost, PDESOLVER_TEST_TOLERANCE);
niklas.baumgarten's avatar
niklas.baumgarten committed
127
128
129
}

int main(int argc, char **argv) {
niklas.baumgarten's avatar
niklas.baumgarten committed
130
    MppTest mppTest = MppTestBuilder(argc, argv).WithPPM().WithScreenLogging();
niklas.baumgarten's avatar
niklas.baumgarten committed
131
132
    return mppTest.RUN_ALL_MPP_TESTS();
}