Kill Mud Weight Calculator

Kill Mud Weight Calculator: Determine Optimal Mud Density body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f8f9fa; color: #333; line-height: 1.6; margin: 0; padding: 0; display: flex; justify-content: center; padding-top: 20px; padding-bottom: 40px; } .container { max-width: 1000px; width: 100%; background-color: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); text-align: center; } header { background-color: #004a99; color: #fff; padding: 20px 0; border-radius: 8px 8px 0 0; margin: -30px -30px 30px -30px; } header h1 { margin: 0; font-size: 2em; } .calculator-section { margin-bottom: 40px; padding: 25px; border: 1px solid #e0e0e0; border-radius: 6px; background-color: #fdfdfd; } .calculator-section h2 { color: #004a99; margin-top: 0; margin-bottom: 20px; } .input-group { margin-bottom: 20px; text-align: left; display: flex; flex-direction: column; gap: 8px; } .input-group label { font-weight: bold; color: #555; } .input-group input, .input-group select { padding: 10px 12px; border: 1px solid #ccc; border-radius: 4px; font-size: 1rem; width: calc(100% – 24px); /* Adjust for padding */ } .input-group .helper-text { font-size: 0.85em; color: #666; margin-top: 5px; } .error-message { color: #dc3545; font-size: 0.85em; margin-top: 5px; min-height: 1.2em; /* Prevent layout shift */ } button { background-color: #007bff; color: white; border: none; padding: 12px 20px; border-radius: 4px; cursor: pointer; font-size: 1rem; margin: 5px; transition: background-color 0.3s ease; } button:hover { background-color: #0056b3; } button.reset-btn { background-color: #ffc107; color: #212529; } button.reset-btn:hover { background-color: #e0a800; } button.copy-btn { background-color: #6c757d; } button.copy-btn:hover { background-color: #5a6268; } .results-container { background-color: #e9ecef; padding: 25px; border-radius: 6px; margin-top: 30px; text-align: left; } .results-container h3 { color: #004a99; margin-top: 0; margin-bottom: 15px; } .main-result { font-size: 2.2em; font-weight: bold; color: #28a745; background-color: #e0f7fa; padding: 15px; border-radius: 5px; margin-bottom: 20px; text-align: center; } .intermediate-results div, .formula-explanation { margin-bottom: 15px; padding: 10px; background-color: #fff; border: 1px solid #dee2e6; border-radius: 4px; } .intermediate-results span { font-weight: bold; color: #004a99; min-width: 150px; display: inline-block; } .formula-explanation p { margin: 0; } table { width: 100%; border-collapse: collapse; margin-top: 20px; margin-bottom: 20px; } th, td { padding: 10px; border: 1px solid #dee2e6; text-align: left; } thead { background-color: #004a99; color: #fff; } tbody tr:nth-child(even) { background-color: #f2f2f2; } canvas { margin-top: 20px; display: block; /* Center canvas using margin auto */ margin-left: auto; margin-right: auto; border: 1px solid #ccc; border-radius: 4px; } .chart-caption { font-size: 0.9em; color: #666; margin-top: 10px; font-style: italic; } .article-content { text-align: left; margin-top: 40px; padding-top: 30px; border-top: 1px solid #e0e0e0; } .article-content h2, .article-content h3 { color: #004a99; margin-top: 25px; margin-bottom: 15px; } .article-content p, .article-content ul, .article-content ol { margin-bottom: 15px; font-size: 1.05em; } .article-content ul, .article-content ol { padding-left: 20px; } .article-content li { margin-bottom: 8px; } .faq-item { margin-bottom: 15px; padding: 10px; border-left: 3px solid #004a99; background-color: #f8f9fa; border-radius: 4px; } .faq-item strong { display: block; color: #004a99; font-size: 1.1em; margin-bottom: 5px; } .internal-links { margin-top: 30px; padding: 20px; background-color: #e9ecef; border-radius: 6px; } .internal-links h3 { color: #004a99; margin-top: 0; margin-bottom: 15px; } .internal-links ul { list-style: none; padding: 0; } .internal-links li { margin-bottom: 10px; } .internal-links a { color: #007bff; text-decoration: none; font-weight: bold; } .internal-links a:hover { text-decoration: underline; } .internal-links p { font-size: 0.9em; color: #666; margin-top: 5px; } @media (max-width: 768px) { .container { padding: 20px; } header h1 { font-size: 1.6em; } button { width: calc(50% – 10px); margin-left: 5px; margin-right: 5px; box-sizing: border-box; } .main-result { font-size: 1.8em; } } @media (max-width: 480px) { button { width: 100%; margin-left: 0; margin-right: 0; margin-bottom: 10px; } .input-group input, .input-group select { width: calc(100% – 14px); /* Adjust for padding */ } }

Kill Mud Weight Calculator

Calculate Required Kill Mud Weight

Enter the following parameters to determine the necessary mud weight to safely control the well.

The pressure exerted by the reservoir fluids, measured in pounds per gallon.
The current density of the drilling fluid at the bottom of the well.
The vertical distance from the surface to the target formation.
The measured depth of the bottom of the last casing string set.
The measured length of the casing string from the surface to the shoe.
The measured pressure in the annulus when flow is stopped.

Calculation Results

Equivalent Circulating Density (ECD):
Hydrostatic Pressure at Shoe:
Kill Rate Pressure:

Formula Explanation

The Kill Mud Weight (KMW) is calculated to ensure the hydrostatic pressure exerted by the mud column is equal to or slightly greater than the formation pressure at the shoe, while accounting for surface pressures. The primary goal is to balance the formation pressure without causing lost circulation. It is generally calculated as: KMW = (Formation Pressure at Shoe + Surface Pressure / 0.052 * TVD) / 0.052 / TVD, where pressures are in psi and depths in feet.

Kill Mud Weight Data Table

Parameter Value Unit
Formation Pressure ppg
Mud Weight on Bottom ppg
True Vertical Depth (TVD) feet
Casing Shoe Depth feet
Surface to Shoe Length feet
Shut-In Annular Pressure psi
Equivalent Circulating Density (ECD) ppg
Hydrostatic Pressure at Shoe psi
Kill Rate Pressure psi
Required Kill Mud Weight (KMW) ppg
Key pressure values involved in kill mud weight calculation.

Kill Mud Weight Dynamics

Comparison of Formation Pressure, Hydrostatic Pressure, and Kill Mud Weight Pressure.

What is Kill Mud Weight?

The kill mud weight refers to the specific density of drilling fluid (mud) required to safely control a well during a kick or blowout situation. A kick occurs when formation fluids (oil, gas, or water) enter the wellbore. If not managed properly, this influx can lead to a blowout, a dangerous and uncontrolled release of hydrocarbons. The kill mud weight is the minimum density needed to exert enough hydrostatic pressure to overcome the formation pressure at the point of entry and prevent further influx. It is a critical parameter in well control operations, ensuring the safety of personnel, equipment, and the environment. Calculating the correct kill mud weight is paramount to preventing well control incidents. Understanding the kill mud weight is essential for drilling engineers and well control specialists.

Who should use it:

  • Drilling Engineers
  • Well Control Specialists
  • Drilling Supervisors
  • Mud Engineers
  • Operations Managers

Common misconceptions:

  • That the kill mud weight is simply the formation pressure. In reality, it needs to account for hydrostatic losses and potentially surface pressures.
  • That the same kill mud weight applies to all wells. Each well's unique pressures and depths require a specific kill mud weight calculation.
  • That the kill mud weight is a static value. It can change as the wellbore conditions evolve.

Kill Mud Weight Formula and Mathematical Explanation

Calculating the kill mud weight involves several steps, primarily focused on balancing the hydrostatic pressure of the mud column against the formation pressure. The most common methods involve the "Drill Pipe Hydrostatic" and "Annulus Hydrostatic" methods. For simplicity and directness in this calculator, we focus on a simplified approach that determines the required hydrostatic pressure at the casing shoe and converts that to an equivalent mud weight, considering available surface pressures.

The fundamental principle is: Hydrostatic Pressure (psi) = 0.052 * Mud Weight (ppg) * True Vertical Depth (feet).

To find the kill mud weight, we aim to achieve a hydrostatic pressure at the shoe that balances the formation pressure there. A simplified approach, often used as a starting point or for specific scenarios, determines the target hydrostatic pressure at the shoe based on the formation pressure and the shut-in pressure in the annulus:

Target Hydrostatic Pressure at Shoe (psi) = Shut-In Annular Pressure (psi) + (Formation Pressure at Shoe (ppg) * 0.052 * Shoe Depth (feet))

However, a more practical and commonly used formula for kill mud weight (KMW) often focuses on overcoming the formation pressure at the wellbore, while also considering the existing mud weight and surface pressures. A direct calculation for the required kill mud weight (KMW) at the surface can be derived based on the pressure required at the casing shoe:

Pressure Required at Shoe (psi) = Formation Pressure at Shoe (ppg) * 0.052 * TVD_to_Shoe (feet)

Where TVD_to_Shoe is the true vertical depth from the surface to the casing shoe.

The total pressure that needs to be overcome by the mud column at the surface to balance the formation pressure at the shoe, considering any annular pressure (which might indicate a kick's severity or the pressure trapped above the shoe), is complex. A common simplified approach to calculate the kill mud weight (KMW) targets balancing the formation pressure at the depth of the shoe.

A widely applied formula for the kill mud weight (KMW) to be circulated from the surface is:

Kill Mud Weight (KMW) = (Formation Pressure at Shoe (psi) + Shut-In Annular Pressure (psi)) / (0.052 * TVD_to_Shoe (feet))

Where:

  • Formation Pressure at Shoe (psi): This is derived from the formation pressure in ppg. It's the pressure the reservoir is exerting at the depth of the shoe.
  • Shut-In Annular Pressure (psi): The pressure measured in the annulus when the well is shut-in, typically indicating the severity of the kick.
  • TVD_to_Shoe (feet): The true vertical depth from the surface to the casing shoe.

The calculator also considers the Equivalent Circulating Density (ECD), which is the effective mud weight when mud is being circulated, accounting for friction pressure. For simplification in this tool, we will focus on static conditions and the required KMW to balance formation pressure at the shoe.

Variable Explanations:

Variable Meaning Unit Typical Range
Formation Pressure (FP) Pressure exerted by reservoir fluids. ppg 8.5 – 18.0
Mud Weight on Bottom (MWOB) Current mud density. ppg 8.0 – 17.0
True Vertical Depth (TVD) Vertical depth to target zone. feet 1,000 – 30,000+
Casing Shoe Depth (CSD) Depth of the casing shoe. feet 1,000 – 25,000+
Surface to Shoe Length Measured length of casing from surface to shoe. feet 1,000 – 25,000+
Shut-In Annular Pressure (SIAP) Pressure in annulus when well is shut-in. psi 0 – 1500+
Kill Mud Weight (KMW) Required mud density to kill the well. ppg MWOB – FP
Hydrostatic Pressure (HP) Pressure due to the weight of the mud column. psi Varies
Equivalent Circulating Density (ECD) Effective mud weight during circulation. ppg Varies

Practical Examples (Real-World Use Cases)

Understanding kill mud weight calculations is crucial. Here are a couple of scenarios:

Example 1: Standard Well Control Scenario

A drilling operation is at 12,000 feet TVD. The current mud weight on bottom is 10.0 ppg. The casing shoe is set at 11,500 feet measured depth (MD) and true vertical depth (TVD). A kick is detected, indicated by a shut-in annular pressure of 300 psi. The formation pressure is estimated to be 15.0 ppg.

  • Formation Pressure (ppg): 15.0
  • Mud Weight on Bottom (ppg): 10.0
  • True Vertical Depth (TVD) (feet): 12,000
  • Casing Shoe Depth (feet): 11,500
  • Surface to Shoe Length (feet): 11,500
  • Shut-In Annular Pressure (psi): 300

Calculation using our tool:

The calculator determines the pressure at the shoe. The formation pressure at the shoe is 15.0 ppg * 0.052 * 11,500 feet = 8,970 psi. With the shut-in annular pressure of 300 psi, the total pressure to overcome at the shoe is 8,970 + 300 = 9,270 psi. The required kill mud weight is then (9,270 psi) / (0.052 * 11,500 feet) = 16.25 ppg.

Interpretation: The drilling team must increase the mud weight from 10.0 ppg to 16.25 ppg to safely control the influx and prevent further entry of formation fluids. This significant increase highlights the severity of the situation.

Example 2: Higher Pressure Formation with Lower TVD

A shallower well at 7,000 feet TVD encounters a high-pressure zone. The current mud weight is 12.0 ppg. The casing shoe is at 6,800 feet TVD. A kick is registered with a shut-in annular pressure of 500 psi. The formation pressure is estimated at 16.5 ppg.

  • Formation Pressure (ppg): 16.5
  • Mud Weight on Bottom (ppg): 12.0
  • True Vertical Depth (TVD) (feet): 7,000
  • Casing Shoe Depth (feet): 6,800
  • Surface to Shoe Length (feet): 6,800
  • Shut-In Annular Pressure (psi): 500

Calculation using our tool:

The formation pressure at the shoe depth is 16.5 ppg * 0.052 * 6,800 feet = 5,824.8 psi. Adding the shut-in annular pressure of 500 psi gives a total pressure of 5,824.8 + 500 = 6,324.8 psi to overcome at the shoe. The required kill mud weight is (6,324.8 psi) / (0.052 * 6,800 feet) = 18.18 ppg.

Interpretation: Even at a shallower depth, the high formation pressure necessitates a substantial increase in mud weight to 18.18 ppg. This demonstrates that formation pressure is a more dominant factor than depth in this case for determining the kill mud weight.

How to Use This Kill Mud Weight Calculator

  1. Input Formation Pressure: Enter the estimated pressure of the reservoir in pounds per gallon (ppg).
  2. Input Mud Weight on Bottom: Enter the current density of the drilling fluid in ppg.
  3. Input True Vertical Depth (TVD): Provide the vertical distance from the surface to the formation of interest in feet.
  4. Input Casing Shoe Depth: Enter the measured depth of the bottom of the last casing string in feet.
  5. Input Surface to Shoe Length: Enter the measured length of the casing from the surface to the shoe in feet. This is often similar to the casing shoe depth in TVD unless there are significant horizontal sections.
  6. Input Shut-In Annular Pressure: Record the pressure measured in the annulus after the well has been shut-in, indicating the severity of the kick, in psi.
  7. Click 'Calculate': The calculator will process your inputs.

How to read results:

  • Primary Result (Required Kill Mud Weight): This is the most critical number – the density your mud needs to reach to safely control the well.
  • Intermediate Values: These provide insight into the pressures being managed:
    • Equivalent Circulating Density (ECD): The effective density when mud is flowing. This is often higher than static mud weight due to friction. For this calculator, it reflects the target static mud weight required.
    • Hydrostatic Pressure at Shoe: The pressure exerted by the current mud column at the depth of the casing shoe.
    • Kill Rate Pressure: The pressure at the shoe that the new, heavier kill mud will exert.
  • Table: A detailed breakdown of all input parameters and calculated results for easy reference.
  • Chart: A visual representation comparing different pressure profiles.

Decision-making guidance: The calculated Kill Mud Weight (KMW) is the target density. Your well control plan will involve slowly increasing the mud weight to this value. It's crucial to do this gradually to avoid fracturing the formation (lost circulation). Monitor well parameters closely throughout the kill operation.

Key Factors That Affect Kill Mud Weight Results

Several factors influence the calculation and the actual kill mud weight required:

  1. Formation Pressure: This is the single most significant factor. Higher formation pressures directly translate to higher kill mud weights needed. Accurately estimating formation pressure is vital.
  2. True Vertical Depth (TVD): Deeper wells have longer mud columns, which naturally exert more hydrostatic pressure. However, if formation pressure increases proportionally with depth, the required kill mud weight might not always be higher for deeper wells.
  3. Casing Shoe Depth and Design: The casing shoe represents a critical point. The kill mud weight must be sufficient to balance formation pressure at this depth without exceeding the fracture gradient of the formation below the shoe. The integrity and depth of the casing string are key design considerations.
  4. Shut-In Annular Pressure (SIAP): A higher SIAP indicates a more severe kick and a greater influx of formation fluids, requiring a higher kill mud weight to counteract it. It provides a direct measure of the pressure the mud column must overcome.
  5. Mud Properties: While this calculator focuses on density (ppg), the rheology and other properties of the mud can affect ECD during circulation. A higher ECD during kill operations can increase the required surface mud weight.
  6. Fracture Gradient: This is the pressure at which the formation rock will fracture. The kill mud weight must be low enough not to exceed the fracture gradient below the casing shoe, as this could lead to lost circulation and an inability to control the well. There's a delicate balance between having enough hydrostatic pressure and not fracturing the formation.
  7. Annular Velocity and Friction: During kill operations, circulating the heavier mud generates frictional pressure losses in the annulus. This friction pressure adds to the required bottom-hole pressure. While simplified calculators might not directly compute this, sophisticated well control procedures account for it, often leading to a higher effective kill mud weight requirement during circulation.
  8. Wellbore Geometry: Variations in wellbore diameter, presence of liners, or complex hole sections can affect annular volume and fluid dynamics, indirectly influencing the pressures and fluid management during a kill operation.

Frequently Asked Questions (FAQ)

Q1: What is the difference between formation pressure and kill mud weight?

Formation pressure is the natural pressure exerted by the fluids within the reservoir rock. Kill mud weight is the density of the drilling fluid that must be pumped into the well to counteract the formation pressure and stop the flow of reservoir fluids into the wellbore. Kill mud weight is typically higher than the current mud weight and often higher than the formation pressure itself to ensure a safety margin.

Q2: Can I use the kill mud weight calculation for any type of kick?

This calculator is designed for common well control scenarios. Different types of kicks (e.g., gas vs. oil vs. water) and complex formations might require specialized well control procedures and more advanced calculations, often performed using specialized software or by experienced well control engineers.

Q3: What does "ppg" stand for?

PPG stands for "pounds per gallon," which is a common unit of density used for drilling fluids in the oil and gas industry.

Q4: How accurate is the kill mud weight calculator?

The accuracy depends heavily on the accuracy of the input data, particularly formation pressure and shut-in annular pressure. The formulas used are standard industry approximations. For critical operations, always consult with experienced well control personnel and use rig-specific software.

Q5: What is the significance of the casing shoe depth?

The casing shoe is the bottom end of a casing string. It's a critical structural point. The kill mud weight must be sufficient to control pressure at the shoe, but also low enough not to fracture the formations below the shoe, which are often less consolidated and have lower fracture gradients.

Q6: How do I gradually increase the mud weight?

This is typically done by mixing higher-density mud at the surface and circulating it into the wellbore. The process is carefully controlled to maintain a safe annular velocity and avoid formation breakdown. This is part of the detailed well kill procedure, not directly part of the KMW calculation itself.

Q7: What is ECD and why is it important for kill mud weight?

ECD stands for Equivalent Circulating Density. When mud is circulated, friction creates additional pressure. ECD accounts for this. While this calculator aims for the static kill mud weight, understanding ECD is crucial because the effective pressure during circulation might be higher, influencing the surface mud weight required.

Q8: What happens if I don't use the correct kill mud weight?

If the kill mud weight is too low, the hydrostatic pressure will not be sufficient to overcome formation pressure, leading to a continued influx of formation fluids and a potential blowout. If it's too high, it could exceed the fracture gradient of the formation below the casing shoe, causing lost circulation and potentially making well control impossible.

© 2023 YourCompany Name. All rights reserved.

var formationPressureInput = document.getElementById('formationPressure'); var mudWeightOnBottomInput = document.getElementById('mudWeightOnBottom'); var trueVerticalDepthInput = document.getElementById('trueVerticalDepth'); var casingShoeDepthInput = document.getElementById('casingShoeDepth'); var surfaceToShoeLengthInput = document.getElementById('surfaceToShoeLength'); var shutInAnnularPressureInput = document.getElementById('shutInAnnularPressure'); var formationPressureError = document.getElementById('formationPressureError'); var mudWeightOnBottomError = document.getElementById('mudWeightOnBottomError'); var trueVerticalDepthError = document.getElementById('trueVerticalDepthError'); var casingShoeDepthError = document.getElementById('casingShoeDepthError'); var surfaceToShoeLengthError = document.getElementById('surfaceToShoeLengthError'); var shutInAnnularPressureError = document.getElementById('shutInAnnularPressureError'); var mainResultDiv = document.getElementById('mainResult'); var intermediatePressureDiv = document.getElementById('intermediatePressure'); var intermediateHydrostaticDiv = document.getElementById('intermediateHydrostatic'); var intermediateKillRateDiv = document.getElementById('intermediateKillRate'); var tableFormationPressure = document.getElementById('tableFormationPressure'); var tableMudWeightOnBottom = document.getElementById('tableMudWeightOnBottom'); var tableTVD = document.getElementById('tableTVD'); var tableCasingShoeDepth = document.getElementById('tableCasingShoeDepth'); var tableSurfaceToShoeLength = document.getElementById('tableSurfaceToShoeLength'); var tableShutInAnnularPressure = document.getElementById('tableShutInAnnularPressure'); var tableECD = document.getElementById('tableECD'); var tableHydrostatic = document.getElementById('tableHydrostatic'); var tableKillRate = document.getElementById('tableKillRate'); var tableKMW = document.getElementById('tableKMW'); var pressureChart; var chartInstance = null; function validateInput(inputElement, errorElement, minValue = 0) { var value = parseFloat(inputElement.value); var isValid = !isNaN(value) && value >= minValue; if (!isValid) { errorElement.textContent = "Please enter a valid number greater than or equal to " + minValue; inputElement.classList.add('error'); } else { errorElement.textContent = ""; inputElement.classList.remove('error'); } return isValid; } function calculateHydrostaticPressure(mudWeight, depth) { if (isNaN(mudWeight) || isNaN(depth) || depth === 0) return 0; return 0.052 * mudWeight * depth; } function calculateKillMudWeight(formationPressurePpg, mudWeightOnBottomPpg, tvd, casingShoeDepth, surfaceToShoeLength, shutInAnnularPressurePsi) { // Use casingShoeDepth for calculation of pressure at shoe, if different from TVD_to_Shoe var depthForPressureCalc = surfaceToShoeLength > 0 ? surfaceToShoeLength : casingShoeDepth; if (depthForPressureCalc === 0) return { kmw: NaN, ecd: NaN, hydrostaticAtShoe: NaN, killRatePressure: NaN }; var formationPressureAtShoePsi = calculateHydrostaticPressure(formationPressurePpg, depthForPressureCalc); // Pressure to overcome at the shoe is formation pressure plus shut-in annular pressure var totalPressureToOvercomeAtShoe = formationPressureAtShoePsi + shutInAnnularPressurePsi; // Kill Mud Weight (KMW) required at the surface to exert enough hydrostatic pressure at the shoe var kmw = totalPressureToOvercomeAtShoe / (0.052 * depthForPressureCalc); // For simplicity in this calculator, we'll use the calculated KMW as the target ECD and represent hydrostatic pressure at shoe based on formation pressure. var hydrostaticAtShoe = formationPressureAtShoePsi; // Pressure exerted by reservoir at shoe depth var killRatePressure = totalPressureToOvercomeAtShoe; // Total pressure needed at shoe depth // Ensure KMW is not less than the current mud weight, as increasing density is required. if (!isNaN(kmw) && kmw MWOB, but a safeguard } return { kmw: kmw, ecd: kmw, // For simplicity, ECD target is the KMW itself hydrostaticAtShoe: hydrostaticAtShoe, killRatePressure: killRatePressure }; } function updateChart(formationPressurePpg, currentMudWeightPpg, killMudWeightPpg, tvd, casingShoeDepth) { var ctx = document.getElementById('pressureChart').getContext('2d'); if (chartInstance) { chartInstance.destroy(); } var maxDepth = tvd > 0 ? tvd : 10000; // Default max depth if tvd is 0 var depthLevels = [0, maxDepth * 0.5, maxDepth]; // Simple depth points var formationPressureValues = []; var currentMudPressureValues = []; var killMudPressureValues = []; for (var i = 0; i tvd) { casingShoeDepthError.textContent = "Casing shoe depth cannot be greater than TVD."; isValidCsd = false; } // Ensure surface to shoe length is not greater than TVD if (isValidS2sl && isValidTvd && s2sl > tvd) { surfaceToShoeLengthError.textContent = "Surface to shoe length cannot be greater than TVD."; isValidS2sl = false; } // Ensure surface to shoe length is not greater than casing shoe depth if casing shoe depth is relevant if (isValidS2sl && isValidCsd && s2sl > csd) { surfaceToShoeLengthError.textContent = "Surface to shoe length cannot be greater than casing shoe depth."; isValidS2sl = false; } if (!(isValidFp && isValidMwob && isValidTvd && isValidCsd && isValidS2sl && isValidSiap)) { mainResultDiv.textContent = "–"; intermediatePressureDiv.innerHTML = "Equivalent Circulating Density (ECD): –"; intermediateHydrostaticDiv.innerHTML = "Hydrostatic Pressure at Shoe: –"; intermediateKillRateDiv.innerHTML = "Kill Rate Pressure: –"; updateTableData('–', '–', '–', '–', '–', '–', '–', '–', '–', '–'); if (chartInstance) chartInstance.destroy(); return; } // Use surfaceToShoeLength for depth calculations if provided and valid, otherwise fallback to casingShoeDepth var effectiveDepthForKmw = s2sl > 0 ? s2sl : csd; if (effectiveDepthForKmw <= 0) { // Fallback if S2SL is 0 and CSD is 0 or invalid effectiveDepthForKmw = tvd; // Use TVD as last resort if other depths are invalid/zero } var results = calculateKillMudWeight(fp, mwob, tvd, csd, effectiveDepthForKmw, siap); var kmw = results.kmw; var ecd = results.ecd; var hydrostaticAtShoe = results.hydrostaticAtShoe; var killRatePressure = results.killRatePressure; var formattedKmw = isNaN(kmw) ? "–" : kmw.toFixed(2); var formattedEcd = isNaN(ecd) ? "–" : ecd.toFixed(2); var formattedHydrostatic = isNaN(hydrostaticAtShoe) ? "–" : hydrostaticAtShoe.toFixed(2); var formattedKillRatePressure = isNaN(killRatePressure) ? "–" : killRatePressure.toFixed(2); mainResultDiv.textContent = formattedKmw + " ppg"; intermediatePressureDiv.innerHTML = "Equivalent Circulating Density (ECD): " + formattedEcd + " ppg"; intermediateHydrostaticDiv.innerHTML = "Hydrostatic Pressure at Shoe: " + formattedHydrostatic + " psi"; intermediateKillRateDiv.innerHTML = "Kill Rate Pressure: " + formattedKillRatePressure + " psi"; updateTableData(fp, mwob, tvd, csd, s2sl, siap, formattedEcd, formattedHydrostatic, formattedKillRatePressure, formattedKmw); if (!isNaN(kmw)) { updateChart(fp, mwob, kmw, tvd, effectiveDepthForKmw); } else { if (chartInstance) chartInstance.destroy(); } } function updateTableData(fp, mwob, tvd, csd, s2sl, siap, ecd, hydrostatic, killRate, kmw) { tableFormationPressure.textContent = typeof fp === 'number' ? fp.toFixed(2) : '–'; tableMudWeightOnBottom.textContent = typeof mwob === 'number' ? mwob.toFixed(2) : '–'; tableTVD.textContent = typeof tvd === 'number' ? tvd.toFixed(0) : '–'; tableCasingShoeDepth.textContent = typeof csd === 'number' ? csd.toFixed(0) : '–'; tableSurfaceToShoeLength.textContent = typeof s2sl === 'number' ? s2sl.toFixed(0) : '–'; tableShutInAnnularPressure.textContent = typeof siap === 'number' ? siap.toFixed(2) : '–'; tableECD.textContent = ecd; tableHydrostatic.textContent = hydrostatic; tableKillRate.textContent = killRate; tableKMW.textContent = kmw; } function resetForm() { formationPressureInput.value = "15.0"; mudWeightOnBottomInput.value = "10.0"; trueVerticalDepthInput.value = "12000"; casingShoeDepthInput.value = "11500"; surfaceToShoeLengthInput.value = "11500"; shutInAnnularPressureInput.value = "300"; formationPressureError.textContent = ""; mudWeightOnBottomError.textContent = ""; trueVerticalDepthError.textContent = ""; casingShoeDepthError.textContent = ""; surfaceToShoeLengthError.textContent = ""; shutInAnnularPressureError.textContent = ""; calculateKillMudWeight(); } function copyResults() { var mainResultText = "Required Kill Mud Weight: " + mainResultDiv.textContent + "\n"; var intermediateResultsText = ""; intermediateResultsText += "Equivalent Circulating Density (ECD): " + document.getElementById('intermediatePressure').innerText.replace('Equivalent Circulating Density (ECD): ', ").trim() + "\n"; intermediateResultsText += "Hydrostatic Pressure at Shoe: " + document.getElementById('intermediateHydrostatic').innerText.replace('Hydrostatic Pressure at Shoe: ', ").trim() + "\n"; intermediateResultsText += "Kill Rate Pressure: " + document.getElementById('intermediateKillRate').innerText.replace('Kill Rate Pressure: ', ").trim() + "\n"; var keyAssumptions = "Key Assumptions:\n"; keyAssumptions += "- Formation Pressure: " + (tableFormationPressure.textContent || '–') + " ppg\n"; keyAssumptions += "- Mud Weight on Bottom: " + (tableMudWeightOnBottom.textContent || '–') + " ppg\n"; keyAssumptions += "- True Vertical Depth (TVD): " + (tableTVD.textContent || '–') + " feet\n"; keyAssumptions += "- Casing Shoe Depth: " + (tableCasingShoeDepth.textContent || '–') + " feet\n"; keyAssumptions += "- Surface to Shoe Length: " + (tableSurfaceToShoeLength.textContent || '–') + " feet\n"; keyAssumptions += "- Shut-In Annular Pressure: " + (tableShutInAnnularPressure.textContent || '–') + " psi\n"; var fullText = mainResultText + "\n" + intermediateResultsText + "\n" + keyAssumptions; navigator.clipboard.writeText(fullText).then(function() { alert('Results copied to clipboard!'); }, function(err) { console.error('Failed to copy results: ', err); alert('Failed to copy results. Please copy manually.'); }); } // Initial calculation on page load document.addEventListener('DOMContentLoaded', function() { resetForm(); // Load with default values and calculate // Ensure chart canvas is available var canvas = document.getElementById('pressureChart'); if (canvas) { var ctx = canvas.getContext('2d'); // Initialize chart with empty data or a placeholder chartInstance = new Chart(ctx, { type: 'line', data: { labels: [], datasets: [{ label: 'Formation Pressure (psi)', data: [], borderColor: '#dc3545', fill: false }, { label: 'Current Mud Pressure (psi)', data: [], borderColor: '#004a99', fill: false }, { label: 'Kill Mud Pressure (psi)', data: [], borderColor: '#28a745', fill: false }] }, options: { responsive: true, scales: { x: { title: { display: true, text: 'Depth (feet)' } }, y: { title: { display: true, text: 'Pressure (psi)' }, beginAtZero: true } } } }); } }); // Add event listeners for real-time updates var inputs = [formationPressureInput, mudWeightOnBottomInput, trueVerticalDepthInput, casingShoeDepthInput, surfaceToShoeLengthInput, shutInAnnularPressureInput]; inputs.forEach(function(input) { input.addEventListener('input', calculateKillMudWeight); });

Leave a Comment