-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
82 lines (69 loc) · 1.85 KB
/
test.py
File metadata and controls
82 lines (69 loc) · 1.85 KB
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
import matplotlib.pyplot as plt
from solver import solve_problem
use_case = 'OAF'
num_eigen = 2000
t = 6000
params = {}
params['OAF'] = {
'k' : 5,
'm' : 7,
'nu' : 3.14,
'C' : 9.,
'x0' : 5,
'xq' : 3,
'dt' : 0.5,
'steps' : 100
}
params['OAA'] = {
'k' : 5,
'm' : 7,
'nu' : 0.4,
'C' : 9,
'x0' : 5,
'xq' : 2,
'dt' : 0.5,
'steps' : 100,
'gamma' : 0.1
}
params['C2D'] = {
'k' : 3,
'u1x' : 5,
'u2x' : 3,
'u1y' : 4,
'u2y' : 2,
'dxy' : 0.5,
'nx' : 20,
'ny' : 20
}
# -----------------------------------------------------
# Test all problem types
algorithm_result, actual_result, x_axis, result_2d = solve_problem(
problem=use_case,
params=params[use_case],
num_eigen=num_eigen,
t=t
)
if use_case in ['OAF', 'OAA']:
plt.figure('Forced oscillator', figsize=(10,6))
plt.plot(x_axis, actual_result, 'b-', linewidth=3, label='PyTorch')
plt.plot(x_axis, algorithm_result, 'r.', markersize=10, label='TN')
plt.xlabel('t'); plt.ylabel('x')
plt.legend(loc='upper right')
plt.tight_layout()
plt.show()
elif use_case == 'C2D':
# Plot 1D comparison
plt.figure('C2Heat', figsize=(10, 6))
plt.plot(x_axis, actual_result, 'b-', linewidth=2, label='PyTorch')
plt.plot(x_axis, algorithm_result, 'r.', markersize=10, label='TN')
plt.xlabel('(x, y)'); plt.ylabel('T(x,y)')
plt.legend(loc='upper right'); plt.tight_layout()
plt.savefig('C2D.pdf')
plt.show()
# Plot 2D heatmap
plt.figure('Heat equation', figsize=(10, 6))
plt.pcolormesh(result_2d, cmap="CMRmap")
plt.colorbar()
plt.xlabel('x'); plt.ylabel('y')
plt.tight_layout()
plt.show()