MonteCarlo.hpp 1.71 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
18
19
20
21
    std::string problemName = "DummyStochasticProblem1D";

    std::string modelName = "DummyPDESolver";

    int degree = 1;

niklas.baumgarten's avatar
niklas.baumgarten committed
22
public:
23
    Level level;
niklas.baumgarten's avatar
niklas.baumgarten committed
24
    bool onlyFine;
niklas.baumgarten's avatar
niklas.baumgarten committed
25
26
27
28
29
30
31

    SampleCounter ctr;
    Sums sums;
    Averages avgs;
    Variances vars;
    Kurtosis kurtosis;

32
    Meshes *meshes;
niklas.baumgarten's avatar
niklas.baumgarten committed
33
    PDESolver *pdeSolver;
34
    MatrixGraphs *solMGraphs;
35

36
37
38
39
    MonteCarlo(Level level, int dM, bool onlyFine) :
        level(level), ctr(SampleCounter(dM)), onlyFine(onlyFine) {

        readConfigEntries();
niklas.baumgarten's avatar
niklas.baumgarten committed
40

41
42
43
44
45
        if (problemName.find("1D") != string::npos)
            meshes = MeshesCreator("Interval").
                WithPLevel(level.coarse).
                WithLevel(level.fine).
                Create();
niklas.baumgarten's avatar
niklas.baumgarten committed
46

47
48
49
50
51
        else if (problemName.find("2D") != string::npos)
            meshes = MeshesCreator("Square").
                WithPLevel(level.coarse).
                WithLevel(level.fine).
                Create();
52

53
54
55
56
57
58
59
60
        pdeSolver = PDESolverCreator(*meshes).
            WithProblem(problemName).
            WithModel(modelName).
            WithDegree(degree).
            Create();

        solMGraphs = pdeSolver->CreateSolutionMatrixGraphs(*meshes);
    }
niklas.baumgarten's avatar
niklas.baumgarten committed
61

62
    ~MonteCarlo() {
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
63
64
65
        if (!solMGraphs) delete solMGraphs;
        if (!pdeSolver) delete pdeSolver;
        if (!meshes) delete meshes;
niklas.baumgarten's avatar
niklas.baumgarten committed
66
    }
67

68
    void Method();
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
69
70
71
72
73
74
75

private:
    void method();

    void computeSampleSolution(int m, SampleID &id, SampleSolution &solution);

    void readConfigEntries();
76
77
78
};

#endif //MLMC_MC_HPP