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