# Lap-joint flange and stub end

Loose ASME B16.5 lap-joint backing flange on a stainless stub end. The flange is flat with a radiused bore edge so it clears the stub-end fillet and turns freely to line up the bolt holes. The stub end is B16.9 long pattern or MSS SP-43 short pattern, with its lap diameter matched to the raised face. The serrated lap face is the gasket face (port A). An optional pipe can be butt-welded on.

**Standards:** ASME B16.5, ASME B16.9, MSS SP-43, ASME B16.25

## Installation

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

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

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

## Props

| Prop | Type | Default | Range |
| --- | --- | --- | --- |
| `nps` | `number (NPS, in)` | `6` |  |
| `rating` | `150 \| 300 \| 600 \| 900 \| 1500 \| 2500` | `150` |  |
| `schedule` | `"5S" \| "10S" \| "40S" \| "80S" \| "40" \| "80"` | `"10S"` |  |
| `pattern` | `"long" \| "short"` | `"long"` |  |
| `stub` | `number (m)` | `0` | 0 – 1 |
| `backing` | `"carbon" \| "galvanised"` | `"carbon"` |  |
| `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` | Lap face | 0.000, 0.000, 0.000 | -1, 0, 0 | 6" | 150 |

## P&ID

In section: a stub end (pipe with a flared lap at the face) with a loose backing flange sitting behind the lap, not welded to the pipe. On P&IDs a short bar like any flange.

tag LJ · ASME B16.5 flange types drawn in half-section (GA / isometric detail convention); on P&IDs every flange is a short bar; MSS SP-43 stub end

The loose ring behind a lap identifies it. Used on stainless or alloy lines where the backing flange can be carbon steel, and where bolt holes must be lined up after welding.

Piping class / flange bill of materials (ASME B16.5, MSS SP-43) fields and the props they set:

| Field | Prop |
| --- | --- |
| Nominal size | `nps` |
| Pressure class | `rating` |
| Stub-end schedule | `schedule` |
| Stub-end pattern | `pattern` |
| Backing flange material | `backing` |
| Tag number | `tag` |

## Source

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

```tsx
// Lap-joint flange: ASME B16.5 loose backing flange with radiused bore on an ASME B16.9 long-pattern or MSS SP-43 short-pattern stub end.
import type { Kit } from '../lib/kit'
import { KitMesh, useKit, type GroupProps } from '../lib/mesh'
import { port, type Port } from '../lib/ports'
import { pipeOD, pipeWall, type Rating, type Schedule } from '../lib/standards'
import { buttWeld, looseFlange, marking, pipeStub, stubEndGeo } from './_flanges'

export interface LapJointFlangeProps {
  /** nominal pipe size, inches (1/2–24) */
  nps?: number
  rating?: Rating
  /** stub-end wall schedule */
  schedule?: Schedule
  /** stub-end pattern: B16.9 long or MSS SP-43 short */
  pattern?: 'long' | 'short'
  /** pipe butt-welded to the stub end, m */
  stub?: number
  /** backing flange material: carbon steel or painted (stub end stays alloy) */
  backing?: 'carbon' | 'galvanised'
  tag?: string
}

export const defaults = { nps: 6, rating: 150 as Rating, schedule: '10S' as Schedule, pattern: 'long' as const, stub: 0, backing: 'carbon' as const, tag: '' }

// Port A is the lap face of the stub end at the origin, pointing -X.
export function ports(p: LapJointFlangeProps = {}): Port[] {
  const { nps, rating } = { ...defaults, ...p }
  return [port('A', 'Lap face', [0, 0, 0], [-1, 0, 0], Math.min(nps, 24), rating)]
}

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

export default LapJointFlange

function build(k: Kit, nps: number, rating: Rating, schedule: Schedule, pattern: 'long' | 'short', stub: number, backing: 'carbon' | 'galvanised', tag: string) {
  const dir: [number, number, number] = [-1, 0, 0]
  // stainless stub end carries the gasket; the loose flange only bolts it up
  const s = stubEndGeo(k, [0, 0, 0], dir, nps, schedule, pattern, 'stainless')
  looseFlange(k, [s.wt + 0.0005, 0, 0], dir, { kind: 'LJ', nps, rating, facing: 'FF', schedule, mat: backing === 'galvanised' ? 'galvanised' : 'flangeSteel', marking: tag || marking('LJ', nps, rating, 'FF') })
  if (stub > 0) {
    pipeStub(k, [s.L, 0, 0], [1, 0, 0], stub, nps, schedule, 'open', 'bevel', 'stainless')
    buttWeld(k, [s.L, 0, 0], [1, 0, 0], pipeOD(nps) / 2, pipeWall(nps, schedule))
  }
}
```
