# No. 316 (Brown 1868): "Mercurial compensation pendulum. A glass jar of mercury is used for the bob or weight. As the pendulum-rod is expanded lengthwise by increased temperature, the expansion of mercury in jar carries it to a greater height therein, and so raises its center of gravity relatively to the rod sufficiently to compensate for downward expansion of the rod. As rod is contracted by a reduction of temperature, contraction of mercury lowers it relatively to rod. In this way the center of oscillation is always kept in the same place, and the effective length of pendulum always the same."
#
# Model (cm, gravity on). The clock is No. 303's dead-beat escapement (a 30-tooth wheel, the pallets on the arbor C); the pendulum's bob is
# a glass jar of mercury, 3 deep, standing in a steel stirrup at the end of the rod; the jar's bottom is 21 below C. The jar is drawn
# without its front wall so the mercury shows. Heat is not simulated: the depth of mercury is the one that compensates the rod (the rod's
# lengthening, 21 x 11.5e-6 per degree, equals the rise of the mercury's centre, 3/2 x 1.63e-4 per degree, mercury's
# expansion less the glass's). Fully physical: the only input is a constant torque on the escape wheel (the clock's weight); the
# pendulum starts from rest, hanging straight, and the escapement starts itself. Generator: opencode-runs/batch12/gen316.py.
number: 316
slug: mercurial-compensation-pendulum
name: Mercurial compensation pendulum
brown: "Mercurial compensation pendulum. A glass jar of mercury is used for the bob or weight. As the pendulum-rod is expanded lengthwise by increased temperature, the expansion of mercury in jar carries it to a greater height therein, and so raises its center of gravity relatively to the rod sufficiently to compensate for downward expansion of the rod. As rod is contracted by a reduction of temperature, contraction of mercury lowers it relatively to rod. In this way the center of oscillation is always kept in the same place, and the effective length of pendulum always the same."
units: cm
sim: {timestep: 0.0002, integrator: implicitfast, iterations: 50, duration_s: 10, floor: false}
bodies:
  # The escape wheel: brass, 30 teeth leaning forward (Graham), rim, four spokes, hub.
  - id: wheel
    shape: part
    pos: [0, 0, 0]
    density: 8500
    friction: 0.1
    color: "#e6d7b0"
    pieces:
      - kind: wheel
        center: [0, 0]
        teeth: 30
        # one tooth, polar (radius, angle from its tip) — the tip leads, the back is curved off
        tooth: [[5.0, 0], [4.45, 0.075], [3.9, 0.165], [3.9, 0.0756]]
        phase: 2.42601        # 139°: tooth 0 just short of D's impulse face
        root: 4.2
        rim: 3.6
        hub: 0.8
        spokes: 4
        spoke_width: 0.45
        y: [-0.25, 0.25]
        collide: 2
      - {kind: disc, center: [0, 0], radius: 0.25, y: [-0.7, 0.9], color: "#8f8a80"}   # arbor
  # The pallets (anchor) and the pendulum: one piece on the arbor C.
  - id: pendulum
    shape: part
    pos: [0, 0, 7.07107]
    density: 7800
    friction: 0.1
    color: "#d9cfba"
    pieces:
      - {kind: disc, center: [0, 7.07107], radius: 0.6, y: [-1.15, 0.35]}                       # 0 hub on the arbor
      - {kind: poly, points: [[-0.45183, 7.16247], [-4.23406, 4.21139], [-3.80346, 3.65951], [-0.02122, 6.61058]], y: [-0.3, 0.3]}  # 1
      - {kind: poly, points: [[0.02117, 6.61058], [3.73434, 3.71273], [4.16501, 4.26457], [0.45184, 7.16242]], y: [-0.3, 0.3]}  # 2
      # D (entry): locking face = outer arc r 5.2399 about C; impulse face down to r 4.8473 over 2.5° of lift
      - {kind: band, center: [0, 7.07107], r: [4.84731, 5.23989], a: [-2.57326, -2.36382], y: [-0.35, 0.35], collide: 1}  # 3
      - {kind: poly, points: [[-3.77162, 3.43357], [-3.73332, 3.39427], [-3.30196, 3.52234], [-3.48904, 3.7061]], y: [-0.35, 0.35], collide: 1}  # 4
      # E (exit): locking face = inner arc r 4.7601 about C; impulse face out to r 5.1527
      - {kind: band, center: [0, 7.07107], r: [4.76011, 5.15269], a: [-0.77788, -0.56844], y: [-0.35, 0.35], collide: 1}  # 5
      - {kind: poly, points: [[3.42591, 3.76625], [3.39111, 3.73056], [3.50957, 3.29838], [3.70845, 3.49369]], y: [-0.35, 0.35], collide: 1}  # 6
      - {kind: rod, from: [0, -1.0, 7.07107], to: [0, -1.0, -8.72893], radius: 0.15, color: "#8f8a80"}   # 7 the pendulum-rod (steel)
      - {kind: poly, points: [[-1.75, -8.97893], [1.75, -8.97893], [1.75, -8.67893], [-1.75, -8.67893]], y: [-1.3, -0.7], color: "#8f8a80"}   # 8 the stirrup's top bar
      - {kind: poly, points: [[-1.75, -14.42893], [-1.55, -14.42893], [-1.55, -8.97893], [-1.75, -8.97893]], y: [-1.3, -0.7], color: "#8f8a80"}   # 9 the stirrup's side
      - {kind: poly, points: [[1.55, -14.42893], [1.75, -14.42893], [1.75, -8.97893], [1.55, -8.97893]], y: [-1.3, -0.7], color: "#8f8a80"}   # 10 the stirrup's side
      - {kind: poly, points: [[-1.75, -14.42893], [1.75, -14.42893], [1.75, -14.12893], [-1.75, -14.12893]], y: [-1.9, -0.1], color: "#8f8a80"}   # 11 the stirrup's foot, the jar stands on it
      - {kind: poly, points: [[-1.4, -14.12893], [1.4, -14.12893], [1.4, -13.92893], [-1.4, -13.92893]], y: [-1.8, -0.2], density: 2500, color: "#c9d6d8"}   # 12 the jar's bottom (glass)
      - {kind: poly, points: [[-1.4, -13.92893], [-1.2, -13.92893], [-1.2, -9.32893], [-1.4, -9.32893]], y: [-1.8, -0.2], density: 2500, color: "#c9d6d8"}   # 13 the jar's wall
      - {kind: poly, points: [[1.2, -13.92893], [1.4, -13.92893], [1.4, -9.32893], [1.2, -9.32893]], y: [-1.8, -0.2], density: 2500, color: "#c9d6d8"}   # 14 the jar's wall
      - {kind: poly, points: [[-1.2, -13.92893], [1.2, -13.92893], [1.2, -9.32893], [-1.2, -9.32893]], y: [-0.4, -0.2], density: 2500, color: "#c9d6d8"}   # 15 the jar's back wall (its front is not drawn)
      - {kind: poly, points: [[-1.2, -13.92893], [1.2, -13.92893], [1.2, -10.92893], [-1.2, -10.92893]], y: [-1.6, -0.4], density: 13546, color: "#b4b8bc"}   # 16 the mercury
  # The cock that carries C (frame, drawn only).
  - id: cock
    shape: part
    pos: [0, 0, 7.07107]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.3, 8.6], [1.3, 8.6], [0.75, 6.75], [-0.75, 6.75]], y: [0.4, 1.0]}
      - {kind: disc, center: [0, 7.07107], radius: 0.18, y: [-1.3, 1.0], color: "#8f8a80"}
joints:
  - {id: j_wheel, type: hinge, body: wheel, axis: [0, 1, 0], damping: 0.00002}
  - {id: j_pend, type: hinge, body: pendulum, axis: [0, 1, 0], damping: 0.0015}   # air and pivot losses
contact: {solref: [0.002, 1], solimp: [0.95, 0.99, 0.0005], margin: 0}
# The clock's weight: a constant torque on the escape wheel, clockwise (+y). Nothing else is driven.
driver: {joint: j_wheel, kind: torque, torque: 0.008, max_torque: 0.05}
checks:
  # the pendulum keeps time: its period against the compound pendulum's 2π√(I/(m g d)) from the model
  - {type: period, joint: j_pend, tol: 0.03, settle_s: 4, window_s: 4}
  # half a tooth (2π/30 / 2) per beat: one tooth per two beats
  - {type: advance, joint: j_wheel, beat: j_pend, expect: 0.10472, tol: 0.03, settle_s: 4, window_s: 4}
  # dead beat: the wheel never turns back while locked (recoil) beyond contact compliance
  - {type: monotonic, joint: j_wheel, direction: 1, max_back: 0.004, settle_s: 2, window_s: 6}
  # the impulse keeps the swing going against the damping
  - {type: amplitude, joint: j_pend, min: 0.05, max: 0.2, sustain: 0.9, settle_s: 4, window_s: 4}
  - {type: penetration, max: 0.0005, settle_s: 1}
camera: {target: [0, 0, -8.6], position: [11, -80.0, -3.6], fov: 30}
display:
  output: j_pend
  swing: j_pend
  labels: {j_wheel: Escape wheel (weight), j_pend: Mercurial pendulum and pallets}
  brake: Extra air drag on the pendulum
  proof: {label: Pallets out of contact, sub: "the teeth no longer touch the pallets: nothing makes good the pendulum's losses, so its swing dies away, and the weight spins the wheel freely"}

