Problem 218755 · medium · Level 02 Linear Data Structures

Tuning a Door Closer

damping ratio · underdamped · critically damped · overdamped · simulation

A fire door has an automatic closer: a spring pulls the door shut and an oil-filled damper slows it down. It is the same mass-spring-damper as a car's suspension, turning instead of moving up and down. The door's angle theta is in degrees (0 = closed), its angular speed w in degrees per second, its inertia I (how hard it is to set turning), the spring constant k (torque per degree) and the damper constant c (torque per degree per second).

How the door moves depends on one number, the damping ratio

zeta = c / (2 * sqrt(k * I))
  • zeta < 1: underdamped. The door swings past closed and bangs into the frame (in the model, the angle goes below 0).
  • zeta = 1: critically damped. The fastest return that does not swing past.
  • zeta > 1: overdamped. It never swings past, but it crawls, and a door that takes half a minute is propped open by annoyed people.

An installer turns a valve and gets close to 1, never exactly; count 0.99 <= zeta <= 1.01 as critically damped.

The installer opens the door to angle0 degrees and lets go (w = 0). Simulate n semi-implicit Euler steps of dt seconds:

acc = (-k * theta - c * w) / I
w = w + dt * acc
theta = theta + dt * w

Write door_closer(I, c, k, angle0, dt, n) that returns a tuple of four values:

  1. zeta,
  2. the kind: "underdamped", "critically damped" or "overdamped",
  3. True if the angle goes below 0 after some step (the door slams), otherwise False,
  4. the closing time: s * dt for the first step s (counting from 1) after which theta <= 1 (the latch catches), or None if that does not happen within the n steps.

To see the difference, collect the angles in a list inside your loop and plot them for three valve settings, for example c = 1, 4, 12 with I = 4, k = 1.

Examples

Input:  I = 4, c = 1, k = 1, angle0 = 90, dt = 0.01, n = 3000
Output: (0.25, 'underdamped', True, 3.73)
Explanation: the door is at 1 degree after 3.73 s, but going fast: it swings on and slams.

Input:  I = 4, c = 12, k = 1, angle0 = 90, dt = 0.01, n = 3000
Output: (3.0, 'overdamped', False, None)
Explanation: still more than a degree open after 30 seconds.

Constraints

  • answers are compared with a tolerance of 1e-6; do not round

Goals

  • Compute the damping ratio of a mass-spring-damper from its three constants
  • Classify a system as underdamped, critically damped or overdamped
  • Connect the damping ratio with what a simulation shows: overshoot or a slow crawl
Starting Python…