# Flanged joint

Complete bolted flange joint: two weld-neck raised-face flanges, a spiral-wound gasket with inner ring and colour-coded centring ring, Xylan-coated B7 stud bolts with two 2H nuts each, short bevelled pipe stubs and a joint-integrity tag. Any ASME B16.5 / B16.47 Series A size and class.

**Standards:** ASME B16.5, ASME B16.47, ASME B16.20, ASME PCC-1, ASTM A193 B7

## Installation

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

Copies `piping/flanged-joint.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 { FlangedJoint } from './components/deck-twin/piping/flanged-joint'

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

## Props

| Prop | Type | Default | Range |
| --- | --- | --- | --- |
| `nps` | `number (NPS, in)` | `6` |  |
| `rating` | `150 \| 300 \| 600 \| 900 \| 1500 \| 2500` | `300` |  |
| `schedule` | `"10" \| "20" \| "40" \| "STD" \| "80" \| "XS" \| "160" \| "XXS" \| "10S" \| "40S" \| "80S"` | `"40"` |  |
| `stub` | `number (m)` | `0.15` | 0 – 1 |
| `tag` | `string` | `"J-101"` |  |
| `...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` | End A (weld end) | -0.251, 0.000, 0.000 | -1, 0, 0 | 6" | – |
| `B` | End B (weld end) | 0.251, 0.000, 0.000 | 1, 0, 0 | 6" | – |

## P&ID

Two short parallel bars across the line (a flange pair), sometimes with a gap between them; at a nozzle only one bar is drawn against the equipment.

ISO 10628-2 / PIP PIC001 (piping)

Two bars with a filled or open paddle between them, or with a figure-8 drawn beside them on a short stem, is a spectacle blind or spade (not a plain joint); two bars with taps and an FE tag is an orifice flange pair. Spec breaks (class changes) are marked at a flange with the two class codes.

Piping class (ASME B16.5 / B16.47 flanges, B16.20 gaskets) fields and the props they set:

| Field | Prop |
| --- | --- |
| Nominal size | `nps` |
| Flange rating | `rating` |
| Wall schedule | `schedule` |
| Tag number | `tag` |

## Typical suppliers

Weldbend · Flexitallic. The geometry is generic and sized from public standards. It is not vendor CAD.

## Source

`piping/flanged-joint.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/flanged-joint.json has every file.

```tsx
// Bolted flange joint: pair of ASME B16.5 / B16.47 weld-neck RF flanges, B16.20 spiral-wound gasket, B7 / 2H stud bolts, pipe stubs and a joint tag.
import type { Kit } from '../lib/kit'
import { KitMesh, useKit, type GroupProps } from '../lib/mesh'
import { port, type Port } from '../lib/ports'
import type { Rating, Schedule } from '../lib/standards'
import { GAP, boreOf, buttWeld, flangeLength, jointStuds, jointTag, portFlange, spiralWound, straight } from './_piping'

export interface FlangedJointProps {
  nps?: number
  rating?: Rating
  schedule?: Schedule
  /** pipe stub beyond each weld neck, m (0 = weld ends at the hubs) */
  stub?: number
  /** bolt-tensioning / joint integrity tag, empty for none */
  tag?: string
}

export const defaults = { nps: 6, rating: 300 as Rating, schedule: '40' as Schedule, stub: 0.15, tag: 'J-101' }

const half = (nps: number, rating: Rating, stub: number) => GAP / 2 + flangeLength(nps, rating) + Math.max(0, stub)

export function ports(p: FlangedJointProps = {}): Port[] {
  const { nps, rating, stub } = { ...defaults, ...p }
  const x = half(nps, rating, stub)
  return [port('A', 'End A (weld end)', [-x, 0, 0], [-1, 0, 0], nps), port('B', 'End B (weld end)', [x, 0, 0], [1, 0, 0], nps)]
}

export function FlangedJoint({ nps = defaults.nps, rating = defaults.rating, schedule = defaults.schedule, stub = defaults.stub, tag = defaults.tag, ...group }: FlangedJointProps & GroupProps) {
  const data = useKit((k) => build(k, nps, rating, schedule, Math.max(0, stub), tag), [nps, rating, schedule, stub, tag])
  return (
    <group {...group}>
      <KitMesh data={data} />
    </group>
  )
}

export default FlangedJoint

function build(k: Kit, nps: number, rating: Rating, schedule: Schedule, stub: number, tag: string) {
  const fl = flangeLength(nps, rating)
  const w = GAP / 2 + fl
  for (const s of [-1, 1]) {
    portFlange(k, nps, rating, [(s * GAP) / 2, 0, 0], [-s, 0, 0], { studs: false, bore: boreOf(nps, schedule) })
    if (stub > 0) {
      straight(k, 'pipePaint', [s * w, 0, 0], [s, 0, 0], stub, nps, schedule, 'open', 'bevel')
      buttWeld(k, nps, [s * w, 0, 0], [1, 0, 0])
    }
  }
  spiralWound(k, nps, rating, [0, 0, 0], [1, 0, 0])
  jointStuds(k, nps, rating, [0, 0, 0], [1, 0, 0])
  if (tag) jointTag(k, nps, rating, tag)
}
```
