Commit 8ed291a5 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

worked on mlmc tests

parent 206132ac
Pipeline #149945 canceled with stages
in 1 minute and 10 seconds
#include "TestMultilevelMonteCarlo.hpp" #include "TestMultilevelMonteCarlo.hpp"
INSTANTIATE_TEST_SUITE_P(
INSTANTIATE_TEST_SUITE_P(TestMultilevelMonteCarlo, TestMultilevelMonteCarlo, Values( TestMultilevelMonteCarlo, TestMultilevelMonteCarloWithEpsilon, Values(
TestParams{"StochasticDummyScalarGeneratorProblem", "GeneratorValue", "DummyPDESolver"}, TestParams{"StochasticLaplace1D", "L2", "LagrangeElliptic"},
TestParams{"StochasticLaplace2DTest", "L2", "LagrangeElliptic"}, TestParams{"StochasticLaplace2D", "L2", "LagrangeElliptic"}
TestParams{"StochasticLaplace2DTest", "Outflow", "HybridElliptic"}
// Todo add more test cases
)); ));
TEST_P(TestMultilevelMonteCarlo, TestSeriellAgainstParallel) { TEST_P(TestMultilevelMonteCarloWithoutEpsilon, TestSeriellAgainstParallel) {
EXPECT_NEAR(mlmcParallel->aggregate.mean.Q, mlmcSeriell->aggregate.mean.Q, MeanTolerance()); mout << GetParam() << endl;
EXPECT_NEAR(mlmcParallel->aggregate.mean.Y, mlmcSeriell->aggregate.mean.Y, MeanTolerance());
EXPECT_NEAR(mlmcParallel->aggregate.sVar.Q, mlmcSeriell->aggregate.sVar.Q, SVarTolerance()); mout.StartBlock("Monte Carlo seriell");
EXPECT_NEAR(mlmcParallel->aggregate.sVar.Y, mlmcSeriell->aggregate.sVar.Y, SVarTolerance()); mout << "Start" << endl;
mlmcSeriell->Method();
mout.EndBlock();
mout << endl;
mlmcParallel->EstimatorResults();
mlmcParallel->MultilevelResults();
mlmcParallel->ExponentResults();
mout.StartBlock("Monte Carlo parallel");
mout << "Start" << endl;
mlmcParallel->Method();
mout.EndBlock();
mout << endl;
mlmcParallel->EstimatorResults();
mlmcParallel->MultilevelResults();
mlmcParallel->ExponentResults();
EXPECT_NEAR(mlmcParallel->aggregate.mean.Q, mlmcSeriell->aggregate.mean.Q, MeanTol());
EXPECT_NEAR(mlmcParallel->aggregate.mean.Y, mlmcSeriell->aggregate.mean.Y, MeanTol());
EXPECT_NEAR(mlmcParallel->aggregate.sVar.Q, mlmcSeriell->aggregate.sVar.Q, SVarTol());
EXPECT_NEAR(mlmcParallel->aggregate.sVar.Y, mlmcSeriell->aggregate.sVar.Y, SVarTol());
} }
TEST_P(TestMultilevelMonteCarlo, TestWithEpsilon) { TEST_P(TestMultilevelMonteCarloWithEpsilon, TestWithEpsilon) {
mout << GetParam() << endl;
mout.StartBlock("Monte Carlo parallel");
mout << "Start" << endl;
mlmcParallel->Method();
mout.EndBlock();
mout << endl;
mlmcParallel->EstimatorResults();
mlmcParallel->MultilevelResults();
mlmcParallel->ExponentResults();
EXPECT_LE(mlmcSeriell->TotalError(), epsilon); EXPECT_LE(mlmcSeriell->TotalError(), epsilon);
EXPECT_LE(mlmcParallel->TotalError(), epsilon); EXPECT_LE(mlmcParallel->TotalError(), epsilon);
} }
......
...@@ -8,29 +8,26 @@ ...@@ -8,29 +8,26 @@
class TestMultilevelMonteCarlo : public TestWithParam<TestParams> { class TestMultilevelMonteCarlo : public TestWithParam<TestParams> {
protected: protected:
double epsilon = 0.003;
Levels levels{3, 4, 5}; Levels levels{3, 4, 5};
Samples samples{12, 6, 3}; Samples samples;
double epsilon;
MeshesCreator meshesCreator; MeshesCreator meshesCreator;
PDESolverCreator pdeSolverCreator; PDESolverCreator pdeSolverCreator;
EstimatorMap estMapSeriell;
EstimatorMap estMapParallel;
std::unique_ptr<Estimator> mlmcSeriell; std::unique_ptr<Estimator> mlmcSeriell;
std::unique_ptr<Estimator> mlmcParallel; std::unique_ptr<Estimator> mlmcParallel;
double MeanTolerance() { return mlmcSeriell->TotalError(); } double MeanTol() { return epsilon; }
double SVarTolerance() { return mlmcSeriell->TotalError(); } double SVarTol() { return epsilon; }
TestMultilevelMonteCarlo() : TestMultilevelMonteCarlo(double epsilon, Samples samples) :
samples(samples), epsilon(epsilon),
meshesCreator(MeshesCreator(). meshesCreator(MeshesCreator().
WithDistribute("RCB"). WithDistribute("RCB").
WithoutOverlap()), WithoutOverlap()),
...@@ -56,26 +53,19 @@ protected: ...@@ -56,26 +53,19 @@ protected:
WithInitLevel(levels). WithInitLevel(levels).
WithEpsilon(epsilon). WithEpsilon(epsilon).
WithParallel(true). WithParallel(true).
CreateUnique()) { CreateUnique()) {}
};
mout << GetParam() << endl;
mout.StartBlock("Monte Carlo seriell");
mout << "Start" << endl;
mlmcSeriell->Method();
mout.EndBlock();
mout << endl;
mlmcSeriell->EstimatorResults();
mout.StartBlock("Monte Carlo parallel"); class TestMultilevelMonteCarloWithoutEpsilon : public TestMultilevelMonteCarlo {
mout << "Start" << endl; public:
mlmcParallel->Method(); TestMultilevelMonteCarloWithoutEpsilon() :
mout.EndBlock(); TestMultilevelMonteCarlo(0.0, {100, 100, 100}) {}
mout << endl; };
mlmcParallel->EstimatorResults(); class TestMultilevelMonteCarloWithEpsilon : public TestMultilevelMonteCarlo {
} public:
TestMultilevelMonteCarloWithEpsilon() :
TestMultilevelMonteCarlo(0.003, {12, 6, 3}) {}
}; };
#endif //TESTMULTILEVELMONTECARLO_HPP #endif //TESTMULTILEVELMONTECARLO_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