/
formulae_mpdata_3d.hpp
331 lines (314 loc) · 11.6 KB
/
formulae_mpdata_3d.hpp
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/** @file
* @copyright University of Warsaw
* @section LICENSE
* GPLv3+ (see the COPYING file or http://www.gnu.org/licenses/)
*/
#pragma once
#include <libmpdata++/formulae/mpdata/formulae_mpdata_common.hpp>
#include <libmpdata++/formulae/mpdata/formulae_mpdata_dfl_3d.hpp>
#include <libmpdata++/formulae/mpdata/formulae_mpdata_hot_3d.hpp>
#include <libmpdata++/formulae/mpdata/formulae_mpdata_fdiv_3d.hpp>
#include <boost/preprocessor/punctuation/comma.hpp>
namespace libmpdataxx
{
namespace formulae
{
namespace mpdata
{
// first come helpers for divergence form of antidiffusive velocity
template <opts_t opts, int dim, class arr_3d_t, class ix_t>
forceinline_macro auto div_2nd(
const arr_3d_t &psi,
const arrvec_t<arr_3d_t> &GC,
const arr_3d_t &G,
const ix_t &i,
const ix_t &j,
const ix_t &k
)
{
return return_helper<ix_t>(
// second order terms
abs(GC[dim](pi<dim>(i+h, j, k))) / 2
* ndx_psi<opts, dim>(psi, i, j, k)
-
GC[dim](pi<dim>(i+h, j, k)) / 2
* nfdiv<opts, dim>(psi, GC, G, i, j, k)
);
}
template <opts_t opts, int dim, class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd_upwind(
const arr_3d_t &psi,
const arrvec_t<arr_3d_t> &GC,
const arr_3d_t &G,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<!opts::isset(opts, opts::iga)>::type* = 0
)
{
return return_helper<ix_t>(
abs(div_2nd<opts, dim>(psi, GC, G, i, j, k)) / 2
* ndx_psi<opts, dim>(psi, i, j, k)
);
}
template <opts_t opts, int dim, class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd_upwind(
const arr_3d_t &psi,
const arrvec_t<arr_3d_t> &GC,
const arr_3d_t &G,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<opts::isset(opts, opts::iga)>::type* = 0
)
{
return 0;
}
template <opts_t opts, int dim, solvers::tmprl_extrp_t tmprl_extrp, class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd_temporal(
const arr_3d_t &psi,
const arrvec_t<arr_3d_t> &ndtt_GC,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<tmprl_extrp == solvers::noextrp>::type* = 0
)
{
return return_helper<ix_t>(
ndtt_GC0<opts, dim>(psi, ndtt_GC[dim], i, j, k)
);
}
template <opts_t opts, int dim, solvers::tmprl_extrp_t tmprl_extrp, class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd_temporal(
const arr_3d_t &psi,
const arrvec_t<arr_3d_t> &ndtt_GC,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<tmprl_extrp == solvers::linear2>::type* = 0
)
{
return return_helper<ix_t>(
10 * ndtt_GC0<opts, dim>(psi, ndtt_GC[dim], i, j, k)
);
}
template <opts_t opts, int dim, solvers::sptl_intrp_t sptl_intrp, class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd_spatial_helper(
const arr_3d_t &psi,
const arrvec_t<arr_3d_t> &GC,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<sptl_intrp == solvers::exact>::type* = 0
)
{
return return_helper<ix_t>(
ndxx_GC0<opts, dim>(psi, GC[dim], i, j, k)
);
}
template <opts_t opts, int dim, solvers::sptl_intrp_t sptl_intrp, class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd_spatial_helper(
const arr_3d_t &psi,
const arrvec_t<arr_3d_t> &GC,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<sptl_intrp == solvers::aver2>::type* = 0
)
{
return return_helper<ix_t>(
4 * ndxx_GC0<opts, dim>(psi, GC[dim], i, j, k)
);
}
template <opts_t opts, int dim, solvers::sptl_intrp_t sptl_intrp, class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd_spatial_helper(
const arr_3d_t &psi,
const arrvec_t<arr_3d_t> &GC,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<sptl_intrp == solvers::aver4>::type* = 0
)
{
return 0;
}
template <opts_t opts, int dim, solvers::sptl_intrp_t sptl_intrp, class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd_spatial(
const arr_3d_t &psi,
const arrvec_t<arr_3d_t> &GC,
const arr_3d_t &G,
const ix_t &i,
const ix_t &j,
const ix_t &k
)
{
return return_helper<ix_t>(
- fconst<arr_3d_t>(1.0 / 24) *
(
4 * GC[dim](pi<dim>(i+h, j, k)) * ndxx_psi<opts, dim>(psi, i, j, k)
+ 2 * ndx_psi<opts, dim>(psi, i, j, k) * ndx_GC0<dim>(GC[dim], i, j, k)
+ div_3rd_spatial_helper<opts, dim, sptl_intrp>(psi, GC, i, j, k)
)
);
}
template <opts_t opts, int dim,
solvers::sptl_intrp_t, solvers::tmprl_extrp_t,
class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd(
const arr_3d_t &psi_np1,
const arr_3d_t &psi_n,
const arrvec_t<arr_3d_t> &GC,
const arrvec_t<arr_3d_t> &ndt_GC,
const arrvec_t<arr_3d_t> &ndtt_GC,
const arr_3d_t &G,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<!opts::isset(opts, opts::div_3rd) && !opts::isset(opts, opts::div_3rd_dt)>::type* = 0
)
{
return 0;
}
template <opts_t opts, int dim,
solvers::sptl_intrp_t sptl_intrp, solvers::tmprl_extrp_t tmprl_extrp,
class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd(
const arr_3d_t &psi_np1,
const arr_3d_t &psi_n,
const arrvec_t<arr_3d_t> &GC,
const arrvec_t<arr_3d_t> &ndt_GC,
const arrvec_t<arr_3d_t> &ndtt_GC,
const arr_3d_t &G,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<opts::isset(opts, opts::div_3rd)>::type* = 0
)
{
return return_helper<ix_t>(
// upwind differencing correction
div_3rd_upwind<opts, dim>(psi_np1, GC, G, i, j, k)
// spatial terms
+ div_3rd_spatial<opts, dim, sptl_intrp>(psi_np1, GC, G, i, j, k)
// mixed terms
+ fconst<arr_3d_t>(0.5) * abs(GC[dim](pi<dim>(i+h, j, k))) * ndx_fdiv<opts, dim>(psi_np1, GC, G, i, j, k)
// temporal terms
+ fconst<arr_3d_t>(1.0 / 24) *
(
- 8 * GC[dim](pi<dim>(i+h, j, k)) * nfdiv_fdiv<opts, dim>(psi_np1, GC, G, i, j, k)
+ div_3rd_temporal<opts, dim, tmprl_extrp>(psi_np1, ndtt_GC, i, j, k)
+ 2 * GC[dim](pi<dim>(i+h, j, k)) * nfdiv<opts, dim>(psi_np1, ndt_GC, G, i, j, k)
- 2 * ndt_GC[dim](pi<dim>(i+h, j, k)) * nfdiv<opts, dim>(psi_np1, GC, G, i, j, k)
)
);
}
template <opts_t opts, int dim,
solvers::sptl_intrp_t sptl_intrp, solvers::tmprl_extrp_t tmprl_extrp,
class arr_3d_t, class ix_t>
forceinline_macro auto div_3rd(
const arr_3d_t &psi_np1,
const arr_3d_t &psi_n,
const arrvec_t<arr_3d_t> &GC,
const arrvec_t<arr_3d_t> &ndt_GC,
const arrvec_t<arr_3d_t> &ndtt_GC,
const arr_3d_t &G,
const ix_t &i,
const ix_t &j,
const ix_t &k,
typename std::enable_if<opts::isset(opts, opts::div_3rd_dt)>::type* = 0
)
{
return return_helper<ix_t>(
// upwind differencing correction
div_3rd_upwind<opts, dim>(psi_np1, GC, G, i, j, k)
// spatial terms
+ div_3rd_spatial<opts, dim, sptl_intrp>(psi_np1, GC, G, i, j, k)
// mixed terms
- fconst<arr_3d_t>(0.5) * abs(GC[dim](pi<dim>(i+h, j, k))) * ndtx_psi<opts, dim>(psi_np1, psi_n, i, j, k)
// temporal terms
+ fconst<arr_3d_t>(1.0 / 24) *
(
+ 8 * GC[dim](pi<dim>(i+h, j, k)) * nfdiv_dt<opts, dim>(psi_np1, psi_n, GC, G, i, j, k)
+ div_3rd_temporal<opts, dim, tmprl_extrp>(psi_np1, ndtt_GC, i, j, k)
+ 2 * GC[dim](pi<dim>(i+h, j, k)) * nfdiv<opts, dim>(psi_np1, ndt_GC, G, i, j, k)
+ 2 * ndt_GC[dim](pi<dim>(i+h, j, k)) * ndt_psi<opts, dim>(psi_np1, psi_n, i, j, k)
)
);
}
// antidiffusive velocity - standard version
template <opts_t opts, int dim, solvers::sptl_intrp_t, solvers::tmprl_extrp_t, class arr_3d_t>
inline void antidiff(
arr_3d_t &res,
const arr_3d_t &psi_np1,
const arr_3d_t &psi_n,
const arrvec_t<arr_3d_t> &GC,
const arrvec_t<arr_3d_t> &ndt_GC, // to have consistent interface with the div_3rd version
const arrvec_t<arr_3d_t> &ndtt_GC, // ditto
const arr_3d_t &G,
const rng_t &ir,
const rng_t &jr,
const rng_t &kr,
typename std::enable_if<!opts::isset(opts, opts::div_2nd) && !opts::isset(opts, opts::div_3rd)>::type* = 0
)
{
for (int i = ir.first(); i <= ir.last(); ++i)
{
for (int j = jr.first(); j <= jr.last(); ++j)
{
for (int k = kr.first(); k <= kr.last(); ++k)
{
res(pi<dim>(i, j, k)) =
// second order terms
abs(GC[dim](pi<dim>(i+h, j, k))) / 2
* (1 - abs(GC[dim](pi<dim>(i+h, j, k))) / G_bar_x<opts, dim>(G, i, j, k))
* ndx_psi<opts, dim>(psi_np1, i, j, k)
- GC[dim](pi<dim>(i+h, j, k)) / 2
* (
GC1_bar_xy<dim>(GC[dim+1], i, j, k)
* ndy_psi<opts, dim>(psi_np1, i, j, k)
+ GC2_bar_xz<dim>(GC[dim-1], i, j, k)
* ndz_psi<opts, dim>(psi_np1, i, j, k)
)
/ G_bar_x<opts, dim>(G, i, j, k)
// third order terms
+ TOT<opts, dim>(psi_np1, GC, G, i, j, k)
// divergent flow correction
+ DFL<opts, dim>(psi_np1, GC, G, i, j, k);
}
}
}
}
// antidiffusive velocity - divergence form
template <opts_t opts, int dim, solvers::sptl_intrp_t sptl_intrp, solvers::tmprl_extrp_t tmprl_extrp, class arr_3d_t>
inline void antidiff(
arr_3d_t &res,
const arr_3d_t &psi_np1,
const arr_3d_t &psi_n,
const arrvec_t<arr_3d_t> &GC,
const arrvec_t<arr_3d_t> &ndt_GC,
const arrvec_t<arr_3d_t> &ndtt_GC,
const arr_3d_t &G,
const rng_t &ir,
const rng_t &jr,
const rng_t &kr,
typename std::enable_if<opts::isset(opts, opts::div_2nd)>::type* = 0
)
{
static_assert(!opts::isset(opts, opts::tot), "div_2nd & div_3rd options are incompatible with tot");
static_assert(!opts::isset(opts, opts::dfl), "div_2nd & div_3rd options are incompatible with dfl");
for (int i = ir.first(); i <= ir.last(); ++i)
{
for (int j = jr.first(); j <= jr.last(); ++j)
{
for (int k = kr.first(); k <= kr.last(); ++k)
{
res(pi<dim>(i + h, j, k)) =
div_2nd<opts, dim>(psi_np1, GC, G, i, j, k) +
div_3rd<opts, dim, sptl_intrp, tmprl_extrp>(psi_np1, psi_n, GC, ndt_GC, ndtt_GC, G, i, j, k);
}
}
}
}
} // namespace mpdata
} // namespace formulae
} // namespcae libmpdataxx