-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_diffusion2d.py
More file actions
81 lines (67 loc) · 2.09 KB
/
test_diffusion2d.py
File metadata and controls
81 lines (67 loc) · 2.09 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
"""
Tests for functionality checks in class SolveDiffusion2D
"""
import numpy as np
from diffusion2d import SolveDiffusion2D
def test_initialize_physical_parameters():
"""
Checks function SolveDiffusion2D.initialize_domain
"""
solver = SolveDiffusion2D()
w, h = 10.0, 5.0
dx, dy = 0.1, 0.1
D = 3.0
T_cold, T_hot = 250.0, 900.0
solver.initialize_domain(w=w, h=h, dx=dx, dy=dy)
solver.initialize_physical_parameters(d=D, T_cold=T_cold, T_hot=T_hot)
expected_nx = int(w / dx)
expected_ny = int(h / dy)
dx2 = dx * dx
dy2 = dy * dy
expected_dt = dx2 * dy2 / (2.0 * D * (dx2 + dy2))
assert solver.w == w
assert solver.h == h
assert solver.dx == dx
assert solver.dy == dy
assert solver.nx == expected_nx
assert solver.ny == expected_ny
assert solver.T_cold == T_cold
assert solver.T_hot == T_hot
assert solver.D == D
assert solver.dt == expected_dt
def test_set_initial_condition():
"""
Checks function SolveDiffusion2D.get_initial_function
"""
solver = SolveDiffusion2D()
w, h = 10.0, 5.0
dx, dy = 1.0, 0.5
D = 4.0
T_cold, T_hot = 300.0, 700.0
solver.initialize_domain(w=w, h=h, dx=dx, dy=dy)
solver.initialize_physical_parameters(d=D, T_cold=T_cold, T_hot=T_hot)
u = solver.set_initial_condition()
expected_nx = int(w / dx)
expected_ny = int(h / dy)
dx2 = dx * dx
dy2 = dy * dy
expected_dt = dx2 * dy2 / (2.0 * D * (dx2 + dy2))
expected_u = T_cold * np.ones((expected_nx, expected_ny))
r, cx, cy = 2, 5, 5
r2 = r ** 2
for i in range(expected_nx):
for j in range(expected_ny):
p2 = (i * dx - cx) ** 2 + (j * dy - cy) ** 2
if p2 < r2:
expected_u[i, j] = T_hot
assert solver.w == w
assert solver.h == h
assert solver.dx == dx
assert solver.dy == dy
assert solver.nx == expected_nx
assert solver.ny == expected_ny
assert solver.T_cold == T_cold
assert solver.T_hot == T_hot
assert solver.D == D
assert solver.dt == expected_dt
assert np.array_equal(u, expected_u)