The Darcy-Weisbach equation is the universal and most theoretically rigorous formula for calculating friction head loss in pipe flow. Unlike empirical formulas like Hazen-Williams, Darcy-Weisbach applies to any fluid and any flow regime (laminar, transitional, or turbulent).
In the hf package, the equation is expressed using the
volumetric flow rate (\(Q\)) for
consistency:
\[h_f = f \frac{8 L Q^2}{\pi^2 g D^5}\]
Where:
The friction factor depends on the Reynolds number and the relative
roughness of the pipe. The hf package provides two distinct
functions to calculate it:
calc_friction_cw(): Uses the implicit
Colebrook-White equation (default). It finds the exact
root iteratively.calc_friction_sj(): Uses the explicit
Swamee-Jain equation, a highly accurate approximation
that runs faster on massive datasets.The calc_head_loss_darcy function calculates the head
loss, but you can inject the friction function you want to use
via the friction_fun argument.
# 1. Default approach (Uses Colebrook-White automatically)
calc_head_loss_darcy(
length = 100, flow = 0.02, diameter = 0.1, roughness = 0.00026
)
#> [1] 8.513127
# 2. Functional Injection (Using Swamee-Jain)
calc_head_loss_darcy(
length = 100, flow = 0.02, diameter = 0.1, roughness = 0.00026,
friction_fun = calc_friction_sj
)
#> [1] 8.55815
# 3. Direct Value (If you already know the friction factor)
calc_head_loss_darcy(
length = 100, flow = 0.02, diameter = 0.1, friction_factor = 0.025
)
#> [1] 8.262686Because the friction factor creates a circular dependency for
diameter and flow rate, the hf package uses internal
numerical solvers (uniroot) to find the exact values.
Functional injection works here as well.
# Calculate the required diameter for a target head loss of 8.56m
calc_diameter_darcy(
loss = 8.56, length = 100, flow = 0.02, roughness = 0.00026
)
#> [1] 0.09989527
# Calculate the maximum flow rate for the same head loss
calc_flow_darcy(
loss = 8.56, length = 100, diameter = 0.1, roughness = 0.00026
)
#> [1] 0.02005564