Skip to content

Commit

Permalink
Merge pull request #161 from MassimoCimmino/issue158_defaultGFunction…
Browse files Browse the repository at this point in the history
…Parameters

Issue158 default g function parameters
  • Loading branch information
MassimoCimmino authored Nov 10, 2021
2 parents 806ade9 + f7ab708 commit 067b113
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [Issue 124](https://github.com/MassimoCimmino/pygfunction/issues/124) - Reformatted `pipes`and `networks` modules to clarify the expected values for `m_flow` parameters. These are replaced by any of `m_flow_pipe`, `m_flow_borehole` or `m_flow_network` depending on the function or class method. Added a nomenclature of commonly used variables to the documentation.
* [Issue 125](https://github.com/MassimoCimmino/pygfunction/issues/125) - Refactored class methods and docstrings in `Pipe` and `Network` objects to better represent the expected shapes of array inputs and outputs.
* [Issue 154](https://github.com/MassimoCimmino/pygfunction/issues/154) - Replaced `numpy.int` and `numpy.bool` dtypes in array initializations with built-in types `int` and `bool`. `numpy.int` and `numpy.bool` are deprecated as of `numpy` version `1.20`.
* [Issue 158](https://github.com/MassimoCimmino/pygfunction/issues/158) - Changed default parameter values for *g*-function calculations. The `gFunction` class now uses the `'equivalent'` solver by default and a non-uniform discretization of `nSegments=8` given by `utilities.segment_ratios()`.

### Bug fixes

Expand Down
3 changes: 2 additions & 1 deletion pygfunction/examples/comparison_gfunction_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def main():
alpha = 1.0e-6 # Ground thermal diffusivity (m2/s)

# g-Function calculation options
options = {'nSegments': 12, 'disp': True}
options = {'nSegments': 8,
'disp': True}

# Geometrically expanding time vector.
dt = 100*3600. # Time step
Expand Down
3 changes: 2 additions & 1 deletion pygfunction/examples/comparison_load_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def main():
T_g = 10.0 # Undisturbed ground temperature (degC)

# g-Function calculation options
options = {'nSegments':12, 'disp':True}
options = {'nSegments': 8,
'disp': True}

# Simulation parameters
dt = 3600. # Time step (s)
Expand Down
1 change: 1 addition & 0 deletions pygfunction/examples/discretize_boreholes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def main():
# discretization
nSegments_uniform = 48
options_uniform = {'nSegments': nSegments_uniform,
'segment_ratios': None,
'disp': True}
# Number of segments used in the calculation with non-uniform
# discretization
Expand Down
7 changes: 4 additions & 3 deletions pygfunction/examples/equal_inlet_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ def main():
k_f = fluid.k # Fluid thermal conductivity (W/m.K)

# g-Function calculation options
nSegments = 12
options = {'nSegments':nSegments, 'disp':True}
nSegments = 8
options = {'nSegments': nSegments,
'disp': True}

# Geometrically expanding time vector.
dt = 100*3600. # Time step
tmax = 3000. * 8760. * 3600. # Maximum time
Nt = 50 # Number of time steps
Nt = 25 # Number of time steps
ts = H**2/(9.*alpha) # Bore field characteristic time
time = gt.utilities.time_geometric(dt, tmax, Nt)

Expand Down
3 changes: 2 additions & 1 deletion pygfunction/examples/fluid_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def main():
k_f = fluid.k # Fluid thermal conductivity (W/m.K)

# g-Function calculation options
options = {'nSegments':12, 'disp':True}
options = {'nSegments': 8,
'disp': True}

# Simulation parameters
dt = 3600. # Time step (s)
Expand Down
3 changes: 2 additions & 1 deletion pygfunction/examples/fluid_temperature_multiple_boreholes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def main():
k_f = fluid.k # Fluid thermal conductivity (W/m.K)

# g-Function calculation options
options = {'nSegments':12, 'disp':True}
options = {'nSegments': 8,
'disp': True}

# Simulation parameters
dt = 3600. # Time step (s)
Expand Down
13 changes: 7 additions & 6 deletions pygfunction/examples/load_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def main():
k_s = 2.0 # Ground thermal conductivity (W/m.K)
T_g = 10.0 # Undisturbed ground temperature (degC)

# Number of segments per borehole
nSegments = 12
# g-Function calculation options
options = {'nSegments': 8,
'disp': True}

# Simulation parameters
dt = 3600. # Time step (s)
Expand All @@ -55,10 +56,10 @@ def main():
# Get time values needed for g-function evaluation
time_req = LoadAgg.get_times_for_simulation()
# Calculate g-function
gFunc = gt.gfunction.uniform_temperature(boreField, time_req, alpha,
nSegments=nSegments)
gFunc = gt.gfunction.gFunction(
boreField, alpha, time=time_req, options=options)
# Initialize load aggregation scheme
LoadAgg.initialize(gFunc/(2*pi*k_s))
LoadAgg.initialize(gFunc.gFunc/(2*pi*k_s))

# -------------------------------------------------------------------------
# Simulation
Expand All @@ -84,7 +85,7 @@ def main():
dQ = np.zeros(Nt)
dQ[0] = Q_b[0]
# Interpolated g-function
g = interp1d(time_req, gFunc)(time)
g = interp1d(time_req, gFunc.gFunc)(time)
for i in range(1, Nt):
dQ[i] = Q_b[i] - Q_b[i-1]

Expand Down
17 changes: 12 additions & 5 deletions pygfunction/examples/mixed_inlet_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ def main():
k_f = fluid.k # Fluid thermal conductivity (W/m.K)

# g-Function calculation options
nSegments = 12
options = {'nSegments':nSegments, 'disp':True, 'profiles':True}
nSegments = 8
options = {'nSegments': nSegments,
'disp': True,
'profiles': True}
# The similarities method is used since the 'equivalent' method does not
# apply if boreholes are connected in series
method = 'similarities'

# Geometrically expanding time vector.
dt = 100*3600. # Time step
tmax = 3000. * 8760. * 3600. # Maximum time
Nt = 50 # Number of time steps
Nt = 25 # Number of time steps
ts = H_mean**2/(9.*alpha) # Bore field characteristic time
time = gt.utilities.time_geometric(dt, tmax, Nt)

Expand Down Expand Up @@ -115,11 +120,13 @@ def main():

# Calculate the g-function for uniform temperature
gfunc_Tb = gt.gfunction.gFunction(
boreField, alpha, time=time, boundary_condition='UBWT', options=options)
boreField, alpha, time=time, boundary_condition='UBWT',
options=options, method=method)

# Calculate the g-function for mixed inlet fluid conditions
gfunc_equal_Tf_mixed = gt.gfunction.gFunction(
network, alpha, time=time, boundary_condition='MIFT', options=options)
network, alpha, time=time, boundary_condition='MIFT', options=options,
method=method)

# -------------------------------------------------------------------------
# Plot g-functions
Expand Down
19 changes: 14 additions & 5 deletions pygfunction/examples/unequal_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main():
# Geometrically expanding time vector.
dt = 100*3600. # Time step
tmax = 3000. * 8760. * 3600. # Maximum time
Nt = 50 # Number of time steps
Nt = 25 # Number of time steps
ts = H**2/(9.*alpha) # Bore field characteristic time
time = gt.utilities.time_geometric(dt, tmax, Nt)

Expand All @@ -47,14 +47,20 @@ def main():
# Evaluate g-functions with different segment options
# -------------------------------------------------------------------------

# The 'similarities' method is used to consider unequal numbers of segments
# per borehole and to plot heat extraction rate profiles along
# individual boreholes
method = 'similarities'

# Calculate g-function with equal number of segments for all boreholes and
# uniform segment lengths
nSegments = 24
options = {'nSegments': nSegments,
'segment_ratios': None,
'disp': True}

gfunc_equal = gt.gfunction.gFunction(
boreField, alpha, time=time, options=options)
boreField, alpha, time=time, options=options, method=method)

# Calculate g-function with predefined number of segments for each
# borehole, the segment lengths will be uniform along each borehole, but
Expand All @@ -66,10 +72,13 @@ def main():
nSegments[12] = 24
nSegments[14] = 24
nSegments[18] = 24
options = {'nSegments': nSegments, 'disp': True, 'profiles': True}
options = {'nSegments': nSegments,
'segment_ratios': None,
'disp': True,
'profiles': True}

gfunc_unequal = gt.gfunction.gFunction(
boreField, alpha, time=time, options=options)
boreField, alpha, time=time, options=options, method=method)

# Calculate g-function with equal number of segments for each borehole,
# unequal segment lengths along the length of the borehole defined by
Expand All @@ -85,7 +94,7 @@ def main():
'profiles': True}

g_func_predefined = gt.gfunction.gFunction(
boreField, alpha, time=time, options=options)
boreField, alpha, time=time, options=options, method=method)

# -------------------------------------------------------------------------
# Plot g-functions
Expand Down
27 changes: 21 additions & 6 deletions pygfunction/examples/uniform_heat_extraction_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,30 @@ def main():

# g-Function calculation options
# The second field is evaluated with more segments to draw the
# temperature profiles
options = [{'nSegments':1, 'disp':True, 'profiles':True},
{'nSegments':12, 'disp':True, 'profiles':True},
{'nSegments':1, 'disp':True, 'profiles':True}]
# temperature profiles. A uniform discretization is used to compare results
# with Cimmino and Bernier (2014).
options = [{'nSegments': 1,
'segment_ratios': None,
'disp': True,
'profiles': True},
{'nSegments': 12,
'segment_ratios': None,
'disp': True,
'profiles': True},
{'nSegments': 1,
'segment_ratios': None,
'disp': True,
'profiles': True}]

# The 'similarities' method is used to consider unequal numbers of segments
# per borehole and to plot heat extraction rate profiles along
# individual boreholes
method = 'similarities'

# Geometrically expanding time vector.
dt = 100*3600. # Time step
tmax = 3000. * 8760. * 3600. # Maximum time
Nt = 50 # Number of time steps
Nt = 25 # Number of time steps
ts = H**2/(9.*alpha) # Bore field characteristic time
time = gt.utilities.time_geometric(dt, tmax, Nt)

Expand Down Expand Up @@ -76,7 +91,7 @@ def main():
for field in [boreField1, boreField2, boreField3]:
gfunc = gt.gfunction.gFunction(
field, alpha, time=time, boundary_condition='UHTR',
options=options[i])
options=options[i], method=method)
# Draw g-function
ax = gfunc.visualize_g_function().axes[0]
# Draw reference g-function
Expand Down
55 changes: 46 additions & 9 deletions pygfunction/examples/uniform_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""
import matplotlib.pyplot as plt
import numpy as np
from time import time as tic

import pygfunction as gt

Expand All @@ -31,14 +32,20 @@ def main():
filePath = './data/CiBe14_uniform_temperature.txt'

# g-Function calculation options
options = {'nSegments':12, 'disp':True, 'profiles':True}
# A uniform discretization is used to compare results with Cimmino and
# Bernier (2014).
options = {'nSegments': 12,
'segment_ratios': None,
'disp': True,
'profiles': True}

# Geometrically expanding time vector.
dt = 100*3600. # Time step
tmax = 3000. * 8760. * 3600. # Maximum time
Nt = 50 # Number of time steps
Nt = 25 # Number of time steps
ts = H**2/(9.*alpha) # Bore field characteristic time
time = gt.utilities.time_geometric(dt, tmax, Nt)
lntts = np.log(time/ts)

# -------------------------------------------------------------------------
# Borehole fields
Expand Down Expand Up @@ -69,21 +76,51 @@ def main():
# -------------------------------------------------------------------------
i = 0
for field in [boreField1, boreField2, boreField3]:
gfunc = gt.gfunction.gFunction(
field, alpha, time=time, options=options)
# Compare 'similarities' and 'equivalent' solvers
t0 = tic()
gfunc_similarities = gt.gfunction.gFunction(
field, alpha, time=time, options=options, method='similarities')
t1 = tic()
t_similarities = t1 - t0
gfunc_equivalent = gt.gfunction.gFunction(
field, alpha, time=time, options=options, method='equivalent')
t2 = tic()
t_equivalent = t2 - t1
# Draw g-function
ax = gfunc.visualize_g_function().axes[0]
ax = gfunc_similarities.visualize_g_function().axes[0]
ax.plot(lntts, gfunc_equivalent.gFunc)
# Draw reference g-function
ax.plot(data[:,0], data[:,i+1], 'bx')
ax.legend(['pygfunction', 'Cimmino and Bernier (2014)'])
ax.plot(data[:,0], data[:,i+1], 'o')
ax.legend(['similarities (t = {:.3f} sec)'.format(t_similarities),
'equivalent (t = {:.3f} sec)'.format(t_equivalent),
'Cimmino and Bernier (2014)'])
ax.set_title('Field of {} boreholes'.format(len(field)))
plt.tight_layout()
i += 1

# For the second borefield, draw the evolution of heat extraction rates
if i == 2:
gfunc.visualize_heat_extraction_rates(iBoreholes=[18, 12, 14])
gfunc.visualize_heat_extraction_rate_profiles(iBoreholes=[14])
fig = gfunc_similarities.visualize_heat_extraction_rates(
iBoreholes=[18, 12, 14])
fig.suptitle("Field of {} boreholes: 'similarities' solver".format(
len(field)))
fig.tight_layout()

fig = gfunc_equivalent.visualize_heat_extraction_rates()
fig.suptitle("Field of {} boreholes: 'equivalent' solver".format(
len(field)))
fig.tight_layout()

fig = gfunc_similarities.visualize_heat_extraction_rate_profiles(
iBoreholes=[18, 12, 14])
fig.suptitle("Field of {} boreholes: 'similarities' solver".format(
len(field)))
fig.tight_layout()

fig = gfunc_equivalent.visualize_heat_extraction_rate_profiles()
fig.suptitle("Field of {} boreholes: 'equivalent' solver".format(
len(field)))
fig.tight_layout()

return

Expand Down
Loading

0 comments on commit 067b113

Please sign in to comment.