TestMonteCarlo.cpp 2.24 KB
Newer Older
1
#include "TestMonteCarlo.hpp"
2
3


niklas.baumgarten's avatar
niklas.baumgarten committed
4
INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, TestMonteCarloWithoutEpsilon, Values(
5
  TestParams{"ScalarGeneratorProblem", "FunctionEvaluation", "DummyPDESolver"},
niklas.baumgarten's avatar
niklas.baumgarten committed
6
7
8
9
10
11
  TestParams{"StochasticLaplace2DTest", "L2", "LagrangeElliptic"},
  TestParams{"StochasticLaplace2DTest", "Outflow", "HybridElliptic"}
  // Todo add more test cases
));

INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, TestMonteCarloWithEpsilon, Values(
12
  TestParams{"ScalarGeneratorProblem", "FunctionEvaluation", "DummyPDESolver"},
13
14
  TestParams{"StochasticLaplace2DTest", "L2", "LagrangeElliptic"},
  TestParams{"StochasticLaplace2DTest", "Outflow", "HybridElliptic"}
niklas.baumgarten's avatar
niklas.baumgarten committed
15
  // Todo add more test cases
niklas.baumgarten's avatar
niklas.baumgarten committed
16
));
niklas.baumgarten's avatar
niklas.baumgarten committed
17

niklas.baumgarten's avatar
niklas.baumgarten committed
18
19
20
21
22
23
24
25
26
TEST_P(TestMonteCarloWithoutEpsilon, TestSeriellAgainstParallel) {
  mout << GetParam() << endl;

  mout.StartBlock("Monte Carlo seriell");
  mout << "Start" << endl;
  mcSeriell->Method();
  mout.EndBlock();
  mout << endl;

niklas.baumgarten's avatar
logging    
niklas.baumgarten committed
27
28
  mcSeriell->EstimatorResults();

niklas.baumgarten's avatar
niklas.baumgarten committed
29
30
31
32
33
34
  mout.StartBlock("Monte Carlo parallel");
  mout << "Start" << endl;
  mcParallel->Method();
  mout.EndBlock();
  mout << endl;

niklas.baumgarten's avatar
logging    
niklas.baumgarten committed
35
36
  mcParallel->EstimatorResults();

niklas.baumgarten's avatar
niklas.baumgarten committed
37
38
39
40
41
42
  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());
}

niklas.baumgarten's avatar
niklas.baumgarten committed
43
44
TEST_P(TestMonteCarloWithEpsilon, TestWithEpsilon){
  mout << GetParam() << endl;
niklas.baumgarten's avatar
niklas.baumgarten committed
45

niklas.baumgarten's avatar
niklas.baumgarten committed
46
47
48
49
50
  mout.StartBlock("Monte Carlo parallel");
  mout << "Start" << endl;
  mcParallel->Method();
  mout.EndBlock();
  mout << endl;
niklas.baumgarten's avatar
logging    
niklas.baumgarten committed
51
52

  mcParallel->EstimatorResults();
niklas.baumgarten's avatar
niklas.baumgarten committed
53
}
54
55

int main(int argc, char **argv) {
niklas.baumgarten's avatar
niklas.baumgarten committed
56
57
  return MppTest(
    MppTestBuilder(argc, argv).
niklas.baumgarten's avatar
niklas.baumgarten committed
58
      WithConfigEntry("GeneratorVerbose", 0).
niklas.baumgarten's avatar
niklas.baumgarten committed
59
      WithConfigEntry("PDESolverVerbose", 0).
niklas.baumgarten's avatar
niklas.baumgarten committed
60
      WithConfigEntry("NewtonVerbose", 0).
niklas.baumgarten's avatar
niklas.baumgarten committed
61
      WithConfigEntry("LinearVerbose", 0).
niklas.baumgarten's avatar
niklas.baumgarten committed
62
63
64
65
66
      WithConfigEntry("ConfigVerbose", 0).
      WithConfigEntry("MeshVerbose", 0).
      WithConfigEntry("MainVerbose", 0).
      WithConfigEntry("MLMCVerbose", 0).
      WithConfigEntry("MCVerbose", 1).
niklas.baumgarten's avatar
niklas.baumgarten committed
67
68
69
70
      WithParallelListeners().
      WithScreenLogging().
      WithPPM()
  ).RUN_ALL_MPP_TESTS();
71
}