# Pipestra Flow 1.0.0-beta - formulas, methods, verification Pipestra Flow calculates the **steady-state flow distribution and pressure drop in pipe networks** with branches and loops. It is Pipestra's own implementation of public textbook methods. All calculations run locally in the browser (plain JavaScript); nothing is uploaded. > Beta software and an engineering aid only. Loss coefficients are generic textbook values and fluid properties are > correlations. All inputs and results must be checked by a qualified engineer. No liability. Units: lengths m (diameters mm), pressure bar(g) input, internal SI (Pa, kg/s), temperatures °C. ## 1. Network model * **Nodes**: junction, fixed pressure (tank, supply, compressor; gauge pressure given), or flow node (demand > 0 leaves the network, supply < 0 enters). Every node has an elevation z. * **Pipes**: from/to node, inner diameter (EN 10220 OD and wall, ASME B36.10M/B36.19M schedule, or a custom ID), length (3D distance from the drawing or entered), absolute roughness ε, fittings (n × K), optional fixed λ, optional pump. * Every connected part of the network needs at least one fixed-pressure node. * One fluid, one temperature (isothermal network). ## 2. Pipe law p_from − p_to = Δp_friction + Δp_fittings + ρ·g·(z_to − z_from) − Δp_pump Δp_friction = λ · L/D · ρ·v·|v|/2 (Darcy-Weisbach) Δp_fittings = ΣK · ρ·v·|v|/2 (K referred to the velocity in this pipe) Δp_pump = ρ·g·H(Q), H(Q) = H0 − (H0 − Hd)·(Q/Qd)·|Q/Qd| g = 9.80665 m/s². The pump acts in the from → to direction; reverse flow and operation beyond the zero-head point are flagged. ## 3. Friction factor | Range | Formula | |---|---| | Re ≤ 2300 | λ = 64/Re (Hagen-Poiseuille) | | Re ≥ 4000 | Colebrook-White: 1/√λ = −2·log10( (ε/D)/3.7 + 2.51/(Re·√λ) ), solved by Newton iteration on 1/√λ to 1e-13 | | 2300 < Re < 4000 | linear blend in Re between λ(2300) laminar and λ(4000) Colebrook; flagged as transitional | | check | Swamee-Jain (1976): λ = 0.25 / [log10( (ε/D)/3.7 + 5.74/Re^0.9 )]², reported next to Colebrook; a note is shown if they differ by > 3 % inside its validity range (5000 ≤ Re ≤ 1e8, 1e-6 ≤ ε/D ≤ 1e-2) | A fixed λ can be entered per pipe instead (used for textbook comparisons). ## 4. Fittings (minor losses) Default K values are typical textbook orders of magnitude (see e.g. Idelchik, *Handbook of Hydraulic Resistance*; White, *Fluid Mechanics*; Çengel & Cimbala, *Fluid Mechanics*). They are editable and should be replaced by manufacturer data where known. | Component | default K | |---|---| | Bend 90° R = 1.5 D / short elbow / 45° / mitre 90° / return 180° | 0.30 / 0.75 / 0.20 / 1.10 / 0.40 | | Tee run / tee branch | 0.40 / 1.20 | | Gate / ball / butterfly / globe valve (open), swing check, Y-strainer | 0.20 / 0.05 / 0.60 / 6.0 / 2.0 / 2.0 | | Entry sharp / rounded / projecting, exit | 0.50 / 0.05 / 0.80 / 1.00 | | Expansion (Borda-Carnot), β = d/D | K = (1 − β²)² | | Contraction (sudden, approximate), β = d/D | K = 0.5·(1 − β²) | Reducers are assigned to the **smaller** pipe (K referred to its velocity). ## 5. Fluids | Fluid | Density | Viscosity | |---|---|---| | Water 0…150 °C | Kell (1975) polynomial | Vogel: μ = 2.414e-5 · 10^(247.8/(T − 140)) Pa·s, T in K | | Air, nitrogen | ideal gas p = ρ·R·T | Sutherland's law | | Other ideal gas | ideal gas with molar mass M | entered | | Steam (basic) | Peng-Robinson cubic EOS, vapour root (Tc = 647.096 K, pc = 22.064 MPa, ω = 0.3443) | μ ≈ (0.407·t + 80.4)·1e-7 Pa·s (low-pressure fit) | | Custom liquid | entered ρ | entered μ | Water: vapour pressure from the Wagner-Pruss equation (IAPWS 1992) → cavitation note if p_abs < p_sat. Steam: condensation note if p_abs > p_sat(T) at a node. ## 6. Compressible flow (gas, steam) Isothermal. In each pipe the density is evaluated at the mean absolute pressure and an acceleration term K_acc = 2·ln(p_up/p_down) is added. Together this is exactly the isothermal pipe-flow equation p1² − p2² = (ṁ/A)² · Z·R·T · [ λ·L/D + ΣK + 2·ln(p1/p2) ] (Re is constant along an isothermal pipe, so λ is constant.) Mach number Ma = v / √(κ·p/ρ) is reported; Ma > 0.5 is flagged (the isothermal limiting Mach number is 1/√κ). Flow units for gases: kg/h or Nm³/h (0 °C, 1.01325 bar). ## 7. Network solver Newton-Raphson on all pipe (energy) and node (continuity) equations at once, reduced to the nodal system of the **global gradient algorithm** (Todini & Pilati, 1988): (Aᵀ G⁻¹ A) Δp = F2 + Aᵀ G⁻¹ F1, Δṁ = G⁻¹ (A Δp − F1) A = incidence matrix (free nodes), G = diag(∂h/∂ṁ) (central differences), F1 = energy residual per pipe, F2 = continuity residual per node. A backtracking line search on the residual norm keeps the iteration stable (and absolute pressures positive for gases). Convergence: max |Δṁ|/max |ṁ| < 1e-7 and scaled residual norm < 1e-9. The convergence report lists every iteration, the step length and the final energy (Pa) and continuity (kg/s) residuals. Branched and looped networks are handled the same way; no loop definition is needed. ## 8. Verification (tests/engine.test.mjs, run `node --test tests/*.test.mjs`) | # | Test | Reference | Tolerance | |---|---|---|---| | 1 | Water ρ, μ at 20 / 80 °C | steam-table values (998.21, 971.8 kg/m³; 1.0016, 0.354 mPa·s) | 0.05–0.2 kg/m³, 0.5–2 % | | 2 | p_sat(100 °C), p_sat(180 °C); steam ρ (10 bar 200 °C, 40 bar 300 °C); air ρ | steam tables (101.418 kPa, 1.0028 MPa, v = 0.2060 / 0.05884 m³/kg) | 0.1–2 % | | 3 | Colebrook (35 Re/ε/D points) | equation residual < 1e-10, independent bisection solution 1e-9, Moody chart (0.0180 smooth Re 1e5; 0.0134 Re 1e6 ε/D 1e-4), Swamee-Jain within 3 % | as stated | | 4 | Laminar pipe | Hagen-Poiseuille Δp = 128 μ L Q / (π D⁴) | 1e-6 | | 5 | Turbulent pipe with fittings and 10 m rise | hand calculation (worked example below) | 1e-7 | | 6 | Two-loop network, λ = 0.02 | Al-Mustansiriyah University, lecture "Analysis of Looped Networks", Example 1 (Hardy Cross): K values 6528.5418 / 49576.114 reproduced; flows vs. an independent Hardy Cross implementation (1e-7 m³/s) and vs. the lecture's last printed iteration (± 0.006 m³/s, the lecture stops before full convergence) | as stated | | 7 | Two-loop network, λ = 0.02 (Hardy Cross 1936 style) | engineeringkit documentation gallery, "Hardy Cross's method for pipe networks (1936)": flows 57.74 / 18.74 / 42.26 / 11.26 / 9.00 l/s, head losses 0.68 / 0.73 / 1.21 / 0.20 / 0.53 m | 0.02 l/s, 0.006 m | | 8 | Looped ring sample (Colebrook, fittings, elevations) | independent Hardy Cross loop-correction solution; loop Δp sums = 0; static head = ρ g Δz | 1e-8 m³/s | | 9 | Pump between two tanks | analytical intersection of pump and system curve (bisection) | 1e-7 | | 10 | Isothermal air pipe | closed-form p1² − p2² equation (bisection) | 1e-7 | | 11 | Steam line | convergence, condensation flag below saturation | - | | 12 | All samples | convergence, energy residual < 0.01 Pa, continuity < 1e-9 kg/s, supply = demand | as stated | | 13 | Input validation | missing fixed-pressure node, zero diameter | - | | 14 | 8 × 8 grid (112 pipes, 49 loops, 2 supplies) | converges in ≤ 30 iterations | - | | 15 | Reducer K | Borda-Carnot / contraction formulas | 1e-12 | Sources: Al-Mustansiriyah University (Baghdad), lecture notes "Pipe Network Analysis - Analysis of Looped Networks", uomustansiriyah.edu.iq (PDF, 2024); engineeringkit documentation, gallery example "Hardy Cross's method for pipe networks (1936)", cpoli.github.io/engineeringkit; Todini, E. & Pilati, S. (1988) "A gradient algorithm for the analysis of pipe networks"; Colebrook, C. F. (1939); Swamee, P. K. & Jain, A. K. (1976); Kell, G. S. (1975); Wagner, W. & Pruss, A. (1993, IAPWS); Peng, D.-Y. & Robinson, D. B. (1976). ### Worked hand calculation (test 5) Water 20 °C: ρ = 998.20 kg/m³, μ = 1.0017 mPa·s. DN100 EN 10220: 114.3 × 3.6 → D = 107.1 mm, A = 0.0090088 m². Q = 50 m³/h → v = 0.013889 / 0.0090088 = **1.5417 m/s**. Re = ρ v D / μ = **164 530**. ε/D = 0.045/107.1 = 4.20e-4. Colebrook → **λ = 0.018785** (Swamee-Jain 0.018877, +0.5 %). Dynamic pressure ρv²/2 = 1186.3 Pa. Friction: 0.018785 · 120/0.1071 · 1186.3 = 24 968 Pa. Fittings: ΣK = 3·0.3 + 0.2 = 1.1 → 1 305 Pa. Static: 998.20 · 9.80665 · 10 = 97 890 Pa. **Δp = 124 164 Pa = 1.2416 bar** → p_end = 6.0 − 1.2416 = 4.7584 bar g. ## 9. Limitations (v1) * Steady state only (no water hammer / transients), single fluid, isothermal (no heat loss, no temperature change). * Two-phase flow, condensation and flashing are not modelled (only flagged). * Steam density uses a cubic equation of state (about 1–2 % from steam tables in the tested range), not IAPWS-IF97. * Fitting K values are generic and independent of Re and size; tee losses do not depend on the flow split. * Pumps: one quadratic curve per pump, no speed control, no efficiency/power; no control valves or pressure regulators. * Dense linear solver: intended for networks up to a few hundred nodes.