StochasticEllipticProblem.hpp 4.4 KB
Newer Older
niklas.baumgarten's avatar
niklas.baumgarten committed
1
2
#ifndef STOCHASTICELLIPTICPROBLEM_HPP
#define STOCHASTICELLIPTICPROBLEM_HPP
3

4
#include "IStochasticProblem.hpp"
5
6


niklas.baumgarten's avatar
niklas.baumgarten committed
7
class IStochasticEllipticProblem : public IStochasticProblem {
8
public:
9
10
  explicit IStochasticEllipticProblem(const Meshes &meshes) :
    IStochasticProblem(meshes) {}
niklas.baumgarten's avatar
niklas.baumgarten committed
11

niklas.baumgarten's avatar
niklas.baumgarten committed
12
  virtual Scalar Solution(const Point &x) const = 0;
13

niklas.baumgarten's avatar
niklas.baumgarten committed
14
  virtual VectorField Flux(const Point &x) const = 0;
15

niklas.baumgarten's avatar
niklas.baumgarten committed
16
  virtual Scalar Load(const Point &x) const = 0;
17

niklas.baumgarten's avatar
niklas.baumgarten committed
18
  virtual Tensor Permeability(const cell &c) const = 0;
19

20
  void Permeability(Vector &kappa) const {
21
22
23
    for (cell c = kappa.cells(); c != kappa.cells_end(); ++c)
      kappa(c(), 0) = Permeability(c)[0][0];
  }
24
25
};

niklas.baumgarten's avatar
niklas.baumgarten committed
26
class StochasticLaplace1D : public IStochasticEllipticProblem {
27
  CirculantEmbedding1D tensorGenerator;
28
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
29
  explicit StochasticLaplace1D(const Meshes &meshes) :
30
31
32
33
34
35
    IStochasticEllipticProblem(meshes),
    tensorGenerator(CirculantEmbedding1D(meshes)) {};

  void DrawSample(const SampleID &id) override {
    tensorGenerator.DrawSample(id);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
36

niklas.baumgarten's avatar
niklas.baumgarten committed
37
38
39
  Scalar Solution(const Point &x) const override {
    return 1 - x[0];
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
40

niklas.baumgarten's avatar
niklas.baumgarten committed
41
42
43
  VectorField Flux(const Point &x) const override {
    return VectorField(1.0, 0.0);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
44

niklas.baumgarten's avatar
niklas.baumgarten committed
45
46
47
  Scalar Load(const Point &x) const override {
    return 0.0;
  }
48

niklas.baumgarten's avatar
niklas.baumgarten committed
49
  Tensor Permeability(const cell &c) const override {
50
    return this->tensorGenerator.EvalSample(c);
niklas.baumgarten's avatar
niklas.baumgarten committed
51
  }
52

niklas.baumgarten's avatar
niklas.baumgarten committed
53
  string Name() const override { return "StochasticLaplace1D"; }
niklas.baumgarten's avatar
niklas.baumgarten committed
54
55
};

56
57
class Laplace1D : public IStochasticEllipticProblem {
public:
58
59
60
61
  explicit Laplace1D(const Meshes &meshes) :
    IStochasticEllipticProblem(meshes) {};

  void DrawSample(const SampleID &id) override {}
62

niklas.baumgarten's avatar
niklas.baumgarten committed
63
64
65
  Scalar Solution(const Point &x) const override {
    return 1 - x[0];
  }
66

niklas.baumgarten's avatar
niklas.baumgarten committed
67
68
69
  VectorField Flux(const Point &x) const override {
    return VectorField(-1.0, 0.0);
  }
70

niklas.baumgarten's avatar
niklas.baumgarten committed
71
72
73
  Scalar Load(const Point &x) const override {
    return 0.0;
  }
74

niklas.baumgarten's avatar
niklas.baumgarten committed
75
76
77
  Tensor Permeability(const cell &c) const override {
    return One;
  }
78

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

niklas.baumgarten's avatar
niklas.baumgarten committed
82
class StochasticLaplace2D : public IStochasticEllipticProblem {
83
  CirculantEmbedding2D tensorGenerator;
niklas.baumgarten's avatar
niklas.baumgarten committed
84
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
85
  explicit StochasticLaplace2D(const Meshes &meshes) :
86
87
88
89
90
91
    IStochasticEllipticProblem(meshes),
    tensorGenerator(CirculantEmbedding2D(meshes)) {}

  void DrawSample(const SampleID &id) override {
    tensorGenerator.DrawSample(id);
  }
92

niklas.baumgarten's avatar
niklas.baumgarten committed
93
94
95
  Scalar Solution(const Point &x) const override {
    return -x[1];
  }
96

niklas.baumgarten's avatar
niklas.baumgarten committed
97
98
99
  VectorField Flux(const Point &x) const override {
    return VectorField(0.0, -1.0);
  }
100

niklas.baumgarten's avatar
niklas.baumgarten committed
101
  Scalar Load(const Point &x) const override { return 0.0; }
102

niklas.baumgarten's avatar
niklas.baumgarten committed
103
  Tensor Permeability(const cell &c) const override {
104
    return this->tensorGenerator.EvalSample(c);
niklas.baumgarten's avatar
niklas.baumgarten committed
105
  }
106

niklas.baumgarten's avatar
niklas.baumgarten committed
107
  string Name() const override { return "StochasticLaplace2D"; }
108
109
};

niklas.baumgarten's avatar
niklas.baumgarten committed
110
class StochasticLaplace2DTest : public IStochasticEllipticProblem {
111
  UniformDistributionRVector rVectorGenerator;
112
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
113
  explicit StochasticLaplace2DTest(const Meshes &meshes) :
114
115
116
117
118
119
    IStochasticEllipticProblem(meshes),
    rVectorGenerator(UniformDistributionRVector(meshes, 2, -1.0, 1.0)) {}

  void DrawSample(const SampleID &id) override {
    rVectorGenerator.DrawSample(id);
  }
120

niklas.baumgarten's avatar
niklas.baumgarten committed
121
122
123
  Scalar Solution(const Point &x) const override {
    return -x[1];
  }
124

niklas.baumgarten's avatar
niklas.baumgarten committed
125
126
127
  VectorField Flux(const Point &x) const override {
    return VectorField(0.0, -1.0);
  }
128

niklas.baumgarten's avatar
niklas.baumgarten committed
129
  Scalar Load(const Point &x) const override { return 0.0; }
130

niklas.baumgarten's avatar
niklas.baumgarten committed
131
132
133
  Tensor Permeability(const cell &c) const override {
    if (c()[1] > 0.125 && c()[1] < 0.375) {
      if (c()[0] > 0.125 && c()[0] < 0.375)
134
        return (1 + 0.9 * this->rVectorGenerator.EvalSample()[0]) * One;
135
      if (c()[0] > 0.625 && c()[0] < 0.875)
136
        return (1 + 0.9 * this->rVectorGenerator.EvalSample()[1]) * One;
137
    }
138
    return One;
niklas.baumgarten's avatar
niklas.baumgarten committed
139
140
  }

141
  string Name() const override { return "StochasticLaplace2DTest"; }
niklas.baumgarten's avatar
niklas.baumgarten committed
142
143
144
145
};

class Laplace2D : public IStochasticEllipticProblem {
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
146
  explicit Laplace2D(const Meshes &meshes) : IStochasticEllipticProblem(meshes) {}
niklas.baumgarten's avatar
niklas.baumgarten committed
147

148
149
  void DrawSample(const SampleID &id) override {}

niklas.baumgarten's avatar
niklas.baumgarten committed
150
151
152
153
154
155
156
157
158
159
160
161
162
  Scalar Solution(const Point &x) const override {
    return -x[1];
  }

  VectorField Flux(const Point &x) const override {
    return VectorField(0.0, -1.0);
  }

  Scalar Load(const Point &x) const override { return 0.0; }

  Tensor Permeability(const cell &c) const override {
    return One;
  }
163

niklas.baumgarten's avatar
niklas.baumgarten committed
164
  string Name() const override { return "Laplace2D"; }
165
166
};

167
IStochasticEllipticProblem *
niklas.baumgarten's avatar
niklas.baumgarten committed
168
CreateStochasticEllipticProblem(const string &problemName, const Meshes &meshes);
169

niklas.baumgarten's avatar
niklas.baumgarten committed
170
#endif //STOCHASTICELLIPTICPROBLEM_HPP