-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathmain.py
71 lines (58 loc) · 1.97 KB
/
main.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
import deepxde as dde
import numpy as np
import matplotlib.pyplot as plt
from advection import Advection, Advection_v2
def main_IC1():
ndata = 1000
nx = 40
nt = 40
geom = dde.geometry.Interval(0, 1)
timedomain = dde.geometry.TimeDomain(0, 1)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)
x = geomtime.uniform_points(nx * nt, boundary=True)
u = []
rng = np.random.default_rng()
for i in range(ndata):
height = rng.random() + 1 # [1, 2]
width = 0.3 * rng.random() + 0.3 # [0.3, 0.6]
x0 = 0.4 * rng.random() + 0.3 # [0.3, 0.7]
pde = Advection(height, width, 1, x0, 0, 1)
u.append(pde.solve(x).reshape(nt, nx))
u = np.array(u)
x, t = x[:, 0].reshape(nt, nx), x[:, 1].reshape(nt, nx)
np.savez_compressed("train.npz", x=x, t=t, u=u)
# for i in range(3):
# plt.figure()
# plt.imshow(u[i])
# plt.colorbar()
# plt.show()
def main_IC2():
ndata = 1000
nx = 40
nt = 40
geom = dde.geometry.Interval(0, 1)
timedomain = dde.geometry.TimeDomain(0, 1)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)
x = geomtime.uniform_points(nx * nt, boundary=True)
u = []
rng = np.random.default_rng()
for i in range(ndata):
c1 = 0.1 * rng.random() + 0.2 # [0.2, 0.3]
w = 0.1 * rng.random() + 0.1 # [0.1, 0.2]
h1 = 1.5 * rng.random() + 0.5 # [0.5, 2]
c2 = 0.1 * rng.random() + 0.7 # [0.7, 0.8]
a = 5 * rng.random() + 5 # 1 / [0.1, 0.2] = [5, 10]
h2 = 1.5 * rng.random() + 0.5 # [0.5, 2]
pde = Advection_v2(0, 1, c1, w, h1, c2, a, h2)
u.append(pde.solve(x).reshape(nt, nx))
u = np.array(u)
x, t = x[:, 0].reshape(nt, nx), x[:, 1].reshape(nt, nx)
np.savez_compressed("train_IC2.npz", x=x, t=t, u=u)
for i in range(3):
plt.figure()
plt.imshow(u[i])
plt.colorbar()
plt.show()
if __name__ == "__main__":
# main_IC1()
main_IC2()