-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update examples #2
base: master
Are you sure you want to change the base?
Changes from 3 commits
b0c3678
8635f04
56d9ebc
8c48424
9c1056e
a5e5b38
f23915e
41e460e
a48d521
1623eab
9b45dfd
606fc76
4adcd98
77b8321
fbe79b7
5663a43
be9dd6d
9aee938
4f9e8aa
3d9a9c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,18 @@ | |
rates. | ||
|
||
""" | ||
import matplotlib.pyplot as plt | ||
try: | ||
import matplotlib.pyplot as plt | ||
except ModuleNotFoundError: | ||
pass | ||
|
||
import numpy as np | ||
from matplotlib.ticker import AutoMinorLocator | ||
from scipy import pi | ||
from scipy.constants import pi | ||
|
||
import pygfunction as gt | ||
|
||
|
||
def main(): | ||
def main(make_plots=True): | ||
# ------------------------------------------------------------------------- | ||
# Simulation parameters | ||
# ------------------------------------------------------------------------- | ||
|
@@ -114,28 +117,28 @@ def main(): | |
# Plot bore field thermal resistances | ||
# ------------------------------------------------------------------------- | ||
|
||
# Configure figure and axes | ||
fig = gt.utilities._initialize_figure() | ||
if make_plots: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely like this as an optional thing 👍 |
||
|
||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
# ------------------------------------------------------------------------- | ||
|
@@ -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) | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any chance to compile all the plotting into one place? Maybe a single file/class called plotting.py? There seems to be quite a bit of repetition, but each of these also seems a little different. So no biggie if not. Just a thought. |
||
|
||
|
||
# Main function | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Myoldmopar, can you take a look here before I push it all the way through?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might consider storing a variable to indicate whether it has been properly imported or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.