-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_diffusion2d_functions.py
More file actions
38 lines (30 loc) · 1.2 KB
/
test_diffusion2d_functions.py
File metadata and controls
38 lines (30 loc) · 1.2 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
"""
Tests for functions in class SolveDiffusion2D
"""
from diffusion2d import SolveDiffusion2D
def test_initialize_domain():
"""
Check function SolveDiffusion2D.initialize_domain
"""
solver = SolveDiffusion2D()
solver.initialize_domain(w=20., h=40., dx=0.2, dy=0.5)
assert solver.nx == 100, "nx is not correctly set"
assert solver.ny == 80, "ny is not correctly set"
def test_initialize_physical_parameters():
"""
Checks function SolveDiffusion2D.initialize_domain
"""
solver = SolveDiffusion2D()
solver.initialize_domain(w=60., h=60., dx=0.2, dy=0.3)
solver.initialize_physical_parameters(d=6., T_cold=200., T_hot=400.)
# Expected dt = 0.04 * 0.09 / (2 * 6 * (0.04 + 0.09)) = 0.0036 / 1.56 = 0.00230769
assert abs(solver.dt - 0.00230769) < 1e-7, "dt is not correctly set"
def test_set_initial_condition():
"""
Checks function SolveDiffusion2D.get_initial_function
"""
solver = SolveDiffusion2D()
solver.initialize_domain(w=60., h=60., dx=0.2, dy=0.3)
solver.initialize_physical_parameters(d=6., T_cold=200., T_hot=400.)
u0 = solver.set_initial_condition()
assert u0.shape == (300, 200), "Initial condition array has wrong shape"