MonteCarlo.hpp 2.02 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;
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) :
48
    level(level), onlyFine(onlyFine), parallel(parallel),
niklas.baumgarten's avatar
niklas.baumgarten committed
49
    pdeSolverCreator(PDESolverCreator()),
50
    meshesCreator(MeshesCreator(pdeSolverCreator.GetMeshName())) {
niklas.baumgarten's avatar
niklas.baumgarten committed
51
52
    Init(dM);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
53

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

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

niklas.baumgarten's avatar
niklas.baumgarten committed
67
68
69
70
71
72
    fineId.fLevel = level;
    fineId.cLevel = level - 1;
    fineId.coarse = false;
    coarseId.fLevel = level;
    coarseId.cLevel = level - 1;
    coarseId.coarse = true;
73
74
    ctr.parallel = parallel; // todo rmv
    ctr.UpdateSampleCounter(dM); // todo rmv
niklas.baumgarten's avatar
niklas.baumgarten committed
75
76
    aggregate.parallel = parallel;
    aggregate.UpdateSampleCounter(dM);
77
78
79
80
81
82

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

84
    pdeSolver = pdeSolverCreator.Create(*meshes);
niklas.baumgarten's avatar
niklas.baumgarten committed
85
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
86

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

niklas.baumgarten's avatar
niklas.baumgarten committed
92
  void Method();
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
93
94

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

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

#endif //MLMC_MC_HPP