TestMultilevelMonteCarlo.cpp 2.47 KB
Newer Older
niklas.baumgarten's avatar
niklas.baumgarten committed
1
#include "TestMultilevelMonteCarlo.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
2
3


niklas.baumgarten's avatar
niklas.baumgarten committed
4
5
INSTANTIATE_TEST_SUITE_P(
  TestMultilevelMonteCarlo, TestMultilevelMonteCarloWithoutEpsilon, Values(
6
  TestParams{"StochasticDummyScalarGeneratorProblem", "FunctionEvaluation", "DummyPDESolver"},
niklas.baumgarten's avatar
niklas.baumgarten committed
7
8
9
10
11
12
  TestParams{"StochasticLaplace2DTest", "L2", "LagrangeElliptic"},
  TestParams{"StochasticLaplace2DTest", "Outflow", "HybridElliptic"}
));



niklas.baumgarten's avatar
niklas.baumgarten committed
13
14
INSTANTIATE_TEST_SUITE_P(
  TestMultilevelMonteCarlo, TestMultilevelMonteCarloWithEpsilon, Values(
niklas.baumgarten's avatar
niklas.baumgarten committed
15
//  TestParams{"StochasticLaplace1D", "L2", "LagrangeElliptic"},
niklas.baumgarten's avatar
niklas.baumgarten committed
16
  TestParams{"StochasticLaplace2D", "L2", "LagrangeElliptic"}
17
18
));

niklas.baumgarten's avatar
niklas.baumgarten committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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());
46
47
}

niklas.baumgarten's avatar
niklas.baumgarten committed
48
49
50
51
52
53
54
55
56
57
58
59
60
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();

61
62
63
64
  EXPECT_LE(mlmcSeriell->TotalError(), epsilon);
  EXPECT_LE(mlmcParallel->TotalError(), epsilon);
}

niklas.baumgarten's avatar
niklas.baumgarten committed
65
66
67
68
int main(int argc, char **argv) {
  return MppTest(
    MppTestBuilder(argc, argv).
      WithConfigEntry("GeneratorVerbose", 0).
niklas.baumgarten's avatar
niklas.baumgarten committed
69
      WithConfigEntry("PDESolverVerbose", 0).
niklas.baumgarten's avatar
niklas.baumgarten committed
70
71
      WithConfigEntry("NewtonVerbose", 0).
      WithConfigEntry("LinearVerbose", 0).
72
73
74
      WithConfigEntry("ConfigVerbose", 0).
      WithConfigEntry("MeshVerbose", 0).
      WithConfigEntry("MainVerbose", 0).
niklas.baumgarten's avatar
niklas.baumgarten committed
75
76
      WithConfigEntry("MLMCVerbose", 1).
      WithConfigEntry("MCVerbose", 1).
niklas.baumgarten's avatar
niklas.baumgarten committed
77
78
79
80
      WithScreenLogging().
      WithPPM()
  ).RUN_ALL_MPP_TESTS();
}