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

4
#include "stochastics/StochasticField.h"
niklas.baumgarten's avatar
niklas.baumgarten committed
5
6

#include <utility>
7
#include <utils/MultilevelPlotter.hpp>
8

9

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

niklas.baumgarten's avatar
niklas.baumgarten committed
15
16
    int l = 0;
    int pLevel = 0;
17
    bool onlyFineLevel = true;
18
19
    string functional = "L2";

niklas.baumgarten's avatar
niklas.baumgarten committed
20
21
    Meshes *meshes = nullptr;
    StochasticField *stochasticField = nullptr;
22
23
24

    int M = 0, dM = 0;

25
    double sumCost = 0.0, avgCost = 0.0;
26
    double sumY1 = 0.0, avgY = 0.0;
27
28
29
    double sumY2 = 0.0, avgY2 = 0.0, varY = 0.0;
    double sumY3 = 0.0, avgY3 = 0.0;
    double sumY4 = 0.0, avgY4 = 0.0;
30
    double sumQ1 = 0.0, avgQ = 0.0;
31
    double sumQ2 = 0.0, avgQ2 = 0.0, varQ = 0.0;
32
33
    double kurtosis = 0.0;

34
35
36
    double fineQ = 0.0, coarseQ = 0.0;
    double fineCost = 0.0, coarseCost = 0.0;

niklas.baumgarten's avatar
niklas.baumgarten committed
37
38
    MonteCarlo(int l, int dM, bool onlyFineLevel,
               Meshes *meshes, StochasticField *stochFields) :
39
40
41
        l(l), dM(dM), onlyFineLevel(onlyFineLevel),
        meshes(meshes), pLevel(meshes->pLevel()),
        stochasticField(stochFields) {
42

43
        config.get("MCPlotting", plotting);
44
        config.get("MCVerbose", verbose);
niklas.baumgarten's avatar
niklas.baumgarten committed
45
        config.get("Functional", functional);
niklas.baumgarten's avatar
niklas.baumgarten committed
46
    }
47

48
    void Method();
49

niklas.baumgarten's avatar
niklas.baumgarten committed
50
51
52
53
    void SolvePDE(int l, int m, bool fine,
                  double &valueQ, double &cost,
                  Vector &solution);

niklas.baumgarten's avatar
niklas.baumgarten committed
54
    virtual void Initialize() = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
55

niklas.baumgarten's avatar
niklas.baumgarten committed
56
protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
57
58
    virtual void method() = 0;

niklas.baumgarten's avatar
niklas.baumgarten committed
59
    virtual void solvePDE(int l, int m, bool fine,
niklas.baumgarten's avatar
niklas.baumgarten committed
60
                          double &valueQ, double &cost,
niklas.baumgarten's avatar
niklas.baumgarten committed
61
62
                          Vector &solution) = 0;

63
    void updateSums(double fineCost, double diffQ, double fineQ);
64

65
    void updateAvg();
66

67
    void updateStatistic();
niklas.baumgarten's avatar
niklas.baumgarten committed
68

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

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

73
    string buildName(int m, const string &name, const string &suffix = "");
74
75
76
};

#endif //MLMC_MC_HPP