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

4
#include "montecarlo/datastructure/WelfordAggregate.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
17
  int level;

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

20
  bool parallel;
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
  PDESolverCreator pdeSolverCreator;
28

niklas.baumgarten's avatar
niklas.baumgarten committed
29
  MeshesCreator meshesCreator;
30

niklas.baumgarten's avatar
niklas.baumgarten committed
31
32
  WelfordAggregate aggregate;

33
  SampleID cId;
34

35
  SampleID fId;
niklas.baumgarten's avatar
niklas.baumgarten committed
36

37
  MonteCarlo(int level, int dM, bool onlyFine, bool parallel) :
38
    level(level), onlyFine(onlyFine), parallel(parallel),
niklas.baumgarten's avatar
niklas.baumgarten committed
39
    pdeSolverCreator(PDESolverCreator()),
40
    meshesCreator(MeshesCreator(pdeSolverCreator.GetMeshName())) {
niklas.baumgarten's avatar
niklas.baumgarten committed
41
42
    Init(dM);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
43

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

niklas.baumgarten's avatar
niklas.baumgarten committed
52
53
54
55
  void Init(int dM) {
    config.get("MCPlotting", plotting);
    config.get("MCVerbose", verbose);
    config.get("MCParallel", parallel);
niklas.baumgarten's avatar
niklas.baumgarten committed
56

57
58
59
60
61
62
    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
63
64
    aggregate.parallel = parallel;
    aggregate.UpdateSampleCounter(dM);
65
66
67
68
69
70

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

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

niklas.baumgarten's avatar
niklas.baumgarten committed
75
76
77
78
  ~MonteCarlo() {
    if (!pdeSolver) delete pdeSolver;
    if (!meshes) delete meshes;
  }
79

niklas.baumgarten's avatar
niklas.baumgarten committed
80
  void Method();
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
81
82

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

niklas.baumgarten's avatar
niklas.baumgarten committed
85
  void computeSampleSolution(int m, SampleID &id, SampleSolution &solution);
86
87
88
};

#endif //MLMC_MC_HPP