Skip to content

Commit 2373595

Browse files
committed
Add __add__ function to borefield class
1 parent 147938f commit 2373595

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pygfunction/borefield.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ def __ne__(
107107
check = not self == other_field
108108
return check
109109

110+
def __add__(self,
111+
other_field: Union[Borehole, List[Borehole], Self]) -> Self:
112+
"""Add two borefields together"""
113+
if isinstance(other_field, Borehole):
114+
return Borefield.from_boreholes(self.to_boreholes() + other_field)
115+
if isinstance(other_field, list):
116+
return Borefield.from_boreholes(self.to_boreholes() + other_field)
117+
return Borefield.from_boreholes(self.to_boreholes() + other_field.to_boreholes())
118+
110119
def evaluate_g_function(
111120
self,
112121
alpha: float,

tests/borefield_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ def test_borefield_ne(field, other_field, expected, request):
7575
assert (borefield != other_field) == expected
7676

7777

78+
def test_borefield_add():
79+
borehole = gt.boreholes.Borehole(100, 1, 0.075, 15, 10)
80+
borefield = gt.borefield.Borefield.rectangle_field(2, 1, 6, 6, 100, 1, 0.075)
81+
borefield_2 = gt.borefield.Borefield.from_boreholes([borehole, gt.boreholes.Borehole(110, 1, 0.075, 20, 15)])
82+
assert borefield + borehole == gt.borefield.Borefield.from_boreholes(borefield.to_boreholes() + [borehole])
83+
assert borefield + [borehole] == gt.borefield.Borefield.from_boreholes(borefield.to_boreholes() + [borehole])
84+
assert borefield + borefield_2 == gt.borefield.Borefield.from_boreholes(borefield.to_boreholes()+borefield_2.to_boreholes())
85+
86+
7887
# =============================================================================
7988
# Test evaluate_g_function (vertical boreholes)
8089
# =============================================================================

0 commit comments

Comments
 (0)