enex_analysis.g_function

Borehole g-function and air property helpers.

Provides: - Finite Line Source (FLS) g-function for borehole heat exchangers - Air dynamic viscosity (Sutherland’s formula) and Prandtl number

Functions

G_FLS(t, ks, as_, rb, H)

Calculate the g-function for finite line source (FLS) model.

G_MFLS_Field(times, boreholes, v_gw, ...)

Calculate the spatial superposition of the MFLS response for a bore field.

air_dynamic_viscosity(T_K)

Calculate air dynamic viscosity using Sutherland's formula.

air_prandtl_number(T_K)

Calculate air Prandtl number.

calc_borehole_thermal_resistance(k_s, k_g, ...)

Calculate the effective borehole thermal resistance R_b* [mK/W] for a Single U-tube.

calc_submerged_coil_thermal_resistance(...)

Calculate the local thermal resistance [mK/W] of a submerged surface water heat exchanger coil.

chi(s, rb, H[, z0])

Helper function for G-function calculation.

chi_mfls(s, r, H, x_prime, U, alpha_s[, z0])

Helper function for MFLS (Moving Finite Line Source) G-function calculation.

f(x)

Helper function for G-function calculation.

precompute_gfunction(N_1, N_2, B, H_b, D_b, ...)

Precompute g-function using pygfunction and return an interpolator.

precompute_gfunction_mls(N_1, N_2, B, H_b, ...)

Precompute the MFLS g-function and return an interpolator.

enex_analysis.g_function.f(x)[source]

Helper function for G-function calculation.

Parameters:

xfloat

Input value

Returns:

: float

f(x) = x*erf(x) - (1-exp(-x²))/√π

enex_analysis.g_function.chi(s, rb, H, z0=0)[source]

Helper function for G-function calculation.

Parameters:

sfloat

Integration variable

rbfloat

Borehole radius [m]

Hfloat

Borehole height [m]

z0float, optional

Reference depth [m] (default: 0)

Returns:

: float

chi function value

enex_analysis.g_function.G_FLS(t, ks, as_, rb, H)[source]

Calculate the g-function for finite line source (FLS) model.

This function calculates the g-function used in ground source heat pump analysis. Results are cached for performance.

Parameters:

tfloat

Time [s]

ksfloat

Ground thermal conductivity [W/mK]

as_float

Ground thermal diffusivity [m²/s]

rbfloat

Borehole radius [m]

Hfloat

Borehole height [m]

Returns:

: float or array

g-function value [mK/W]. Returns scalar for single time value, array for multiple time values.

enex_analysis.g_function.precompute_gfunction(N_1, N_2, B, H_b, D_b, r_b, alpha_s, k_s, t_max_s, dt_s)[source]

Precompute g-function using pygfunction and return an interpolator.

Creates a rectangular borehole field and computes the g-function for log-spaced time steps up to t_max_s (plus an extra margin). Returns a callable interp1d object predicting the g-function [mK/W].

Parameters:
  • N_1 (int) – Number of boreholes in x-direction.

  • N_2 (int) – Number of boreholes in y-direction.

  • B (float) – Borehole spacing [m].

  • H_b (float) – Borehole depth/length [m].

  • D_b (float) – Buried depth [m].

  • r_b (float) – Borehole radius [m].

  • alpha_s (float) – Ground thermal diffusivity [m²/s].

  • k_s (float) – Ground thermal conductivity [W/mK].

  • t_max_s (float) – Maximum simulation time [s].

  • dt_s (float) – Simulation timestep [s].

Returns:

Interpolator function mapping time [s] to g-function [mK/W].

Return type:

scipy.interpolate.interp1d

enex_analysis.g_function.chi_mfls(s, r, H, x_prime, U, alpha_s, z0=0)[source]

Helper function for MFLS (Moving Finite Line Source) G-function calculation.

Ref: Molina-Giraldo et al. (2011), “A moving finite line source model to simulate borehole heat exchangers with groundwater advection”

enex_analysis.g_function.G_MFLS_Field(times, boreholes, v_gw, theta_gw, rho_w, c_w, alpha_s, k_s, rho_s, c_s)[source]

Calculate the spatial superposition of the MFLS response for a bore field.

Parameters:
  • times (np.ndarray) – Array of time values [s]

  • boreholes (list) – List of pygfunction Borehole objects

  • v_gw (float) – Darcy velocity of groundwater [m/s]

  • theta_gw (float) – Direction of groundwater flow [rad]

  • rho_w (float) – Density of groundwater [kg/m³]

  • c_w (float) – Specific heat capacity of groundwater [J/kgK]

  • alpha_s (float) – Ground thermal diffusivity [m²/s]

  • k_s (float) – Ground thermal conductivity [W/mK]

  • rho_s (float) – Density of ground [kg/m³]

  • c_s (float) – Specific heat capacity of ground [J/kgK]

Returns:

Dimensional g-values for the entire field over time [mK/W]

Return type:

np.ndarray

enex_analysis.g_function.precompute_gfunction_mls(N_1, N_2, B, H_b, D_b, r_b, alpha_s, k_s, rho_s, c_s, v_gw, theta_gw, rho_w, c_w, t_max_s, dt_s)[source]

Precompute the MFLS g-function and return an interpolator.

Parameters:
  • N_1 (int)

  • N_2 (int)

  • B (float)

  • H_b (float)

  • D_b (float)

  • r_b (float)

  • alpha_s (float)

  • k_s (float)

  • rho_s (float)

  • c_s (float)

  • v_gw (float)

  • theta_gw (float)

  • rho_w (float)

  • c_w (float)

  • t_max_s (float)

  • dt_s (float)

Return type:

interp1d

enex_analysis.g_function.air_dynamic_viscosity(T_K)[source]

Calculate air dynamic viscosity using Sutherland’s formula.

Parameters:

T_Kfloat

Temperature [K]

Returns:

: float

Dynamic viscosity [Pa·s]

Reference: Sutherland’s formula for air mu = mu0 * (T/T0)^1.5 * (T0 + S) / (T + S) where mu0 = 1.716e-5 Pa·s at T0 = 273.15 K, S = 110.4 K

enex_analysis.g_function.air_prandtl_number(T_K)[source]

Calculate air Prandtl number.

Parameters:

T_Kfloat

Temperature [K]

Returns:

: float

Prandtl number [-]

Note: Pr ≈ 0.71 for air at typical temperatures (20-50°C) Temperature dependence is weak, so using constant value.

enex_analysis.g_function.calc_borehole_thermal_resistance(k_s, k_g, k_p, r_b, r_out, r_in, D_s, H_b, m_flow_borehole, rho_f, mu_f, cp_f, k_f)[source]

Calculate the effective borehole thermal resistance R_b* [mK/W] for a Single U-tube.

Implements the full three-stage calculation in a single call:

Stage 1 — Fluid-to-pipe resistance (R_fp):

R_fp = R_conv + R_cond R_conv: convective resistance inside the pipe (Gnielinski correlation). R_cond: conductive resistance through the pipe wall (ln(r_out/r_in)/(2πk_p)).

Stage 2 — 2D cross-section (Local R_b via multipole method):

SingleUTube solves the steady-state 2D Laplace equation in the grout cross-section using Hellström’s multipole expansion (default order J=10). Boundary conditions: R_fp at each pipe surface, T=const at borehole wall. Outputs: Local R_b (fluid → borehole wall, cross-section only).

Stage 3 — Axial short-circuit correction (Effective R_b*):

pipe.effective_borehole_thermal_resistance() applies the Cimmino / Hellström (1991) analytical solution for axial fluid temperature variation and thermal short-circuiting between the two U-tube legs.

For a Single U-tube (series flow), each pipe leg carries the full borehole flow rate; m_flow_borehole is passed directly without division by 2.

Parameters:
  • k_s (float) – Ground thermal conductivity [W/mK]

  • k_g (float) – Grout thermal conductivity [W/mK]

  • k_p (float) – Pipe thermal conductivity [W/mK]

  • r_b (float) – Borehole radius [m]

  • r_out (float) – Pipe outer radius [m]

  • r_in (float) – Pipe inner radius [m]

  • D_s (float) – Distance from borehole centre to pipe centre [m]

  • H_b (float) – Borehole depth [m]

  • m_flow_borehole (float) – Total fluid mass flow rate into the borehole [kg/s]. For a Single U-tube (series), this equals the flow in each pipe leg.

  • rho_f (float) – Fluid density [kg/m³]

  • mu_f (float) – Fluid dynamic viscosity [Pa·s]

  • cp_f (float) – Fluid specific heat capacity [J/kgK]

  • k_f (float) – Fluid thermal conductivity [W/mK]

Returns:

Effective borehole thermal resistance R_b* [mK/W].

Return type:

float

References

enex_analysis.g_function.calc_submerged_coil_thermal_resistance(r_out, r_in, D_s, k_p, m_flow_pipe, rho_f, mu_f, cp_f, k_f, v_river=0.5)[source]

Calculate the local thermal resistance [mK/W] of a submerged surface water heat exchanger coil.

Uses the Churchill-Bernstein correlation for cross-flow forced convection over a cylinder to estimate the external (river water) convective heat transfer coefficient. It tricks pygfunction’s SingleUTube model into capturing this pure pipe resistance without any ground thermal mass by assigning exceptionally high thermal conductivities to the grout and ground.

Parameters:
  • r_out (float) – Pipe outer radius [m]

  • r_in (float) – Pipe inner radius [m]

  • D_s (float) – Shank spacing (half distance between pipes) [m]

  • k_p (float) – Pipe thermal conductivity [W/mK]

  • m_flow_pipe (float) – Mass flow rate per pipe [kg/s]

  • rho_f (float) – Internal fluid density [kg/m³]

  • mu_f (float) – Internal fluid dynamic viscosity [Pa·s]

  • cp_f (float) – Internal fluid specific heat capacity [J/kgK]

  • k_f (float) – Internal fluid thermal conductivity [W/mK]

  • v_river (float) – Velocity of the river water cross-flow [m/s]

Returns:

Thermal resistance of the submerged coil [mK/W].

Return type:

float