TestMultilevelMonteCarlo.hpp 1.9 KB
Newer Older
niklas.baumgarten's avatar
niklas.baumgarten committed
1
2
#ifndef TESTMULTILEVELMONTECARLO_HPP
#define TESTMULTILEVELMONTECARLO_HPP
niklas.baumgarten's avatar
niklas.baumgarten committed
3

niklas.baumgarten's avatar
niklas.baumgarten committed
4
5
#include "MultilevelEstimator.hpp"

6
#include "TestMonteCarlo.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
7
8


9
10
11
12
class TestMultilevelMonteCarlo : public TestWithParam<TestParams> {
protected:
  double epsilon = 0.003;

niklas.baumgarten's avatar
niklas.baumgarten committed
13
  Levels levels{3, 4, 5};
14

niklas.baumgarten's avatar
niklas.baumgarten committed
15
  Samples samples{12, 6, 3};
niklas.baumgarten's avatar
niklas.baumgarten committed
16

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
44
45
46
47
48
49
50
  MeshesCreator meshesCreator;

  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()),
niklas.baumgarten's avatar
niklas.baumgarten committed
51

52
53
54
55
56
57
58
59
    mlmcParallel(EstimatorCreator("MultilevelMonteCarlo").
      WithPDESolverCreator(pdeSolverCreator).
      WithMeshesCreator(meshesCreator).
      WithInitSamples(samples).
      WithInitLevel(levels).
      WithEpsilon(epsilon).
      WithParallel(true).
      CreateUnique()) {
niklas.baumgarten's avatar
niklas.baumgarten committed
60

niklas.baumgarten's avatar
niklas.baumgarten committed
61
62
63
64
    mout << GetParam() << endl;

    mout.StartBlock("Monte Carlo seriell");
    mout << "Start" << endl;
65
    mlmcSeriell->Method();
niklas.baumgarten's avatar
niklas.baumgarten committed
66
67
68
69
70
71
72
73
74
75
76
77
    mout.EndBlock();
    mout << endl;

    mlmcSeriell->EstimatorResults();

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

    mlmcParallel->EstimatorResults();
niklas.baumgarten's avatar
niklas.baumgarten committed
78
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
79
80
};

niklas.baumgarten's avatar
niklas.baumgarten committed
81
#endif //TESTMULTILEVELMONTECARLO_HPP