MonteCarlo.hpp 1.9 KB
Newer Older
1
2
3
#ifndef MLMC_MC_HPP
#define MLMC_MC_HPP

niklas.baumgarten's avatar
niklas.baumgarten committed
4
#include "montecarlo/datastructure/EmpiricMeasures.hpp"
5
#include "montecarlo/datastructure/WelfordAggregate.hpp"
6
7
8
#include "pdesolver/PDESolverCreator.hpp"

#include "mesh/MeshesCreator.hpp"
9
10


11
class MonteCarlo {
niklas.baumgarten's avatar
niklas.baumgarten committed
12
protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
13
  int verbose = 1;
14

niklas.baumgarten's avatar
niklas.baumgarten committed
15
  int plotting = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
16

niklas.baumgarten's avatar
niklas.baumgarten committed
17
  bool onlyFine;
18

19
  bool parallel;
20

niklas.baumgarten's avatar
niklas.baumgarten committed
21
  int level;
niklas.baumgarten's avatar
niklas.baumgarten committed
22

niklas.baumgarten's avatar
niklas.baumgarten committed
23
  Meshes *meshes;
24

niklas.baumgarten's avatar
niklas.baumgarten committed
25
  PDESolver *pdeSolver;
26
27

public:
niklas.baumgarten's avatar
niklas.baumgarten committed
28
  WelfordAggregate aggregate;
29

niklas.baumgarten's avatar
niklas.baumgarten committed
30
  Sums sums;
31

niklas.baumgarten's avatar
niklas.baumgarten committed
32
  Averages avgs;
33

niklas.baumgarten's avatar
niklas.baumgarten committed
34
  Variances vars;
35

niklas.baumgarten's avatar
niklas.baumgarten committed
36
  Kurtosis kurtosis;
niklas.baumgarten's avatar
niklas.baumgarten committed
37

niklas.baumgarten's avatar
niklas.baumgarten committed
38
  PDESolverCreator pdeSolverCreator;
39

niklas.baumgarten's avatar
niklas.baumgarten committed
40
  MeshesCreator meshesCreator;
41

42
  SampleID cId;
43

44
  SampleID fId;
niklas.baumgarten's avatar
niklas.baumgarten committed
45

46
  MonteCarlo(int level, int dM, bool onlyFine, bool parallel) :
47
    level(level), onlyFine(onlyFine), parallel(parallel),
niklas.baumgarten's avatar
niklas.baumgarten committed
48
    pdeSolverCreator(PDESolverCreator()),
49
    meshesCreator(MeshesCreator(pdeSolverCreator.GetMeshName())) {
niklas.baumgarten's avatar
niklas.baumgarten committed
50
51
    Init(dM);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
52

53
  MonteCarlo(int level, int dM, bool onlyFine, bool parallel,
niklas.baumgarten's avatar
niklas.baumgarten committed
54
             MeshesCreator meshesCreator, PDESolverCreator pdeCreator) :
55
    level(level), onlyFine(onlyFine), parallel(parallel),
niklas.baumgarten's avatar
niklas.baumgarten committed
56
57
58
59
    pdeSolverCreator(pdeCreator),
    meshesCreator(meshesCreator) {
    Init(dM);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
60

niklas.baumgarten's avatar
niklas.baumgarten committed
61
62
63
64
  void Init(int dM) {
    config.get("MCPlotting", plotting);
    config.get("MCVerbose", verbose);
    config.get("MCParallel", parallel);
niklas.baumgarten's avatar
niklas.baumgarten committed
65

66
67
68
69
70
71
    fId.fLevel = level;
    fId.cLevel = level - 1;
    fId.coarse = false;
    cId.fLevel = level;
    cId.cLevel = level - 1;
    cId.coarse = true;
niklas.baumgarten's avatar
niklas.baumgarten committed
72
73
    aggregate.parallel = parallel;
    aggregate.UpdateSampleCounter(dM);
74
75
76
77
78
79

    meshes = meshesCreator.
      WithCommSplit(aggregate.commSplit).
      WithPLevel(level - 1).
      WithLevel(level).
      Create();
niklas.baumgarten's avatar
niklas.baumgarten committed
80

81
    pdeSolver = pdeSolverCreator.Create(*meshes);
niklas.baumgarten's avatar
niklas.baumgarten committed
82
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
83

niklas.baumgarten's avatar
niklas.baumgarten committed
84
85
86
87
  ~MonteCarlo() {
    if (!pdeSolver) delete pdeSolver;
    if (!meshes) delete meshes;
  }
88

niklas.baumgarten's avatar
niklas.baumgarten committed
89
  void Method();
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
90
91

private:
niklas.baumgarten's avatar
niklas.baumgarten committed
92
  void method();
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
93

niklas.baumgarten's avatar
niklas.baumgarten committed
94
  void computeSampleSolution(int m, SampleID &id, SampleSolution &solution);
95
96
97
};

#endif //MLMC_MC_HPP