Field fix / guideDesign DocumentVendor-agnostic (IEC 61131-3)Oil & Gasindustrial-automation

Pipeline Flow Metering & Leak Detection — Control Design

Shared by TSIMEREZIVO Team · 4 Oct 2026 · 35 views

# Oil & Gas Template: Pipeline Flow Metering & Leak Detection ## 1. Overview **Purpose:** Continuously measure crude/gas flow through transmission pipeline (orifice plate, turbine, or ultrasonic meter) and detect leaks by comparing expected flow (from surface + subsurface meters) against actual outlet flow. A 2% daily discrepancy (100 bopd on 5000 bopd line) could indicate a crack, corrosion hole, or theft. **Industry Standards:** - API 14.1 (Design of Onshore Drilling Mud Treatment Systems) - ISO 2186 (Measurement of Fluid Flow — Orifice Plates) - ASME B39.1 (Nonmetallic Tube Fittings) - AGA Report 3 (Orifice Metering for Natural Gas) - ISO 9951 (Turbine Flow Meter) **Critical Constraints:** - **Orifice plate accuracy:** ±1–2% at design flow; drops to ±3–5% at 50% flow - **Temperature compensation:** meter factor = k(T); oil meters sensitive to T shifts (±0.5% per 5°C) - **Pressure drop:** orifice creates ΔP = meter reading; large lines must minimize parasitic loss - **Meter factor drift:** orifice degrades over 2–3 years (erosion, deposits); periodic calibration required - **Leak threshold:** operators typically alert on >1–2% unexplained loss - **Detection lag:** pressure drops take 30 sec – 5 min to propagate down long pipeline; flow doesn't reflect immediately **Relevant Physics:** - **Orifice flow:** $Q = C_d × A × \sqrt{2 \times \Delta P / \rho}$ (Cd ≈ 0.6–0.65 for sharp-edge orifices) - **Compressibility factor (Z):** real gas correction: $Z = 1 - \frac{BRT}{V}$ (virial coefficients) - **Temperature viscosity:** meter output may require T correction: $Q_{corrected} = Q × f(T)$ --- ## 2. Control Philosophy ``` LAYER 1: Multi-Point Flow Measurement Points: Wellhead + subsurface + mid-pipeline + export header Benefits: triangulate leak location (if any) LAYER 2: Mass Balance Check Input: sum of all inlet sources Output: sum of all outlet flows Expected = Measured? If not, leak exists LAYER 3: Leak Localization If inlet flow > outlet flow: Is leak pre-meter-1 or post-meter-1? Compare: wellhead − meter-1 vs. meter-1 − meter-2 etc. LAYER 4: Pressure Profile Warning If pressure drops abnormally at single location → localize via spatial derivative ``` --- ## 3. Control Logic (Condensed) ```pascal { === PIPELINE FLOW METERING & LEAK DETECTION === } PROCEDURE Pipeline_Leak_Detection_Master CONSTANTS NUM_METERS = 4 { wellhead, mid1, mid2, export } METER_ACCURACY_PCT = 2.0 { orifice plate } ACCEPTABLE_LOSS_PCT = 1.5 { 1.5% materialbalance error OK } LEAK_ALARM_THRESHOLD_PCT = 2.0 { >2% triggers alert } CONFIDENCE_WINDOW_HOURS = 2 { need 2 hrs stable flow for diagnosis } VARIABLES flow_measured_bopd[1..NUM_METERS] : REAL flow_prev_bopd[1..NUM_METERS] : REAL pressure_psi[1..NUM_METERS] : REAL temperature_f[1..NUM_METERS] : REAL mass_balance_input_bopd : REAL { sum of all sources } mass_balance_output_bopd : REAL { sum of all sinks } unaccounted_loss_pct : REAL meter_k_factor[1..NUM_METERS] : REAL { calibration factor } leak_detected : BOOLEAN leak_location_segment : STRING { "well-to-mid1" etc } leak_severity : ENUMERATION { MINOR | MODERATE | MAJOR | CRITICAL } BEGIN FOR m = 1 TO NUM_METERS DO { Read each meter } flow_measured_bopd[m] = Read_Flow_Meter(m) { impulse / electronic } pressure_psi[m] = Read_Pressure_Transmitter(m) temperature_f[m] = Read_Temperature_Sensor(m) { Apply temperature correction to meter factor } IF temperature_f[m] < > temperature_prev_f[m] THEN RECALC_METER_K_FACTOR(m, temperature_f[m]) END IF { Apply calibration factor } flow_measured_bopd[m] = flow_measured_bopd[m] × meter_k_factor[m] END FOR { === MASS BALANCE CHECK === } mass_balance_input_bopd = SUM(flow_measured_bopd[1..2]) { sources } mass_balance_output_bopd = SUM(flow_measured_bopd[3..4]) { sinks } unaccounted_loss_pct = ABS((mass_balance_input - mass_balance_output) / mass_balance_input) × 100 { === LEAK DETECTION LOGIC === } IF unaccounted_loss_pct > ACCEPTABLE_LOSS_PCT THEN { Possible leak; need to localize } leak_detected = TRUE { Segment 1: wellhead to mid1 } segment_1_loss = ABS(flow_measured_bopd[1] − flow_measured_bopd[2]) segment_1_loss_pct = (segment_1_loss / flow_measured_bopd[1]) × 100 { Segment 2: mid1 to mid2 } segment_2_loss = ABS(flow_measured_bopd[2] − flow_measured_bopd[3]) segment_2_loss_pct = (segment_2_loss / flow_measured_bopd[2]) × 100 { Segment 3: mid2 to export } segment_3_loss = ABS(flow_measured_bopd[3] − flow_measured_bopd[4]) segment_3_loss_pct = (segment_3_loss / flow_measured_bopd[3]) × 100 { Find which segment is losing most } IF segment_1_loss_pct > LEAK_ALARM_THRESHOLD_PCT THEN leak_location_segment = "WELLHEAD_TO_MID1" leak_severity = CRITICAL ELSIF segment_2_loss_pct > LEAK_ALARM_THRESHOLD_PCT THEN leak_location_segment = "MID1_TO_MID2" leak_severity = MAJOR ELSIF segment_3_loss_pct > LEAK_ALARM_THRESHOLD_PCT THEN leak_location_segment = "MID2_TO_EXPORT" leak_severity = MODERATE ELSE { No single segment shows >2%, but total is high } { Possible distributed weeping or meter errors } leak_location_segment = "DISTRIBUTED_OR_METERING" leak_severity = MINOR END IF Log_Alarm("LEAK_DETECTED", segment=leak_location_segment, loss_pct=unaccounted_loss_pct) ELSE leak_detected = FALSE END IF { === PRESSURE PROFILE ANALYSIS === } { If pressure drops sudden between two meters, likely restriction or small rupture } FOR m = 1 TO NUM_METERS − 1 DO pressure_drop_psi = pressure_psi[m] − pressure_psi[m+1] expected_drop_psi = Get_Expected_Pressure_Drop(m, flow_measured_bopd[m]) IF pressure_drop_psi > expected_drop_psi × 1.2 THEN { 20% higher than expected } Log_Warning("ABNORMAL_PRESSURE_DROP_SEGMENT_" + STR(m), measured_drop=pressure_drop_psi, expected=expected_drop_psi) END IF END FOR { === METER DRIFT DETECTION === } { Over 2 hours, meter output should be stable ±0.5% } IF MOD(scan_count, 240) = 0 THEN { every 2 hours } FOR m = 1 TO NUM_METERS DO hourly_avg = Average(flow_measured_bopd[m], last_60_minutes) hourly_drift_pct = ABS(flow_measured_bopd[m] − hourly_avg) / hourly_avg × 100 IF hourly_drift_pct > 5 THEN { >5% swing } Log_Warning("METER_DATA_NOISY_OR_INSTABLE", meter=m, drift_pct=hourly_drift_pct) END IF END FOR END IF { === LOGGING === } IF MOD(scan_count, 60) = 0 THEN { every 1 hr } Log_Process_Data({ timestamp: Get_Timestamp(), flow_bopd: flow_measured_bopd[], pressure_psi: pressure_psi[], temperature_f: temperature_f[], mass_balance_loss_pct: unaccounted_loss_pct, leak_detected: leak_detected, leak_location: leak_location_segment }) END IF flow_prev_bopd[] := flow_measured_bopd[] END PROCEDURE ``` --- ## 4. Tag List ``` FLOW_METER_1_WELLHEAD_BOPD { source flow } FLOW_METER_2_MID1_BOPD { first check point } FLOW_METER_3_MID2_BOPD { second check point } FLOW_METER_4_EXPORT_BOPD { sink measurement } PRESSURE_SEGMENT_1_PSI { between meters 1 & 2 } TEMPERATURE_METER_1_F { for meter factor correction } MASS_BALANCE_INPUT_BOPD { total sourced } MASS_BALANCE_OUTPUT_BOPD { total exported } UNACCOUNTED_LOSS_PCT { leak indicator } LEAK_DETECTED { boolean alarm } LEAK_LOCATION_SEGMENT { geographic hint } METER_DRIFT_PCT { stability check } ``` --- ## 5. Alarm & Trip Matrix | **Condition** | **Severity** | **Action** | |---|---|---| | **Loss > 2%** | 🔴 CRIT | Leak localization; dispatch inspection | | **Pressure drop anomaly** | ⚠ WARN | Check segment; possible blockage | | **Meter drift >5%** | ⚠ WARN | Meter possibly fouled; schedule maintenance | --- **Document Version:** 1.0 **Last Updated:** 2026-04-13 **Status:** Ready for Production

More like this

Rate, comment, and get full access

Members can download files, rate contributions, and discuss fixes with the engineers who posted them — free.

Join the library