Newer
Older
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
import numpy as np
import numpy.linalg as la # noqa: F401
import pyopencl as cl # noqa: F401
import pyopencl.array # noqa
import pyopencl.tools # noqa
import pyopencl.clrandom # noqa
import loopy as lp # noqa
def test_weno_weight_computation(ctx_factory, flux_test_data_fixture):
data = flux_test_data_fixture
def weno_weights(oscillation):
linear = np.array([0.1, 0.6, 0.3])
eps = 1e-6
raw_weights = np.empty((5,3))
for i in range(5):
for j in range(3):
raw_weights[i,j] = linear[j]/(oscillation[i,j] + eps)**2
weight_sum = raw_weights.sum(axis=1)
weights = np.empty((5,3))
for i in range(5):
for j in range(3):
weights[i,j] = raw_weights[i,j]/weight_sum[i]
return weights
prg = u.get_weno_program_with_root_kernel("weno_weights_pos")
queue = u.get_queue(ctx_factory)
weights_dev = u.empty_array_on_device(queue, data.nvars, 3)
prg(queue, nvars=data.nvars,
characteristic_fluxes=data.char_fluxes_pos,
combined_frozen_metrics=1.0,
w=weights_dev)
w = weno_weights(data.oscillation_pos)
u.compare_arrays(weights_dev.get(), w)
prg = u.get_weno_program_with_root_kernel("weno_weights_neg")
queue = u.get_queue(ctx_factory)
weights_dev = u.empty_array_on_device(queue, data.nvars, 3)
prg(queue, nvars=data.nvars,
characteristic_fluxes=data.char_fluxes_neg,
combined_frozen_metrics=1.0,
w=weights_dev)
w = weno_weights(data.oscillation_neg)
u.compare_arrays(weights_dev.get(), w)