StochasticTransportProblem.hpp 11.5 KB
Newer Older
1
2
3
#ifndef MLMC_STOCHASTICTRANSPORTPROBLEM_HPP
#define MLMC_STOCHASTICTRANSPORTPROBLEM_HPP

niklas.baumgarten's avatar
niklas.baumgarten committed
4
#include "problems/IStochasticProblem.hpp"
5

6

niklas.baumgarten's avatar
niklas.baumgarten committed
7
class IStochasticTransportProblem : public IStochasticProblem {
8
9
10
private:
    bool rhs = true;

11
public:
12
13
    IStochasticTransportProblem(Meshes &meshes, GeneratorNames genNames = {})
        : IStochasticProblem(meshes, genNames) {}
14

15
16
    bool RHS() const { return rhs; }

niklas.baumgarten's avatar
niklas.baumgarten committed
17
    // Todo rmv
18
19
    virtual bool Dirichlet(const Point &x) const { return false; }

niklas.baumgarten's avatar
niklas.baumgarten committed
20
    virtual Scalar Solution(double t, const Point &x) const = 0;
21

niklas.baumgarten's avatar
niklas.baumgarten committed
22
23
    // Todo cell and point necessary?
    virtual VectorField CellFlux(const cell &c, const Point &x) const = 0;
24

niklas.baumgarten's avatar
niklas.baumgarten committed
25
26
27
    // Todo cell and point necessary?
    virtual Scalar FaceNormalFlux(const cell &c, int face, const VectorField &N,
                                  const Point &x) const = 0;
28
29
};

niklas.baumgarten's avatar
niklas.baumgarten committed
30
class StochasticPollution1D : public IStochasticTransportProblem {
niklas.baumgarten's avatar
niklas.baumgarten committed
31
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
32
    StochasticPollution1D(Meshes &meshes) :
33
        IStochasticTransportProblem(meshes, GeneratorNames{"HybridFluxGenerator"}) {}
34

niklas.baumgarten's avatar
niklas.baumgarten committed
35
36
37
    Scalar Solution(double t, const Point &x) const override {
        if (abs(1.0 * t - x[0] + 0.5) > 0.06251) return 0.0;
        return 1.0;
niklas.baumgarten's avatar
niklas.baumgarten committed
38
39
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
40
    VectorField CellFlux(const cell &c, const Point &x) const override {
41
        return this->genContainer.vectorFieldGenerator->EvalSample(c);
niklas.baumgarten's avatar
niklas.baumgarten committed
42
    }
niklas.baumgarten's avatar
niklas.baumgarten committed
43

niklas.baumgarten's avatar
niklas.baumgarten committed
44
45
    Scalar FaceNormalFlux(const cell &c, int face, const VectorField &N,
                          const Point &x) const override {
46
        return this->genContainer.scalarGenerator->EvalSample(face, c);
niklas.baumgarten's avatar
niklas.baumgarten committed
47
48
49
    }

    string Name() const override { return "StochasticPollution1D"; }
50
};
niklas.baumgarten's avatar
niklas.baumgarten committed
51

niklas.baumgarten's avatar
niklas.baumgarten committed
52
class StochasticPollutionCosHat1D : public IStochasticTransportProblem {
niklas.baumgarten's avatar
niklas.baumgarten committed
53
54
55
56
57
private:
    double amplitude = 1.00;
    double cc = 6.0;

public:
niklas.baumgarten's avatar
niklas.baumgarten committed
58
    StochasticPollutionCosHat1D(Meshes &meshes) :
59
        IStochasticTransportProblem(meshes, GeneratorNames{"HybridFluxGenerator"}) {}
niklas.baumgarten's avatar
niklas.baumgarten committed
60

niklas.baumgarten's avatar
niklas.baumgarten committed
61
    Scalar Solution(double t, const Point &x) const override {
niklas.baumgarten's avatar
niklas.baumgarten committed
62
63
        Point midPoint = Point(0.2, 0.0);
        double r = dist(midPoint, x);
niklas.baumgarten's avatar
niklas.baumgarten committed
64
65
66
67
        if (r < 1 / cc)
            return amplitude * pow(cos(cc * Pi * r) + 1.0, 2.0);
        return 0.0;
    }
niklas.baumgarten's avatar
niklas.baumgarten committed
68

niklas.baumgarten's avatar
niklas.baumgarten committed
69
    VectorField CellFlux(const cell &c, const Point &x) const override {
70
        return this->genContainer.vectorFieldGenerator->EvalSample(c);
niklas.baumgarten's avatar
niklas.baumgarten committed
71
72
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
73
74
    Scalar FaceNormalFlux(const cell &c, int face,
                          const VectorField &N, const Point &x) const override {
75
        return this->genContainer.scalarGenerator->EvalSample(face, c);
niklas.baumgarten's avatar
niklas.baumgarten committed
76
77
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
78
    string Name() const override { return "StochasticPollutionCosHat1D"; }
niklas.baumgarten's avatar
niklas.baumgarten committed
79
80
};

niklas.baumgarten's avatar
niklas.baumgarten committed
81
82
83
84
class StochasticPollution2D : public IStochasticTransportProblem {
private:
    double d = 1.0 / 16.0;

85
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
86
    StochasticPollution2D(Meshes &meshes) :
87
        IStochasticTransportProblem(meshes, GeneratorNames{"HybridFluxGenerator"}) {}
niklas.baumgarten's avatar
niklas.baumgarten committed
88
89

    Scalar Solution(double t, const Point &x) const override {
niklas.baumgarten's avatar
niklas.baumgarten committed
90
91
        if ((abs(1 - x[1] - 1.5 * d) < d / 2) && (abs(0.5 - x[0]) < 3 * d))
            return 1.0;
niklas.baumgarten's avatar
niklas.baumgarten committed
92
        return 0.0;
niklas.baumgarten's avatar
niklas.baumgarten committed
93
    }
niklas.baumgarten's avatar
niklas.baumgarten committed
94

niklas.baumgarten's avatar
niklas.baumgarten committed
95
    VectorField CellFlux(const cell &c, const Point &x) const override {
96
        return this->genContainer.vectorFieldGenerator->EvalSample(c);
niklas.baumgarten's avatar
niklas.baumgarten committed
97
98
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
99
100
    Scalar FaceNormalFlux(const cell &c, int face,
                          const VectorField &N, const Point &x) const override {
101
        return this->genContainer.scalarGenerator->EvalSample(face, c);
niklas.baumgarten's avatar
niklas.baumgarten committed
102
103
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
104
    string Name() const override { return "StochasticPollution2D"; }
niklas.baumgarten's avatar
niklas.baumgarten committed
105
106
};

107
108
109
110
111
class CircleWave2D : public IStochasticTransportProblem {
    double aa = 1.00;
    double cc = 0.5;
public:
    explicit CircleWave2D(Meshes &meshes) :
112
        IStochasticTransportProblem(meshes) {
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    }

    double Solution(double t, const Point &x) const override {
        Point midPoint = 5.0 * Point(cos(2. * Pi * t), sin(2. * Pi * t));
        double r = dist(midPoint, x);
        if (r < 1 / cc)
            return aa * pow(cos(cc * Pi * r) + 1.0, 2.0);
        return 0.0;
    }

    bool Dirichlet(const Point &x) const override { return true; }

    VectorField CircleVectorField(const Point &x) const {
        return 2 * Pi * VectorField(-x[1], x[0], 0.0);
    }

    VectorField CellFlux(const cell &c, const Point &x) const override {
        return CircleVectorField(x);
    };

    Scalar FaceNormalFlux(const cell &c, int face, const VectorField &N,
                          const Point &x) const override {
        return CircleVectorField(x) * N;
    };

    string Name() const override { return "CircleWave2D"; }
};

niklas.baumgarten's avatar
niklas.baumgarten committed
141
class StochasticPollutionCosHat2D : public IStochasticTransportProblem {
142
private:
niklas.baumgarten's avatar
niklas.baumgarten committed
143
    double amplitude = 1.00;
144
    double cc = 6.0;
niklas.baumgarten's avatar
niklas.baumgarten committed
145

christian.wieners's avatar
.    
christian.wieners committed
146
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
147
    StochasticPollutionCosHat2D(Meshes &meshes) :
148
        IStochasticTransportProblem(meshes, GeneratorNames{"HybridFluxGenerator1D"}) {}
149

niklas.baumgarten's avatar
niklas.baumgarten committed
150
    double Solution(double t, const Point &x) const override {
151
152
153
        Point midPoint = Point(0.5, 0.8);
        double r = dist(midPoint, x);
        if (r < 1 / cc)
niklas.baumgarten's avatar
niklas.baumgarten committed
154
            return amplitude * pow(cos(cc * Pi * r) + 1.0, 2.0);
155
156
        return 0.0;
    }
christian.wieners's avatar
.    
christian.wieners committed
157

niklas.baumgarten's avatar
niklas.baumgarten committed
158
    VectorField CellFlux(const cell &c, const Point &x) const override {
159
        return this->genContainer.vectorFieldGenerator->EvalSample(c);
niklas.baumgarten's avatar
niklas.baumgarten committed
160
161
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
162
163
    Scalar FaceNormalFlux(const cell &c, int face,
                          const VectorField &N, const Point &x) const override {
164
        return this->genContainer.scalarGenerator->EvalSample(face, c);
niklas.baumgarten's avatar
niklas.baumgarten committed
165
166
167
    }

    string Name() const override { return "StochasticPollutionCosHat2D"; }
niklas.baumgarten's avatar
niklas.baumgarten committed
168
169
};

niklas.baumgarten's avatar
niklas.baumgarten committed
170
class StochasticPollutionMollifiedBar2D : public IStochasticTransportProblem {
171
private:
niklas.baumgarten's avatar
niklas.baumgarten committed
172
    double ee = 0.12, xl = 0.6, yl = 0.05;
niklas.baumgarten's avatar
niklas.baumgarten committed
173
174
175
176
177
178
179
180
    Point midPoint = Point(0.5, 0.8);
    double sh = 1 / (xl * yl + 2 * (xl + yl) * exp(1) * ee * 0.2219969080840397
        + exp(1) * 2 * Pi * ee * ee * 0.0742477533879610);
    Point tl = Point(midPoint[0] - 0.5 * xl, midPoint[1] + 0.5 * yl);
    Point tr = Point(midPoint[0] + 0.5 * xl, midPoint[1] + 0.5 * yl);
    Point br = Point(midPoint[0] + 0.5 * xl, midPoint[1] - 0.5 * yl);
    Point bl = Point(midPoint[0] - 0.5 * xl, midPoint[1] - 0.5 * yl);

181
    double phit(const Point &x, const Point &y) const {
niklas.baumgarten's avatar
niklas.baumgarten committed
182
183
        if (dist(x, y) < ee)
            return sh * exp(1.0) * exp(-1 / (1 - pow(dist(x, y) / ee, 2)));
184
185
        return 0.0;
    }
niklas.baumgarten's avatar
niklas.baumgarten committed
186

187
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
188
    StochasticPollutionMollifiedBar2D(Meshes &meshes) :
189
        IStochasticTransportProblem(meshes, GeneratorNames{"HybridFluxGenerator"}) {}
190

niklas.baumgarten's avatar
niklas.baumgarten committed
191
192
193
    Scalar Solution(double t, const Point &x) const override {
        if (abs(midPoint[0] - x[0]) <= 0.5 * xl &&
            abs(midPoint[1] - x[1]) <= 0.5 * yl) {
194
            return sh;
niklas.baumgarten's avatar
niklas.baumgarten committed
195
        } else if (abs(midPoint[0] - x[0]) <= 0.5 * xl) {
196
197
            Point hp1 = Point(x[0], midPoint[1] - 0.5 * yl);
            Point hp2 = Point(x[0], midPoint[1] + 0.5 * yl);
niklas.baumgarten's avatar
niklas.baumgarten committed
198
            return max(this->phit(x, hp1), this->phit(x, hp2));
niklas.baumgarten's avatar
niklas.baumgarten committed
199
        } else if (abs(midPoint[1] - x[1]) <= 0.5 * yl) {
niklas.baumgarten's avatar
niklas.baumgarten committed
200
201
202
203
204
205
            Point hp1 = Point(midPoint[0] - 0.5 * xl, x[1]);
            Point hp2 = Point(midPoint[0] + 0.5 * xl, x[1]);
            return max(this->phit(x, hp1), this->phit(x, hp2));
        } else
            return max(max(this->phit(x, tl), this->phit(x, tr)),
                       max(this->phit(x, br), this->phit(x, bl)));
206
207
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
208
    VectorField CellFlux(const cell &c, const Point &x) const override {
209
        return this->genContainer.vectorFieldGenerator->EvalSample(c);
niklas.baumgarten's avatar
niklas.baumgarten committed
210
211
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
212
213
    Scalar FaceNormalFlux(const cell &c, int face,
                          const VectorField &N, const Point &x) const override {
214
        return this->genContainer.scalarGenerator->EvalSample(face, c);
niklas.baumgarten's avatar
niklas.baumgarten committed
215
216
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
217
    string Name() const override { return "StochasticPollutionMollifiedBar2D"; }
218
219
};

niklas.baumgarten's avatar
niklas.baumgarten committed
220
class StochasticInitialConditionsTransport1D : public IStochasticTransportProblem {
niklas.baumgarten's avatar
niklas.baumgarten committed
221
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
222
    StochasticInitialConditionsTransport1D(Meshes &meshes) :
223
224
        IStochasticTransportProblem(meshes,
                                    GeneratorNames{"NormalDistributionGenerator"}) {}
niklas.baumgarten's avatar
niklas.baumgarten committed
225

niklas.baumgarten's avatar
niklas.baumgarten committed
226
227
    Scalar Solution(double t, const Point &x) const override {
        if (abs(1.0 * t - x[0] + 0.5) > 0.06251) return 0.0;
niklas.baumgarten's avatar
niklas.baumgarten committed
228
229
230
        return 1.0;
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
231
232
    VectorField CellFlux(const cell &c, const Point &x) const override {
        return VectorField(1, 0, 0);
niklas.baumgarten's avatar
niklas.baumgarten committed
233
234
    }

niklas.baumgarten's avatar
niklas.baumgarten committed
235
236
237
    Scalar FaceNormalFlux(const cell &c, int face,
                          const VectorField &N, const Point &x) const override {
        return VectorField(1, 0, 0) * N;
niklas.baumgarten's avatar
niklas.baumgarten committed
238
239
240
241
242
    }

    string Name() const override { return "RiemannTransport1D"; }
};

243
244
245
class GaussHat2D : public IStochasticTransportProblem {
private:
    VectorField vectorField;
niklas.baumgarten's avatar
niklas.baumgarten committed
246
247
    VectorField mu;
    Tensor sigma;
248
249
250

public:
    GaussHat2D(Meshes &meshes) :
niklas.baumgarten's avatar
niklas.baumgarten committed
251
        mu(VectorField(0.5, 0.5, 0.0)),
niklas.baumgarten's avatar
niklas.baumgarten committed
252
        sigma(Tensor()),
253
        vectorField(VectorField(1 / sqrt(2), 1 / sqrt(2), 0)),
254
        IStochasticTransportProblem(meshes) {
niklas.baumgarten's avatar
niklas.baumgarten committed
255
        sigma[0][0] = 0.01;
niklas.baumgarten's avatar
niklas.baumgarten committed
256
257
        sigma[0][1] = 0.0;
        sigma[1][0] = 0.0;
niklas.baumgarten's avatar
niklas.baumgarten committed
258
        sigma[1][1] = 0.01;
niklas.baumgarten's avatar
niklas.baumgarten committed
259
    }
260
261

    Scalar Solution(double t, const Point &x) const override {
niklas.baumgarten's avatar
niklas.baumgarten committed
262
263
264
        double factor = 1 / sqrt(pow(2 * Pi, 2) * sigma.det());
        VectorField diff = (x - mu);
        VectorField temp = Invert(sigma) * diff;
niklas.baumgarten's avatar
niklas.baumgarten committed
265
        Scalar exponent = -0.5 * diff * temp;
niklas.baumgarten's avatar
niklas.baumgarten committed
266
        return factor * exp(exponent);
267
268
269
270
271
272
273
274
275
276
277
278
279
    }

    VectorField CellFlux(const cell &c, const Point &x) const override {
        return vectorField;
    }

    Scalar FaceNormalFlux(const cell &c, int face,
                          const VectorField &N, const Point &x) const override {
        return vectorField * N;
    }

    string Name() const override { return "GaussHat2D"; }
};
280

281
282
283
284
285
286
287
288
289
290
class StochasticGaussHat2D : public IStochasticTransportProblem {
private:
    double mu = 0.0;
    double sigma = 1.0; // (sigma squared)

    VectorField vectorField;

public:
    StochasticGaussHat2D(Meshes &meshes) :
        vectorField(VectorField(1 / sqrt(2), 1 / sqrt(2), 0)),
291
        IStochasticTransportProblem(meshes) {}
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

    Scalar Solution(double t, const Point &x) const override {
        // Todo 2D Gaussfunction for t = 0
//        1 / (sigma * sqrt(2 * PI)) exp ()
        if (abs(1.0 * t - x[0] + 0.5) > 0.06251) return 0.0;
        return 1.0;
    }

    VectorField CellFlux(const cell &c, const Point &x) const override {
        return vectorField;
    }

    Scalar FaceNormalFlux(const cell &c, int face,
                          const VectorField &N, const Point &x) const override {
        return vectorField * N;
    }

    string Name() const override { return "GaussHat2D"; }
};
311

niklas.baumgarten's avatar
niklas.baumgarten committed
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
//class StochasticInflowTransport1D : public IStochasticTransportProblem {
//public:
//    explicit StochasticInflowTransport1D() {}
//
//    double ut(double t, const Point &x) const override {
//        if (x[0] == 0.0 && x[1] >= 1.0) return 1.0;
//        else return 0.0;
//    }
//
//    string Name() const override { return "InflowTest"; }
//};
//
//class StochasticCircleWave2D : public IStochasticTransportProblem {
//    /*
//     * Todo Idea: create stochastic flux
//     */
//    double aa = 1.00;
//    double cc = 0.5;
//public:
//    StochasticCircleWave2D() {}
//
//    double ut(double t, const Point &x) const override {
//        Point midPoint = 5.0 * Point(cos(2. * Pi * t), sin(2. * Pi * t));
//        double r = dist(midPoint, x);
//        if (r < 1 / cc)
//            return aa * pow(cos(cc * Pi * r) + 1.0, 2.0);
//        return 0.0;
//    }
//
//    bool Dirichlet(const Point &x) const override { return true; }
//
//    VectorField B(const Point &x) const override {
//        return 2 * Pi * VectorField(-x[1], x[0], 0.0);
//    }
//
//    string Name() const override { return "StochasticCircleWave2D"; }
//};
niklas.baumgarten's avatar
niklas.baumgarten committed
349

350
351
352
IStochasticTransportProblem *
CreateStochasticTransportProblem(std::string problemName, Meshes &meshes);

niklas.baumgarten's avatar
niklas.baumgarten committed
353
#endif