Skip to content

Commit

Permalink
improve handling of mdot=0, use correct hofer_numba
Browse files Browse the repository at this point in the history
  • Loading branch information
jkisse committed Jan 7, 2025
1 parent 0ce86f8 commit c83b746
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/pandapipes/pf/derivative_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def calc_lambda_transition_area(lambda_laminar, lambda_turb, re, begin_transitio
def calc_lambda(m, eta, d, k, gas_mode, friction_model, lengths, options, area):
"""
Function calculates the friction factor of a pipe. Turbulence is calculated based on
Nikuradse. If v equals 0, a value of 0.001 is used in order to avoid division by zero.
Nikuradse. If m equals 0, a value of 0.001 is used in order to avoid division by zero.
This should not be a problem as the pressure loss term will equal zero (lambda * u^2).
:param m:
Expand All @@ -184,9 +184,8 @@ def calc_lambda(m, eta, d, k, gas_mode, friction_model, lengths, options, area):
if options["use_numba"]:
from pandapipes.pf.derivative_toolbox_numba import calc_lambda_nikuradse_incomp_numba as \
calc_lambda_nikuradse_incomp, colebrook_numba as colebrook, \
calc_lambda_nikuradse_comp_numba as calc_lambda_nikuradse_comp
from pandapipes.pf.derivative_toolbox import calc_lambda_hofer_comp_np as calc_lambda_hofer_comp # numba version
# not yet implemented
calc_lambda_nikuradse_comp_numba as calc_lambda_nikuradse_comp, \
calc_lambda_hofer_comp_numba as calc_lambda_hofer_comp
else:
from pandapipes.pf.derivative_toolbox import calc_lambda_nikuradse_incomp_np as \
calc_lambda_nikuradse_incomp, colebrook_np as colebrook, \
Expand All @@ -213,7 +212,7 @@ def calc_lambda(m, eta, d, k, gas_mode, friction_model, lengths, options, area):
lambda_swamee_jain = 0.25 / ((np.log10(k / (3.7 * d) + 5.74 / (re ** 0.9))) ** 2)
return lambda_swamee_jain, re
elif friction_model.lower() == "hofer":
re, lambda_hofer = calc_lambda_hofer_comp(m, d, k, eta, area)
re, lambda_laminar, lambda_hofer = calc_lambda_hofer_comp(m, d, k, eta, area)
lambda_tot = calc_lambda_transition_area(lambda_laminar, lambda_hofer, re,
begin_transition_re=2000, end_transition_re=4000)
return lambda_tot, re
Expand Down Expand Up @@ -251,7 +250,7 @@ def calc_der_lambda(m, eta, d, k, friction_model, lambda_pipe, area):
df_dm = np.zeros_like(m)
df_dlambda = np.zeros_like(m)
lambda_der = np.zeros_like(m)
pos = m != 0
pos = ~np.isclose(abs(m), 0)

if friction_model.lower() in ["colebrook", "hofer"]: # hofer is explicit approximation of
# colebrook
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/pf/derivative_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def calc_lambda_hofer_comp_np(m, d, k, eta, area, hofer_re_threshold=2000):
lambda_hofer = \
np.divide(1, (-2 * np.log10((4.518/re_lower_lim) * np.log10(re_lower_lim/7) + (k / (3.71 * d)))) ** 2)
lambda_hofer[re < hofer_re_threshold] = 0
return re, lambda_hofer
return re, lambda_laminar, lambda_hofer


def calc_medium_pressure_with_derivative_np(p_init_i_abs, p_init_i1_abs):
Expand Down
5 changes: 3 additions & 2 deletions src/pandapipes/pf/derivative_toolbox_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def calc_lambda_nikuradse_comp_numba(m, d, k, eta, area):
return re, lambda_laminar, lambda_nikuradse


@jit((float64[:], float64[:], float64[:], float64[:], float64[:], int64), nopython=True)
def calc_lambda_hofer_comp_numba(m, d, k, eta, area, hofer_re_threshold=2000):
@jit((float64[:], float64[:], float64[:], float64[:], float64[:]), nopython=True)
def calc_lambda_hofer_comp_numba(m, d, k, eta, area):
"""Calculate Lambda acc. to Hofer-Equation (explicit version of Colebrook) [1].
Due to nested log10 operations, small Reynolds numbers must be avoided.
It is justified because the laminar Lambda (instead of Hofer) will be applied for small
Expand All @@ -130,6 +130,7 @@ def calc_lambda_hofer_comp_numba(m, d, k, eta, area, hofer_re_threshold=2000):
[1]: P. Hofer. Beurteilung von Fehlern in Rohrnetzberechnungen (Error evaluation in calculation
of pipelines). GWF–Gas/Erdgas, 114(3):113–119, 1973
"""
hofer_re_threshold = 2000
lambda_hofer = np.zeros_like(m)
lambda_laminar = np.zeros_like(m)
re = np.empty_like(m)
Expand Down

0 comments on commit c83b746

Please sign in to comment.