TestPDESolver.cpp 2.39 KB
Newer Older
niklas.baumgarten's avatar
niklas.baumgarten committed
1
2
3
4
#include "assemble/LagrangeEllipticAssemble.hpp"
#include "assemble/MixedEllipticAssemble.hpp"
#include "assemble/HybridEllipticAssemble.hpp"
#include "assemble/DGEllipticAssemble.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
5
6
7
8
#include "assemble/DGTransportAssemble.hpp"
#include "assemble/DGReactionAssemble.hpp"
#include "assemble/PGReactionAssemble.hpp"
#include "montecarlo/PDESolver.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
9
10
11
#include "TestEnvironment.hpp"


niklas.baumgarten's avatar
niklas.baumgarten committed
12
13
14
constexpr double tolerance_pde_solver_test = 1e-10;


niklas.baumgarten's avatar
niklas.baumgarten committed
15
16
class TestPDESolver : public Test {
protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
17
18
    Meshes *meshes;

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

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

    SampleID dummyID;

    TestPDESolver() {
niklas.baumgarten's avatar
niklas.baumgarten committed
26
        dummyID.level = Level(6, 0);
niklas.baumgarten's avatar
niklas.baumgarten committed
27
28
        dummyID.coarse = false;
        dummyID.number = -1;
niklas.baumgarten's avatar
niklas.baumgarten committed
29
30
31
        meshes = createTestMeshes("Square_DirichletBC",
                                  dummyID.level.pLevel,
                                  dummyID.level.fine);
niklas.baumgarten's avatar
niklas.baumgarten committed
32
33
34
    }

    void TearDown() override {
niklas.baumgarten's avatar
niklas.baumgarten committed
35
36
        delete pdeSolver;
        delete meshes;
niklas.baumgarten's avatar
niklas.baumgarten committed
37
38
39
40
41
    }
};

class TestEllipticPDESolver : public TestPDESolver {
protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
42
43
44
45
    TestEllipticPDESolver() : TestPDESolver() {
        pdeSolver = new EllipticPDESolver(
            new LagrangeEllipticAssemble(
                new LagrangeDiscretization(*meshes, 1),
niklas.baumgarten's avatar
niklas.baumgarten committed
46
                CreateStochasticEllipticProblem("Laplace2D", *meshes)
niklas.baumgarten's avatar
niklas.baumgarten committed
47
48
            )
        );
niklas.baumgarten's avatar
niklas.baumgarten committed
49
        pdeSolver->SetQuantity("L2Error");
niklas.baumgarten's avatar
niklas.baumgarten committed
50
        mGraphs = pdeSolver->CreateSolutionMatrixGraph(*meshes);
niklas.baumgarten's avatar
niklas.baumgarten committed
51
52
53
    }
};

niklas.baumgarten's avatar
niklas.baumgarten committed
54
55
56
57
58
TEST_F(TestEllipticPDESolver, TestLagrangeDiscretization) {
    SampleSolution solution(*mGraphs, dummyID);
    pdeSolver->Run(solution);
    ASSERT_NEAR(solution.Q, 0.0, tolerance_pde_solver_test);
}
niklas.baumgarten's avatar
niklas.baumgarten committed
59

niklas.baumgarten's avatar
niklas.baumgarten committed
60
61
62
63
64
65
66
67
68
69
70
class TestTransportPDESolver : public TestPDESolver {
protected:
    TestTransportPDESolver() : TestPDESolver() {
        pdeSolver = new TransportPDESolver(
            new DGTransportAssemble(
                new DGDiscretization(*meshes, 2),
                CreateStochasticTransportProblem("CircleWave2D", *meshes)
            )
        );
        pdeSolver->SetQuantity("Mass");
        mGraphs = pdeSolver->CreateSolutionMatrixGraph(*meshes);
niklas.baumgarten's avatar
niklas.baumgarten committed
71
72
73
    }
};

niklas.baumgarten's avatar
niklas.baumgarten committed
74
75
76
77
TEST_F(TestTransportPDESolver, TestCircleWave2D) {
//    SampleSolution solution(*mGraphs, dummyID);
//    pdeSolver->Run(solution);
//    ASSERT_NEAR(solution.Q, 0.0, tolerance_pde_solver_test);
niklas.baumgarten's avatar
niklas.baumgarten committed
78
79
80
}

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