Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential API for PyGFunction #4

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5294981
example api showing how to pass in config and return gfunction
vtnate Nov 1, 2024
21ccaa8
test demonstrating use of api
vtnate Nov 1, 2024
f6241ab
fix typing and allow options dict
vtnate Nov 6, 2024
97a7068
add todo in api test
vtnate Nov 6, 2024
dce7030
some cleanups
mitchute Nov 8, 2024
a4ec330
fix type hinting that I broke
mitchute Nov 8, 2024
2c3cf40
incorporate suggestions
mitchute Nov 11, 2024
1c9d52a
fix typing
mitchute Nov 11, 2024
a9a18df
more typing
mitchute Nov 11, 2024
3e0869a
cleanup tests
mitchute Nov 12, 2024
b2f5988
Updated API file a bit
Myoldmopar Nov 12, 2024
cbf728c
add docstrings and other documenting comments
mitchute Nov 12, 2024
ce9d520
combine classes, update docs
mitchute Nov 12, 2024
a67ad63
return list
mitchute Nov 12, 2024
a4fb763
Initial implementation of Borefield class
MassimoCimmino Nov 24, 2024
f52c143
Class method to evaluate g-function
MassimoCimmino Nov 24, 2024
5f86520
Change init to use arrays instead of boreholes
MassimoCimmino Nov 27, 2024
7c1bfc8
Fix broadcasting of tilt and orientation
MassimoCimmino Nov 27, 2024
8320711
Fix borefield.from_file to call class init
MassimoCimmino Nov 27, 2024
5f31f6b
Docstrings
MassimoCimmino Nov 27, 2024
4707959
Remove api module
MassimoCimmino Nov 27, 2024
fc78296
Test g-functions
MassimoCimmino Nov 28, 2024
f2d4341
Test borefield.from_boreholes
MassimoCimmino Nov 28, 2024
4806d16
Implement bore field creation methods
MassimoCimmino Nov 28, 2024
d5374ce
Deprecation warnings for old bore field functions
MassimoCimmino Nov 28, 2024
1a5f0c1
Fix Borefield.from_file
MassimoCimmino Nov 28, 2024
59e0d99
Update examples
MassimoCimmino Nov 28, 2024
6027e42
Boreholes can have negative tilt
MassimoCimmino Nov 28, 2024
f999eac
Save field to file
MassimoCimmino Nov 28, 2024
2010311
Fix dense and box fields
MassimoCimmino Nov 28, 2024
4364c06
Update tests
MassimoCimmino Nov 28, 2024
0645d57
Remove blank space
MassimoCimmino Nov 28, 2024
8f5543c
Import Self from typing_extensions
MassimoCimmino Nov 29, 2024
c512fc7
Update CHANGELOG.md
MassimoCimmino Nov 29, 2024
5972850
Update requirements
MassimoCimmino Nov 29, 2024
e3c92d7
Review changes
MassimoCimmino Nov 30, 2024
34d5543
Re-order methods
MassimoCimmino Nov 30, 2024
033c9ac
Implement Borefield.visualize_field
MassimoCimmino Dec 1, 2024
1084a09
Typing for Borefield.visualize_field
MassimoCimmino Dec 1, 2024
a37a8ca
Final review
MassimoCimmino Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions pygfunction/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from pygfunction.gfunction import gFunction
from pygfunction.boreholes import Borehole

from typing import Union, List, Tuple, Dict


class BHFieldParams(object):
vtnate marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, xy_coord_pairs: Union[List[Tuple[float, float]], List[List[float]]],
height: Union[float, List[float]], depth: Union[float, List[float]],
borehole_radius: Union[float, List[float]], tilt_angle: Union[float, List[float]] = 0,
orientation_angle: Union[float, List[float]] = 0):

self.xy_coords = xy_coord_pairs
self.x_coords = [xy_pair[0] for xy_pair in xy_coord_pairs]
self.y_coords = [xy_pair[1] for xy_pair in xy_coord_pairs]
self.num_bh = len(xy_coord_pairs)
self.height = height
self.height_list = []
self.depth = depth
self.depth_list = []
self.bh_radius = borehole_radius
self.bh_radius_list = []
self.tilt_angle = tilt_angle
self.tilt_angle_list = []
self.orientation_angle = orientation_angle
self.orientation_angle_list = []

def setup_list(self, user_value):
if type(user_value) == list:
if len(user_value) != self.num_bh:
assert False
return user_value
else:
return [user_value] * self.num_bh

def as_config(self):
self.height_list = self.setup_list(self.height)
self.depth_list = self.setup_list(self.depth)
self.bh_radius_list = self.setup_list(self.bh_radius)
self.tilt_angle_list = self.setup_list(self.tilt_angle)
self.orientation_angle_list = self.setup_list(self.orientation_angle)

all_bh_configs = zip(self.height_list,
self.depth_list,
self.bh_radius_list,
self.x_coords,
self.y_coords,
self.tilt_angle_list,
self.orientation_angle_list)

return [Borehole(*cfg) for cfg in all_bh_configs]


class GFunctionGenerator(object):

def __init__(self, borehole_field: BHFieldParams,
alpha: float,
time: List[float],
options: Union[Dict[str, str], None] = None,
solver_method: str = "equivalent",
boundary_condition: str = "UHTR"):
"""
Borehole config parameters are defined in the Borehole class
All other parameters are defined in the PyGFunction class
"""

if options is None:
options = {}

self.gfunc = gFunction(
borehole_field.as_config(),
alpha,
time=time,
boundary_condition=boundary_condition,
options=options,
method=solver_method,
)

def to_list(self):
return self.gfunc.gFunc.tolist()
4 changes: 2 additions & 2 deletions pygfunction/gfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class gFunction(object):
of

- 'UHTR' :
**Uniform heat transfer rate**. This is corresponds to boundary
**Uniform heat transfer rate**. This corresponds to boundary
condition *BC-I* as defined by Cimmino and Bernier (2014)
[#gFunction-CimBer2014]_.
- 'UBWT' :
**Uniform borehole wall temperature**. This is corresponds to
**Uniform borehole wall temperature**. This corresponds to
boundary condition *BC-III* as defined by Cimmino and Bernier
(2014) [#gFunction-CimBer2014]_.
- 'MIFT' :
Expand Down
67 changes: 67 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import numpy as np

from unittest import TestCase
from pygfunction.api import GFunctionGenerator, BHFieldParams


class TestAPI(TestCase):

def setUp(self):
self.height = 150
self.depth = 4
self.bh_radius = 0.075

# g-function config
self.alpha = 1e-6 # Ground thermal diffusivity [m2/s]
ts = self.height ** 2 / (9 * self.alpha)
self.time = np.array([0.1, 1., 10.]) * ts

def test_compute_vertical_g_functions_from_api(self):
vtnate marked this conversation as resolved.
Show resolved Hide resolved
# bh locations
xy_coords = [(0, 5), (0, 10), (0, 15), (0, 20)]

# compute g-functions
bh_field_params = BHFieldParams(xy_coords, self.height, self.depth, self.bh_radius)
GFunctionGenerator(bh_field_params, self.alpha, self.time)

def test_compute_inclined_g_functions_from_api(self):
# borehole config
self.height = 150. # Borehole length [m]
self.depth = 4. # Borehole buried self.depth [m]
self.bh_radius = 0.075 # Borehole radius [m]

# bh locations
xy_coords = [(0, 5), (0, 10), (0, 15), (0, 20)]
vtnate marked this conversation as resolved.
Show resolved Hide resolved

# compute g-functions
bh_field_params = BHFieldParams(xy_coords, self.height, self.depth, self.bh_radius, tilt_angle=20,
orientation_angle=20)
GFunctionGenerator(bh_field_params, self.alpha, self.time, solver_method="detailed")

# # Set up initial borehole config values
# complete_borehole_config = [self.height, self.depth, self.bh_radius, x, y, tilt, orientation]
# # print(f"{complete_borehole_config=}=")
# simple_borehole_config = [self.height, self.depth, self.bh_radius, x, y]
# # print(f"{simple_borehole_config=}")
#
# number_of_boreholes = 6
# # only change x, y coordinates between boreholes
# increment_indices = [3, 4]
# # Generate list of lists of borehole configs. Increment each value by 1 to avoid duplicates
# complete_borefield_config = [
# [x + i if idx in increment_indices else x for idx, x in enumerate(complete_borehole_config)] for i in
# range(number_of_boreholes)]
# # pprint(f"{complete_borefield_config=}=")
# simple_borefield_config = [
# [x + i if idx in increment_indices else x for idx, x in enumerate(simple_borehole_config)] for i in
# range(number_of_boreholes)]
# # pprint(f"{simple_borefield_config=}=")
#
# # -- Act
# # TODO: submit various options and test the output
# pyg_1 = GFunctionGenerator(complete_borefield_config, alpha, time, solver_method="detailed")
# pyg_2 = GFunctionGenerator(simple_borefield_config, alpha, time)

# -- Assert
# assert isinstance(pyg_1.to_list(), list)
vtnate marked this conversation as resolved.
Show resolved Hide resolved
# assert isinstance(pyg_2.to_list(), list)
Loading