StochasticFields.h 2.11 KB
Newer Older
niklas.baumgarten's avatar
niklas.baumgarten committed
1
2
3
4
5
6
#ifndef M_STOCHASTICFIELD_HPP
#define M_STOCHASTICFIELD_HPP

#include "m++.h"
#include "CirculantEmbedding.h"

7
class StochasticFieldPair {
niklas.baumgarten's avatar
niklas.baumgarten committed
8
public:
9
10
11
12
13
//    const Mesh &coarseMesh;
//    const Mesh &fineMesh;
//
//    StochasticFieldPair(const Mesh &coarseMesh, const Mesh &fineMesh) :
//            coarseMesh(coarseMesh), fineMesh(fineMesh) {}
niklas.baumgarten's avatar
niklas.baumgarten committed
14

15
    StochasticFieldPair() = default;
niklas.baumgarten's avatar
niklas.baumgarten committed
16

17
    virtual void generate() {};
niklas.baumgarten's avatar
niklas.baumgarten committed
18

19
    virtual double getFineValue(const Point &z) const { return 0.0; };
niklas.baumgarten's avatar
niklas.baumgarten committed
20

21
    virtual double getCoarseValue(const Point &z) const { return 0.0; };
niklas.baumgarten's avatar
niklas.baumgarten committed
22

23
24
25
    virtual pair<double, double> getFineMinMaxValues() const {
        return {0.0, 0.0};
    };
niklas.baumgarten's avatar
niklas.baumgarten committed
26

27
28
29
    virtual pair<double, double> getCoarseMinMaxValues() const {
        return {0.0, 0.0};
    };
niklas.baumgarten's avatar
niklas.baumgarten committed
30
31
};

niklas.baumgarten's avatar
niklas.baumgarten committed
32
StochasticFieldPair *getStochasticFieldPair(int l, int dim, string fieldName);
niklas.baumgarten's avatar
niklas.baumgarten committed
33

34
35
class StochasticFields {
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
36
    const string &fieldName;
37
    int currentLevel;
niklas.baumgarten's avatar
niklas.baumgarten committed
38
    bool fineField = true;
39
40
    map<int, StochasticFieldPair *> stochFieldPairs;

niklas.baumgarten's avatar
niklas.baumgarten committed
41
42
    explicit StochasticFields(const string &fieldName, Meshes &meshes) :
            fieldName(fieldName), currentLevel(meshes.pLevel()) {
43
        for (int l = meshes.pLevel(); l <= meshes.Level(); l++) {
niklas.baumgarten's avatar
niklas.baumgarten committed
44
            stochFieldPairs[l] = getStochasticFieldPair(l, meshes.dim(), fieldName);
niklas.baumgarten's avatar
niklas.baumgarten committed
45
46
47
        }
    }

48
49
50
    ~StochasticFields() {
        for (auto &iter : stochFieldPairs)
            delete iter.second;
niklas.baumgarten's avatar
niklas.baumgarten committed
51
52
    }

53
54
    void generate() {
        stochFieldPairs[currentLevel]->generate();
niklas.baumgarten's avatar
niklas.baumgarten committed
55
56
    }

57
58
59
60
61
62
63
    double getValue(const Point &z) {
        if (fineField)
            return stochFieldPairs[currentLevel]->getFineValue(z);
        else
            return stochFieldPairs[currentLevel]->getCoarseValue(z);
    };

niklas.baumgarten's avatar
niklas.baumgarten committed
64
65
    virtual pair<double, double> getMinMaxValues(bool _fineField) {
        if (_fineField)
66
67
68
69
70
71
72
            return stochFieldPairs[currentLevel]->getFineMinMaxValues();
        else
            return stochFieldPairs[currentLevel]->getCoarseMinMaxValues();
    };

    void setCurrentLevel(int l) {
        currentLevel = l;
niklas.baumgarten's avatar
niklas.baumgarten committed
73
74
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
75
76
    void setFineField(bool _fineField) {
        fineField = _fineField;
niklas.baumgarten's avatar
niklas.baumgarten committed
77
78
79
80
    }
};

#endif //M_STOCHASTICFIELD_HPP