forked from mdelorme/fv2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInit.h
247 lines (203 loc) · 5.89 KB
/
Init.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#pragma once
#include <fstream>
#include <Kokkos_Random.hpp>
#include "SimInfo.h"
#include "BoundaryConditions.h"
namespace fv2d {
namespace {
using RandomPool = Kokkos::Random_XorShift64_Pool<>;
/**
* @brief Sod Shock tube aligned along the X axis
*/
KOKKOS_INLINE_FUNCTION
void initSodX(Array Q, int i, int j, const Params ¶ms) {
if (getPos(params, i, j)[IX] <= 0.5) {
Q(j, i, IR) = 1.0;
Q(j, i, IP) = 1.0;
Q(j, i, IU) = 0.0;
}
else {
Q(j, i, IR) = 0.125;
Q(j, i, IP) = 0.1;
Q(j, i, IU) = 0.0;
}
}
/**
* @brief Sod Shock tube aligned along the Y axis
*/
KOKKOS_INLINE_FUNCTION
void initSodY(Array Q, int i, int j, const Params ¶ms) {
if (getPos(params, i, j)[IY] <= 0.5) {
Q(j, i, IR) = 1.0;
Q(j, i, IP) = 1.0;
Q(j, i, IU) = 0.0;
}
else {
Q(j, i, IR) = 0.125;
Q(j, i, IP) = 0.1;
Q(j, i, IU) = 0.0;
}
}
/**
* @brief Sedov blast initial conditions
*/
KOKKOS_INLINE_FUNCTION
void initBlast(Array Q, int i, int j, const Params ¶ms) {
real_t xmid = 0.5 * (params.xmin+params.xmax);
real_t ymid = 0.5 * (params.ymin+params.ymax);
Pos pos = getPos(params, i, j);
real_t x = pos[IX];
real_t y = pos[IY];
real_t xr = xmid - x;
real_t yr = ymid - y;
real_t r = sqrt(xr*xr+yr*yr);
if (r < 0.2) {
Q(j, i, IR) = 1.0;
Q(j, i, IU) = 0.0;
Q(j, i, IP) = 10.0;
}
else {
Q(j, i, IR) = 1.2;
Q(j, i, IU) = 0.0;
Q(j, i, IP) = 0.1;
}
}
/**
* @brief Stratified convection based on Hurlburt et al 1984
*/
KOKKOS_INLINE_FUNCTION
void initH84(Array Q, int i, int j, const Params ¶ms, const RandomPool &random_pool) {
Pos pos = getPos(params, i, j);
real_t x = pos[IX];
real_t y = pos[IY];
real_t T = y;
real_t rho = pow(y, params.m1);
real_t prs = pow(y, params.m1+1.0);
auto generator = random_pool.get_state();
real_t pert = params.h84_pert * (generator.drand(-0.5, 0.5));
random_pool.free_state(generator);
Q(j, i, IR) = rho;
Q(j, i, IU) = 0.0;
Q(j, i, IV) = pert;
Q(j, i, IP) = prs;
}
/**
* @brief Stratified convection based on Cattaneo et al. 1991
*/
KOKKOS_INLINE_FUNCTION
void initC91(Array Q, int i, int j, const Params ¶ms, const RandomPool &random_pool) {
Pos pos = getPos(params, i, j);
real_t x = pos[IX];
real_t y = pos[IY];
real_t T = (1.0 + params.theta1*y);
real_t rho = pow(T, params.m1);
real_t prs = pow(T, params.m1+1.0);
auto generator = random_pool.get_state();
real_t pert = params.c91_pert * (generator.drand(-0.5, 0.5));
random_pool.free_state(generator);
prs = prs * (1.0 + pert);
Q(j, i, IR) = rho;
Q(j, i, IU) = 0.0;
Q(j, i, IV) = 0.0;
Q(j, i, IP) = prs;
}
/**
* @brief Simple diffusion test with a structure being advected on the grid
*/
KOKKOS_INLINE_FUNCTION
void initDiffusion(Array Q, int i, int j, const Params ¶ms) {
real_t xmid = 0.5 * (params.xmin+params.xmax);
real_t ymid = 0.5 * (params.ymin+params.ymax);
Pos pos = getPos(params, i, j);
real_t x0 = (pos[IX]-xmid);
real_t y0 = (pos[IY]-ymid);
real_t r = sqrt(x0*x0+y0*y0);
if (r < 0.2)
Q(j, i, IR) = 1.0;
else
Q(j, i, IR) = 0.1;
Q(j, i, IP) = 1.0;
Q(j, i, IU) = 1.0;
Q(j, i, IV) = 1.0;
}
/**
* @brief Rayleigh-Taylor instability setup
*/
KOKKOS_INLINE_FUNCTION
void initRayleighTaylor(Array Q, int i, int j, const Params ¶ms) {
real_t ymid = 0.5*(params.ymin + params.ymax);
Pos pos = getPos(params, i, j);
real_t x = pos[IX];
real_t y = pos[IY];
const real_t P0 = 2.5;
if (y < ymid) {
Q(j, i, IR) = 1.0;
Q(j, i, IU) = 0.0;
Q(j, i, IP) = P0 + 0.1 * params.g * y;
}
else {
Q(j, i, IR) = 2.0;
Q(j, i, IU) = 0.0;
Q(j, i, IP) = P0 + 0.1 * params.g * y;
}
if (y > -1.0/3.0 && y < 1.0/3.0)
Q(j, i, IV) = 0.01 * (1.0 + cos(4*M_PI*x)) * (1 + cos(3.0*M_PI*y))/4.0;
}
}
/**
* @brief Enum describing the type of initialization possible
*/
enum InitType {
SOD_X,
SOD_Y,
BLAST,
RAYLEIGH_TAYLOR,
DIFFUSION,
H84,
C91
};
struct InitFunctor {
private:
Params params;
InitType init_type;
public:
InitFunctor(Params ¶ms)
: params(params) {
std::map<std::string, InitType> init_map {
{"sod_x", SOD_X},
{"sod_y", SOD_Y},
{"blast", BLAST},
{"rayleigh-taylor", RAYLEIGH_TAYLOR},
{"diffusion", DIFFUSION},
{"H84", H84},
{"C91", C91}
};
if (init_map.count(params.problem) == 0)
throw std::runtime_error("Error unknown problem " + params.problem);
init_type = init_map[params.problem];
};
~InitFunctor() = default;
void init(Array &Q) {
auto init_type = this->init_type;
auto params = this->params;
RandomPool random_pool(params.seed);
// Filling active domain ...
Kokkos::parallel_for( "Initialization",
params.range_dom,
KOKKOS_LAMBDA(const int i, const int j) {
switch(init_type) {
case SOD_X: initSodX(Q, i, j, params); break;
case SOD_Y: initSodY(Q, i, j, params); break;
case BLAST: initBlast(Q, i, j, params); break;
case DIFFUSION: initDiffusion(Q, i, j, params); break;
case RAYLEIGH_TAYLOR: initRayleighTaylor(Q, i, j, params); break;
case H84: initH84(Q, i, j, params, random_pool); break;
case C91: initC91(Q, i, j, params, random_pool); break;
}
});
// ... and boundaries
BoundaryManager bc(params);
bc.fillBoundaries(Q);
}
};
}