TestMultilevelMonteCarlo.cpp 2.46 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{"ScalarGeneratorProblem", "FunctionEvaluation", "DummyPDESolver"},
niklas.baumgarten's avatar
niklas.baumgarten committed
7
8
9
10
  TestParams{"StochasticLaplace2DTest", "L2", "LagrangeElliptic"},
  TestParams{"StochasticLaplace2DTest", "Outflow", "HybridElliptic"}
));

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

niklas.baumgarten's avatar
niklas.baumgarten committed
17
18
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
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());
44
45
}

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

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