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

Wellhead Pressure Management & Production Optimization — Control Design

Shared by TSIMEREZIVO Team · 4 Oct 2026 · 39 views

# Oil & Gas Template: Wellhead Pressure Management & Production Optimization ## 1. Overview **Purpose:** Automatically regulate wellhead backpressure (tubing head pressure) to optimize production rate while protecting subsurface equipment and preventing sand production. Most oil/gas wells produce under pressure differential: reservoir pressure − tubing pressure = driving force for flow. Excessive backpressure → low production; too little backpressure → sand erosion + equipment damage. Goal: find the sweet spot (Pwh setpoint) that maximizes well flowrate while staying within equipment limits. **Industry Standards:** - API 14A (Subsurface Safety Valve Systems) - API 6A (Wellhead Equipment Specifications) - ASME B31.3 (Process Piping) - ISO 10418 (Oil & gas production piping — safety) - SPE (Society of Petroleum Engineers) Production Standards **Critical Constraints:** - **Tubing head pressure (Pwh):** typically 50–2000 psi; must stay within equipment working pressure rating - **Reservoir pressure (Pres):** declines over well life (primary, secondary, enhanced recovery phases) - **Production rate (Q):** driven by pressure drawdown: Q ∝ (Pres − Pwh) / (skin factor + friction loss) [Darcy flow] - **Sand production threshold:** if Pwh too low → drawdown >critical velocity → sand grains mobilize → production decline + erosion - **Liquid carryover:** high velocity can entrain free surfaces → liquid slugs up tubing → separator upsets - **Choke valve control:** choke (adjustable needle valve) is main Pwh adjustment; 0–100% opening typical - **Slugging:** inconsistent pressure/flow cycles; typically in wells with low productivity index or excessive liquid **Relevant Physics:** - **Capacity:** $Q = C_d × A \times \sqrt{2 × \Delta P / \rho}$ (choke valve flow; $C_d$ = discharge coefficient) - **Drawdown:** $(P_{res} - P_{wh}) = Q × (f × L/D + Skin)$ (pressure drop in well tubing) - **Sand critical velocity:** $v_c \approx 1.5 × \sqrt{D}$ (ft/sec; D = tubing diameter in inches; rule of thumb, varies by sand grain size) - **Production forecast:** daily decline rate ≈ 5–10% per month (primary depletion); stabilizes with secondary recovery --- ## 2. Control Philosophy **Challenge:** Wellhead pressure must adapt to: - Declining reservoir pressure (well gets "tired") - Changing surface conditions (temperature, back-pressure from downstream separation) - Well interventions (workover, water injection, acid stimulation) - Production targets (company may elect to restrict flow for economic reasons) Cannot simply set Pwh = constant and forget it. Solution: **adaptive setpoint optimization with constraints**. ``` LAYER 1: Reservoir Drawdown Estimator Inputs: Current production rate (Q), choke opening (%), tubing head pressure Model: Estimate current Pres from historical trend + decline curve Output: Estimated drawdown = Pres − Pwh LAYER 2: Production Rate Optimizer Input: Drawdown (from Layer 1) Logic: Compute optimal choke opening that maximizes Q while respecting: - Equipment Pwh limit (max 2000 psi) - Sand critical velocity (min velocity constraint) - Separator separator inlet pressure setpoint (min 100 psi for stable operation) Output: Target Pwh setpoint (adaptive) LAYER 3: Wellhead Pressure Controller (PID) Input: Measured Pwh (choke pressure transmitter) SP: From Layer 2 Output: Choke valve position (0–100%) Tuning: Conservative (avoid oscillation that causes slugging) LAYER 4: Safety Interlocks - Pressure > 2000 psi for >1 hour → close choke, alert - Production shutdown signal → full choke closure (safety) - Choke stuck (valve position mismatch) → alert technician ``` --- ## 3. Control Logic **Pseudocode: Wellhead Pressure & Production Optimization** ```pascal { === WELLHEAD PRESSURE & PRODUCTION MANAGEMENT === } { Adaptive backpressure control with reservoir decline tracking } PROCEDURE Wellhead_Pressure_Optimizer CONSTANTS TUBING_ID_INCHES = 2.875 { tubing inside diameter } TUBING_LENGTH_FT = 8000 { well depth } SKIN_FACTOR = 1.5 { dimensionless; flow obstruction } SAND_CRITICAL_VELOCITY_FPS = 4.2 { ft/sec; tubing-dependent } PWH_MAX_EQUIPMENT_PSI = 2000 { max allowable } PWH_MIN_SEPARATOR_PSI = 100 { inlet to separator } PWH_CURRENT_SETPOINT_PSI = 500 { initial guess } CHOKE_FULLY_OPEN_PCT = 100 CHOKE_FULLY_CLOSED_PCT = 0 CHOKE_MAX_OPENING_PCT = 95 { never full open — control authority } PID_KP = 0.05 { low; system lag is high } PID_KI = 0.001 PID_KD = 0.1 DECLINE_CURVE_NOMINAL_PCT_PER_MONTH = 0.08 { 8% decline rate } PRODUCTION_FORECAST_WINDOW_DAYS = 30 SLUG_DETECTION_THRESHOLD_PSI = 200 { pressure swing >200 psi = slugging } CHOKE_STEP_LIMIT_PCT_PER_MIN = 2 { max rate: 2% per minute } VARIABLES { Measured inputs } pwh_measured_psi : REAL { psi, tubing head pressure } choke_position_pct : REAL { %, valve opening (feedback) } choke_command_pct : REAL { %, desired position } production_rate_bopd : REAL { barrels of oil per day } separator_inlet_pressure_psi : REAL { downstream backpressure } tubing_temperature_f : REAL { °F } { Well state } reservoir_pressure_estimated_psi : REAL drawdown_current_psi : REAL { Pres − Pwh } skin_factor_effective : REAL { may change over time } { Controller state } pwh_setpoint_psi : REAL { adaptive target } pwh_setpoint_prev_psi : REAL { for rate limiting } pwh_error_psi : REAL pwh_error_integral : REAL { Optimization logic } production_rate_forecast_bopd : REAL choke_opening_optimal_pct : REAL { calculated from optimization } velocity_in_tubing_fps : REAL { flow speed (sand risk indicator) } slugging_detected : BOOLEAN { Safety & diagnostics } high_pressure_latch : BOOLEAN { tracks >2000 psi condition } production_target_bopd : REAL { operator-set desired rate } decline_curve_model : ARRAY[*] { historical points } alarms_active : ARRAY[*] OF STRING BEGIN { === SENSOR ACQUISITION === } pwh_measured_psi = Read_Tubing_Head_Pressure() { 0–3000 psi transmitter } choke_position_pct = Read_Choke_Position_Feedback() { %open } production_rate_bopd = Read_Oil_Production_Rate() { bopd } separator_inlet_pressure_psi = Read_Separator_Upstream_PRESSURE() tubing_temperature_f = Read_TUBING_TEMPERATURE() { === RESERVOIR PRESSURE ESTIMATION === } { Track historical production & pressure; fit decline curve } { Simplified: assume exponential decline } time_since_startup_days = Days_Since(well_startup_date) { Empirical decline model: Q(t) = Q_0 × e^(-D_nom × t) } { where D_nom ≈ 8% per month = 0.27% per day } forecast_rate_bopd = Initial_Production_Rate × EXP(-DECLINE_CURVE_NOMINAL_PCT_PER_MONTH / 30 × time_since_startup_days) { Estimate reservoir pressure from current + forecast } { Model: Pres = Pres_initial − decline_fraction × (Pres_initial − Pmin) } { Simplified: linear approximation over next 30 days } months_elapsed = time_since_startup_days / 30 cumulative_decline_pct = DECLINE_CURVE_NOMINAL_PCT_PER_MONTH × months_elapsed cumulative_decline_pct = MIN(cumulative_decline_pct, 0.95) { don't go below ~5% Pres } reservoir_pressure_estimated_psi = Initial_Reservoir_Pressure × (1 - cumulative_decline_pct) production_rate_forecast_bopd = forecast_rate_bopd APPEND decline_curve_model {timestamp, measured_rate, measured_pwh, est_pres} { === CALCULATE VELOCITY IN TUBING === } { Convert production to volume velocity } { 1 barrel = 42 gallons; convert bopd → ft³/min } tubing_area_sqin = π × (TUBING_ID_INCHES / 2)² tubing_area_sqft = tubing_area_sqin / 144 { 144 sq in per sq ft } velocity_in_tubing_fps = (production_rate_bopd × 42) / (1440 × tubing_area_sqft) { === SAND PRODUCTION RISK === } sand_risk_ratio = velocity_in_tubing_fps / SAND_CRITICAL_VELOCITY_FPS IF sand_risk_ratio > 1.0 THEN Log_Warning("SAND_PRODUCTION_RISK_VELOCITY_EXCEEDS_CRITICAL") { Recommend reduced drawdown } END IF { === CHOICE: Optimize Pwh for maximum production vs constrained mode === } { MODE A: Aggressive optimization (maximize recovery) } IF Production_Target_Is_Unconstrained THEN { Find choke opening that maximizes rate without violating constraints } { Grid search: iterate choke_pct from 10% to CHOKE_MAX_OPENING_PCT } best_production_bopd := 0 optimal_choke_pct := CHOKE_FULLY_CLOSED_PCT FOR choke_test_pct = 10 TO CHOKE_MAX_OPENING_PCT STEP 5 DO { Forecast Pwh for this choke setting (use flow model) } { Simplified: PWH ∝ (1 / choke_Cv)^2 × flow_rate } estimated_pwh_pct_change = (1 / (choke_test_pct / 100)) ^ 2 / Current_Pwh_Estimate pwh_forecast_at_test = Current_Pwh_Estimate × estimated_pwh_pct_change pwh_forecast_at_test = MAX(PWH_MIN_SEPARATOR_PSI, pwh_forecast_at_test) { Calculate drawdown } drawdown_test = reservoir_pressure_estimated_psi − pwh_forecast_at_test { Calculate production from Darcy } production_test = drawdown_test / (SKIN_FACTOR + friction_loss_coefficient) { Check constraints } velocity_test = (production_test × 42) / (1440 × tubing_area_sqft) IF pwh_forecast_at_test <= PWH_MAX_EQUIPMENT_PSI AND velocity_test <= SAND_CRITICAL_VELOCITY_FPS THEN IF production_test > best_production_bopd THEN best_production_bopd := production_test optimal_choke_pct := choke_test_pct END IF END IF END FOR pwh_setpoint_psi := Choke_Settings_To_Pwh_Curve(optimal_choke_pct) { MODE B: Constrained operation (e.g., market limitation) } ELSE { User specifies desired production target (bopd) } { Adjust Pwh to achieve that rate } target_drawdown = production_target_bopd × (SKIN_FACTOR + friction_loss) pwh_setpoint_psi = MAX(PWH_MIN_SEPARATOR_PSI, reservoir_pressure_estimated_psi − target_drawdown) END IF { === SLUGGING DETECTION & MITIGATION === } pwh_swing = MAX_Pwh_In_Last_20_Min − MIN_Pwh_In_Last_20_Min IF pwh_swing > SLUG_DETECTION_THRESHOLD_PSI THEN slugging_detected = TRUE Log_Warning("SLUGGING_DETECTED_PRESSURE_SWING_" + STR(pwh_swing) + "_PSI") { Mild slugging often cured by slight choke opening (reduce backpressure) } pwh_setpoint_psi = pwh_setpoint_psi − 50 { reduce by 50 psi } ELSE slugging_detected = FALSE END IF { === WELLHEAD PRESSURE FEEDBACK CONTROLLER === } pwh_error_psi = pwh_setpoint_psi − pwh_measured_psi pwh_error_integral = pwh_error_integral + pwh_error_psi pwh_error_integral = LIMIT(pwh_error_integral, -1000, 1000) pwh_error_derivative = pwh_error_psi − pwh_error_psi_prev { PID } pid_output = (PID_KP × pwh_error_psi) + (PID_KI × pwh_error_integral) + (PID_KD × pwh_error_derivative) { Convert PID to choke command (PID ∝ percent opening) } choke_command_pct_new = 50 + pid_output { 50% neutral, ±range = feedback } { Rate limiter: don't change choke >2% per minute } choke_step_allowed = CHOKE_STEP_LIMIT_PCT_PER_MIN × (Scan_Interval_Min / 1.0) IF ABS(choke_command_pct_new − choke_command_pct) > choke_step_allowed THEN choke_command_pct_new = choke_command_pct + SIGN(...) × choke_step_allowed END IF choke_command_pct = LIMIT(choke_command_pct_new, CHOKE_FULLY_CLOSED_PCT, CHOKE_MAX_OPENING_PCT) { === SAFETY INTERLOCKS === } CLEAR alarms_active { High pressure latch } IF pwh_measured_psi > PWH_MAX_EQUIPMENT_PSI THEN IF NOT high_pressure_latch THEN high_pressure_latch = TRUE Log_Alarm("TUBING_HEAD_PRESSURE_EXCEEDS_EQUIPMENT_LIMIT") high_pressure_timer := 0 END IF { If high pressure persists >1 hour, close choke completely } high_pressure_timer := high_pressure_timer + 1 IF high_pressure_timer > 60 THEN { 60 minutes } choke_command_pct := CHOKE_FULLY_CLOSED_PCT APPEND alarms_active "CRITICAL_PRESSURE_CHOKE_CLOSURE_INITIATED" END IF ELSE high_pressure_latch = FALSE END IF { Production shutdown signal (e.g., from topside operator) } IF Production_Shutdown_Command THEN choke_command_pct := CHOKE_FULLY_CLOSED_PCT Log_Event("PRODUCTION_SHUTDOWN_INITIATED") END IF { Choke position feedback mismatch (valve stuck) } choke_position_error = ABS(choke_command_pct − choke_position_pct) IF choke_position_error > 15 THEN { >15% discrepancy } Log_Warning("CHOKE_VALVE_STUCK_POSITION_MISMATCH_" + STR(choke_position_error)) END IF { === OUTPUT === } Write_Choke_Valve_Command(choke_command_pct) { === LOGGING & DIAGNOSTICS === } IF MOD(scan_count, 60) = 0 THEN { every 1 hour (assume 1 min scans) } Log_Process_Data({ timestamp: Get_Timestamp(), pwh_measured_psi: pwh_measured_psi, pwh_setpoint_psi: pwh_setpoint_psi, choke_position_pct: choke_position_pct, choke_command_pct: choke_command_pct, production_rate_bopd: production_rate_bopd, reservoir_pressure_est_psi: reservoir_pressure_estimated_psi, drawdown_psi: drawdown_current_psi, velocity_fps: velocity_in_tubing_fps, sand_risk_ratio: sand_risk_ratio, slugging_flag: slugging_detected, forecast_production_bopd: production_rate_forecast_bopd }) END IF pwh_error_psi_prev := pwh_error_psi pwh_setpoint_prev_psi := pwh_setpoint_psi END PROCEDURE ``` --- ## 4. Tag List ``` TUBING_HEAD_PRESSURE_PSI { psi, primary feedback } TUBING_HEAD_PRESSURE_SETPOINT_PSI { psi, adaptive target } CHOKE_POSITION_PCT { %, feedback } CHOKE_COMMAND_PCT { %, desired position } PRODUCTION_RATE_BOPD { barrels per day } RESERVOIR_PRESSURE_ESTIMATED_PSI { calculated from decline curve } DRAWDOWN_CURRENT_PSI { Pres − Pwh } VELOCITY_IN_TUBING_FPS { flow speed, sand risk indicator } SAND_RISK_RATIO { v_actual / v_critical } SEPARATOR_INLET_PRESSURE_PSI { downstream backpressure } TUBING_TEMPERATURE_F { °F } SLUGGING_DETECTED { boolean } PRODUCTION_FORECAST_BOPD_30D { forecast rate } DECLINE_CURVE_MODEL { historical trend data } ``` --- ## 5. Alarm & Trip Matrix | **Condition** | **Severity** | **Action** | |---|---|---| | **PWH > 2000 psi sustained** | 🔴 CRIT | Close choke; investigate overpressure cause | | **Sand risk ratio >1.0** | ⚠ WARN | Reduce drawdown (close choke slightly) | | **Slugging detected** | ⚠ WARN | Reduce PWH by 50 psi; smooth choke ramp | | **Choke position mismatch** | ⚠ WARN | Valve may be stuck; manual intervention | | **Production rate drop >20% (1 day)** | ⚠ WARN | Well decline or plugging; schedule inspection | --- ## 6. HMI Layout ``` ╔════════════════════════════════════════════════════════════════════╗ ║ WELLHEAD PRESSURE & PRODUCTION MANAGEMENT — Well-001 ║ ╚════════════════════════════════════════════════════════════════════╝ SYSTEM STATUS: [ OPTIMIZING PRODUCTION ] Target: 450 BOPD ┌─────────────────────────────────────────────────────────────────┐ │ TUBING HEAD PRESSURE CONTROL │ │ │ │ Setpoint: 520 psi (adaptive) │ │ Measured: 515 psi ✓ [████████████░░░░░░░░░░░░░░░░░░] │ │ Error: -5 psi (holding within deadband) │ │ Equipment Max: 2000 psi (current 25.8% of limit) │ │ │ │ Choke Position: 62% ✓ OPEN (command 61% feedback 62%) │ │ Choke Status: Normal ✓ (position error <5%) │ └─────────────────────────────────────────────────────────────────┘ ┌─────────────────────────────────────────────────────────────────┐ │ PRODUCTION & RESERVOIR STATE │ │ │ │ Current Production: 438 BOPD (target 450; close) │ │ 30-Day Forecast: 412 BOPD (6.0% decline) │ │ All-Time Peak: 580 BOPD (3 months ago) │ │ │ │ Estimated Res. Pressure: 2850 psi (declined from 3100 initial)│ │ Current Drawdown: 2335 psi (2850 − 515) │ │ Drawdown Limit: 2800 psi (safety margin) │ │ │ │ Flow Velocity in Tubing: 3.2 ft/sec ✓ OK │ │ Sand Critical Velocity: 4.2 ft/sec (ratio: 0.76 safe) │ │ Sand Production Risk: LOW ✓ │ └─────────────────────────────────────────────────────────────────┘ ┌─────────────────────────────────────────────────────────────────┐ │ SYSTEM CONDITIONS │ │ │ │ Well Depth: 8,000 ft │ │ Tubing Diameter: 2.875" ID │ │ Tubing Temperature: 185°F (normal for this well depth) │ │ Separator Inlet: 135 psi ✓ (minimum 100 psi) │ │ Slugging Status: NOT DETECTED ✓ │ └─────────────────────────────────────────────────────────────────┘ 30-DAY PRODUCTION TREND: ┌─────────────────────────────────────────────────────────────────┐ │ BOPD PWH (psi) Choke (%open) │ │ 600 ┤ ╱╲ 2000 ┤ 100 ┤ │ │ 500 ┤ ╱ ╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 500 ┤ ───────────┐ 50 ┤────┐ │ │ 400 ┤ 200 ┤ ✓ STABLE \ ┤ │ │ └───────────────── └─────────────── └──────── │ │ 0 10 20 30 0 10 30 0 10 │ │ Declining per forecast Stable around SP Choke stable │ └─────────────────────────────────────────────────────────────────┘ CONTROL BUTTONS: [ Increase Setpoint 50 psi ] [ Decrease Setpoint 50 psi ] [ Manual Choke Control ] [ Emergency Shutdown ] [ View Decline Curve ] ``` --- ## 7. Configuration **JSON (wellhead_pressure_config.json)** ```json { "well": { "id": "Well-001", "location": "Field-A", "depth_ft": 8000, "tubing_id_inches": 2.875, "initial_reservoir_pressure_psi": 3100, "initial_production_rate_bopd": 580 }, "pressure_control": { "pwh_setpoint_base_psi": 500, "pwh_min_separator_psi": 100, "pwh_max_equipment_psi": 2000, "safety_margin_psi": 100 }, "pid_tuning": { "kp": 0.05, "ki": 0.001, "kd": 0.1, "rate_limit_choke_pct_per_min": 2 }, "production": { "sand_critical_velocity_fps": 4.2, "decline_rate_nominal_pct_per_month": 8, "skin_factor": 1.5 }, "alarms": { "pwh_max_psi": 2000, "slug_swing_threshold_psi": 200, "choke_position_error_threshold_pct": 15, "production_drop_alert_pct": 20 } } ``` --- ## 8. Commissioning Checklist - [ ] Tubing head pressure transmitter (0–3000 psi) calibrated - [ ] Choke valve position feedback verified (0–100% stroke) - [ ] Production meter (oil flowmeter) calibrated & proven (±2% accuracy) - [ ] Separator inlet pressure transmitter installed - [ ] Temperature sensor (RTD or thermocouple) functional - [ ] Initial well test performed: measured flow vs. choke position (build pump curve analogue) - [ ] Decline curve baseline established: 14-day shut-in pressure buildup test - [ ] PID tuning: set Kp = 0.05; observe response; adjust if hunting observed - [ ] Sand production test: run at high velocity (~4 fps); examine produced fluid for sand grains - [ ] 30-day monitoring: log all parameters; verify forecast accuracy - [ ] Operator training: setpoint adjustment, emergency shutdown, manual choke control --- **Document Version:** 1.0 **Last Updated:** 2026-04-13 **Status:** Ready for Production **Approval:** Petroleum Engineering & Production Operations (pending)

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