Skip to contents

Introduction

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 (QQ) for consistency:

hf=f8LQ2π2gD5h_f = f \frac{8 L Q^2}{\pi^2 g D^5}

Where:

  • hfh_f: Friction head loss (m)
  • ff: Darcy friction factor (dimensionless)
  • LL: Pipe length (m)
  • QQ: Volumetric flow rate (m3/sm^3/s)
  • DD: Internal diameter (m)
  • gg: Acceleration due to gravity (m/s2m/s^2)

1. The Friction Factor (ff)

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.
# Flow parameters
Re <- 100000        # Reynolds number
e <- 0.00026        # Absolute roughness (m)
D <- 0.1            # Diameter (m)

# Compare both methods
calc_friction_cw(reynolds = Re, roughness = e, diameter = D)
#> [1] 0.02657412
calc_friction_sj(reynolds = Re, roughness = e, diameter = D)
#> [1] 0.02681396

2. Calculating Head Loss with Functional Injection

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.262686

3. Calculating Diameter and Flow Rate

Because 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