Skip to content

Commit

Permalink
Implemented tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterpeere committed Nov 11, 2023
1 parent 18666d6 commit 9fd58c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 6 additions & 2 deletions pygfunction/boreholes.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,14 @@ def dense_field(N_1, N_2, B, H, D, r_b, include_last_borehole = True):
"""
borefield = []

# check for line
if N_1 == 1 or N_2 == 1:
return rectangle_field(N_1, N_2, B, B, H, D, r_b)

for j in range(N_2): # y direction
for i in range(N_1): # x direction
x = i * B + (B/2 if j % 2 == 1 else 0)
y = j * B/2
x = i * B*np.sqrt(2) + (B*np.sqrt(2)/2 if j % 2 == 1 else 0)
y = j * B*np.sqrt(2)/2
if include_last_borehole or (j % 2 == 0 or i != N_1 - 1): # last borehole in the x direction on an oneven row
borefield.append(Borehole(H, D, r_b, x, y))

Expand Down
15 changes: 11 additions & 4 deletions tests/boreholes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@ def test_rectangular_field(N_1, N_2, B_1, B_2):
(1, 2, 5., True), # 1 by 2
(2, 2, 5., True), # 2 by 2
(10, 9, 7.5, True), # 10 by 9
(10, 10, 7.5, True), # 10 by 10
(1, 1, 5., False), # 1 by 1
(2, 1, 5., False), # 2 by 1
(1, 2, 5., False), # 1 by 2
(2, 2, 5., False), # 2 by 2
(10, 9, 7.5, False), # 10 by 9
])
def test_rectangular_field(N_1, N_2, B, include_last_element):
(10, 10, 7.5, False), # 10 by 10
])
def test_dense_field(N_1, N_2, B, include_last_element):
H = 150. # Borehole length [m]
D = 4. # Borehole buried depth [m]
r_b = 0.075 # Borehole radius [m]
Expand All @@ -120,10 +123,12 @@ def test_rectangular_field(N_1, N_2, B, include_last_element):
np.subtract.outer(x, x)**2 + np.subtract.outer(y, y)**2)[
~np.eye(len(field), dtype=bool)]

if include_last_element:
if include_last_element or N_1 == 1 or N_2 == 1:
assert len(field) == N_1 * N_2
elif N_2 % 2 == 0:
assert len(field) == N_2 * (2 * N_1 - 1) / 2
else:
assert len(field) == N_2 * N_1 * (N_1 - 1) / 2 + (0 if N_2 % 2 == 0 else N_2)
assert len(field) == (N_2 - 1) * (2 * N_1 - 1) / 2 + N_1

assert np.all(
[np.allclose(H, [b.H for b in field]),
Expand All @@ -140,6 +145,8 @@ def test_rectangular_field(N_1, N_2, B, include_last_element):
(2, 2, 5., 7.5), # 2 by 2 (different x/y spacings)
(10, 9, 7.5, 5.), # 10 by 9 (different x/y spacings)
])


def test_L_shaped_field(N_1, N_2, B_1, B_2):
H = 150. # Borehole length [m]
D = 4. # Borehole buried depth [m]
Expand Down

0 comments on commit 9fd58c2

Please sign in to comment.