-
Notifications
You must be signed in to change notification settings - Fork 0
/
reference.py
130 lines (97 loc) · 2.85 KB
/
reference.py
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
import numpy as np
from scipy.integrate import quad
# =============================================================================
# Reference solution generator
# =============================================================================
# Scattering ratio
c = 1.1
i = complex(0, 1)
def integrand(u, eta, t):
q = (1 + eta) / (1 - eta)
xi = (np.log(q) + i * u) / (eta + i * np.tan(u / 2))
return (
1.0
/ (np.cos(u / 2)) ** 2
* (xi**2 * np.e ** (c * t / 2 * (1 - eta**2) * xi)).real
)
def phi(x, t):
if t == 0.0 or abs(x) >= t:
return 0.0
eta = x / t
integral = quad(integrand, 0.0, np.pi, args=(eta, t))[0]
return np.e**-t / 2 / t * (1 + c * t / 4 / np.pi * (1 - eta**2) * integral)
def phi_t(t, x):
return phi(x, t)
def phiX(x, t0, t1):
if abs(x) >= t1:
return 0.0
t0 = max(t0, abs(x))
return quad(phi_t, t0, t1, args=(x))[0]
# =============================================================================
# Time edge, spatial edge
# =============================================================================
# Spatial grid
J = 420
x_full = np.linspace(-11, 11, J + 1)
# Time grid
K = 200
t_full = np.linspace(0.8, 20.0, K + 1)
phi_full = np.zeros((K + 1, J + 1))
for k in range(K + 1):
for j in range(J + 1):
phi_full[k, j] = phi(x_full[j], t_full[k])
# =============================================================================
# Quantity of interest
# =============================================================================
# Time grid
K = 20
t = np.linspace(0.0, 20.0, K + 1)
qoi = np.zeros(K)
for k in range(K):
x0 = -1.0
x1 = 1.0
dx = x1 - x0
t0 = t[k]
t1 = t[k + 1]
dt = t1 - t0
qoi[k] = quad(phiX, x0, x1, args=(t0, t1))[0] / dx / dt
# =============================================================================
# Time average, spatial edge
# =============================================================================
# Spatial grid
J = 420
x = np.linspace(-21.0, 21.0, J + 1)
# Time grid
K = 20
t = np.linspace(0.0, 20.0, K + 1)
phi_spatial = np.zeros([K, J + 1])
for k in range(K):
for j in range(J + 1):
t0 = t[k]
t1 = t[k + 1]
dt = t1 - t0
phi_spatial[k, j] = quad(phi_t, t0, t1, args=(x[j]))[0] / dt
# =============================================================================
# Time edge, spatial center
# =============================================================================
# Time grid
K = 200
t = np.linspace(0.0, 20.0, K + 1)
t[0] = 1e-2
phi_center = np.zeros(K + 1)
for k in range(K + 1):
x0 = -1.0
x1 = 1.0
dx = x1 - x0
phi_center[k] = quad(phi, x0, x1, args=(t[k]))[0] / dx
np.savez(
"reference.npz",
x=x,
t=t,
phi_spatial=phi_spatial,
phi_center=phi_center,
qoi=qoi,
x_full=x_full,
t_full=t_full,
phi_full=phi_full,
)