TestPDESolver.cpp 4.57 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;

24
    TestPDESolver(const std::string &meshName) {
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
        meshes = createTestMeshes(meshName, dummyID.level.pLevel,
                                  dummyID.level.fine);
31

niklas.baumgarten's avatar
niklas.baumgarten committed
32
33
34
35
36
        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
37
38
39
    }

    void TearDown() override {
niklas.baumgarten's avatar
niklas.baumgarten committed
40
        delete mGraphs;
niklas.baumgarten's avatar
niklas.baumgarten committed
41
42
        delete pdeSolver;
        delete meshes;
niklas.baumgarten's avatar
niklas.baumgarten committed
43
44
45
    }
};

46
47
48
49
class TestLaplace1D : public TestPDESolver {
public:
    TestLaplace1D() : TestPDESolver("Interval_DirichletBC") {};
};
niklas.baumgarten's avatar
niklas.baumgarten committed
50

51
INSTANTIATE_TEST_CASE_P(TestPDESolver, TestLaplace1D, Values(
niklas.baumgarten's avatar
niklas.baumgarten committed
52
    TestParams{"LagrangeElliptic", "Laplace1D", "L2Error", 0.0},
53
    TestParams{"LagrangeElliptic", "Laplace1D", "EnergyError", 0.0},
niklas.baumgarten's avatar
niklas.baumgarten committed
54
55
56
    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
57

niklas.baumgarten's avatar
niklas.baumgarten committed
58
    TestParams{"MixedElliptic", "Laplace1D", "L2CellAverageError", 0.0},
59
    TestParams{"MixedElliptic", "Laplace1D", "EnergyError", 0.0},
niklas.baumgarten's avatar
niklas.baumgarten committed
60
61
    TestParams{"MixedElliptic", "Laplace1D", "FluxError", 0.0},
    TestParams{"MixedElliptic", "Laplace1D", "Inflow", -1.0},
62
    TestParams{"MixedElliptic", "Laplace1D", "Outflow", 1.0}
niklas.baumgarten's avatar
niklas.baumgarten committed
63
64
65
66
67

//    TestParams{"HybridElliptic", "Laplace1D", "L2CellAverageError", 0.0},
//    TestParams{"HybridElliptic", "Laplace1D", "Inflow", -1.0},
//    TestParams{"HybridElliptic", "Laplace1D", "Outflow", 1.0},
//    TestParams{"HybridElliptic", "Laplace1D", "EnergyError", 0.0},
68
//    TestParams{"HybridElliptic", "Laplace1D", "FluxError", 0.0}
69
70
71
));

TEST_P(TestLaplace1D, TestRun) {
72
    SampleSolution solution(mGraphs, dummyID);
73
74
75
76
    pdeSolver->Run(solution);
    ASSERT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
}

77
78
79
80
class TestLaplace2D : public TestPDESolver {
public:
    TestLaplace2D() : TestPDESolver("Square_DirichletBC") {};
};
niklas.baumgarten's avatar
niklas.baumgarten committed
81

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

89
90
91
92
93
    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}
niklas.baumgarten's avatar
niklas.baumgarten committed
94
95
96
97
98

//    TestParams{"HybridElliptic", "Laplace2D", "L2CellAverageError", 0.0},
//    TestParams{"HybridElliptic", "Laplace2D", "EnergyError", 0.0},
//    TestParams{"HybridElliptic", "Laplace2D", "FluxError", 0.0},
//    TestParams{"HybridElliptic", "Laplace2D", "Inflow", -1.0},
99
//    TestParams{"HybridElliptic", "Laplace2D", "Outflow", 1.0}
niklas.baumgarten's avatar
niklas.baumgarten committed
100

niklas.baumgarten's avatar
niklas.baumgarten committed
101
102
103
104
105
//    TestParams{"DGElliptic", "Laplace2D", "L2Error", 0.0},
//    TestParams{"DGElliptic", "Laplace2D", "EnergyError", 0.0},
//    TestParams{"DGElliptic", "Laplace2D", "FluxError", 0.0},
//    TestParams{"DGElliptic", "Laplace2D", "Inflow", -1.0},
//    TestParams{"DGElliptic", "Laplace2D", "Outflow", 1.0}
106
107
108
));

TEST_P(TestLaplace2D, TestRun) {
109
    SampleSolution solution(mGraphs, dummyID);
110
111
112
113
    pdeSolver->Run(solution);
    ASSERT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
}

114
115
class TestGaussHat : public TestPDESolver {
public:
116
    TestGaussHat() : TestPDESolver("Square_DirichletBC") {};
117
};
niklas.baumgarten's avatar
niklas.baumgarten committed
118

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

123
TEST_P(TestGaussHat, TestRun) {
124
    SampleSolution solution(mGraphs, dummyID);
niklas.baumgarten's avatar
niklas.baumgarten committed
125
    pdeSolver->Run(solution);
126
    ASSERT_NEAR(solution.Q, GetParam().Q, 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();
}