// Configuration for units and labels
var units = {
metric: {
flow: "m³/h",
diameter: "mm",
velocity: "m/s",
area: "cm²"
},
imperial: {
flow: "GPM",
diameter: "inches",
velocity: "ft/s",
area: "sq. inches"
}
};
function updateLabels() {
var system = document.getElementById('unitSystem').value;
document.getElementById('labelFlow').innerText = "(" + units[system].flow + ")";
document.getElementById('labelDiameter').innerText = "(" + units[system].diameter + ")";
document.getElementById('labelVelocity').innerText = "(" + units[system].velocity + ")";
// Re-calculate if results are visible
if(document.getElementById('result-box').style.display === 'block') {
calculatePipe();
}
}
function updateFormState() {
var target = document.getElementById('calcTarget').value;
var flowInput = document.getElementById('inputFlow');
var diaInput = document.getElementById('inputDiameter');
var velInput = document.getElementById('inputVelocity');
// Reset all
flowInput.disabled = false;
flowInput.style.backgroundColor = "white";
diaInput.disabled = false;
diaInput.style.backgroundColor = "white";
velInput.disabled = false;
velInput.style.backgroundColor = "white";
// Disable target input
if (target === 'flow') {
flowInput.disabled = true;
flowInput.style.backgroundColor = "#e9ecef";
flowInput.value = "";
} else if (target === 'diameter') {
diaInput.disabled = true;
diaInput.style.backgroundColor = "#e9ecef";
diaInput.value = "";
} else if (target === 'velocity') {
velInput.disabled = true;
velInput.style.backgroundColor = "#e9ecef";
velInput.value = "";
}
document.getElementById('result-box').style.display = 'none';
}
function calculatePipe() {
var system = document.getElementById('unitSystem').value;
var target = document.getElementById('calcTarget').value;
// Get raw values
var flowVal = parseFloat(document.getElementById('inputFlow').value);
var diaVal = parseFloat(document.getElementById('inputDiameter').value);
var velVal = parseFloat(document.getElementById('inputVelocity').value);
var result = 0;
var resultText = "";
var secondaryText = "";
// MATH LOGIC
// We will normalize everything to Metric SI units (m3/s, meters, m/s) for calculation, then convert back.
// SI Units: Flow (Q) in m³/s, Diameter (D) in meters, Velocity (V) in m/s.
// Formula: Q = (PI * D^2 / 4) * V
var siFlow = 0; // m3/s
var siDia = 0; // meters
var siVel = 0; // m/s
// 1. Convert Inputs to SI
if (system === 'metric') {
if (!isNaN(flowVal)) siFlow = flowVal / 3600; // m3/h to m3/s
if (!isNaN(diaVal)) siDia = diaVal / 1000; // mm to m
if (!isNaN(velVal)) siVel = velVal; // m/s
} else {
// Imperial: GPM, inches, ft/s
// 1 GPM = 6.30902e-5 m3/s
// 1 inch = 0.0254 m
// 1 ft = 0.3048 m
if (!isNaN(flowVal)) siFlow = flowVal * 0.0000630902;
if (!isNaN(diaVal)) siDia = diaVal * 0.0254;
if (!isNaN(velVal)) siVel = velVal * 0.3048;
}
// 2. Calculate based on Target
if (target === 'diameter') {
// Needed: Flow and Velocity
if (isNaN(flowVal) || isNaN(velVal) || flowVal <= 0 || velVal <= 0) {
alert("Please enter valid positive numbers for Flow Rate and Velocity.");
return;
}
// Area = Q / V
// D = sqrt(4 * Area / PI) = sqrt(4 * Q / (PI * V))
siDia = Math.sqrt((4 * siFlow) / (Math.PI * siVel));
// Convert back
if (system === 'metric') {
result = siDia * 1000; // to mm
resultText = result.toFixed(2) + " " + units.metric.diameter;
} else {
result = siDia / 0.0254; // to inches
resultText = result.toFixed(2) + " " + units.imperial.diameter;
}
secondaryText = "Recommended Internal Diameter";
} else if (target === 'flow') {
// Needed: Diameter and Velocity
if (isNaN(diaVal) || isNaN(velVal) || diaVal <= 0 || velVal <= 0) {
alert("Please enter valid positive numbers for Diameter and Velocity.");
return;
}
// Q = A * V = (PI * D^2 / 4) * V
siFlow = (Math.PI * Math.pow(siDia, 2) / 4) * siVel;
// Convert back
if (system === 'metric') {
result = siFlow * 3600; // to m3/h
resultText = result.toFixed(2) + " " + units.metric.flow;
} else {
result = siFlow / 0.0000630902; // to GPM
resultText = result.toFixed(2) + " " + units.imperial.flow;
}
secondaryText = "Calculated Flow Rate";
} else if (target === 'velocity') {
// Needed: Flow and Diameter
if (isNaN(flowVal) || isNaN(diaVal) || flowVal <= 0 || diaVal <= 0) {
alert("Please enter valid positive numbers for Flow Rate and Diameter.");
return;
}
// V = Q / A = Q / (PI * D^2 / 4)
siVel = siFlow / (Math.PI * Math.pow(siDia, 2) / 4);
// Convert back
if (system === 'metric') {
result = siVel; // already m/s
resultText = result.toFixed(2) + " " + units.metric.velocity;
} else {
result = siVel / 0.3048; // to ft/s
resultText = result.toFixed(2) + " " + units.imperial.velocity;
}
secondaryText = "Resulting Fluid Velocity";
}
// Display Result
var resBox = document.getElementById('result-box');
var resMain = document.getElementById('mainResult');
var resSub = document.getElementById('secondaryResult');
resMain.innerHTML = resultText;
resSub.innerHTML = secondaryText;
resBox.style.display = 'block';
}
// Initialize
updateFormState();
updateLabels();
How to Calculate Pipe Size and Flow Rate
Properly sizing pipes is crucial for efficient fluid transport in engineering, plumbing, and irrigation systems. A pipe that is too small can cause excessive pressure drop and noise due to high velocity, while a pipe that is too large can lead to sediment buildup and unnecessary material costs.
The Fundamental Formula
The relationship between Flow Rate ($Q$), Pipe Diameter ($D$), and Fluid Velocity ($V$) is governed by the continuity equation:
Q = A × V
Where:
Q is the volumetric flow rate (e.g., m³/h or GPM).
A is the cross-sectional area of the pipe ($\pi \cdot r^2$ or $\frac{\pi \cdot D^2}{4}$).
V is the average fluid velocity (e.g., m/s or ft/s).
Recommended Velocity Ranges
When designing a system, you usually start with a required flow rate and aim for a specific velocity to determine the pipe diameter. Common industry standards for water include:
General Water Supply: 1.0 to 2.5 m/s (3 to 8 ft/s).
Pump Suction Lines: Keep velocity lower, typically 0.6 to 1.2 m/s (2 to 4 ft/s) to prevent cavitation.
Pump Discharge Lines: 1.5 to 3.0 m/s (5 to 10 ft/s).
Why Velocity Matters
High Velocity: Causes water hammer, noise, erosion of pipe walls, and significant friction head loss, requiring more powerful pumps.
Low Velocity: In drainage or wastewater lines, low velocity (below 0.6 m/s or 2 ft/s) may prevent solids from being flushed out, leading to clogs.
Using This Calculator
This tool allows you to solve for any of the three variables. If you know your target flow rate (e.g., for a shower or irrigation zone) and the recommended velocity (e.g., 2 m/s), select "Pipe Diameter" to find the required internal size. Remember that pipes are sold by nominal outer diameter, so you may need to consult a pipe schedule chart (like Schedule 40 or 80) to find the closest matching standard size.