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

4
#include "m++.h"
5
#include "stochastics/StochasticField.h"
6
#include "utils/IndentedLogger.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
7
8
9
#include <sys/stat.h>

#include <utility>
10
#include <utils/MultilevelPlotter.hpp>
11

12

13
class MonteCarlo {
14
15
private:

16
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
17
    int plotting = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
18
19
    Plot *coarsePlot = nullptr;
    Plot *finePlot = nullptr;
20
21
22

    int verbose = 0;
    IndentedLogger *logger = nullptr;
23

niklas.baumgarten's avatar
niklas.baumgarten committed
24
25
    int l = 0;
    int pLevel = 0;
26
    bool onlyFineLevel = true;
27
28
    string functional = "L2";

niklas.baumgarten's avatar
niklas.baumgarten committed
29
30
    Meshes *meshes = nullptr;
    StochasticField *stochasticField = nullptr;
31
32
33

    int M = 0, dM = 0;

34
    double sumCost = 0.0, avgCost = 0.0;
35
    double sumY1 = 0.0, avgY = 0.0;
36
37
38
    double sumY2 = 0.0, avgY2 = 0.0, varY = 0.0;
    double sumY3 = 0.0, avgY3 = 0.0;
    double sumY4 = 0.0, avgY4 = 0.0;
39
    double sumQ1 = 0.0, avgQ = 0.0;
40
    double sumQ2 = 0.0, avgQ2 = 0.0, varQ = 0.0;
41
42
    double kurtosis = 0.0;

43
44
45
    double fineQ = 0.0, coarseQ = 0.0;
    double fineCost = 0.0, coarseCost = 0.0;

46
47
48
49
50
51
    MonteCarlo(int l,
               int dM,
               bool onlyFineLevel,
               Meshes *meshes,
               MultilevelPlotter &plots,
               StochasticField *stochFields) :
52
53
54
        l(l), dM(dM), onlyFineLevel(onlyFineLevel),
        meshes(meshes), pLevel(meshes->pLevel()),
        stochasticField(stochFields) {
55

56
57
        config.get("MCPlotting", plotting);
        config.get("functional", functional);
58

59
60
        coarsePlot = plots.GetPlot(l - 1);
        finePlot = plots.GetPlot(l);
61
62
63

        config.get("MCVerbose", verbose);
        logger = IndentedLogger::GetInstance();
niklas.baumgarten's avatar
niklas.baumgarten committed
64
    }
65

66
    void Method();
67
68

protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
69
70
71
72
    virtual void initialize() = 0;

    virtual void method() = 0;

73
74
75
76
77
    virtual void solvePDE(int l,
                          int m,
                          bool fineLevel,
                          double &valueQ,
                          double &cost,
niklas.baumgarten's avatar
niklas.baumgarten committed
78
79
                          Vector &solution) = 0;

80
    void updateSums(double fineCost, double diffQ, double fineQ);
81

82
    void updateAvg();
83

84
    void updateStatistic();
niklas.baumgarten's avatar
niklas.baumgarten committed
85

86
    string mkSampleDirName(int m, bool fineLevel);
niklas.baumgarten's avatar
niklas.baumgarten committed
87

88
    static void mkSampleDir(int m, const string &sampleDirName);
niklas.baumgarten's avatar
niklas.baumgarten committed
89

90
    string buildName(int m, const string &name, const string &suffix = "");
91
92
93
};

#endif //MLMC_MC_HPP