# No. 421 (Brown 1868): "Trunk engine used for marine purposes. The piston has attached to it a trunk at the lower end of which the pitman is
# connected directly with the piston. The trunk works through a stuffing-box in cylinder-head. ..."
#
# Model (cm, Brown's section through the cylinder, no gravity). The cylinder, its head and stuffing-box are cut through the axis (only the back
# half is drawn, y >= 0); so are the piston and the trunk, a tube 6 cm across fixed on the piston and passing out through the stuffing-box.
# The pitman (17 cm) is pinned on the gudgeon in the hollow of the piston, inside the trunk, and takes the crank (3 cm) of the shaft above:
# the trunk is wide enough for the pitman to swing in it, so the engine needs no piston-rod and no guides and stands short. The steam (the one
# input) presses the piston down on the down-stroke and up on the up-stroke, 2 N each way, let in and out by the shaft's own position (a valve
# timed by the crank, feet.timed on j_c: the pressure is greatest at half-stroke and nothing at the dead-centres). The shaft works against a
# load (0.0047 N m s) and runs clockwise as drawn. Generator: opencode-runs/batch13/gen421.py.
number: 421
slug: trunk-engine-marine
name: Trunk engine used for marine purposes
brown: "Trunk engine used for marine purposes. The piston has attached to it a trunk at the lower end of which the pitman is connected directly with the piston. The trunk works through a stuffing-box in cylinder-head. The effective area of the upper side of the piston is greatly reduced by the trunk. To equalize the power on both sides of piston, high-pressure steam has been first used on the upper side and afterward exhausted into and used expansively in the part of cylinder below."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  duration_s: 10
  floor: false
  gravity: 0
bodies:
  - id: crank
    shape: part
    pos: [0, 0, 24]
    density: 7800
    color: "#8f8a80"
    pieces:
      - {kind: disc, center: [0, 24], radius: 0.7, y: [-1.2, 11.0], color: "#6f6a60"}   # the shaft
      - {kind: disc, center: [0, 24], radius: 4.8, inner: 3.2, y: [6.8, 10.8], color: "#7d776c"}   # a fly-wheel on the shaft, behind the standard
      - {kind: disc, center: [0, 24], radius: 3.2, inner: 0.7, y: [7.6, 10.0], color: "#8f8a80"}
      - {kind: disc, center: [0, 24], radius: 1.5, y: [-0.9, -0.3]}   # the crank
      - {kind: poly, points: [[0, 24.9], [3, 24.7], [3, 23.3], [0, 23.1]], y: [-0.9, -0.3]}
      - {kind: disc, center: [3, 24], radius: 0.9, y: [-0.9, -0.3]}
      - {kind: rod, from: [3, -0.3, 24], to: [3, -1.9, 24], radius: 0.3, color: "#5a564e"}   # the crank-pin
  - id: piston
    shape: part
    pos: [0, 0, 7.2668]
    density: 7800
    color: "#a39d90"
    pieces:
      - {kind: poly, points: [[-4.5, 5.6668], [4.5, 5.6668], [4.5, 7.6668], [1, 7.6668], [1, 7.2668], [0.9659, 7.008], [0.866, 6.7668], [0.7071, 6.5597], [0.5, 6.4008], [0.2588, 6.3009], [0, 6.2668], [-0.2588, 6.3009], [-0.5, 6.4008], [-0.7071, 6.5597], [-0.866, 6.7668], [-0.9659, 7.008], [-1, 7.2668], [-1, 7.6668], [-4.5, 7.6668]], y: [0, 4.5]}   # the piston, cut through; the gudgeon in its hollow
      - {kind: poly, points: [[-3, 7.6668], [-2.6, 7.6668], [-2.6, 17.7668], [-3, 17.7668]], y: [0, 3], color: "#b8b1a3"}   # the trunk, cut through
      - {kind: poly, points: [[2.6, 7.6668], [3, 7.6668], [3, 17.7668], [2.6, 17.7668]], y: [0, 3], color: "#b8b1a3"}
      - {kind: poly, points: [[-2.6, 7.6668], [2.6, 7.6668], [2.6, 17.7668], [-2.6, 17.7668]], y: [2.6, 3], color: "#9d968a"}   # its back wall
      - {kind: rod, from: [0, -1.9, 7.2668], to: [0, 2.6, 7.2668], radius: 0.4, color: "#5a564e"}   # the gudgeon
  - id: pitman
    shape: part
    pos: [0, 0, 7.2668]
    mount: piston
    density: 7800
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [0, -1.3, 7.2668], to: [3, -1.3, 24], radius: 0.35}   # the pitman
      - {kind: disc, center: [0, 7.2668], radius: 0.8, inner: 0.4, y: [-1.6, -1.0]}
      - {kind: disc, center: [3, 24], radius: 0.7, inner: 0.3, y: [-1.6, -1.0]}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-5.4, 1], [-4.6, 1], [-4.6, 10.8], [-5.4, 10.8]], y: [0, 5.4]}   # the cylinder, cut through
      - {kind: poly, points: [[5.4, 10.8], [4.6, 10.8], [4.6, 1], [5.4, 1]], y: [0, 5.4]}
      - {kind: poly, points: [[-5.4, 1], [5.4, 1], [5.4, 2], [-5.4, 2]], y: [0, 5.4]}
      - {kind: poly, points: [[-7.6, 10.8], [-3.08, 10.8], [-3.08, 13.6], [-4.2, 13.6], [-4.2, 12.2], [-7.6, 12.2]], y: [0, 5.4]}   # its head, and the stuffing-box round the trunk
      - {kind: poly, points: [[7.6, 12.2], [4.2, 12.2], [4.2, 13.6], [3.08, 13.6], [3.08, 10.8], [7.6, 10.8]], y: [0, 5.4]}
      - {kind: poly, points: [[-7.2, 1.6], [-5.4, 1.6], [-5.4, 2.4], [-7.2, 2.4]], y: [0, 3.0]}   # steam ports
      - {kind: poly, points: [[7.2, 2.4], [5.4, 2.4], [5.4, 1.6], [7.2, 1.6]], y: [0, 3.0]}
      - {kind: poly, points: [[-7.6, -1], [-6.8, -1], [-6.8, 10.8], [-7.6, 10.8]], y: [0, 5.4], color: "#bdb4a2"}   # the frame's columns and base
      - {kind: poly, points: [[7.6, 10.8], [6.8, 10.8], [6.8, -1], [7.6, -1]], y: [0, 5.4], color: "#bdb4a2"}
      - {kind: poly, points: [[-9, -2], [9, -2], [9, -1], [-9, -1]], y: [-1.0, 6.4], color: "#bdb4a2"}
      - {kind: poly, points: [[-7.6, 12.2], [-6.6, 12.2], [-0.6, 23], [-1.6, 23]], y: [5.6, 6.2], color: "#bdb4a2"}   # the shaft's standard, behind
      - {kind: poly, points: [[7.6, 12.2], [6.6, 12.2], [0.6, 23], [1.6, 23]], y: [5.6, 6.2], color: "#bdb4a2"}
      - {kind: disc, center: [0, 24], radius: 1.6, inner: 0.7, y: [5.4, 6.4], color: "#bdb4a2"}   # its bearing
joints:
  - {id: j_c, type: hinge, body: crank, axis: [0, -1, 0], damping: 0.0047}   # the shaft and crank; + : anticlockwise as drawn (it runs clockwise)
  - {id: j_x, type: slide, body: piston, axis: [0, 0, 1], range: [-3.5668, 3.0332], damping: 0.01}   # the piston and trunk (the steam's: the one driven joint); + : up
  - {id: j_r, type: hinge, body: pitman, axis: [0, -1, 0], damping: 0.0002}   # the pitman on the gudgeon
pins:
  - {id: pin_c, a: pitman, b: crank, at: [3, -1.3, 24]}   # the pitman on the crank-pin
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_x, kind: feet, feet: {joints: [j_x, j_x], sign: [1, -1], force: 2, timed: {joint: j_c, shape: sin, gain: 1, offset: 1.5708}}, max_torque: 4}
checks:
  - {type: monotonic, joint: j_c, direction: -1, max_back: 0.05, settle_s: 0.0, window_s: 9.5}   # from rest at half-stroke the shaft goes one way only, over both dead-centres
  - {type: turning, joint: j_c, direction: -1, min_mean: 4.0, min_fraction: 0.9, settle_s: 3.0, window_s: 6.5}
  - {type: amplitude, joint: j_x, min: 0.0296, max: 0.0304, sustain: 0.95, settle_s: 3.0, window_s: 6.5}   # the piston's stroke is twice the crank: the pitman holds the gudgeon to the crank-pin
  - {type: amplitude, joint: j_r, min: 0.1714, max: 0.1834, sustain: 0.95, settle_s: 3.0, window_s: 6.5}   # the pitman swings asin(R/L) either way inside the trunk
  - {type: penetration, max: 0.002}
camera: {target: [0, 0, 9.0], position: [0, -95, 9.0], fov: 27.2}
display:
  output: j_c
  labels: {j_x: "Piston and trunk (steam)", j_c: "Shaft and crank", j_r: "Pitman"}
  proof: {label: "Pitman off the crank-pin", sub: "the steam drives the piston but the shaft stands"}
