An industrial-grade Pressure Safety Valve engineering workbench — real fluid properties (NIST-quality EOS), a full overpressure-scenario engine, auto-generated engineering drawings, and client-ready HTML / PDF / Excel deliverables.
Built and maintained by Tahir Yamin
↑ This engineering drawing is not a static image — ReliefCraft draws it from the live calculation results on every run.
- ✨ Highlights
- 📄 Deliverables
- 🎮 Interactive Dashboard
- 🚀 Quick Start
- 🗂️ Repository Layout
- 📖 API Naming Conventions
- ✅ Verification
⚠️ Engineering Disclaimer
| Capability | Standard | Detail |
|---|---|---|
| Gas/vapor sizing | API 520 Pt I §5.6 | Critical and sub-critical (F₂), Kb/Kc/Kd corrections |
| Liquid sizing | API 520 Pt I §5.8 | Certified capacity, Kᵥ viscosity correction |
| Steam sizing | API 520 Pt I §5.9 | Napier, Kₙ high-pressure + K_sh superheat (Table 9) |
| Two-phase flow | API 520 Annex C | Omega method (mass-flux maximization) + Leung subcooled flashing (high/low subcooling regions) |
| Scenario engine | API 521 §4.4 | Blocked outlet · CV failure · tube rupture · external fire · thermal expansion · utility/reflux failure — governing case auto-selected |
| Fire case | API 521 §4.4.13 | Q = C·F·A^0.82, adequate/inadequate drainage, F-factor library |
| Real fluid properties | NIST-quality EOS | CoolProp — MW, k, Z, ρ, μ, latent heat at actual relieving conditions. No more guessed Z-factors |
| Device rules | API 520 | Conventional / Balanced-bellows (Fig. 30 Kb curve) / Pilot-operated backpressure limits; rupture-disk Kc = 0.9 |
| Valve envelope | API 526 | Purchasable specs — e.g. 4P6, 300#×150# RF, SA-216 WCB — with class-availability validation |
| Materials | ASME B16.34 / VIII-1 | P-T rating interpolation (Groups 1.1/1.9/2.2, Class 150→2500), temperature-based material selection (LTCS, Ni-steel, Cr-Mo, SS), UG-27 shell thickness |
| Piping compliance | API 520 Pt II | 3% inlet rule (computed from geometry + fittings K-factors), built-up backpressure (Darcy-Weisbach / Swamee-Jain) |
| Mechanical effects | API 520 Pt II / API 521 | Reaction force at first elbow, noise at 30 m with silencer flag |
| Guardrails | — | Physically suspicious inputs flagged before sizing (Z out of range, BP ≥ set, impossible MW, …) |
- Visual HTML/PDF datasheet with revision block, and a full calculation audit trail (equation → substitution → result, checker-reviewable)
- Engineering drawings drawn from the live results — annotated installation schematic (pass/fail colored), API 526 orifice ladder, compliance margin gauges — all inline vector SVG
- Color-coded Excel compliance workbook for the whole valve list
- Project JSON save/load for study persistence
A live ipywidgets dashboard (works in Jupyter and Google Colab): pick a CoolProp fluid preset, drag set-pressure/temperature/flow sliders, switch Conventional/Bellows/Pilot device types, toggle a rupture disk, flip SI ⇄ US units — sizing, orifice selection, valve spec, noise, and all compliance badges update instantly.
- Click the badge ↑ (opens the notebook directly from this repo)
- Runtime → Run all. The first cell auto-installs everything (CoolProp, openpyxl, ipywidgets, chromium for PDF export).
git clone https://github.com/Tahir-yamin/ReliefCraft-API520.git
cd ReliefCraft-API520
pip install -r requirements.txt
jupyter lab PSV_Sizing_Compliance_Workspace.ipynbimport calculations.gas_sizing as gas
import utils.orifice_tables as orif
sz = gas.size_gas_vapor(W_kg_h=25_000, P1_bara=17.5, P2_bara=1.9,
T_k=393.15, Z=0.92, MW=22.0, k=1.25)
print(sz) # {'required_area_mm2': 2284.25, 'flow_regime': 'Critical', ...}
print(orif.select_orifice(sz['required_area_mm2'])) # {'designation': 'M', ...}├── PSV_Sizing_Compliance_Workspace.ipynb # the full workbench (66 cells, 10 sections)
├── calculations/
│ ├── gas_sizing.py # API 520 gas/vapor (critical + F2 sub-critical)
│ ├── liquid_steam_sizing.py # liquid (Kv), steam (Napier/Kn/Ksh), omega two-phase
│ ├── flashing.py # Leung subcooled flashing (API 520 Annex C)
│ ├── two_phase_sizing.py # HEM screening
│ ├── fire_case.py # API 521 fire heat input & vapor generation
│ ├── scenario_engine.py # API 521 §4.4 scenario loads + governing case
│ ├── relieving_conditions.py # overpressure/accumulation basis
│ ├── backpressure.py # Darcy-Weisbach tailpipe hydraulics
│ ├── piping_design.py # minimum inlet diameter (3% rule)
│ └── mechanical.py # reaction force, noise, inlet-line ΔP w/ fittings
├── utils/
│ ├── fluid_properties.py # CoolProp wrapper (gas/liquid/saturation/omega flash)
│ ├── correction_factors.py # Kb (Fig. 30), Ksh (Table 9)
│ ├── devices.py # conventional/bellows/pilot rules, rupture-disk Kc
│ ├── api526_valves.py # purchasable valve envelope
│ ├── orifice_tables.py # API 526 orifice areas D→T
│ ├── material_selection.py # ASME B16.34 P-T tables, B16.5 flanges, B16.20 gaskets
│ ├── validation.py # API 520 Pt II compliance checks
│ ├── guardrails.py # input sanity screening
│ ├── units.py # SI ⇄ US display layer
│ └── project_io.py # Excel export, PDF (headless browser), JSON persistence
├── report/
│ ├── report_generator.py # HTML datasheet w/ audit trail & revision block
│ └── drawings.py # auto-generated SVG schematics/ladders/gauges
├── examples/ # sample PDF, HTML and Excel outputs
└── docs/images/ # preview graphics
The standards family this project implements, and how the industry names things:
| Code | Full Name | What it Governs | Where in ReliefCraft |
|---|---|---|---|
| API 520 Part I | Sizing, Selection & Installation of Pressure-Relieving Devices — Sizing and Selection | Orifice sizing equations (gas, liquid, steam, two-phase), correction factors K_d, K_b, K_c, K_v, K_n, K_sh | calculations/gas_sizing.py, liquid_steam_sizing.py, flashing.py, utils/correction_factors.py |
| API 520 Part II | — Installation | 3% inlet-loss rule, built-up backpressure limits, reaction forces | utils/validation.py, calculations/mechanical.py |
| API 521 | Pressure-Relieving and Depressuring Systems | Overpressure scenarios (fire, blocked outlet, CV failure…), relief loads, flare/noise | calculations/scenario_engine.py, fire_case.py |
| API 526 | Flanged Steel Pressure-Relief Valves | Standard valve envelope: orifice letters, body sizes, flange classes | utils/api526_valves.py, orifice_tables.py |
| API 527 | Seat Tightness of PRVs | Leakage acceptance testing (out of scope — shop test) | — |
| ASME BPVC VIII Div 1 | Boiler & Pressure Vessel Code — Pressure Vessels | Set pressure/accumulation rules (UG-125…UG-137), shell thickness (UG-27) | calculations/relieving_conditions.py, utils/material_selection.py |
| ASME B16.34 / B16.5 / B16.20 | Valves / Flanges / Gaskets | Pressure-temperature ratings, flange dimensions, spiral-wound gaskets | utils/material_selection.py |
API 526 valves are named <inlet NPS> <orifice letter> <outlet NPS>:
4 P 6 , 300# × 150# RF , SA-216 WCB
│ │ │ │ │ │
│ │ │ │ │ └── body material (ASME spec)
│ │ │ │ └── outlet flange class (150#)
│ │ │ └── inlet flange class (300#)
│ │ └── outlet nominal pipe size: 6 inch
│ └── effective orifice letter: P (= 4116 mm² / 6.38 in²)
└── inlet nominal pipe size: 4 inch
| Letter | D | E | F | G | H | J | K | L | M | N | P | Q | R | T |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Area (in²) | 0.110 | 0.196 | 0.307 | 0.503 | 0.785 | 1.287 | 1.838 | 2.853 | 3.60 | 4.34 | 6.38 | 11.05 | 16.0 | 26.0 |
| Area (mm²) | 71 | 126 | 198 | 325 | 506 | 830 | 1186 | 1841 | 2323 | 2800 | 4116 | 7129 | 10323 | 16774 |
(No I, O, or S — skipped to avoid confusion with 1, 0, and 5.)
| Symbol | Name | Applied When |
|---|---|---|
| K_d | Discharge coefficient | Always (0.975 gas prelim., 0.65 liquid, 0.62 rupture disk alone) |
| K_b | Backpressure correction | Balanced bellows above ~30% backpressure (Fig. 30) |
| K_c | Combination correction | 0.9 with a rupture disk upstream of the PSV |
| K_v | Viscosity correction | Viscous liquids (Re-based, Fig. 36) |
| K_n | Napier correction | Steam above 1500 psig |
| K_sh | Superheat correction | Superheated steam (Table 9) |
The notebook carries its own proof: Section 4 runs 45+ assertion-based self-tests against known-good values (hand-checked mass fluxes, published Kb/Ksh points, B16.34 table values, Leung correlation η_c) before any design work is possible. The repository ships only after a full clean kernel execution — 33 code cells, zero errors.
✅ ALL SELF-VERIFICATION TESTS PASSED
✅ ALL v3 INDUSTRIAL MODULE TESTS PASSED
(CoolProp, Kb/Ksh, devices, envelope, guardrails, units, mechanical, flashing, scenarios)
This workspace implements textbook API/ASME equations for study and preliminary design. Final relief-device sizing must be performed/verified by a licensed professional engineer against the current editions of API 520/521/526, ASME BPVC, and manufacturer-certified data. Correction-factor curves (Kb, Ksh, noise) are digitized approximations of the published figures.
MIT © Tahir Yamin
If ReliefCraft saves you a sizing iteration, consider giving it a ⭐ — it helps other engineers find it.
Open in Colab · Report an issue · Tahir Yamin
ReliefCraft — because "the valve was too small" is never an acceptable incident report.

