MonteCarlo.hpp 2.04 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
6
7
#include "pdesolver/PDESolverCreator.hpp"

#include "mesh/MeshesCreator.hpp"
8
9


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

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

niklas.baumgarten's avatar
niklas.baumgarten committed
16
  bool onlyFine = false;
17

18
  bool parallel;
19

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

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

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

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

niklas.baumgarten's avatar
niklas.baumgarten committed
29
  SampleCounter ctr; // todo remove, is still here for test
30

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

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

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

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

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

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

niklas.baumgarten's avatar
niklas.baumgarten committed
43
  SampleID coarseId;
44

niklas.baumgarten's avatar
niklas.baumgarten committed
45
  SampleID fineId;
niklas.baumgarten's avatar
niklas.baumgarten committed
46

47
  MonteCarlo(int level, int dM, bool onlyFine, bool parallel) :
niklas.baumgarten's avatar
niklas.baumgarten committed
48
49
    level(level),
    onlyFine(onlyFine),
50
    parallel(parallel),
niklas.baumgarten's avatar
niklas.baumgarten committed
51
52
53
54
55
56
57
    pdeSolverCreator(PDESolverCreator()),
    meshesCreator(MeshesCreator(pdeSolverCreator.GetMeshName()).
      WithCommSplit(aggregate.commSplit). // Todo: Is this correct?
      WithPLevel(level - 1).
      WithLevel(level)) {
    Init(dM);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
58

59
  MonteCarlo(int level, int dM, bool onlyFine, bool parallel,
niklas.baumgarten's avatar
niklas.baumgarten committed
60
61
62
             MeshesCreator meshesCreator, PDESolverCreator pdeCreator) :
    level(level),
    onlyFine(onlyFine),
63
    parallel(parallel),
niklas.baumgarten's avatar
niklas.baumgarten committed
64
65
66
67
    pdeSolverCreator(pdeCreator),
    meshesCreator(meshesCreator) {
    Init(dM);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
68

niklas.baumgarten's avatar
niklas.baumgarten committed
69
70
71
72
  void Init(int dM) {
    config.get("MCPlotting", plotting);
    config.get("MCVerbose", verbose);
    config.get("MCParallel", parallel);
niklas.baumgarten's avatar
niklas.baumgarten committed
73

niklas.baumgarten's avatar
niklas.baumgarten committed
74
75
    meshes = meshesCreator.Create();
    pdeSolver = pdeSolverCreator.Create(*meshes);
niklas.baumgarten's avatar
niklas.baumgarten committed
76

niklas.baumgarten's avatar
niklas.baumgarten committed
77
78
79
80
81
82
83
84
85
86
87
    fineId.fLevel = level;
    fineId.cLevel = level - 1;
    fineId.coarse = false;
    coarseId.fLevel = level;
    coarseId.cLevel = level - 1;
    coarseId.coarse = true;
    ctr.parallel = parallel;
    ctr.UpdateSampleCounter(dM);
    aggregate.parallel = parallel;
    aggregate.UpdateSampleCounter(dM);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
88

niklas.baumgarten's avatar
niklas.baumgarten committed
89
90
91
92
  ~MonteCarlo() {
    if (!pdeSolver) delete pdeSolver;
    if (!meshes) delete meshes;
  }
93

niklas.baumgarten's avatar
niklas.baumgarten committed
94
  void Method();
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
95
96

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

niklas.baumgarten's avatar
niklas.baumgarten committed
99
  void computeSampleSolution(int m, SampleID &id, SampleSolution &solution);
100
101
102
};

#endif //MLMC_MC_HPP