Calculate Flow Rate from Pressure Difference
function calculateFlowRate() {
var pressureDifference = parseFloat(document.getElementById("pressureDifference").value);
var orificeCoefficient = parseFloat(document.getElementById("orificeCoefficient").value);
var orificeArea = parseFloat(document.getElementById("orificeArea").value);
var fluidDensity = parseFloat(document.getElementById("fluidDensity").value);
var flowRateResultElement = document.getElementById("flowRateResult");
if (isNaN(pressureDifference) || isNaN(orificeCoefficient) || isNaN(orificeArea) || isNaN(fluidDensity) ||
pressureDifference < 0 || orificeCoefficient <= 0 || orificeArea <= 0 || fluidDensity <= 0) {
flowRateResultElement.textContent = "Flow Rate: Please enter valid positive numbers.";
return;
}
// Formula: Q = Cd * A * sqrt((2 * ΔP) / ρ)
var flowRate = orificeCoefficient * orificeArea * Math.sqrt((2 * pressureDifference) / fluidDensity);
flowRateResultElement.textContent = "Flow Rate: " + flowRate.toFixed(4);
}
.calculator-widget {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 600px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-widget h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.calculator-inputs .input-group {
margin-bottom: 15px;
display: flex;
align-items: center;
}
.calculator-inputs label {
flex: 1;
margin-right: 10px;
font-weight: bold;
color: #555;
}
.calculator-inputs input[type="number"] {
flex: 2;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.calculator-inputs button {
display: block;
width: 100%;
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-inputs button:hover {
background-color: #0056b3;
}
.calculator-results {
margin-top: 25px;
padding-top: 15px;
border-top: 1px dashed #eee;
}
.calculator-results h3 {
color: #333;
margin-bottom: 10px;
}
.calculator-results p {
margin-bottom: 8px;
color: #444;
}
.calculator-explanation {
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid #eee;
font-size: 0.9em;
color: #666;
line-height: 1.5;
}
.calculator-explanation h3, .calculator-explanation h4 {
color: #444;
margin-bottom: 10px;
}
.calculator-explanation ul {
margin-left: 20px;
margin-bottom: 10px;
}
.calculator-explanation li {
margin-bottom: 5px;
}
.calculator-explanation strong {
color: #333;
}