# Threaded flange

ASME B16.5 threaded (screwed) flange with an ASME B1.20.1 NPT taper thread through the hub (11.5 or 8 threads per inch by size, 1:16 taper) and a 45° entry chamfer. The pipe is made up power-tight with two threads showing at the hub end; optional seal weld. RF / FF / RTJ facing, real bolt holes. Where B16.5 has no threaded flange (Class 1500 above NPS 2-1/2, Class 2500 above NPS 12), the next lower class that has one is used.

**Standards:** ASME B16.5, ASME B1.20.1, ASME B31.3

## Installation

```bash
npx -y https://decktwin.com/cli/deck-twin-0.2.2.tgz add threaded-flange
```

Copies `piping/threaded-flange.tsx`, any helper files it imports and the shared `lib/` into `src/components/deck-twin/`. Needs `three`, `@react-three/fiber` and `@react-three/drei`.

## Usage

```tsx
import { Canvas } from '@react-three/fiber'
import { OrbitControls } from '@react-three/drei'
import { Stage } from './components/deck-twin/lib/stage'
import { ThreadedFlange } from './components/deck-twin/piping/threaded-flange'

export default function Scene() {
  return (
    <Canvas shadows camera={{ position: [8, 5, 9], fov: 35 }}>
      <Stage>
        <ThreadedFlange />
      </Stage>
      <OrbitControls makeDefault />
    </Canvas>
  )
}
```

## Props

| Prop | Type | Default | Range |
| --- | --- | --- | --- |
| `nps` | `number (NPS, in)` | `2` |  |
| `rating` | `150 \| 300 \| 600 \| 900 \| 1500 \| 2500` | `300` |  |
| `facing` | `"RF" \| "FF" \| "RTJ"` | `"RF"` |  |
| `schedule` | `"40" \| "80" \| "160" \| "XXS"` | `"80"` |  |
| `stub` | `number (m)` | `0.15` | 0 – 0.6 |
| `sealWeld` | `boolean` | `false` |  |
| `tag` | `string` | `""` |  |
| `...group` | position, rotation, scale… |  |  |

## Ports

Flange faces in the component's local frame, metres. Origin: pipe centreline, flow along X.

| Id | Label | Position | Direction | Size | Class |
| --- | --- | --- | --- | --- | --- |
| `A` | Flange face | 0.000, 0.000, 0.000 | -1, 0, 0 | 2" | 300 |

## P&ID

In section: a flange with a short hub and thread marks (zig-zag) in the bore where the pipe screws in, sometimes with a seal weld. On P&IDs a short bar, usually on utility or small-bore lines.

tag THD · tag SCRD · ASME B16.5 flange types drawn in half-section (GA / isometric detail convention); on P&IDs every flange is a short bar; ASME B1.20.1 NPT

Zig-zag thread lines in the bore identify it. Most offshore hydrocarbon piping classes do not allow threaded joints; expect it on utility water or air.

Piping class / flange bill of materials (ASME B16.5, B1.20.1) fields and the props they set:

| Field | Prop |
| --- | --- |
| Nominal size | `nps` |
| Pressure class | `rating` |
| Facing | `facing` |
| Pipe schedule | `schedule` |
| Seal weld | `sealWeld` |
| Tag number | `tag` |

## Typical suppliers

All Metals & Forge Group. The geometry is generic and sized from public standards. It is not vendor CAD.

## Source

`piping/threaded-flange.tsx`. This is the component file only: it imports shared code, so install it with the command above rather than pasting it alone. https://decktwin.com/r/threaded-flange.json has every file.

```tsx
// Threaded flange: ASME B16.5 flange with ASME B1.20.1 NPT internal thread, entry chamfer, screwed pipe and optional seal weld.
import type { Kit } from '../lib/kit'
import { KitMesh, useKit, type GroupProps } from '../lib/mesh'
import { port, type Port } from '../lib/ports'
import { inch, pipeOD, type Rating, type Schedule } from '../lib/standards'
import { definedRating, facingHeight, filletWeld, looseFlange, marking, nptTpi, pipeStub, type Facing } from './_flanges'

export interface ThreadedFlangeProps {
  /** nominal pipe size, inches (1/2–24; 1/2–2-1/2 in Class 1500, to 12 in Class 2500) */
  nps?: number
  rating?: Rating
  facing?: Facing
  schedule?: Schedule
  /** pipe screwed into the flange, m (0 for the bare flange) */
  stub?: number
  /** seal weld at the hub end (B31.3 practice for hydrocarbon service) */
  sealWeld?: boolean
  tag?: string
}

export const defaults = { nps: 2, rating: 300 as Rating, facing: 'RF' as Facing, schedule: '80' as Schedule, stub: 0.15, sealWeld: false, tag: '' }

// Port A is the gasket face at the origin, pointing -X; the threaded bore opens along +X.
export function ports(p: ThreadedFlangeProps = {}): Port[] {
  const { nps, rating } = { ...defaults, ...p }
  const n = Math.min(nps, 24)
  return [port('A', 'Flange face', [0, 0, 0], [-1, 0, 0], n, definedRating('THD', n, rating))]
}

export function ThreadedFlange({ nps = defaults.nps, rating = defaults.rating, facing = defaults.facing, schedule = defaults.schedule, stub = defaults.stub, sealWeld = defaults.sealWeld, tag = defaults.tag, ...group }: ThreadedFlangeProps & GroupProps) {
  const data = useKit((k) => build(k, Math.min(nps, 24), definedRating('THD', Math.min(nps, 24), rating), facing, schedule, Math.max(0, stub), sealWeld, tag), [nps, rating, facing, schedule, stub, sealWeld, tag])
  return (
    <group {...group}>
      <KitMesh data={data} />
    </group>
  )
}

export default ThreadedFlange

function build(k: Kit, nps: number, rating: Rating, facing: Facing, schedule: Schedule, stub: number, sealWeld: boolean, tag: string) {
  const h = facingHeight(facing, nps, rating)
  const base: [number, number, number] = [h, 0, 0]
  const dir: [number, number, number] = [-1, 0, 0]
  const i = looseFlange(k, base, dir, { kind: 'THD', nps, rating, facing, schedule, marking: tag || marking('THD', nps, rating, facing, 'NPT') })
  if (stub <= 0) return
  // pipe made up power-tight: engaged most of the hub, two threads left showing at the hub end
  const pitch = 0.0254 / nptTpi(nps)
  const L2 = inch((0.8 * (pipeOD(nps) / 0.0254) + 6.8) / nptTpi(nps))
  const engage = Math.min(i.Y - 0.004, L2 - 2 * pitch)
  const yEnd = -i.Y + engage
  pipeStub(k, [h - yEnd, 0, 0], [1, 0, 0], engage + stub, nps, schedule, 'thread', 'bevel')
  if (sealWeld) filletWeld(k, base, dir, pipeOD(nps) / 2, -i.Y, Math.max(0.004, pitch * 3))
}
```
