TestPDESolver.cpp 4.12 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
6
constexpr double tolerance_pde_solver_test = 1e-10;

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
39
40
41
42
43

        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);

        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
44
45
46
    }

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


niklas.baumgarten's avatar
niklas.baumgarten committed
54
55
56
57
58
59
60
INSTANTIATE_TEST_CASE_P(TestPDESolver, TestPDESolver, Values(
    // 1D Laplace
    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
61

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

//    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},

    // 2D Laplace
    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
80

niklas.baumgarten's avatar
niklas.baumgarten committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    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},
    TestParams{"DGElliptic", "Laplace2D", "Outflow", 1.0},

//    TestParams{"DGTransport", "CircleWave2D", "Mass", 0.0}
));

TEST_P(TestPDESolver, TestRun) {
    SampleSolution solution(*mGraphs, dummyID);
    pdeSolver->Run(solution);
    ASSERT_NEAR(solution.Q, GetParam().Q, tolerance_pde_solver_test);
niklas.baumgarten's avatar
niklas.baumgarten committed
106
107
108
}

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