-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_diffusion2d_functions.py
More file actions
63 lines (49 loc) · 1.56 KB
/
test_diffusion2d_functions.py
File metadata and controls
63 lines (49 loc) · 1.56 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
"""
Tests for functions in class SolveDiffusion2D
"""
import unittest
from diffusion2d import SolveDiffusion2D
class TestDiffusion2D(unittest.TestCase):
def setUp(self):
self.solver = SolveDiffusion2D()
def test_initialize_domain(self):
"""
Check if nx and ny are calculated correctly.
"""
w = 20.0
h = 10.0
dx = 2.0
dy = 5.0
expected_nx = 10
expected_ny = 2
self.solver.initialize_domain(w, h, dx, dy)
self.assertEqual(self.solver.nx, expected_nx)
self.assertEqual(self.solver.ny, expected_ny)
def test_initialize_physical_parameters(self):
"""
Check if dt is calculated correctly.
"""
d = 5.0
T_cold = 200.0
T_hot = 500.0
self.solver.dx = 2.0
self.solver.dy = 2.0
# 2. Expected output
# dt = (dx^2 * dy^2) / (2 * d * (dx^2 + dy^2))
# dt = (4 * 4) / (2 * 5 * (4 + 4))
# dt = 16 / (10 * 8) = 16 / 80 = 0.2
expected_dt = 0.2
self.solver.initialize_physical_parameters(d, T_cold, T_hot)
self.assertAlmostEqual(self.solver.dt, expected_dt, places=5)
def test_set_initial_condition(self):
"""
Check if u matrix is initialized correctly.
"""
self.solver.nx = 3
self.solver.ny = 3
self.solver.dx = 1.0
self.solver.dy = 1.0
self.solver.T_cold = 100.0
self.solver.T_hot = 200.0
u = self.solver.set_initial_condition()
self.assertEqual(u[0, 0], 100.0)