Skip to content

Commit

Permalink
begin updating examples to run during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchute committed Jul 11, 2024
1 parent b0c3678 commit 8635f04
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 155 deletions.
44 changes: 24 additions & 20 deletions examples/bore_field_thermal_resistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
rates.
"""
import matplotlib.pyplot as plt
try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
pass

import numpy as np
from scipy.constants import pi

import pygfunction as gt


def main():
def main(make_plots=True):
# -------------------------------------------------------------------------
# Simulation parameters
# -------------------------------------------------------------------------
Expand Down Expand Up @@ -113,28 +117,28 @@ def main():
# Plot bore field thermal resistances
# -------------------------------------------------------------------------

# Configure figure and axes
fig = gt.utilities._initialize_figure()
if make_plots:

ax1 = fig.add_subplot(111)
# Axis labels
ax1.set_xlabel(r'$\dot{m}$ [kg/s]')
ax1.set_ylabel(r'$R^*_{field}$ [m.K/W]')
# Axis limits
ax1.set_xlim([0., 1.])
ax1.set_ylim([0., 1.])
# Configure figure and axes
fig = gt.utilities._initialize_figure()

gt.utilities._format_axes(ax1)
ax1 = fig.add_subplot(111)
# Axis labels
ax1.set_xlabel(r'$\dot{m}$ [kg/s]')
ax1.set_ylabel(r'$R^*_{field}$ [m.K/W]')
# Axis limits
ax1.set_xlim([0., 1.])
ax1.set_ylim([0., 1.])

# Bore field thermal resistances
ax1.plot(m_flow_network, R[0,:], '-', label='1 borehole')
ax1.plot(m_flow_network, R[2,:], '--', label='3 boreholes')
ax1.plot(m_flow_network, R[4,:], '-.', label='5 boreholes')
ax1.legend()
# Adjust to plot window
plt.tight_layout()
gt.utilities._format_axes(ax1)

return
# Bore field thermal resistances
ax1.plot(m_flow_network, R[0,:], '-', label='1 borehole')
ax1.plot(m_flow_network, R[2,:], '--', label='3 boreholes')
ax1.plot(m_flow_network, R[4,:], '-.', label='5 boreholes')
ax1.legend()
# Adjust to plot window
plt.tight_layout()


# Main function
Expand Down
204 changes: 105 additions & 99 deletions examples/comparison_gfunction_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
speed while maintaining reasonable accuracy.
"""
import matplotlib.pyplot as plt
try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
pass

import numpy as np
from time import perf_counter

import pygfunction as gt


def main():
def main(make_plots=True):
# -------------------------------------------------------------------------
# Simulation parameters
# -------------------------------------------------------------------------
Expand Down Expand Up @@ -77,57 +81,59 @@ def main():
t3 = perf_counter()
t_equivalent = t3 - t2

# -------------------------------------------------------------------------
# Plot results
# -------------------------------------------------------------------------
# Draw g-functions
ax = gfunc_detailed.visualize_g_function().axes[0]
ax.plot(lntts, gfunc_similarities.gFunc, 'bx')
ax.plot(lntts, gfunc_equivalent.gFunc, 'ro')
ax.legend([f'detailed (t = {t_detailed:.3f} sec)',
f'similarities (t = {t_similarities:.3f} sec)',
f'equivalent (t = {t_equivalent:.3f} sec)'])
ax.set_title(f'Field of {N_1} by {N_2} boreholes')
plt.tight_layout()

# Draw absolute error
# Configure figure and axes
fig = gt.utilities._initialize_figure()
ax = fig.add_subplot(111)
# Axis labels
ax.set_xlabel(r'ln$(t/t_s)$')
ax.set_ylabel(r'Absolute error')
gt.utilities._format_axes(ax)
# Absolute error
ax.plot(lntts, np.abs(gfunc_similarities.gFunc - gfunc_detailed.gFunc),
'-', label='similarities')
ax.plot(lntts, np.abs(gfunc_equivalent.gFunc - gfunc_detailed.gFunc),
'--', label='equivalent')
ax.legend()
ax.set_title(f"Absolute error relative to the 'detailed' solver "
f"(Field of {N_1} by {N_2} boreholes)")
# Adjust to plot window
fig.tight_layout()

# Draw relative error
# Configure figure and axes
fig = gt.utilities._initialize_figure()
ax = fig.add_subplot(111)
# Axis labels
ax.set_xlabel(r'ln$(t/t_s)$')
ax.set_ylabel(r'Relative error')
gt.utilities._format_axes(ax)
# Relative error
gFunc_ref = gfunc_detailed.gFunc # reference g-function
ax.plot(lntts, (gfunc_similarities.gFunc - gFunc_ref) / gFunc_ref,
'-', label='similarities')
ax.plot(lntts, (gfunc_equivalent.gFunc - gFunc_ref) / gFunc_ref,
'--', label='equivalent')
ax.legend()
ax.set_title(f"Relative error relative to the 'detailed' solver "
f"(Field of {N_1} by {N_2} boreholes)")
# Adjust to plot window
fig.tight_layout()
if make_plots:

# -------------------------------------------------------------------------
# Plot results
# -------------------------------------------------------------------------
# Draw g-functions
ax = gfunc_detailed.visualize_g_function().axes[0]
ax.plot(lntts, gfunc_similarities.gFunc, 'bx')
ax.plot(lntts, gfunc_equivalent.gFunc, 'ro')
ax.legend([f'detailed (t = {t_detailed:.3f} sec)',
f'similarities (t = {t_similarities:.3f} sec)',
f'equivalent (t = {t_equivalent:.3f} sec)'])
ax.set_title(f'Field of {N_1} by {N_2} boreholes')
plt.tight_layout()

# Draw absolute error
# Configure figure and axes
fig = gt.utilities._initialize_figure()
ax = fig.add_subplot(111)
# Axis labels
ax.set_xlabel(r'ln$(t/t_s)$')
ax.set_ylabel(r'Absolute error')
gt.utilities._format_axes(ax)
# Absolute error
ax.plot(lntts, np.abs(gfunc_similarities.gFunc - gfunc_detailed.gFunc),
'-', label='similarities')
ax.plot(lntts, np.abs(gfunc_equivalent.gFunc - gfunc_detailed.gFunc),
'--', label='equivalent')
ax.legend()
ax.set_title(f"Absolute error relative to the 'detailed' solver "
f"(Field of {N_1} by {N_2} boreholes)")
# Adjust to plot window
fig.tight_layout()

# Draw relative error
# Configure figure and axes
fig = gt.utilities._initialize_figure()
ax = fig.add_subplot(111)
# Axis labels
ax.set_xlabel(r'ln$(t/t_s)$')
ax.set_ylabel(r'Relative error')
gt.utilities._format_axes(ax)
# Relative error
gFunc_ref = gfunc_detailed.gFunc # reference g-function
ax.plot(lntts, (gfunc_similarities.gFunc - gFunc_ref) / gFunc_ref,
'-', label='similarities')
ax.plot(lntts, (gfunc_equivalent.gFunc - gFunc_ref) / gFunc_ref,
'--', label='equivalent')
ax.legend()
ax.set_title(f"Relative error relative to the 'detailed' solver "
f"(Field of {N_1} by {N_2} boreholes)")
# Adjust to plot window
fig.tight_layout()

# -------------------------------------------------------------------------
# Borehole field (Second bore field)
Expand All @@ -150,52 +156,52 @@ def main():
t3 = perf_counter()
t_equivalent = t3 - t2

# -------------------------------------------------------------------------
# Plot results
# -------------------------------------------------------------------------
# Draw g-functions
ax = gfunc_similarities.visualize_g_function().axes[0]
ax.plot(lntts, gfunc_equivalent.gFunc, 'ro')
ax.legend([f'similarities (t = {t_similarities:.3f} sec)',
f'equivalent (t = {t_equivalent:.3f} sec)'])
ax.set_title(f'Field of {N_1} by {N_2} boreholes')
plt.tight_layout()

# Draw absolute error
# Configure figure and axes
fig = gt.utilities._initialize_figure()
ax = fig.add_subplot(111)
# Axis labels
ax.set_xlabel(r'ln$(t/t_s)$')
ax.set_ylabel(r'Absolute error')
gt.utilities._format_axes(ax)
# Absolute error
ax.plot(lntts, np.abs(gfunc_equivalent.gFunc - gfunc_similarities.gFunc),
label='equivalent')
ax.legend()
ax.set_title(f"Absolute error relative to the 'similarities' solver "
f"(Field of {N_1} by {N_2} boreholes)")
# Adjust to plot window
fig.tight_layout()

# Draw relative error
# Configure figure and axes
fig = gt.utilities._initialize_figure()
ax = fig.add_subplot(111)
# Axis labels
ax.set_xlabel(r'ln$(t/t_s)$')
ax.set_ylabel(r'Relative error')
gt.utilities._format_axes(ax)
# Relative error
ax.plot(lntts, (gfunc_equivalent.gFunc - gfunc_similarities.gFunc) / gfunc_similarities.gFunc,
label='equivalent')
ax.legend()
ax.set_title(f"Relative error relative to the 'similarities' solver "
f"(Field of {N_1} by {N_2} boreholes)")
# Adjust to plot window
fig.tight_layout()

return
if make_plots:

# -------------------------------------------------------------------------
# Plot results
# -------------------------------------------------------------------------
# Draw g-functions
ax = gfunc_similarities.visualize_g_function().axes[0]
ax.plot(lntts, gfunc_equivalent.gFunc, 'ro')
ax.legend([f'similarities (t = {t_similarities:.3f} sec)',
f'equivalent (t = {t_equivalent:.3f} sec)'])
ax.set_title(f'Field of {N_1} by {N_2} boreholes')
plt.tight_layout()

# Draw absolute error
# Configure figure and axes
fig = gt.utilities._initialize_figure()
ax = fig.add_subplot(111)
# Axis labels
ax.set_xlabel(r'ln$(t/t_s)$')
ax.set_ylabel(r'Absolute error')
gt.utilities._format_axes(ax)
# Absolute error
ax.plot(lntts, np.abs(gfunc_equivalent.gFunc - gfunc_similarities.gFunc),
label='equivalent')
ax.legend()
ax.set_title(f"Absolute error relative to the 'similarities' solver "
f"(Field of {N_1} by {N_2} boreholes)")
# Adjust to plot window
fig.tight_layout()

# Draw relative error
# Configure figure and axes
fig = gt.utilities._initialize_figure()
ax = fig.add_subplot(111)
# Axis labels
ax.set_xlabel(r'ln$(t/t_s)$')
ax.set_ylabel(r'Relative error')
gt.utilities._format_axes(ax)
# Relative error
ax.plot(lntts, (gfunc_equivalent.gFunc - gfunc_similarities.gFunc) / gfunc_similarities.gFunc,
label='equivalent')
ax.legend()
ax.set_title(f"Relative error relative to the 'similarities' solver "
f"(Field of {N_1} by {N_2} boreholes)")
# Adjust to plot window
fig.tight_layout()


# Main function
Expand Down
78 changes: 42 additions & 36 deletions examples/comparison_load_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
"""
from time import perf_counter

import matplotlib.pyplot as plt
try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
pass

import numpy as np
from scipy.constants import pi
from scipy.interpolate import interp1d
Expand All @@ -23,7 +27,7 @@
import pygfunction as gt


def main():
def main(make_plots=True):
# -------------------------------------------------------------------------
# Simulation parameters
# -------------------------------------------------------------------------
Expand Down Expand Up @@ -118,40 +122,42 @@ def main():
# Convolution in Fourier domain
T_b_exact = T_g - fftconvolve(dQ, g/(2.0*pi*k_s*H), mode='full')[0:Nt]

# -------------------------------------------------------------------------
# plot results
# -------------------------------------------------------------------------

# Configure figure and axes
fig = gt.utilities._initialize_figure()

ax1 = fig.add_subplot(311)
# Axis labels
ax1.set_xlabel(r'$t$ [hours]')
ax1.set_ylabel(r'$Q_b$ [W]')
gt.utilities._format_axes(ax1)
hours = np.array([(j+1)*dt/3600. for j in range(Nt)])
ax1.plot(hours, Q_b)

ax2 = fig.add_subplot(312)
# Axis labels
ax2.set_xlabel(r'$t$ [hours]')
ax2.set_ylabel(r'$T_b$ [degC]')
gt.utilities._format_axes(ax2)
for T_b_n, line, label in zip(T_b, loadAgg_lines, loadAgg_labels):
ax2.plot(hours, T_b_n, line, label=label)
ax2.plot(hours, T_b_exact, 'k.', label='exact')
ax2.legend()

ax3 = fig.add_subplot(313)
# Axis labels
ax3.set_xlabel(r'$t$ [hours]')
ax3.set_ylabel(r'Error [degC]')
gt.utilities._format_axes(ax3)
for T_b_n, line, label in zip(T_b, loadAgg_lines, loadAgg_labels):
ax3.plot(hours, T_b_n - T_b_exact, line, label=label)
# Adjust to plot window
plt.tight_layout()
if make_plots:

# -------------------------------------------------------------------------
# plot results
# -------------------------------------------------------------------------

# Configure figure and axes
fig = gt.utilities._initialize_figure()

ax1 = fig.add_subplot(311)
# Axis labels
ax1.set_xlabel(r'$t$ [hours]')
ax1.set_ylabel(r'$Q_b$ [W]')
gt.utilities._format_axes(ax1)
hours = np.array([(j+1)*dt/3600. for j in range(Nt)])
ax1.plot(hours, Q_b)

ax2 = fig.add_subplot(312)
# Axis labels
ax2.set_xlabel(r'$t$ [hours]')
ax2.set_ylabel(r'$T_b$ [degC]')
gt.utilities._format_axes(ax2)
for T_b_n, line, label in zip(T_b, loadAgg_lines, loadAgg_labels):
ax2.plot(hours, T_b_n, line, label=label)
ax2.plot(hours, T_b_exact, 'k.', label='exact')
ax2.legend()

ax3 = fig.add_subplot(313)
# Axis labels
ax3.set_xlabel(r'$t$ [hours]')
ax3.set_ylabel(r'Error [degC]')
gt.utilities._format_axes(ax3)
for T_b_n, line, label in zip(T_b, loadAgg_lines, loadAgg_labels):
ax3.plot(hours, T_b_n - T_b_exact, line, label=label)
# Adjust to plot window
plt.tight_layout()

# -------------------------------------------------------------------------
# Print performance metrics
Expand Down

0 comments on commit 8635f04

Please sign in to comment.