Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
MassimoCimmino committed Nov 28, 2024
1 parent 1a5f0c1 commit 59e0d99
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 147 deletions.
21 changes: 8 additions & 13 deletions examples/bore_field_thermal_resistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import AutoMinorLocator
from scipy import pi

import pygfunction as gt

Expand Down Expand Up @@ -61,15 +60,11 @@ def main():
# Borehole field
# -------------------------------------------------------------------------

boreField = []
bore_connectivity = []
for i in range(nBoreholes):
x = i*B
borehole = gt.boreholes.Borehole(H, D, r_b, x, 0.)
boreField.append(borehole)
# Boreholes are connected in series: The index of the upstream
# borehole is that of the previous borehole
bore_connectivity.append(i - 1)
x = np.arange(nBoreholes) * B
borefield = gt.borefield.Borefield(H, D, r_b, x, 0.)
# Boreholes are connected in series: The index of the upstream
# borehole is that of the previous borehole
bore_connectivity = [i - 1 for i in range(nBoreholes)]

# -------------------------------------------------------------------------
# Evaluate the effective bore field thermal resistance
Expand All @@ -91,16 +86,16 @@ def main():
# Fluid to inner pipe wall thermal resistance (Single U-tube)
h_f = gt.pipes.convective_heat_transfer_coefficient_circular_pipe(
m_flow_pipe, r_in, mu_f, rho_f, k_f, cp_f, epsilon)
R_f = 1.0/(h_f*2*pi*r_in)
R_f = 1.0 / (h_f * 2 * np.pi * r_in)

# Single U-tube, same for all boreholes in the bore field
UTubes = []
for borehole in boreField:
for borehole in borefield:
SingleUTube = gt.pipes.SingleUTube(
pos_pipes, r_in, r_out, borehole, k_s, k_g, R_f + R_p)
UTubes.append(SingleUTube)
network = gt.networks.Network(
boreField[:nBoreholes],
borefield[:nBoreholes],
UTubes[:nBoreholes],
bore_connectivity=bore_connectivity[:nBoreholes])

Expand Down
9 changes: 5 additions & 4 deletions examples/comparison_gfunction_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,23 @@ def main():
# Field of 6x4 (n=24) boreholes
N_1 = 6
N_2 = 4
field = gt.boreholes.rectangle_field(N_1, N_2, B, B, H, D, r_b)
borefield = gt.borefield.Borefield.rectangle_field(
N_1, N_2, B, B, H, D, r_b)

# -------------------------------------------------------------------------
# Evaluate g-functions
# -------------------------------------------------------------------------
t0 = perf_counter()
gfunc_detailed = gt.gfunction.gFunction(
field, alpha, time=time, options=options, method='detailed')
borefield, alpha, time=time, options=options, method='detailed')
t1 = perf_counter()
t_detailed = t1 - t0
gfunc_similarities = gt.gfunction.gFunction(
field, alpha, time=time, options=options, method='similarities')
borefield, alpha, time=time, options=options, method='similarities')
t2 = perf_counter()
t_similarities = t2 - t1
gfunc_equivalent = gt.gfunction.gFunction(
field, alpha, time=time, options=options, method='equivalent')
borefield, alpha, time=time, options=options, method='equivalent')
t3 = perf_counter()
t_equivalent = t3 - t2

Expand Down
20 changes: 10 additions & 10 deletions examples/comparison_load_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import matplotlib.pyplot as plt
import numpy as np
from scipy.constants import pi
from scipy.interpolate import interp1d
from scipy.signal import fftconvolve

Expand Down Expand Up @@ -64,12 +63,12 @@ def main():
# -------------------------------------------------------------------------

# The field contains only one borehole
boreField = [gt.boreholes.Borehole(H, D, r_b, x=0., y=0.)]
borehole = gt.boreholes.Borehole(H, D, r_b, x=0., y=0.)
# Evaluate the g-function on a geometrically expanding time grid
time_gFunc = gt.utilities.time_geometric(dt, tmax, 50)
# Calculate g-function
gFunc = gt.gfunction.gFunction(
boreField, alpha, time=time_gFunc, options=options)
borehole, alpha, time=time_gFunc, options=options)

# -------------------------------------------------------------------------
# Simulation
Expand All @@ -88,7 +87,7 @@ def main():
bounds_error=False,
fill_value=(0., gFunc.gFunc[-1]))(time_req)
# Initialize load aggregation scheme
LoadAgg.initialize(gFunc_int/(2*pi*k_s))
LoadAgg.initialize(gFunc_int / (2 * np.pi * k_s))

tic = perf_counter()
for i in range(Nt):
Expand Down Expand Up @@ -116,7 +115,8 @@ def main():
g = interp1d(time_gFunc, gFunc.gFunc)(time)

# Convolution in Fourier domain
T_b_exact = T_g - fftconvolve(dQ, g/(2.0*pi*k_s*H), mode='full')[0:Nt]
T_b_exact = T_g - fftconvolve(
dQ, g / (2.0 * np.pi * k_s * H), mode='full')[0:Nt]

# -------------------------------------------------------------------------
# plot results
Expand Down Expand Up @@ -186,14 +186,14 @@ def synthetic_load(x):

func = (168.0-C)/168.0
for i in [1, 2, 3]:
func += 1.0/(i*pi)*(np.cos(C*pi*i/84.0) - 1.0) \
*(np.sin(pi*i/84.0*(x - B)))
func = func*A*np.sin(pi/12.0*(x - B)) \
*np.sin(pi/4380.0*(x - B))
func += 1.0/(i*np.pi)*(np.cos(C*np.pi*i/84.0) - 1.0) \
*(np.sin(np.pi*i/84.0*(x - B)))
func = func*A*np.sin(np.pi/12.0*(x - B)) \
*np.sin(np.pi/4380.0*(x - B))

y = func + (-1.0)**np.floor(D/8760.0*(x - B))*abs(func) \
+ E*(-1.0)**np.floor(D/8760.0*(x - B)) \
/np.sign(np.cos(D*pi/4380.0*(x - F)) + G)
/np.sign(np.cos(D*np.pi/4380.0*(x - F)) + G)
return -y


Expand Down
17 changes: 7 additions & 10 deletions examples/custom_bore_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
""" Example of definition of a bore field using custom borehole positions.
"""
import numpy as np

import pygfunction as gt


Expand All @@ -20,32 +22,27 @@ def main():
# Position 1 has a borehole that is directly on top of another bore
# Position 2 has a borehole with radius inside of another bore
# The duplicates will be removed with the remove_duplicates function
pos = [(0.0, 0.0),
(0.0, 0.0), # Duplicate (for example purposes)
(0.03, 0.0), # Duplicate (for example purposes)
(5.0, 0.),
(3.5, 4.0),
(1.0, 7.0),
(5.5, 5.5)]
x = np.array([0., 0., 0.03, 5., 3.5, 1., 5.5])
y = np.array([0., 0., 0., 0., 4., 7., 5.5])

# -------------------------------------------------------------------------
# Borehole field
# -------------------------------------------------------------------------

# Build list of boreholes
field = [gt.boreholes.Borehole(H, D, r_b, x, y) for (x, y) in pos]
borefield = gt.borefield.Borefield(H, D, r_b, x, y)

# -------------------------------------------------------------------------
# Find and remove duplicates from borehole field
# -------------------------------------------------------------------------

field = gt.boreholes.remove_duplicates(field, disp=True)
borefield = gt.boreholes.remove_duplicates(borefield, disp=True)

# -------------------------------------------------------------------------
# Draw bore field
# -------------------------------------------------------------------------

gt.boreholes.visualize_field(field)
gt.boreholes.visualize_field(borefield)

return

Expand Down
4 changes: 2 additions & 2 deletions examples/custom_bore_field_from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def main():
# -------------------------------------------------------------------------

# Build list of boreholes
field = gt.boreholes.field_from_file(filename)
borefield = gt.borefield.Borefield.from_file(filename)

# -------------------------------------------------------------------------
# Draw bore field
# -------------------------------------------------------------------------

gt.boreholes.visualize_field(field)
gt.boreholes.visualize_field(borefield)

return

Expand Down
15 changes: 8 additions & 7 deletions examples/discretize_boreholes.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def main():
# Field of 6x4 (n=24) boreholes
N_1 = 6
N_2 = 4
boreField = gt.boreholes.rectangle_field(N_1, N_2, B, B, H, D, r_b)
gt.boreholes.visualize_field(boreField)
nBoreholes = len(boreField)
borefield = gt.borefield.Borefield.rectangle_field(
N_1, N_2, B, B, H, D, r_b)
gt.boreholes.visualize_field(borefield)
nBoreholes = len(borefield)

# -------------------------------------------------------------------------
# Initialize pipe model
Expand All @@ -107,14 +108,14 @@ def main():

# Single U-tube, same for all boreholes in the bore field
UTubes = []
for borehole in boreField:
for borehole in borefield:
SingleUTube = gt.pipes.SingleUTube(
pos_pipes, r_in, r_out, borehole, k_s, k_g, R_f + R_p)
UTubes.append(SingleUTube)
m_flow_network = m_flow_borehole*nBoreholes

# Network of boreholes connected in parallel
network = gt.networks.Network(boreField, UTubes)
network = gt.networks.Network(borefield, UTubes)

# -------------------------------------------------------------------------
# Evaluate the g-functions for the borefield
Expand All @@ -128,7 +129,7 @@ def main():

# Calculate the g-function for uniform borehole wall temperature
gfunc_UBWT_uniform = gt.gfunction.gFunction(
boreField, alpha, time=time, boundary_condition='UBWT',
borefield, alpha, time=time, boundary_condition='UBWT',
options=options_uniform)

# Compute g-function for the MIFT case with equal number of segments per
Expand All @@ -139,7 +140,7 @@ def main():

# Calculate the g-function for uniform borehole wall temperature
gfunc_UBWT_unequal = gt.gfunction.gFunction(
boreField, alpha, time=time, boundary_condition='UBWT',
borefield, alpha, time=time, boundary_condition='UBWT',
options=options_unequal)

# Compute the rmse between the reference cases and the discretized
Expand Down
16 changes: 8 additions & 8 deletions examples/equal_inlet_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import AutoMinorLocator
from scipy import pi

import pygfunction as gt

Expand Down Expand Up @@ -74,8 +73,9 @@ def main():
# Field of 6x4 (n=24) boreholes
N_1 = 6
N_2 = 4
boreField = gt.boreholes.rectangle_field(N_1, N_2, B, B, H, D, r_b)
nBoreholes = len(boreField)
borefield = gt.borefield.Borefield.rectangle_field(
N_1, N_2, B, B, H, D, r_b)
nBoreholes = len(borefield)

# -------------------------------------------------------------------------
# Initialize pipe model
Expand All @@ -88,29 +88,29 @@ def main():
m_flow_pipe = m_flow_borehole
h_f = gt.pipes.convective_heat_transfer_coefficient_circular_pipe(
m_flow_pipe, r_in, mu_f, rho_f, k_f, cp_f, epsilon)
R_f = 1.0/(h_f*2*pi*r_in)
R_f = 1.0 / (h_f * 2 * np.pi * r_in)

# Single U-tube, same for all boreholes in the bore field
UTubes = []
for borehole in boreField:
for borehole in borefield:
SingleUTube = gt.pipes.SingleUTube(
pos_pipes, r_in, r_out, borehole, k_s, k_g, R_f + R_p)
UTubes.append(SingleUTube)
m_flow_network = m_flow_borehole * nBoreholes
network = gt.networks.Network(boreField, UTubes)
network = gt.networks.Network(borefield, UTubes)

# -------------------------------------------------------------------------
# Evaluate the g-functions for the borefield
# -------------------------------------------------------------------------

# Calculate the g-function for uniform heat extraction rate
gfunc_uniform_Q = gt.gfunction.gFunction(
boreField, alpha, time=time, boundary_condition='UHTR',
borefield, alpha, time=time, boundary_condition='UHTR',
options=options)

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

# Calculate the g-function for equal inlet fluid temperature
Expand Down
22 changes: 9 additions & 13 deletions examples/fluid_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""
import matplotlib.pyplot as plt
import numpy as np
from scipy.constants import pi

import pygfunction as gt

Expand Down Expand Up @@ -85,16 +84,13 @@ def main():

# The field contains only one borehole
borehole = gt.boreholes.Borehole(H, D, r_b, x=0., y=0.)
boreField = [borehole]
# Get time values needed for g-function evaluation
time_req = LoadAgg.get_times_for_simulation()
# Calculate g-function
gFunc = gt.gfunction.gFunction(
boreField, alpha, time=time_req, options=options)
# gt.gfunction.uniform_temperature(boreField, time_req, alpha,
# nSegments=nSegments)
borehole, alpha, time=time_req, options=options)
# Initialize load aggregation scheme
LoadAgg.initialize(gFunc.gFunc/(2*pi*k_s))
LoadAgg.initialize(gFunc.gFunc / (2 * np.pi * k_s))

# -------------------------------------------------------------------------
# Initialize pipe models
Expand All @@ -107,11 +103,11 @@ def main():
# U-tube in series)
h_f = gt.pipes.convective_heat_transfer_coefficient_circular_pipe(
m_flow, rp_in, visc_f, den_f, k_f, cp_f, epsilon)
R_f_ser = 1.0/(h_f*2*pi*rp_in)
R_f_ser = 1.0 / (h_f * 2 * np.pi * rp_in)
# Fluid to inner pipe wall thermal resistance (Double U-tube in parallel)
h_f = gt.pipes.convective_heat_transfer_coefficient_circular_pipe(
m_flow/2, rp_in, visc_f, den_f, k_f, cp_f, epsilon)
R_f_par = 1.0/(h_f*2*pi*rp_in)
R_f_par = 1.0 / (h_f * 2 * np.pi * rp_in)

# Single U-tube
SingleUTube = gt.pipes.SingleUTube(pos_single, rp_in, rp_out,
Expand Down Expand Up @@ -284,13 +280,13 @@ def synthetic_load(x):

func = (168.0-C)/168.0
for i in [1, 2, 3]:
func += 1.0/(i*pi)*(np.cos(C*pi*i/84.0)-1.0) \
*(np.sin(pi*i/84.0*(x-B)))
func = func*A*np.sin(pi/12.0*(x-B)) \
*np.sin(pi/4380.0*(x-B))
func += 1.0/(i*np.pi)*(np.cos(C*np.pi*i/84.0)-1.0) \
*(np.sin(np.pi*i/84.0*(x-B)))
func = func*A*np.sin(np.pi/12.0*(x-B)) \
*np.sin(np.pi/4380.0*(x-B))

y = func + (-1.0)**np.floor(D/8760.0*(x-B))*abs(func) \
+ E*(-1.0)**np.floor(D/8760.0*(x-B))/np.sign(np.cos(D*pi/4380.0*(x-F))+G)
+ E*(-1.0)**np.floor(D/8760.0*(x-B))/np.sign(np.cos(D*np.pi/4380.0*(x-F))+G)
return -y


Expand Down
Loading

0 comments on commit 59e0d99

Please sign in to comment.