Heat transfer & exchangers¶
ε-NTU heat exchanger calculations, the air-side fan + heat-exchanger model used by ASHP/ASHPB, and the borehole g-function and coupling abstractions used by GSHP/GSHPB.
ε-NTU heat exchanger¶
Heat transfer and fluid dynamics calculations.
- tmhp.heat_transfer.TRIDIAG_MATRIX_ALGORITHM(a_M, a_P, a_E, a_W, b_P)[source]¶
Solve tridiagonal matrix system using Thomas algorithm.
- Parameters:
a_M (
list[float]) – Main diagonal (a_P in standard notation).a_P (
list[float]) – Not used directly, maintained for signature compatibility.a_E (
list[float]) – Upper diagonal.a_W (
list[float]) – Lower diagonal.b_P (
list[float]) – RHS vector.
- Returns:
Solution vector.
- Return type:
list[float]
- tmhp.heat_transfer.calc_LMTD_counter_flow(Th_in, Th_out, Tc_in, Tc_out)[source]¶
Calculate Log-Mean Temperature Difference for counter-flow heat exchanger.
- Parameters:
Th_in (
float) – Hot stream inlet temp [K].Th_out (
float) – Hot stream outlet temp [K].Tc_in (
float) – Cold stream inlet temp [K].Tc_out (
float) – Cold stream outlet temp [K].
- Returns:
LMTD [K].
- Return type:
float
- tmhp.heat_transfer.calc_LMTD_parallel_flow(Th_in, Th_out, Tc_in, Tc_out)[source]¶
Calculate Log-Mean Temperature Difference for parallel-flow heat exchanger.
- Parameters:
Th_in (
float) – Hot stream inlet temp [K].Th_out (
float) – Hot stream outlet temp [K].Tc_in (
float) – Cold stream inlet temp [K].Tc_out (
float) – Cold stream outlet temp [K].
- Returns:
LMTD [K].
- Return type:
float
- tmhp.heat_transfer.calc_UA_tank_arr(arr_D_in, arr_D_out, arr_L, arr_k, h_in, h_out)[source]¶
Calculate thermal conductance (UA) of a multi-layer cylindrical tank.
- Parameters:
arr_D_in (
list[float]) – Inner diameters of layers [m].arr_D_out (
list[float]) – Outer diameters of layers [m].arr_L (
list[float]) – Lengths of layers [m].arr_k (
list[float]) – Thermal conductivities of layers [W/mK].h_in (
float) – Inner convection coefficient [W/m2K].h_out (
float) – Outer convection coefficient [W/m2K].
- Returns:
Thermal conductance [W/K].
- Return type:
float
- tmhp.heat_transfer.calc_h_vertical_plate(T_s, T_inf, L, fluid='Air', is_active=True)[source]¶
Calculate natural convection heat transfer coefficient for a vertical plate.
- Parameters:
T_s (
float) – Surface temperature [K].T_inf (
float) – Fluid temperature [K].L (
float) – Characteristic length [m].fluid (
str) – Fluid name. Default is ‘Air’.is_active (
bool) – If False, returns np.nan.
- Returns:
Heat transfer coefficient [W/m2K].
- Return type:
float
- tmhp.heat_transfer.calc_simple_tank_UA(r0=0.2, H=0.8, x_shell=0.01, x_ins=0.1, k_shell=25.0, k_ins=0.03, h_o=10.0)[source]¶
Calculate simple tank UA value.
- Parameters:
r0 (
float) – Tank radius [m]H (
float) – Tank height [m]x_shell (
float) – Shell thickness [m]x_ins (
float) – Insulation thickness [m]k_shell (
float) – Shell thermal conductivity [W/mK]k_ins (
float) – Insulation thermal conductivity [W/mK]h_o (
float) – External convective heat transfer coefficient [W/m²K]
- Returns:
Tank UA value [W/K]
- Return type:
float
- tmhp.heat_transfer.darcy_friction_factor(Re, e, d, is_active=True)[source]¶
Calculate the Darcy friction factor.
Uses Haaland equation.
- Parameters:
Re (
float) – Reynolds number.e (
float) – Surface roughness [m].d (
float) – Diameter [m].is_active (
bool) – If False, returns np.nan.
- Returns:
Friction factor.
- Return type:
float
Air-side fan & heat exchanger¶
Air-side fan UA and power utility functions.
Airflow-based correlations for the outdoor-coil heat exchanger: a
velocity-dependent UA scaling law (calc_UA_from_dV_fan) and a fan power
curve (calc_fan_power_from_dV_fan). HX performance solving lives in
enex_functions and HP schedule checking in dynamic_context.
- tmhp.hx_fan.is_generic_fan_curve(vsd_coeffs)[source]¶
Identify the unmodified ASHRAE Appendix G Method 2 correlation.
- Parameters:
vsd_coeffs (
dict|None)- Return type:
bool
- tmhp.hx_fan.calc_ashrae_fan_power_ratio(flow_ratio)[source]¶
Raw Appendix G Method 2 fit for table parity, not a flow controller.
Table G3.1.3.15 Method 1 spans 0–1. Its x=0.1 row can be compared mathematically, but generic operating control separately enforces x>=0.15. Source: https://www.ashrae.org/file%20library/technical%20resources/standards%20and%20guidelines/standards%20addenda/90.1-2016/90_1_2016_be_bm_bn_bo_bp_br_bs_bu_bv_cf_cl_cm_cq_ct_cu_cv_cw_cy_20210324.pdf
- Parameters:
flow_ratio (
float)- Return type:
float
- tmhp.hx_fan.calc_fan_operating_point(dV_fan, fan_params, vsd_coeffs, is_active=True)[source]¶
Clamp fan flow to its model/control limits, then compute power.
The default is the single-zone VAV surrogate with an independent 10% electrical floor. Its 15% airflow bound is a TMHP control assumption. The following fixed-SP curve remains an explicit alternative.
Source: ANSI/ASHRAE/IES Standard 90.1-2016, Appendix G, Table G3.1.3.15, Method 2: P* = 0.0013 + 0.1470*x + 0.9506*x**2 - 0.0998*x**3. x = actual airflow / fixed reference airflow. The generic correlation is restricted to 0.15 <= x <= 1.0. ASHRAE 2025 Fundamentals Chapter 19 cautions against extrapolation below a minimum ratio (example 0.15). 90.1-2022 Addendum u is supporting multizone-VAV turndown evidence; its informative foreword discusses 16% power at 15% airflow, not a normative 16% requirement or a universal electrical floor. The amended body 6.5.3.2.1(b) removes the old 30% power sentence without adding 16%. Its airflow turndown provision includes the design minimum outdoor air. Evidence: references/fan_model/01_ashrae_90_1_fan_curve.png through 04_ashrae_addendum_u_normative.png, captured in Windows Chrome via CDP. Generic 0.15–1.0 is a TMHP assumption, not a heat-pump requirement. Nondefault user coefficients define a custom curve with explicit limits. A raw demand is clamped here; HX solvers must separately close heat duty. An optional
power_min_ratioimplements a part-flow electrical power floor independently of those airflow bounds: P/P_ref=max(polynomial, floor). It does not invert the power curve to impose a minimum airflow. The SINGLE_ZONE_VAV_COEFFICIENTS alternative comes from PNNL-26917, PRM Reference Manual, Eq. (11) / Table 50 (printed pp. 3.153–3.154). That row is a single-zone/static-pressure-reset modeling surrogate, not a measured fan curve or a requirement for every heat pump.- Parameters:
dV_fan (
float) – Current flow rate [m³/s].fan_params (
dict) – Must containfan_design_flow_rateandfan_design_power.vsd_coeffs (
dict|None) – VSD Curve coefficients (c1throughc5).is_active (
bool) – If False, reports zero actual flow andnp.nanpower.
- Returns:
Actual flow, ratio, power [W] and min/max limit flags.
- Return type:
dict
- tmhp.hx_fan.calc_fan_power_from_dV_fan(dV_fan, fan_params, vsd_coeffs, is_active=True)[source]¶
Electrical power [W] at the bounded fan operating point.
ASHRAE Appendix G Method 2 uses its unchanged empirical coefficients only over 0.15–1.0 of reference airflow. See calc_fan_operating_point for actual flow and limit flags. The default single-zone surrogate has a 10% electrical floor; custom settings may explicitly supply an independent
power_min_ratio.- Parameters:
dV_fan (
float)fan_params (
dict)vsd_coeffs (
dict|None)is_active (
bool)
- Return type:
float
Air properties¶
Air properties at the state an air coil draws its air.
A fan moves a volume of air, a coil exchanges heat with a mass of it. The two
are tied by the density of the air the fan draws, and that density follows the
air temperature: at a fixed volume flow, air at -25 degC carries 16 % more mass
(and heat capacity) than the 15 degC standard air of constants.rho_a, air
at 35 degC 6.5 % less.
air_density is the ideal-gas density of dry air,
rho = P / (R_a T), with R_a = 287.055 J/(kg K) (constants.R_a).
At 15 degC and 101 325 Pa it gives 1.2250 kg/m3, the value of
constants.rho_a, so the two agree at the standard state.
What is left out, and how much it is:
Humidity. Water vapour makes moist air lighter and its specific heat larger; per cubic metre the two nearly cancel. At 20 degC and 50 % relative humidity the sensible heat capacity of a cubic metre is 0.2 % above the dry-air figure, at 35 degC and 40 % it is 0.3 % above. The coils of the cycle models exchange sensible heat with a dry-air stream, so dry air is used; the optional wet indoor coil of the air-to-air model adds its latent heat on top of the same dry-air heat capacity rate (
tmhp.heat_exchanger.calc_HX_perf_for_target_heat()).Specific heat.
constants.c_a(1005 J/(kg K)) is kept constant: the specific heat of dry air changes by 0.1 % between -25 and 40 degC.Altitude. The pressure argument defaults to one standard atmosphere. The models use that default; at 1 600 m the density is 18 % lower.
Fan power. The fan curves stay functions of the volume flow at the rated static pressure. By the fan laws the pressure rise, and so the power, is proportional to the density at a fixed volume flow; the models do not apply that (outdoor fan at -25 degC: +16 % of its power, 0.5 to 0.7 % of the total electrical input).
The volume flows of the air-source models (dV_ou_a, dV_iu_a, the fan
references and limits) are volumes at the coil inlet state, so the air mass
flow of a coil is air_density(T_in) * dV and is the same before and after
the coil and the fan.
- tmhp.air_properties.air_density(T_C, P=101325.0)[source]¶
Density of dry air [kg/m3] at temperature
T_C[degC] and pressureP[Pa].Ideal gas,
rho = P / (R_a (T_C + 273.15)).T_Cmay be a scalar or an array-like (NumPy array, pandas Series); the result has the same shape. A scalar at or below absolute zero, or a non-positive pressure, raisesValueError.Examples
>>> round(air_density(15.0), 4) 1.225 >>> round(air_density(-25.0), 3), round(air_density(35.0), 3) (1.422, 1.145)
- Parameters:
T_C (
Any)P (
float)
- Return type:
Any
- tmhp.air_properties.air_heat_capacity_rate(dV, T_C, P=101325.0)[source]¶
Heat capacity rate of an air stream [W/K]:
c_a * air_density(T_C, P) * dV.dV[m3/s] is the volume flow at the state (T_C[degC],P[Pa]) the density is taken at – for a coil, its inlet air.- Parameters:
dV (
Any)T_C (
Any)P (
float)
- Return type:
Any
Borehole 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
- tmhp.g_function.f(x)[source]¶
Helper function for G-function calculation.
- Parameters:
x (float) – Input value
- Returns:
f(x) = x*erf(x) - (1-exp(-x²))/√π
- Return type:
float
- tmhp.g_function.chi(s, rb, H, z0=0)[source]¶
Helper function for G-function calculation.
- Parameters:
s (float) – Integration variable
rb (float) – Borehole radius [m]
H (float) – Borehole height [m]
z0 (float, optional) – Reference depth [m] (default: 0)
- Returns:
chi function value
- Return type:
float
- tmhp.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. Scalar results are cached by the input values in a bounded cache.
- Parameters:
t (
float|ndarray) – Positive time or times [s], in any order.ks (
float) – Ground thermal conductivity [W/mK]as (float) – Ground thermal diffusivity [m²/s]
rb (
float) – Borehole radius [m]H (
float) – Borehole height [m]as_ (
float)
- Returns:
g-function value [mK/W]. Scalar and zero-dimensional inputs return a float. Array inputs return a flat array, including arrays of length one.
- Return type:
float|ndarray
- class tmhp.g_function.GFunction(N_1, N_2, B, H_b, D_b, r_b, alpha_s, k_s, t_max_s, dt_s, boundary_condition='UBWT', num=100)[source]¶
Bases:
objectDimensional g-function
g(t)[m·K/W] of a bore field.Built by
precompute_gfunction(); callable like thescipy.interpolate.interp1dit replaces (g(t)for a scalar or an array of times [s]).Values. pygfunction is evaluated on a log-spaced grid from
t_min = 3600 sto the horizon, withg(0) = 0prepended; between nodes the value is interpolated linearly int(relative error ≤ 7e-4 against direct pygfunction evaluation for the default grid density). Belowt_minthe value is the straight line from(0, 0)to the first node: the model has no grout or fluid heat capacity, so the response in the first hour is only approximate.Horizon. The grid ends at
1.5 * t_max_s. A request beyond it does not extrapolate: the grid is recomputed by pygfunction to cover the request (at least twice the previous horizon, keeping the node density per decade). For a 10×10 field this costs about 0.2 s. A simulation longer thant_max_stherefore gets the same values it would have got with a largert_max_s.Step mean.
step_mean()returns(1/dt) ∫_τ^{τ+dt} g(s) ds, integrated exactly for the piecewise-linearg. This is the response a time-stepping model needs when its stepnrepresents the interval[t_n, t_n + dt]and a load pulse starts att_i: the mean wall temperature over the step isT_s - Σ Δq_i · step_mean(t_n - t_i, dt). It includes the step’s own pulse (τ = 0) and gives the same interval means for anydtthat divides the load’s own resolution.Any bore field. The constructor builds an
N_1 × N_2rectangle.from_field()takes anyBoreField(arbitrary coordinates and per-borehole depths) and, with the'MIFT'boundary condition, aBoreNetwork(pipes, flow, series or parallel connections). Grid, first hour, horizon andstep_mean()behave the same way for every field. Such a g-function also returns the per-borehole split of the field load (borehole_load_shares()).- Parameters:
N_1 (
int)N_2 (
int)B (
float)H_b (
float)D_b (
float)r_b (
float)alpha_s (
float)k_s (
float)t_max_s (
float)dt_s (
float)boundary_condition (
str)num (
int)
- POINTS_PER_DECADE = 24.0¶
Minimum node density of the log-spaced grid [nodes per decade].
- __init__(N_1, N_2, B, H_b, D_b, r_b, alpha_s, k_s, t_max_s, dt_s, boundary_condition='UBWT', num=100)[source]¶
- Parameters:
N_1 (
int)N_2 (
int)B (
float)H_b (
float)D_b (
float)r_b (
float)alpha_s (
float)k_s (
float)t_max_s (
float)dt_s (
float)boundary_condition (
str)num (
int)
- classmethod from_field(field, alpha_s, k_s, t_max_s, *, boundary_condition='UBWT', network=None, dt_s=3600.0, num=100, method=None)[source]¶
g-function of an arbitrary bore field.
- Parameters:
field (
BoreField) – Borehole positions, depths, buried depths and radius.alpha_s (
float) – Ground thermal diffusivity [m²/s] and conductivity [W/(m·K)].k_s (
float) – Ground thermal diffusivity [m²/s] and conductivity [W/(m·K)].t_max_s (
float) – Expected simulation length [s] (grid to1.5 * t_max_s).boundary_condition (
str) –'MIFT'(mixed inlet fluid temperature, Cimmino 2015/2019) couples the boreholes through the fluid and needsnetwork; its g is the effective borehole wall temperature, defined byT_b* = (T_in + T_out)/2 + q'·R_fieldwithR_fieldthe network’s field resistance (q'field load per metre, extraction positive), so the host’sT_f = T_wall − q'·R_bholds withR_b = R_field.network (
BoreNetwork|None) – Pipes, total flow and connections; required for'MIFT'only. Itsk_smust equalk_s. The g-function is valid for that flow only.dt_s (
float)num (
int)method (
str|None) – pygfunction solver. Default'equivalent'(as the constructor),'similarities'when a MIFT network has series connections ('equivalent'does not support them).'equivalent'load shares are per cluster of similar boreholes (seeborehole_load_shares()).
- Return type:
Notes
The boreholes are handed to pygfunction sorted by (depth, buried depth, y, x). The g-function is a field mean, so the order is physically irrelevant, but pygfunction 2.3.1’s
'equivalent'solver assigns boreholes to clusters in the wrong order when boreholes of different depths are interleaved (depths 100/200/100/ 200/100 m on a line give a g 5 % off its'similarities'value); sorted input avoids it. A rectangle is already in this order.
Fraction of the field load carried by each borehole after a unit load step.
Returns an
(n_boreholes, n_times)array for timest[s] (field order); each column sums to 1. Solved by pygfunction together with the g-function (heat rate per segment, weighted by segment length) and interpolated linearly in time between grid nodes. Att = 0the share isH_i / ΣH(pygfunction’s linearisation of the first instants), and the line from there to the first node covers the first hour. With pygfunction’s'equivalent'solver (the default) boreholes in one cluster share its load per metre;'similarities'or'detailed'resolve every borehole. Available for g-functions built byfrom_field().- Return type:
ndarray
- tmhp.g_function.g_step_mean(g, tau, dt)[source]¶
Step-mean response
(1/dt) ∫_τ^{τ+dt} g(s) dsfor any g-function callable.Uses
GFunction.step_mean()(exact) when available; any other callableg(t)(a user or test g-function) is integrated with an 8-point Gauss–Legendre rule per step.A g-function rises from zero on the time scale
r_b²/α(tens of minutes) and likeln tafterwards, so one rule cannot resolve an interval that starts at or neart = 0and is much longer than that: for the first step of a line source it is 5e-4 off with daily steps and 1e-3 with monthly ones. An interval withτ < dt(the first step of a run, a run window of the current step) is therefore integrated on panels that narrow towards its start, 8 points each; against the closed-form step mean of a line source that is exact to 2e-9 for steps from a minute to a year. Intervals withτ >= dtuse the single rule.- Parameters:
dt (
float)
- tmhp.g_function.precompute_gfunction(N_1, N_2, B, H_b, D_b, r_b, alpha_s, k_s, t_max_s, dt_s, boundary_condition='UBWT')[source]¶
Precompute the g-function with pygfunction and return it as a callable.
Creates a rectangular borehole field and computes the g-function for log-spaced time steps up to
1.5 * t_max_s. Returns aGFunctionmapping time [s] to the g-function [mK/W]; a request past that horizon recomputes the grid instead of extrapolating (seeGFunction).The g-function is built from the finite line source (FLS) solution of Claesson and Javed (2011), extended to boreholes at different vertical positions by Cimmino and Bernier (2014). Because a borehole has finite length, the wall temperature is not uniform along its depth, so an axial boundary condition must be assumed:
'UHTR'(uniform heat transfer rate): every depth exchanges the same heat per unit length; the wall temperature then varies with depth and the g-function is its depth-average.'UBWT'(uniform borehole wall temperature): the wall is at a single temperature over the whole depth and the heat flux varies instead. This is Eskilson’s original definition and is the more realistic of the two for a circulated borehole.
- 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) – Expected simulation length [s]. The grid covers1.5 * t_max_s; longer requests trigger a recompute, never an extrapolation.dt_s (
float) – Construction timestep [s], kept on the result asdt_s. It does not shape the grid (first node always 3600 s) or any response: time-stepping hosts pass their run’s step toGFunction.step_mean().boundary_condition (
str) – Axial boundary condition along the borehole. Either'UBWT'(uniform borehole wall temperature) or'UHTR'(uniform heat transfer rate). Default is'UBWT'.
- Returns:
Callable mapping time [s] to g-function [mK/W], with
GFunction.step_mean()for time-stepping models.- Return type:
References
Claesson, J., & Javed, S. (2011). An analytical method to calculate borehole fluid temperatures for time scales from minutes to decades. ASHRAE Transactions, 117(2), 279-288.
Cimmino, M., & Bernier, M. (2014). A semi-analytical method to generate g-functions for geothermal bore fields. International Journal of Heat and Mass Transfer, 70, 641-650.
- tmhp.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.
Warning
Unused in tmhp and not verified against a reference MFLS solution (#96). Kept pending co-author confirmation.
Ref: Molina-Giraldo et al. (2011), “A moving finite line source model to simulate borehole heat exchangers with groundwater advection”
- tmhp.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.
Warning
Unused in tmhp and not verified against a reference MFLS solution (#96). Kept pending co-author confirmation.
- Parameters:
times (
ndarray) – Array of time values [s]boreholes (
list) – List of pygfunction Borehole objectsv_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:
ndarray
- tmhp.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.
Warning
Unused in tmhp and not verified against a reference MFLS solution (#96). Unlike
precompute_gfunction(), the returned interpolator extrapolates linearly in time past1.5 * t_max_s. Kept pending co-author confirmation.- 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
- tmhp.g_function.air_dynamic_viscosity(T_K)[source]¶
Calculate air dynamic viscosity using Sutherland’s formula.
- Parameters:
T_K (float) – 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
- tmhp.g_function.air_prandtl_number(T_K)[source]¶
Calculate air Prandtl number.
- Parameters:
T_K (float) – 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.
- tmhp.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
Ground coupling¶
Ground-coupling abstraction for borehole-heat-exchanger temporal superposition.
This module separates the ground thermal response (how the borehole-wall temperature responds to a history of ground loads) from the heat-pump cycle physics, so the response backend becomes swappable behind one small contract:
AggregateGFunctionCoupler(default) wraps a single field-average g-functiong(tau)[m·K/W] and superposes load pulses with its step-mean response (the same convention as the inline superposition ofGroundSourceHeatPumpandGroundSourceHeatPumpEmpirical).External packages (e.g.
geolink) can implement theGroundCouplerprotocol with a resolved multi-borehole network response — replacing the single lumped g-function with full borehole-to-borehole superposition — without this package depending on them (dependency inversion:tmhpdefines the abstraction it needs; the richer implementation lives elsewhere and is injected).
Contract¶
A coupler owns the ground-load pulse history. The host
(GroundSourceHeatPumpBoiler) calls
GroundCoupler.reset() once per simulation and
GroundCoupler.wall_temperature_rise() once per timestep with the current
per-length ground load q_unit [W/m]; the coupler returns the borehole-wall
temperature rise magnitude dT [K].
Time convention: step n stands for the interval [t_n, t_n + dt] and
the returned dT is the wall-temperature rise averaged over that
interval, including the response to the step’s own load q_unit. An
external backend should return the same quantity so that results do not
depend on which backend is injected.
Sign convention (matches the legacy GSHPB)¶
q_unit > 0 denotes heat extraction from the ground; the returned dT is
the positive magnitude such that the disturbed wall temperature is
T_wall = T_undisturbed - dT. (Note this is the opposite sign labelling from
geolink’s q' > 0 = injection convention; a geolink coupler maps the
sign at its boundary so the value returned here keeps the extraction-positive
meaning.)
Borehole heat capacity (fluid-referenced wall temperature)¶
The host turns the wall temperature into the mean fluid temperature with the
steady relation T_f = T_wall - q' R_b. A backend that models the heat
capacity of the borehole (DynamicGFunction)
therefore returns the fluid-referenced rise: the wall-temperature rise that
gives the dynamic fluid temperature through that unchanged relation. It
equals the physical wall rise once the borehole has settled (hours) and
differs from it just after a load change, when the fluid has not yet followed.
Such a backend reports the physical wall rise separately through the optional
borehole_wall_rise(n, time_arr) (physical_wall_rise()), and says so
with a true fluid_referenced attribute.
Runs that cover part of a step¶
The history holds one load per step. A host whose compressor runs for the
first part of a step records the step-average load, but the fluid while it
runs carries the running load. With a fluid-referenced response the host must
therefore ask for the response over the run itself, under the running load
(preview_wall_temperature_rise(..., window_s=...), see
run_window_preview()): the first-instant terms of the response then
cancel the host’s q' R_b for the same load. A backend that does not take
window_s is asked for the whole step with the step-average load, as
before.
- class tmhp.ground_coupling.GroundCoupler(*args, **kwargs)[source]¶
Bases:
ProtocolPluggable ground-response backend for BHE temporal superposition.
- reset(n_steps, time_arr)[source]¶
Initialise pulse-history state for a simulation of
n_stepssteps.A backend may also accept a keyword
dt_s(the run’s step length [s]);reset_ground_coupler()passes it when the signature allows, which is the only way to know the step length of a one-step run.- Parameters:
n_steps (
int) – Number of timesteps in the upcoming simulation.time_arr (
ndarray) – Absolute time of each step [s] (uniform grid). Backends that precompute a response matrix at fixed times use this.
- Return type:
None
- wall_temperature_rise(n, time_arr, q_unit)[source]¶
Borehole-wall temperature rise [K] at step
nfor loadq_unit.- Parameters:
n (
int) – Current step index (0-based).time_arr (
ndarray) – Absolute time of each step [s] (same array passed toreset()).q_unit (
float) – Per-length ground load at this step [W/m], extraction-positive.
- Return type:
float
- __init__(*args, **kwargs)¶
- class tmhp.ground_coupling.AggregateGFunctionCoupler(g_interp, pulse_tol=1e-06, dt_s=None)[source]¶
Bases:
objectSingle field-average g-function temporal superposition (default backend).
A pulse is recorded whenever the per-length load changes by more than
pulse_tol; the pulse train is convolved with the step-mean responseḡ(τ; dt) = (1/dt) ∫_τ^{τ+dt} g(g_step_mean()). The value returned for stepnis therefore the mean wall-temperature rise over the interval[t_n, t_n + dt], including the response to the step’s own load. (Before #96 G4 the pulse train was evaluated at the step start,g(t_n - t_i), so the current step’s pulse contributedg(0) ≈ 0and the wall was reported up to ~0.8 K too warm at 25 W/m with hourly steps.)On a uniform time grid the step-mean responses for every lag are computed once in
reset()and each step is a contiguous dot product; a different time array passed later falls back to direct evaluation with the same step length. A non-uniform grid is rejected atreset().Long runs. The dot product grows with the step index (a run of
Nsteps costsN²/2: about 7 s for 525 600 steps, half an hour for 5 256 000). FromFAST_MIN_STEPSsteps on (a year at ten-minute steps), the same pulse sum is accumulated ahead of time by an online FFT convolution (tmhp._online_convolution), at a cost per step that does not depend on the run length (about 1 s and 10 s for the two runs above). It is not a load-aggregation scheme: nothing is averaged or truncated, and the values differ from the dot product by round-off only (1e-11K over 250 000 steps). It applies while steps are recorded in increasing order on the grid given toreset(); any other use (a step recorded again, another time array) is answered by the dot product, with the same values.- Parameters:
g_interp (Callable[[np.ndarray], np.ndarray]) – Field-average g-function mapping lag time
tau[s] to the dimensional responseg[m·K/W]. AGFunctionis integrated exactly; any other callable by Gauss–Legendre quadrature.pulse_tol (
float) – Minimum load change [W/m] that registers a new pulse (default 1e-6).dt_s (
float|None) – Fixed step length [s] for every run. Normally omitted: the host passes the run’s own step length toreset()(dt_s=). The step length is never taken from how the g-function was built.
- FAST_MIN_STEPS: int = 50000¶
Run length [steps] from which the pulse history is accumulated ahead of time (see “Long runs”). Measured break-even of a whole run: about 50 000 steps with one call per step, below 10 000 when the host also previews candidates and reads the wall temperature every step.
- __init__(g_interp, pulse_tol=1e-06, dt_s=None)[source]¶
- Parameters:
pulse_tol (
float)dt_s (
float|None)
- reset(n_steps, time_arr, dt_s=None)[source]¶
Start a run of
n_stepssteps on the uniform gridtime_arr[s].The step length is, in order:
dt_sgiven here (the run’s own step), the constructordt_s, the spacing oftime_arr. A one-step grid without either raises; a grid whose spacing is not uniform or differs from the step length raises, since the step-mean response assumes every step lastsdt.- Parameters:
n_steps (
int)time_arr (
ndarray)dt_s (
float|None)
- Return type:
None
- property fluid_referenced: bool¶
Whether the returned rise is fluid-referenced (a g-function with borehole heat capacity).
See the module docstring. A host uses the run window of
preview_wall_temperature_rise()with such a response.
- preview_wall_temperature_rise(n, time_arr, q_unit, window_s=None)[source]¶
Evaluate an uncommitted candidate without modifying load history.
Optional extension for coupled flow control; the original GroundCoupler protocol remains unchanged for legacy external backends.
Without
window_sthis is the mean rise over the whole step withq_unitheld over it, the valuewall_temperature_rise()would return. Withwindow_sit is the mean over the firstwindow_sseconds of the step,[t_n, t_n + window_s], withq_unitheld over that window: the rise a compressor sees that runs for the first part of a step. Give the load while it runs, not the step average. The value is continuous in the window: it tends to the rise att_nunder the previous load as the window vanishes, and equals the whole-step value atwindow_s = dt. Nothing is recorded; the history keeps step-average loads.- Parameters:
n (
int)time_arr (
ndarray)q_unit (
float)window_s (
float|None)
- Return type:
float
- wall_temperature_rise(n, time_arr, q_unit)[source]¶
- Parameters:
n (
int)time_arr (
ndarray)q_unit (
float)
- Return type:
float
- borehole_wall_rise(n, time_arr)[source]¶
Physical borehole-wall temperature rise [K] at step
nfor the committed loads.Call it after
wall_temperature_rise()for the same step. For a plain g-function it is that method’s value. For a g-function with borehole heat capacity (one that haswall_step_mean) the value returned bywall_temperature_rise()is fluid-referenced (see the module docstring) and this is the wall itself.- Parameters:
n (
int)time_arr (
ndarray)
- Return type:
float
- tmhp.ground_coupling.run_window_preview(coupler)[source]¶
coupler’s run-window preview(n, time_arr, q_run, window_s) -> rise, orNone.A host that lets the compressor run for part of a step asks for the response over that part (
window_sofAggregateGFunctionCoupler.preview_wall_temperature_rise()) when the response is fluid-referenced: only then does it contain the first-instant terms that must act on the running load. A coupler qualifies when itsfluid_referencedattribute is true and itspreview_wall_temperature_riseacceptswindow_s. Every other coupler (a plain g-function, an external backend that does not know the argument) returnsNoneand is used with the step-average load, as before.- Parameters:
coupler (
Any)- Return type:
Callable[[int,ndarray,float,float],float] |None
- tmhp.ground_coupling.physical_wall_rise(coupler, n, time_arr, rise)[source]¶
Physical borehole-wall rise [K] of the step just committed.
riseis whatGroundCoupler.wall_temperature_rise()returned for it. That is the wall itself unless the coupler’s response is fluid-referenced and it reports the wall throughborehole_wall_rise.- Parameters:
coupler (
Any)n (
int)time_arr (
ndarray)rise (
float)
- Return type:
float
- tmhp.ground_coupling.reset_ground_coupler(coupler, n_steps, time_arr, dt_s)[source]¶
Reset
couplerfor a run, giving it the run’s step length when it accepts one.Hosts call this instead of
coupler.reset(n_steps, time_arr)so that the step-mean response always uses the step of the run being simulated, not the step the g-function was built for (#96 G4 follow-up). An external coupler whoseresettakes only(n_steps, time_arr)is called the old way.- Parameters:
coupler (
GroundCoupler)n_steps (
int)time_arr (
ndarray)dt_s (
float)
- Return type:
None
Fast temporal superposition for long runs¶
Exact fast temporal superposition, forced on for any run length.
AggregateGFunctionCoupler (the default ground
coupler) sums the load history with one dot product per step, whose cost
grows with the step index, and switches by itself to an online FFT
convolution for long runs (from
FAST_MIN_STEPS
steps on). Nothing has to be enabled for a long run to be fast.
The two give the same values (to round-off): the online convolution is not a
load-aggregation scheme, nothing is averaged or truncated. See
tmhp._online_convolution for the method.
This module keeps FastGFunctionCoupler, the same coupler with the
online convolution used from the first step whatever the run length. It is
useful for tests and for timing; a simulation does not need it.
- class tmhp.ground_superposition.FastGFunctionCoupler(g_interp, pulse_tol=1e-06, dt_s=None)[source]¶
Bases:
AggregateGFunctionCouplerAggregateGFunctionCouplerwith the online convolution at any run length.Same contract, parameters and values as the default coupler, which already does this for runs of
FAST_MIN_STEPSsteps or more. Below that length the dot product of the default coupler is faster.- Parameters:
pulse_tol (
float)dt_s (
float|None)
- FAST_MIN_STEPS: int = 0¶
Run length [steps] from which the pulse history is accumulated ahead of time (see “Long runs”). Measured break-even of a whole run: about 50 000 steps with one call per step, below 10 000 when the host also previews candidates and reads the wall temperature every step.
- tmhp.ground_superposition.enable_fast_superposition(model)[source]¶
Switch a ground-source model to
FastGFunctionCoupler, in place.Not needed for speed: the default coupler accelerates long runs by itself. Works on
GroundSourceHeatPumpBoilerand its solar variants; the g-function, pulse tolerance and fixed step of the model’s coupler are kept, so the results do not change. Functions that rebuild the model’s coupler afterwards (enable_borehole_dynamics(), attaching aFieldGroundResponse) put the default coupler back.- Returns:
The coupler now used by
model.- Return type:
- Parameters:
model (
Any)
History sum of a growing sequence against a fixed kernel, at a cost per step independent of its length.
Used by AggregateGFunctionCoupler for long
runs. For a sequence p that is appended to step by step and a kernel
k known in advance, OnlineHistory.history() returns
exactly (to round-off), without summing the whole history at every step.
After step t − 1 is known, the block of the last s entries, where
s is the largest power of two dividing t, is convolved with k
once and added to the next s steps. Every pair (entry, later step) is
covered by exactly one block (the one at the highest binary digit in which
the two indices differ), so H_n is complete once the entries before
n have been folded in, and no later block changes it. Blocks are
convolved with the FFT, which makes a run of N steps O(N log² N)
instead of N²/2. This is the standard online (relaxed) convolution of
computer algebra with one fixed operand.
A single step can take long when a large block is due (once, half-way
through the run, a block of N/2 entries); only the total matters for a
simulation.
- class tmhp._online_convolution.OnlineHistory(kernel)[source]¶
Σ_{i<n} p[i]·k[n-i]for a sequencepwhose entries beforenare final.- Parameters:
kernel (
ndarray) –k[0..N-1];k[0]multiplies a step’s own entry and is not used here.
- folded¶
Number of leading entries of the sequence already folded in.
Borehole resistance and pipe configurations¶
Borehole wall-to-fluid resistance; ground response lives in g_function.
- tmhp.borehole.PIPE_KINDS = ('single_u', 'double_u_parallel', 'double_u_series', 'coaxial')¶
Pipe configurations understood by
BoreholePipe.
- tmhp.borehole.COAXIAL_FLOW_DOWN = ('annulus', 'inner')¶
Which channel of a coaxial pipe carries the fluid down the borehole.
- class tmhp.borehole.BoreholePipe(kind='single_u', r_in=0.013, r_out=0.016, D_s=0.025, k_p=0.4, k_g=1.5, r_in_inner=None, r_out_inner=None, r_in_outer=None, r_out_outer=None, k_p_inner=None, flow_down='annulus', epsilon=1e-06, J=2)[source]¶
Bases:
objectPipe configuration inside one borehole: single/double U-tube or coaxial.
All lengths in metres, conductivities in W/(m·K). The defaults are those of
GroundSourceHeatPumpBoiler, soBoreholePipe()reproduces the resistance the boiler computes today.U-tubes (
"single_u","double_u_parallel","double_u_series"): every leg is a pipe of radiir_in/r_outwhose centre isD_sfrom the borehole axis. A single U-tube has its two legs at(-D_s, 0)and(D_s, 0). A double U-tube puts its four legs 90° apart on the same circle, each U-tube’s legs facing each other (pygfunction order: down legs(-D_s, 0),(0, -D_s); up legs(D_s, 0),(0, D_s)). In"double_u_parallel"each U-tube carries half the borehole flow; in"double_u_series"the fluid runs through one U-tube and then the other, so each leg carries the whole flow.Coaxial (
"coaxial"): an inner pipe(r_in_inner, r_out_inner)centred inside an outer pipe(r_in_outer, r_out_outer); the annulus between them is the second channel.flow_downsays which channel takes the fluid down ("annulus": down the annulus, up the inner pipe).k_pis the outer pipe’s conductivity andk_p_innerthe inner pipe’s (None: same ask_p). Build one withcoaxial().k_gis the grout conductivity,epsilonthe pipe roughness [m] andJthe multipole order (pygfunction default 2).- Parameters:
kind (
str)r_in (
float)r_out (
float)D_s (
float)k_p (
float)k_g (
float)r_in_inner (
float|None)r_out_inner (
float|None)r_in_outer (
float|None)r_out_outer (
float|None)k_p_inner (
float|None)flow_down (
str)epsilon (
float)J (
int)
- kind: str = 'single_u'¶
- r_in: float = 0.013¶
- r_out: float = 0.016¶
- D_s: float = 0.025¶
- k_p: float = 0.4¶
- k_g: float = 1.5¶
- r_in_inner: float | None = None¶
- r_out_inner: float | None = None¶
- r_in_outer: float | None = None¶
- r_out_outer: float | None = None¶
- k_p_inner: float | None = None¶
- flow_down: str = 'annulus'¶
- epsilon: float = 1e-06¶
- J: int = 2¶
- classmethod coaxial(r_in_inner=0.0221, r_out_inner=0.025, r_in_outer=0.0487, r_out_outer=0.055, k_p=0.4, k_g=1.5, *, k_p_inner=None, flow_down='annulus', epsilon=1e-06, J=2)[source]¶
Coaxial pipe; default radii are pygfunction’s coaxial example (outer pipe 110 mm OD).
- Parameters:
r_in_inner (
float)r_out_inner (
float)r_in_outer (
float)r_out_outer (
float)k_p (
float)k_g (
float)k_p_inner (
float|None)flow_down (
str)epsilon (
float)J (
int)
- Return type:
- property n_pipes: int¶
1 single U, 2 double U, 1 coaxial.
- Type:
Number of U-tubes (pygfunction
nPipes)
- property outer_radius: float¶
Distance from the borehole axis to the outermost pipe surface [m].
- positions()[source]¶
Pipe centre positions in pygfunction order (down legs first).
- Return type:
list[tuple[float,float]]
- check_fits(r_b)[source]¶
Raise
ValueErrorif the pipes do not fit inside a borehole of radiusr_b[m].- Parameters:
r_b (
float)- Return type:
None
- fluid_to_pipe_resistance(m_flow_borehole, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606)[source]¶
Fluid-to-outer-pipe-wall resistance
R_fp[m·K/W] of one pipe.U-tubes: convection inside one leg (Gnielinski, pygfunction) plus the pipe wall. In
"double_u_parallel"each leg carries half the borehole flow. Coaxial: convection on the annulus’s outer surface plus the outer pipe wall (the path from the annulus fluid to the grout).- Parameters:
m_flow_borehole (
float)rho_f (
float)mu_f (
float)cp_f (
float)k_f (
float)
- Return type:
float
- fluid_to_fluid_resistance(m_flow_borehole, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606)[source]¶
Coaxial only: inner-pipe fluid to annulus fluid resistance
R_ff[m·K/W].- Parameters:
m_flow_borehole (
float)rho_f (
float)mu_f (
float)cp_f (
float)k_f (
float)
- Return type:
float
- pygfunction_pipe(borehole, k_s, m_flow_borehole, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606)[source]¶
pygfunction pipe object for
borehole(apygfunction.boreholes.Borehole).- Parameters:
borehole (
Any)k_s (
float)m_flow_borehole (
float)rho_f (
float)mu_f (
float)cp_f (
float)k_f (
float)
- Return type:
Any
- local_resistance(*, r_b, k_s, m_flow_borehole, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606)[source]¶
Local (cross-section) borehole resistance
R_b[m·K/W], multipole method.- Parameters:
r_b (
float)k_s (
float)m_flow_borehole (
float)rho_f (
float)mu_f (
float)cp_f (
float)k_f (
float)
- Return type:
float
- effective_resistance(H, *, r_b, k_s, m_flow_borehole, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606)[source]¶
Effective borehole resistance
R_b*[m·K/W] for a uniform wall temperature.Defined by
Q/H = (T_b - (T_in + T_out)/2) / R_b*over a borehole of lengthH[m] (pygfunctioneffective_borehole_thermal_resistance); it includes the thermal short-circuit between down and up channels.- Parameters:
H (
float)r_b (
float)k_s (
float)m_flow_borehole (
float)rho_f (
float)mu_f (
float)cp_f (
float)k_f (
float)
- Return type:
float
- __init__(kind='single_u', r_in=0.013, r_out=0.016, D_s=0.025, k_p=0.4, k_g=1.5, r_in_inner=None, r_out_inner=None, r_in_outer=None, r_out_outer=None, k_p_inner=None, flow_down='annulus', epsilon=1e-06, J=2)¶
- Parameters:
kind (
str)r_in (
float)r_out (
float)D_s (
float)k_p (
float)k_g (
float)r_in_inner (
float|None)r_out_inner (
float|None)r_in_outer (
float|None)r_out_outer (
float|None)k_p_inner (
float|None)flow_down (
str)epsilon (
float)J (
int)
- tmhp.borehole.precompute_borehole_resistance(m_flow_rated, min_ratio, max_ratio, H, cp_f, boundary_condition='uniform_temperature', **geometry)[source]¶
Precompute Rb* [m K/W] on a mass-flow grid, including the rated point.
Uses the legacy local-resistance/axial model at initialization only. PCHIP interpolation preserves its shape; out-of-range flow is an input error, never silently extrapolated. The flow is per borehole, not field total.
- Parameters:
m_flow_rated (
float)min_ratio (
float)max_ratio (
float)H (
float)cp_f (
float)boundary_condition (
str)geometry (
float)
- Return type:
Callable[[float],float]
- tmhp.borehole.precompute_borehole_resistance_from_flow(m_flow_min, m_flow_max, H, cp_f, boundary_condition='uniform_temperature', *, anchor_flows=(), _sample_flows=None, **geometry)[source]¶
Interpolate Rb* using actual branch mass flow [kg/s], with no normalization.
Reference/setpoint anchors reproduce their physical resistance exactly; changing the upper limit does not redefine any reference operating point.
- Parameters:
m_flow_min (
float)m_flow_max (
float)H (
float)cp_f (
float)boundary_condition (
str)anchor_flows (
tuple[float,...])_sample_flows (
tuple[float,...] |None)geometry (
float)
- Return type:
Callable[[float],float]
- tmhp.borehole.calc_local_borehole_thermal_resistance(k_s, k_g, k_p, r_b, r_out, r_in, D_s, m_flow_pipe, rho_f, mu_f, cp_f, k_f)[source]¶
Calculate the local borehole thermal resistance and internal thermal resistance [mK/W] using pygfunction multipole method.
Assumes a Single U-tube configuration.
- 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) – Shank spacing (half distance between pipes) [m]m_flow_pipe (
float) – Mass flow rate per pipe [kg/s]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:
(R_b, R_a) R_b: Local borehole thermal resistance [mK/W]. R_a: Internal (pipe-to-pipe) thermal resistance [mK/W]: the temperature difference between the two legs per unit heat flow when one leg gives and the other takes the same heat per metre,
R_a = R_11 + R_22 - 2 R_12of the multipole resistance matrix (Hellström 1991). It is always positive. It is not the delta-circuit pipe-to-pipe branchR_12^Δ, which can be negative for pipes close to the borehole wall; for a symmetric U-tube the two are related by1/R_a = 1/R_12^Δ + 1/(4 R_b).- Return type:
tuple[float,float]
Notes
Before #96 G6 the second value was
R_12^Δread from pygfunction’s private_Rd.calc_effective_borehole_thermal_resistance()now takesR_ain both branches; pass it the pair returned here.
- tmhp.borehole.calc_effective_borehole_thermal_resistance(R_b, R_a, H, m_flow_pipe, cp_f, boundary_condition='uniform_temperature')[source]¶
Calculate the effective borehole thermal resistance [mK/W].
- Parameters:
R_b (
float) – Local borehole thermal resistance [mK/W]R_a (
float) – Internal (pipe-to-pipe) thermal resistance [mK/W], as returned bycalc_local_borehole_thermal_resistance()(must be positive).H (
float) – Borehole depth [m]m_flow_pipe (
float) – Mass flow rate per pipe [kg/s]; for a single U-tube, the borehole flow.cp_f (
float) – Fluid specific heat capacity [J/kgK]boundary_condition (
str) – Boundary condition for the calculation. Options: ‘uniform_temperature’ or ‘uniform_heat_flux’.
- Returns:
Effective borehole thermal resistance [mK/W].
- Return type:
float
Notes
With
η = H / (ṁ c_p √(R_b R_a))(Hellström 1991):uniform borehole-wall temperature:
R_b* = R_b η coth η(identical to pygfunction’sSingleUTube.effective_borehole_thermal_resistance);uniform heat flux:
R_b* = R_b + H² / (3 R_a (ṁ c_p)²) = R_b (1 + η²/3).
Since
η coth η = 1 + η²/3 - η⁴/45 + …, the uniform-heat-flux value is never below the uniform-temperature one; they agree to first order and separate at low flow (largeη).References
Hellström, G. (1991). Ground Heat Storage: Thermal Analyses of Duct Storage Systems (Ph.D. thesis). University of Lund, Sweden.
Lamarche, L., Kajl, S., & Beauchamp, B. (2010). A review of methods to evaluate borehole thermal resistances in geothermal heat-pump systems. Geothermics, 39(2), 187-200. DOI: 10.1016/j.geothermics.2010.03.003
Javed, S., & Spitler, J. D. (2016). Accuracy of borehole thermal resistance calculation methods for grouted single U-tube ground heat exchangers. Applied Energy, 182, 161-176. DOI: 10.1016/j.apenergy.2016.08.054
- tmhp.borehole.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 at pygfunction’s default order J=2 (for the default GSHPB geometry at 24 L/min and H_b = 200 m, R_b* is 5e-5 relative below its J=10 value: 0.164398 vs 0.164405 m·K/W); see Javed and Spitler (2016) for an accuracy benchmark of this method. 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 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
Hellström, G. (1991). Ground Heat Storage: Thermal Analyses of Duct Storage Systems (Ph.D. thesis). University of Lund, Sweden.
Claesson, J., & Hellström, G. (2011). Multipole method to calculate borehole thermal resistances in a borehole heat exchanger. HVAC&R Research, 17(6), 895-911. DOI: 10.1080/10789669.2011.609927
Javed, S., & Spitler, J. D. (2016). Accuracy of borehole thermal resistance calculation methods for grouted single U-tube ground heat exchangers. Applied Energy, 182, 161-176. DOI: 10.1016/j.apenergy.2016.08.054
Bore fields¶
See Ground response for usage and checks.
Bore-field layouts, pipe networks and the assembled field ground response.
BoreField describes where the boreholes are and how deep they go
(any coordinates, per-borehole depth). BoreNetwork adds the pipes,
the total flow and how the boreholes are connected (parallel headers or
series chains). FieldGroundResponse puts them together into what a
host model needs: the field g-function, the field resistance R_b for
T_f = T_wall − q'·R_b (q' = Q/ΣH), the flow in each borehole and the
split of the field load between boreholes.
All physics comes from pygfunction (Cimmino’s g-functions, multipole resistances, network fluid coupling); this module only arranges inputs and checks them.
- class tmhp.borefield.BoreField(x, y, H, D, r_b)[source]¶
Bases:
objectVertical boreholes at arbitrary positions with per-borehole depths.
x,yare the borehole head positions [m],Hthe active lengths [m],Dthe buried depths of the borehole tops [m],r_bthe common borehole radius [m]. Arrays are stored as read-only copies. Boreholes must not touch: every centre-to-centre distance exceeds2 r_b.- Parameters:
x (
ndarray)y (
ndarray)H (
ndarray)D (
ndarray)r_b (
float)
- x: ndarray¶
- y: ndarray¶
- H: ndarray¶
- D: ndarray¶
- r_b: float¶
- classmethod from_coordinates(xy, H, D=0.0, r_b=0.08)[source]¶
Boreholes at
xy(shape(n, 2), metres);H/Dscalar or per borehole.- Parameters:
xy (
Any)H (
Any)D (
Any)r_b (
float)
- Return type:
- classmethod rectangle(N_1, N_2, B, H, D=0.0, r_b=0.08)[source]¶
N_1 × N_2rectangle with spacingB[m], in pygfunction’s order (x fastest).- Parameters:
N_1 (
int)N_2 (
int)B (
float)H (
float)D (
float)r_b (
float)
- Return type:
- classmethod l_shape(N_1, N_2, B_1, B_2, H, D=0.0, r_b=0.08)[source]¶
L-shaped field (pygfunction
Borefield.L_shaped_field).- Parameters:
N_1 (
int)N_2 (
int)B_1 (
float)B_2 (
float)H (
float)D (
float)r_b (
float)
- Return type:
- classmethod u_shape(N_1, N_2, B_1, B_2, H, D=0.0, r_b=0.08)[source]¶
U-shaped field (pygfunction
Borefield.U_shaped_field).- Parameters:
N_1 (
int)N_2 (
int)B_1 (
float)B_2 (
float)H (
float)D (
float)r_b (
float)
- Return type:
- classmethod box(N_1, N_2, B_1, B_2, H, D=0.0, r_b=0.08)[source]¶
Box-shaped field: the rectangle’s perimeter (pygfunction
Borefield.box_shaped_field).- Parameters:
N_1 (
int)N_2 (
int)B_1 (
float)B_2 (
float)H (
float)D (
float)r_b (
float)
- Return type:
- classmethod circle(N, R, H, D=0.0, r_b=0.08)[source]¶
Nboreholes on a circle of radiusR[m] (pygfunctionBorefield.circle_field).- Parameters:
N (
int)R (
float)H (
float)D (
float)r_b (
float)
- Return type:
- property n_boreholes: int¶
- property total_length: float¶
the length the host’s linear load
q' = Q/ΣHrefers to.- Type:
ΣH [m]
- property mean_depth: float¶
ΣH / n [m].
- property uniform_depth: bool¶
True when every borehole has the same length and buried depth.
- boreholes()[source]¶
List of
pygfunction.boreholes.Boreholein this field’s order.- Return type:
list[Any]
- __init__(x, y, H, D, r_b)¶
- Parameters:
x (
ndarray)y (
ndarray)H (
ndarray)D (
ndarray)r_b (
float)
- class tmhp.borefield.BoreNetwork(pipe, k_s, m_flow_total, connectivity=None, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606)[source]¶
Bases:
objectPipes, total flow and connections of a bore field (pygfunction
Networkinputs).connectivityfollows pygfunction’sbore_connectivity: entryiis-1when boreholeiis fed from the supply header andjwhen it is fed by the outlet of boreholej(series).Noneconnects every borehole in parallel. Each circuit (a chain starting at the header) receivesm_flow_total / n_circuits— pygfunction’s equal split; the circuits are not hydraulically balanced by length. The same pipe configurationpipeis used in every borehole.- Parameters:
pipe (
BoreholePipe)k_s (
float)m_flow_total (
float)connectivity (
tuple[int,...] |None)rho_f (
float)mu_f (
float)cp_f (
float)k_f (
float)
- pipe: BoreholePipe¶
- k_s: float¶
- m_flow_total: float¶
- connectivity: tuple[int, ...] | None = None¶
- rho_f: float = 1000¶
- mu_f: float = 0.001¶
- cp_f: float = 4186¶
- k_f: float = 0.606¶
- borehole_flows(n)[source]¶
Mass flow through each borehole [kg/s] (the flow of its circuit).
- Parameters:
n (
int)- Return type:
ndarray
- to_pygfunction(field, order=None)[source]¶
pygfunction
Networkforfield, boreholes optionally reordered byorder.order[k]is the field index of the network’sk-th borehole; connections are renumbered accordingly.- Parameters:
field (
BoreField)order (
Sequence[int] |ndarray|None)
- Return type:
Any
- field_resistance(field)[source]¶
Field resistance
R_field[m·K/W] (pygfunctionnetwork_thermal_resistance).(T_in + T_out)/2 = T_b − q'·R_fieldfor a uniform wall temperatureT_band field load per metreq' = Q/ΣH(extraction positive). For identical parallel boreholes it equals one borehole’sR_b*at its share of the flow.- Parameters:
field (
BoreField)- Return type:
float
- __init__(pipe, k_s, m_flow_total, connectivity=None, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606)¶
- Parameters:
pipe (
BoreholePipe)k_s (
float)m_flow_total (
float)connectivity (
tuple[int,...] |None)rho_f (
float)mu_f (
float)cp_f (
float)k_f (
float)
- tmhp.borefield.FIELD_BOUNDARY_CONDITIONS = ('auto', 'UBWT', 'UHTR', 'MIFT')¶
Boundary conditions accepted by
FieldGroundResponse.
- class tmhp.borefield.FieldGroundResponse(field, pipe=None, *, k_s, alpha_s, m_flow_total, t_max_s, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606, connectivity=None, boundary_condition='auto', dt_s=3600.0, num=100, method=None)[source]¶
Bases:
objectGround response of a bore field, assembled for a host model.
- Parameters:
field (
BoreField)pipe (
BoreholePipe|None) – Pipe configuration, the same in every borehole.k_s (
float) – Ground conductivity [W/(m·K)] and diffusivity [m²/s].alpha_s (
float) – Ground conductivity [W/(m·K)] and diffusivity [m²/s].m_flow_total (
float) – Total circulating mass flow [kg/s]; the resistance and, for MIFT, the g-function are evaluated at this flow.t_max_s (
float) – Expected simulation length [s].rho_f (
float) – Fluid properties (default: water fromtmhp.constants).mu_f (
float) – Fluid properties (default: water fromtmhp.constants).cp_f (
float) – Fluid properties (default: water fromtmhp.constants).k_f (
float) – Fluid properties (default: water fromtmhp.constants).connectivity (
Sequence[int] |None) – pygfunctionbore_connectivity(−1 = from the header, j = downstream of borehole j). Default: all parallel.boundary_condition (
str) –'auto':'UBWT'when every borehole is in parallel and all have the same length and buried depth (identical to the rectangular constructor for a rectangle), otherwise'MIFT'.dt_s (
float)num (
int)method (
str|None) – pygfunction solver, passed toGFunction.from_field(). The default'equivalent'groups boreholes of similar steady temperature into clusters, so every member of a cluster gets the cluster’s load per metre inborehole_load_shares()(an irregular 12-borehole field: up to 0.01 off'similarities'in a share of about 0.08, g within 0.15 %). Pass'similarities'for per-borehole shares; it costs more for large fields.
- R_b¶
Field resistance [m·K/W] for
T_f = T_wall − q'·R_bwithq' = Q/ΣH. Always the network’s field resistance (uniform wall temperature over the field); for MIFT it is the one the g-function’s effective wall temperature is defined with.- Type:
float
- m_flow_boreholes¶
Mass flow in each borehole [kg/s].
- Type:
ndarray
- boundary_condition¶
The boundary condition used (
'auto'resolved).- Type:
str
- __init__(field, pipe=None, *, k_s, alpha_s, m_flow_total, t_max_s, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606, connectivity=None, boundary_condition='auto', dt_s=3600.0, num=100, method=None)[source]¶
- Parameters:
field (
BoreField)pipe (
BoreholePipe|None)k_s (
float)alpha_s (
float)m_flow_total (
float)t_max_s (
float)rho_f (
float)mu_f (
float)cp_f (
float)k_f (
float)connectivity (
Sequence[int] |None)boundary_condition (
str)dt_s (
float)num (
int)method (
str|None)
Per-borehole fraction of a unit field-load step, shape
(n, n_times); columns sum to 1.- Parameters:
times (
Any)- Return type:
ndarray
- dynamic_gfunction(*, rhoc_g=None, rhoc_p=None, transit=True)[source]¶
The field g-function with borehole heat capacity, short-time response and fluid transit.
See
tmhp.borehole_capacity. The section is built from this field’s pipe and resistance; the transit uses one circuit (its boreholes in series, its share of the flow). A coaxial pipe is mapped with the outer pipe as the equivalent cylinder.- Parameters:
rhoc_g (
float|None)rhoc_p (
float|None)transit (
bool)
- Return type:
Any
- model_kwargs(c_s=800.0)[source]¶
Constructor arguments that make a ground-source model describe this field.
For
GroundSourceHeatPumpBoilerandGroundSourceHeatPump: the borehole count, the mean depth (so thatN * H_bis the total length), the field resistance as a fixedR_b, the ground properties and the loop flow. The model’s own rectangular g-function is then replaced withattach():response = FieldGroundResponse(field, pipe, k_s=2.0, alpha_s=1.25e-6, m_flow_total=0.8, t_max_s=10 * 8760 * 3600) model = GroundSourceHeatPumpBoiler(**response.model_kwargs(), hp_capacity=12000.0) response.attach(model)
c_s[J/(kg K)] splits the ground heat capacityk_s / alpha_sinto thec_sandrho_sthe models take.- Parameters:
c_s (
float)- Return type:
dict[str,Any]
- attach(model, *, borehole_dynamics=None, rhoc_g=None, rhoc_p=None, transit=True)[source]¶
Make
modeluse this field’s ground response, in place.modelmust have been constructed withmodel_kwargs()(same borehole count, total length, resistance, ground properties and flow); a mismatch raises instead of mixing two fields. Returns the g-function now used by the model.borehole_dynamicschooses the borehole model, as the models’ own argument does:Trueisdynamic_gfunction()(heat capacity and fluid transit of this field’s pipes and circuits),Falsethe steady borehole (g). The defaultNonekeeps the model’s choice: dynamic unless the model was constructed withborehole_dynamics=False.model.borehole_dynamicssays which one is in use afterwards.The field resistance and a MIFT g-function hold for the flow given here, so the model must run that constant flow (no
variable_Rb, no variable ground flow).- Parameters:
model (
Any)borehole_dynamics (
bool|None)rhoc_g (
float|None)rhoc_p (
float|None)transit (
bool)
- Return type:
Any
Borehole heat capacity and short-time response¶
See Ground response for the model and its checks.
Borehole heat capacity and short-time ground response.
The steady borehole model used so far has two short-time defects that act in opposite directions:
the borehole-wall response is a line source evaluated at
r_b, valid only afterFo = alpha t / r_b^2of about 5 (several hours), and before one hourGFunctionis a straight line from the origin; andthe fluid-to-wall temperature difference
q' R_bappears instantly, whereas the fluid, pipe and grout store heat and the fluid temperature moves over one to three hours.
This module replaces both by one load-step response of the borehole cross section, the 1-D radial equivalent-cylinder model (ECM) of Xu and Spitler (2006):
fluid node (C_f) - R_in - node at r_eq (C_p)
- grout annulus r_eq..r_b (k_g,eq, rho c_g) - wall node (r_b, no capacity)
- ground r_b..r_far (k_s, rho c_s) - T = 0 at r_far
r_eq = sqrt(n) r_po keeps the grout cross-section (and so its heat
capacity) equal to the real one, R_in = R_fp / n is the fluid-to-pipe
resistance of the n pipes in parallel, and the equivalent grout
conductivity is chosen so that the steady resistance of the model is exactly
the target R_b (by default the multipole/Hellstrom value the host already
uses):
R_b = R_in + ln(r_b / r_eq) / (2 pi k_g,eq)
The model is discretised with log-spaced finite volumes (conductance between
cell centres 2 pi k / ln(r_{i+1}/r_i), exact for steady radial
conduction) and backward Euler in time; energy is conserved to round-off.
Splicing onto the long-time g-function¶
For a unit load step the ECM gives the mean-fluid response S_cap(t) and
the wall response W_cap(t) [m.K/W]. A g-function built from finite line
sources behaves at short times like an infinite line source evaluated at
r_b, which already fills the borehole with soil. The dynamic response is
therefore the Yavuzturk-Spitler splice
fluid: S_dyn(t) = g(t) - G_ILS(r_b, t) + S_cap(t) wall : W_dyn(t) = g(t) - G_ILS(r_b, t) + W_cap(t)
with G_ILS = E1(r_b^2 / (4 alpha t)) / (4 pi k_s). Both corrections vanish
at long times (S_cap -> R_b + G_ILS), so nothing changes after a few
days. DynamicGFunction tabulates
K_f(t) = S_dyn(t) - R_b (“fluid-referenced” kernel, K_f(0) = -R_b) K_w(t) = W_dyn(t) (physical wall kernel)
and is a drop-in replacement for the g-function: a host that computes
T_f = T_s - sum(dq * K_f) - q' R_b (the unchanged steady formula) obtains
the dynamic mean fluid temperature, exact for piecewise-constant loads.
Limits¶
One-dimensional cross-section (the pipe layout enters only through R_b):
against a 2-D finite-element reference the correction is, for most DN32
sections, within 5 % of R_b between 0.5 h and 2 h and about 2 % after 4 h
(geolink technical note, see below; that comparison mapped the section to the
local resistance, not to the effective R_b* used here). In the section
model the fluid is one node; its transit through the U-tube is added
separately (loop_outlet_response()) for one constant flow and a loop
that keeps circulating. The fluid outside the borehole is not modelled.
Provenance¶
Ported from geolink.borehole.equivalent_cylinder (bet-lab/geolink, MIT
License, Copyright (c) 2026 betlab), which documents the derivation and its
verification in docs/technote/borehole-capacity-equivalent-cylinder.tex.
The equivalent-radius mapping follows Xu and Spitler (2006) as implemented in
GHEDesigner (BSD-3-Clause); no GHEDesigner code is included.
References
Xu, X., & Spitler, J. D. (2006). Modeling of vertical ground loop heat exchangers with variable convective resistance and thermal mass of the fluid. Proc. Ecostock 2006.
Yavuzturk, C., & Spitler, J. D. (1999). A short time step response factor model for vertical ground loop heat exchangers. ASHRAE Transactions, 105(2), 475-485.
Carslaw, H. S., & Jaeger, J. C. (1959). Conduction of Heat in Solids (2nd ed.), section 13.5. Oxford University Press.
Albers, A., Huttenloch, P., Zorn, R., Steger, H., & Blum, P. (2024). Determination of thermal properties of grouting materials for borehole heat exchangers (BHE). Geothermal Energy, 12, 36 (grout heat capacity).
Javed, S. (2010). Design of ground source heat pump systems: Thermal modelling and evaluation of boreholes. Licentiate thesis, Chalmers University of Technology (grout heat capacity, Table 4.2).
- tmhp.borehole_capacity.BOREHOLE_DYNAMICS_MODES = ('transit', 'lumped', 'off')¶
fluid transit resolved, fluid as one node, steady borehole.
- Type:
model.borehole_dynamicsvalues
- tmhp.borehole_capacity.RHOC_GROUT_DEFAULT = 3400000.0¶
Volumetric heat capacity of a set, water-saturated grout [J/(m3 K)]. Measured cement-based and thermally enhanced grouts lie between 3.0e6 and 3.6e6 (Albers et al. 2024, seven commercial grouts); water-rich bentonite grout is higher (3.84e6, Javed 2010). A saturated grout is a mixture of water (4.18e6) and solids (about 2.0e6 to 2.3e6), so values much below 3.0e6 would need a water volume fraction under 40 %.
- tmhp.borehole_capacity.RHOC_PIPE_DEFAULT = 1800000.0¶
Volumetric heat capacity of a HDPE pipe wall [J/(m3 K)] (950 kg/m3 x 1900 J/(kg K)).
- class tmhp.borehole_capacity.CapacityStepResponse(times, fluid, wall, fluid_no_capacity, wall_no_capacity, ground_cylinder, ground_line, steady_resistance, stored_fluid, stored_borehole, stored_ground, far_outflow)[source]¶
Bases:
objectResponse of the borehole section to a unit load step [m.K/W = K per W/m].
- Parameters:
times (
ndarray) – Evaluation times [s], increasing.fluid (
ndarray) – Mean fluid temperature riseS_cap(t)with heat capacity.wall (
ndarray) – Borehole-wall temperature riseW_cap(t)with heat capacity.fluid_no_capacity (
ndarray) – The same model withC_f = C_p = rho c_g = 0on the same grid:fluid_no_capacity = R_b + wall_no_capacityexactly, andwall_no_capacityis the finite-volume cylindrical source.wall_no_capacity (
ndarray) – The same model withC_f = C_p = rho c_g = 0on the same grid:fluid_no_capacity = R_b + wall_no_capacityexactly, andwall_no_capacityis the finite-volume cylindrical source.ground_cylinder (
ndarray) – Analytical hollow-cylinder and infinite-line-source wall responses.ground_line (
ndarray) – Analytical hollow-cylinder and infinite-line-source wall responses.steady_resistance (
float) – Steady resistanceR_bof the model [m.K/W].stored_fluid (
ndarray) – Where the injected heat is at each time [J/m per W/m = s]: fluid, pipe + grout, ground, and lost throughr_far. Their sum istimesto round-off.stored_borehole (
ndarray) – Where the injected heat is at each time [J/m per W/m = s]: fluid, pipe + grout, ground, and lost throughr_far. Their sum istimesto round-off.stored_ground (
ndarray) – Where the injected heat is at each time [J/m per W/m = s]: fluid, pipe + grout, ground, and lost throughr_far. Their sum istimesto round-off.far_outflow (
ndarray) – Where the injected heat is at each time [J/m per W/m = s]: fluid, pipe + grout, ground, and lost throughr_far. Their sum istimesto round-off.
- times: ndarray¶
- fluid: ndarray¶
- wall: ndarray¶
- fluid_no_capacity: ndarray¶
- wall_no_capacity: ndarray¶
- ground_cylinder: ndarray¶
- ground_line: ndarray¶
- steady_resistance: float¶
- stored_fluid: ndarray¶
- stored_borehole: ndarray¶
- stored_ground: ndarray¶
- far_outflow: ndarray¶
- property fluid_deviation: ndarray¶
add to
g + R_bfor the dynamic fluid response.Computed as
(S_cap - S_nocap) + G_ICS - G_ILSso that the ground discretisation error cancels between the two finite-volume runs. Tends to zero at long times;-R_batt = 0.- Type:
S_cap - R_b - G_ILS
- property wall_deviation: ndarray¶
add to
gfor the dynamic wall response (same cancellation).- Type:
W_cap - G_ILS
- __init__(times, fluid, wall, fluid_no_capacity, wall_no_capacity, ground_cylinder, ground_line, steady_resistance, stored_fluid, stored_borehole, stored_ground, far_outflow)¶
- Parameters:
times (
ndarray)fluid (
ndarray)wall (
ndarray)fluid_no_capacity (
ndarray)wall_no_capacity (
ndarray)ground_cylinder (
ndarray)ground_line (
ndarray)steady_resistance (
float)stored_fluid (
ndarray)stored_borehole (
ndarray)stored_ground (
ndarray)far_outflow (
ndarray)
- class tmhp.borehole_capacity.DynamicGFunction(g_field, section, t_max_s=None, *, H=None, m_cp=None)[source]¶
Bases:
objectg-function with borehole heat capacity and short-time response.
Wraps a long-time field g-function
g(t)[m.K/W] and the capacity response of one borehole section. It is callable and hasstep_meanlikeGFunction, so it can replace it inAggregateGFunctionCouplerand in the inline superposition of the other ground-source models.Returned quantity.
g_dyn(t)is the fluid-referenced kernelK_f(t) = S_dyn(t) - R_b, whereS_dynis the mean-fluid temperature response to a unit load step. With it the host’s steady relationT_f = T_wall - q' R_bgives the dynamic fluid temperature, andT_wall = T_s - sum(dq * K_f)is the wall temperature the fluid would need in steady state. It starts atK_f(0) = -R_b(the fluid has not moved yet) and joins the long-time g-function within days. The physical wall temperature useswall()/wall_step_mean().In a field every borehole responds alone at these time scales, so the correction of one section is added to the field g-function; the load per metre is the field average.
- Parameters:
g_field (
Any) – Long-time g-functiong(t)[m.K/W]. AGFunctionis read on its own grid and its horizon is extended on demand; any other callable is sampled on a log grid up tot_max_s.section (
EquivalentCylinderBorehole) – Borehole section; itssteady_resistancemust be theR_bthe host subtracts.t_max_s (
float|None) – Horizon [s] for a plain callableg_field(ignored for aGFunction).H (
float|None)m_cp (
float|None)
- T_JOIN = 3600.0¶
below it the field response is the line source at
r_b.- Type:
Start of the long-time g-function
- __init__(g_field, section, t_max_s=None, *, H=None, m_cp=None)[source]¶
- Parameters:
g_field (
Any)section (
EquivalentCylinderBorehole)t_max_s (
float|None)H (
float|None)m_cp (
float|None)
- half_loop¶
Half the loop temperature difference per unit load,
H / (2 m_cp)[m.K/W] (0 without transit).
- transit_time: float | None¶
Fluid transit time through the U-tube [s];
Nonewhen the fluid is one lumped node.
- property n_builds: int¶
Number of times the underlying g-function grid was (re)computed.
- ensure_horizon(t)[source]¶
Extend the table to cover time
t[s] (recomputing the field g-function if needed).- Parameters:
t (
float)- Return type:
None
- __call__(t)[source]¶
Fluid-referenced kernel
K_f(t) = S_dyn(t) - R_b[m.K/W].- Parameters:
t (
Any)- Return type:
ndarray
- wall(t)[source]¶
Physical borehole-wall response
W_dyn(t)[m.K/W].- Parameters:
t (
Any)- Return type:
ndarray
- fluid(t)[source]¶
Mean-fluid response
S_dyn(t) = K_f(t) + R_b[m.K/W].- Parameters:
t (
Any)- Return type:
ndarray
- class tmhp.borehole_capacity.EquivalentCylinderBorehole(r_eq, r_b, k_g, k_s, rhoc_g, rhoc_s, R_in, C_f, C_p=0.0)[source]¶
Bases:
objectMapped equivalent-cylinder borehole section (see the module docstring).
Build it from a real section with
from_pipes().- Parameters:
r_eq (
float) – Equivalent pipe radius [m] (inner radius of the grout annulus).r_b (
float) – Borehole radius [m].k_g (
float) – Equivalent grout conductivity [W/(m K)].k_s (
float) – Ground conductivity [W/(m K)].rhoc_g (
float) – Volumetric heat capacity of the grout annulus and of the ground [J/(m3 K)].rhoc_s (
float) – Volumetric heat capacity of the grout annulus and of the ground [J/(m3 K)].R_in (
float) – Fluid node tor_eqresistance [m.K/W] (R_fp / n_pipes).C_f (
float) – Fluid heat capacity per metre of borehole [J/(m K)].C_p (
float) – Heat capacity lumped atr_eq(pipe walls) [J/(m K)].
- r_eq: float¶
- r_b: float¶
- k_g: float¶
- k_s: float¶
- rhoc_g: float¶
- rhoc_s: float¶
- R_in: float¶
- C_f: float¶
- C_p: float = 0.0¶
- classmethod from_pipes(*, n_pipes, r_out, r_in, r_b, R_b, R_fp, k_s, rhoc_s, rhoc_g=3400000.0, rhoc_f=4186000, rhoc_p=1800000.0)[source]¶
Map a U-tube section onto the cylinder so that its steady resistance is
R_b.- Parameters:
n_pipes (
int) – Number of pipes in the borehole (2 for a single U-tube, 4 for a double).r_out (
float) – Pipe outer and inner radius [m].r_in (
float) – Pipe outer and inner radius [m].r_b (
float) – Borehole radius [m].R_b (
float) – Steady borehole resistance to reproduce [m.K/W] (the value the host uses inT_f = T_wall - q' R_b).R_fp (
float) – Fluid-to-outer-pipe-wall resistance of one pipe [m.K/W] (fluid_to_pipe_resistance()).k_s (
float) – Ground conductivity [W/(m K)] and volumetric heat capacity [J/(m3 K)].rhoc_s (
float) – Ground conductivity [W/(m K)] and volumetric heat capacity [J/(m3 K)].rhoc_g (
float) – Volumetric heat capacity of grout, fluid and pipe wall [J/(m3 K)].rhoc_f (
float) – Volumetric heat capacity of grout, fluid and pipe wall [J/(m3 K)].rhoc_p (
float) – Volumetric heat capacity of grout, fluid and pipe wall [J/(m3 K)].
- Raises:
ValueError – If the pipes cannot fit in the borehole or
R_b <= R_fp / n_pipes(the grout would need a negative resistance).- Return type:
- property steady_resistance: float¶
R_b = R_in + ln(r_b / r_eq) / (2 pi k_g)[m.K/W].
- property borehole_heat_capacity: float¶
Fluid + pipe + grout heat capacity per metre [J/(m K)].
- property capacity_ratio: float¶
Borehole heat capacity over that of the soil it replaces,
pi r_b^2 rho c_s[-].
- property ground_diffusivity: float¶
alpha_s = k_s / (rho c_s)[m2/s].
- load_step_response(times, *, cells_per_decade=40, min_grout_cells=12, dt_min=1.0, step_fraction=0.01, far_field_factor=8.0)[source]¶
Response to a unit load per metre applied to the fluid from
t = 0.- Parameters:
times (
Any) – Evaluation times [s], positive and increasing; each is an exact step end (no interpolation in time).cells_per_decade (
int) – Radial cells per decade of radius (grout and ground).min_grout_cells (
int) – Minimum number of grout cells.dt_min (
float) – Time stepmax(dt_min, step_fraction * t)[s].step_fraction (
float) – Time stepmax(dt_min, step_fraction * t)[s].far_field_factor (
float) – Outer radiusr_b + factor * sqrt(alpha_s t_max); 8 makes the line-source temperature thereE1(16)(6e-9) of the wall scale.
- Return type:
- __init__(r_eq, r_b, k_g, k_s, rhoc_g, rhoc_s, R_in, C_f, C_p=0.0)¶
- Parameters:
r_eq (
float)r_b (
float)k_g (
float)k_s (
float)rhoc_g (
float)rhoc_s (
float)R_in (
float)C_f (
float)C_p (
float)
- tmhp.borehole_capacity.configure_borehole_dynamics(model, requested, *, injected_coupler=False)[source]¶
Constructor hook of the ground-source models for their
borehole_dynamicsargument.requested:None(default)The dynamic borehole response (heat capacity and fluid transit,
"transit") wherever the model can use it, the steady borehole ("off") where it cannot:a
ground_couplersupplied by the caller owns the response;variable_Rband variable ground flow: the response is built for one resistance and one loop flow;a flow so low that the loop cannot be calibrated to
R_b(the loop temperature difference alone exceeds it);a cross-section that cannot be mapped onto the equivalent cylinder (pipes that fill the borehole, a supplied
R_bbelow the fluid-to-pipe resistance).
Nothing is raised or warned; the outcome is
model.borehole_dynamicsand the reason, when it is"off",model.borehole_dynamics_note.TrueThe dynamic response, or
ValueErrorwith that reason.FalseThe steady borehole (resistance without heat capacity).
The lumped-fluid variant (
"lumped") is never chosen here. Without the transit the models’ loop temperature differenceQ / (2 m c_p)appears at once, so the fluid entering the heat pump starts above where it was when extraction begins: 2.2 K above the undisturbed ground in a run of the default boiler withground_flow_control="optimal_power"(the controller settles at half the reference flow). The steady borehole errs on the cold side instead.enable_borehole_dynamics(model, transit=False)remains for callers who want it.- Parameters:
model (
Any)requested (
bool|None)injected_coupler (
bool)
- Return type:
None
- tmhp.borehole_capacity.cylinder_source_wall(times, k_s, alpha_s, r_b)[source]¶
Hollow cylindrical source: wall temperature of
r > r_bfor a unit flux atr_b[m.K/W].Carslaw and Jaeger (1959), constant flux on the surface of a cylindrical cavity in an infinite medium, evaluated at the surface:
G = 2 / (pi^3 k) * int_0^inf (1 - exp(-Fo b^2)) / (b^3 (J1(b)^2 + Y1(b)^2)) db, Fo = alpha t / r_b^2
integrated in
u = ln bfor all times at once. AboveB = max(200, 12 / sqrt(Fo_min))the integrand is replaced by its closed-form tail(pi/2) (1/B - 1/(8 B^3)).- Parameters:
times (
Any)k_s (
float)alpha_s (
float)r_b (
float)
- Return type:
ndarray
- tmhp.borehole_capacity.enable_borehole_dynamics(model, *, rhoc_g=3400000.0, rhoc_p=1800000.0, n_pipes=2, transit=True)[source]¶
Switch a ground-source model to the dynamic borehole response, in place.
The models do this themselves at construction (their
borehole_dynamicsargument,configure_borehole_dynamics()); call this function to rebuild the response with other heat capacities, or to turn it on for a model constructed withborehole_dynamics=False:model = GroundSourceHeatPumpBoiler(H_b=150.0) enable_borehole_dynamics(model, rhoc_g=3.0e6) # a known grout
Works on
GroundSourceHeatPumpBoiler(and its solar variants) andGroundSourceHeatPump. Everything is derived from what the model already holds: borehole and pipe radii, pipe conductivity, ground properties, the borehole resistance it uses, the depth and the loop flow. Calling it again replaces the response instead of nesting it. For the steady borehole, construct the model withborehole_dynamics=False. A model given its ownground_coupleris left to that coupler and raises here.The response is built for one flow. The models subtract the steady
q' R_band addQ / (2 m c_p)at the flow of each step, and the kernel cancels exactly those two terms at the first instant. It therefore raises forvariable_Rband, with the transit resolved, for variable ground flow.transit=False(a lumped fluid) is accepted with variable flow, but thenQ / (2 m c_p)is not cancelled and the fluid entering the heat pump starts above where it was when extraction begins; the models never choose it by themselves. A model whose field was set up withtmhp.borefield.FieldGroundResponse.attach()must get its dynamics fromattach(..., borehole_dynamics=True), which knows the pipes and circuits; calling this function on it raises.- Parameters:
model (
Any) – A ground-source model built with the default g-function backend.rhoc_g (
float) – Volumetric heat capacity of grout and pipe wall [J/(m3 K)].rhoc_p (
float) – Volumetric heat capacity of grout and pipe wall [J/(m3 K)].n_pipes (
int) – Pipes per borehole (2 for the single U-tube the models assume).transit (
bool) – Resolve the fluid transit through the U-tube (default).
- Returns:
The response now used by
model.- Return type:
- tmhp.borehole_capacity.fluid_to_pipe_resistance(m_flow_pipe, r_in, r_out, k_p, rho_f=1000, mu_f=0.001, cp_f=4186, k_f=0.606)[source]¶
Fluid-to-outer-pipe-wall resistance of one pipe
R_fp[m.K/W].Convection inside the pipe (the correlation pygfunction uses for the borehole resistance) plus conduction through the pipe wall.
- Parameters:
m_flow_pipe (
float)r_in (
float)r_out (
float)k_p (
float)rho_f (
float)mu_f (
float)cp_f (
float)k_f (
float)
- Return type:
float
- tmhp.borehole_capacity.line_source_wall(times, k_s, alpha_s, r_b)[source]¶
Infinite line source at
r_b:E1(r_b^2 / (4 alpha t)) / (4 pi k_s)[m.K/W].- Parameters:
times (
Any)k_s (
float)alpha_s (
float)r_b (
float)
- Return type:
ndarray
- tmhp.borehole_capacity.loop_outlet_response(section, times, H, m_cp)[source]¶
Borehole outlet temperature rise for a unit load step, fluid in plug flow [m.K/W].
The fluid travels through the U-tube (borehole depth
H[m], heat capacity ratem_cp[W/K]) exchanging heat with the section at every depth; the loadq' His added between outlet and inlet. In the Laplace domain one pass multiplies the fluid temperature byE(s) = exp(-(s C_f + Y(s)) H / m_cp), so the outlet is(H / m_cp) / s * sum_{k>=1} E^k: nothing reaches the outlet before one transit timet_tr = C_f H / m_cp, and each later passkarrives atk t_tr. The legs do not exchange heat with each other here (that part of the steady resistance is restored by calibrating the section, seeDynamicGFunction).- Parameters:
section (
EquivalentCylinderBorehole)times (
Any)H (
float)m_cp (
float)
- Return type:
ndarray
- tmhp.borehole_capacity.section_admittance(section, s)[source]¶
Admittance
Y(s)[W/(m K)] the fluid sees in the Laplace domain.Heat flow from the fluid into the section per unit fluid temperature for the continuous equivalent cylinder (pipe node, grout annulus, infinite ground), the fluid’s own heat capacity excluded. The response of the lumped fluid node to a unit load step is
1 / (s (s C_f + Y(s))). Exponentially scaled Bessel functions keep it finite for large|s|.- Parameters:
section (
EquivalentCylinderBorehole)s (
Any)
- Return type:
ndarray
- tmhp.borehole_capacity.with_borehole_capacity(g_field, *, r_b, k_s, rhoc_s, R_b, r_out, r_in, n_pipes=2, R_fp=None, k_p=0.4, m_flow_borehole=None, rhoc_g=3400000.0, rhoc_f=4186000, rhoc_p=1800000.0, t_max_s=None, H=None, cp_f=4186, transit=True)[source]¶
Add borehole heat capacity and the short-time response to a g-function.
All inputs are ones the ground-source models already have; the heat capacities default to water, a set saturated grout and HDPE. When the borehole depth
Hand flowm_flow_boreholeare given the fluid transit through the U-tube is resolved as well (transit=Falsekeeps the fluid as one node).- Parameters:
g_field (
Any) – Long-time g-function (e.g. fromprecompute_gfunction()).r_b (
float) – Borehole radius [m].k_s (
float) – Ground conductivity [W/(m K)] and volumetric heat capacityrho_s c_s[J/(m3 K)].rhoc_s (
float) – Ground conductivity [W/(m K)] and volumetric heat capacityrho_s c_s[J/(m3 K)].R_b (
float) – Borehole resistance the host uses [m.K/W] (effectiveR_b*).r_out (
float) – Pipe outer and inner radius [m].r_in (
float) – Pipe outer and inner radius [m].n_pipes (
int) – Pipes per borehole: 2 (single U-tube, default) or 4 (double U-tube).R_fp (
float|None) – Fluid-to-outer-pipe-wall resistance of one pipe [m.K/W]. If omitted it is computed fromm_flow_boreholeandk_pfor water (single U-tube: each pipe carries the borehole flow; double U-tube in parallel: half of it).k_p (
float) – Pipe conductivity [W/(m K)], used whenR_fpis omitted.m_flow_borehole (
float|None) – Mass flow through one borehole [kg/s], used whenR_fpis omitted.rhoc_g (
float) – Volumetric heat capacity of grout, fluid and pipe wall [J/(m3 K)].rhoc_f (
float) – Volumetric heat capacity of grout, fluid and pipe wall [J/(m3 K)].rhoc_p (
float) – Volumetric heat capacity of grout, fluid and pipe wall [J/(m3 K)].t_max_s (
float|None) – Horizon [s]; required only wheng_fieldis a plain callable.H (
float|None) – Borehole depth [m] (the mean depth of a field); withm_flow_boreholeit enables the transit-resolved response.cp_f (
float) – Fluid specific heat [J/(kg K)] for the heat capacity ratem c_p.transit (
bool) – Resolve the fluid transit whenHandm_flow_boreholeare known (default).Falsetreats the fluid as one node.
- Return type:
Source-loop fluid and freezing limit¶
See Ground-loop liquid and its freezing limit for the rule and its basis.
Source-loop fluid of the liquid-source models: water or an antifreeze mixture.
The ground- and water-source models (GSHP, GSHPB, WSHPB) circulate a liquid between the source (a borefield, a coil lying in surface water) and the heat pump’s source-side heat exchanger. This module says what that liquid is, where it freezes and how cold it may run:
SourceFluid– freezing point, operating lower limit and the properties the source-side balances use;resolve_source_fluid()– the constructor argumentsource_fluid("water","MEG-25%","MPG-30%","ethanol-20%", … or aSourceFluid; left out: 25 % ethylene glycol for the ground-source models,GROUND_LOOP_FLUID_DEFAULT, and water for the water-source boiler);limit_duty_to_source_freeze()andsource_freeze_limited()– the rule applied to every solved point.
Why a limit¶
Water freezes at 0 °C. Without the limit a model fed with a cold source returned a running cycle whose loop “water” left the evaporator at -3 °C or -12 °C. A real water loop does not do that: ice forms on the evaporator plates, which are colder than the liquid, the flow stops and the plate heat exchanger bursts. Loops that run near or below 0 °C are filled with an antifreeze mixture (propylene or ethylene glycol, ethanol), and the heat pump’s controller stops the compressor before the mixture can freeze.
Operating lower limit¶
T_min = T_freeze + 3 K (FREEZE_MARGIN_K), applied to the coldest
liquid in the loop: in heating the liquid leaving the heat pump
(T_bhe_f_in [°C]). Two things set the margin.
The evaporator surface is colder than the liquid leaving it. The default source heat exchanger holds the leaving-end approach real brine-to-refrigerant evaporators print (3.5 K at their duty,
tmhp.default_inputs.estimate_hx_UA()); with the default flow (3 K loop temperature difference at the rated source heat) the refrigerant evaporates 3.4 K below the leaving liquid at the rated duty (effectiveness 0.47:3 K / 0.47 - 3 K). A 3 K margin therefore keeps the refrigerant within about 0.4 K of the freezing point at that duty (the earlierUA = 0.18 * hp_capacityevaporated 2.9 K below the leaving liquid, inside the margin).Manufacturers of water-to-water and water-to-air units ask for antifreeze whenever the loop may enter the unit below 40-45 °F (4.4-7.2 °C), and for a freezing point 10-15 °F (5.6-8.3 K) below the lowest entering temperature (ClimateMaster and Carrier installation manuals: 15 °F; Enertech technical bulletin TB19.001: 10-15 °F; Trane GETB/WPHF: antifreeze below 45 °F). With the 3 K loop difference the leaving liquid is 3 K colder than the entering one, so those rules put the freezing point 2.6-5.3 K below the leaving liquid. 3 K is inside that range; for water it means: full duty down to about 6 °C entering, none below 3 °C.
A SourceFluid built by the caller can carry any other limit.
What happens at the limit¶
A variable-speed unit does not trip the moment the limit is reached: its
controller lowers the compressor speed, the evaporator takes less heat from
the liquid and the liquid leaves warmer. The models do the same
(limit_duty_to_source_freeze()): the result is the largest duty whose
loop liquid stays at or above T_min, with capacity_clamped == "max"
and capacity_binding == "source_fluid_freezing". When no duty helps –
the liquid already reaches the heat pump below the limit, or it leaves below
the limit even at the compressor’s lowest speed – the compressor does not
run: the off state with failure_reason == "source_fluid_freezing".
At the lowest speed the running machine cannot take less heat, but a unit
that switches on and off can run for less of the time. That warms the liquid
only where the source answers the mean load: a borehole wall in a dynamic
step of the ground-source heat pump, which is warmer under shorter runs. The
duty is then lowered further, into the cycling range, to the largest mean
duty whose running liquid stays on the limit; the row is an on/off mean with
capacity_clamped == "max". Against a prescribed source or wall
temperature, and in a model that does not cycle, a smaller duty leaves the
running liquid as cold as before (one trial shows it) and the unit is off.
Properties¶
Water keeps the constants of tmhp.constants (1000 kg/m³, 4186 J/(kg K),
1.0 mPa s, 0.606 W/(m K)), so every result with the default fluid is unchanged
by the property path. Mixtures are read from CoolProp’s incompressible
mixtures (INCOMP::MPG[0.25] and the like; concentrations by mass) at
PROPERTY_REFERENCE_C = 0 °C, the liquid inlet temperature of the
ISO 13256-1 ground-loop and EN 14511 brine rating points and the cold end an
antifreeze loop is designed for. They are constants in a run, like water’s.
Viscosity of the source-side Reynolds number¶
The viscosity changes far more with temperature than the other properties:
water has 1.79 mPa s at 0 °C, 1.31 at 10 °C and 1.00 at 20 °C (the constant
mu_w), 25 % ethylene glycol 3.70 mPa s at 0 °C and 1.90 at 20 °C.
SourceFluid.viscosity() gives it at a temperature (water:
tmhp.constants.water_viscosity(); mixtures: the same CoolProp mixture),
and the source-side Reynolds number of the heat pump hosts – the laminar-flow
warning and the pipe convection inside the borehole or coil resistance
R_b – takes it at the loop’s design liquid temperature: the source
inlet temperature of the family’s heating rating point,
GROUND_LOOP_DESIGN_INLET_C (0 °C, EN 14511 B0 and ISO 13256-1 ground
loop) for GSHP and GSHPB and WATER_LOOP_DESIGN_INLET_C (10 °C,
EN 14511 W10 and ISO 13256-1 ground water) for WSHPB. Those quantities are
evaluated once, at the reference flow, like R_b itself; the default glycol
is therefore evaluated at the temperature its properties are read at (0 °C,
unchanged), and water no longer at 20 °C (in a ground loop 1.79 mPa s at
0 °C, the coldest it is liquid; in the water-source boiler 1.31 mPa s). The ground-loop helpers that run during a step (hydraulic pump loss,
flow-dependent R_b) keep the properties of water, see
warn_if_loop_modelled_as_water().
- tmhp.source_fluid.FREEZE_MARGIN_K = 3.0¶
Operating lower limit above the freezing point [K]; see the module docstring.
- tmhp.source_fluid.GROUND_LOOP_DESIGN_INLET_C = 0.0¶
the source inlet of the heating rating points (EN 14511 B0, ISO 13256-1 ground loop 0 °C). The source-side Reynolds number of GSHP and GSHPB takes the viscosity there.
- Type:
Design liquid temperature of a ground loop [°C]
- tmhp.source_fluid.GROUND_LOOP_FLUID_DEFAULT = 'MEG-25%'¶
25 % ethylene glycol by mass, freezing at -11.0 °C. Ground loops are rated and run with brine (EN 14511 B0, ISO 13256-1 liquid entering at 0 °C), and of the common fills this one stays turbulent in the default U-tube at the default flow (3.7 mPa s at 0 °C against 5.5 for propylene glycol of the same strength).
- Type:
Default loop liquid of the ground-source models (GSHP, GSHPB)
- tmhp.source_fluid.PROPERTY_REFERENCE_C = 0.0¶
Temperature at which the properties of an antifreeze mixture are read [°C].
- tmhp.source_fluid.SOURCE_FLUID_FREEZING = 'source_fluid_freezing'¶
failure_reasonof a point whose loop liquid would run below its operating limit, andcapacity_bindingof a duty reduced to stay on it.
- tmhp.source_fluid.SOURCE_FLUID_PRESETS: tuple[str, ...] = ('water', 'MEG-20%', 'MEG-25%', 'MEG-30%', 'MPG-20%', 'MPG-25%', 'MPG-30%', 'ethanol-20%', 'ethanol-25%')¶
The fluids listed in the documentation (any concentration in
_MIXTURE_RANGE_PCTis accepted, these are the common fills).
- tmhp.source_fluid.WATER_LOOP_FLUID_DEFAULT = 'water'¶
plain water.
- Type:
Default loop liquid of the water-source boiler (WSHPB)
- tmhp.source_fluid.WATER_LOOP_DESIGN_INLET_C = 10.0¶
the source inlet of the heating rating points (EN 14511 W10, ISO 13256-1 ground water 10 °C), for the source-side Reynolds number of WSHPB.
- Type:
Design liquid temperature of a water-source loop [°C]
- class tmhp.source_fluid.SourceFluid(name, T_freeze_C, rho, cp, mu, k, T_min_C=None, coolprop=None)[source]¶
Bases:
objectLiquid of the source loop: freezing point, operating limit and properties.
- Parameters:
name (
str) – Label used in messages and results.T_freeze_C (
float) – Freezing point [°C].rho (
float) – Density [kg/m³], specific heat [J/(kg K)], dynamic viscosity [Pa s] and thermal conductivity [W/(m K)], constant during a run.cp (
float) – Density [kg/m³], specific heat [J/(kg K)], dynamic viscosity [Pa s] and thermal conductivity [W/(m K)], constant during a run.mu (
float) – Density [kg/m³], specific heat [J/(kg K)], dynamic viscosity [Pa s] and thermal conductivity [W/(m K)], constant during a run.k (
float) – Density [kg/m³], specific heat [J/(kg K)], dynamic viscosity [Pa s] and thermal conductivity [W/(m K)], constant during a run.T_min_C (
float|None) – Coldest the liquid may run [°C].None(default):T_freeze_C + FREEZE_MARGIN_K. It may not lie below the freezing point.coolprop (
str|None) – Whereviscosity()reads the viscosity at another temperature:"Water"(tmhp.constants.water_viscosity()) or a CoolProp incompressible fluid ("INCOMP::MEG[0.25]").None(default, a fluid built by the caller):muat every temperature – water built this way keeps the 20 °C viscosity everywhere, as before.
- name: str¶
- T_freeze_C: float¶
- rho: float¶
- cp: float¶
- mu: float¶
- k: float¶
- T_min_C: float | None = None¶
- coolprop: str | None = None¶
- property limit_C: float¶
The operating lower limit [°C] as a float (
T_min_Cafter defaulting).
- viscosity(T_C)[source]¶
Dynamic viscosity [Pa s] at
T_C[°C].Read from
coolpropatT_Cheld between the freezing point and the upper end of the CoolProp mixture’s range;muwhen the fluid names no source (coolprop=None).- Parameters:
T_C (
float)- Return type:
float
- property is_water: bool¶
True for the default fluid, whose properties the ground-loop helpers assume.
- __init__(name, T_freeze_C, rho, cp, mu, k, T_min_C=None, coolprop=None)¶
- Parameters:
name (
str)T_freeze_C (
float)rho (
float)cp (
float)mu (
float)k (
float)T_min_C (
float|None)coolprop (
str|None)
- tmhp.source_fluid.freeze_violation(result, fluid)[source]¶
failure_detailwhen a running result’s loop liquid is below the limit, elseNone.DETAIL_INLETwhen the liquid already reaches the heat pump belowfluid.T_min_C,DETAIL_OUTLETwhen only the liquid leaving it is. A result that is not a running point is never a violation.- Parameters:
result (
Mapping[str,Any])fluid (
SourceFluid)
- Return type:
str|None
- tmhp.source_fluid.limit_duty_to_source_freeze(model, result, solve, request, off, *, delivered_key='Q_ref_tank [W]', once=False, what='analyze_steady')[source]¶
Keep a solved point’s loop liquid at or above the fluid’s operating limit.
resultis the solve at the dutyrequest(signed as the model takes it);solve(q)solves the same point at a duty of magnitudeq;off(detail)is the model’s off-state row for a point that does not run (failure_reason = "source_fluid_freezing").A running
resultwhose coldest liquid is at or abovemodel.source_fluid.T_min_Cis returned as it is, and so is a result that does not run. Otherwise the duty is lowered until the liquid stays on the limit: the coldest liquid falls almost linearly with the duty, so a false-position search between the refused duty and zero closes in two or three solves (where the liquid arrives below the limit and a smaller duty warms it, the first two refused duties are extrapolated; a duty another limit refuses bounds the search from below). The largest duty found is returned withcapacity_clamped = "max",capacity_binding = "source_fluid_freezing",Q_max [W]andQ_request [W]. On the compressor’s speed floor (capacity_clamped == "min") the search goes on only while a smaller duty leaves the liquid warmer – a unit that cycles against a source answering the mean load; two duties on the floor with the same liquid temperature end it. When no duty runs – the liquid enters below the limit while it gives heat up (DETAIL_INLET), it leaves below the limit at the compressor’s lowest speed, or another limit refuses every smaller duty –off(detail)is returned.Nothing warns here. The liquid temperature that was refused is left for the call that owns the result (
tmhp.operating_limits.note_refusal()):analyze_steadyreports a point that does not run, or runs reduced, in oneOperatingLimitWarning, and a dynamic run counts such steps in its end-of-run summary.onceandwhatare accepted for callers written against the earlier per-call warning and have no effect.- Parameters:
model (
Any)result (
dict)solve (
Callable[[float],Any])request (
float)off (
Callable[[str],dict])delivered_key (
str)once (
bool)what (
str)
- Return type:
dict
- tmhp.source_fluid.resolve_source_fluid(source_fluid, default='water')[source]¶
The
SourceFluida constructor’ssource_fluidargument names.Noneis the family’sdefault(GROUND_LOOP_FLUID_DEFAULTfor GSHP and GSHPB, water for WSHPB)."water"is plain water."<base>-<percent>%"is an antifreeze mixture by mass withbaseone ofMPG(propylene glycol),MEG(ethylene glycol) orethanol, 5-60 %: its freezing point and properties come from CoolProp (INCOMP::MPG,MEG,MEA) at 0 °C. ASourceFluidis returned as given. Anything else raisesValueError.- Parameters:
source_fluid (
str|SourceFluid|None)default (
str)
- Return type:
- tmhp.source_fluid.source_fluid_table(names=('water', 'MEG-20%', 'MEG-25%', 'MEG-30%', 'MPG-20%', 'MPG-25%', 'MPG-30%', 'ethanol-20%', 'ethanol-25%'))[source]¶
Freezing point, operating limit and properties of the listed fluids (for documentation).
- Parameters:
names (
tuple[str,...])- Return type:
list[dict[str,Any]]
- tmhp.source_fluid.source_freeze_limited(duty_arg, off, delivered_key='Q_ref_tank [W]')[source]¶
Decorate a single-duty solver method with the source-fluid freezing limit.
duty_argnames the method’s duty parameter (signed as the model takes it);offnames the model methodoff(arguments, detail) -> dictthat builds the off-state row from the call’s bound arguments. The decorated method returnslimit_duty_to_source_freeze()of its result. Put it outside a compressor-envelope decorator, so the duties it tries are themselves inside the envelope. Areturn_dict=Falsecall gets its one-row DataFrame back. The limit is reported by the call that owns the result (tmhp.operating_limits), never here.- Parameters:
duty_arg (
str)off (
str)delivered_key (
str)
- Return type:
Callable[[TypeVar(_F, bound=Callable[...,Any])],TypeVar(_F, bound=Callable[...,Any])]
- tmhp.source_fluid.warn_if_loop_modelled_as_water(fluid, settings, what, *, chosen=True)[source]¶
UserWarningfor the ground-loop options that still evaluate the loop as water.Only for a fluid the caller
chosen: a model left on its default liquid does not warn about it (the limitation is documented instead).The pipe pressure loss of the hydraulic pump model, the flow-dependent borehole resistance and the fluid-temperature closure of the coupled ground-flow solver live in
tmhp.ground_loopandtmhp.ground_flow_control, which use the properties of water. With an antifreeze mixture the freezing limit and the heat pump’s own source-side balance use the mixture; those three do not.- Parameters:
fluid (
SourceFluid)settings (
Mapping[str,Any])what (
str)chosen (
bool)
- Return type:
None
Ground-side defaults¶
Capacity-proportional ground-side defaults and sizing checks (#96).
A model that is given only its capacity sizes the ground side from the heat the ground loop carries at the rating point. The rules here are shared by the ground- and water-source families; a value the user supplies always replaces the default it would have produced.
default_ground_flow_lpm()– loop flow from the rated source-side heatdefault_borefield_layout()– borehole count from the specific loadwarn_if_laminar_ground_flow(),warn_if_borefield_undersized()– sizing slips reported instead of being solved silentlythe default pump power is
tmhp.pump.default_ground_pump_power()
- tmhp.ground_defaults.RATED_SOURCE_HEAT_FRACTION = 0.75¶
a heating machine at COP 4 takes 0.75 of its capacity from the ground.
- Type:
Source-side heat at the rating point as a share of the rated capacity
- tmhp.ground_defaults.GROUND_LOOP_DESIGN_DT_K = 3.0¶
Ground-loop temperature change [K] at that heat, which fixes the default flow (about 3.6 L/min per kW of capacity for water).
- tmhp.ground_defaults.BOREHOLE_DESIGN_LINEAR_LOAD = 50.0¶
Specific borehole load [W/m] at the rated source-side heat that the default borefield stays below, and the load above which a user-given field is reported as undersized (VDI 4640-2 specific extraction rates span about 20-80 W/m between dry sediment and water-bearing rock).
- tmhp.ground_defaults.BOREHOLE_DEFAULT_DEPTH = 100.0¶
Default active depth of one borehole [m].
- tmhp.ground_defaults.LAMINAR_REYNOLDS_LIMIT = 2300.0¶
Pipe Reynolds number below which the U-tube flow is laminar.
- tmhp.ground_defaults.calc_rated_source_heat(hp_capacity, source_heat_fraction=0.75)[source]¶
Source-side heat [W] at the rating point,
source_heat_fraction * hp_capacity.- Parameters:
hp_capacity (
float)source_heat_fraction (
float)
- Return type:
float
- tmhp.ground_defaults.default_ground_flow_lpm(hp_capacity, *, source_heat_fraction=0.75, delta_T_K=3.0, rho=1000.0, cp=4186.0)[source]¶
Default field-total source-side flow [L/min] for a rated capacity [W].
0.75 * hp_capacity / (rho * cp * 3 K): the flow at which the rated source-side heat changes the loop temperature by 3 K (14.3 L/min of water for 4 kW, 3.58 L/min per kW). In cooling, where the loop carries about 1.2 times the capacity, the same flow gives about 4.8 K. Parallel boreholes share this flow equally.- Parameters:
hp_capacity (
float)source_heat_fraction (
float)delta_T_K (
float)rho (
float)cp (
float)
- Return type:
float
- tmhp.ground_defaults.calc_rated_linear_load(hp_capacity, n_boreholes, H_b, *, source_heat_fraction=0.75)[source]¶
Specific borehole load [W/m] at the rated source-side heat.
- Parameters:
hp_capacity (
float)n_boreholes (
int)H_b (
float)source_heat_fraction (
float)
- Return type:
float
- tmhp.ground_defaults.default_borefield_layout(hp_capacity, H_b=100.0, *, max_linear_load=50.0, source_heat_fraction=0.75)[source]¶
Smallest near-square
(N_1, N_2)field that keeps the rated load withinmax_linear_load.The number of boreholes of depth
H_bis the smallest that carries the rated source-side heat at no more thanmax_linear_load[W/m]; it is then rounded up to a rectangle withN_1 = ceil(sqrt(n))columns. One 100 m borehole serves up to 6.67 kW of capacity; 8 kW gets 2 x 1, 14 kW 2 x 2, 30 kW 3 x 2 and 100 kW 4 x 4.- Parameters:
hp_capacity (
float)H_b (
float)max_linear_load (
float)source_heat_fraction (
float)
- Return type:
tuple[int,int]
- tmhp.ground_defaults.calc_borehole_reynolds(volume_flow_total, n_boreholes, pipe_inner_diameter, rho=1000.0, mu=0.001)[source]¶
Pipe Reynolds number in one U-tube leg for a field-total flow [m³/s].
- Parameters:
volume_flow_total (
float)n_boreholes (
int)pipe_inner_diameter (
float)rho (
float)mu (
float)
- Return type:
float
- tmhp.ground_defaults.warn_if_laminar_ground_flow(volume_flow_total, n_boreholes, pipe_inner_diameter, *, rho=1000.0, mu=0.001, label='reference', stacklevel=2)[source]¶
Return the U-tube Reynolds number; warn (
UserWarning) when it is laminar.A laminar U-tube is not an error: the borehole resistance and the pipe loss are evaluated for it. It is reported because the fluid film then dominates the borehole resistance (R_b* roughly doubles) and such a loop is normally a sizing slip – a flow that was not scaled with the number of parallel boreholes.
- Parameters:
volume_flow_total (
float)n_boreholes (
int)pipe_inner_diameter (
float)rho (
float)mu (
float)label (
str)stacklevel (
int)
- Return type:
float
- tmhp.ground_defaults.warn_if_borefield_undersized(hp_capacity, n_boreholes, H_b, *, max_linear_load=80.0, source_heat_fraction=0.75, stacklevel=2)[source]¶
Return the rated specific borehole load [W/m]; warn when it exceeds
max_linear_load.- Parameters:
hp_capacity (
float)n_boreholes (
int)H_b (
float)max_linear_load (
float)source_heat_fraction (
float)stacklevel (
int)
- Return type:
float