-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_diffusion2d_functions.py
More file actions
85 lines (75 loc) · 1.82 KB
/
test_diffusion2d_functions.py
File metadata and controls
85 lines (75 loc) · 1.82 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
83
84
85
"""
Tests for functions in class SolveDiffusion2D
"""
import numpy
import pytest
from diffusion2d import SolveDiffusion2D
def test_initialize_domain():
"""
Check function SolveDiffusion2D.initialize_domain
"""
solver = SolveDiffusion2D()
solver.initialize_domain(w=20.0, h=20.0, dx=0.5, dy=0.5)
assert solver.nx == 40
assert solver.ny == 40
def test_initialize_physical_parameters():
"""
Checks function SolveDiffusion2D.initialize_domain
"""
solver = SolveDiffusion2D()
solver.dx = 0.5
solver.dy = 0.5
solver.initialize_physical_parameters(d=3.0, T_cold=200.0, T_hot=800.0)
assert solver.dt == pytest.approx(0.02083333333, rel=1e-6)
def test_set_initial_condition():
"""
Checks function SolveDiffusion2D.get_initial_function
"""
solver = SolveDiffusion2D()
solver.nx = 5
solver.ny = 5
solver.dx = 3
solver.dy = 3
solver.T_cold = 200.0
solver.T_hot = 800.0
actual_result = solver.set_initial_condition()
expected_result = numpy.array(
[
[
200.0,
200.0,
200.0,
200.0,
200.0,
],
[
200.0,
200.0,
200.0,
200.0,
200.0,
],
[
200.0,
200.0,
800.0,
200.0,
200.0,
],
[
200.0,
200.0,
200.0,
200.0,
200.0,
],
[
200.0,
200.0,
200.0,
200.0,
200.0,
],
]
)
assert numpy.array_equal(actual_result, expected_result)