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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import math
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
st.set_page_config(page_title="UG-37 Nozzle Reinforcement Calculator", layout="wide")
|
| 8 |
+
|
| 9 |
+
st.title("UG-37 Nozzle Reinforcement Calculator — Streamlit (Hugging Face)")
|
| 10 |
+
st.caption("This app is a developer-ready skeleton: calculation hooks are provided.\nIMPORTANT: replace the placeholder formulas with the official UG-37 formulas from the ASME Code before using for design.")
|
| 11 |
+
|
| 12 |
+
# ---------------------------
|
| 13 |
+
# Helpers
|
| 14 |
+
# ---------------------------
|
| 15 |
+
|
| 16 |
+
def to_si_length(val, unit):
|
| 17 |
+
# convert inches to mm if needed
|
| 18 |
+
if unit == 'in':
|
| 19 |
+
return val * 25.4
|
| 20 |
+
return val
|
| 21 |
+
|
| 22 |
+
def to_si_pressure(val, unit):
|
| 23 |
+
# convert psi to MPa
|
| 24 |
+
if unit == 'psi':
|
| 25 |
+
return val * 0.00689476
|
| 26 |
+
return val
|
| 27 |
+
|
| 28 |
+
# Placeholder: conservative demo required-area formula for internal pressure
|
| 29 |
+
# *** DO NOT USE FOR DESIGN. Replace with UG-37(c) exact formula. ***
|
| 30 |
+
def required_area_internal_demo(P, d, S, F=1.0):
|
| 31 |
+
# very conservative demo: required area proportional to pressure * diameter / allowable stress
|
| 32 |
+
# Units: P in MPa, d in mm, S in MPa -> result in mm^2
|
| 33 |
+
# Formula (demo): A_req = F * (P * d) / S * 1000
|
| 34 |
+
return F * (P * d) / S * 1000.0
|
| 35 |
+
|
| 36 |
+
# Placeholder: demo external pressure formula
|
| 37 |
+
def required_area_external_demo(P_ext, d, S, F=1.0):
|
| 38 |
+
# external pressure often more critical; demo uses same shape
|
| 39 |
+
return F * (abs(P_ext) * d) / S * 1200.0
|
| 40 |
+
|
| 41 |
+
# Simple available-area calculators (geometric approximations)
|
| 42 |
+
def calc_A1(Do, tn, d):
|
| 43 |
+
# A1 — area of shell material around the opening (approx):
|
| 44 |
+
# approximate annulus area associated with thickness tn over an effective ring width = tn
|
| 45 |
+
# This is a placeholder conservative estimate: area = circumference * tn * tn
|
| 46 |
+
ring_width = tn
|
| 47 |
+
circumference = math.pi * Do
|
| 48 |
+
return circumference * ring_width
|
| 49 |
+
|
| 50 |
+
def calc_A2_pad(d, pad_OD, pad_t):
|
| 51 |
+
# A2 — pad area contribution (approx) = pad ring area (projected radial area)
|
| 52 |
+
if pad_OD is None:
|
| 53 |
+
return 0.0
|
| 54 |
+
return math.pi * ( (pad_OD/2)**2 - (d/2)**2 ) * (pad_t / (pad_t + 1e-9))
|
| 55 |
+
|
| 56 |
+
def calc_A_welds(perimeter, leg, include_welds):
|
| 57 |
+
if not include_welds:
|
| 58 |
+
return 0.0
|
| 59 |
+
# approximate weld throat area = perimeter * leg
|
| 60 |
+
return perimeter * leg
|
| 61 |
+
|
| 62 |
+
# ---------------------------
|
| 63 |
+
# Sidebar inputs
|
| 64 |
+
# ---------------------------
|
| 65 |
+
with st.sidebar.form('settings'):
|
| 66 |
+
st.header('Global settings')
|
| 67 |
+
units = st.selectbox('Units system', ['SI (mm, MPa)', 'Imperial (in, psi)'])
|
| 68 |
+
unit_len = 'mm' if units.startswith('SI') else 'in'
|
| 69 |
+
unit_pres = 'MPa' if units.startswith('SI') else 'psi'
|
| 70 |
+
include_welds = st.checkbox('Include weld areas in available reinforcement', value=False)
|
| 71 |
+
f_mode = st.selectbox('F-factor mode', ['Figure UG-37 lookup (manual entry)', 'Force F = 1.0'])
|
| 72 |
+
if f_mode.startswith('Figure'):
|
| 73 |
+
F_val = st.number_input('F factor (enter value from Figure UG-37)', min_value=0.01, value=1.0, format='%.3f')
|
| 74 |
+
else:
|
| 75 |
+
F_val = 1.0
|
| 76 |
+
demo_mode = st.checkbox('Run demo (placeholder formulas) — DO NOT USE FOR DESIGN', value=True)
|
| 77 |
+
st.form_submit_button('Apply')
|
| 78 |
+
|
| 79 |
+
# ---------------------------
|
| 80 |
+
# Main inputs
|
| 81 |
+
# ---------------------------
|
| 82 |
+
st.header('Inputs')
|
| 83 |
+
col1, col2 = st.columns(2)
|
| 84 |
+
with col1:
|
| 85 |
+
st.subheader('Vessel / Shell')
|
| 86 |
+
Do = st.number_input(f'Vessel diameter (Do) [{unit_len}]', value=1000.0)
|
| 87 |
+
tn = st.number_input(f'Shell thickness (tn) [{unit_len}]', value=10.0)
|
| 88 |
+
vessel_type = st.selectbox('Vessel type', ['cylinder', 'cone', 'sphere'])
|
| 89 |
+
P_internal = st.number_input(f'Design internal pressure [{unit_pres}]', value=0.5)
|
| 90 |
+
P_external = st.number_input(f'Design external pressure (use negative for vacuum) [{unit_pres}]', value=0.0)
|
| 91 |
+
S_allow = st.number_input('Allowable stress S [MPa]', value=138.0)
|
| 92 |
+
|
| 93 |
+
with col2:
|
| 94 |
+
st.subheader('Nozzle / Opening')
|
| 95 |
+
d = st.number_input(f'Nozzle inside diameter (d) [{unit_len}]', value=150.0)
|
| 96 |
+
tn_nozzle = st.number_input(f'Nozzle neck thickness [{unit_len}]', value=6.0)
|
| 97 |
+
projection = st.number_input(f'Projection (length) [{unit_len}]', value=30.0)
|
| 98 |
+
pad_yes = st.checkbox('Reinforcing pad present', value=False)
|
| 99 |
+
pad_OD = None
|
| 100 |
+
pad_t = None
|
| 101 |
+
pad_weld_leg = 0.0
|
| 102 |
+
if pad_yes:
|
| 103 |
+
pad_OD = st.number_input(f'Pad OD [{unit_len}]', value=250.0)
|
| 104 |
+
pad_t = st.number_input(f'Pad thickness [{unit_len}]', value=8.0)
|
| 105 |
+
pad_weld_leg = st.number_input('Pad weld leg length (effective) [mm or in]', value=4.0)
|
| 106 |
+
split_pad = st.checkbox('Split pad (apply 0.75 multiplier to A5)', value=False)
|
| 107 |
+
orientation = st.selectbox('Location / orientation', ['axial (longitudinal)', 'circumferential', 'oblique'])
|
| 108 |
+
orientation_angle = None
|
| 109 |
+
if orientation == 'oblique':
|
| 110 |
+
orientation_angle = st.number_input('Orientation angle (deg)', min_value=0.0, max_value=90.0, value=45.0)
|
| 111 |
+
|
| 112 |
+
# Unit conversions to internal SI mm/MPa for calculation convenience
|
| 113 |
+
if units.startswith('Imperial'):
|
| 114 |
+
Do_si = to_si_length(Do, 'in')
|
| 115 |
+
d_si = to_si_length(d, 'in')
|
| 116 |
+
tn_si = to_si_length(tn, 'in')
|
| 117 |
+
tn_nozzle_si = to_si_length(tn_nozzle, 'in')
|
| 118 |
+
pad_OD_si = to_si_length(pad_OD, 'in') if pad_OD is not None else None
|
| 119 |
+
pad_t_si = to_si_length(pad_t, 'in') if pad_t is not None else None
|
| 120 |
+
P_internal_si = to_si_pressure(P_internal, 'psi')
|
| 121 |
+
P_external_si = to_si_pressure(P_external, 'psi')
|
| 122 |
+
pad_weld_leg_si = to_si_length(pad_weld_leg, 'in') if pad_weld_leg is not None else 0.0
|
| 123 |
+
else:
|
| 124 |
+
Do_si = Do
|
| 125 |
+
d_si = d
|
| 126 |
+
tn_si = tn
|
| 127 |
+
tn_nozzle_si = tn_nozzle
|
| 128 |
+
pad_OD_si = pad_OD
|
| 129 |
+
pad_t_si = pad_t
|
| 130 |
+
P_internal_si = P_internal
|
| 131 |
+
P_external_si = P_external
|
| 132 |
+
pad_weld_leg_si = pad_weld_leg
|
| 133 |
+
|
| 134 |
+
# ---------------------------
|
| 135 |
+
# Calculations
|
| 136 |
+
# ---------------------------
|
| 137 |
+
st.header('Calculations')
|
| 138 |
+
if demo_mode:
|
| 139 |
+
A_req_int = required_area_internal_demo(P_internal_si, d_si, S_allow, F=F_val)
|
| 140 |
+
A_req_ext = required_area_external_demo(P_external_si, d_si, S_allow, F=F_val) if P_external_si != 0 else 0.0
|
| 141 |
+
else:
|
| 142 |
+
A_req_int = None
|
| 143 |
+
A_req_ext = None
|
| 144 |
+
|
| 145 |
+
A1 = calc_A1(Do_si, tn_si, d_si)
|
| 146 |
+
A2 = calc_A2_pad(d_si, pad_OD_si, pad_t_si) if pad_yes else 0.0
|
| 147 |
+
perimeter = math.pi * d_si
|
| 148 |
+
A_weld = calc_A_welds(perimeter, pad_weld_leg_si, include_welds)
|
| 149 |
+
|
| 150 |
+
# A5 placeholder: pad projection/tangential contribution
|
| 151 |
+
A5 = A2
|
| 152 |
+
if split_pad:
|
| 153 |
+
A5 = 0.75 * A5
|
| 154 |
+
|
| 155 |
+
A_avail = A1 + A2 + A_weld
|
| 156 |
+
|
| 157 |
+
# Governing required area
|
| 158 |
+
if A_req_ext and A_req_ext > A_req_int:
|
| 159 |
+
A_req = A_req_ext
|
| 160 |
+
governing = 'External pressure (UG-37(d))'
|
| 161 |
+
else:
|
| 162 |
+
A_req = A_req_int
|
| 163 |
+
governing = 'Internal pressure (UG-37(c))'
|
| 164 |
+
|
| 165 |
+
# ---------------------------
|
| 166 |
+
# Results
|
| 167 |
+
# ---------------------------
|
| 168 |
+
st.subheader('Summary')
|
| 169 |
+
colr1, colr2 = st.columns([1,2])
|
| 170 |
+
with colr1:
|
| 171 |
+
if A_req is None:
|
| 172 |
+
st.warning('Required-area formula not implemented. App is running in demo mode — results are NOT code-validated.')
|
| 173 |
+
else:
|
| 174 |
+
pass
|
| 175 |
+
|
| 176 |
+
with colr2:
|
| 177 |
+
st.markdown(f"**Governing case:** {governing}")
|
| 178 |
+
st.markdown(f"**Required reinforcement area (A_req)**: {A_req:,.1f} mm²")
|
| 179 |
+
st.markdown(f"**Available reinforcement area (A_avail)**: {A_avail:,.1f} mm²")
|
| 180 |
+
|
| 181 |
+
margin = None
|
| 182 |
+
if A_req and A_avail is not None:
|
| 183 |
+
margin = A_avail - A_req
|
| 184 |
+
pct = (margin / A_req * 100.0) if A_req != 0 else 0.0
|
| 185 |
+
if margin >= 0:
|
| 186 |
+
st.success(f'PASS — Margin = {margin:,.1f} mm² ({pct:.1f}%)')
|
| 187 |
+
else:
|
| 188 |
+
st.error(f'FAIL — Shortfall = {abs(margin):,.1f} mm² ({pct:.1f}%)')
|
| 189 |
+
|
| 190 |
+
# Detailed table
|
| 191 |
+
st.subheader('Component breakdown (approximate / demo values)')
|
| 192 |
+
comp = pd.DataFrame({
|
| 193 |
+
'Component':['A1 - Shell material', 'A2 - Pad ring', 'A_weld - Weld contribution', 'A5 - Pad effective'],
|
| 194 |
+
'Area_mm2':[A1, A2, A_weld, A5]
|
| 195 |
+
})
|
| 196 |
+
st.dataframe(comp)
|
| 197 |
+
|
| 198 |
+
# Download results
|
| 199 |
+
st.subheader('Export')
|
| 200 |
+
buf = BytesIO()
|
| 201 |
+
comp.to_csv(buf, index=False)
|
| 202 |
+
buf.seek(0)
|
| 203 |
+
st.download_button('Download components CSV', buf, file_name='ug37_components.csv', mime='text/csv')
|
| 204 |
+
|
| 205 |
+
st.info('Reminder: This app is a skeleton/demo. Replace required-area functions with the official UG-37 formulas and verify against the ASME Code before using for design.')
|