MonteCarlo.hpp 1.82 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
15
    int plotting = 0;

16
17
    bool onlyFine = false;

18
    Level level;
niklas.baumgarten's avatar
niklas.baumgarten committed
19

20
21
22
23
24
    Meshes *meshes;

    PDESolver *pdeSolver;

public:
niklas.baumgarten's avatar
niklas.baumgarten committed
25
    SampleCounter ctr;
26

niklas.baumgarten's avatar
niklas.baumgarten committed
27
    Sums sums;
28

niklas.baumgarten's avatar
niklas.baumgarten committed
29
    Averages avgs;
30

niklas.baumgarten's avatar
niklas.baumgarten committed
31
    Variances vars;
32

niklas.baumgarten's avatar
niklas.baumgarten committed
33
34
    Kurtosis kurtosis;

35
36
37
38
    PDESolverCreator pdeSolverCreator;

    MeshesCreator meshesCreator;

niklas.baumgarten's avatar
niklas.baumgarten committed
39
    SampleID coarseId;
40

niklas.baumgarten's avatar
niklas.baumgarten committed
41
42
    SampleID fineId;

43
    MonteCarlo(Level level, int dM, bool onlyFine) :
44
45
46
47
48
49
50
51
52
        level(level),
        onlyFine(onlyFine),
        ctr(SampleCounter(dM)),
        pdeSolverCreator(PDESolverCreator()),
        meshesCreator(MeshesCreator(pdeSolverCreator.GetMeshName()).
            WithCommSplit(ctr.commSplit).
            WithPLevel(level.coarse).
            WithLevel(level.fine)) {
        Init();
53
    }
niklas.baumgarten's avatar
niklas.baumgarten committed
54

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

65
66
67
    void Init() {
        config.get("MCPlotting", plotting);
        config.get("MCVerbose", verbose);
niklas.baumgarten's avatar
niklas.baumgarten committed
68

niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
69
        meshes = meshesCreator.Create();
70
        pdeSolver = pdeSolverCreator.Create(*meshes);
niklas.baumgarten's avatar
niklas.baumgarten committed
71
72
73
74
75
76
77

        fineId.level = level;
        fineId.coarse = false;
        coarseId.level = level;
        coarseId.coarse = true;
    }

78
    ~MonteCarlo() {
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
79
80
        if (!pdeSolver) delete pdeSolver;
        if (!meshes) delete meshes;
niklas.baumgarten's avatar
niklas.baumgarten committed
81
    }
82

83
    void Method();
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
84
85
86
87
88

private:
    void method();

    void computeSampleSolution(int m, SampleID &id, SampleSolution &solution);
89
90
91
};

#endif //MLMC_MC_HPP