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

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


niklas.baumgarten's avatar
niklas.baumgarten committed
7
class IStochasticEllipticProblem : public IStochasticProblem {
8
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
9
10
  IStochasticEllipticProblem(Meshes &meshes, GeneratorNames genNames = {})
    : IStochasticProblem(meshes, genNames) {}
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
21
22
23
  void Permeability(Vector &kappa) {
    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
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
28
29
  StochasticLaplace1D(Meshes &meshes) :
    IStochasticEllipticProblem(meshes, GeneratorNames{"CirculantEmbedding"}) {};
niklas.baumgarten's avatar
niklas.baumgarten committed
30

niklas.baumgarten's avatar
niklas.baumgarten committed
31
32
33
  Scalar Solution(const Point &x) const override {
    return 1 - x[0];
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
34

niklas.baumgarten's avatar
niklas.baumgarten committed
35
36
37
  VectorField Flux(const Point &x) const override {
    return VectorField(1.0, 0.0);
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
38

niklas.baumgarten's avatar
niklas.baumgarten committed
39
40
41
  Scalar Load(const Point &x) const override {
    return 0.0;
  }
42

niklas.baumgarten's avatar
niklas.baumgarten committed
43
44
45
  Tensor Permeability(const cell &c) const override {
    return this->genContainer.tensorGenerator->EvalSample(c);
  }
46

niklas.baumgarten's avatar
niklas.baumgarten committed
47
  string Name() const override { return "StochasticLaplace1D"; }
niklas.baumgarten's avatar
niklas.baumgarten committed
48
49
};

50
51
class Laplace1D : public IStochasticEllipticProblem {
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
52
  Laplace1D(Meshes &meshes) : IStochasticEllipticProblem(meshes) {};
53

niklas.baumgarten's avatar
niklas.baumgarten committed
54
55
56
  Scalar Solution(const Point &x) const override {
    return 1 - x[0];
  }
57

niklas.baumgarten's avatar
niklas.baumgarten committed
58
59
60
  VectorField Flux(const Point &x) const override {
    return VectorField(-1.0, 0.0);
  }
61

niklas.baumgarten's avatar
niklas.baumgarten committed
62
63
64
  Scalar Load(const Point &x) const override {
    return 0.0;
  }
65

niklas.baumgarten's avatar
niklas.baumgarten committed
66
67
68
  Tensor Permeability(const cell &c) const override {
    return One;
  }
69

niklas.baumgarten's avatar
niklas.baumgarten committed
70
  string Name() const override { return "Laplace1D"; }
71
72
};

niklas.baumgarten's avatar
niklas.baumgarten committed
73
class StochasticLaplace2D : public IStochasticEllipticProblem {
niklas.baumgarten's avatar
niklas.baumgarten committed
74
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
75
76
  StochasticLaplace2D(Meshes &meshes) :
    IStochasticEllipticProblem(meshes, GeneratorNames{"CirculantEmbedding"}) {}
77

niklas.baumgarten's avatar
niklas.baumgarten committed
78
79
80
  Scalar Solution(const Point &x) const override {
    return -x[1];
  }
81

niklas.baumgarten's avatar
niklas.baumgarten committed
82
83
84
  VectorField Flux(const Point &x) const override {
    return VectorField(0.0, -1.0);
  }
85

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

niklas.baumgarten's avatar
niklas.baumgarten committed
88
89
90
  Tensor Permeability(const cell &c) const override {
    return this->genContainer.tensorGenerator->EvalSample(c);
  }
91

niklas.baumgarten's avatar
niklas.baumgarten committed
92
  string Name() const override { return "StochasticLaplace2D"; }
93
94
};

niklas.baumgarten's avatar
niklas.baumgarten committed
95
class StochasticLaplace2DTest : public IStochasticEllipticProblem {
96
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
97
  StochasticLaplace2DTest(Meshes &meshes) :
98
    IStochasticEllipticProblem(meshes, GeneratorNames{"UniformDistributionRVector"}) {}
99

niklas.baumgarten's avatar
niklas.baumgarten committed
100
101
102
  Scalar Solution(const Point &x) const override {
    return -x[1];
  }
103

niklas.baumgarten's avatar
niklas.baumgarten committed
104
105
106
  VectorField Flux(const Point &x) const override {
    return VectorField(0.0, -1.0);
  }
107

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

niklas.baumgarten's avatar
niklas.baumgarten committed
110
111
112
  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)
niklas.baumgarten's avatar
niklas.baumgarten committed
113
        return (1 + 0.9 * this->genContainer.rVectorGenerator->EvalSample()[0]) * One;
114
      if (c()[0] > 0.625 && c()[0] < 0.875)
niklas.baumgarten's avatar
niklas.baumgarten committed
115
        return (1 + 0.9 * this->genContainer.rVectorGenerator->EvalSample()[1]) * One;
116
    }
117
    return One;
niklas.baumgarten's avatar
niklas.baumgarten committed
118
119
  }

120
  string Name() const override { return "StochasticLaplace2DTest"; }
niklas.baumgarten's avatar
niklas.baumgarten committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
};

class Laplace2D : public IStochasticEllipticProblem {
public:
  Laplace2D(Meshes &meshes) : IStochasticEllipticProblem(meshes) {}

  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;
  }
140

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

144
IStochasticEllipticProblem *
niklas.baumgarten's avatar
niklas.baumgarten committed
145
CreateStochasticEllipticProblem(const string &problemName, Meshes &meshes);
146

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