GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
NavierStokes.hh
Go to the documentation of this file.
1
2#include "Effect.hh"
3
4class Derivative : public Function<float,float>
5{
6public:
7 Derivative(Function<float,float> &f, float dx) : f(f), dx(dx) { }
8 float Index(float x) const
9 {
10 return (f.Index(x+dx)-f.Index(x))/dx;
11 }
12private:
14 float dx;
15};
16
17class Integrate : public Function<float,float>
18{
19public:
20 Integrate(Function<float,float> &f, float start_x, float end_x, float dx) : f(f), start_x(start_x), end_x(end_x), dx(dx) { }
21 float Index(float x) const
22 {
23 float val = 0.0;
24 for(float x = start_x; x<end_x;x+=dx)
25 {
26 val += f.Index(x)*dx;
27 }
28 return val;
29 }
30private:
32 float start_x;
33 float end_x;
34 float dx;
35};
36
37struct P
38{
39 float x;
40 float y;
41 float z;
42 float t;
43};
44
45class Derivative_x : public Function<P, float>
46{
47public:
48 Derivative_x(Function<P, float> &f, float dx) : f(f) , dx(dx) {}
49 float Index(P p) const
50 {
51 P pp;
52 pp.x = p.x + dx;
53 pp.y = p.y;
54 pp.z = p.z;
55 pp.t = p.t;
56 float val = f.Index(pp);
57 pp.x = p.x;
58 float val2 = f.Index(pp);
59 return (val-val2)/dx;
60 }
61private:
63 float dx;
64};
65class Derivative_xx : public Function<P, float>
66{
67public:
68 Derivative_xx(Function<P, float> &f, float dx1, float dx2) : d1(f, dx1), d2(d1, dx2) { }
69 float Index(P p) const { return d2.Index(p); }
70private:
71 Derivative_x d1;
72 Derivative_x d2;
73};
74
75class Derivative_y : public Function<P, float>
76{
77public:
78 Derivative_x(Function<P, float> &f, float dy) : f(f) , dy(dy) {}
79 float Index(P p) const
80 {
81 P pp;
82 pp.x = p.x;
83 pp.y = p.y + dy;
84 pp.z = p.z;
85 pp.t = p.t;
86 float val = f.Index(pp);
87 pp.y = p.y;
88 float val2 = f.Index(pp);
89 return (val-val2)/dy;
90 }
91private:
93 float dy;
94};
95
96class Derivative_yy : public Function<P, float>
97{
98public:
99 Derivative_yy(Function<P, float> &f, float dx1, float dx2) : d1(f, dx1), d2(d1, dx2) { }
100 float Index(P p) const { return d2.Index(p); }
101private:
102 Derivative_y d1;
103 Derivative_y d2;
104};
105
106
107class Derivative_z : public Function<P, float>
108{
109public:
110 Derivative_z(Function<P, float> &f, float dz) : f(f) , dz(dz) {}
111 float Index(P p) const
112 {
113 P pp;
114 pp.x = p.x;
115 pp.y = p.y;
116 pp.z = p.z + dz;
117 pp.t = p.t;
118 float val = f.Index(pp);
119 pp.z = p.z;
120 float val2 = f.Index(pp);
121 return (val-val2)/dz;
122 }
123private:
125 float dz;
126};
127
128class Derivative_zz : public Function<P, float>
129{
130public:
131 Derivative_zz(Function<P, float> &f, float dx1, float dx2) : d1(f, dx1), d2(d1, dx2) { }
132 float Index(P p) const { return d2.Index(p); }
133private:
134 Derivative_z d1;
135 Derivative_z d2;
136};
137
138
139
140class Derivative_t : public Function<P, float>
141{
142public:
143 Derivative_t(Function<P, float> &f, float dt) : f(f) , dt(dt) {}
144 float Index(P p) const
145 {
146 P pp;
147 pp.x = p.x;
148 pp.y = p.y;
149 pp.z = p.z;
150 pp.t = p.t + dt;
151 float val = f.Index(pp);
152 pp.t = p.t;
153 float val2 = f.Index(pp);
154 return (val-val2)/dt;
155 }
156private:
158 float dt;
159};
160
161class Derivative_tt : public Function<P, float>
162{
163public:
164 Derivative_tt(Function<P, float> &f, float dx1, float dx2) : d1(f, dx1), d2(d1, dx2) { }
165 float Index(P p) const { return d2.Index(p); }
166private:
167 Derivative_t d1;
168 Derivative_t d2;
169};
170
171
172template<class A, class B>
173class Equation
174{
175public:
176 virtual B f(A a) const=0;
177 virtual B g(A a) const=0;
178};
179
180class Bools : public Function<std::pair<float,float>, bool>
181{
182public:
183 bool Index(std::pair<float,float> p) const
184 {
185 return p.first < p.second;
186 }
187};
188
189class Intersection : public Function<std::pair<bool,bool>, bool>
190{
191public:
192 bool Index(std::pair<bool,bool> p) const
193 {
194 return p.first && p.second;
195 }
196};
197
212
213class NavierStokesEquation_1 : public Equation<NavierStokesVariables, float>
214{
215public:
217 {
218 Derivative_t Dt(*v.u, 0.01);
219 Derivative_x Dx(*v.u, 0.01);
220 Derivative_y Dy(*v.u, 0.01);
221 Derivative_z Dz(*v.u, 0.01);
222 return v.p*(Dt.Index(v.pos) + v.u->Index(v.pos) * Dx.Index(v.pos) + v.v->Index(v.pos) * Dy.Index(v.pos) + v.w->Index(v.pos) * Dz.Index(v.pos));
223 }
225 {
226 Derivative_x Dpx(*v.pp, 0.01);
227 Derivative_xx Dux(*v.u, 0.01, 0.01);
228 Derivative_yy Duy(*v.u, 0.01, 0.01);
229 Derivative_zz Duz(*v.u, 0.01, 0.01);
230 return -Dpx.Index(v.pos)+v.my*(Dux.Index(v.pos)+Duy.Index(v.pos)+Duz.Index(v.pos)) + v.p*v.g_x;
231 }
232};
233
234class NavierStokesEquation_2 : public Equation<NavierStokesVariables, float>
235{
236public:
238 {
239 Derivative_t Dt(*v.u, 0.01);
240 Derivative_x Dx(*v.u, 0.01);
241 Derivative_y Dy(*v.u, 0.01);
242 Derivative_z Dz(*v.u, 0.01);
243 return v.p*(Dt.Index(v.pos) + v.u->Index(v.pos) * Dx.Index(v.pos) + v.v->Index(v.pos) * Dy.Index(v.pos) + v.w->Index(v.pos) * Dz.Index(v.pos));
244 }
246 {
247 Derivative_x Dpx(*v.pp, 0.01);
248 Derivative_xx Dux(*v.u, 0.01, 0.01);
249 Derivative_yy Duy(*v.u, 0.01, 0.01);
250 Derivative_zz Duz(*v.u, 0.01, 0.01);
251 return -Dpx.Index(v.pos)+v.my*(Dux.Index(v.pos)+Duy.Index(v.pos)+Duz.Index(v.pos)) + v.p*v.g_y;
252 }
253};
254
255class NavierStokesEquation_3 : public Equation<NavierStokesVariables, float>
256{
257public:
259 {
260 Derivative_t Dt(*v.u, 0.01);
261 Derivative_x Dx(*v.u, 0.01);
262 Derivative_y Dy(*v.u, 0.01);
263 Derivative_z Dz(*v.u, 0.01);
264 return v.p*(Dt.Index(v.pos) + v.u->Index(v.pos) * Dx.Index(v.pos) + v.v->Index(v.pos) * Dy.Index(v.pos) + v.w->Index(v.pos) * Dz.Index(v.pos));
265 }
267 {
268 Derivative_x Dpx(*v.pp, 0.01);
269 Derivative_xx Dux(*v.u, 0.01, 0.01);
270 Derivative_yy Duy(*v.u, 0.01, 0.01);
271 Derivative_zz Duz(*v.u, 0.01, 0.01);
272 return -Dpx.Index(v.pos)+v.my*(Dux.Index(v.pos)+Duy.Index(v.pos)+Duz.Index(v.pos)) + v.p*v.g_z;
273 }
274};
275
276class ContinuityEquation : public Equation<NavierStokesVariables, float>
277{
278public:
280 {
281 Derivative_x Dx(*v.u, 0.01);
282 Derivative_y Dy(*v.u, 0.01);
283 Derivative_z Dz(*v.u, 0.01);
284 return Dx.Index(v.pos)+Dy.Index(v.pos)+Dz.Index(v.pos);
285 }
287 {
288 return 0.0;
289 }
290};
size dy
Definition GameApi_gui.cc:1727
Definition compiled_tests.cpp:1189
Definition compiled_tests.cpp:1200
Definition NavierStokes.hh:181
bool Index(std::pair< float, float > p) const
Definition NavierStokes.hh:183
Definition NavierStokes.hh:277
float g(NavierStokesVariables v) const
Definition NavierStokes.hh:286
float f(NavierStokesVariables v) const
Definition NavierStokes.hh:279
Definition NavierStokes.hh:141
float Index(P p) const
Definition NavierStokes.hh:144
Derivative_t(Function< P, float > &f, float dt)
Definition NavierStokes.hh:143
Derivative_tt(Function< P, float > &f, float dx1, float dx2)
Definition NavierStokes.hh:164
float Index(P p) const
Definition NavierStokes.hh:165
Definition NavierStokes.hh:46
float Index(P p) const
Definition NavierStokes.hh:49
Derivative_x(Function< P, float > &f, float dx)
Definition NavierStokes.hh:48
Definition NavierStokes.hh:66
float Index(P p) const
Definition NavierStokes.hh:69
Derivative_xx(Function< P, float > &f, float dx1, float dx2)
Definition NavierStokes.hh:68
Definition NavierStokes.hh:76
Derivative_x(Function< P, float > &f, float dy)
Definition NavierStokes.hh:78
float Index(P p) const
Definition NavierStokes.hh:79
Definition NavierStokes.hh:97
float Index(P p) const
Definition NavierStokes.hh:100
Derivative_yy(Function< P, float > &f, float dx1, float dx2)
Definition NavierStokes.hh:99
Definition NavierStokes.hh:108
float Index(P p) const
Definition NavierStokes.hh:111
Derivative_z(Function< P, float > &f, float dz)
Definition NavierStokes.hh:110
Definition NavierStokes.hh:129
Derivative_zz(Function< P, float > &f, float dx1, float dx2)
Definition NavierStokes.hh:131
float Index(P p) const
Definition NavierStokes.hh:132
Derivative(Function< float, float > &f, float dx)
Definition NavierStokes.hh:7
float Index(float x) const
Definition NavierStokes.hh:8
Definition Math.hh:178
virtual B f(A a) const =0
virtual B g(A a) const =0
Definition EffectI.hh:11
virtual B Index(A a) const =0
float Index(float x) const
Definition NavierStokes.hh:21
Integrate(Function< float, float > &f, float start_x, float end_x, float dx)
Definition NavierStokes.hh:20
Definition Equalizer.hh:478
bool Index(std::pair< bool, bool > p) const
Definition NavierStokes.hh:192
Definition NavierStokes.hh:214
float g(NavierStokesVariables v) const
Definition NavierStokes.hh:224
float f(NavierStokesVariables v) const
Definition NavierStokes.hh:216
Definition NavierStokes.hh:235
float g(NavierStokesVariables v) const
Definition NavierStokes.hh:245
float f(NavierStokesVariables v) const
Definition NavierStokes.hh:237
Definition NavierStokes.hh:256
float f(NavierStokesVariables v) const
Definition NavierStokes.hh:258
float g(NavierStokesVariables v) const
Definition NavierStokes.hh:266
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
Definition NavierStokes.hh:199
float g_x
Definition NavierStokes.hh:207
float g_z
Definition NavierStokes.hh:209
Function< P, float > * u
Definition NavierStokes.hh:202
Function< P, float > * v
Definition NavierStokes.hh:203
float g_y
Definition NavierStokes.hh:208
Function< P, float > * w
Definition NavierStokes.hh:204
float p
Definition NavierStokes.hh:201
float my
Definition NavierStokes.hh:206
Function< P, float > * pp
Definition NavierStokes.hh:205
P pos
Definition NavierStokes.hh:210
Definition GameApi.h:23
float z
Definition NavierStokes.hh:41
float y
Definition NavierStokes.hh:40
float x
Definition NavierStokes.hh:39
float t
Definition NavierStokes.hh:42