MonteCarlo.hpp 1.97 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

niklas.baumgarten's avatar
niklas.baumgarten committed
18
  bool parallel = true;
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

niklas.baumgarten's avatar
niklas.baumgarten committed
47
48
49
50
51
52
53
54
55
56
  MonteCarlo(int level, int dM, bool onlyFine) :
    level(level),
    onlyFine(onlyFine),
    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
57

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

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

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

niklas.baumgarten's avatar
niklas.baumgarten committed
75
76
77
78
79
80
81
82
83
84
85
    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
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