From 9fd58c2b3c3ecc94d8b6c4be14a235790ff77a62 Mon Sep 17 00:00:00 2001 From: wouterpeere Date: Sat, 11 Nov 2023 13:14:37 +0100 Subject: [PATCH] Implemented tests --- pygfunction/boreholes.py | 8 ++++++-- tests/boreholes_test.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pygfunction/boreholes.py b/pygfunction/boreholes.py index ace8173..ac700b4 100644 --- a/pygfunction/boreholes.py +++ b/pygfunction/boreholes.py @@ -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)) diff --git a/tests/boreholes_test.py b/tests/boreholes_test.py index 8ff6074..90a119f 100644 --- a/tests/boreholes_test.py +++ b/tests/boreholes_test.py @@ -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] @@ -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]), @@ -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]