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

Issue33 commong function interface #84

Merged
merged 28 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
890def6
JCC initial recomendation for g-function interface
Jan 10, 2021
ee338c4
Remove example, the existing examples were modified to use the new in…
MassimoCimmino Apr 8, 2021
d4a776e
Add nominal conditions to Network class
MassimoCimmino Jan 12, 2021
07ff805
Fix gFunction template
MassimoCimmino Jan 24, 2021
3f7e4f9
Add Solver classes
MassimoCimmino Mar 2, 2021
5b65f7d
Display total calculation time for g-function
MassimoCimmino Mar 20, 2021
e82bc40
Add visualization features
MassimoCimmino Mar 20, 2021
cd59974
Partial formatting of gFunction class
MassimoCimmino Mar 30, 2021
ea6e632
Check and format inputs
MassimoCimmino Apr 7, 2021
40c5294
Update existing functions and examples
MassimoCimmino Mar 2, 2021
a2f232a
Add docstrings
MassimoCimmino Apr 8, 2021
b224299
Change default value of options to an empty dict
MassimoCimmino Apr 10, 2021
f47a710
Check for duplicate boreholes at initialization of gFunction
MassimoCimmino Apr 10, 2021
40d61cf
Add dtype option to gFunction solvers
MassimoCimmino Apr 10, 2021
4e025ab
Fix docstrings for references, formatting
MassimoCimmino Apr 15, 2021
40029d7
Format messages for disp True
MassimoCimmino Apr 16, 2021
5d98bd0
Remove Solver classes from public interface
MassimoCimmino Apr 16, 2021
00775cd
Reformat
MassimoCimmino Apr 16, 2021
29099a6
Update CHANGELOG.md
MassimoCimmino Apr 17, 2021
8d2a59d
Update README.md example
MassimoCimmino Apr 22, 2021
d5b165c
Reformat examples
MassimoCimmino Apr 22, 2021
746250d
Reformat docstrings
MassimoCimmino Apr 22, 2021
569ff18
Update CHANGELOD.md
MassimoCimmino Apr 22, 2021
95b9bdc
Add missing time assignement in solve
MassimoCimmino Apr 29, 2021
9e16524
Fix indentation in _BaseSolver.solve
MassimoCimmino May 6, 2021
916c658
Deprecate unused functions in heat_transfer
MassimoCimmino May 15, 2021
2851f8d
Allow float input for time
MassimoCimmino May 17, 2021
6d46830
Update unit tests
MassimoCimmino May 17, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* [Issue 33](https://github.com/MassimoCimmino/pygfunction/issues/33), [Issue 54](https://github.com/MassimoCimmino/pygfunction/issues/54), [Issue 85](https://github.com/MassimoCimmino/pygfunction/issues/85) - New class `gFunction` for the calculation of g-functions. The new class is a common interface to all boundary conditions and calculation methods. The new implementation of the solver reduces the memory requirements of pygfunction. The new class implements visualization features for the g-function and for heat extraction rates and borehole wall temperatures (both as a function of time and for the profiles along the borehole lengths).
* [Issue 75](https://github.com/MassimoCimmino/pygfunction/issues/75) - New module `media` with properties of brine mixtures.
* [Issue 81](https://github.com/MassimoCimmino/pygfunction/issues/81) - Added functions to find a remove duplicate boreholes.

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ the *g*-function of a 10 x 10 square array of boreholes (100 boreholes
total):

```python
time = [(i+1)*3600. for i in range(24)] # Calculate hourly for one day
import pygfunction as gt
import numpy as np
time = np.array([(i+1)*3600. for i in range(24)]) # Calculate hourly for one day
boreField = gt.boreholes.rectangle_field(N_1=10, N_2=10, B_1=7.5, B_2=7.5, H=150., D=4., r_b=0.075)
gFunc = gt.gfunction.uniform_temperature(boreField, time, alpha=1.0e-6)
gFunc = gt.gfunction.gFunction(boreField, alpha=1.0e-6, time=time)
gFunc.visualize_g_function()
```

Once the *g*-function is evaluated, *pygfunction* provides tools to predict
Expand Down
14 changes: 7 additions & 7 deletions pygfunction/examples/comparison_load_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ 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':12, 'disp':True}

# Simulation parameters
dt = 3600. # Time step (s)
Expand All @@ -67,8 +67,8 @@ def main():
time_gFunc = gt.utilities.time_geometric(dt, tmax, 50)
# Calculate g-function
print('Calculation of the g-function ...')
gFunc = gt.gfunction.uniform_temperature(boreField, time_gFunc, alpha,
nSegments=nSegments)
gFunc = gt.gfunction.gFunction(
boreField, alpha, time=time_gFunc, options=options)

# -------------------------------------------------------------------------
# Simulation
Expand All @@ -84,10 +84,10 @@ def main():
# Interpolate g-function at required times
time_req = LoadAgg.get_times_for_simulation()
gFunc_int = interp1d(np.hstack([0., time_gFunc]),
np.hstack([0., gFunc]),
np.hstack([0., gFunc.gFunc]),
kind='cubic',
bounds_error=False,
fill_value=(0., gFunc[-1]))(time_req)
fill_value=(0., gFunc.gFunc[-1]))(time_req)
# Initialize load aggregation scheme
LoadAgg.initialize(gFunc_int/(2*pi*k_s))

Expand Down Expand Up @@ -121,7 +121,7 @@ def main():
dQ[0] = Q[0]
# Interpolated g-function
time = np.array([(j+1)*dt for j in range(Nt)])
g = interp1d(time_gFunc, gFunc)(time)
g = interp1d(time_gFunc, gFunc.gFunc)(time)
for i in range(1, Nt):
dQ[i] = Q[i] - Q[i-1]

Expand Down
46 changes: 17 additions & 29 deletions pygfunction/examples/equal_inlet_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def main():
visc_f = fluid.mu # Fluid dynamic viscosity (kg/m.s)
k_f = fluid.k # Fluid thermal conductivity (W/m.K)

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

# Geometrically expanding time vector.
dt = 100*3600. # Time step
Expand All @@ -75,6 +76,7 @@ def main():
N_1 = 6
N_2 = 4
boreField = gt.boreholes.rectangle_field(N_1, N_2, B, B, H, D, r_b)
nBoreholes = len(boreField)

# -------------------------------------------------------------------------
# Initialize pipe model
Expand All @@ -100,49 +102,35 @@ def main():
SingleUTube = gt.pipes.SingleUTube(pos_pipes, rp_in, rp_out,
borehole, k_s, k_g, R_f + R_p)
UTubes.append(SingleUTube)
network = gt.networks.Network(boreField, UTubes, m_flow=m_flow*nBoreholes,
cp=cp_f, nSegments=nSegments)

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

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

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

# Calculate the g-function for equal inlet fluid temperature
gfunc_equal_Tf_in = gt.gfunction.equal_inlet_temperature(
boreField, UTubes, m_flow, cp_f, time, alpha,
nSegments=nSegments, disp=True)
gfunc_equal_Tf_in = gt.gfunction.gFunction(
network, alpha, time=time, boundary_condition='MIFT', options=options)

# -------------------------------------------------------------------------
# Plot g-functions
# -------------------------------------------------------------------------

plt.rc('figure')
fig = plt.figure()
ax1 = fig.add_subplot(111)
# g-functions
ax1.plot(np.log(time/ts), gfunc_uniform_Q,
'k-', lw=1.5, label='Uniform heat extraction rate')
ax1.plot(np.log(time/ts), gfunc_uniform_T,
'b--', lw=1.5, label='Uniform borehole wall temperature')
ax1.plot(np.log(time/ts), gfunc_equal_Tf_in,
'r-.', lw=1.5, label='Equal inlet temperature')
ax1.legend()
# Axis labels
ax1.set_xlabel(r'$ln(t/t_s)$')
ax1.set_ylabel(r'$g(t/t_s)$')
# Axis limits
ax1.set_xlim([-10.0, 5.0])
ax1.set_ylim([0., 50.])
# Show minor ticks
ax1.xaxis.set_minor_locator(AutoMinorLocator())
ax1.yaxis.set_minor_locator(AutoMinorLocator())
# Adjust to plot window
ax = gfunc_uniform_Q.visualize_g_function().axes[0]
ax.plot(np.log(time/ts), gfunc_uniform_T.gFunc, 'k--')
ax.plot(np.log(time/ts), gfunc_equal_Tf_in.gFunc, 'r-.')
ax.legend(['Uniform heat extraction rate',
'Uniform borehole wall temperature',
'Equal inlet temperature'])
plt.tight_layout()

return
Expand Down
35 changes: 13 additions & 22 deletions pygfunction/examples/fluid_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def main():
visc_f = fluid.mu # Fluid dynamic viscosity (kg/m.s)
k_f = fluid.k # Fluid thermal conductivity (W/m.K)

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

# Simulation parameters
dt = 3600. # Time step (s)
Expand All @@ -87,37 +87,28 @@ 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)
# gt.gfunction.uniform_temperature(boreField, time_req, alpha,
# nSegments=nSegments)
# Initialize load aggregation scheme
LoadAgg.initialize(gFunc/(2*pi*k_s))
LoadAgg.initialize(gFunc.gFunc/(2*pi*k_s))

# -------------------------------------------------------------------------
# Initialize pipe models
# -------------------------------------------------------------------------

# Pipe thermal resistance
R_p = gt.pipes.conduction_thermal_resistance_circular_pipe(rp_in,
rp_out,
k_p)
R_p = gt.pipes.conduction_thermal_resistance_circular_pipe(
rp_in, rp_out, k_p)
# Fluid to inner pipe wall thermal resistance (Single U-tube and double
# 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)
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)
# 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)
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)

# Single U-tube
Expand Down
14 changes: 7 additions & 7 deletions pygfunction/examples/fluid_temperature_multiple_boreholes.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def main():
visc_f = fluid.mu # Fluid dynamic viscosity (kg/m.s)
k_f = fluid.k # Fluid thermal conductivity (W/m.K)

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

# Simulation parameters
dt = 3600. # Time step (s)
Expand Down Expand Up @@ -102,7 +102,7 @@ def main():
nPipes=2, config='parallel')
UTubes.append(UTube)
# Build a network object from the list of UTubes
network = gt.networks.Network(boreField, UTubes)
network = gt.networks.Network(boreField, UTubes, m_flow=m_flow, cp=cp_f)

# -------------------------------------------------------------------------
# Calculate g-function
Expand All @@ -111,11 +111,11 @@ def main():
# Get time values needed for g-function evaluation
time_req = LoadAgg.get_times_for_simulation()
# Calculate g-function
gFunc = gt.gfunction.mixed_inlet_temperature(
network, m_flow, cp_f, time_req, alpha,
nSegments=nSegments, disp=True)
gFunc = gt.gfunction.gFunction(
network, alpha, time=time_req, boundary_condition='MIFT',
options=options)
# Initialize load aggregation scheme
LoadAgg.initialize(gFunc/(2*pi*k_s))
LoadAgg.initialize(gFunc.gFunc/(2*pi*k_s))

# -------------------------------------------------------------------------
# Simulation
Expand Down
62 changes: 23 additions & 39 deletions pygfunction/examples/mixed_inlet_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ def main():
visc_f = fluid.mu # Fluid dynamic viscosity (kg/m.s)
k_f = fluid.k # Fluid thermal conductivity (W/m.K)

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

# Geometrically expanding time vector.
dt = 100*3600. # Time step
Expand Down Expand Up @@ -90,17 +91,11 @@ def main():
# -------------------------------------------------------------------------

# Pipe thermal resistance
R_p = gt.pipes.conduction_thermal_resistance_circular_pipe(rp_in,
rp_out,
k_p)
R_p = gt.pipes.conduction_thermal_resistance_circular_pipe(
rp_in, rp_out, k_p)
# Fluid to inner pipe wall thermal resistance (Single U-tube)
h_f = gt.pipes.convective_heat_transfer_coefficient_circular_pipe(m_flow,
rp_in,
visc_f,
den_f,
k_f,
cp_f,
epsilon)
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 = 1.0/(h_f*2*pi*rp_in)

# Single U-tube, same for all boreholes in the bore field
Expand All @@ -109,49 +104,38 @@ def main():
SingleUTube = gt.pipes.SingleUTube(pos_pipes, rp_in, rp_out,
borehole, k_s, k_g, R_f + R_p)
UTubes.append(SingleUTube)
network = gt.networks.Network(boreField, UTubes, bore_connectivity)
network = gt.networks.Network(
boreField, UTubes, bore_connectivity=bore_connectivity, m_flow=m_flow,
cp=cp_f, nSegments=nSegments)

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

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

# Calculate the g-function for mixed inlet fluid conditions
gfunc_equal_Tf_mixed = \
gt.gfunction.mixed_inlet_temperature(
network, m_flow, cp_f, time, alpha,
nSegments=nSegments, disp=True)
gfunc_equal_Tf_mixed = gt.gfunction.gFunction(
network, alpha, time=time, boundary_condition='MIFT', options=options)

# -------------------------------------------------------------------------
# Plot g-functions
# -------------------------------------------------------------------------

plt.rc('figure')
fig = plt.figure()
ax1 = fig.add_subplot(111)
# g-functions
ax1.plot(np.log(time/ts), gfunc_Tb,
'k-', lw=1.5, label='Uniform temperature')
ax1.plot(np.log(time/ts), gfunc_equal_Tf_mixed,
'r-.', lw=1.5, label='Mixed inlet temperature')
ax1.legend()
# Axis labels
ax1.set_xlabel(r'$ln(t/t_s)$')
ax1.set_ylabel(r'g-function')
# Axis limits
ax1.set_xlim([-10.0, 5.0])
ax1.set_ylim([0., 12.])
# Show minor ticks
ax1.xaxis.set_minor_locator(AutoMinorLocator())
ax1.yaxis.set_minor_locator(AutoMinorLocator())
# Adjust to plot window
ax = gfunc_Tb.visualize_g_function().axes[0]
ax.plot(np.log(time/ts), gfunc_equal_Tf_mixed.gFunc, 'r-.')
ax.legend(['Uniform temperature', 'Mixed inlet temperature'])
plt.tight_layout()

# For the mixed inlet fluid temperature condition, draw the temperatures
# and heat extraction rates
gfunc_equal_Tf_mixed.visualize_temperatures()
gfunc_equal_Tf_mixed.visualize_temperature_profiles()
gfunc_equal_Tf_mixed.visualize_heat_extraction_rates()
gfunc_equal_Tf_mixed.visualize_heat_extraction_rate_profiles()

return


Expand Down
2 changes: 1 addition & 1 deletion pygfunction/examples/multiple_independent_Utubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def main():
k_g = 1.0 # Grout thermal conductivity (W/m.K)

# Fluid properties
R_fp = 0.0 # Fluid to outer pipe wall thermal resistance (m.K/W)
R_fp = 1e-30 # Fluid to outer pipe wall thermal resistance (m.K/W)
# Fluid specific isobaric heat capacity per U-tube (J/kg.K)
cp = 4000.*np.ones(nPipes)

Expand Down
Loading