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

started with multilevel test

parent 92337c7d
Pipeline #149572 failed with stages
in 17 minutes and 27 seconds
#include "TestMultilevelMonteCarlo.hpp" #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
));
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(TestMultilevelMonteCarlo, TestWithEpsilon) {
EXPECT_LE(mlmcSeriell->TotalError(), epsilon);
EXPECT_LE(mlmcParallel->TotalError(), epsilon);
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
return MppTest( return MppTest(
MppTestBuilder(argc, argv). MppTestBuilder(argc, argv).
WithConfigEntry("Model", "LagrangeElliptic").
WithConfigEntry("Quantity", "L2").
WithConfigEntry("degree", 1).
WithConfigEntry("maxLevel", 8).
WithConfigEntry("MCParallel", false).
WithConfigEntry("StochasticField", "LogNormal").
WithConfigEntry("lambda", "[0.15, 0.15]").
WithConfigEntry("Mean", 0.0).
WithConfigEntry("sigma", 1.0).
WithConfigEntry("smoothing", 1.8).
WithConfigEntry("PDESolverPlotting", 1).
WithConfigEntry("GeneratorVerbose", 0). WithConfigEntry("GeneratorVerbose", 0).
WithConfigEntry("PDESolverVerbose", 0). WithConfigEntry("PDESolverVerbose", 0).
WithConfigEntry("NewtonVerbose", 0). WithConfigEntry("NewtonVerbose", 0).
WithConfigEntry("LinearVerbose", 0). WithConfigEntry("LinearVerbose", 0).
WithConfigEntry("ConfigVerbose", 1). WithConfigEntry("ConfigVerbose", 0).
WithConfigEntry("MeshVerbose", 1). WithConfigEntry("MeshVerbose", 0).
WithConfigEntry("MainVerbose", 1). WithConfigEntry("MainVerbose", 0).
WithConfigEntry("MLMCVerbose", 1). WithConfigEntry("MLMCVerbose", 0).
WithConfigEntry("MCVerbose", 1). WithConfigEntry("MCVerbose", 0).
WithScreenLogging(). WithScreenLogging().
WithPPM() WithPPM()
).RUN_ALL_MPP_TESTS(); ).RUN_ALL_MPP_TESTS();
......
...@@ -3,24 +3,62 @@ ...@@ -3,24 +3,62 @@
#include "MultilevelEstimator.hpp" #include "MultilevelEstimator.hpp"
#include "TestEnvironment.hpp" #include "TestMonteCarlo.hpp"
struct TestParams { class TestMultilevelMonteCarlo : public TestWithParam<TestParams> {
protected:
double epsilon = 0.003;
Levels levels{3, 4, 5}; Levels levels{3, 4, 5};
Samples samples{12, 6, 3}; Samples samples{12, 6, 3};
};
class TestMultilevelMonteCarlo : public TestWithParam<TestParams> { MeshesCreator meshesCreator;
protected:
EstimatorMap estimatorMap; PDESolverCreator pdeSolverCreator;
EstimatorMap estMapSeriell;
EstimatorMap estMapParallel;
std::unique_ptr<Estimator> mlmcSeriell;
std::unique_ptr<Estimator> mlmcParallel;
double MeanTolerance() { return mlmcSeriell->TotalError(); }
double SVarTolerance() { return mlmcSeriell->TotalError(); }
TestMultilevelMonteCarlo() :
meshesCreator(MeshesCreator().
WithDistribute("RCB").
WithoutOverlap()),
pdeSolverCreator(PDESolverCreator().
WithProblem(GetParam().problemName).
WithQuantity(GetParam().quantity).
WithModel(GetParam().model)),
mlmcSeriell(EstimatorCreator("MultilevelMonteCarlo").
WithPDESolverCreator(pdeSolverCreator).
WithMeshesCreator(meshesCreator).
WithInitSamples(samples).
WithInitLevel(levels).
WithEpsilon(epsilon).
WithParallel(false).
CreateUnique()),
MultilevelEstimator mlmc; mlmcParallel(EstimatorCreator("MultilevelMonteCarlo").
WithPDESolverCreator(pdeSolverCreator).
WithMeshesCreator(meshesCreator).
WithInitSamples(samples).
WithInitLevel(levels).
WithEpsilon(epsilon).
WithParallel(true).
CreateUnique()) {
TestMultilevelMonteCarlo() { mlmcSeriell->Method();
CreateMonteCarloMap(estimatorMap, GetParam().levels, GetParam().samples);
mlmc = MultilevelEstimator(estimatorMap);
mlmc.Method();
} }
}; };
......
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