The hf package provides simple, efficient, and mathematically rigorous functions to calculate friction head loss, flow rate, and required pipe diameters using standard hydraulic equations.
It fully supports the universal Darcy-Weisbach equation (with Colebrook-White, Swamee-Jain, and other friction factors) and empirical equations (such as Hazen-Williams and Flamant), making it an ideal tool for agronomic and engineering hydraulic designs.
You can try the package directly in your browser without installing R!
The hf package includes a serverless Shiny application powered by
WebAssembly (shinylive), allowing you to perform complex hydraulic
calculations on the fly.
With the interactive app, you can:
👉 Try the hf Hydraulic Calculator
You can install the development version of hf from
GitHub with:
# install.packages("devtools")
devtools::install_github("joaobtj/hf")
Alternatively, you can install it via R-Universe:
install.packages("hf", repos = c("https://joaobtj.r-universe.dev", "https://cloud.r-project.org"))
The universal Darcy-Weisbach method allows for the calculation of head loss using different friction factor functions. By default, it uses the implicit Colebrook-White equation.
library(hf)
# Calculate head loss (m) for a 100m pipe, 0.02 m³/s flow, 0.1m diameter
calc_head_loss_darcy(
length = 100,
flow = 0.02,
diameter = 0.1,
roughness = 0.00026
)
#> [1] 8.513127
# Use functional injection to apply the Swamee-Jain approximation
calc_head_loss_darcy(
length = 100,
flow = 0.02,
diameter = 0.1,
roughness = 0.00026,
friction_fun = calc_friction_sj
)
#> [1] 8.55815
For full documentation and bilingual tutorials (English and Portuguese), visit the package website: joaobtj.github.io/hf
Author: Joao Batista Tolentino Jr. (UFSC - Campus Curitibanos)
Contact: joao.tolentino@ufsc.br | ORCID:
0000-0003-1303-4202