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

4
#include "main/MultilevelPlotter.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
5
#include "EmpiricMeasures.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
6
#include "PDESolver.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
7
#include "Sample.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
8
#include "assemble/IStochasticAssemble.hpp"
9
10


11
class MonteCarlo {
niklas.baumgarten's avatar
niklas.baumgarten committed
12
protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
13
    int plotting = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
14
    int verbose = 1;
15

niklas.baumgarten's avatar
niklas.baumgarten committed
16
    virtual void method();
17

niklas.baumgarten's avatar
niklas.baumgarten committed
18
19
    void findSampleSolution(int m, SampleID &id, SampleSolution &solution);

niklas.baumgarten's avatar
niklas.baumgarten committed
20
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
21
22
23
    int level;
    int pLevel;
    bool onlyFine;
niklas.baumgarten's avatar
niklas.baumgarten committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

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

    IStochasticAssemble *assemble;
    PDESolver *pdeSolver;

    MatrixGraphs solMGraphs;
    SampleID coarseId;
    SampleID fineId;
    SampleSolution coarseSolution;
    SampleSolution fineSolution;

    MonteCarlo(int level,
               int dM,
               bool onlyFine,
               Meshes &meshes,
               IStochasticAssemble *assemble,
               PDESolver *pdeSolver) :
        level(level), onlyFine(onlyFine),
        assemble(assemble), pdeSolver(pdeSolver),
        solMGraphs(MatrixGraphs(meshes, *assemble->GetDiscretization())),
niklas.baumgarten's avatar
niklas.baumgarten committed
49
50
        coarseSolution(SampleSolution(solMGraphs, level - meshes.pLevel() - 1)),
        fineSolution(SampleSolution(solMGraphs, level - meshes.pLevel())) {
51

52
        config.get("MCPlotting", plotting);
53
        config.get("MCVerbose", verbose);
niklas.baumgarten's avatar
niklas.baumgarten committed
54
55
56
57

        ctr.dM = dM;
        fineId.level = level;
        fineId.coarse = false;
niklas.baumgarten's avatar
niklas.baumgarten committed
58
        coarseId.level = level;
niklas.baumgarten's avatar
niklas.baumgarten committed
59
        coarseId.coarse = true;
niklas.baumgarten's avatar
niklas.baumgarten committed
60
    }
61

62
63
    virtual ~MonteCarlo() {};

64
    void Method();
65
66
67
};

#endif //MLMC_MC_HPP