Commit e27308a9 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

pdesolver test refactoring

parent 9711af40
Pipeline #131761 passed with stages
in 9 minutes and 24 seconds
#include "pdesolver/PDESolverCreator.hpp"
#include "TestPDESolver.hpp"
#include "MeshesCreator.hpp"
#include "TestEnvironment.hpp"
PDESOLVERTEST_TESTRUN(TestLaplace1D)
PDESOLVERTEST_TESTRUN(TestLaplace2D)
constexpr double PDESOLVER_TEST_TOLERANCE = 1e-3;
//PDESOLVERTEST_TESTRUN(TestTransport1D)
struct TestParams {
std::string model;
std::string problem;
std::string quantity;
double Q;
std::string GetOverlap() const {
if (model.find("DG") != -1) return "dG1";
else return "NoOverlap";
}
};
std::ostream &operator<<(std::ostream &s, const TestParams &testParams) {
return s << "{Model: " << testParams.model
<< ", Problem: " << testParams.problem
<< ", Quantity: " << testParams.quantity << "}" << endl;
}
class TestPDESolver : public TestWithParam<TestParams> {
protected:
SampleID id;
Meshes *meshes;
PDESolver *pdeSolver;
TestPDESolver(const std::string &meshName, int commSplit = 0) {
// Todo use googletest number as m!
id = SampleID(5, 0, false);
meshes = MeshesCreator(meshName).
WithOverlap(GetParam().GetOverlap()).
WithCommSplit(commSplit).
WithDistribute("RCB").
WithPLevel(id.level.pLevel).
WithLevel(id.level.fine).
Create();
pdeSolver = PDESolverCreator().
WithModel(GetParam().model).
WithProblem(GetParam().problem).
WithQuantity(GetParam().quantity).
Create(*meshes);
}
void TearDown() override {
delete pdeSolver;
delete meshes;
}
};
class TestLaplace1D : public TestPDESolver {
public:
TestLaplace1D() : TestPDESolver("Interval") {};
};
INSTANTIATE_TEST_SUITE_P(TestPDESolver, TestLaplace1D, Values(
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},
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},
TestParams{"DGElliptic", "Laplace1D", "L2Error", 0.0},
TestParams{"DGElliptic", "Laplace1D", "EnergyError", 0.0},
TestParams{"DGElliptic", "Laplace1D", "FluxError", 0.0},
TestParams{"DGElliptic", "Laplace1D", "Inflow", -1.0},
TestParams{"DGElliptic", "Laplace1D", "Outflow", 1.0}
));
TEST_P(TestLaplace1D, TestRun) {
SampleSolution solution(pdeSolver->MGraphs(), id);
pdeSolver->Run(solution);
EXPECT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
}
class TestLaplace2D : public TestPDESolver {
public:
TestLaplace2D() : TestPDESolver("Square") {};
};
INSTANTIATE_TEST_SUITE_P(TestPDESolver, TestLaplace2D, Values(
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},
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}
));
TEST_P(TestLaplace2D, TestRun) {
SampleSolution solution(pdeSolver->MGraphs(), id);
pdeSolver->Run(solution);
EXPECT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
}
//class TestTransport1D : public TestPDESolver {
//public:
// TestTransport1D() : TestPDESolver("Interval") {};
//};
//
//INSTANTIATE_TEST_SUITE_P(TestPDESolver, TestTransport1D, Values(
// TestParams{"DGTransport", "Pollution1D", "Mass", 1.0}
//));
//
//TEST_P(TestTransport1D, TestRun) {
// SampleSolution solution(pdeSolver->MGraphs(), id);
// pdeSolver->Run(solution);
// EXPECT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
//}
class TestTransport2D : public TestPDESolver {
public:
TestTransport2D() : TestPDESolver("Square") {};
};
INSTANTIATE_TEST_SUITE_P(TestPDESolver, TestTransport2D, Values(
TestParams{"DGTransport", "GaussHat2D", "Mass", 1.0}
));
TEST_P(TestTransport2D, TestRun) {
SampleSolution solution(pdeSolver->MGraphs(), id);
pdeSolver->Run(solution);
EXPECT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
}
//PDESOLVERTEST_TESTRUN(TestTransport2D)
int main(int argc, char **argv) {
return MppTest(
......
#ifndef TESTPDESOLVER_HPP
#define TESTPDESOLVER_HPP
#include "pdesolver/PDESolverCreator.hpp"
#include "MeshesCreator.hpp"
#include "TestEnvironment.hpp"
constexpr double PDESOLVER_TEST_TOLERANCE = 1e-3;
struct TestParams {
std::string model;
std::string problem;
std::string quantity;
double Q;
std::string GetOverlap() const {
if (model.find("DG") != -1) return "dG1";
else return "NoOverlap";
}
};
std::ostream &operator<<(std::ostream &s, const TestParams &testParams) {
return s << "{Model: " << testParams.model
<< ", Problem: " << testParams.problem
<< ", Quantity: " << testParams.quantity << "}" << endl;
}
class TestPDESolver : public TestWithParam<TestParams> {
protected:
SampleID id;
Meshes *meshes;
PDESolver *pdeSolver;
TestPDESolver(const std::string &meshName, int commSplit = 0) {
// Todo use googletest number as m!
id = SampleID(5, 0, false);
meshes = MeshesCreator(meshName).
WithOverlap(GetParam().GetOverlap()).
WithPLevel(id.level.pLevel).
WithLevel(id.level.fine).
WithCommSplit(commSplit).
WithDistribute("RCB").
Create();
pdeSolver = PDESolverCreator().
WithModel(GetParam().model).
WithProblem(GetParam().problem).
WithQuantity(GetParam().quantity).
Create(*meshes);
}
void TearDown() override {
if (!meshes) delete meshes;
if (!pdeSolver) delete pdeSolver;
}
};
class TestLaplace1D : public TestPDESolver {
public:
TestLaplace1D() : TestPDESolver("Interval") {};
};
INSTANTIATE_TEST_SUITE_P(TestPDESolver, TestLaplace1D, Values(
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},
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},
TestParams{"DGElliptic", "Laplace1D", "L2Error", 0.0},
TestParams{"DGElliptic", "Laplace1D", "EnergyError", 0.0},
TestParams{"DGElliptic", "Laplace1D", "FluxError", 0.0},
TestParams{"DGElliptic", "Laplace1D", "Inflow", -1.0},
TestParams{"DGElliptic", "Laplace1D", "Outflow", 1.0}
));
class TestLaplace2D : public TestPDESolver {
public:
TestLaplace2D() : TestPDESolver("Square") {};
};
INSTANTIATE_TEST_SUITE_P(TestPDESolver, TestLaplace2D, Values(
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},
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}
));
//class TestTransport1D : public TestPDESolver {
//public:
// TestTransport1D() : TestPDESolver("Interval") {};
//};
//
//INSTANTIATE_TEST_SUITE_P(TestPDESolver, TestTransport1D, Values(
// TestParams{"DGTransport", "Pollution1D", "Mass", 1.0}
//));
//
//TEST_P(TestTransport1D, TestRun) {
// SampleSolution solution(pdeSolver->MGraphs(), id);
// pdeSolver->Run(solution);
// EXPECT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);
//}
class TestTransport2D : public TestPDESolver {
public:
TestTransport2D() : TestPDESolver("Square") {};
};
INSTANTIATE_TEST_SUITE_P(TestPDESolver, TestTransport2D, Values(
TestParams{"DGTransport", "Pollution2D", "Mass", 1.0},
TestParams{"DGTransport", "PollutionCosHat2D", "Mass", 1.0},
TestParams{"DGTransport", "GaussHat2D", "Mass", 1.0}
));
#define PDESOLVERTEST_TESTRUN(TestClass) \
\
TEST_P(TestClass, TestRun) {\
SampleSolution solution(pdeSolver->MGraphs(), id);\
pdeSolver->Run(solution);\
EXPECT_NEAR(solution.Q, GetParam().Q, PDESOLVER_TEST_TOLERANCE);\
}\
#endif //TESTPDESOLVER_HPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment