-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest_diffusion2d.py
More file actions
61 lines (48 loc) · 1.42 KB
/
test_diffusion2d.py
File metadata and controls
61 lines (48 loc) · 1.42 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
"""
Tests for functionality checks in class SolveDiffusion2D
"""
import pytest
import numpy as np
from diffusion2d import SolveDiffusion2D
@pytest.fixture
def solver():
solver = SolveDiffusion2D()
return solver
def test_initialize_physical_parameters(solver):
"""
Checks function SolveDiffusion2D.initialize_domain
"""
w = 20.
h = 15.
dx = 0.2
dy = 0.3
d = 5.
T_cold = 200.
T_hot = 500.
solver.initialize_domain(w,h,dx,dy)
solver.initialize_physical_parameters(d,T_cold,T_hot)
expected_dt = 0.00276923076923077
assert solver.dt == pytest.approx(expected_dt), "dt should be approximately {expected_dt}"
def test_set_initial_condition(solver):
"""
Checks function SolveDiffusion2D.get_initial_function
"""
w = 20.
h = 15.
dx = 0.2
dy = 0.3
d = 5.
T_cold = 200.
T_hot = 500.
solver.initialize_domain(w,h,dx,dy)
solver.initialize_physical_parameters(d,T_cold,T_hot)
computed_u = solver.set_initial_condition()
expected_u = solver.T_cold * np.ones((solver.nx, solver.ny))
r, cx, cy = 2, 5, 5
r2 = r ** 2
for i in range(solver.nx):
for j in range(solver.ny):
p2 = (i * solver.dx - cx) ** 2 + (j * solver.dy - cy) ** 2
if p2 < r2:
expected_u[i, j] = solver.T_hot
assert np.array_equal(expected_u, computed_u), "Initial condition array is not equal to the expected"