MonteCarlo.hpp 1.77 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;

22
23
    bool onlyFine = false;

24
    Level level;
niklas.baumgarten's avatar
niklas.baumgarten committed
25

26
27
28
29
30
31
32
    Meshes *meshes;

    PDESolver *pdeSolver;

    MatrixGraphs *solMGraphs;

public:
niklas.baumgarten's avatar
niklas.baumgarten committed
33
34
35
36
37
38
    SampleCounter ctr;
    Sums sums;
    Averages avgs;
    Variances vars;
    Kurtosis kurtosis;

39
40
41
42
    MonteCarlo(Level level, int dM, bool onlyFine) :
        level(level), ctr(SampleCounter(dM)), onlyFine(onlyFine) {

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

44
        // Todo make function problemName -> meshes
45
46
47
48
49
        if (problemName.find("1D") != string::npos)
            meshes = MeshesCreator("Interval").
                WithPLevel(level.coarse).
                WithLevel(level.fine).
                Create();
niklas.baumgarten's avatar
niklas.baumgarten committed
50

51
52
53
54
55
        else if (problemName.find("2D") != string::npos)
            meshes = MeshesCreator("Square").
                WithPLevel(level.coarse).
                WithLevel(level.fine).
                Create();
56

57
58
59
60
61
62
63
64
        pdeSolver = PDESolverCreator(*meshes).
            WithProblem(problemName).
            WithModel(modelName).
            WithDegree(degree).
            Create();

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

66
    ~MonteCarlo() {
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
67
68
69
        if (!solMGraphs) delete solMGraphs;
        if (!pdeSolver) delete pdeSolver;
        if (!meshes) delete meshes;
niklas.baumgarten's avatar
niklas.baumgarten committed
70
    }
71

72
    void Method();
niklas.baumgarten's avatar
bug fix    
niklas.baumgarten committed
73
74
75
76
77
78
79

private:
    void method();

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

    void readConfigEntries();
80
81
82
};

#endif //MLMC_MC_HPP