Skip to main content

Python Android Termux Calculator for Piping Size, Flow & Velocity

Steps required #

graph TD; A[πŸ“± Get Android] --> B[πŸ“¦ Install Termux] B --> C[🐍 Install Python] C --> D[βš™οΈ Install Python's Library] D --> E[πŸƒβ€β™‚οΈ Run Script]

Script Features #

This python calculator offers x3 calculation methods which are mostly used for initial piping estimations.

  1. Velocity from Pipe internal diameter & Volumetric flow
  2. Pipe internal diameter from Velocity & Volumetric flow
  3. Volumetric flow from Pipe internal diameter & Velocity

In this script I used x2 python libraries

  1. Pint (universal unit converter)
  2. Scipy (optmisation function)

Script application #

In petrochemical industry while designing piping vendor generally provide standards that needs to be followed. In chlor-alkali industry for instance following velocities are observed for various fluids:

ServiceMaterial of ConstructionSuperficial Design Velocity (ft/s)
Brine, gravity flowMild steel, rubber lined or FRP1.8-2.0
Brine, forced flowMild steel, rubber lined or FRP4.5-5.0
Lime solution (25 g/l concentration), forced flowPVC/FRP1.5-1.8
Soda ash solution (20 g/l concentration), forced flowPVC/FRP1.5-1.8
Hydrogen gasMild steel, seamless22.0-25.0
Chlorine gasMild steel, rubber lined15.0-20.0
Hβ‚‚SOβ‚„, forced flowSteel5.0-7.0
HCl (33%), gravity flowMild steel, rubber lined or PVC/FRP1.0-1.2
HCl (33%), forced flowMild steel, rubber lined or PVC/FRP3.0-5.0
Caustic lye (50% concentration), forced flowMild steel pipe1.0-1.2
Water-forced flowMild steel/PVC/FRP5.0-7.0

UHDENORA one the primary EPC & design company have mentioned following additional guidelines

ServiceRecommended Velocity in m/s
Cooling / demin water1.5-2.0
Instrument air10-30
Nitrogen15-20
Process Condensate1.2-2.5
Steam Condensate0.5-1
Steam (L.P.)15-30
Steam (M.P.)25-40
Wet Chlorine5-10
Wet Hydrogen10-15
Ultra Pure Brine1-2
32 % NaOH, pump discharge1-2
32 % NaOH, below cells0.7-0.9
Anolyte, below cells0.5-0.7

Additional tables & sources are uploaded here. Using these tables & the python calculator one can have preliminary checks at various units of plant which handles different fluids

Script source code #

#! /usr/bin/python
from scipy.optimize import fsolve
from math import *
import pint
unt = pint.UnitRegistry(autoconvert_offset_to_baseunit=True,\
 auto_reduce_dimensions=True)
Q_ = unt.Quantity

print ('1- Velocity [m/s] from I.D & flow')
print ('2- I.D [mm] from velocity & flow')
print ('3- Flow [m^3/hr] from I.D & velocity')

cho= int( input('Type choice 1, 2 or 3: ') )

def roots(x, *args):
	if cho==1:
		v=x
		d,f= args[0], args[1]
	elif cho==2:
		d=x
		v,f= args[0], args[1]
	else:
		f=x
		v,d= args[0], args[1]
	return f / (pi * d**2 * 0.25) - v

def caseV():
	flo= input('Type flow in m^3/hr: ')
	f= float(flo) * unt('m^3/hr')
	id= input('Type I.D in mm: ')
	d= float(id) * unt('mm')
	d.ito(unt('m'))
	sol, =fsolve( roots, x0=5000, args=(d.m,f.m) )
	sol= abs( sol.item() ) * unt('m/hr') #np.float64-> python float
	print( sol.to(unt('m/s')) ) #cannot use .ito ??

def caseD():
	flo= input('Type flow in m^3/hr: ')
	f= float(flo) * unt('m^3/hr')
	vel= input('Type velocity in m/s: ')
	v= float(vel) * unt('m/s')
	v.ito(unt('m/hr'))
	sol, =fsolve( roots, x0=0.2, args=(v.m,f.m) )
	sol= abs( sol.item() ) * unt('m')
	print( sol.to(unt('mm')) )

def caseF():
	id= input('Type I.D in mm: ')
	d= float(id) * unt('mm')
	d.ito(unt('m')) #float-> d.m is magnitude
	vel= input('Type velocity in m/s: ')
	v= float(vel) * unt('m/s')
	v.ito(unt('m/hr')) #float-> v.m is magnitude 
	sol, =fsolve( roots, x0=10, args=(v.m,d.m) )
	print( abs( sol.item() ) * unt('m^3/hr') )

caseV() if cho==1 else ( caseD() if cho==2 else caseF() )

Important Considerations #

  • For corrosive fluids, it is generally recommended to use lower velocities to minimize corrosion and erosion.
    • Sulfuric Acid (Hβ‚‚SOβ‚„):
      • For carbon steel piping, it is crucial to maintain fluid velocities between 1 and 3 ft/s (0.3 to 0.9 m/s).
      • Velocities below 1 ft/s can lead to hydrogen-grooving failure, while velocities above approximately 3 ft/s can cause erosion-corrosion.
  • For fluids with suspended solids, the velocity must be high enough to prevent settling but not so high as to cause excessive erosion.
    • Pure Brine:
      • A velocity in the range of 1 to 2 m/s (3.3 to 6.6 ft/s) is a reasonable starting point.
      • Leaning towards the lower end of the range is suggested to mitigate corrosion and erosion.
    • Raw Brine (with high sulfate):
      • General recommendations for fluid velocities in pipelines often fall within the range of 1 to 2 m/s (3.3 to 6.6 ft/s).
      • To prevent scaling and solids sedimentation, the velocity needs to be carefully managed. Too low a velocity can allow solids to settle, while too high a velocity might not prevent certain types of scaling and could lead to erosion.

Screencast #