Commit 809ef236 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

Test refactoring

parent 6dc8d671
......@@ -2,37 +2,44 @@
/*
* Todo: More tests with other pde's.
* Maybe hand 1D problems to Chinmay.
* Test Parallel MonteCarlo against Seriell one
* MonteCarlo tests with epsilon, level such that total error can be met
* Idea: Point mesh for ode's -> Enables parallelized ode solving
*
* Extend this test idea to multilevel test
* Then Extend idea to Collocation
*
* Test of Estimators against each other
*/
INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, TestMonteCarlo, Values(
TestParams{"StochasticDummyScalarGeneratorProblem", "GeneratorValue", "DummyPDESolver"},
TestParams{"StochasticLaplace2DTest", "L2", "LagrangeElliptic"},
TestParams{"StochasticLaplace2DTest", "Outflow", "HybridElliptic"}
// Todo add more test cases
));
TEST_P(TestMonteCarlo, TestMethodOnlyFine) {
EXPECT_NEAR(mcParallel.aggregate.mean.Q, mcSeriell.aggregate.mean.Q, sqrt(1.0 / dM));
EXPECT_NEAR(mcParallel.aggregate.mean.Y, mcSeriell.aggregate.mean.Y, sqrt(1.0 / dM));
EXPECT_NEAR(mcParallel.aggregate.sVar.Q, mcSeriell.aggregate.sVar.Q, sqrt(10.0 / dM));
EXPECT_NEAR(mcParallel.aggregate.sVar.Y, mcSeriell.aggregate.sVar.Y, sqrt(10.0 / dM));
TEST_P(TestMonteCarlo, TestSeriellAgainstParallel) {
EXPECT_NEAR(mcParallel->aggregate.mean.Q, mcSeriell->aggregate.mean.Q, MeanTolerance());
EXPECT_NEAR(mcParallel->aggregate.mean.Y, mcSeriell->aggregate.mean.Y, MeanTolerance());
EXPECT_NEAR(mcParallel->aggregate.sVar.Q, mcSeriell->aggregate.sVar.Q, SVarTolerance());
EXPECT_NEAR(mcParallel->aggregate.sVar.Y, mcSeriell->aggregate.sVar.Y, SVarTolerance());
}
TEST_P(TestMonteCarlo, TestWithEpsilon){
}
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
WithConfigEntry("GeneratorVerbose", 0).
WithConfigEntry("PDESolverVerbose", 0).
WithConfigEntry("NewtonVerbose", 0).
WithConfigEntry("LinearVerbose", 0).
WithConfigEntry("ConfigVerbose", 0).
WithConfigEntry("MeshVerbose", 0).
WithConfigEntry("MainVerbose", 0).
WithConfigEntry("MLMCVerbose", 0).
WithConfigEntry("MCVerbose", 1).
WithParallelListeners().
WithScreenLogging().
WithPPM()
......
......@@ -29,36 +29,57 @@ protected:
int level = 3;
int dM = 1e4;
int samples = 1e4;
MeshesCreator meshesCreator;
PDESolverCreator pdeSolverCreator;
MeshesCreator meshesCreator;
std::unique_ptr<Estimator> mcSeriell;
MonteCarlo mcSeriell;
std::unique_ptr<Estimator> mcParallel;
MonteCarlo mcParallel;
double MeanTolerance() { return sqrt(1.0 / samples); }
double SVarTolerance() { return sqrt(10.0 / samples); }
TestMonteCarlo() :
meshesCreator(MeshesCreator().
WithDistribute("RCB").
WithoutOverlap()),
pdeSolverCreator(PDESolverCreator().
WithProblem(GetParam().problemName).
WithQuantity(GetParam().quantity).
WithModel(GetParam().model)),
meshesCreator(MeshesCreator(pdeSolverCreator.GetMeshName()).
WithDistribute("RCB").
WithoutOverlap()),
mcSeriell(MonteCarlo(level, dM, onlyFine, false, meshesCreator, pdeSolverCreator)),
mcParallel(MonteCarlo(level, dM, onlyFine, true, meshesCreator, pdeSolverCreator)) {
mcSeriell(EstimatorCreator("MonteCarlo").
WithPDESolverCreator(pdeSolverCreator).
WithMeshesCreator(meshesCreator).
WithInitSamples(samples).
WithOnlyFine(onlyFine).
WithInitLevel(level).
WithParallel(false).
CreateUnique()),
mcParallel(EstimatorCreator("MonteCarlo").
WithPDESolverCreator(pdeSolverCreator).
WithMeshesCreator(meshesCreator).
WithInitSamples(samples).
WithOnlyFine(onlyFine).
WithInitLevel(level).
WithParallel(true).
CreateUnique()) {
mout.StartBlock("Monte Carlo seriell");
mout << "Start" << endl;
mcSeriell.Method();
mcSeriell->Method();
mout.EndBlock();
mout << endl;
mout.StartBlock("Monte Carlo parallel");
mout << "Start" << endl;
mcParallel.Method();
mcParallel->Method();
mout.EndBlock();
mout << endl;
}
......
Supports Markdown
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