# No. 422 (Brown 1868): "Oscillating piston engine. The profile of the cylinder A, is of the form of a sector. The piston, B, is attached to a
# rock-shaft, C, and steam is admitted to the cylinder to operate on one and the other side of piston alternately, by means of a slide-valve, D,
# substantially like that of an ordinary reciprocating engine. The rock-shaft is connected with a crank to produce rotary motion."
#
# Model (cm, Brown's section through the cylinder, no gravity; only the back half of the cut parts is drawn). The cylinder A is a sector
# 48 degrees wide about the rock-shaft C, with a steam passage from the valve-chest down each side; the piston B is a vane
# fast on C reaching to the sector's arc. Behind the cylinder an arm on C (5 cm) and a rod (9.98 cm) take the rock-shaft to a crank
# (1.6 cm) with a fly-wheel, which shows to the right. The steam (the one input) presses the piston one way and then the other, 0.08 N m,
# let in by the valve as timed by the crank (feet.timed on j_c: greatest at mid-swing, nothing at the ends); the slide-valve D is drawn in its chest but carries no motion. The crank shaft
# works against a load (0.002 N m s). Generator: opencode-runs/batch13/gen422.py.
number: 422
slug: oscillating-piston-engine
name: Oscillating piston engine
brown: "Oscillating piston engine. The profile of the cylinder A, is of the form of a sector. The piston, B, is attached to a rock-shaft, C, and steam is admitted to the cylinder to operate on one and the other side of piston alternately, by means of a slide-valve, D, substantially like that of an ordinary reciprocating engine. The rock-shaft is connected with a crank to produce rotary motion."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS
  duration_s: 10
  floor: false
  gravity: 0
bodies:
  - id: piston
    shape: part
    pos: [0, 0, 2.4]
    density: 7800
    color: "#a39d90"
    pieces:
      - {kind: poly, points: [[-0.3, 3.4], [0.3, 3.4], [0.3, 13.4], [-0.3, 13.4]], y: [0, 1.5]}   # the piston B, cut through
      - {kind: disc, center: [0, 2.4], radius: 1.15, y: [0, 1.5], color: "#6f6a60"}   # the rock-shaft C
      - {kind: disc, center: [0, 2.4], radius: 0.55, y: [1.5, 4.6], color: "#6f6a60"}   # it passes out behind
      - {kind: poly, points: [[0.4645, 2.215], [2.2221, 6.8969], [1.4789, 7.193], [-0.4645, 2.585]], y: [3.6, 4.2], color: "#7d776c"}   # the arm on the rock-shaft
      - {kind: rod, from: [1.8505, 3.6, 7.045], to: [1.8505, 5.4, 7.045], radius: 0.25, color: "#5a564e"}
  - id: rod
    shape: part
    pos: [1.8505, 0, 7.045]
    mount: piston
    density: 7800
    color: "#b8ad97"
    pieces:
      - {kind: rod, from: [1.8505, 4.8, 7.045], to: [10.4079, 4.8, 1.9136], radius: 0.28}   # the rod to the crank
      - {kind: disc, center: [1.8505, 7.045], radius: 0.55, inner: 0.25, y: [4.5, 5.1]}
      - {kind: disc, center: [10.4079, 1.9136], radius: 0.55, inner: 0.25, y: [4.5, 5.1]}
  - id: crank
    shape: part
    pos: [11, 0, 3.4]
    density: 7800
    color: "#7d776c"
    pieces:
      - {kind: disc, center: [11, 3.4], radius: 0.5, y: [4.2, 9.0], color: "#6f6a60"}   # the crank shaft
      - {kind: poly, points: [[11.5574, 3.1779], [10.8724, 1.7286], [9.9434, 2.0987], [10.4426, 3.6221]], y: [5.2, 5.8]}   # the crank
      - {kind: rod, from: [10.4079, 4.2, 1.9136], to: [10.4079, 5.8, 1.9136], radius: 0.22, color: "#5a564e"}
      - {kind: disc, center: [11, 3.4], radius: 3.2, inner: 2.3, y: [6.0, 8.6], color: "#8f8a80"}   # the fly-wheel
      - {kind: disc, center: [11, 3.4], radius: 2.3, inner: 0.5, y: [7.0, 7.6], color: "#a39d90"}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[0.6508, 3.8617], [4.7995, 13.1798], [5.2563, 12.9765], [1.1076, 3.6583]], y: [0, 2.1]}   # the cylinder A, cut through: its two sides,
      - {kind: poly, points: [[-1.1076, 3.6583], [-5.2563, 12.9765], [-4.7995, 13.1798], [-0.6508, 3.8617]], y: [0, 2.1]}
      - {kind: poly, points: [[2.0194, 4.3265], [7.1512, 12.9093], [7.5803, 12.6527], [2.4486, 4.0699]], y: [0, 2.1]}   # the steam passages' outer walls,
      - {kind: poly, points: [[-2.4486, 4.0699], [-7.5803, 12.6527], [-7.1512, 12.9093], [-2.0194, 4.3265]], y: [0, 2.1]}
      - {kind: poly, points: [[-4.3646, 13.3631], [-3.8407, 13.5575], [-3.3081, 13.7268], [-2.7682, 13.8707], [-2.222, 13.9889], [-1.6709, 14.0811], [-1.116, 14.1471], [-0.5586, 14.1868], [0, 14.2], [0.5586, 14.1868], [1.116, 14.1471], [1.6709, 14.0811], [2.222, 13.9889], [2.7682, 13.8707], [3.3081, 13.7268], [3.8407, 13.5575], [4.3646, 13.3631], [4.1426, 12.8057], [3.6454, 12.9901], [3.1399, 13.1509], [2.6274, 13.2875], [2.1091, 13.3996], [1.5859, 13.4871], [1.0593, 13.5498], [0.5302, 13.5874], [0, 13.6], [-0.5302, 13.5874], [-1.0593, 13.5498], [-1.5859, 13.4871], [-2.1091, 13.3996], [-2.6274, 13.2875], [-3.1399, 13.1509], [-3.6454, 12.9901], [-4.1426, 12.8057]], y: [0, 2.1]}   # the arc over the piston,
      - {kind: poly, points: [[-7.0434, 13.917], [-6.2372, 14.3728], [-5.4018, 14.7722], [-4.5409, 15.1134], [-3.6586, 15.3948], [-2.7591, 15.615], [-1.8467, 15.7731], [-0.9255, 15.8682], [0, 15.9], [0.9255, 15.8682], [1.8467, 15.7731], [2.7591, 15.615], [3.6586, 15.3948], [4.5409, 15.1134], [5.4018, 14.7722], [6.2372, 14.3728], [7.0434, 13.917], [6.7303, 13.4051], [5.96, 13.8406], [5.1617, 14.2223], [4.339, 14.5484], [3.496, 14.8172], [2.6365, 15.0277], [1.7646, 15.1787], [0.8844, 15.2696], [0, 15.3], [-0.8844, 15.2696], [-1.7646, 15.1787], [-2.6365, 15.0277], [-3.496, 14.8172], [-4.339, 14.5484], [-5.1617, 14.2223], [-5.96, 13.8406], [-6.7303, 13.4051]], y: [0, 2.1]}
      - {kind: poly, points: [[-1.9078, 3.8561], [-1.7284, 4.0652], [-1.5261, 4.2523], [-1.3038, 4.415], [-1.0643, 4.5511], [-0.8107, 4.6589], [-0.5465, 4.737], [-0.2751, 4.7842], [0, 4.8], [0.2751, 4.7842], [0.5465, 4.737], [0.8107, 4.6589], [1.0643, 4.5511], [1.3038, 4.415], [1.5261, 4.2523], [1.7284, 4.0652], [1.9078, 3.8561], [1.2719, 3.3707], [1.1522, 3.5101], [1.0174, 3.6348], [0.8692, 3.7433], [0.7095, 3.8341], [0.5405, 3.9059], [0.3643, 3.958], [0.1834, 3.9895], [0, 4], [-0.1834, 3.9895], [-0.3643, 3.958], [-0.5405, 3.9059], [-0.7095, 3.8341], [-0.8692, 3.7433], [-1.0174, 3.6348], [-1.1522, 3.5101], [-1.2719, 3.3707]], y: [0, 2.1]}   # the bearing round C
      - {kind: poly, points: [[-2.6, 0.4], [2.6, 0.4], [7.8317, 13.3961], [7.1366, 13.8595], [6.4142, 14.2789], [5.6672, 14.6529], [4.8985, 14.9799], [4.1111, 15.2588], [3.3079, 15.4885], [2.4921, 15.668], [1.6667, 15.7967], [0.835, 15.8742], [0, 15.9], [-0.835, 15.8742], [-1.6667, 15.7967], [-2.4921, 15.668], [-3.3079, 15.4885], [-4.1111, 15.2588], [-4.8985, 14.9799], [-5.6672, 14.6529], [-6.4142, 14.2789], [-7.1366, 13.8595], [-7.8317, 13.3961]], y: [1.5, 2.1], color: "#bdb4a2"}   # the cylinder's back plate
      - {kind: poly, points: [[-3.4, 15.6], [3.4, 15.6], [3.4, 19.3], [-3.4, 19.3]], y: [0, 2.1]}   # the valve-chest
      - {kind: poly, points: [[-2.8, 16.2], [2.8, 16.2], [2.8, 18.7], [-2.8, 18.7]], y: [-0.1, 1.6], color: "#efe6d4"}
      - {kind: poly, points: [[-1.6, 16.2], [1.6, 16.2], [1.6, 17.3], [-1.6, 17.3]], y: [0, 1.5], color: "#7d776c"}   # the slide-valve D
      - {kind: rod, from: [1.6, 0.75, 16.75], to: [6.5, 0.75, 16.75], radius: 0.2, color: "#5a564e"}   # its stem
      - {kind: poly, points: [[-7.5, -1.6], [7.5, -1.6], [7.5, -0.2], [-7.5, -0.2]], y: [-1.5, 9.4], color: "#bdb4a2"}   # the bed
      - {kind: poly, points: [[-5.6, -0.2], [5.6, -0.2], [3, 1], [1.8, 1.4], [-1.8, 1.4], [-3, 1]], y: [0, 2.1], color: "#bdb4a2"}
      - {kind: poly, points: [[10.2, -0.2], [11.8, -0.2], [11.5, 3.4], [10.5, 3.4]], y: [8.8, 9.4], color: "#bdb4a2"}   # the crank shaft's pedestal, behind
      - {kind: poly, points: [[7.5, -1.6], [12.2, -1.6], [12.2, -0.2], [7.5, -0.2]], y: [8.0, 9.4], color: "#bdb4a2"}
joints:
  - {id: j_B, type: hinge, body: piston, axis: [0, -1, 0], range: [-0.39, 0.39], damping: 0.0005}   # the piston and rock-shaft (the steam's: the one driven joint); + : anticlockwise as drawn; its range: the sector's sides
  - {id: j_r, type: hinge, body: rod, axis: [0, -1, 0], damping: 0.0001}
  - {id: j_c, type: hinge, body: crank, axis: [0, -1, 0], damping: 0.002}   # the crank shaft and fly-wheel; + : anticlockwise as drawn
pins:
  - {id: pin_c, a: rod, b: crank, at: [10.4079, 4.8, 1.9136]}   # the rod on the crank-pin
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_B, kind: feet, feet: {joints: [j_B, j_B], sign: [1, -1], force: 0.08, timed: {joint: j_c, shape: sin, gain: 1, offset: 4.7124}}, max_torque: 0.16}
checks:
  - {type: monotonic, joint: j_c, direction: -1, max_back: 0.05, settle_s: 0.0, window_s: 9.5}   # from rest the crank goes one way only (clockwise as drawn), over both dead-centres
  - {type: turning, joint: j_c, direction: -1, min_mean: 3.5, min_fraction: 0.9, settle_s: 3.0, window_s: 6.5}
  - {type: amplitude, joint: j_B, min: 0.318, max: 0.334, sustain: 0.95, settle_s: 3.0, window_s: 6.5}   # the piston swings to and fro in the sector, clear of its sides (+/-0.419 rad less the piston's half-width)
  - {type: penetration, max: 0.002}
camera: {target: [0, 0, 8.6], position: [0, -95, 8.6], fov: 24}
display:
  output: j_c
  labels: {j_B: "Piston and rock-shaft (steam)", j_c: "Crank and fly-wheel", j_r: "Rod"}
  proof: {label: "Rod off the crank-pin", sub: "the steam rocks the piston but the crank stands"}
