diff --git a/scipy/simple_pendulum/093/video.mp4 b/scipy/simple_pendulum/093/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..476b8d1eb84c0660d9de67e9a40d65fb43d9d645 --- /dev/null +++ b/scipy/simple_pendulum/093/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6581091f3eba41a77eddd9aefd41801ad6a4747ff8e3e7ebd346dfd4954ec124 +size 18457 diff --git a/scipy/simple_pendulum/124/cot.json b/scipy/simple_pendulum/124/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..55ef9940b6ad7139032053f7716b2059792e6c48 --- /dev/null +++ b/scipy/simple_pendulum/124/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=1.160 kg) swings on a rigid rod (L=1.833 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.317 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 2.717 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0176 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 1.8329999996219075, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 1.1597203451890215, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.3168662072282229, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": -1.1089314525626406, + "unit": "", + "description": "" + }, + "omega0": { + "value": -1.1340552704445384, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/124/params.json b/scipy/simple_pendulum/124/params.json new file mode 100644 index 0000000000000000000000000000000000000000..89be9aaf8c688610d9aadbd7cc762f73784a02e0 --- /dev/null +++ b/scipy/simple_pendulum/124/params.json @@ -0,0 +1,10 @@ +{ + "L": 1.8329999996219075, + "m": 1.1597203451890215, + "g": 9.8, + "b": 0.3168662072282229, + "A": 0.0, + "k_freq": 0.0, + "theta0": -1.1089314525626406, + "omega0": -1.1340552704445384 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/124/simulation_code.py b/scipy/simple_pendulum/124/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ce45012dffbb5e38f8488162a95d2640eda1cabb --- /dev/null +++ b/scipy/simple_pendulum/124/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 1.8329999996219075 +m = 1.1597203451890215 +g = 9.8 +b = 0.3168662072282229 +A = 0.0 +k_freq = 0.0 +theta0 = -1.108931 +omega0 = -1.134055 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/124/video.mp4 b/scipy/simple_pendulum/124/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f9a580997ae799ce4f99f9528d9da87431508d9d --- /dev/null +++ b/scipy/simple_pendulum/124/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd070760cbc286abe87f584fb294bb1d138f6958e09c6df7a1c3670bac825b11 +size 20239 diff --git a/scipy/simple_pendulum/166/cot.json b/scipy/simple_pendulum/166/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4c9f84dbc5bbfea35ac608f443c4108a486271b5 --- /dev/null +++ b/scipy/simple_pendulum/166/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=2.268 kg) swings on a rigid rod (L=0.945 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.354 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 1.951 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0272 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 0.9445214222595294, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 2.2680322714152794, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.3542802301140774, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": -0.7475111368830135, + "unit": "", + "description": "" + }, + "omega0": { + "value": 0.3863347480043964, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/166/params.json b/scipy/simple_pendulum/166/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c08385c3be14eab00b52d4f85d9ad9d7e4b8c65f --- /dev/null +++ b/scipy/simple_pendulum/166/params.json @@ -0,0 +1,10 @@ +{ + "L": 0.9445214222595294, + "m": 2.2680322714152794, + "g": 9.8, + "b": 0.3542802301140774, + "A": 0.0, + "k_freq": 0.0, + "theta0": -0.7475111368830135, + "omega0": 0.3863347480043964 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/166/simulation_code.py b/scipy/simple_pendulum/166/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..7909350f049554ceed504d3b1ea4d45e85c1b279 --- /dev/null +++ b/scipy/simple_pendulum/166/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 0.9445214222595294 +m = 2.2680322714152794 +g = 9.8 +b = 0.3542802301140774 +A = 0.0 +k_freq = 0.0 +theta0 = -0.747511 +omega0 = 0.386335 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/166/video.mp4 b/scipy/simple_pendulum/166/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..11142838d808fe20e86352e41a2f5a8a4fdd486a --- /dev/null +++ b/scipy/simple_pendulum/166/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fcf8ea7d1e7c1f6360b133789778118f2cfe228f434bfd69b662de1a07eab501 +size 18404 diff --git a/scipy/simple_pendulum/172/cot.json b/scipy/simple_pendulum/172/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..704f5d51a6a9127e3299d97d4b363e47c5410ae7 --- /dev/null +++ b/scipy/simple_pendulum/172/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=0.559 kg) swings on a rigid rod (L=0.601 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.767 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 1.556 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.4705 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 0.6013621759061185, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 0.5585668445268679, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.7674040909680111, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": 0.9731495666549164, + "unit": "", + "description": "" + }, + "omega0": { + "value": 1.1875933991542498, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/172/params.json b/scipy/simple_pendulum/172/params.json new file mode 100644 index 0000000000000000000000000000000000000000..a48a29aebf2e4eb5cc32a9cb56904d7680b19e92 --- /dev/null +++ b/scipy/simple_pendulum/172/params.json @@ -0,0 +1,10 @@ +{ + "L": 0.6013621759061185, + "m": 0.5585668445268679, + "g": 9.8, + "b": 0.7674040909680111, + "A": 0.0, + "k_freq": 0.0, + "theta0": 0.9731495666549164, + "omega0": 1.1875933991542498 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/172/simulation_code.py b/scipy/simple_pendulum/172/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..369441f7f903e01b6b5d008185c922f6598c2a4c --- /dev/null +++ b/scipy/simple_pendulum/172/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 0.6013621759061185 +m = 0.5585668445268679 +g = 9.8 +b = 0.7674040909680111 +A = 0.0 +k_freq = 0.0 +theta0 = 0.973150 +omega0 = 1.187593 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/172/video.mp4 b/scipy/simple_pendulum/172/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e01386afbd77f5d4bb0af1662000df2c171d62bd --- /dev/null +++ b/scipy/simple_pendulum/172/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f8ea047e51a53b2f43878dd8f77f3006d84f65ec7c1bc5da4324c803072fcaf +size 7876 diff --git a/scipy/simple_pendulum/194/cot.json b/scipy/simple_pendulum/194/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f1988029d6c788340faddfc5888c57c4fc7eaf85 --- /dev/null +++ b/scipy/simple_pendulum/194/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=2.130 kg) swings on a rigid rod (L=0.415 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.527 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 1.293 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.1480 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 0.41488344817326833, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 2.1296002786531414, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.5274503698207139, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": -0.9065253975301019, + "unit": "", + "description": "" + }, + "omega0": { + "value": 0.1729949534358286, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/194/params.json b/scipy/simple_pendulum/194/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5776843de154a739503231ba9351f4975969ef71 --- /dev/null +++ b/scipy/simple_pendulum/194/params.json @@ -0,0 +1,10 @@ +{ + "L": 0.41488344817326833, + "m": 2.1296002786531414, + "g": 9.8, + "b": 0.5274503698207139, + "A": 0.0, + "k_freq": 0.0, + "theta0": -0.9065253975301019, + "omega0": 0.1729949534358286 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/194/simulation_code.py b/scipy/simple_pendulum/194/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..cd1c987bb026b7ee0e13b8c5bfb860b4196b8bc6 --- /dev/null +++ b/scipy/simple_pendulum/194/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 0.41488344817326833 +m = 2.1296002786531414 +g = 9.8 +b = 0.5274503698207139 +A = 0.0 +k_freq = 0.0 +theta0 = -0.906525 +omega0 = 0.172995 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/194/video.mp4 b/scipy/simple_pendulum/194/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..7c3158c21761254693f05dc0df5a9b4b956baec4 --- /dev/null +++ b/scipy/simple_pendulum/194/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6461946ee3673769ba2ea399907a7bf92a5b191e8b2544866286042f83ad8cd3 +size 11218 diff --git a/scipy/simple_pendulum/230/cot.json b/scipy/simple_pendulum/230/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..1f1add63907a2560afa08f451bea6cfb5bc10747 --- /dev/null +++ b/scipy/simple_pendulum/230/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=1.233 kg) swings on a rigid rod (L=0.629 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.166 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 1.591 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0433 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 0.6286572038019055, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 1.2325747307848998, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.1664965190797424, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": 0.7905132115576572, + "unit": "", + "description": "" + }, + "omega0": { + "value": -1.4547450691880077, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/230/params.json b/scipy/simple_pendulum/230/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6b18feb3bfcdcafd2aafa4bae75dd4b5476a054c --- /dev/null +++ b/scipy/simple_pendulum/230/params.json @@ -0,0 +1,10 @@ +{ + "L": 0.6286572038019055, + "m": 1.2325747307848998, + "g": 9.8, + "b": 0.1664965190797424, + "A": 0.0, + "k_freq": 0.0, + "theta0": 0.7905132115576572, + "omega0": -1.4547450691880077 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/230/simulation_code.py b/scipy/simple_pendulum/230/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..43e9584f424e5dfa9cc176ee69de9c7205827dfe --- /dev/null +++ b/scipy/simple_pendulum/230/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 0.6286572038019055 +m = 1.2325747307848998 +g = 9.8 +b = 0.1664965190797424 +A = 0.0 +k_freq = 0.0 +theta0 = 0.790513 +omega0 = -1.454745 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/230/video.mp4 b/scipy/simple_pendulum/230/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..04639c0a096106a6b5a812798709743822b5008e --- /dev/null +++ b/scipy/simple_pendulum/230/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b7065e2052b956e85495abf07ba1e3f79027497f264a16b270463f8ce5c630af +size 18306 diff --git a/scipy/simple_pendulum/237/cot.json b/scipy/simple_pendulum/237/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..85e6cf2aeb57d00a2b0056068ef980cad6248370 --- /dev/null +++ b/scipy/simple_pendulum/237/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=1.638 kg) swings on a rigid rod (L=1.169 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.462 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 2.170 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0356 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 1.16861925009374, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 1.6379829709013396, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.46159094158599534, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": 0.2805122442187755, + "unit": "", + "description": "" + }, + "omega0": { + "value": 1.7872493033509262, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/237/params.json b/scipy/simple_pendulum/237/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3c04ed97e4e252189df960110e2dfd80ea688f1e --- /dev/null +++ b/scipy/simple_pendulum/237/params.json @@ -0,0 +1,10 @@ +{ + "L": 1.16861925009374, + "m": 1.6379829709013396, + "g": 9.8, + "b": 0.46159094158599534, + "A": 0.0, + "k_freq": 0.0, + "theta0": 0.2805122442187755, + "omega0": 1.7872493033509262 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/237/simulation_code.py b/scipy/simple_pendulum/237/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8229d8d70f5b5e293d7087c8bdfdea4e696905f3 --- /dev/null +++ b/scipy/simple_pendulum/237/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 1.16861925009374 +m = 1.6379829709013396 +g = 9.8 +b = 0.46159094158599534 +A = 0.0 +k_freq = 0.0 +theta0 = 0.280512 +omega0 = 1.787249 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/237/video.mp4 b/scipy/simple_pendulum/237/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..5b06c72dad73b535222656ad59359510b043a9fb --- /dev/null +++ b/scipy/simple_pendulum/237/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38f89c098896dbbb8f6e6414ef7f7f574fcb3d2ef19f9d7b481a9661d162fda0 +size 16964 diff --git a/scipy/simple_pendulum/253/cot.json b/scipy/simple_pendulum/253/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..65c9fa954b5073d2eb51d329e1ed504ad3b6d8e3 --- /dev/null +++ b/scipy/simple_pendulum/253/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=2.326 kg) swings on a rigid rod (L=1.278 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.183 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 2.269 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0087 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 1.2781632002220964, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 2.3264372822788344, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.1829715228971649, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": -0.2523547013977694, + "unit": "", + "description": "" + }, + "omega0": { + "value": 0.5221641548467515, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/253/params.json b/scipy/simple_pendulum/253/params.json new file mode 100644 index 0000000000000000000000000000000000000000..bee512e57b84936a16463fbaa42058e60668c103 --- /dev/null +++ b/scipy/simple_pendulum/253/params.json @@ -0,0 +1,10 @@ +{ + "L": 1.2781632002220964, + "m": 2.3264372822788344, + "g": 9.8, + "b": 0.1829715228971649, + "A": 0.0, + "k_freq": 0.0, + "theta0": -0.2523547013977694, + "omega0": 0.5221641548467515 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/253/simulation_code.py b/scipy/simple_pendulum/253/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..145788b180ca673cb96ccf4d3162a1d8943e00e6 --- /dev/null +++ b/scipy/simple_pendulum/253/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 1.2781632002220964 +m = 2.3264372822788344 +g = 9.8 +b = 0.1829715228971649 +A = 0.0 +k_freq = 0.0 +theta0 = -0.252355 +omega0 = 0.522164 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/253/video.mp4 b/scipy/simple_pendulum/253/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9ff0d17af713ba13a98b9a940c21382299fba3c6 --- /dev/null +++ b/scipy/simple_pendulum/253/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4e5baeba6c477bfa41d4f31cb379d81d694ff56195de55b2a2898791ec3bf3e +size 13336 diff --git a/scipy/simple_pendulum/291/cot.json b/scipy/simple_pendulum/291/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..85918ed97ed7bfbdb047be9c9f49c69774e336e4 --- /dev/null +++ b/scipy/simple_pendulum/291/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=1.354 kg) swings on a rigid rod (L=1.985 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.546 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 2.828 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0230 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 1.985317149343413, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 1.3543539575820556, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.5459261597934555, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": -0.9893118272453896, + "unit": "", + "description": "" + }, + "omega0": { + "value": -1.1517172650095255, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/291/params.json b/scipy/simple_pendulum/291/params.json new file mode 100644 index 0000000000000000000000000000000000000000..cc99904d55804061fd6a73194d9466119f08816d --- /dev/null +++ b/scipy/simple_pendulum/291/params.json @@ -0,0 +1,10 @@ +{ + "L": 1.985317149343413, + "m": 1.3543539575820556, + "g": 9.8, + "b": 0.5459261597934555, + "A": 0.0, + "k_freq": 0.0, + "theta0": -0.9893118272453896, + "omega0": -1.1517172650095255 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/291/simulation_code.py b/scipy/simple_pendulum/291/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..f953d497c6b8ff0cdbe7ff567f0877a6cca81361 --- /dev/null +++ b/scipy/simple_pendulum/291/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 1.985317149343413 +m = 1.3543539575820556 +g = 9.8 +b = 0.5459261597934555 +A = 0.0 +k_freq = 0.0 +theta0 = -0.989312 +omega0 = -1.151717 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/291/video.mp4 b/scipy/simple_pendulum/291/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f0d2828ef7e9c3e5af825d4d044b138d1cf9d2da --- /dev/null +++ b/scipy/simple_pendulum/291/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1877b6c31a8714f40aa1bceabbb1fd9eb992cdb1d357f3f76a7f9f1dd42bb0f +size 19491 diff --git a/scipy/simple_pendulum/312/cot.json b/scipy/simple_pendulum/312/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..1e83c1941bb4f59231f6597a2a665a7ed307bb5c --- /dev/null +++ b/scipy/simple_pendulum/312/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=1.154 kg) swings on a rigid rod (L=1.085 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.823 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 2.091 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.1007 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 1.0849505187077768, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 1.1541228656471134, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.8225973156956716, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": -0.7673190158807073, + "unit": "", + "description": "" + }, + "omega0": { + "value": 0.8856744423875038, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/312/params.json b/scipy/simple_pendulum/312/params.json new file mode 100644 index 0000000000000000000000000000000000000000..84fb613c430792aa50fd54267ae99e472ca0b077 --- /dev/null +++ b/scipy/simple_pendulum/312/params.json @@ -0,0 +1,10 @@ +{ + "L": 1.0849505187077768, + "m": 1.1541228656471134, + "g": 9.8, + "b": 0.8225973156956716, + "A": 0.0, + "k_freq": 0.0, + "theta0": -0.7673190158807073, + "omega0": 0.8856744423875038 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/312/simulation_code.py b/scipy/simple_pendulum/312/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..77d2531abf8127b8903ffee4acb0465a5975e183 --- /dev/null +++ b/scipy/simple_pendulum/312/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 1.0849505187077768 +m = 1.1541228656471134 +g = 9.8 +b = 0.8225973156956716 +A = 0.0 +k_freq = 0.0 +theta0 = -0.767319 +omega0 = 0.885674 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/312/video.mp4 b/scipy/simple_pendulum/312/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..bf9f297be50209cf49e84abd8b92986d7a76b6ac --- /dev/null +++ b/scipy/simple_pendulum/312/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c55068076d8b65b93a537ba5e9f5e1a9592906ae38b00f1d46ea6afdae33a8c +size 14164 diff --git a/scipy/simple_pendulum/342/cot.json b/scipy/simple_pendulum/342/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..3a371c86566c80f8faf63e080cdca0f6dc28de41 --- /dev/null +++ b/scipy/simple_pendulum/342/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=1.881 kg) swings on a rigid rod (L=1.322 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.483 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 2.308 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0270 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 1.322259956741556, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 1.8812506757161336, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.48291024558609186, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": 0.42691573272259875, + "unit": "", + "description": "" + }, + "omega0": { + "value": 0.865603536370211, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/342/params.json b/scipy/simple_pendulum/342/params.json new file mode 100644 index 0000000000000000000000000000000000000000..e925da56090f186636396ae686bd261607b25fb8 --- /dev/null +++ b/scipy/simple_pendulum/342/params.json @@ -0,0 +1,10 @@ +{ + "L": 1.322259956741556, + "m": 1.8812506757161336, + "g": 9.8, + "b": 0.48291024558609186, + "A": 0.0, + "k_freq": 0.0, + "theta0": 0.42691573272259875, + "omega0": 0.865603536370211 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/342/simulation_code.py b/scipy/simple_pendulum/342/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..71c33496b1320f4e97a7fdae3db3928dfedd18fc --- /dev/null +++ b/scipy/simple_pendulum/342/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 1.322259956741556 +m = 1.8812506757161336 +g = 9.8 +b = 0.48291024558609186 +A = 0.0 +k_freq = 0.0 +theta0 = 0.426916 +omega0 = 0.865604 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/342/video.mp4 b/scipy/simple_pendulum/342/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..49dc3ce89f57b6cc06b36a559195104d35d5ce28 --- /dev/null +++ b/scipy/simple_pendulum/342/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6adb64557ea3c0db317104cf830f5556840b6ee2b3440d1ca315cb65f61f9cc1 +size 15322 diff --git a/scipy/simple_pendulum/384/cot.json b/scipy/simple_pendulum/384/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..8e50fc1c511fff0d1b258992c392e3ba357cb696 --- /dev/null +++ b/scipy/simple_pendulum/384/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=1.943 kg) swings on a rigid rod (L=1.358 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.904 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 2.339 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0470 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 1.3577866152812446, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 1.9426225871701344, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.9043079134505962, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": -0.14241045052608903, + "unit": "", + "description": "" + }, + "omega0": { + "value": -1.453082425551408, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/384/params.json b/scipy/simple_pendulum/384/params.json new file mode 100644 index 0000000000000000000000000000000000000000..d3fb63070a9349839cb1f3fd4302b9ccec354462 --- /dev/null +++ b/scipy/simple_pendulum/384/params.json @@ -0,0 +1,10 @@ +{ + "L": 1.3577866152812446, + "m": 1.9426225871701344, + "g": 9.8, + "b": 0.9043079134505962, + "A": 0.0, + "k_freq": 0.0, + "theta0": -0.14241045052608903, + "omega0": -1.453082425551408 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/384/simulation_code.py b/scipy/simple_pendulum/384/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8a7d6b2da8170f720e1f08c2faf4420267e20dcb --- /dev/null +++ b/scipy/simple_pendulum/384/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 1.3577866152812446 +m = 1.9426225871701344 +g = 9.8 +b = 0.9043079134505962 +A = 0.0 +k_freq = 0.0 +theta0 = -0.142410 +omega0 = -1.453082 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/384/video.mp4 b/scipy/simple_pendulum/384/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..cad4ca0f28ea4a7937406cf082cbe6f514987fbb --- /dev/null +++ b/scipy/simple_pendulum/384/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6013669824d7d62de9e64ec05b465fed69306317da0635cc3d643be54ae5199e +size 14543 diff --git a/scipy/simple_pendulum/435/cot.json b/scipy/simple_pendulum/435/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4034102fa29f4da4016e06a19f48e90167b267b0 --- /dev/null +++ b/scipy/simple_pendulum/435/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=1.365 kg) swings on a rigid rod (L=1.598 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.136 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 2.538 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0078 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 1.5984920446864335, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 1.3652568151447508, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.13552422115173968, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": 0.9607950584411478, + "unit": "", + "description": "" + }, + "omega0": { + "value": -1.086853161978845, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/435/params.json b/scipy/simple_pendulum/435/params.json new file mode 100644 index 0000000000000000000000000000000000000000..f1b608bcde8c6babf9793b86240e7b06bae02a33 --- /dev/null +++ b/scipy/simple_pendulum/435/params.json @@ -0,0 +1,10 @@ +{ + "L": 1.5984920446864335, + "m": 1.3652568151447508, + "g": 9.8, + "b": 0.13552422115173968, + "A": 0.0, + "k_freq": 0.0, + "theta0": 0.9607950584411478, + "omega0": -1.086853161978845 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/435/simulation_code.py b/scipy/simple_pendulum/435/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..f77a04f9eb0b900090a6ea2516a84afa8afd0323 --- /dev/null +++ b/scipy/simple_pendulum/435/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 1.5984920446864335 +m = 1.3652568151447508 +g = 9.8 +b = 0.13552422115173968 +A = 0.0 +k_freq = 0.0 +theta0 = 0.960795 +omega0 = -1.086853 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/435/video.mp4 b/scipy/simple_pendulum/435/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6cd2a51ebced6a388b85e4abd6084cb27676b88b --- /dev/null +++ b/scipy/simple_pendulum/435/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd4b49b86cf89b81bf9d602876878cc18a31dd8205391bf9015cb299a09bbe4c +size 21135 diff --git a/scipy/simple_pendulum/451/cot.json b/scipy/simple_pendulum/451/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..da3df19205a33e186832b409a592faa3b0291313 --- /dev/null +++ b/scipy/simple_pendulum/451/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "simple_pendulum", + "physical_observation": "A point mass (m=0.847 kg) swings on a rigid rod (L=1.310 m) from a fixed pivot. The oscillation amplitude decays due to damping (b=0.467 kg \\cdot m^2/s).", + "physical_law": { + "name": "Newton's Second Law for Rotational Motion (\\tau = I\\alpha)", + "statement": "The net torque on a body about a fixed axis equals the moment of inertia times the angular acceleration.", + "formula": "I\\ddot{\\theta} = \\Sigma\\tau \\rightarrow mL^2\\ddot{\\theta} = -mgL \\sin(\\theta) - b\\dot{\\theta}" + }, + "ode_system": { + "state_variables": [ + "\\theta (angle, rad)", + "\\omega = \\dot{\\theta} (angular velocity, rad/s)" + ], + "equations_latex": [ + "\\dot{\\theta} = \\omega", + "\\dot{\\omega} = -(g/L) \\sin(\\theta) - (b/(mL^2)) \\omega" + ], + "equations_python": [ + "theta_dot = omega", + "omega_dot = -(g/L) * np.sin ( theta ) - (b/(mL**2)) * omega" + ] + }, + "derivation_steps": [ + "Identify the generalized coordinate: \\theta = angle of the rod from the downward vertical.", + "Moment of inertia for a point mass at distance L from the pivot: I = m L^2.", + "Torques about the pivot:", + " \\tau_gravity = -m g L \\sin(\\theta) [restoring, acts opposite to displacement]", + " \\tau_damping = -b \\dot{\\theta} [b has units kg \\cdot m^2/s; opposes angular velocity]", + " \\tau_drive = 0 [undriven system]", + "Newton's second law for rotation: I \\ddot{\\theta} = \\Sigma\\tau", + " m L^2 \\ddot{\\theta} = -m g L \\sin(\\theta) - b \\dot{\\theta}", + "Divide by m L^2 to obtain the state-space form:", + " \\ddot{\\theta} = -(g/L) \\sin(\\theta) - (b/mL^2) \\dot{\\theta}" + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Matches the 4th-order Runge-Kutta solver used in myphysicslab TypeScript source." + }, + "code_validation": { + "ode_source": "Newton's 2nd law for rotation; exact translation of PendulumSim.ts evaluate()", + "energy_check": "Total energy E = \\tfrac{1}{2} mL^2\\omega^2 + mgL(1-\\cos(\\theta)) should decrease monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural period (small angles): T_0 \\approx 2.297 s", + "Damping ratio \\zeta = b/(2mL^2\\omega_0) = 0.0587 < 1 \\rightarrow underdamped oscillation" + ], + "parameters": { + "L": { + "value": 1.3099022326262473, + "unit": "m", + "description": "Rod length" + }, + "m": { + "value": 0.8473171893318376, + "unit": "kg", + "description": "Bob mass" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "b": { + "value": 0.46690308154074256, + "unit": "kg \\cdot m^2/s", + "description": "Angular damping coefficient" + }, + "A": { + "value": 0.0, + "unit": "N \\cdot m", + "description": "Driving torque amplitude" + }, + "k_freq": { + "value": 0.0, + "unit": "rad/s", + "description": "Driving angular frequency" + }, + "theta0": { + "value": -0.9918879756660004, + "unit": "", + "description": "" + }, + "omega0": { + "value": -0.7312740032972802, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/simple_pendulum/451/params.json b/scipy/simple_pendulum/451/params.json new file mode 100644 index 0000000000000000000000000000000000000000..28b3a181b9cd53142e1c2d7e864d7618a5ebb2bd --- /dev/null +++ b/scipy/simple_pendulum/451/params.json @@ -0,0 +1,10 @@ +{ + "L": 1.3099022326262473, + "m": 0.8473171893318376, + "g": 9.8, + "b": 0.46690308154074256, + "A": 0.0, + "k_freq": 0.0, + "theta0": -0.9918879756660004, + "omega0": -0.7312740032972802 +} \ No newline at end of file diff --git a/scipy/simple_pendulum/451/simulation_code.py b/scipy/simple_pendulum/451/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..1ab78c508e4335ffab283d839dbe7580db4394f1 --- /dev/null +++ b/scipy/simple_pendulum/451/simulation_code.py @@ -0,0 +1,64 @@ +""" +Simple Pendulum — auto-generated simulation script. +Physics: θ̈ = -(g/L)·sin(θ) - (b/mL²)·ω + (A/mL²)·cos(k_freq·t) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + + +L = 1.3099022326262473 +m = 0.8473171893318376 +g = 9.8 +b = 0.46690308154074256 +A = 0.0 +k_freq = 0.0 +theta0 = -0.991888 +omega0 = -0.731274 +duration = 12 + + +def ode(t, y): + theta, omega = y + mlsq = m * L * L + dtheta = omega + domega = -(g / L) * np.sin(theta) - (b / mlsq) * omega + (A / mlsq) * np.cos(k_freq * t) + return [dtheta, domega] + + +fps = 30 +t_eval = np.linspace(0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0, duration), [theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t, theta = sol.t, sol.y[0] + +bob_x = L * np.sin(theta) +bob_y = -L * np.cos(theta) + + +pad = L * 0.35 +fig, ax = plt.subplots(figsize=(5, 5), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-L - pad, L + pad); ax.set_ylim(-L - pad, L * 0.4) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([0], [0], "o", color="white", ms=7, zorder=5) + +rod, = ax.plot([], [], "-", color="#a8dadc", lw=2.5, zorder=3) +bob_p, = ax.plot([], [], "o", color="#e63946", ms=14, zorder=4) +trail, = ax.plot([], [], "-", color="#e63946", alpha=0.35, lw=1.2, zorder=2) +tx, ty = [], [] + +def update(frame): + rod.set_data([0, bob_x[frame]], [0, bob_y[frame]]) + bob_p.set_data([bob_x[frame]], [bob_y[frame]]) + tx.append(bob_x[frame]); ty.append(bob_y[frame]) + if len(tx) > 90: tx.pop(0); ty.pop(0) + trail.set_data(tx, ty) + return rod, bob_p, trail + +ani = animation.FuncAnimation(fig, update, frames=len(t), interval=1000/fps, blit=True) +writer = animation.FFMpegWriter(fps=fps, bitrate=1800) +ani.save("simple_pendulum.mp4", writer=writer, dpi=120) +plt.close() +print("Saved simple_pendulum.mp4") diff --git a/scipy/simple_pendulum/451/video.mp4 b/scipy/simple_pendulum/451/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e2c1842dc3ba1019977c3e25311d6b3202bb8ac6 --- /dev/null +++ b/scipy/simple_pendulum/451/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04770c4036502bd1d4abc3fbe63d532084fc5f00c2f71d7748b786c0a52d232e +size 17900 diff --git a/scipy/single_spring/005/cot.json b/scipy/single_spring/005/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d612635c62f80ed806711a09ca816a1006629ffa --- /dev/null +++ b/scipy/single_spring/005/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.619 kg) is attached to a spring (k=1.571 N/m) fixed to a wall and displaced u_0=1.028 m from equilibrium. Damping coefficient b=2.865 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 0.9849, + "T_0_seconds": 6.3796, + "damping_ratio_zeta": 0.8981, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 0.4332 rad/s, period T_d = 14.5041 s" + ], + "parameters": { + "k": { + "value": 1.5707460882786841, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.6193240744252198, + "unit": "kg", + "description": "" + }, + "b": { + "value": 2.8645796724440036, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": 1.0275360513562117, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": 1.237503022651964, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/005/params.json b/scipy/single_spring/005/params.json new file mode 100644 index 0000000000000000000000000000000000000000..2d80558c013323d27b7736945086d0c62a7b7d3b --- /dev/null +++ b/scipy/single_spring/005/params.json @@ -0,0 +1,7 @@ +{ + "k": 1.5707460882786841, + "m": 1.6193240744252198, + "b": 2.8645796724440036, + "u0": 1.0275360513562117, + "v0": 1.237503022651964 +} \ No newline at end of file diff --git a/scipy/single_spring/005/simulation_code.py b/scipy/single_spring/005/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..f17869863d8f30587cc32cca7eb2b6e3895424d5 --- /dev/null +++ b/scipy/single_spring/005/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=1.5707460882786841 N/m, m=1.6193240744252198 kg, b=2.8645796724440036 kg/s + ω₀ = 0.9849 rad/s, ζ = 0.8981 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 1.5707460882786841, 1.6193240744252198, 2.8645796724440036 +u0, v0 = 1.027536, 1.237503 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/005/video.mp4 b/scipy/single_spring/005/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..d5dfb3dd3644fdb00b91e59136160dd543058624 --- /dev/null +++ b/scipy/single_spring/005/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e97766fa49e588f2a359e3e17403212b6a01f3ec098f7e7ab79e0b07e65a63e +size 20306 diff --git a/scipy/single_spring/108/cot.json b/scipy/single_spring/108/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..04f6b362fc6636483e3076891b9ed3442081b6c2 --- /dev/null +++ b/scipy/single_spring/108/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.441 kg) is attached to a spring (k=9.110 N/m) fixed to a wall and displaced u_0=-1.389 m from equilibrium. Damping coefficient b=0.171 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 2.514, + "T_0_seconds": 2.4992, + "damping_ratio_zeta": 0.0235, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 2.5133 rad/s, period T_d = 2.4999 s" + ], + "parameters": { + "k": { + "value": 9.1095616971194, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.4413003283640284, + "unit": "kg", + "description": "" + }, + "b": { + "value": 0.17065337114226253, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": -1.3888494475370265, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": 0.8556132165452186, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/108/params.json b/scipy/single_spring/108/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c7d83222cf6e017b261efec99892f8c055057051 --- /dev/null +++ b/scipy/single_spring/108/params.json @@ -0,0 +1,7 @@ +{ + "k": 9.1095616971194, + "m": 1.4413003283640284, + "b": 0.17065337114226253, + "u0": -1.3888494475370265, + "v0": 0.8556132165452186 +} \ No newline at end of file diff --git a/scipy/single_spring/108/simulation_code.py b/scipy/single_spring/108/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..2358c9503997c9ee12ea75f87759c57d6a9b94a9 --- /dev/null +++ b/scipy/single_spring/108/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=9.1095616971194 N/m, m=1.4413003283640284 kg, b=0.17065337114226253 kg/s + ω₀ = 2.5140 rad/s, ζ = 0.0235 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 9.1095616971194, 1.4413003283640284, 0.17065337114226253 +u0, v0 = -1.388849, 0.855613 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/108/video.mp4 b/scipy/single_spring/108/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1623750850c21a52f2c38fbd09a40911a291e6b7 --- /dev/null +++ b/scipy/single_spring/108/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:867ce340af183c19d46255686af3f6a8b3f60d6ba78d267d0616bc4e8741876b +size 32540 diff --git a/scipy/single_spring/132/cot.json b/scipy/single_spring/132/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..b0f5eb5fce58fc94815a275886011e68aabc55f6 --- /dev/null +++ b/scipy/single_spring/132/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.116 kg) is attached to a spring (k=5.313 N/m) fixed to a wall and displaced u_0=-1.325 m from equilibrium. Damping coefficient b=0.253 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 2.1823, + "T_0_seconds": 2.8791, + "damping_ratio_zeta": 0.052, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 2.1794 rad/s, period T_d = 2.8830 s" + ], + "parameters": { + "k": { + "value": 5.312948750871412, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.1155693318111264, + "unit": "kg", + "description": "" + }, + "b": { + "value": 0.25320508575696365, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": -1.3250576955617444, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": -0.44725687608220355, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/132/params.json b/scipy/single_spring/132/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8ee0832cac38b6488bcedea7231a46d9cea9802a --- /dev/null +++ b/scipy/single_spring/132/params.json @@ -0,0 +1,7 @@ +{ + "k": 5.312948750871412, + "m": 1.1155693318111264, + "b": 0.25320508575696365, + "u0": -1.3250576955617444, + "v0": -0.44725687608220355 +} \ No newline at end of file diff --git a/scipy/single_spring/132/simulation_code.py b/scipy/single_spring/132/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..9d0316e6ceaaa80d20c8c47c4737236c9d5c1efb --- /dev/null +++ b/scipy/single_spring/132/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=5.312948750871412 N/m, m=1.1155693318111264 kg, b=0.25320508575696365 kg/s + ω₀ = 2.1823 rad/s, ζ = 0.0520 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 5.312948750871412, 1.1155693318111264, 0.25320508575696365 +u0, v0 = -1.325058, -0.447257 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/132/video.mp4 b/scipy/single_spring/132/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9444d58024bcd29aa7fb5645908454ed9b92b852 --- /dev/null +++ b/scipy/single_spring/132/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6fafc893f8da2e133d337015f6e6cc14c86765fae2e0c18a82cb655cec7237d6 +size 29225 diff --git a/scipy/single_spring/141/cot.json b/scipy/single_spring/141/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..96bcc96a0893e3d8c9173ed7b9fa9eebb932595e --- /dev/null +++ b/scipy/single_spring/141/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.434 kg) is attached to a spring (k=8.283 N/m) fixed to a wall and displaced u_0=-1.592 m from equilibrium. Damping coefficient b=1.539 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 2.4038, + "T_0_seconds": 2.6139, + "damping_ratio_zeta": 0.2233, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 2.3431 rad/s, period T_d = 2.6816 s" + ], + "parameters": { + "k": { + "value": 8.283472245678874, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.4335605485198968, + "unit": "kg", + "description": "" + }, + "b": { + "value": 1.539143149056832, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": -1.5923677487095564, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": -1.3757276275870725, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/141/params.json b/scipy/single_spring/141/params.json new file mode 100644 index 0000000000000000000000000000000000000000..9abbe281b2d65e04a0e942a49722743062576569 --- /dev/null +++ b/scipy/single_spring/141/params.json @@ -0,0 +1,7 @@ +{ + "k": 8.283472245678874, + "m": 1.4335605485198968, + "b": 1.539143149056832, + "u0": -1.5923677487095564, + "v0": -1.3757276275870725 +} \ No newline at end of file diff --git a/scipy/single_spring/141/simulation_code.py b/scipy/single_spring/141/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..aea7960eca2df7f5cdeae79fdce398fc96b26824 --- /dev/null +++ b/scipy/single_spring/141/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=8.283472245678874 N/m, m=1.4335605485198968 kg, b=1.539143149056832 kg/s + ω₀ = 2.4038 rad/s, ζ = 0.2233 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 8.283472245678874, 1.4335605485198968, 1.539143149056832 +u0, v0 = -1.592368, -1.375728 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/141/video.mp4 b/scipy/single_spring/141/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..5009ff99b5a6dc28381ba2b03cb3ada4cb3474ed --- /dev/null +++ b/scipy/single_spring/141/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28f70f465d81ee1a15346b87955755a2ff9ca92dca7dbce74fdf70f72c322d78 +size 20820 diff --git a/scipy/single_spring/143/cot.json b/scipy/single_spring/143/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d8f5cfb4437c4594eff47e423742063e54696880 --- /dev/null +++ b/scipy/single_spring/143/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.278 kg) is attached to a spring (k=1.136 N/m) fixed to a wall and displaced u_0=1.184 m from equilibrium. Damping coefficient b=2.086 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 0.9429, + "T_0_seconds": 6.6638, + "damping_ratio_zeta": 0.8657, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 0.4719 rad/s, period T_d = 13.3142 s" + ], + "parameters": { + "k": { + "value": 1.1360763180500533, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.2779007938225468, + "unit": "kg", + "description": "" + }, + "b": { + "value": 2.0862503119370666, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": 1.183685347016282, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": -2.436716346685249, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/143/params.json b/scipy/single_spring/143/params.json new file mode 100644 index 0000000000000000000000000000000000000000..4415bbf57315bd5b6655d28f25c7cc0a1440ea0a --- /dev/null +++ b/scipy/single_spring/143/params.json @@ -0,0 +1,7 @@ +{ + "k": 1.1360763180500533, + "m": 1.2779007938225468, + "b": 2.0862503119370666, + "u0": 1.183685347016282, + "v0": -2.436716346685249 +} \ No newline at end of file diff --git a/scipy/single_spring/143/simulation_code.py b/scipy/single_spring/143/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..49a28a10281eb13e5c1ccd1ef961b287ae8c1571 --- /dev/null +++ b/scipy/single_spring/143/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=1.1360763180500533 N/m, m=1.2779007938225468 kg, b=2.0862503119370666 kg/s + ω₀ = 0.9429 rad/s, ζ = 0.8657 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 1.1360763180500533, 1.2779007938225468, 2.0862503119370666 +u0, v0 = 1.183685, -2.436716 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/143/video.mp4 b/scipy/single_spring/143/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0f53a1458728d645565d8ab0a868631d69f940a7 --- /dev/null +++ b/scipy/single_spring/143/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84194f380d22a2abcc66f67efd7c6c779a6129b7a3921d1bce982eb5d2bf8ecc +size 20993 diff --git a/scipy/single_spring/174/cot.json b/scipy/single_spring/174/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..1be097c7e312508f78375ff18c768f0486f850a6 --- /dev/null +++ b/scipy/single_spring/174/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.642 kg) is attached to a spring (k=3.077 N/m) fixed to a wall and displaced u_0=-0.202 m from equilibrium. Damping coefficient b=2.936 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 1.3689, + "T_0_seconds": 4.5899, + "damping_ratio_zeta": 0.6532, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 1.0365 rad/s, period T_d = 6.0617 s" + ], + "parameters": { + "k": { + "value": 3.0769922083346897, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.6419969459907846, + "unit": "kg", + "description": "" + }, + "b": { + "value": 2.9364153257606667, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": -0.20210106311943132, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": 0.8941482635722462, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/174/params.json b/scipy/single_spring/174/params.json new file mode 100644 index 0000000000000000000000000000000000000000..1f9f12f178491bf8860356a538981c91d1c5de92 --- /dev/null +++ b/scipy/single_spring/174/params.json @@ -0,0 +1,7 @@ +{ + "k": 3.0769922083346897, + "m": 1.6419969459907846, + "b": 2.9364153257606667, + "u0": -0.20210106311943132, + "v0": 0.8941482635722462 +} \ No newline at end of file diff --git a/scipy/single_spring/174/simulation_code.py b/scipy/single_spring/174/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..86daee7a55de042a8758edd4c50b2a1e5e7a57f3 --- /dev/null +++ b/scipy/single_spring/174/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=3.0769922083346897 N/m, m=1.6419969459907846 kg, b=2.9364153257606667 kg/s + ω₀ = 1.3689 rad/s, ζ = 0.6532 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 3.0769922083346897, 1.6419969459907846, 2.9364153257606667 +u0, v0 = -0.202101, 0.894148 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/174/video.mp4 b/scipy/single_spring/174/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..647d0904b9b127bc1c57d8c6f9b4d73473a893a6 --- /dev/null +++ b/scipy/single_spring/174/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36ca63c6b11ce10e62e702d0a78fc01d5c1919adf19c00a283d97ea974a8b79d +size 16779 diff --git a/scipy/single_spring/181/cot.json b/scipy/single_spring/181/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..204432b2a4c9de1b3abc4fb420184f5f33440c32 --- /dev/null +++ b/scipy/single_spring/181/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=0.925 kg) is attached to a spring (k=1.410 N/m) fixed to a wall and displaced u_0=-1.624 m from equilibrium. Damping coefficient b=2.631 kg/s. Motion is overdamped (non-oscillatory decay).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 1.2346, + "T_0_seconds": 5.0894, + "damping_ratio_zeta": 1.1523, + "regime": "overdamped (non-oscillatory decay)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "System returns exponentially without oscillating." + ], + "parameters": { + "k": { + "value": 1.409595515710188, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 0.9248587429664432, + "unit": "kg", + "description": "" + }, + "b": { + "value": 2.6314198292522426, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": -1.623595376942622, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": 1.4246306029449745, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/181/params.json b/scipy/single_spring/181/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ca00d61406d8c76f031fccbce2b5aebea53fd6b5 --- /dev/null +++ b/scipy/single_spring/181/params.json @@ -0,0 +1,7 @@ +{ + "k": 1.409595515710188, + "m": 0.9248587429664432, + "b": 2.6314198292522426, + "u0": -1.623595376942622, + "v0": 1.4246306029449745 +} \ No newline at end of file diff --git a/scipy/single_spring/181/simulation_code.py b/scipy/single_spring/181/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..526f575733f770c4ab973f95f08bc66cf9f5fc07 --- /dev/null +++ b/scipy/single_spring/181/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=1.409595515710188 N/m, m=0.9248587429664432 kg, b=2.6314198292522426 kg/s + ω₀ = 1.2346 rad/s, ζ = 1.1523 (overdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 1.409595515710188, 0.9248587429664432, 2.6314198292522426 +u0, v0 = -1.623595, 1.424631 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/181/video.mp4 b/scipy/single_spring/181/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..44e86670071faf4f825e6aa12f4a0f00a99758dd --- /dev/null +++ b/scipy/single_spring/181/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e3152806ebf4ba479077a8ac34b1f382df531708d806312407606923430ee8f +size 19472 diff --git a/scipy/single_spring/249/cot.json b/scipy/single_spring/249/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..8e30a46b0dc30a3770364aae447c881b9dfe0ac1 --- /dev/null +++ b/scipy/single_spring/249/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=0.801 kg) is attached to a spring (k=4.794 N/m) fixed to a wall and displaced u_0=-1.494 m from equilibrium. Damping coefficient b=2.343 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 2.447, + "T_0_seconds": 2.5677, + "damping_ratio_zeta": 0.5979, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 1.9615 rad/s, period T_d = 3.2032 s" + ], + "parameters": { + "k": { + "value": 4.794399723828906, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 0.8006615029030768, + "unit": "kg", + "description": "" + }, + "b": { + "value": 2.3428085894220576, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": -1.4938773464000463, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": 1.2651593107302261, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/249/params.json b/scipy/single_spring/249/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ec98e05e2444ef15ef3220fb17031e29508e49b9 --- /dev/null +++ b/scipy/single_spring/249/params.json @@ -0,0 +1,7 @@ +{ + "k": 4.794399723828906, + "m": 0.8006615029030768, + "b": 2.3428085894220576, + "u0": -1.4938773464000463, + "v0": 1.2651593107302261 +} \ No newline at end of file diff --git a/scipy/single_spring/249/simulation_code.py b/scipy/single_spring/249/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..400537a4ee93286b750801ebd859e133debb21f2 --- /dev/null +++ b/scipy/single_spring/249/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=4.794399723828906 N/m, m=0.8006615029030768 kg, b=2.3428085894220576 kg/s + ω₀ = 2.4470 rad/s, ζ = 0.5979 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 4.794399723828906, 0.8006615029030768, 2.3428085894220576 +u0, v0 = -1.493877, 1.265159 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/249/video.mp4 b/scipy/single_spring/249/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4c91bb4931ac7d3878a02cdfca886cd128b15d5b --- /dev/null +++ b/scipy/single_spring/249/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3fe94ccdfc268a5ce0c08c7a5419c77709aa3e5103f8f256fec6099e93ecb813 +size 15798 diff --git a/scipy/single_spring/264/cot.json b/scipy/single_spring/264/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5bcf9b48af3ea5d4dfd4290eb71b9f015acc5a68 --- /dev/null +++ b/scipy/single_spring/264/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=0.817 kg) is attached to a spring (k=7.764 N/m) fixed to a wall and displaced u_0=1.498 m from equilibrium. Damping coefficient b=1.989 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 3.0826, + "T_0_seconds": 2.0383, + "damping_ratio_zeta": 0.395, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 2.8320 rad/s, period T_d = 2.2186 s" + ], + "parameters": { + "k": { + "value": 7.763821898804275, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 0.8170258339770693, + "unit": "kg", + "description": "" + }, + "b": { + "value": 1.9894966629423159, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": 1.4980891300959964, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": -2.2056359767548246, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/264/params.json b/scipy/single_spring/264/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c05c935a0ff00e0a145cebd48e68633443bad7f8 --- /dev/null +++ b/scipy/single_spring/264/params.json @@ -0,0 +1,7 @@ +{ + "k": 7.763821898804275, + "m": 0.8170258339770693, + "b": 1.9894966629423159, + "u0": 1.4980891300959964, + "v0": -2.2056359767548246 +} \ No newline at end of file diff --git a/scipy/single_spring/264/simulation_code.py b/scipy/single_spring/264/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..3ea02bcf47e73e7ef778cbfd0b127a4f7ed412bb --- /dev/null +++ b/scipy/single_spring/264/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=7.763821898804275 N/m, m=0.8170258339770693 kg, b=1.9894966629423159 kg/s + ω₀ = 3.0826 rad/s, ζ = 0.3950 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 7.763821898804275, 0.8170258339770693, 1.9894966629423159 +u0, v0 = 1.498089, -2.205636 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/264/video.mp4 b/scipy/single_spring/264/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..85765f26b271bdbe085c262a03145705dd97a38d --- /dev/null +++ b/scipy/single_spring/264/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27a3a29f9ab9884dddce9eaba6f0083d49d2b23044ec2a4551d1f466e2ee95e6 +size 16885 diff --git a/scipy/single_spring/284/cot.json b/scipy/single_spring/284/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..428d8b4dcb9ea69fc7edd3c5b651e1ba64d9670b --- /dev/null +++ b/scipy/single_spring/284/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.018 kg) is attached to a spring (k=6.038 N/m) fixed to a wall and displaced u_0=0.648 m from equilibrium. Damping coefficient b=0.490 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 2.4351, + "T_0_seconds": 2.5802, + "damping_ratio_zeta": 0.0989, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 2.4232 rad/s, period T_d = 2.5929 s" + ], + "parameters": { + "k": { + "value": 6.037603266172854, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.0181600339193784, + "unit": "kg", + "description": "" + }, + "b": { + "value": 0.4902887377960998, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": 0.6479648686563899, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": 1.642048417688585, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/284/params.json b/scipy/single_spring/284/params.json new file mode 100644 index 0000000000000000000000000000000000000000..98af67d4fb80becff11a0719f13b190b35768fa3 --- /dev/null +++ b/scipy/single_spring/284/params.json @@ -0,0 +1,7 @@ +{ + "k": 6.037603266172854, + "m": 1.0181600339193784, + "b": 0.4902887377960998, + "u0": 0.6479648686563899, + "v0": 1.642048417688585 +} \ No newline at end of file diff --git a/scipy/single_spring/284/simulation_code.py b/scipy/single_spring/284/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b5f85c0df24f67081ae495e994f1a9ec36f4b89d --- /dev/null +++ b/scipy/single_spring/284/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=6.037603266172854 N/m, m=1.0181600339193784 kg, b=0.4902887377960998 kg/s + ω₀ = 2.4351 rad/s, ζ = 0.0989 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 6.037603266172854, 1.0181600339193784, 0.4902887377960998 +u0, v0 = 0.647965, 1.642048 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/284/video.mp4 b/scipy/single_spring/284/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..01628c1d3e96f10cf48456cc7bf01d9cc5fe40ad --- /dev/null +++ b/scipy/single_spring/284/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b87c6f28f1be4a4f9f5202c484f1f78a0c0d631bf6a2cd6151a62d962a3e4094 +size 30803 diff --git a/scipy/single_spring/305/cot.json b/scipy/single_spring/305/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..0a424261ea689959c9b7203b69e6f8b15f62b060 --- /dev/null +++ b/scipy/single_spring/305/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.000 kg) is attached to a spring (k=6.574 N/m) fixed to a wall and displaced u_0=0.621 m from equilibrium. Damping coefficient b=0.315 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 2.5637, + "T_0_seconds": 2.4508, + "damping_ratio_zeta": 0.0615, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 2.5588 rad/s, period T_d = 2.4555 s" + ], + "parameters": { + "k": { + "value": 6.573688883512583, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.0001734606341124, + "unit": "kg", + "description": "" + }, + "b": { + "value": 0.3152605499572627, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": 0.6209054817958637, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": 2.248409707757813, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/305/params.json b/scipy/single_spring/305/params.json new file mode 100644 index 0000000000000000000000000000000000000000..f761533ce358dc908194013ce113d5feefdabc14 --- /dev/null +++ b/scipy/single_spring/305/params.json @@ -0,0 +1,7 @@ +{ + "k": 6.573688883512583, + "m": 1.0001734606341124, + "b": 0.3152605499572627, + "u0": 0.6209054817958637, + "v0": 2.248409707757813 +} \ No newline at end of file diff --git a/scipy/single_spring/305/simulation_code.py b/scipy/single_spring/305/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..429b9e5c39b583f880e6d642a3ae42e8d990b983 --- /dev/null +++ b/scipy/single_spring/305/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=6.573688883512583 N/m, m=1.0001734606341124 kg, b=0.3152605499572627 kg/s + ω₀ = 2.5637 rad/s, ζ = 0.0615 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 6.573688883512583, 1.0001734606341124, 0.3152605499572627 +u0, v0 = 0.620905, 2.248410 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/305/video.mp4 b/scipy/single_spring/305/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..64e7d2273de1ff88a7370211e5147e8b5575769f --- /dev/null +++ b/scipy/single_spring/305/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d07cea22720344b1e6b90f0238db3263bfdc52eb49eafbbf8c0a236d5a61e5c6 +size 35659 diff --git a/scipy/single_spring/359/cot.json b/scipy/single_spring/359/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..0f8a3f2638dd119fc4c84b0541fd36824fab080c --- /dev/null +++ b/scipy/single_spring/359/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=0.254 kg) is attached to a spring (k=4.132 N/m) fixed to a wall and displaced u_0=-1.943 m from equilibrium. Damping coefficient b=2.400 kg/s. Motion is overdamped (non-oscillatory decay).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 4.0309, + "T_0_seconds": 1.5588, + "damping_ratio_zeta": 1.1708, + "regime": "overdamped (non-oscillatory decay)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "System returns exponentially without oscillating." + ], + "parameters": { + "k": { + "value": 4.131900234758749, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 0.2543049972287708, + "unit": "kg", + "description": "" + }, + "b": { + "value": 2.4002673096529556, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": -1.9432994334253624, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": 1.9439795413383276, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/359/params.json b/scipy/single_spring/359/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b3c2ae4136f0022f67e8625dfb7dac73427e9c02 --- /dev/null +++ b/scipy/single_spring/359/params.json @@ -0,0 +1,7 @@ +{ + "k": 4.131900234758749, + "m": 0.2543049972287708, + "b": 2.4002673096529556, + "u0": -1.9432994334253624, + "v0": 1.9439795413383276 +} \ No newline at end of file diff --git a/scipy/single_spring/359/simulation_code.py b/scipy/single_spring/359/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..5231643ee83750ee0972636d280a9bf097059be8 --- /dev/null +++ b/scipy/single_spring/359/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=4.131900234758749 N/m, m=0.2543049972287708 kg, b=2.4002673096529556 kg/s + ω₀ = 4.0309 rad/s, ζ = 1.1708 (overdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 4.131900234758749, 0.2543049972287708, 2.4002673096529556 +u0, v0 = -1.943299, 1.943980 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/359/video.mp4 b/scipy/single_spring/359/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f740160abbea3c741a104a0a0548c01044d172d9 --- /dev/null +++ b/scipy/single_spring/359/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c812314888bec15a35bbbbd715f0e6ed97c7658726bfd68da397d0c2f7fcb51c +size 12905 diff --git a/scipy/single_spring/408/cot.json b/scipy/single_spring/408/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ffca2bba30a5466db62edb7b6830c6ed44f1347f --- /dev/null +++ b/scipy/single_spring/408/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.289 kg) is attached to a spring (k=3.101 N/m) fixed to a wall and displaced u_0=0.962 m from equilibrium. Damping coefficient b=0.683 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 1.551, + "T_0_seconds": 4.051, + "damping_ratio_zeta": 0.1708, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 1.5282 rad/s, period T_d = 4.1114 s" + ], + "parameters": { + "k": { + "value": 3.101431570481302, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.2892029127517515, + "unit": "kg", + "description": "" + }, + "b": { + "value": 0.6830551595388962, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": 0.9616144615452451, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": 0.27507542263546725, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/408/params.json b/scipy/single_spring/408/params.json new file mode 100644 index 0000000000000000000000000000000000000000..fed0abe41049f3bced5f23dfed7ee3392373c94c --- /dev/null +++ b/scipy/single_spring/408/params.json @@ -0,0 +1,7 @@ +{ + "k": 3.101431570481302, + "m": 1.2892029127517515, + "b": 0.6830551595388962, + "u0": 0.9616144615452451, + "v0": 0.27507542263546725 +} \ No newline at end of file diff --git a/scipy/single_spring/408/simulation_code.py b/scipy/single_spring/408/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..6d19ce52a766afcbec078e104a6c4bd7138563c4 --- /dev/null +++ b/scipy/single_spring/408/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=3.101431570481302 N/m, m=1.2892029127517515 kg, b=0.6830551595388962 kg/s + ω₀ = 1.5510 rad/s, ζ = 0.1708 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 3.101431570481302, 1.2892029127517515, 0.6830551595388962 +u0, v0 = 0.961614, 0.275075 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/408/video.mp4 b/scipy/single_spring/408/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ee64539bdb5cb2e7fb357ac42b12d5854ad36a45 --- /dev/null +++ b/scipy/single_spring/408/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8491f74e0e57451a9aa9e6bc4b59fae14c56820b3f9ae675454724620163aadc +size 23346 diff --git a/scipy/single_spring/450/cot.json b/scipy/single_spring/450/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..b379e7b1dc3653fb22407fc099f2f6f2e847a976 --- /dev/null +++ b/scipy/single_spring/450/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.996 kg) is attached to a spring (k=7.288 N/m) fixed to a wall and displaced u_0=1.138 m from equilibrium. Damping coefficient b=1.802 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 1.9108, + "T_0_seconds": 3.2883, + "damping_ratio_zeta": 0.2362, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 1.8567 rad/s, period T_d = 3.3840 s" + ], + "parameters": { + "k": { + "value": 7.2881121472534875, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.996152258020408, + "unit": "kg", + "description": "" + }, + "b": { + "value": 1.8018192887465134, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": 1.1375859219619877, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": -0.8498657161428822, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/450/params.json b/scipy/single_spring/450/params.json new file mode 100644 index 0000000000000000000000000000000000000000..df83f3a68c6b26e9754f77b33ced5b0e6a48bec1 --- /dev/null +++ b/scipy/single_spring/450/params.json @@ -0,0 +1,7 @@ +{ + "k": 7.2881121472534875, + "m": 1.996152258020408, + "b": 1.8018192887465134, + "u0": 1.1375859219619877, + "v0": -0.8498657161428822 +} \ No newline at end of file diff --git a/scipy/single_spring/450/simulation_code.py b/scipy/single_spring/450/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..898bc3fed26e1a4e8d15f33d0dda7235c36a8450 --- /dev/null +++ b/scipy/single_spring/450/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=7.2881121472534875 N/m, m=1.996152258020408 kg, b=1.8018192887465134 kg/s + ω₀ = 1.9108 rad/s, ζ = 0.2362 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 7.2881121472534875, 1.996152258020408, 1.8018192887465134 +u0, v0 = 1.137586, -0.849866 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/450/video.mp4 b/scipy/single_spring/450/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..596be72885b74fe03018f6e55b2f32f618a346d1 --- /dev/null +++ b/scipy/single_spring/450/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41240d72a1e10c8ae637d4f66043caeba6805614f6771cea5e2362f787d6976b +size 22096 diff --git a/scipy/single_spring/485/cot.json b/scipy/single_spring/485/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ed3fd0e4717a1ef282fbad5d40135fbaaf2789f0 --- /dev/null +++ b/scipy/single_spring/485/cot.json @@ -0,0 +1,77 @@ +{ + "simulation": "single_spring", + "physical_observation": "A block (m=1.966 kg) is attached to a spring (k=2.517 N/m) fixed to a wall and displaced u_0=0.672 m from equilibrium. Damping coefficient b=0.055 kg/s. Motion is underdamped (decaying oscillation).", + "physical_law": { + "name": "Newton's Second Law + Hooke's Law + Viscous Damping", + "statement": "\\SigmaF = ma. Spring force: F_s = -ku. Damping force: F_d = -bv.", + "formula": "m\\ddot{u} + bv + ku = 0 \\rightarrow \\ddot{u} = -(k/m)u - (b/m)\\dot{u}" + }, + "ode_system": { + "state_variables": [ + "u (displacement from equilibrium, m)", + "v = \\dot{u} (velocity, m/s)" + ], + "equations_latex": [ + "\\dot{u} = v", + "\\dot{v} = -(k/m) u - (b/m) v" + ], + "equations_python": [ + "u_dot = v", + "v_dot = -(k/m) * u - (b/m) * v" + ] + }, + "derivation_steps": [ + "Let u = x - x_eq (displacement from spring equilibrium position).", + "At x_eq: spring stretch = 0; spring force = 0.", + "For displacement u: spring force = -k u (Hooke's Law).", + "Viscous damping force = -b v (proportional to velocity).", + "Newton's 2nd law: m \\ddot{u} = -k u - b v.", + "Divide by m: \\ddot{u} = -(k/m) u - (b/m) v.", + "Equivalently: \\dot{v} = (-k \\cdot u - b \\cdot v) / m, the textbook damped-harmonic-oscillator form." + ], + "physical_constants_derived": { + "omega_0": 1.1314, + "T_0_seconds": 5.5534, + "damping_ratio_zeta": 0.0124, + "regime": "underdamped (decaying oscillation)" + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11" + }, + "code_validation": { + "ode_source": "Newton's 2nd law on a single mass under linear-spring + viscous-damping forces (textbook damped harmonic oscillator).", + "energy_check": "E = \\tfrac{1}{2} mv^2 + \\tfrac{1}{2} ku^2 decreases monotonically when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Damped oscillation frequency \\omega_d = 1.1313 rad/s, period T_d = 5.5538 s" + ], + "parameters": { + "k": { + "value": 2.516525093199455, + "unit": "N/m", + "description": "" + }, + "m": { + "value": 1.9658680433962639, + "unit": "kg", + "description": "" + }, + "b": { + "value": 0.0550505400589032, + "unit": "kg/s", + "description": "" + }, + "u0": { + "value": 0.6719602469309724, + "unit": "m", + "description": "Displacement from equilibrium" + }, + "v0": { + "value": -0.24801911044123415, + "unit": "m/s", + "description": "Velocity" + } + } +} diff --git a/scipy/single_spring/485/params.json b/scipy/single_spring/485/params.json new file mode 100644 index 0000000000000000000000000000000000000000..508e36692a9b8f719272597aabbbb377dc605215 --- /dev/null +++ b/scipy/single_spring/485/params.json @@ -0,0 +1,7 @@ +{ + "k": 2.516525093199455, + "m": 1.9658680433962639, + "b": 0.0550505400589032, + "u0": 0.6719602469309724, + "v0": -0.24801911044123415 +} \ No newline at end of file diff --git a/scipy/single_spring/485/simulation_code.py b/scipy/single_spring/485/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b771674ad1bc8e65e193d7e82c44f96958e57d60 --- /dev/null +++ b/scipy/single_spring/485/simulation_code.py @@ -0,0 +1,53 @@ +""" +Spring-Mass-Damper — auto-generated simulation script. +Physics (Newton's Second Law): + ü = -(k/m)·u - (b/m)·u̇ +Parameters: k=2.516525093199455 N/m, m=1.9658680433962639 kg, b=0.0550505400589032 kg/s + ω₀ = 1.1314 rad/s, ζ = 0.0124 (underdamped) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b = 2.516525093199455, 1.9658680433962639, 0.0550505400589032 +u0, v0 = 0.671960, -0.248019 +duration = 12 + +def ode(t, y): + u, v = y + return [v, (-k*u - b*v)/m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode,(0,duration),[u0,v0],t_eval=t_eval,method="RK45",rtol=1e-9,atol=1e-11) +u_arr = sol.y[0] + +wall_x, block_w, block_h, track_y = -3.5, 0.4, 0.4, 0.0 +x_max = wall_x + 2*abs(u0) + 2.5 +fig, ax = plt.subplots(figsize=(8,4),facecolor="#1a1a2e") +ax.set_facecolor("#16213e"); ax.set_xlim(wall_x-0.3,x_max); ax.set_ylim(-1.0,1.0) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(track_y-block_h/2,color="#4a4e69",lw=1.5,zorder=1) +ax.add_patch(patches.Rectangle((wall_x-0.2,-0.6),0.2,1.2, + facecolor="#4a4e69",edgecolor="#adb5bd",lw=1,hatch="////")) +ax.axvline(0,color="#4a4e69",lw=0.8,ls="--",alpha=0.5,zorder=1) +sp, = ax.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bp = patches.FancyBboxPatch((-block_w/2,track_y-block_h/2),block_w,block_h, + boxstyle="round,pad=0.02",lw=1.5,edgecolor="white",facecolor="#e63946") +ax.add_patch(bp) + +def spring_path_fn(x1,x2,n=8,r=0.15): + t=np.linspace(0,1,n*20+2) + env=np.where((t<0.08)|(t>0.92),0,np.sin(n*2*np.pi*(t-0.08)/(1-2*0.08))) + return x1+t*(x2-x1), track_y+r*env + +def update(f): + bx=u_arr[f]; bp.set_x(bx-block_w/2) + sx,sy=spring_path_fn(wall_x,bx-block_w/2); sp.set_data(sx,sy) + return (sp,) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("single_spring.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=120) +plt.close(); print("Saved single_spring.mp4") diff --git a/scipy/single_spring/485/video.mp4 b/scipy/single_spring/485/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ddb8c7faa02e052c17941c3ee36a2503107c7512 --- /dev/null +++ b/scipy/single_spring/485/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dbfacf22293ed2c4130aed48d95b526b48a32a46804508bf59d2e90114edec26 +size 28460 diff --git a/scipy/slab_springs_block_drop/087/cot.json b/scipy/slab_springs_block_drop/087/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..68facb185b3f6e1b25c71a4367f2c3fa2e09033c --- /dev/null +++ b/scipy/slab_springs_block_drop/087/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=0.762 kg, length L=1.388 m) is suspended above the floor by two vertical Hookean springs (each k=36.730 N/m, rest length L_0=0.610 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.340 kg) is released from rest at height H_drop=0.947 m above the slab's body-frame x = +L/4 = 0.347 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.1070 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2398 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.12217 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.15045 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.5082 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 4.3090 m/s; t_impact = 0.4397 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -1.3297 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -2.3347 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 8.167 rad/s; period 0.769 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 15.511 rad/s; period 0.405 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.1013836407728823, + "d_block_m": 0.23983639042681767, + "d_slab_m": 0.10704168422071235, + "I_total_kg_m2": 0.1504465877457782, + "Y_s_eq_m": 0.5081693435909707, + "v_impact_m_s": 4.3090429466857145, + "t_impact_s": 0.43969825986588923, + "v_com_y_after_m_s": -1.329709912802367, + "omega_after_rad_s": -2.3346848501722586, + "omega_trans_rad_s": 8.16683477331019, + "omega_rot_rad_s": 15.511280683008946 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.440 s, hits slab at v_impact=4.309 m/s.", + "Combined system oscillates with translational period 0.769 s and rotational period 0.405 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 0.7615121744045803, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.3875122985901203, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.339871466368302, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 36.729597093910456, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6097607017820761, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.21312592361206467, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.08144121153206249, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.947339342672546, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/087/params.json b/scipy/slab_springs_block_drop/087/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8627cd14ca18dc25adf2a732101f132db8454806 --- /dev/null +++ b/scipy/slab_springs_block_drop/087/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 0.7615121744045803, + "L_slab": 1.3875122985901203, + "m_b": 0.339871466368302, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 36.729597093910456, + "L_0": 0.6097607017820761, + "gamma_y": 0.21312592361206467, + "gamma_theta": 0.08144121153206249, + "H_drop": 0.947339342672546 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/087/simulation_code.py b/scipy/slab_springs_block_drop/087/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..68d00fc6c77ee27366500e2b10faf38d2a3ba5ab --- /dev/null +++ b/scipy/slab_springs_block_drop/087/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 0.7615121744045803 +L_slab = 1.3875122985901203 +m_b = 0.339871466368302 +block_size = 0.18 +slab_thick = 0.1 +k = 36.729597093910456 +L_0 = 0.6097607017820761 +gamma_y = 0.21312592361206467 +gamma_theta = 0.08144121153206249 +H_drop = 0.947339342672546 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/087/video.mp4 b/scipy/slab_springs_block_drop/087/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ab05421cd0c9319b9992289a669b4e5be06d741b --- /dev/null +++ b/scipy/slab_springs_block_drop/087/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d590583742b6f883e3bd9d6723ceb717ae86efb8f88a51364a561acd913b3267 +size 43826 diff --git a/scipy/slab_springs_block_drop/195/cot.json b/scipy/slab_springs_block_drop/195/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..348e7e9289eefdc0dfc0cb4b9209887618e9b296 --- /dev/null +++ b/scipy/slab_springs_block_drop/195/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=1.131 kg, length L=1.249 m) is suspended above the floor by two vertical Hookean springs (each k=27.473 N/m, rest length L_0=0.661 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.315 kg) is released from rest at height H_drop=1.190 m above the slab's body-frame x = +L/4 = 0.312 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0681 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2442 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.14713 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.17117 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4595 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 4.8302 m/s; t_impact = 0.4929 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -1.0527 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -2.1731 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 6.163 rad/s; period 1.020 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 11.256 rad/s; period 0.558 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.4468216577190727, + "d_block_m": 0.24422187736598014, + "d_slab_m": 0.06806213857278012, + "I_total_kg_m2": 0.17117498676513013, + "Y_s_eq_m": 0.4595056099798186, + "v_impact_m_s": 4.830168842529719, + "t_impact_s": 0.492874371686706, + "v_com_y_after_m_s": -1.0527327826943655, + "omega_after_rad_s": -2.173088487028348, + "omega_trans_rad_s": 6.162503356763981, + "omega_rot_rad_s": 11.256096516742014 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.493 s, hits slab at v_impact=4.830 m/s.", + "Combined system oscillates with translational period 1.020 s and rotational period 0.558 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 1.1314876312183826, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.249136063755041, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.31533402650069015, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 27.4725734514639, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6613174061249898, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.17720855753352802, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.06268919344268592, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 1.1903332167012697, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/195/params.json b/scipy/slab_springs_block_drop/195/params.json new file mode 100644 index 0000000000000000000000000000000000000000..4fbb632fc6c260caec3e15bfcab92c63d6e03e70 --- /dev/null +++ b/scipy/slab_springs_block_drop/195/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 1.1314876312183826, + "L_slab": 1.249136063755041, + "m_b": 0.31533402650069015, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 27.4725734514639, + "L_0": 0.6613174061249898, + "gamma_y": 0.17720855753352802, + "gamma_theta": 0.06268919344268592, + "H_drop": 1.1903332167012697 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/195/simulation_code.py b/scipy/slab_springs_block_drop/195/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..50e768340e4c87984120708cea45e6d9488fb72f --- /dev/null +++ b/scipy/slab_springs_block_drop/195/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 1.1314876312183826 +L_slab = 1.249136063755041 +m_b = 0.31533402650069015 +block_size = 0.18 +slab_thick = 0.1 +k = 27.4725734514639 +L_0 = 0.6613174061249898 +gamma_y = 0.17720855753352802 +gamma_theta = 0.06268919344268592 +H_drop = 1.1903332167012697 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/195/video.mp4 b/scipy/slab_springs_block_drop/195/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b50b2cd5342cb3a2c8779b9f473e3020b486ed2a --- /dev/null +++ b/scipy/slab_springs_block_drop/195/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eaa013f2c5737863202c71bc934e10eb2e19019afbb1b15a2402ab520c7ae0e1 +size 39625 diff --git a/scipy/slab_springs_block_drop/246/cot.json b/scipy/slab_springs_block_drop/246/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..103e41dbd77c9c4cab03153741dfd0345f6417f9 --- /dev/null +++ b/scipy/slab_springs_block_drop/246/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=1.047 kg, length L=1.582 m) is suspended above the floor by two vertical Hookean springs (each k=32.160 N/m, rest length L_0=0.581 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.325 kg) is released from rest at height H_drop=0.954 m above the slab's body-frame x = +L/4 = 0.396 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0937 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.3019 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.21846 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.25727 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4210 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 4.3251 m/s; t_impact = 0.4413 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -1.0243 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.6492 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 6.847 rad/s; period 0.918 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 12.597 rad/s; period 0.499 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.3720708737912024, + "d_block_m": 0.3018857645904899, + "d_slab_m": 0.09368435397388596, + "I_total_kg_m2": 0.25726963203683373, + "Y_s_eq_m": 0.4209927547092649, + "v_impact_m_s": 4.325115739780187, + "t_impact_s": 0.44133834079389656, + "v_com_y_after_m_s": -1.0243333733451616, + "omega_after_rad_s": -1.649194875940886, + "omega_trans_rad_s": 6.846718282121323, + "omega_rot_rad_s": 12.596611914096364 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.441 s, hits slab at v_impact=4.325 m/s.", + "Combined system oscillates with translational period 0.918 s and rotational period 0.499 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 1.047118185544618, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.5822804742575034, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3249526882465843, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 32.159661341916916, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.5805366956300929, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.23559205807841954, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.07915497892913428, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.9544197021680769, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/246/params.json b/scipy/slab_springs_block_drop/246/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c80743cb687807bcb613a7ae5ca506d3fad630dc --- /dev/null +++ b/scipy/slab_springs_block_drop/246/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 1.047118185544618, + "L_slab": 1.5822804742575034, + "m_b": 0.3249526882465843, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 32.159661341916916, + "L_0": 0.5805366956300929, + "gamma_y": 0.23559205807841954, + "gamma_theta": 0.07915497892913428, + "H_drop": 0.9544197021680769 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/246/simulation_code.py b/scipy/slab_springs_block_drop/246/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..340696124b8929262b737b689d822d950a42a22b --- /dev/null +++ b/scipy/slab_springs_block_drop/246/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 1.047118185544618 +L_slab = 1.5822804742575034 +m_b = 0.3249526882465843 +block_size = 0.18 +slab_thick = 0.1 +k = 32.159661341916916 +L_0 = 0.5805366956300929 +gamma_y = 0.23559205807841954 +gamma_theta = 0.07915497892913428 +H_drop = 0.9544197021680769 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/246/video.mp4 b/scipy/slab_springs_block_drop/246/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..5ca1657ca0133e117a583a4766a53b1b6466545f --- /dev/null +++ b/scipy/slab_springs_block_drop/246/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62baaa9413b1071010dabeeeccb8d39dc41c5c92b65caa4dbc33aea39ba04fe0 +size 44931 diff --git a/scipy/slab_springs_block_drop/247/cot.json b/scipy/slab_springs_block_drop/247/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..38647ebd48054a18cd92ecfc24e3777267de380f --- /dev/null +++ b/scipy/slab_springs_block_drop/247/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=1.133 kg, length L=1.411 m) is suspended above the floor by two vertical Hookean springs (each k=29.338 N/m, rest length L_0=0.662 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.315 kg) is released from rest at height H_drop=0.831 m above the slab's body-frame x = +L/4 = 0.353 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0767 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2760 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.18804 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.21872 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4730 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 4.0367 m/s; t_impact = 0.4119 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -0.8782 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.6052 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 6.365 rad/s; period 0.987 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 11.624 rad/s; period 0.541 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.448459176618325, + "d_block_m": 0.27601391758290905, + "d_slab_m": 0.07674588947495756, + "I_total_kg_m2": 0.21872470643606431, + "Y_s_eq_m": 0.4730070233504163, + "v_impact_m_s": 4.036706723406951, + "t_impact_s": 0.41190884932723987, + "v_com_y_after_m_s": -0.8782198023670772, + "omega_after_rad_s": -1.6052497981715592, + "omega_trans_rad_s": 6.364718254699368, + "omega_rot_rad_s": 11.623766778978672 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.412 s, hits slab at v_impact=4.037 m/s.", + "Combined system oscillates with translational period 0.987 s and rotational period 0.541 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 1.1333345914086987, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.4110392282314665, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3151245852096262, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 29.338278785672447, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6622935025768198, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.2117044688980128, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.09827486867229715, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.831377610755045, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/247/params.json b/scipy/slab_springs_block_drop/247/params.json new file mode 100644 index 0000000000000000000000000000000000000000..909626b4ff66b79f34498edf90a7faa662dadb24 --- /dev/null +++ b/scipy/slab_springs_block_drop/247/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 1.1333345914086987, + "L_slab": 1.4110392282314665, + "m_b": 0.3151245852096262, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 29.338278785672447, + "L_0": 0.6622935025768198, + "gamma_y": 0.2117044688980128, + "gamma_theta": 0.09827486867229715, + "H_drop": 0.831377610755045 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/247/simulation_code.py b/scipy/slab_springs_block_drop/247/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..0b8aeea53fd9c454c3f3af93dccd3dd6065a185c --- /dev/null +++ b/scipy/slab_springs_block_drop/247/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 1.1333345914086987 +L_slab = 1.4110392282314665 +m_b = 0.3151245852096262 +block_size = 0.18 +slab_thick = 0.1 +k = 29.338278785672447 +L_0 = 0.6622935025768198 +gamma_y = 0.2117044688980128 +gamma_theta = 0.09827486867229715 +H_drop = 0.831377610755045 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/247/video.mp4 b/scipy/slab_springs_block_drop/247/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..18a7c4c0450f09db9bb14cb9b5c3ddffab7f4208 --- /dev/null +++ b/scipy/slab_springs_block_drop/247/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a338832695893e96999cecbcee3b08f66d6b1a154331e304a020413838df58df +size 42669 diff --git a/scipy/slab_springs_block_drop/416/cot.json b/scipy/slab_springs_block_drop/416/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..9eaa669afcb16338c9de612ed2a4bb706c74cf83 --- /dev/null +++ b/scipy/slab_springs_block_drop/416/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=0.840 kg, length L=1.377 m) is suspended above the floor by two vertical Hookean springs (each k=32.495 N/m, rest length L_0=0.622 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.298 kg) is released from rest at height H_drop=0.721 m above the slab's body-frame x = +L/4 = 0.344 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0902 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2540 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.13267 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.15873 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4953 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 3.7588 m/s; t_impact = 0.3835 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -0.9846 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.7930 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 7.558 rad/s; period 0.831 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 14.049 rad/s; period 0.447 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.1378231519844757, + "d_block_m": 0.2540495735490314, + "d_slab_m": 0.090165194030088, + "I_total_kg_m2": 0.15873002646192672, + "Y_s_eq_m": 0.49532672644610115, + "v_impact_m_s": 3.758781985206361, + "t_impact_s": 0.38354918216391437, + "v_com_y_after_m_s": -0.9845925826962976, + "omega_after_rad_s": -1.7930430121853254, + "omega_trans_rad_s": 7.557613103088829, + "omega_rot_rad_s": 14.048995999860841 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.384 s, hits slab at v_impact=3.759 m/s.", + "Combined system oscillates with translational period 0.831 s and rotational period 0.447 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 0.8397765400039909, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.3768590703164774, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.2980466119804849, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 32.49481593963073, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6219593885194693, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.2836443813820335, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.05304181662448837, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.720838878179177, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/416/params.json b/scipy/slab_springs_block_drop/416/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ce365ddd644c05b748472624cbf8a967ab90303c --- /dev/null +++ b/scipy/slab_springs_block_drop/416/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 0.8397765400039909, + "L_slab": 1.3768590703164774, + "m_b": 0.2980466119804849, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 32.49481593963073, + "L_0": 0.6219593885194693, + "gamma_y": 0.2836443813820335, + "gamma_theta": 0.05304181662448837, + "H_drop": 0.720838878179177 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/416/simulation_code.py b/scipy/slab_springs_block_drop/416/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..948caf1df9c0bbbcf07e6da491a2029cf9dcdf5b --- /dev/null +++ b/scipy/slab_springs_block_drop/416/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 0.8397765400039909 +L_slab = 1.3768590703164774 +m_b = 0.2980466119804849 +block_size = 0.18 +slab_thick = 0.1 +k = 32.49481593963073 +L_0 = 0.6219593885194693 +gamma_y = 0.2836443813820335 +gamma_theta = 0.05304181662448837 +H_drop = 0.720838878179177 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/416/video.mp4 b/scipy/slab_springs_block_drop/416/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..64076f9c15fe8fee79ff025d8d48e8c2df8c1ec1 --- /dev/null +++ b/scipy/slab_springs_block_drop/416/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:722f071b63ac46c037e24b2dbe9efb6e0a456cb000a2a7153ddf946a0c0e3b4b +size 45778 diff --git a/scipy/slab_springs_block_drop/458/cot.json b/scipy/slab_springs_block_drop/458/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..98df4e4f0af1861e65291ecbccb9a3a2f5c81665 --- /dev/null +++ b/scipy/slab_springs_block_drop/458/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=1.078 kg, length L=1.320 m) is suspended above the floor by two vertical Hookean springs (each k=30.511 N/m, rest length L_0=0.622 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.327 kg) is released from rest at height H_drop=0.844 m above the slab's body-frame x = +L/4 = 0.330 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0767 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2533 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.15648 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.18377 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4487 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 4.0679 m/s; t_impact = 0.4151 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -0.9460 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.8307 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 6.592 rad/s; period 0.953 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 12.108 rad/s; period 0.519 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.4042801760578971, + "d_block_m": 0.25325452129072135, + "d_slab_m": 0.0767362354075019, + "I_total_kg_m2": 0.18376784866247603, + "Y_s_eq_m": 0.44869399548448796, + "v_impact_m_s": 4.067940807867649, + "t_impact_s": 0.41509600080282133, + "v_com_y_after_m_s": -0.9459612341256711, + "omega_after_rad_s": -1.8306898790218256, + "omega_trans_rad_s": 6.591991562260303, + "omega_rot_rad_s": 12.107554434658411 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.415 s, hits slab at v_impact=4.068 m/s.", + "Combined system oscillates with translational period 0.953 s and rotational period 0.519 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 1.0777280773074074, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.319963026792893, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3265520987504896, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 30.5110430699785, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6217745278902265, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.27853751843118524, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.08755152117372215, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.8442929804242296, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/458/params.json b/scipy/slab_springs_block_drop/458/params.json new file mode 100644 index 0000000000000000000000000000000000000000..73494628e7aa07d217d414dc59cb471eb5ef7905 --- /dev/null +++ b/scipy/slab_springs_block_drop/458/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 1.0777280773074074, + "L_slab": 1.319963026792893, + "m_b": 0.3265520987504896, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 30.5110430699785, + "L_0": 0.6217745278902265, + "gamma_y": 0.27853751843118524, + "gamma_theta": 0.08755152117372215, + "H_drop": 0.8442929804242296 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/458/simulation_code.py b/scipy/slab_springs_block_drop/458/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e8e10a1f87f02fc74aefe79a708b4187dd06e10d --- /dev/null +++ b/scipy/slab_springs_block_drop/458/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 1.0777280773074074 +L_slab = 1.319963026792893 +m_b = 0.3265520987504896 +block_size = 0.18 +slab_thick = 0.1 +k = 30.5110430699785 +L_0 = 0.6217745278902265 +gamma_y = 0.27853751843118524 +gamma_theta = 0.08755152117372215 +H_drop = 0.8442929804242296 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/458/video.mp4 b/scipy/slab_springs_block_drop/458/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1abd01becb807aed11370dbd0f6c36f190afee95 --- /dev/null +++ b/scipy/slab_springs_block_drop/458/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da944e637a1d1be472a2e87a234ef659121910d9e20145d9a6891319869091ce +size 43002 diff --git a/scipy/slab_springs_block_drop/487/cot.json b/scipy/slab_springs_block_drop/487/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..026fe121dbfc6dcaef2f8768abedb4d383afd8f9 --- /dev/null +++ b/scipy/slab_springs_block_drop/487/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=0.950 kg, length L=1.507 m) is suspended above the floor by two vertical Hookean springs (each k=29.134 N/m, rest length L_0=0.645 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.309 kg) is released from rest at height H_drop=0.776 m above the slab's body-frame x = +L/4 = 0.377 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0924 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2844 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.17991 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.21298 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4855 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 3.8995 m/s; t_impact = 0.3979 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -0.9558 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.6070 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 6.803 rad/s; period 0.924 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 12.558 rad/s; period 0.500 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.258893931592916, + "d_block_m": 0.2844468126339004, + "d_slab_m": 0.09236086805697448, + "I_total_kg_m2": 0.21298061472795488, + "Y_s_eq_m": 0.4855474761290923, + "v_impact_m_s": 3.8994831701413415, + "t_impact_s": 0.3979064459327899, + "v_com_y_after_m_s": -0.955818230423186, + "omega_after_rad_s": -1.6070354057132155, + "omega_trans_rad_s": 6.803263819402587, + "omega_rot_rad_s": 12.558244535488937 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.398 s, hits slab at v_impact=3.899 m/s.", + "Combined system oscillates with translational period 0.924 s and rotational period 0.500 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 0.9503213035074319, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.5072307227634998, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.308572628085484, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 29.133574260212953, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6453828037684405, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.1562908722929111, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.059326758640004765, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.775814744602835, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/487/params.json b/scipy/slab_springs_block_drop/487/params.json new file mode 100644 index 0000000000000000000000000000000000000000..32e5259446357b13ec268d0da626bb1160cba05b --- /dev/null +++ b/scipy/slab_springs_block_drop/487/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 0.9503213035074319, + "L_slab": 1.5072307227634998, + "m_b": 0.308572628085484, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 29.133574260212953, + "L_0": 0.6453828037684405, + "gamma_y": 0.1562908722929111, + "gamma_theta": 0.059326758640004765, + "H_drop": 0.775814744602835 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/487/simulation_code.py b/scipy/slab_springs_block_drop/487/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..f634a364a532fe76297581775b322351ffa42afb --- /dev/null +++ b/scipy/slab_springs_block_drop/487/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 0.9503213035074319 +L_slab = 1.5072307227634998 +m_b = 0.308572628085484 +block_size = 0.18 +slab_thick = 0.1 +k = 29.133574260212953 +L_0 = 0.6453828037684405 +gamma_y = 0.1562908722929111 +gamma_theta = 0.059326758640004765 +H_drop = 0.775814744602835 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/487/video.mp4 b/scipy/slab_springs_block_drop/487/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9f9a70b905799f47b057bd6986d9530440bbd4e1 --- /dev/null +++ b/scipy/slab_springs_block_drop/487/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2153347990b51d90dd770fa8664620971f8019c0d7f561da666588107145da39 +size 48774 diff --git a/scipy/slab_springs_block_drop/500/cot.json b/scipy/slab_springs_block_drop/500/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4967c5156f8f3e2bae3127785f7fafed1ef26543 --- /dev/null +++ b/scipy/slab_springs_block_drop/500/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=0.789 kg, length L=1.406 m) is suspended above the floor by two vertical Hookean springs (each k=39.371 N/m, rest length L_0=0.567 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.375 kg) is released from rest at height H_drop=0.810 m above the slab's body-frame x = +L/4 = 0.352 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.1133 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2384 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.13006 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.16148 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4683 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 3.9850 m/s; t_impact = 0.4066 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -1.2836 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -2.2052 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 8.225 rad/s; period 0.764 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 15.729 rad/s; period 0.399 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.1638385109338367, + "d_block_m": 0.23835793098736127, + "d_slab_m": 0.11326345549541032, + "I_total_kg_m2": 0.16147821480536406, + "Y_s_eq_m": 0.4683115628294382, + "v_impact_m_s": 3.9849617578277794, + "t_impact_s": 0.406628750798753, + "v_com_y_after_m_s": -1.2836265257453376, + "omega_after_rad_s": -2.2051953816996526, + "omega_trans_rad_s": 8.22541762240871, + "omega_rot_rad_s": 15.729452161389151 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.407 s, hits slab at v_impact=3.985 m/s.", + "Combined system oscillates with translational period 0.764 s and rotational period 0.399 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 0.7889455821914093, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.4064855459310863, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.37489292874242747, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 39.37119915383614, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.5665009356659838, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.29878033859025627, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.08910474370210478, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.8102000107831564, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/500/params.json b/scipy/slab_springs_block_drop/500/params.json new file mode 100644 index 0000000000000000000000000000000000000000..bf33e6d6c449d21c193f2a26572336f3409618f3 --- /dev/null +++ b/scipy/slab_springs_block_drop/500/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 0.7889455821914093, + "L_slab": 1.4064855459310863, + "m_b": 0.37489292874242747, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 39.37119915383614, + "L_0": 0.5665009356659838, + "gamma_y": 0.29878033859025627, + "gamma_theta": 0.08910474370210478, + "H_drop": 0.8102000107831564 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/500/simulation_code.py b/scipy/slab_springs_block_drop/500/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..050155e02ebe6700d456ea7679d4c13e1f9c408a --- /dev/null +++ b/scipy/slab_springs_block_drop/500/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 0.7889455821914093 +L_slab = 1.4064855459310863 +m_b = 0.37489292874242747 +block_size = 0.18 +slab_thick = 0.1 +k = 39.37119915383614 +L_0 = 0.5665009356659838 +gamma_y = 0.29878033859025627 +gamma_theta = 0.08910474370210478 +H_drop = 0.8102000107831564 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/500/video.mp4 b/scipy/slab_springs_block_drop/500/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0c5d050c28cc78397c4e0e84d23476fc4e2dd8fd --- /dev/null +++ b/scipy/slab_springs_block_drop/500/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b7985efad5d5e07064cb3d38f0d99f06a99e637ac3cfddef7449cb91266a753 +size 39333 diff --git a/scipy/slab_springs_block_drop/502/cot.json b/scipy/slab_springs_block_drop/502/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..a484138652015cd8cd65740aa55df36c30fa3c3c --- /dev/null +++ b/scipy/slab_springs_block_drop/502/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=1.110 kg, length L=1.729 m) is suspended above the floor by two vertical Hookean springs (each k=31.663 N/m, rest length L_0=0.609 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.342 kg) is released from rest at height H_drop=0.894 m above the slab's body-frame x = +L/4 = 0.432 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.1017 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.3305 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.27637 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.32515 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4378 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 4.1870 m/s; t_impact = 0.4272 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -0.9853 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.4534 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 6.606 rad/s; period 0.951 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 12.146 rad/s; period 0.517 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.4511646275997292, + "d_block_m": 0.3304861184201786, + "d_slab_m": 0.10170735690176656, + "I_total_kg_m2": 0.32514523038986276, + "Y_s_eq_m": 0.4377643744621512, + "v_impact_m_s": 4.187024219157281, + "t_impact_s": 0.4272473693017633, + "v_com_y_after_m_s": -0.9853253020466107, + "omega_after_rad_s": -1.4533564876689222, + "omega_trans_rad_s": 6.6058688897799325, + "omega_rot_rad_s": 12.146287315622233 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.427 s, hits slab at v_impact=4.187 m/s.", + "Combined system oscillates with translational period 0.951 s and rotational period 0.517 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 1.10966451912965, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.7287739012877807, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.34150010847007933, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 31.662600967645663, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.609492406195597, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.22540060533732081, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.04891682168031874, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.8944475414188588, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/502/params.json b/scipy/slab_springs_block_drop/502/params.json new file mode 100644 index 0000000000000000000000000000000000000000..cacbfb0e247a3d6011f7021b3d9b3416804bff35 --- /dev/null +++ b/scipy/slab_springs_block_drop/502/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 1.10966451912965, + "L_slab": 1.7287739012877807, + "m_b": 0.34150010847007933, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 31.662600967645663, + "L_0": 0.609492406195597, + "gamma_y": 0.22540060533732081, + "gamma_theta": 0.04891682168031874, + "H_drop": 0.8944475414188588 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/502/simulation_code.py b/scipy/slab_springs_block_drop/502/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..adfa5048d19e2b0ccd1d8d842a427161473f530a --- /dev/null +++ b/scipy/slab_springs_block_drop/502/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 1.10966451912965 +L_slab = 1.7287739012877807 +m_b = 0.34150010847007933 +block_size = 0.18 +slab_thick = 0.1 +k = 31.662600967645663 +L_0 = 0.609492406195597 +gamma_y = 0.22540060533732081 +gamma_theta = 0.04891682168031874 +H_drop = 0.8944475414188588 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/502/video.mp4 b/scipy/slab_springs_block_drop/502/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f14a1557ea9f1d68cd90592b4462346f994dee89 --- /dev/null +++ b/scipy/slab_springs_block_drop/502/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c0df68c25ddad56f80bbabb679d9740e19de2ab189385f4ad83bab5dea5bc53 +size 46306 diff --git a/scipy/slab_springs_block_drop/568/cot.json b/scipy/slab_springs_block_drop/568/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..fab4d8968fd1e0555aca8894a8a3560c0e6060e1 --- /dev/null +++ b/scipy/slab_springs_block_drop/568/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=1.014 kg, length L=1.245 m) is suspended above the floor by two vertical Hookean springs (each k=32.975 N/m, rest length L_0=0.673 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.339 kg) is released from rest at height H_drop=0.723 m above the slab's body-frame x = +L/4 = 0.311 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0779 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2334 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.13111 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.15572 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.5224 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 3.7655 m/s; t_impact = 0.3842 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -0.9425 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.9116 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 6.981 rad/s; period 0.900 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 12.914 rad/s; period 0.487 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.353157875169415, + "d_block_m": 0.23340795087891086, + "d_slab_m": 0.07792370858493439, + "I_total_kg_m2": 0.15571833126287482, + "Y_s_eq_m": 0.5223742558068825, + "v_impact_m_s": 3.765471287480582, + "t_impact_s": 0.38423176402863074, + "v_com_y_after_m_s": -0.9424659470735552, + "omega_after_rad_s": -1.9115692760697232, + "omega_trans_rad_s": 6.981257238346309, + "omega_rot_rad_s": 12.914148526347855 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.384 s, hits slab at v_impact=3.765 m/s.", + "Combined system oscillates with translational period 0.900 s and rotational period 0.487 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 1.0144737846541825, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.2453266378553811, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3386840905152325, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 32.975072209080835, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6731221150772734, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.23557838406962095, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.07466548309215892, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.7234068375939118, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/568/params.json b/scipy/slab_springs_block_drop/568/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3156b220dc078f9179875d446f7b53168d248b49 --- /dev/null +++ b/scipy/slab_springs_block_drop/568/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 1.0144737846541825, + "L_slab": 1.2453266378553811, + "m_b": 0.3386840905152325, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 32.975072209080835, + "L_0": 0.6731221150772734, + "gamma_y": 0.23557838406962095, + "gamma_theta": 0.07466548309215892, + "H_drop": 0.7234068375939118 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/568/simulation_code.py b/scipy/slab_springs_block_drop/568/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..c7eeb4f6fa665c455bf4673d7a0cce98f8df97d9 --- /dev/null +++ b/scipy/slab_springs_block_drop/568/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 1.0144737846541825 +L_slab = 1.2453266378553811 +m_b = 0.3386840905152325 +block_size = 0.18 +slab_thick = 0.1 +k = 32.975072209080835 +L_0 = 0.6731221150772734 +gamma_y = 0.23557838406962095 +gamma_theta = 0.07466548309215892 +H_drop = 0.7234068375939118 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/568/video.mp4 b/scipy/slab_springs_block_drop/568/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6c8528fafb1128f4b3d046e3c9f7d08bfabc6e8a --- /dev/null +++ b/scipy/slab_springs_block_drop/568/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:827be81955cd046886704ce018365ba08439a9bbec2e935291e73e0ea572947b +size 46082 diff --git a/scipy/slab_springs_block_drop/661/cot.json b/scipy/slab_springs_block_drop/661/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..7fd8eea1269b5270086211dc83600e0ef2917263 --- /dev/null +++ b/scipy/slab_springs_block_drop/661/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=0.731 kg, length L=1.434 m) is suspended above the floor by two vertical Hookean springs (each k=25.067 N/m, rest length L_0=0.652 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.211 kg) is released from rest at height H_drop=0.683 m above the slab's body-frame x = +L/4 = 0.358 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0801 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2782 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.12519 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.14619 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.5095 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 3.6578 m/s; t_impact = 0.3732 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -0.8180 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.4659 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 7.297 rad/s; period 0.861 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 13.356 rad/s; period 0.470 s." + ], + "physical_constants_derived": { + "M_total_kg": 0.9415772900098709, + "d_block_m": 0.27824527394057824, + "d_slab_m": 0.08014192718132536, + "I_total_kg_m2": 0.1461878830981823, + "Y_s_eq_m": 0.5095041433175556, + "v_impact_m_s": 3.6578323544838396, + "t_impact_s": 0.37324819943712645, + "v_com_y_after_m_s": -0.8179581560861259, + "omega_after_rad_s": -1.4658970863325098, + "omega_trans_rad_s": 7.296847617365215, + "omega_rot_rad_s": 13.356351937516855 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.373 s, hits slab at v_impact=3.658 m/s.", + "Combined system oscillates with translational period 0.861 s and rotational period 0.470 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 0.7310234019933916, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.4335488044876143, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.21055388801647934, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 25.06666362392498, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6524036820638588, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.2527215499127622, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.0923414797815427, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.682639670076979, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/661/params.json b/scipy/slab_springs_block_drop/661/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c28e9ca53b48cf3ec116c0fc34c9faa9902d43ce --- /dev/null +++ b/scipy/slab_springs_block_drop/661/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 0.7310234019933916, + "L_slab": 1.4335488044876143, + "m_b": 0.21055388801647934, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 25.06666362392498, + "L_0": 0.6524036820638588, + "gamma_y": 0.2527215499127622, + "gamma_theta": 0.0923414797815427, + "H_drop": 0.682639670076979 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/661/simulation_code.py b/scipy/slab_springs_block_drop/661/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..bb506619ce9de99e4dc985d1a9b853edb0a63679 --- /dev/null +++ b/scipy/slab_springs_block_drop/661/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 0.7310234019933916 +L_slab = 1.4335488044876143 +m_b = 0.21055388801647934 +block_size = 0.18 +slab_thick = 0.1 +k = 25.06666362392498 +L_0 = 0.6524036820638588 +gamma_y = 0.2527215499127622 +gamma_theta = 0.0923414797815427 +H_drop = 0.682639670076979 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/661/video.mp4 b/scipy/slab_springs_block_drop/661/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..2c3efa255da46a4a06bd18a0d83bb9f9a7ee2df9 --- /dev/null +++ b/scipy/slab_springs_block_drop/661/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6256824f3256db2b9d2d3e3b8a17f7e710e9c11aa5fc5cc6cf53f2bf8a6d4056 +size 41254 diff --git a/scipy/slab_springs_block_drop/707/cot.json b/scipy/slab_springs_block_drop/707/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5740343b1f96a0393bc0a2db9a2f0a73ddcc9c3c --- /dev/null +++ b/scipy/slab_springs_block_drop/707/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=0.949 kg, length L=1.676 m) is suspended above the floor by two vertical Hookean springs (each k=32.519 N/m, rest length L_0=0.690 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.349 kg) is released from rest at height H_drop=0.872 m above the slab's body-frame x = +L/4 = 0.419 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.1127 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.3064 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.22217 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.26698 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.5466 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 4.1345 m/s; t_impact = 0.4219 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -1.1117 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.6557 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 7.079 rad/s; period 0.888 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 13.199 rad/s; period 0.476 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.2977611526311716, + "d_block_m": 0.30638654458330394, + "d_slab_m": 0.11268148916770955, + "I_total_kg_m2": 0.2669752095566658, + "Y_s_eq_m": 0.5465543233157617, + "v_impact_m_s": 4.134474131110895, + "t_impact_s": 0.421885115419479, + "v_com_y_after_m_s": -1.1117018347807133, + "omega_after_rad_s": -1.6557007474351328, + "omega_trans_rad_s": 7.079189494372918, + "omega_rot_rad_s": 13.199268134665303 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.422 s, hits slab at v_impact=4.134 m/s.", + "Combined system oscillates with translational period 0.888 s and rotational period 0.476 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 0.9488114655038365, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.6762721350040541, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.348949687127335, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 32.51860070045275, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6895240723463241, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.24379846888542714, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.0796714128771593, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.8721365480012847, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/707/params.json b/scipy/slab_springs_block_drop/707/params.json new file mode 100644 index 0000000000000000000000000000000000000000..588a9093c3edaab3a1ca7b3457b081f206bf373e --- /dev/null +++ b/scipy/slab_springs_block_drop/707/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 0.9488114655038365, + "L_slab": 1.6762721350040541, + "m_b": 0.348949687127335, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 32.51860070045275, + "L_0": 0.6895240723463241, + "gamma_y": 0.24379846888542714, + "gamma_theta": 0.0796714128771593, + "H_drop": 0.8721365480012847 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/707/simulation_code.py b/scipy/slab_springs_block_drop/707/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e47c4e9f6c4340bca279339a588acf963f4635dc --- /dev/null +++ b/scipy/slab_springs_block_drop/707/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 0.9488114655038365 +L_slab = 1.6762721350040541 +m_b = 0.348949687127335 +block_size = 0.18 +slab_thick = 0.1 +k = 32.51860070045275 +L_0 = 0.6895240723463241 +gamma_y = 0.24379846888542714 +gamma_theta = 0.0796714128771593 +H_drop = 0.8721365480012847 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/707/video.mp4 b/scipy/slab_springs_block_drop/707/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..bf37627e194fc1c4114b79839476b29d8e22276f --- /dev/null +++ b/scipy/slab_springs_block_drop/707/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48e529b52e57f10f406dd39b0edef0b7e7766098e55f01347042c1e8a1c1c59f +size 50536 diff --git a/scipy/slab_springs_block_drop/728/cot.json b/scipy/slab_springs_block_drop/728/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d3ce63653dfc70eb2deeb9a5c7c539f987bfab0e --- /dev/null +++ b/scipy/slab_springs_block_drop/728/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=0.948 kg, length L=1.215 m) is suspended above the floor by two vertical Hookean springs (each k=27.505 N/m, rest length L_0=0.591 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.273 kg) is released from rest at height H_drop=0.815 m above the slab's body-frame x = +L/4 = 0.304 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0679 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2359 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.11664 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.13618 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4221 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 3.9963 m/s; t_impact = 0.4078 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -0.8927 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.8878 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 6.713 rad/s; period 0.936 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 12.287 rad/s; period 0.511 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.2206621836887965, + "d_block_m": 0.23591515778398545, + "d_slab_m": 0.06785861789818147, + "I_total_kg_m2": 0.13617950742760976, + "Y_s_eq_m": 0.4221166185755563, + "v_impact_m_s": 3.9963180102786664, + "t_impact_s": 0.40778755206925166, + "v_com_y_after_m_s": -0.8927189855350006, + "omega_after_rad_s": -1.8877928983315744, + "omega_trans_rad_s": 6.71311664412418, + "omega_rot_rad_s": 12.286793038894992 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.408 s, hits slab at v_impact=3.996 m/s.", + "Combined system oscillates with translational period 0.936 s and rotational period 0.511 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 0.9479841076445893, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.2150951027286678, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.2726780760442072, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 27.505141360910805, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.5909985765523275, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.29539041252252884, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.06293098463022331, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 0.8148243693509, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/728/params.json b/scipy/slab_springs_block_drop/728/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b508b746257a54d140cc1113901611b24ed1d5ed --- /dev/null +++ b/scipy/slab_springs_block_drop/728/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 0.9479841076445893, + "L_slab": 1.2150951027286678, + "m_b": 0.2726780760442072, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 27.505141360910805, + "L_0": 0.5909985765523275, + "gamma_y": 0.29539041252252884, + "gamma_theta": 0.06293098463022331, + "H_drop": 0.8148243693509 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/728/simulation_code.py b/scipy/slab_springs_block_drop/728/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..394510bde7f5481af829e692fdb03ec5e6f25990 --- /dev/null +++ b/scipy/slab_springs_block_drop/728/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 0.9479841076445893 +L_slab = 1.2150951027286678 +m_b = 0.2726780760442072 +block_size = 0.18 +slab_thick = 0.1 +k = 27.505141360910805 +L_0 = 0.5909985765523275 +gamma_y = 0.29539041252252884 +gamma_theta = 0.06293098463022331 +H_drop = 0.8148243693509 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/728/video.mp4 b/scipy/slab_springs_block_drop/728/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..7bb3488018cbd09cf686c213572277f13bec7e59 --- /dev/null +++ b/scipy/slab_springs_block_drop/728/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11c7de416670a55c634e5c3996ca9d762016d996d89f0ae740d34e052b5659bc +size 38542 diff --git a/scipy/slab_springs_block_drop/737/cot.json b/scipy/slab_springs_block_drop/737/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..caf71256f7fc030a5d44bd92bac0afb53f58c49b --- /dev/null +++ b/scipy/slab_springs_block_drop/737/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=1.261 kg, length L=1.411 m) is suspended above the floor by two vertical Hookean springs (each k=34.925 N/m, rest length L_0=0.623 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.353 kg) is released from rest at height H_drop=1.107 m above the slab's body-frame x = +L/4 = 0.353 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.0771 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2755 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.20903 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.24331 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4466 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 4.6586 m/s; t_impact = 0.4754 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -1.0186 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.8612 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 6.580 rad/s; period 0.955 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 12.021 rad/s; period 0.523 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.613495036470855, + "d_block_m": 0.2755322255920306, + "d_slab_m": 0.07710287431232678, + "I_total_kg_m2": 0.24330554009205732, + "Y_s_eq_m": 0.4465562708985911, + "v_impact_m_s": 4.658571204271614, + "t_impact_s": 0.47536440859914425, + "v_com_y_after_m_s": -1.0185861536058074, + "omega_after_rad_s": -1.8611689740285828, + "omega_trans_rad_s": 6.5796286502207915, + "omega_rot_rad_s": 12.021111601648075 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.475 s, hits slab at v_impact=4.659 m/s.", + "Combined system oscillates with translational period 0.955 s and rotational period 0.523 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 1.2607079627101405, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.4105403996174295, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.35278707376071444, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 34.92532081443127, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6234327855082189, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.2247975535831614, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.09436461612083419, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 1.1072594727177896, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/737/params.json b/scipy/slab_springs_block_drop/737/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3d96e375652b6be9122ab810157f13d6716125f1 --- /dev/null +++ b/scipy/slab_springs_block_drop/737/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 1.2607079627101405, + "L_slab": 1.4105403996174295, + "m_b": 0.35278707376071444, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 34.92532081443127, + "L_0": 0.6234327855082189, + "gamma_y": 0.2247975535831614, + "gamma_theta": 0.09436461612083419, + "H_drop": 1.1072594727177896 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/737/simulation_code.py b/scipy/slab_springs_block_drop/737/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..aa099bb56dc3b9904263f362fe87d173ed3a6fc4 --- /dev/null +++ b/scipy/slab_springs_block_drop/737/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 1.2607079627101405 +L_slab = 1.4105403996174295 +m_b = 0.35278707376071444 +block_size = 0.18 +slab_thick = 0.1 +k = 34.92532081443127 +L_0 = 0.6234327855082189 +gamma_y = 0.2247975535831614 +gamma_theta = 0.09436461612083419 +H_drop = 1.1072594727177896 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/737/video.mp4 b/scipy/slab_springs_block_drop/737/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a07a65c97dccb055bac18f1a89f601e4add400cf --- /dev/null +++ b/scipy/slab_springs_block_drop/737/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2740528fb0bca1fcf628d76e1cfb4fa869b508a948d43796b9bcd46d9139578b +size 38306 diff --git a/scipy/slab_springs_block_drop/776/cot.json b/scipy/slab_springs_block_drop/776/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5f646ff0129094027d18436c15c4a30e2c8a56e2 --- /dev/null +++ b/scipy/slab_springs_block_drop/776/cot.json @@ -0,0 +1,126 @@ +{ + "simulation": "slab_springs_block_drop", + "physical_observation": "A horizontal rigid slab (mass M_slab=1.120 kg, length L=1.577 m) is suspended above the floor by two vertical Hookean springs (each k=25.419 N/m, rest length L_0=0.632 m) attached to its left and right ends. At t=0 the slab is in static equilibrium. A point block (mass m_b=0.392 kg) is released from rest at height H_drop=1.028 m above the slab's body-frame x = +L/4 = 0.394 m, free-falls under gravity, hits the slab at that point and STICKS perfectly inelastically. The combined system then exhibits coupled translation+rotation about its new COM.", + "physical_law": { + "name": "Newton-Euler equations for a 3-DOF rigid body + ideal Hookean springs + impulsive perfectly inelastic collision", + "statement": "Pre-impact: slab in static equilibrium, block free-falls (mg). Impact: linear and angular impulses applied at the contact point conserve linear and angular momentum across the perfectly inelastic collision. Post-impact: M_total a = sum F (springs + gravity + viscous damping); I_total alpha = sum tau.", + "formula": "v_impact = \\sqrt(2 g H); v_com_y_after = m_b v_impact / M_total; omega_after = m_b v_impact d_block / I_total; M_total Y_com'' = F_L + F_R - M_total g - gamma_y vY; I_total theta'' = a_arm F_L + b_arm F_R - gamma_theta omega" + }, + "ode_system": { + "state_variables": [ + "X_com, Y_com --- combined COM position (m)", + "theta --- slab orientation (rad)", + "vX, vY, omega --- derivatives" + ], + "equations_latex": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t^2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total a_com = F_L + F_R + (0, -M_total g) - gamma_y vY (y-only damping)", + "I_total alpha = a_arm F_L_y + b_arm F_R_y - gamma_theta omega" + ], + "equations_python": [ + "Pre-impact: y_block(t) = y_block_0 - 0.5 g t**2 (free-fall).", + "Impact at t_impact: linear+angular momentum conserved.", + "Post-impact: M_total * a_com = F_L + F_R + (0, -M_total * g) - gamma_y * vY (y-only * damping)", + "I_total * alpha = a_arm * F_L_y + b_arm * F_R_y - gamma_theta * omega" + ] + }, + "derivation_steps": [ + "Combined COM offset from slab geometric centre toward block: d_slab = m_b L/4 / M_total = 0.1023 m.", + "Block's body-frame x relative to combined COM: d_block = M_slab L/4 / M_total = 0.2920 m.", + "Slab moment of inertia about its own centre: I_slab = (1/12) M_slab L^2 = 0.23215 kg m^2.", + "Combined moment of inertia (parallel-axis): I_total = I_slab + M_slab d_slab^2 + m_b d_block^2 = 0.27732 kg m^2.", + "Slab static equilibrium height: Y_s_eq = L_0 - M_slab g / (2 k) = 0.4162 m.", + "Block impact speed: v_impact = \\sqrt(2 g H) = 4.4894 m/s; t_impact = 0.4581 s.", + "Linear momentum conservation: v_com_y_after = m_b v_impact / M_total = -1.1646 m/s.", + "Angular momentum conservation (about combined COM): omega_after = d_block m_b v_impact / I_total = -1.8544 rad/s.", + "Springs attached at slab body-frame ends: arms a = -(L/2 + d_slab), b = +(L/2 - d_slab).", + "Translation eigenmode: omega_trans = \\sqrt(2k/M_total) = 5.798 rad/s; period 1.084 s.", + "Rotation eigenmode: omega_rot = \\sqrt(k(a^2 + b^2)/I_total) = 10.766 rad/s; period 0.584 s." + ], + "physical_constants_derived": { + "M_total_kg": 1.5123008849115829, + "d_block_m": 0.2920045405109036, + "d_slab_m": 0.10227853111271798, + "I_total_kg_m2": 0.27731927123307876, + "Y_s_eq_m": 0.4162085016840066, + "v_impact_m_s": 4.489395293007743, + "t_impact_s": 0.4581015605109942, + "v_com_y_after_m_s": -1.1645662449122336, + "omega_after_rad_s": -1.8544364647273388, + "omega_trans_rad_s": 5.79798970627602, + "omega_rot_rad_s": 10.766318828872999 + }, + "numerical_method": { + "solver": "Analytic free-fall pre-impact + RK45 for the post-impact 3-DOF rigid-body ODE.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Smooth post-impact dynamics; tight tolerances and small max_step capture the rigid-body oscillations accurately." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of motion with two ideal Hookean springs at the slab ends and viscous damping; impulse-momentum at the perfectly inelastic impact.", + "energy_check": "Energy decreases over time due to viscous damping (gamma_y, gamma_theta) and the impact dissipation.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block free-falls for 0.458 s, hits slab at v_impact=4.489 m/s.", + "Combined system oscillates with translational period 1.084 s and rotational period 0.584 s.", + "Damping causes the oscillations to decay over the simulation window." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M_slab": { + "value": 1.1200042730578732, + "unit": "", + "description": "" + }, + "L_slab": { + "value": 1.5771322864944861, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3922966118537097, + "unit": "", + "description": "" + }, + "block_size": { + "value": 0.18, + "unit": "", + "description": "" + }, + "slab_thickness": { + "value": 0.1, + "unit": "", + "description": "" + }, + "k": { + "value": 25.41927095995843, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.632108514970326, + "unit": "", + "description": "" + }, + "gamma_y": { + "value": 0.24376876451913404, + "unit": "", + "description": "" + }, + "gamma_theta": { + "value": 0.09253015682226949, + "unit": "", + "description": "" + }, + "H_drop": { + "value": 1.0282994947387796, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/slab_springs_block_drop/776/params.json b/scipy/slab_springs_block_drop/776/params.json new file mode 100644 index 0000000000000000000000000000000000000000..0df85af6ec29edb31d566404c6a7a51e1080c834 --- /dev/null +++ b/scipy/slab_springs_block_drop/776/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.8, + "M_slab": 1.1200042730578732, + "L_slab": 1.5771322864944861, + "m_b": 0.3922966118537097, + "block_size": 0.18, + "slab_thickness": 0.1, + "k": 25.41927095995843, + "L_0": 0.632108514970326, + "gamma_y": 0.24376876451913404, + "gamma_theta": 0.09253015682226949, + "H_drop": 1.0282994947387796 +} \ No newline at end of file diff --git a/scipy/slab_springs_block_drop/776/simulation_code.py b/scipy/slab_springs_block_drop/776/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..205d55063b1fe31a1aecc40dbdb2d0301af0d9a1 --- /dev/null +++ b/scipy/slab_springs_block_drop/776/simulation_code.py @@ -0,0 +1,154 @@ +"""Slab on two vertical springs + falling block — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.transforms import Affine2D + +g = 9.8 +M_slab = 1.1200042730578732 +L_slab = 1.5771322864944861 +m_b = 0.3922966118537097 +block_size = 0.18 +slab_thick = 0.1 +k = 25.41927095995843 +L_0 = 0.632108514970326 +gamma_y = 0.24376876451913404 +gamma_theta = 0.09253015682226949 +H_drop = 1.0282994947387796 +duration = 12 +fps = 30 + +X_anchor_L = -L_slab/2.0 +X_anchor_R = +L_slab/2.0 +M_total = M_slab + m_b +block_off = L_slab/4.0 +d_block = M_slab*block_off/M_total +d_slab = m_b*block_off/M_total +I_slab = (1.0/12.0)*M_slab*L_slab**2 +I_total = I_slab + M_slab*d_slab**2 + m_b*d_block**2 +a_arm = -(L_slab/2.0 + d_slab) +b_arm = +(L_slab/2.0 - d_slab) +b_block_arm = +d_block +Y_s_eq = L_0 - M_slab*g/(2.0*k) + +y_block_0 = Y_s_eq + slab_thick/2.0 + H_drop +v_impact = np.sqrt(2.0*g*H_drop) +t_impact = v_impact/g +v_com_y_after = m_b*(-v_impact)/M_total +omega_after = (b_block_arm*m_b*(-v_impact))/I_total +X_com0 = d_slab; Y_com0 = Y_s_eq + +def rhs(t, s): + X, Y, th, vX, vY, om = s + c, sn = np.cos(th), np.sin(th) + yL = Y + a_arm*sn; yR = Y + b_arm*sn + FLy = k*(L_0 - yL); FRy = k*(L_0 - yR) + aY = (FLy + FRy - M_total*g - gamma_y*vY)/M_total + rxL = a_arm*c; rxR = b_arm*c + tau = rxL*FLy + rxR*FRy - gamma_theta*om + return [vX, vY, om, 0.0, aY, tau/I_total] + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +N = len(t_eval) +y_block_arr = np.full(N, np.nan) +X_arr = np.full(N, np.nan); Y_arr = np.full(N, np.nan); th_arr = np.full(N, np.nan) +sticky = np.zeros(N, dtype=bool) +for i, t in enumerate(t_eval): + if t <= t_impact: + y_block_arr[i] = y_block_0 - 0.5*g*t*t + X_arr[i] = 0.0; Y_arr[i] = Y_s_eq; th_arr[i] = 0.0 + else: + sticky[i] = True +post = np.where(t_eval > t_impact)[0] +if post.size > 0: + t_post = t_eval[post] + t_post_local = np.concatenate(([t_impact], t_post)) + sol = solve_ivp(rhs, (t_impact, duration), + [X_com0, Y_com0, 0.0, 0.0, v_com_y_after, omega_after], + t_eval=t_post_local, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.005) + Xs = sol.y[0][1:]; Ys = sol.y[1][1:]; ths = sol.y[2][1:] + for j, idx in enumerate(post): + X_arr[idx] = Xs[j]; Y_arr[idx] = Ys[j]; th_arr[idx] = ths[j] + y_anchor_above = slab_thick/2.0 + block_size/2.0 + y_block_arr[idx] = Ys[j] + b_block_arm*np.sin(ths[j]) + y_anchor_above*np.cos(ths[j]) + +fig_w, fig_h = 8, 5; fa = fig_w/fig_h +x_lo_d, x_hi_d = -1.20, +1.20 +y_lo_d = -0.20 +y_hi_d = max(1.6, y_block_0 + 0.20) +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +for xa in (X_anchor_L, X_anchor_R): + ax.add_patch(patches.Rectangle((xa-0.06, -0.025), 0.12, 0.025, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +slab_p = patches.Rectangle((-L_slab/2.0, -slab_thick/2.0), L_slab, slab_thick, + facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab_p) +block_p = patches.Rectangle((-block_size/2.0, -block_size/2.0), block_size, block_size, + facecolor="#e63946", edgecolor="white", lw=1.5, zorder=5) +ax.add_patch(block_p) +sL, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) +sR, = ax.plot([],[], color="#a8dadc", lw=2.5, zorder=3) + +def spzz(p0, p1, n_coils=8, amp=0.06, n_pts=200): + x0, y0 = p0; x1, y1 = p1 + dx, dy = x1-x0, y1-y0; L = np.hypot(dx, dy) + if L < 1e-9: return np.array([x0,x1]), np.array([y0,y1]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + lead = min(0.06, 0.25*L) + s = np.linspace(0,1, n_pts); arc = s*L + middle = (arc>=lead) & (arc<=L-lead) + seg = max(L - 2*lead, 1e-6) + phase = np.zeros_like(arc); phase[middle] = (arc[middle]-lead)/seg + env = np.where(middle, amp*np.sin(2*np.pi*n_coils*phase), 0.0) + return x0+ux*arc+nx*env, y0+uy*arc+ny*env + +x_block_lab = block_off + +def update(f): + th = th_arr[f]; Xc = X_arr[f]; Yc = Y_arr[f] + c, sn = np.cos(th), np.sin(th) + if sticky[f]: + sx = Xc - d_slab*c; sy = Yc - d_slab*sn + else: + sx = 0.0; sy = Y_s_eq + tr = (Affine2D().rotate(th).translate(sx, sy)) + ax.transData + slab_p.set_transform(tr) + y_off = slab_thick/2.0 + block_size/2.0 + if sticky[f]: + xL = Xc + a_arm*c; yL = Yc + a_arm*sn + xR = Xc + b_arm*c; yR = Yc + b_arm*sn + bx = Xc + b_block_arm*c - y_off*sn + by = Yc + b_block_arm*sn + y_off*c + tb = (Affine2D().rotate(th).translate(bx, by)) + ax.transData + block_p.set_transform(tb) + else: + xL = -L_slab/2.0; yL = Y_s_eq + xR = +L_slab/2.0; yR = Y_s_eq + tb = (Affine2D().translate(x_block_lab, y_block_arr[f])) + ax.transData + block_p.set_transform(tb) + sxL, syL = spzz((X_anchor_L, 0.0), (xL, yL)) + sxR, syR = spzz((X_anchor_R, 0.0), (xR, yR)) + sL.set_data(sxL, syL); sR.set_data(sxR, syR) + return slab_p, block_p, sL, sR + +ani = animation.FuncAnimation(fig, update, frames=N, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/slab_springs_block_drop/776/video.mp4 b/scipy/slab_springs_block_drop/776/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f616b3bb2ac1d83f78457379ef5138d2d1a1712a --- /dev/null +++ b/scipy/slab_springs_block_drop/776/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:741fa46c83d36ce9d404ad50f2b3f602e9ab0ea6d7c0d62d3eee46c2f28d3d1b +size 43838 diff --git a/scipy/sliding_block_step_topple/017/cot.json b/scipy/sliding_block_step_topple/017/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d32a269ff69607d4e0d82175524b6fe1cf042c7f --- /dev/null +++ b/scipy/sliding_block_step_topple/017/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=0.899 kg, side s=0.300 m) slides at v_0=3.102 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.042 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.084, the upper mu_upper=0.233. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01352 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1851 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.04431 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.7525 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 6.0401 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5174 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.8083 J must exceed M g delta_h_max = 0.6775 J.", + "Topple possible: True.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.013516263796285025, + "d_pivot_m": 0.18509402523474322, + "I_pivot_kg_m2": 0.04430941889763483, + "phi_0_rad": 2.5173776357686353, + "theta_unstable_rad": 0.9465813089737387, + "delta_h_max_m": 0.07691387848770312, + "v_at_step_m_s": 2.7524755549248647, + "omega_after_rad_s": 6.040103376824258, + "KE_rot_post_impact_J": 0.8082669150894822, + "PE_threshold_J": 0.6774857685651616, + "topple_possible": true + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.247 m on the lower level with friction mu_floor=0.084 before reaching the step.", + "Block pivots about the step's top corner; either topples to the upper level or swings back.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 0.8988130911256632, + "unit": "", + "description": "" + }, + "s": { + "value": 0.3003787877157016, + "unit": "", + "description": "" + }, + "v_0": { + "value": 3.101818962600509, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.08370924401649521, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.042009247110810694, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.28536390544231044, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.2331785191536717, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.3967047360937308, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/017/params.json b/scipy/sliding_block_step_topple/017/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8cf2b2d0e3072f72acd7ca7bc2e7fa9131332abc --- /dev/null +++ b/scipy/sliding_block_step_topple/017/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 0.8988130911256632, + "s": 0.3003787877157016, + "v_0": 3.101818962600509, + "mu_floor": 0.08370924401649521, + "h_step": 0.042009247110810694, + "x_step": 1.0, + "e_land": 0.28536390544231044, + "mu_upper": 0.2331785191536717, + "X_b_0": -0.3967047360937308 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/017/simulation_code.py b/scipy/sliding_block_step_topple/017/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..527a034ec888d626b05d286f8b0c7d7a169d1160 --- /dev/null +++ b/scipy/sliding_block_step_topple/017/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 0.8988130911256632 +s = 0.3003787877157016 +v_0 = 3.101818962600509 +mu_floor = 0.08370924401649521 +h_step = 0.042009247110810694 +x_step = 1.0 +e_land = 0.28536390544231044 +mu_upper = 0.2331785191536717 +X_b_0 = -0.3967047360937308 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/017/video.mp4 b/scipy/sliding_block_step_topple/017/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..dda4957e8673abc4e8c1d244c433f5cf34917ee0 --- /dev/null +++ b/scipy/sliding_block_step_topple/017/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d890c1dd796ab8fe321f9763884957c3a8ef1182f650e2b7e8247a2322cab1d +size 5813 diff --git a/scipy/sliding_block_step_topple/095/cot.json b/scipy/sliding_block_step_topple/095/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..e8167fdbe1029e94a08a6486a81c6c6fdf7c229a --- /dev/null +++ b/scipy/sliding_block_step_topple/095/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.029 kg, side s=0.305 m) slides at v_0=3.189 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.054 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.077, the upper mu_upper=0.209. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01591 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1812 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.04970 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.8643 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 5.8257 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5687 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.8433 J must exceed M g delta_h_max = 0.8368 J.", + "Topple possible: True.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.015907207695174057, + "d_pivot_m": 0.18120551686552774, + "I_pivot_kg_m2": 0.049696300615046055, + "phi_0_rad": 2.5687039915042167, + "theta_unstable_rad": 0.9979076647093201, + "delta_h_max_m": 0.08298093522965055, + "v_at_step_m_s": 2.864284365580967, + "omega_after_rad_s": 5.825671081045431, + "KE_rot_post_impact_J": 0.8433075463978421, + "PE_threshold_J": 0.8368316597715512, + "topple_possible": true + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.295 m on the lower level with friction mu_floor=0.077 before reaching the step.", + "Block pivots about the step's top corner; either topples to the upper level or swings back.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.0290434237051462, + "unit": "", + "description": "" + }, + "s": { + "value": 0.3045479988767613, + "unit": "", + "description": "" + }, + "v_0": { + "value": 3.188926150733291, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.0774265842201237, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.054049417802503476, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.3609396464458988, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.20937839990035775, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.4471972362952832, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/095/params.json b/scipy/sliding_block_step_topple/095/params.json new file mode 100644 index 0000000000000000000000000000000000000000..fc4ecd93751ad3701eea87c31879489e8c6eaed0 --- /dev/null +++ b/scipy/sliding_block_step_topple/095/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.0290434237051462, + "s": 0.3045479988767613, + "v_0": 3.188926150733291, + "mu_floor": 0.0774265842201237, + "h_step": 0.054049417802503476, + "x_step": 1.0, + "e_land": 0.3609396464458988, + "mu_upper": 0.20937839990035775, + "X_b_0": -0.4471972362952832 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/095/simulation_code.py b/scipy/sliding_block_step_topple/095/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..82017f18fe0829e2740efe226e4a9abc726c5d6e --- /dev/null +++ b/scipy/sliding_block_step_topple/095/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.0290434237051462 +s = 0.3045479988767613 +v_0 = 3.188926150733291 +mu_floor = 0.0774265842201237 +h_step = 0.054049417802503476 +x_step = 1.0 +e_land = 0.3609396464458988 +mu_upper = 0.20937839990035775 +X_b_0 = -0.4471972362952832 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/095/video.mp4 b/scipy/sliding_block_step_topple/095/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f1fbf77a7e2af1959bacdb7077f168a62fbb84ca --- /dev/null +++ b/scipy/sliding_block_step_topple/095/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e224457f3637712b3ce664a54de7e4a5c448f54ac991d3d6271bcad31aa7ee0 +size 6586 diff --git a/scipy/sliding_block_step_topple/226/cot.json b/scipy/sliding_block_step_topple/226/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..fcb95781d5df0eaf0050aa2a678bb4a02eaf3e4c --- /dev/null +++ b/scipy/sliding_block_step_topple/226/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=0.866 kg, side s=0.252 m) slides at v_0=2.856 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.043 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.086, the upper mu_upper=0.399. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.00918 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1510 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.02892 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.3806 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 5.9128 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5599 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.5055 J must exceed M g delta_h_max = 0.5773 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.009184880119024703, + "d_pivot_m": 0.15095417364159922, + "I_pivot_kg_m2": 0.028919772341155472, + "phi_0_rad": 2.559903338999665, + "theta_unstable_rad": 0.9891070122047685, + "delta_h_max_m": 0.0680144856930866, + "v_at_step_m_s": 2.3805823267753703, + "omega_after_rad_s": 5.9128279352818165, + "KE_rot_post_impact_J": 0.5055398047686823, + "PE_threshold_J": 0.5772607148890272, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.478 m on the lower level with friction mu_floor=0.086 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 0.8660530764919148, + "unit": "", + "description": "" + }, + "s": { + "value": 0.2522551938242021, + "unit": "", + "description": "" + }, + "v_0": { + "value": 2.855819635901825, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.08592328311316492, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.04318790896358842, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.26489057363428414, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.3991767024747439, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.6037945841353762, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/226/params.json b/scipy/sliding_block_step_topple/226/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8008101137852f8cd51823a88653b346d3f67bfb --- /dev/null +++ b/scipy/sliding_block_step_topple/226/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 0.8660530764919148, + "s": 0.2522551938242021, + "v_0": 2.855819635901825, + "mu_floor": 0.08592328311316492, + "h_step": 0.04318790896358842, + "x_step": 1.0, + "e_land": 0.26489057363428414, + "mu_upper": 0.3991767024747439, + "X_b_0": -0.6037945841353762 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/226/simulation_code.py b/scipy/sliding_block_step_topple/226/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ce491ad56eade1b67b13dfaca828e78f24850e4e --- /dev/null +++ b/scipy/sliding_block_step_topple/226/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 0.8660530764919148 +s = 0.2522551938242021 +v_0 = 2.855819635901825 +mu_floor = 0.08592328311316492 +h_step = 0.04318790896358842 +x_step = 1.0 +e_land = 0.26489057363428414 +mu_upper = 0.3991767024747439 +X_b_0 = -0.6037945841353762 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/226/video.mp4 b/scipy/sliding_block_step_topple/226/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..7d7cfb4311211cc3144319e200fd2d80c6deffeb --- /dev/null +++ b/scipy/sliding_block_step_topple/226/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b4a493319c29db19feeca41229251bcf45ab194d0dad1c74b2571fadd8db5c7 +size 5644 diff --git a/scipy/sliding_block_step_topple/249/cot.json b/scipy/sliding_block_step_topple/249/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d444579cde66ea672eab4ac286998566152c746f --- /dev/null +++ b/scipy/sliding_block_step_topple/249/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.149 kg, side s=0.254 m) slides at v_0=2.825 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.048 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.134, the upper mu_upper=0.382. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01234 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1497 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.03809 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.0419 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 4.8854 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5832 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.4545 J must exceed M g delta_h_max = 0.7924 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.012343666136430675, + "d_pivot_m": 0.14967908966882118, + "I_pivot_kg_m2": 0.03808549613777982, + "phi_0_rad": 2.583188714536169, + "theta_unstable_rad": 1.0123923877412726, + "delta_h_max_m": 0.07037413096398089, + "v_at_step_m_s": 2.0419401868875378, + "omega_after_rad_s": 4.885408614204871, + "KE_rot_post_impact_J": 0.4544974066777329, + "PE_threshold_J": 0.7924215398158807, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.452 m on the lower level with friction mu_floor=0.134 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.148992388110974, + "unit": "", + "description": "" + }, + "s": { + "value": 0.25388622183104453, + "unit": "", + "description": "" + }, + "v_0": { + "value": 2.8254558802753937, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.1340392526335918, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.047638152210681975, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.2499428748866876, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.38150740581229775, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.5785743893510631, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/249/params.json b/scipy/sliding_block_step_topple/249/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6d0710c7f571959e146d6e1f3ee70388ef58442c --- /dev/null +++ b/scipy/sliding_block_step_topple/249/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.148992388110974, + "s": 0.25388622183104453, + "v_0": 2.8254558802753937, + "mu_floor": 0.1340392526335918, + "h_step": 0.047638152210681975, + "x_step": 1.0, + "e_land": 0.2499428748866876, + "mu_upper": 0.38150740581229775, + "X_b_0": -0.5785743893510631 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/249/simulation_code.py b/scipy/sliding_block_step_topple/249/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..2f8842551fbed281e5bde3cc896299d24f806b3f --- /dev/null +++ b/scipy/sliding_block_step_topple/249/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.148992388110974 +s = 0.25388622183104453 +v_0 = 2.8254558802753937 +mu_floor = 0.1340392526335918 +h_step = 0.047638152210681975 +x_step = 1.0 +e_land = 0.2499428748866876 +mu_upper = 0.38150740581229775 +X_b_0 = -0.5785743893510631 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/249/video.mp4 b/scipy/sliding_block_step_topple/249/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..900c6462a4de2a95429126806ea335b948549450 --- /dev/null +++ b/scipy/sliding_block_step_topple/249/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:db40bfec8a502204082c9dc9d0722496f1c9c7d014c284ac7f771d1ab56c8c4e +size 5203 diff --git a/scipy/sliding_block_step_topple/301/cot.json b/scipy/sliding_block_step_topple/301/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..72628edcec8d1526f4cef482ef5a061b1d83c6da --- /dev/null +++ b/scipy/sliding_block_step_topple/301/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=0.757 kg, side s=0.255 m) slides at v_0=3.099 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.046 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.119, the upper mu_upper=0.319. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.00818 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1509 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.02542 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.4650 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 5.9409 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5754 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.4486 J must exceed M g delta_h_max = 0.5188 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.008184151383106419, + "d_pivot_m": 0.1509194153325828, + "I_pivot_kg_m2": 0.02542034531255205, + "phi_0_rad": 2.5753831340161404, + "theta_unstable_rad": 1.0045868072212438, + "delta_h_max_m": 0.0699606613719671, + "v_at_step_m_s": 2.4650282381554693, + "omega_after_rad_s": 5.940943360660821, + "KE_rot_post_impact_J": 0.4486031037354253, + "PE_threshold_J": 0.5188372225741619, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.514 m on the lower level with friction mu_floor=0.119 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 0.7567477592953569, + "unit": "", + "description": "" + }, + "s": { + "value": 0.25473397952745225, + "unit": "", + "description": "" + }, + "v_0": { + "value": 3.0986622542520914, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.11883127447176817, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.04640823580311044, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.3084310653814657, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.31946453585010587, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.6409791906633318, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/301/params.json b/scipy/sliding_block_step_topple/301/params.json new file mode 100644 index 0000000000000000000000000000000000000000..be81c992a42dc3c5c45955179665c08096f5e03d --- /dev/null +++ b/scipy/sliding_block_step_topple/301/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 0.7567477592953569, + "s": 0.25473397952745225, + "v_0": 3.0986622542520914, + "mu_floor": 0.11883127447176817, + "h_step": 0.04640823580311044, + "x_step": 1.0, + "e_land": 0.3084310653814657, + "mu_upper": 0.31946453585010587, + "X_b_0": -0.6409791906633318 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/301/simulation_code.py b/scipy/sliding_block_step_topple/301/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..5f75903a559b7747d6e1c2df8be9a5747b5a5218 --- /dev/null +++ b/scipy/sliding_block_step_topple/301/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 0.7567477592953569 +s = 0.25473397952745225 +v_0 = 3.0986622542520914 +mu_floor = 0.11883127447176817 +h_step = 0.04640823580311044 +x_step = 1.0 +e_land = 0.3084310653814657 +mu_upper = 0.31946453585010587 +X_b_0 = -0.6409791906633318 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/301/video.mp4 b/scipy/sliding_block_step_topple/301/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..062dc446d2d3c734344a8021a0b768b400f94aca --- /dev/null +++ b/scipy/sliding_block_step_topple/301/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aa872c56ba7b83c1f69f3b970d3495cb49f6f64108850757df38ae0d6ac71597 +size 5710 diff --git a/scipy/sliding_block_step_topple/313/cot.json b/scipy/sliding_block_step_topple/313/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4ab8f89eb6f8221390d67ce27bb7e9992205c615 --- /dev/null +++ b/scipy/sliding_block_step_topple/313/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=0.759 kg, side s=0.284 m) slides at v_0=3.418 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.048 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.127, the upper mu_upper=0.394. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01018 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1703 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.03218 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.9004 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 6.4390 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5556 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.6671 J must exceed M g delta_h_max = 0.5659 J.", + "Topple possible: True.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.010181242918131354, + "d_pivot_m": 0.17029269331965008, + "I_pivot_kg_m2": 0.032181106223512744, + "phi_0_rad": 2.5556200699734863, + "theta_unstable_rad": 0.9848237431785898, + "delta_h_max_m": 0.07611913511655642, + "v_at_step_m_s": 2.9004267916818676, + "omega_after_rad_s": 6.438991814161576, + "KE_rot_post_impact_J": 0.6671242370817975, + "PE_threshold_J": 0.5659106598093103, + "topple_possible": true + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.311 m on the lower level with friction mu_floor=0.127 before reaching the step.", + "Block pivots about the step's top corner; either topples to the upper level or swings back.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 0.7586264032874888, + "unit": "", + "description": "" + }, + "s": { + "value": 0.28376710403729977, + "unit": "", + "description": "" + }, + "v_0": { + "value": 3.417669819874579, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.1271435636008391, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.047709993815556226, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.38727950524953214, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.39367310284182694, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.4532692926176301, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/313/params.json b/scipy/sliding_block_step_topple/313/params.json new file mode 100644 index 0000000000000000000000000000000000000000..4c9dec2f9d28e4a56e63a49d0f2a54915553faa6 --- /dev/null +++ b/scipy/sliding_block_step_topple/313/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 0.7586264032874888, + "s": 0.28376710403729977, + "v_0": 3.417669819874579, + "mu_floor": 0.1271435636008391, + "h_step": 0.047709993815556226, + "x_step": 1.0, + "e_land": 0.38727950524953214, + "mu_upper": 0.39367310284182694, + "X_b_0": -0.4532692926176301 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/313/simulation_code.py b/scipy/sliding_block_step_topple/313/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d37797ece6f0260005d6ede5f26f173875411f81 --- /dev/null +++ b/scipy/sliding_block_step_topple/313/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 0.7586264032874888 +s = 0.28376710403729977 +v_0 = 3.417669819874579 +mu_floor = 0.1271435636008391 +h_step = 0.047709993815556226 +x_step = 1.0 +e_land = 0.38727950524953214 +mu_upper = 0.39367310284182694 +X_b_0 = -0.4532692926176301 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/313/video.mp4 b/scipy/sliding_block_step_topple/313/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..78cec264b6e3774e784f812b4002251aa594b090 --- /dev/null +++ b/scipy/sliding_block_step_topple/313/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd89093286a7f1e0705814533952215a85a25fae44f994b5409679ce675a33bc +size 5846 diff --git a/scipy/sliding_block_step_topple/352/cot.json b/scipy/sliding_block_step_topple/352/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f682e633ab603af636f4ec14624e8a2d31510caf --- /dev/null +++ b/scipy/sliding_block_step_topple/352/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.216 kg, side s=0.266 m) slides at v_0=3.090 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.050 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.092, the upper mu_upper=0.313. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01433 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1565 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.04411 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.6545 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 6.0433 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5857 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.8055 J must exceed M g delta_h_max = 0.8808 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.01432682656882869, + "d_pivot_m": 0.15651484136560595, + "I_pivot_kg_m2": 0.04411148553217847, + "phi_0_rad": 2.5856883671237747, + "theta_unstable_rad": 1.0148920403288781, + "delta_h_max_m": 0.07392013803934026, + "v_at_step_m_s": 2.654539459172892, + "omega_after_rad_s": 6.043260013366319, + "KE_rot_post_impact_J": 0.8054975960528512, + "PE_threshold_J": 0.8807860465510773, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.392 m on the lower level with friction mu_floor=0.092 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.2158544286166981, + "unit": "", + "description": "" + }, + "s": { + "value": 0.26589479536197735, + "unit": "", + "description": "" + }, + "v_0": { + "value": 3.0901561275733496, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.09175026015962252, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.05035269435472299, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.3201176998855726, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.3126344125496094, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.5245272545616873, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/352/params.json b/scipy/sliding_block_step_topple/352/params.json new file mode 100644 index 0000000000000000000000000000000000000000..dec5bffb48821d5cf6a6f7ee4f5ee72232ae7ab0 --- /dev/null +++ b/scipy/sliding_block_step_topple/352/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.2158544286166981, + "s": 0.26589479536197735, + "v_0": 3.0901561275733496, + "mu_floor": 0.09175026015962252, + "h_step": 0.05035269435472299, + "x_step": 1.0, + "e_land": 0.3201176998855726, + "mu_upper": 0.3126344125496094, + "X_b_0": -0.5245272545616873 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/352/simulation_code.py b/scipy/sliding_block_step_topple/352/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..625f6ddb7e90dbada2acb8fa0035ae84d6b939ff --- /dev/null +++ b/scipy/sliding_block_step_topple/352/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.2158544286166981 +s = 0.26589479536197735 +v_0 = 3.0901561275733496 +mu_floor = 0.09175026015962252 +h_step = 0.05035269435472299 +x_step = 1.0 +e_land = 0.3201176998855726 +mu_upper = 0.3126344125496094 +X_b_0 = -0.5245272545616873 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/352/video.mp4 b/scipy/sliding_block_step_topple/352/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..bd22ffec7cd193de9717538f9e3c18e2aab23b4e --- /dev/null +++ b/scipy/sliding_block_step_topple/352/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:647e73924692143dd1a36097eaaf2d3f349567ad9c51f5fc43d9f6a2639a42d0 +size 6075 diff --git a/scipy/sliding_block_step_topple/377/cot.json b/scipy/sliding_block_step_topple/377/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..28ad5cecba8ee94197efd92dffb179503d106fe4 --- /dev/null +++ b/scipy/sliding_block_step_topple/377/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.214 kg, side s=0.346 m) slides at v_0=2.893 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.043 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.101, the upper mu_upper=0.205. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.02426 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.2166 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.08118 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.4145 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 4.6948 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.4974 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.8947 J must exceed M g delta_h_max = 1.0288 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.0242603325351541, + "d_pivot_m": 0.2165675501302642, + "I_pivot_kg_m2": 0.08118187919581624, + "phi_0_rad": 2.49737266724711, + "theta_unstable_rad": 0.9265763404522134, + "delta_h_max_m": 0.08650250519871203, + "v_at_step_m_s": 2.414497832624231, + "omega_after_rad_s": 4.6948123655269764, + "KE_rot_post_impact_J": 0.8946755810819738, + "PE_threshold_J": 1.0288325256981867, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.287 m on the lower level with friction mu_floor=0.101 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.2136401199521836, + "unit": "", + "description": "" + }, + "s": { + "value": 0.3463211680297802, + "unit": "", + "description": "" + }, + "v_0": { + "value": 2.892815772856573, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.10067140536539043, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.04309553908333792, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.2911577474045059, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.2048650739704424, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.4597181349060368, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/377/params.json b/scipy/sliding_block_step_topple/377/params.json new file mode 100644 index 0000000000000000000000000000000000000000..a41fc95943b09576e2610325ebbec5f41c642cfa --- /dev/null +++ b/scipy/sliding_block_step_topple/377/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.2136401199521836, + "s": 0.3463211680297802, + "v_0": 2.892815772856573, + "mu_floor": 0.10067140536539043, + "h_step": 0.04309553908333792, + "x_step": 1.0, + "e_land": 0.2911577474045059, + "mu_upper": 0.2048650739704424, + "X_b_0": -0.4597181349060368 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/377/simulation_code.py b/scipy/sliding_block_step_topple/377/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d4fd41d4e53ecd16eff2aec017618f71de0623dc --- /dev/null +++ b/scipy/sliding_block_step_topple/377/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.2136401199521836 +s = 0.3463211680297802 +v_0 = 2.892815772856573 +mu_floor = 0.10067140536539043 +h_step = 0.04309553908333792 +x_step = 1.0 +e_land = 0.2911577474045059 +mu_upper = 0.2048650739704424 +X_b_0 = -0.4597181349060368 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/377/video.mp4 b/scipy/sliding_block_step_topple/377/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1a87ce08f67a6b8470444db7ba536fd3ee876534 --- /dev/null +++ b/scipy/sliding_block_step_topple/377/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:516c34c4fcba110ea9ebdc37d84dda6a85172ce127a4ce2b2cee1fc09ac770c5 +size 6345 diff --git a/scipy/sliding_block_step_topple/414/cot.json b/scipy/sliding_block_step_topple/414/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..66ef874de0500997de2f326d8367d34d3d0c2cb2 --- /dev/null +++ b/scipy/sliding_block_step_topple/414/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.106 kg, side s=0.267 m) slides at v_0=2.979 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.042 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.093, the upper mu_upper=0.236. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01312 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1615 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.04195 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.5530 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 6.1267 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5427 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.7874 J must exceed M g delta_h_max = 0.7637 J.", + "Topple possible: True.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.013116308736133574, + "d_pivot_m": 0.16145642852612557, + "I_pivot_kg_m2": 0.04195399621142043, + "phi_0_rad": 2.542740562440697, + "theta_unstable_rad": 0.9719442356458003, + "delta_h_max_m": 0.07044429685213335, + "v_at_step_m_s": 2.5530094431160903, + "omega_after_rad_s": 6.126721241582304, + "KE_rot_post_impact_J": 0.7874075611048025, + "PE_threshold_J": 0.7636980155799755, + "topple_possible": true + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.286 m on the lower level with friction mu_floor=0.093 before reaching the step.", + "Block pivots about the step's top corner; either topples to the upper level or swings back.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.106240993508791, + "unit": "", + "description": "" + }, + "s": { + "value": 0.26672060438269707, + "unit": "", + "description": "" + }, + "v_0": { + "value": 2.978565434473189, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.0933603985726964, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.04234817051735631, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.26505557530854884, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.23566967828221072, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.41979201111382597, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/414/params.json b/scipy/sliding_block_step_topple/414/params.json new file mode 100644 index 0000000000000000000000000000000000000000..7106b427a96f70ee7d0aab8d3bc35c66e15d4335 --- /dev/null +++ b/scipy/sliding_block_step_topple/414/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.106240993508791, + "s": 0.26672060438269707, + "v_0": 2.978565434473189, + "mu_floor": 0.0933603985726964, + "h_step": 0.04234817051735631, + "x_step": 1.0, + "e_land": 0.26505557530854884, + "mu_upper": 0.23566967828221072, + "X_b_0": -0.41979201111382597 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/414/simulation_code.py b/scipy/sliding_block_step_topple/414/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..90f5fe08ae449d866a0c5318c7b6e3e40128e2c3 --- /dev/null +++ b/scipy/sliding_block_step_topple/414/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.106240993508791 +s = 0.26672060438269707 +v_0 = 2.978565434473189 +mu_floor = 0.0933603985726964 +h_step = 0.04234817051735631 +x_step = 1.0 +e_land = 0.26505557530854884 +mu_upper = 0.23566967828221072 +X_b_0 = -0.41979201111382597 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/414/video.mp4 b/scipy/sliding_block_step_topple/414/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..34c7642eea35ebf24a48f6fd9f5047305fb632b2 --- /dev/null +++ b/scipy/sliding_block_step_topple/414/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79d16a9c9ac989dcf0fe425c54800108225a0056792bc361c4341d855a992b7e +size 6155 diff --git a/scipy/sliding_block_step_topple/484/cot.json b/scipy/sliding_block_step_topple/484/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..c612450965a95641cb946d2f0de09fb020ffa67f --- /dev/null +++ b/scipy/sliding_block_step_topple/484/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.007 kg, side s=0.281 m) slides at v_0=3.284 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.044 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.114, the upper mu_upper=0.209. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01327 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1704 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.04250 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.7529 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 6.2707 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5418 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.8356 J must exceed M g delta_h_max = 0.7321 J.", + "Topple possible: True.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.013274973782253275, + "d_pivot_m": 0.17039164601921203, + "I_pivot_kg_m2": 0.042497949611319356, + "phi_0_rad": 2.541827165524354, + "theta_unstable_rad": 0.9710308387294573, + "delta_h_max_m": 0.074214267692646, + "v_at_step_m_s": 2.7528758758000658, + "omega_after_rad_s": 6.270749172585264, + "KE_rot_post_impact_J": 0.8355584596969513, + "PE_threshold_J": 0.7320509765830706, + "topple_possible": true + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.437 m on the lower level with friction mu_floor=0.114 before reaching the step.", + "Block pivots about the step's top corner; either topples to the upper level or swings back.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.0065325922574926, + "unit": "", + "description": "" + }, + "s": { + "value": 0.28130570510649117, + "unit": "", + "description": "" + }, + "v_0": { + "value": 3.2843343520328236, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.113949233674768, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.04447547422667955, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.2688126739290743, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.2090715412357536, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.5772604436871756, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/484/params.json b/scipy/sliding_block_step_topple/484/params.json new file mode 100644 index 0000000000000000000000000000000000000000..d23bd5d424acdc3f868baee0e4ab87895c8e43ec --- /dev/null +++ b/scipy/sliding_block_step_topple/484/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.0065325922574926, + "s": 0.28130570510649117, + "v_0": 3.2843343520328236, + "mu_floor": 0.113949233674768, + "h_step": 0.04447547422667955, + "x_step": 1.0, + "e_land": 0.2688126739290743, + "mu_upper": 0.2090715412357536, + "X_b_0": -0.5772604436871756 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/484/simulation_code.py b/scipy/sliding_block_step_topple/484/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..2568db33f1fe56230692aafbb22472b5da3bf94f --- /dev/null +++ b/scipy/sliding_block_step_topple/484/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.0065325922574926 +s = 0.28130570510649117 +v_0 = 3.2843343520328236 +mu_floor = 0.113949233674768 +h_step = 0.04447547422667955 +x_step = 1.0 +e_land = 0.2688126739290743 +mu_upper = 0.2090715412357536 +X_b_0 = -0.5772604436871756 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/484/video.mp4 b/scipy/sliding_block_step_topple/484/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1afbfde74fa6b7379784419267427aa78d60d478 --- /dev/null +++ b/scipy/sliding_block_step_topple/484/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7e3910b0a9b4d563aec43331194bff58da7c028b3be720bb6150f285aa84371 +size 5813 diff --git a/scipy/sliding_block_step_topple/543/cot.json b/scipy/sliding_block_step_topple/543/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..bce39ca410cc7529386e71acbf8a2b1bbf5f5e10 --- /dev/null +++ b/scipy/sliding_block_step_topple/543/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.208 kg, side s=0.293 m) slides at v_0=2.993 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.054 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.070, the upper mu_upper=0.372. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01727 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1730 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.05342 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.6949 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 5.6122 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5801 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.8412 J must exceed M g delta_h_max = 0.9575 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.017268300559413113, + "d_pivot_m": 0.1730075689149993, + "I_pivot_kg_m2": 0.053417632126653826, + "phi_0_rad": 2.5801482896125636, + "theta_unstable_rad": 1.009351962817667, + "delta_h_max_m": 0.08089671499838474, + "v_at_step_m_s": 2.694868382326668, + "omega_after_rad_s": 5.61220852091879, + "KE_rot_post_impact_J": 0.8412444942048978, + "PE_threshold_J": 0.9574740808736562, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.238 m on the lower level with friction mu_floor=0.070 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.2077305836929626, + "unit": "", + "description": "" + }, + "s": { + "value": 0.29289731642765404, + "unit": "", + "description": "" + }, + "v_0": { + "value": 2.992516912835559, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.06975082832237522, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.054337804297212466, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.3472610995902255, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.37206122262373653, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.3847061172777309, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/543/params.json b/scipy/sliding_block_step_topple/543/params.json new file mode 100644 index 0000000000000000000000000000000000000000..0a4630863785ffabbc309ee38c8902645d72c6b1 --- /dev/null +++ b/scipy/sliding_block_step_topple/543/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.2077305836929626, + "s": 0.29289731642765404, + "v_0": 2.992516912835559, + "mu_floor": 0.06975082832237522, + "h_step": 0.054337804297212466, + "x_step": 1.0, + "e_land": 0.3472610995902255, + "mu_upper": 0.37206122262373653, + "X_b_0": -0.3847061172777309 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/543/simulation_code.py b/scipy/sliding_block_step_topple/543/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..db37667c37a5ad2c8b15c1c5b27c5194efe75c85 --- /dev/null +++ b/scipy/sliding_block_step_topple/543/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.2077305836929626 +s = 0.29289731642765404 +v_0 = 2.992516912835559 +mu_floor = 0.06975082832237522 +h_step = 0.054337804297212466 +x_step = 1.0 +e_land = 0.3472610995902255 +mu_upper = 0.37206122262373653 +X_b_0 = -0.3847061172777309 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/543/video.mp4 b/scipy/sliding_block_step_topple/543/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..775a02df1f858f33870af2d939ad903047b5bd9c --- /dev/null +++ b/scipy/sliding_block_step_topple/543/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edd04d5d89f8f7f188e7c80c5b69f34b0eb65633f8a25aa44f75a67daed07a7f +size 5850 diff --git a/scipy/sliding_block_step_topple/566/cot.json b/scipy/sliding_block_step_topple/566/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..8c22b632fa36b756337e44d91144a0732dfc8a64 --- /dev/null +++ b/scipy/sliding_block_step_topple/566/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.035 kg, side s=0.274 m) slides at v_0=3.141 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.060 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.108, the upper mu_upper=0.356. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01294 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1570 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.03846 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.6220 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 5.4214 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.6303 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.5652 J must exceed M g delta_h_max = 0.8133 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.012939355774507538, + "d_pivot_m": 0.15703696068541229, + "I_pivot_kg_m2": 0.03845884905596374, + "phi_0_rad": 2.630272525154033, + "theta_unstable_rad": 1.0594761983591363, + "delta_h_max_m": 0.08019422865867006, + "v_at_step_m_s": 2.62202577387259, + "omega_after_rad_s": 5.421403784075475, + "KE_rot_post_impact_J": 0.5651839191231707, + "PE_threshold_J": 0.8132750974637135, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.419 m on the lower level with friction mu_floor=0.108 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.0348282692069268, + "unit": "", + "description": "" + }, + "s": { + "value": 0.2739036440500784, + "unit": "", + "description": "" + }, + "v_0": { + "value": 3.1412969897022736, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.10758199427761783, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.06010908999829696, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.2414142786462096, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.3560546015730949, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.5562430858726921, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/566/params.json b/scipy/sliding_block_step_topple/566/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b2195929c26804972d7001eb9abcf97f7f615733 --- /dev/null +++ b/scipy/sliding_block_step_topple/566/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.0348282692069268, + "s": 0.2739036440500784, + "v_0": 3.1412969897022736, + "mu_floor": 0.10758199427761783, + "h_step": 0.06010908999829696, + "x_step": 1.0, + "e_land": 0.2414142786462096, + "mu_upper": 0.3560546015730949, + "X_b_0": -0.5562430858726921 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/566/simulation_code.py b/scipy/sliding_block_step_topple/566/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..7087aec37f6ef81cb795b55c787aa2a0ed6ddcf0 --- /dev/null +++ b/scipy/sliding_block_step_topple/566/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.0348282692069268 +s = 0.2739036440500784 +v_0 = 3.1412969897022736 +mu_floor = 0.10758199427761783 +h_step = 0.06010908999829696 +x_step = 1.0 +e_land = 0.2414142786462096 +mu_upper = 0.3560546015730949 +X_b_0 = -0.5562430858726921 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/566/video.mp4 b/scipy/sliding_block_step_topple/566/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..5a99a24e614e2fb7603c252b47d3f3129f317670 --- /dev/null +++ b/scipy/sliding_block_step_topple/566/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45d0296e04b3412c316668eee39881a8d3c712f291b7b3d769295caa063a9195 +size 5488 diff --git a/scipy/sliding_block_step_topple/595/cot.json b/scipy/sliding_block_step_topple/595/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..e81717d24e6877fc91214acb771f0485821a6a2e --- /dev/null +++ b/scipy/sliding_block_step_topple/595/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=0.889 kg, side s=0.305 m) slides at v_0=3.024 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.046 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.104, the upper mu_upper=0.209. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01373 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1856 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.04435 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.4763 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 5.2685 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.5326 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.6156 J must exceed M g delta_h_max = 0.6918 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.01373363749409596, + "d_pivot_m": 0.18562188497502138, + "I_pivot_kg_m2": 0.044354660813002524, + "phi_0_rad": 2.532585927843439, + "theta_unstable_rad": 0.9617896010485425, + "delta_h_max_m": 0.07943632094507566, + "v_at_step_m_s": 2.476266360444577, + "omega_after_rad_s": 5.268474916872161, + "KE_rot_post_impact_J": 0.6155723444771525, + "PE_threshold_J": 0.6918413901071256, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.472 m on the lower level with friction mu_floor=0.104 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 0.8887126112477537, + "unit": "", + "description": "" + }, + "s": { + "value": 0.30450031312510906, + "unit": "", + "description": "" + }, + "v_0": { + "value": 3.024246877057887, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.10449138846250881, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.046064592532608806, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.36325935864488484, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.20949086124099128, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.623992415722956, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/595/params.json b/scipy/sliding_block_step_topple/595/params.json new file mode 100644 index 0000000000000000000000000000000000000000..1102cd548e62dae0bb490f27e9b890de5e9580b1 --- /dev/null +++ b/scipy/sliding_block_step_topple/595/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 0.8887126112477537, + "s": 0.30450031312510906, + "v_0": 3.024246877057887, + "mu_floor": 0.10449138846250881, + "h_step": 0.046064592532608806, + "x_step": 1.0, + "e_land": 0.36325935864488484, + "mu_upper": 0.20949086124099128, + "X_b_0": -0.623992415722956 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/595/simulation_code.py b/scipy/sliding_block_step_topple/595/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..2f8c8b6b2fff44ddeb6da1661ed468e8caf26e8d --- /dev/null +++ b/scipy/sliding_block_step_topple/595/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 0.8887126112477537 +s = 0.30450031312510906 +v_0 = 3.024246877057887 +mu_floor = 0.10449138846250881 +h_step = 0.046064592532608806 +x_step = 1.0 +e_land = 0.36325935864488484 +mu_upper = 0.20949086124099128 +X_b_0 = -0.623992415722956 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/595/video.mp4 b/scipy/sliding_block_step_topple/595/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..bde38d4a8b36f519082610bf3945572772e53d36 --- /dev/null +++ b/scipy/sliding_block_step_topple/595/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d3e6db587b7708820163717284c583b8b815cec28203eb3b3ff7d8a483cf969 +size 5920 diff --git a/scipy/sliding_block_step_topple/679/cot.json b/scipy/sliding_block_step_topple/679/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..478673771e193980014f348eb06e13809069a0be --- /dev/null +++ b/scipy/sliding_block_step_topple/679/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.232 kg, side s=0.271 m) slides at v_0=3.405 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.065 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.132, the upper mu_upper=0.295. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01504 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1523 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.04362 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.8481 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 5.6240 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.6647 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.6898 J must exceed M g delta_h_max = 0.9948 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.01503769926198898, + "d_pivot_m": 0.1523037626664206, + "I_pivot_kg_m2": 0.04361520701089727, + "phi_0_rad": 2.6647138763167653, + "theta_unstable_rad": 1.0939175495218687, + "delta_h_max_m": 0.08239505290128374, + "v_at_step_m_s": 2.8480572195098697, + "omega_after_rad_s": 5.623997835188851, + "KE_rot_post_impact_J": 0.6897603599221628, + "PE_threshold_J": 0.9947874515429096, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.349 m on the lower level with friction mu_floor=0.132 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.2319783779791222, + "unit": "", + "description": "" + }, + "s": { + "value": 0.2706230472175142, + "unit": "", + "description": "" + }, + "v_0": { + "value": 3.4053681211624958, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.13178653924512293, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.06540281384362023, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.23340845378851494, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.294747416263853, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.4845489602837806, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/679/params.json b/scipy/sliding_block_step_topple/679/params.json new file mode 100644 index 0000000000000000000000000000000000000000..f66ce27627c89e3d0e50df1e81ee50bd06153023 --- /dev/null +++ b/scipy/sliding_block_step_topple/679/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.2319783779791222, + "s": 0.2706230472175142, + "v_0": 3.4053681211624958, + "mu_floor": 0.13178653924512293, + "h_step": 0.06540281384362023, + "x_step": 1.0, + "e_land": 0.23340845378851494, + "mu_upper": 0.294747416263853, + "X_b_0": -0.4845489602837806 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/679/simulation_code.py b/scipy/sliding_block_step_topple/679/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d36b1af1fb1cc99ebd8aa2f81c39a05f9fcba696 --- /dev/null +++ b/scipy/sliding_block_step_topple/679/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.2319783779791222 +s = 0.2706230472175142 +v_0 = 3.4053681211624958 +mu_floor = 0.13178653924512293 +h_step = 0.06540281384362023 +x_step = 1.0 +e_land = 0.23340845378851494 +mu_upper = 0.294747416263853 +X_b_0 = -0.4845489602837806 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/679/video.mp4 b/scipy/sliding_block_step_topple/679/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c0cb1a825a1d7f3541a1764bb10c9de2610d836f --- /dev/null +++ b/scipy/sliding_block_step_topple/679/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2ebd74dc8144d0dab03dd40773652cc17b5f96fc97476faacf336fc55b4d820e +size 5368 diff --git a/scipy/sliding_block_step_topple/708/cot.json b/scipy/sliding_block_step_topple/708/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..084774a2fd94fecf8da8bff6c79f5c30223d6d83 --- /dev/null +++ b/scipy/sliding_block_step_topple/708/cot.json @@ -0,0 +1,117 @@ +{ + "simulation": "sliding_block_step_topple", + "physical_observation": "A cubical block (mass M=1.219 kg, side s=0.259 m) slides at v_0=2.922 m/s in +x on the lower of a two-level floor (lower at y=0; upper at y=0.063 m for x>=1.000 m). The lower floor has kinetic friction mu_floor=0.114, the upper mu_upper=0.245. When the right face reaches the step, the block's right face engages the step's top corner and pivots about that corner; the topple-or-swing-back outcome depends on whether the post-impact rotational KE exceeds the gravitational PE rise to the unstable equilibrium.", + "physical_law": { + "name": "Newton's laws + impulsive angular-momentum conservation about the pivot + Lagrangian for a rigid body pivoting about a fixed axis", + "statement": "Slide phase: m a = -mu_floor m g. Step impact: angular momentum of the block about the pivot is conserved (impulse at the contact passes through the pivot). Pivot phase: I_pivot theta_ddot = M g d \\cos(phi_0 - theta) (gravity torque about pivot).", + "formula": "v_at_step^2 = v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2); omega_after = M v_at_step (s/2 - h_step) / I_pivot; I_pivot theta_ddot = M g d \\cos(phi_0 - theta)" + }, + "ode_system": { + "state_variables": [ + "theta (CW pivot angle, rad)", + "omega = theta_dot (rad/s)" + ], + "equations_latex": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t^2 (until cm_x = x_step - s/2).", + "Pivot: \\dot{theta} = omega; \\dot{omega} = M g d_pivot \\cos(phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) on whichever floor." + ], + "equations_python": [ + "Slide: cm_x(t) = X_b_0 + v_0 t - 0.5 mu_floor g t**2 (until cm_x = x_step - s/2).", + "Pivot: theta_dot = omega; omega_dot = M g d_pivot np.cos (phi_0 - theta) / I_pivot.", + "Post-pivot: sliding kinematics (constant deceleration mu g) * on whichever floor." + ] + }, + "derivation_steps": [ + "Cube moment of inertia: I_cm = M s^2 / 6 = 0.01357 kg m^2.", + "Pivot is the step's top corner at (x_step, h_step). Vector pivot->CM at impact = (-s/2, s/2 - h_step), so d_pivot = \\sqrt((s/2)^2 + (s/2 - h)^2) = 0.1455 m.", + "Parallel-axis: I_pivot = I_cm + M d^2 = 0.03936 kg m^2.", + "Pre-impact slide: v_at_step = \\sqrt(v_0^2 - 2 mu_floor g (x_step - X_b_0 - s/2)) = 2.3140 m/s.", + "Angular-momentum conservation about pivot: omega_after = M v_at_step (s/2 - h_step)/I_pivot = 4.7794 rad/s.", + "Pivot dynamics: gravity torque about pivot tau = M g d \\cos(phi_0 - theta), where phi_0 = \\atan2(s/2 - h_step, -s/2) = 2.6652 rad.", + "Topple criterion: post-impact rotational KE = (1/2) I_pivot omega_after^2 = 0.4495 J must exceed M g delta_h_max = 0.9405 J.", + "Topple possible: False.", + "If toppled: rotational KE -> sliding KE on upper level with restitution e_land.", + "Otherwise: block swings back to theta=0, separates with the same |omega| reversed, slides leftward." + ], + "physical_constants_derived": { + "I_cm_kg_m2": 0.013574111889683299, + "d_pivot_m": 0.14545285649779013, + "I_pivot_kg_m2": 0.039357689678618954, + "phi_0_rad": 2.6651847815805483, + "theta_unstable_rad": 1.0943884547856517, + "delta_h_max_m": 0.0787496304764552, + "v_at_step_m_s": 2.313986407393748, + "omega_after_rad_s": 4.779436727694626, + "KE_rot_post_impact_J": 0.44952415638835225, + "PE_threshold_J": 0.94053134093083, + "topple_possible": false + }, + "numerical_method": { + "solver": "RK45 with terminal events for the pivot phase; analytic kinematics elsewhere.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.005", + "justification": "Pivot ODE is smooth; impact and post-pivot phases use closed-form kinematic updates." + }, + "code_validation": { + "ode_source": "Standard 2D rigid-body slide-impact-pivot sequence with Coulomb friction and angular-momentum conservation at the impulsive step impact.", + "energy_check": "Friction monotonically decreases KE during sliding; the step impact dissipates KE by factor [I_pivot/(I_cm + M d^2)] (here ~unity since the pivot is the only contact). Topple-vs-swing-back outcome conserves energy along the gravity arc.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block slides 1.422 m on the lower level with friction mu_floor=0.114 before reaching the step.", + "Block lacks rotational KE to topple; swings back to lower floor and slides leftward.", + "Final motion settles to rest within the simulation duration." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.218705220946561, + "unit": "", + "description": "" + }, + "s": { + "value": 0.25851277029743375, + "unit": "", + "description": "" + }, + "v_0": { + "value": 2.9223908083160524, + "unit": "", + "description": "" + }, + "mu_floor": { + "value": 0.11433228631962633, + "unit": "", + "description": "" + }, + "h_step": { + "value": 0.06255315912738194, + "unit": "", + "description": "" + }, + "x_step": { + "value": 1.0, + "unit": "", + "description": "" + }, + "e_land": { + "value": 0.3570298880830206, + "unit": "", + "description": "" + }, + "mu_upper": { + "value": 0.24465408696416846, + "unit": "", + "description": "" + }, + "X_b_0": { + "value": -0.5509247901216773, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/sliding_block_step_topple/708/params.json b/scipy/sliding_block_step_topple/708/params.json new file mode 100644 index 0000000000000000000000000000000000000000..306703c9d9b2df9fbbe7bdd4c1ba55c3d10828f5 --- /dev/null +++ b/scipy/sliding_block_step_topple/708/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.218705220946561, + "s": 0.25851277029743375, + "v_0": 2.9223908083160524, + "mu_floor": 0.11433228631962633, + "h_step": 0.06255315912738194, + "x_step": 1.0, + "e_land": 0.3570298880830206, + "mu_upper": 0.24465408696416846, + "X_b_0": -0.5509247901216773 +} \ No newline at end of file diff --git a/scipy/sliding_block_step_topple/708/simulation_code.py b/scipy/sliding_block_step_topple/708/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e48b0c1d20025e07a0c5023759c3b86bcd5bb08f --- /dev/null +++ b/scipy/sliding_block_step_topple/708/simulation_code.py @@ -0,0 +1,143 @@ +"""Sliding block step topple — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Polygon +from scipy.integrate import solve_ivp + +g = 9.8 +M = 1.218705220946561 +s = 0.25851277029743375 +v_0 = 2.9223908083160524 +mu_floor = 0.11433228631962633 +h_step = 0.06255315912738194 +x_step = 1.0 +e_land = 0.3570298880830206 +mu_upper = 0.24465408696416846 +X_b_0 = -0.5509247901216773 +duration = 12 +fps = 30 + +I_cm = (1.0/6.0)*M*s**2 +half_s = s/2.0 +d2 = half_s**2 + (half_s - h_step)**2 +d_pivot = np.sqrt(d2) +I_pivot = I_cm + M*d2 +phi_0 = np.arctan2(half_s - h_step, -half_s) +slide_dist = (x_step - half_s) - X_b_0 +a_floor = mu_floor*g +v_at_step_sq = v_0**2 - 2.0*a_floor*slide_dist +if v_at_step_sq <= 0: v_at_step_sq = 1e-6 +v_at_step = np.sqrt(v_at_step_sq) +t1_end = (v_0 - v_at_step)/a_floor if a_floor > 1e-12 else slide_dist/v_0 +omega_after = M*v_at_step*(half_s - h_step)/I_pivot + +def pivot_ode(t, y): + th, om = y + return [om, M*g*d_pivot*np.cos(phi_0 - th)/I_pivot] +def ev_top(t, y): return y[0] - np.pi/2.0 +ev_top.terminal=True; ev_top.direction=+1 +def ev_back(t, y): return y[0] +ev_back.terminal=True; ev_back.direction=-1 + +sol = solve_ivp(pivot_ode, (0.0, 5.0), [0.0, omega_after], + events=[ev_top, ev_back], dense_output=True, + rtol=1e-9, atol=1e-11, max_step=0.005) +t_pivot_end = float(sol.t[-1]) +omega_end = float(sol.y[1,-1]) +toppled = len(sol.t_events[0]) > 0 +t2_end = t1_end + t_pivot_end +if toppled: + KE_rot = 0.5*I_pivot*omega_end**2 + v_slide_upper = e_land*np.sqrt(2.0*KE_rot/M) + a_up = mu_upper*g + t3_end_dur = v_slide_upper/a_up if a_up>0 else duration + ds_up = v_slide_upper**2/(2.0*a_up) if a_up>0 else 0.0 + final_up = x_step + (half_s - h_step) + ds_up + t3_end = t2_end + t3_end_dur + v_back_x = 0.0; final_lo = 0.0 +else: + om_z = abs(omega_end) + v_back_x = -om_z*(half_s - h_step) + a_dec = mu_floor*g + t3_end_dur = abs(v_back_x)/a_dec if a_dec>0 else duration + ds_back = v_back_x**2/(2.0*a_dec)*np.sign(v_back_x) + final_lo = (x_step - half_s) + ds_back + t3_end = t2_end + t3_end_dur + v_slide_upper = 0.0; final_up = 0.0 + +def state_at_t(t): + if t <= t1_end: + cx = X_b_0 + v_0*t - 0.5*a_floor*t*t + return cx, half_s, 0.0 + if t <= t2_end: + dt = t - t1_end + if dt <= sol.t[-1]: + theta = float(sol.sol(dt)[0]) + else: + theta = float(sol.y[0,-1]) + r0 = np.array([-half_s, half_s - h_step]) + c, sn = np.cos(theta), np.sin(theta) + Rm = np.array([[c, sn], [-sn, c]]) + r = Rm @ r0 + return x_step + r[0], h_step + r[1], theta + dt = t - t2_end + if toppled: + if dt < (t3_end - t2_end): + cx = (x_step + (half_s - h_step)) + v_slide_upper*dt - 0.5*(mu_upper*g)*dt*dt + else: + cx = final_up + return cx, h_step + half_s, np.pi/2.0 + else: + if dt < (t3_end - t2_end): + a = -np.sign(v_back_x)*mu_floor*g + cx = (x_step - half_s) + v_back_x*dt + 0.5*a*dt*dt + else: + cx = final_lo + return cx, half_s, 0.0 + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +cm_x = np.zeros(t_eval.size); cm_y = np.zeros(t_eval.size); th = np.zeros(t_eval.size) +for i, ti in enumerate(t_eval): + cm_x[i], cm_y[i], th[i] = state_at_t(ti) + +local = np.array([[-half_s,-half_s],[+half_s,-half_s], + [+half_s,+half_s],[-half_s,+half_s]]) +def corners(cx, cy, tcw): + c, sn = np.cos(tcw), np.sin(tcw) + Rm = np.array([[c, sn], [-sn, c]]) + return (Rm @ local.T).T + np.array([cx, cy]) + +x_lo_d = X_b_0 - 0.50; x_hi_d = x_step + 1.50 +y_lo_d = -0.10; y_hi_d = s + 0.30 +fig_w, fig_h = 9.0, 5.0; fa = fig_w/fig_h +dx, dy = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx/dy < fa: + e = (fa*dy-dx)/2; xlo, xhi, ylo, yhi = x_lo_d-e, x_hi_d+e, y_lo_d, y_hi_d +else: + e = (dx/fa-dy)/2; xlo, xhi, ylo, yhi = x_lo_d, x_hi_d, y_lo_d-e, y_hi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") + +ff = Polygon([(xlo,ylo),(xlo,0.0),(x_step,0.0),(x_step,h_step),(xhi,h_step),(xhi,ylo)], + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(ff) +ax.plot([xlo,x_step],[0,0], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,x_step],[0,h_step], color="#adb5bd", lw=2.0, zorder=1) +ax.plot([x_step,xhi],[h_step,h_step], color="#adb5bd", lw=2.0, zorder=1) +bp = Polygon(corners(X_b_0, half_s, 0.0), + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(bp) + +def update(f): + bp.set_xy(corners(cm_x[f], cm_y[f], th[f])) + return (bp,) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/sliding_block_step_topple/708/video.mp4 b/scipy/sliding_block_step_topple/708/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0f290f7a09f5d7f142a8dff208ee08934cdf694d --- /dev/null +++ b/scipy/sliding_block_step_topple/708/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e9629e2f0a2d500d9df9e87fdb5246f8e550931570de4638040b2a08ac500db4 +size 4995 diff --git a/scipy/spinning_ball_bounce/123/cot.json b/scipy/spinning_ball_bounce/123/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..0fc49525a88ccadfee881af48475d74d4fe39df7 --- /dev/null +++ b/scipy/spinning_ball_bounce/123/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.475 kg and radius R=0.111 m (I = (2/5) m R^2 = 0.00234 kg m^2) is launched from (-2.255, 1.096) m with initial velocity (3.772, 0.000) m/s and angular velocity omega_0=59.093 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.556 and Coulomb friction mu=0.401.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00234 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.002343492235017776, + "initial_contact_tangent_speed_vs0_m_s": 10.336624482505743, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.4482163088770923 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.6914 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.11109118383051399, + "unit": "", + "description": "" + }, + "m": { + "value": 0.47472744280685747, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.5555481284191288, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.40103361015582034, + "unit": "", + "description": "" + }, + "x0": { + "value": -2.2551886378317376, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.0964951848909157, + "unit": "", + "description": "" + }, + "vx0": { + "value": 3.771861509152986, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 59.093464908685036, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/123/params.json b/scipy/spinning_ball_bounce/123/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5f52530db06e98cdf204c121ba0a6d47d510a104 --- /dev/null +++ b/scipy/spinning_ball_bounce/123/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.11109118383051399, + "m": 0.47472744280685747, + "g": 9.81, + "e_n": 0.5555481284191288, + "mu": 0.40103361015582034, + "x0": -2.2551886378317376, + "y0": 1.0964951848909157, + "vx0": 3.771861509152986, + "vy0": 0.0, + "omega0": 59.093464908685036, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/123/simulation_code.py b/scipy/spinning_ball_bounce/123/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..45b77c6b2bf7a93d520cf13c4e0ab310e5f5d8e0 --- /dev/null +++ b/scipy/spinning_ball_bounce/123/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.11109118383051399 +m = 0.47472744280685747 +g = 9.81 +e_n = 0.5555481284191288 +mu = 0.40103361015582034 +x0, y0 = -2.2551886378317376, 1.0964951848909157 +vx0, vy0= 3.771861509152986, 0.0 +omega0 = 59.093464908685036 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/123/video.mp4 b/scipy/spinning_ball_bounce/123/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..af2e486f8a0e7828203b68d180e8f60aed006a67 --- /dev/null +++ b/scipy/spinning_ball_bounce/123/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50a15cf95122844dea84ebef54017b3c373fb57f36f72cbc2c2aa50fcb4331ac +size 7596 diff --git a/scipy/spinning_ball_bounce/197/cot.json b/scipy/spinning_ball_bounce/197/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5e1389efa1752428ac32828aade9df02ef945163 --- /dev/null +++ b/scipy/spinning_ball_bounce/197/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.483 kg and radius R=0.196 m (I = (2/5) m R^2 = 0.00746 kg m^2) is launched from (-1.793, 1.130) m with initial velocity (2.460, 0.000) m/s and angular velocity omega_0=73.375 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.647 and Coulomb friction mu=0.527.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00746 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.007456010341156517, + "initial_contact_tangent_speed_vs0_m_s": 16.874992966105765, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.43626256145670667 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.5812 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.19645597310341656, + "unit": "", + "description": "" + }, + "m": { + "value": 0.4829654179658335, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.6471662475169034, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.5274937327561218, + "unit": "", + "description": "" + }, + "x0": { + "value": -1.7932741936663017, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.1300002086070173, + "unit": "", + "description": "" + }, + "vx0": { + "value": 2.459952631093132, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 73.37542405709598, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/197/params.json b/scipy/spinning_ball_bounce/197/params.json new file mode 100644 index 0000000000000000000000000000000000000000..1743f666e57f706534d0152c1cfea5fc08c9fda7 --- /dev/null +++ b/scipy/spinning_ball_bounce/197/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.19645597310341656, + "m": 0.4829654179658335, + "g": 9.81, + "e_n": 0.6471662475169034, + "mu": 0.5274937327561218, + "x0": -1.7932741936663017, + "y0": 1.1300002086070173, + "vx0": 2.459952631093132, + "vy0": 0.0, + "omega0": 73.37542405709598, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/197/simulation_code.py b/scipy/spinning_ball_bounce/197/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..596243781fcd3d47ff1c1ddc4817c8070739c168 --- /dev/null +++ b/scipy/spinning_ball_bounce/197/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.19645597310341656 +m = 0.4829654179658335 +g = 9.81 +e_n = 0.6471662475169034 +mu = 0.5274937327561218 +x0, y0 = -1.7932741936663017, 1.1300002086070173 +vx0, vy0= 2.459952631093132, 0.0 +omega0 = 73.37542405709598 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/197/video.mp4 b/scipy/spinning_ball_bounce/197/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..57afce08eea6b8e0b61ee1772e9aaac807c946b9 --- /dev/null +++ b/scipy/spinning_ball_bounce/197/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0f0ca7c648b108a3ddc007a4359616548a97fdfbad757b12689e84d452b6535 +size 6879 diff --git a/scipy/spinning_ball_bounce/236/cot.json b/scipy/spinning_ball_bounce/236/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..29516f7829a73934dbd13a4ba1ce8655443dc506 --- /dev/null +++ b/scipy/spinning_ball_bounce/236/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.516 kg and radius R=0.152 m (I = (2/5) m R^2 = 0.00478 kg m^2) is launched from (-1.733, 1.284) m with initial velocity (2.857, 0.000) m/s and angular velocity omega_0=91.490 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.599 and Coulomb friction mu=0.618.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00478 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.004778171361156509, + "initial_contact_tangent_speed_vs0_m_s": 16.7787831754925, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.4802835555049122 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.6409 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.15216972511901622, + "unit": "", + "description": "" + }, + "m": { + "value": 0.5158758736867685, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.5992732903710627, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.6177820129414906, + "unit": "", + "description": "" + }, + "x0": { + "value": -1.7325202269740463, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.2836173256608145, + "unit": "", + "description": "" + }, + "vx0": { + "value": 2.8568505698658186, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 91.48950354440048, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/236/params.json b/scipy/spinning_ball_bounce/236/params.json new file mode 100644 index 0000000000000000000000000000000000000000..2abb50f570267a3066e6b2661e18d22820823d7b --- /dev/null +++ b/scipy/spinning_ball_bounce/236/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.15216972511901622, + "m": 0.5158758736867685, + "g": 9.81, + "e_n": 0.5992732903710627, + "mu": 0.6177820129414906, + "x0": -1.7325202269740463, + "y0": 1.2836173256608145, + "vx0": 2.8568505698658186, + "vy0": 0.0, + "omega0": 91.48950354440048, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/236/simulation_code.py b/scipy/spinning_ball_bounce/236/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..bbb3b1bc999ae94c3e8e756be1f943bed7d6ec1c --- /dev/null +++ b/scipy/spinning_ball_bounce/236/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.15216972511901622 +m = 0.5158758736867685 +g = 9.81 +e_n = 0.5992732903710627 +mu = 0.6177820129414906 +x0, y0 = -1.7325202269740463, 1.2836173256608145 +vx0, vy0= 2.8568505698658186, 0.0 +omega0 = 91.48950354440048 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/236/video.mp4 b/scipy/spinning_ball_bounce/236/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..8b4cb93d1a310b6db8b3c6feaac9cf78277bce99 --- /dev/null +++ b/scipy/spinning_ball_bounce/236/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee1b785f19a854d896cda6b9c694d585a08767dc3fdc0648c53fddeae540fb17 +size 6418 diff --git a/scipy/spinning_ball_bounce/257/cot.json b/scipy/spinning_ball_bounce/257/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..b25f343a953c3fb26044a6284d377efceb1f4e8f --- /dev/null +++ b/scipy/spinning_ball_bounce/257/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.534 kg and radius R=0.108 m (I = (2/5) m R^2 = 0.00250 kg m^2) is launched from (-1.606, 1.175) m with initial velocity (2.317, 0.000) m/s and angular velocity omega_0=54.492 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.677 and Coulomb friction mu=0.549.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00250 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.002500363353524398, + "initial_contact_tangent_speed_vs0_m_s": 8.2130075719892, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.46638624480283664 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.5421 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.10819789343265698, + "unit": "", + "description": "" + }, + "m": { + "value": 0.5339560640491867, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.6767004063927017, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.549366396830285, + "unit": "", + "description": "" + }, + "x0": { + "value": -1.6059351488296445, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.1751145078516916, + "unit": "", + "description": "" + }, + "vx0": { + "value": 2.3171354562427062, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 54.49156105258297, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/257/params.json b/scipy/spinning_ball_bounce/257/params.json new file mode 100644 index 0000000000000000000000000000000000000000..13eda7323750be7d52abaafcefae74ef8e429161 --- /dev/null +++ b/scipy/spinning_ball_bounce/257/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.10819789343265698, + "m": 0.5339560640491867, + "g": 9.81, + "e_n": 0.6767004063927017, + "mu": 0.549366396830285, + "x0": -1.6059351488296445, + "y0": 1.1751145078516916, + "vx0": 2.3171354562427062, + "vy0": 0.0, + "omega0": 54.49156105258297, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/257/simulation_code.py b/scipy/spinning_ball_bounce/257/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..076d628ebbb7737e2f04933b3bb4cee5d59b0bfe --- /dev/null +++ b/scipy/spinning_ball_bounce/257/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.10819789343265698 +m = 0.5339560640491867 +g = 9.81 +e_n = 0.6767004063927017 +mu = 0.549366396830285 +x0, y0 = -1.6059351488296445, 1.1751145078516916 +vx0, vy0= 2.3171354562427062, 0.0 +omega0 = 54.49156105258297 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/257/video.mp4 b/scipy/spinning_ball_bounce/257/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..66cf44c5cbb5de02c719e8e3b1ba4640f4e4cdd6 --- /dev/null +++ b/scipy/spinning_ball_bounce/257/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:24d89f10101104279ad9810e84a0e96aec66615fd84887a9be654db25aa01cb2 +size 7472 diff --git a/scipy/spinning_ball_bounce/277/cot.json b/scipy/spinning_ball_bounce/277/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5e9bdab8f6f0cbec57d98cfa88c620bcbc888106 --- /dev/null +++ b/scipy/spinning_ball_bounce/277/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.280 kg and radius R=0.189 m (I = (2/5) m R^2 = 0.00400 kg m^2) is launched from (-2.029, 1.099) m with initial velocity (2.170, 0.000) m/s and angular velocity omega_0=55.289 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.561 and Coulomb friction mu=0.386.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00400 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.003997280481357012, + "initial_contact_tangent_speed_vs0_m_s": 12.622111924721436, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.4306924537514091 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.6856 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.18905196303876065, + "unit": "", + "description": "" + }, + "m": { + "value": 0.2796032718273115, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.5606712351627834, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.38595505072467134, + "unit": "", + "description": "" + }, + "x0": { + "value": -2.0286946287501437, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.09890979260756, + "unit": "", + "description": "" + }, + "vx0": { + "value": 2.169548860975923, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 55.28936539845641, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/277/params.json b/scipy/spinning_ball_bounce/277/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8bb81919d844f486c23917bc86455d72936bf9fd --- /dev/null +++ b/scipy/spinning_ball_bounce/277/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.18905196303876065, + "m": 0.2796032718273115, + "g": 9.81, + "e_n": 0.5606712351627834, + "mu": 0.38595505072467134, + "x0": -2.0286946287501437, + "y0": 1.09890979260756, + "vx0": 2.169548860975923, + "vy0": 0.0, + "omega0": 55.28936539845641, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/277/simulation_code.py b/scipy/spinning_ball_bounce/277/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..aebab4619702250af3896e8abfb424004c77e5b7 --- /dev/null +++ b/scipy/spinning_ball_bounce/277/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.18905196303876065 +m = 0.2796032718273115 +g = 9.81 +e_n = 0.5606712351627834 +mu = 0.38595505072467134 +x0, y0 = -2.0286946287501437, 1.09890979260756 +vx0, vy0= 2.169548860975923, 0.0 +omega0 = 55.28936539845641 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/277/video.mp4 b/scipy/spinning_ball_bounce/277/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..22405d50392bbc40a99bac803530083f2a932deb --- /dev/null +++ b/scipy/spinning_ball_bounce/277/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2729e5193ec233b970ea47e846358769a4a6984c232621fc22e9e4539d8c669 +size 7006 diff --git a/scipy/spinning_ball_bounce/313/cot.json b/scipy/spinning_ball_bounce/313/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..033c0017274150fd91dabf2877a027e790d12858 --- /dev/null +++ b/scipy/spinning_ball_bounce/313/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.370 kg and radius R=0.150 m (I = (2/5) m R^2 = 0.00332 kg m^2) is launched from (-1.911, 1.045) m with initial velocity (3.832, 0.000) m/s and angular velocity omega_0=98.157 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.466 and Coulomb friction mu=0.580.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00332 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.0033220008999148335, + "initial_contact_tangent_speed_vs0_m_s": 18.543914917076176, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.4273089837959128 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.7829 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.14987877635700975, + "unit": "", + "description": "" + }, + "m": { + "value": 0.36970853517779395, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.465898925299276, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.5798343150832175, + "unit": "", + "description": "" + }, + "x0": { + "value": -1.911330235181665, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.045497282595382, + "unit": "", + "description": "" + }, + "vx0": { + "value": 3.8321994643130797, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 98.15742969318042, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/313/params.json b/scipy/spinning_ball_bounce/313/params.json new file mode 100644 index 0000000000000000000000000000000000000000..cfff49256030066b1f7b9d23050d32b2db8a60ff --- /dev/null +++ b/scipy/spinning_ball_bounce/313/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.14987877635700975, + "m": 0.36970853517779395, + "g": 9.81, + "e_n": 0.465898925299276, + "mu": 0.5798343150832175, + "x0": -1.911330235181665, + "y0": 1.045497282595382, + "vx0": 3.8321994643130797, + "vy0": 0.0, + "omega0": 98.15742969318042, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/313/simulation_code.py b/scipy/spinning_ball_bounce/313/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..caeaf79a5a8eeae08bdecdd5b4c8971af5124de7 --- /dev/null +++ b/scipy/spinning_ball_bounce/313/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.14987877635700975 +m = 0.36970853517779395 +g = 9.81 +e_n = 0.465898925299276 +mu = 0.5798343150832175 +x0, y0 = -1.911330235181665, 1.045497282595382 +vx0, vy0= 3.8321994643130797, 0.0 +omega0 = 98.15742969318042 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/313/video.mp4 b/scipy/spinning_ball_bounce/313/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e4f41cc1ccc5d22440124a8fb0a6ef8847a03a2e --- /dev/null +++ b/scipy/spinning_ball_bounce/313/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43f644eabfe7742fe314fdf925c885b7af5970237dcc811bd28e9c5c6afdfb50 +size 6575 diff --git a/scipy/spinning_ball_bounce/323/cot.json b/scipy/spinning_ball_bounce/323/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..afcc5257384705ce5ecece6d3de176d3945fcb78 --- /dev/null +++ b/scipy/spinning_ball_bounce/323/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.270 kg and radius R=0.113 m (I = (2/5) m R^2 = 0.00137 kg m^2) is launched from (-2.382, 1.236) m with initial velocity (3.208, 0.000) m/s and angular velocity omega_0=94.881 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.498 and Coulomb friction mu=0.485.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00137 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.0013727171179298953, + "initial_contact_tangent_speed_vs0_m_s": 13.900564325546219, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.4784885867563278 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.7522 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.11269912040928048, + "unit": "", + "description": "" + }, + "m": { + "value": 0.2701966779548394, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.49783696742245165, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.4847820158511983, + "unit": "", + "description": "" + }, + "x0": { + "value": -2.381929709698284, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.2357053825622935, + "unit": "", + "description": "" + }, + "vx0": { + "value": 3.2075613069648057, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 94.88098025741886, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/323/params.json b/scipy/spinning_ball_bounce/323/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c4f89897dcedf8eea40f69f77c7b794404a30273 --- /dev/null +++ b/scipy/spinning_ball_bounce/323/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.11269912040928048, + "m": 0.2701966779548394, + "g": 9.81, + "e_n": 0.49783696742245165, + "mu": 0.4847820158511983, + "x0": -2.381929709698284, + "y0": 1.2357053825622935, + "vx0": 3.2075613069648057, + "vy0": 0.0, + "omega0": 94.88098025741886, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/323/simulation_code.py b/scipy/spinning_ball_bounce/323/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..fd27052966221db619eaa451e5fff67dd60d79b8 --- /dev/null +++ b/scipy/spinning_ball_bounce/323/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.11269912040928048 +m = 0.2701966779548394 +g = 9.81 +e_n = 0.49783696742245165 +mu = 0.4847820158511983 +x0, y0 = -2.381929709698284, 1.2357053825622935 +vx0, vy0= 3.2075613069648057, 0.0 +omega0 = 94.88098025741886 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/323/video.mp4 b/scipy/spinning_ball_bounce/323/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0c3113b174e5dbbc11a15717e1e611419535ab14 --- /dev/null +++ b/scipy/spinning_ball_bounce/323/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8bbcc6527851ad7ba18f57ad3a704de39be23eeab0fa2bbb35fc85b1532bbff3 +size 7779 diff --git a/scipy/spinning_ball_bounce/338/cot.json b/scipy/spinning_ball_bounce/338/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..adae795e7b0ed6ca0c78286d978364eabd299127 --- /dev/null +++ b/scipy/spinning_ball_bounce/338/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.488 kg and radius R=0.151 m (I = (2/5) m R^2 = 0.00448 kg m^2) is launched from (-2.441, 1.192) m with initial velocity (2.127, 0.000) m/s and angular velocity omega_0=77.928 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.596 and Coulomb friction mu=0.657.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00448 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.004481167539835061, + "initial_contact_tangent_speed_vs0_m_s": 13.930743921180833, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.46067565562500656 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.6445 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.15146371367269132, + "unit": "", + "description": "" + }, + "m": { + "value": 0.48833065532050246, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.5961974442465378, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.6567888156877315, + "unit": "", + "description": "" + }, + "x0": { + "value": -2.44050151078915, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.192412916430214, + "unit": "", + "description": "" + }, + "vx0": { + "value": 2.127468058721208, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 77.92807647623219, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/338/params.json b/scipy/spinning_ball_bounce/338/params.json new file mode 100644 index 0000000000000000000000000000000000000000..70bc21e1bc4d661acaae7f162614b90c38c0427c --- /dev/null +++ b/scipy/spinning_ball_bounce/338/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.15146371367269132, + "m": 0.48833065532050246, + "g": 9.81, + "e_n": 0.5961974442465378, + "mu": 0.6567888156877315, + "x0": -2.44050151078915, + "y0": 1.192412916430214, + "vx0": 2.127468058721208, + "vy0": 0.0, + "omega0": 77.92807647623219, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/338/simulation_code.py b/scipy/spinning_ball_bounce/338/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..78f9d218295e44c40e079b27539304e0677b7ca1 --- /dev/null +++ b/scipy/spinning_ball_bounce/338/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.15146371367269132 +m = 0.48833065532050246 +g = 9.81 +e_n = 0.5961974442465378 +mu = 0.6567888156877315 +x0, y0 = -2.44050151078915, 1.192412916430214 +vx0, vy0= 2.127468058721208, 0.0 +omega0 = 77.92807647623219 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/338/video.mp4 b/scipy/spinning_ball_bounce/338/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6fadbf4a89a04c6acc1022a6c848644a11f79eea --- /dev/null +++ b/scipy/spinning_ball_bounce/338/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:835b62f96365ee94357b95f0f47985f06849a5653a4777f9fea1cc28607e08d2 +size 6406 diff --git a/scipy/spinning_ball_bounce/360/cot.json b/scipy/spinning_ball_bounce/360/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..798dbfc386b3d9f444ad4d705b4e5be5fa9344f7 --- /dev/null +++ b/scipy/spinning_ball_bounce/360/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.383 kg and radius R=0.164 m (I = (2/5) m R^2 = 0.00411 kg m^2) is launched from (-2.027, 1.243) m with initial velocity (3.220, 0.000) m/s and angular velocity omega_0=64.133 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.569 and Coulomb friction mu=0.511.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00411 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.004111830247993371, + "initial_contact_tangent_speed_vs0_m_s": 13.728014085870095, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.46901820875541494 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.6766 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.16385117780352515, + "unit": "", + "description": "" + }, + "m": { + "value": 0.38289178677135827, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.568668031071625, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.5112750701948322, + "unit": "", + "description": "" + }, + "x0": { + "value": -2.02748984237296, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.2428436609105225, + "unit": "", + "description": "" + }, + "vx0": { + "value": 3.2197187620290655, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 64.13316928634828, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/360/params.json b/scipy/spinning_ball_bounce/360/params.json new file mode 100644 index 0000000000000000000000000000000000000000..93925c40fd0b7ba060223aaff3bb3933b1981d08 --- /dev/null +++ b/scipy/spinning_ball_bounce/360/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.16385117780352515, + "m": 0.38289178677135827, + "g": 9.81, + "e_n": 0.568668031071625, + "mu": 0.5112750701948322, + "x0": -2.02748984237296, + "y0": 1.2428436609105225, + "vx0": 3.2197187620290655, + "vy0": 0.0, + "omega0": 64.13316928634828, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/360/simulation_code.py b/scipy/spinning_ball_bounce/360/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..4a73735b1d794916c7d97a7a35e10981993d67c5 --- /dev/null +++ b/scipy/spinning_ball_bounce/360/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.16385117780352515 +m = 0.38289178677135827 +g = 9.81 +e_n = 0.568668031071625 +mu = 0.5112750701948322 +x0, y0 = -2.02748984237296, 1.2428436609105225 +vx0, vy0= 3.2197187620290655, 0.0 +omega0 = 64.13316928634828 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/360/video.mp4 b/scipy/spinning_ball_bounce/360/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..55af93fdbab19be628593eed70e88162b1d9b460 --- /dev/null +++ b/scipy/spinning_ball_bounce/360/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3d2b8cc06dd54e6aaf9ddcde44fa0762d32473b87b2a5076e24e0aa35f7b9ff +size 8826 diff --git a/scipy/spinning_ball_bounce/435/cot.json b/scipy/spinning_ball_bounce/435/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..56d5ee476983830423cf0b6906485d98e3dab2ca --- /dev/null +++ b/scipy/spinning_ball_bounce/435/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.308 kg and radius R=0.167 m (I = (2/5) m R^2 = 0.00343 kg m^2) is launched from (-1.519, 1.330) m with initial velocity (2.742, 0.000) m/s and angular velocity omega_0=62.753 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.655 and Coulomb friction mu=0.648.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00343 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.003429205435031976, + "initial_contact_tangent_speed_vs0_m_s": 13.207771125869678, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.48701078529609343 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.5709 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.16677546863120868, + "unit": "", + "description": "" + }, + "m": { + "value": 0.3082259307568501, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.6550348625196397, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.6475527227896699, + "unit": "", + "description": "" + }, + "x0": { + "value": -1.5192398664112932, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.3301409406302984, + "unit": "", + "description": "" + }, + "vx0": { + "value": 2.7421641406812207, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 62.75267622440984, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/435/params.json b/scipy/spinning_ball_bounce/435/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ef4ad68285826e4de305655e29629ad60200cd01 --- /dev/null +++ b/scipy/spinning_ball_bounce/435/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.16677546863120868, + "m": 0.3082259307568501, + "g": 9.81, + "e_n": 0.6550348625196397, + "mu": 0.6475527227896699, + "x0": -1.5192398664112932, + "y0": 1.3301409406302984, + "vx0": 2.7421641406812207, + "vy0": 0.0, + "omega0": 62.75267622440984, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/435/simulation_code.py b/scipy/spinning_ball_bounce/435/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..225d82cf97d6d6ebb1e336ee93c36b20eb722fc2 --- /dev/null +++ b/scipy/spinning_ball_bounce/435/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.16677546863120868 +m = 0.3082259307568501 +g = 9.81 +e_n = 0.6550348625196397 +mu = 0.6475527227896699 +x0, y0 = -1.5192398664112932, 1.3301409406302984 +vx0, vy0= 2.7421641406812207, 0.0 +omega0 = 62.75267622440984 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/435/video.mp4 b/scipy/spinning_ball_bounce/435/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4273851aa5aa6dba88147c35297568d97aba184a --- /dev/null +++ b/scipy/spinning_ball_bounce/435/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b7bd2c05d01c0b5884df81b01f46c34009da39fc7f005e8edc5be54408503152 +size 7820 diff --git a/scipy/spinning_ball_bounce/464/cot.json b/scipy/spinning_ball_bounce/464/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..54c36b00df8cc1636811a52f14462a344cc4fdaa --- /dev/null +++ b/scipy/spinning_ball_bounce/464/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.419 kg and radius R=0.164 m (I = (2/5) m R^2 = 0.00451 kg m^2) is launched from (-2.241, 1.252) m with initial velocity (2.277, 0.000) m/s and angular velocity omega_0=98.433 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.690 and Coulomb friction mu=0.498.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00451 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.004506377019107793, + "initial_contact_tangent_speed_vs0_m_s": 18.4106063263799, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.47098610726182494 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.5237 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.16390801314157172, + "unit": "", + "description": "" + }, + "m": { + "value": 0.419340839571527, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.6901325708806034, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.4981506928441639, + "unit": "", + "description": "" + }, + "x0": { + "value": -2.2411261616797415, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.2519739275526116, + "unit": "", + "description": "" + }, + "vx0": { + "value": 2.2767040274688286, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 98.43266347799475, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/464/params.json b/scipy/spinning_ball_bounce/464/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3a0e58a5cf86f3a309c2ce85ae52e4e635fd4793 --- /dev/null +++ b/scipy/spinning_ball_bounce/464/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.16390801314157172, + "m": 0.419340839571527, + "g": 9.81, + "e_n": 0.6901325708806034, + "mu": 0.4981506928441639, + "x0": -2.2411261616797415, + "y0": 1.2519739275526116, + "vx0": 2.2767040274688286, + "vy0": 0.0, + "omega0": 98.43266347799475, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/464/simulation_code.py b/scipy/spinning_ball_bounce/464/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..47b206f5e753b2f2fc7f5d3a0df522a1195560a5 --- /dev/null +++ b/scipy/spinning_ball_bounce/464/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.16390801314157172 +m = 0.419340839571527 +g = 9.81 +e_n = 0.6901325708806034 +mu = 0.4981506928441639 +x0, y0 = -2.2411261616797415, 1.2519739275526116 +vx0, vy0= 2.2767040274688286, 0.0 +omega0 = 98.43266347799475 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/464/video.mp4 b/scipy/spinning_ball_bounce/464/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e845d4a801682fb3fada93f4a10925dfe84d4e18 --- /dev/null +++ b/scipy/spinning_ball_bounce/464/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8971dcc95b05f713ad617ae8bdb76357d48627d44c55651b166f9816519de989 +size 6601 diff --git a/scipy/spinning_ball_bounce/563/cot.json b/scipy/spinning_ball_bounce/563/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f58b9d97913ac6256593a4237f2dc73e4e1c3997 --- /dev/null +++ b/scipy/spinning_ball_bounce/563/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.453 kg and radius R=0.101 m (I = (2/5) m R^2 = 0.00186 kg m^2) is launched from (-2.357, 1.349) m with initial velocity (2.648, 0.000) m/s and angular velocity omega_0=73.827 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.531 and Coulomb friction mu=0.446.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00186 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.001860828065120124, + "initial_contact_tangent_speed_vs0_m_s": 10.127316362576408, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.5042560650382649 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.7185 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.10131141838720231, + "unit": "", + "description": "" + }, + "m": { + "value": 0.4532412878446938, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.5306082094662112, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.44645908926470285, + "unit": "", + "description": "" + }, + "x0": { + "value": -2.357383964118144, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.348526267009429, + "unit": "", + "description": "" + }, + "vx0": { + "value": 2.6477864590973628, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 73.82711665227127, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/563/params.json b/scipy/spinning_ball_bounce/563/params.json new file mode 100644 index 0000000000000000000000000000000000000000..12a34878d6750b40cefeeff56820b9e8c283c303 --- /dev/null +++ b/scipy/spinning_ball_bounce/563/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.10131141838720231, + "m": 0.4532412878446938, + "g": 9.81, + "e_n": 0.5306082094662112, + "mu": 0.44645908926470285, + "x0": -2.357383964118144, + "y0": 1.348526267009429, + "vx0": 2.6477864590973628, + "vy0": 0.0, + "omega0": 73.82711665227127, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/563/simulation_code.py b/scipy/spinning_ball_bounce/563/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b89fe5667bef05c5e7b0aa95c09fe4f43c96f07d --- /dev/null +++ b/scipy/spinning_ball_bounce/563/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.10131141838720231 +m = 0.4532412878446938 +g = 9.81 +e_n = 0.5306082094662112 +mu = 0.44645908926470285 +x0, y0 = -2.357383964118144, 1.348526267009429 +vx0, vy0= 2.6477864590973628, 0.0 +omega0 = 73.82711665227127 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/563/video.mp4 b/scipy/spinning_ball_bounce/563/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..676bc1d61cbd31733cbf590ec36c462c8aa8bc87 --- /dev/null +++ b/scipy/spinning_ball_bounce/563/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c659abe5595802dc0ce346a75e466273b9d7044a868c5c7a228dbdc0ecc76a5 +size 8292 diff --git a/scipy/spinning_ball_bounce/719/cot.json b/scipy/spinning_ball_bounce/719/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..c44810b6a357e2be282d0eb3abe46b025957732d --- /dev/null +++ b/scipy/spinning_ball_bounce/719/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.454 kg and radius R=0.101 m (I = (2/5) m R^2 = 0.00185 kg m^2) is launched from (-2.004, 1.034) m with initial velocity (3.483, 0.000) m/s and angular velocity omega_0=64.017 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.634 and Coulomb friction mu=0.354.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00185 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.001846465441959945, + "initial_contact_tangent_speed_vs0_m_s": 9.93542900572838, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.4362755589618292 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.5983 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.10078868052322128, + "unit": "", + "description": "" + }, + "m": { + "value": 0.45442024681911425, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.6338196372086162, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.35397448040993007, + "unit": "", + "description": "" + }, + "x0": { + "value": -2.003924263684942, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.0343885427424957, + "unit": "", + "description": "" + }, + "vx0": { + "value": 3.4832444795928375, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 64.01695599784131, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/719/params.json b/scipy/spinning_ball_bounce/719/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5dd9bd63722809fe5cff37e572fd8ed7273b0c0c --- /dev/null +++ b/scipy/spinning_ball_bounce/719/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.10078868052322128, + "m": 0.45442024681911425, + "g": 9.81, + "e_n": 0.6338196372086162, + "mu": 0.35397448040993007, + "x0": -2.003924263684942, + "y0": 1.0343885427424957, + "vx0": 3.4832444795928375, + "vy0": 0.0, + "omega0": 64.01695599784131, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/719/simulation_code.py b/scipy/spinning_ball_bounce/719/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..3ccd5bf862989116db417dcf219244485a123dcb --- /dev/null +++ b/scipy/spinning_ball_bounce/719/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.10078868052322128 +m = 0.45442024681911425 +g = 9.81 +e_n = 0.6338196372086162 +mu = 0.35397448040993007 +x0, y0 = -2.003924263684942, 1.0343885427424957 +vx0, vy0= 3.4832444795928375, 0.0 +omega0 = 64.01695599784131 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/719/video.mp4 b/scipy/spinning_ball_bounce/719/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..5f2a30e6c89afe4c026a6e893faee21f51fed821 --- /dev/null +++ b/scipy/spinning_ball_bounce/719/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b984aea2cdd7d91426539a144db2e96cdad5a9f80aca94e62c1fe53c12fac6cd +size 7443 diff --git a/scipy/spinning_ball_bounce/738/cot.json b/scipy/spinning_ball_bounce/738/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..e99dc15dad06a218ee2dea8257610795d96c43b6 --- /dev/null +++ b/scipy/spinning_ball_bounce/738/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.566 kg and radius R=0.109 m (I = (2/5) m R^2 = 0.00269 kg m^2) is launched from (-1.742, 1.252) m with initial velocity (3.317, 0.000) m/s and angular velocity omega_0=92.024 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.621 and Coulomb friction mu=0.641.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00269 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.00269039503840138, + "initial_contact_tangent_speed_vs0_m_s": 13.346909194368743, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.48277568809300303 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.6149 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.10899005391907958, + "unit": "", + "description": "" + }, + "m": { + "value": 0.5662162474455825, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.6205414793622254, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.6408509238415988, + "unit": "", + "description": "" + }, + "x0": { + "value": -1.7420082502855476, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.2522100043111435, + "unit": "", + "description": "" + }, + "vx0": { + "value": 3.317241619118693, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 92.02369587500752, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/738/params.json b/scipy/spinning_ball_bounce/738/params.json new file mode 100644 index 0000000000000000000000000000000000000000..aaedf2ee286c1749afadff6b1fb920224a79c3f5 --- /dev/null +++ b/scipy/spinning_ball_bounce/738/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.10899005391907958, + "m": 0.5662162474455825, + "g": 9.81, + "e_n": 0.6205414793622254, + "mu": 0.6408509238415988, + "x0": -1.7420082502855476, + "y0": 1.2522100043111435, + "vx0": 3.317241619118693, + "vy0": 0.0, + "omega0": 92.02369587500752, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/738/simulation_code.py b/scipy/spinning_ball_bounce/738/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..7f80093bce68fe3ee03079097c128bed4bb3de24 --- /dev/null +++ b/scipy/spinning_ball_bounce/738/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.10899005391907958 +m = 0.5662162474455825 +g = 9.81 +e_n = 0.6205414793622254 +mu = 0.6408509238415988 +x0, y0 = -1.7420082502855476, 1.2522100043111435 +vx0, vy0= 3.317241619118693, 0.0 +omega0 = 92.02369587500752 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/738/video.mp4 b/scipy/spinning_ball_bounce/738/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..642c9c26c11531b1fb8d60da3e10758e3ae3184d --- /dev/null +++ b/scipy/spinning_ball_bounce/738/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c31468b305eea9c4867e45f96de70677391dfc14afffcef5727ce6986d5a3e8 +size 8070 diff --git a/scipy/spinning_ball_bounce/763/cot.json b/scipy/spinning_ball_bounce/763/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..7c437965a18d37b5ee5f84ffcad1858ec49dce3d --- /dev/null +++ b/scipy/spinning_ball_bounce/763/cot.json @@ -0,0 +1,118 @@ +{ + "simulation": "spinning_ball_bounce", + "physical_observation": "A solid ball of mass m=0.242 kg and radius R=0.134 m (I = (2/5) m R^2 = 0.00173 kg m^2) is launched from (-1.574, 1.265) m with initial velocity (2.185, 0.000) m/s and angular velocity omega_0=75.791 rad/s (CCW positive => backspin when moving right). Free flight is purely ballistic; each ground impact is resolved with normal restitution e_n=0.544 and Coulomb friction mu=0.379.", + "physical_law": { + "name": "Newton's laws for free flight + impulsive friction-cone (Routh) contact at the floor", + "statement": "Between bounces gravity acts on the ball's centre of mass; spin is conserved (no aerodynamic torque). At each contact the normal impulse J_n = -(1+e_n) m v_y (with v_y < 0 incoming) reverses the vertical velocity to -e_n v_y. The tangential impulse either drives the contact-point tangential velocity to zero (stick: J_t = -(2/7) m v_s) or saturates on the cone |J_t| = mu J_n (slip).", + "formula": "Free: vx' = 0, vy' = -g, omega' = 0. Bounce: J_n = -(1+e_n) m vy; J_t = clamp(-(2/7) m v_s, +/-mu J_n); vx <- vx + J_t/m; vy <- -e_n vy; omega <- omega + R J_t / I." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "omega (rad/s)", + "theta (rad)" + ], + "equations_latex": [ + "\\dot{x} = vx, \\dot{y} = vy", + "\\dot{vx} = 0, \\dot{vy} = -g", + "\\dot{omega} = 0, \\dot{theta} = omega", + "Plus impulsive jump at each (y - R = 0, vy < 0) event." + ], + "equations_python": [ + "x_dot = vx, y_dot = vy", + "vx_dot = 0, vy_dot = -g", + "omega_dot = 0, theta_dot = omega", + "Plus * impulsive * jump * at * each (y - R = 0, vy < 0) * event." + ] + }, + "derivation_steps": [ + "Solid sphere moment of inertia: I = (2/5) m R^2 = 0.00173 kg m^2.", + "Free flight ODE: only gravity acts, so trajectory is a parabola; spin and angular orientation evolve linearly.", + "Bounce condition: y_c - R = 0 with vy < 0 (use solve_ivp event with direction = -1).", + "Newton's restitution: vy' = -e_n vy.", + "Tangential contact-point velocity: v_s = vx + omega R.", + "Stick impulse (would zero v_s in one shot): J_t_stick = -(2/7) m v_s (reduced effective mass = m / (1 + m R^2 / I) = (2/7) m for solid sphere).", + "If |J_t_stick| <= mu J_n, contact STICKS; else slips with J_t = -sign(v_s) mu J_n.", + "Update post-bounce velocities and angular velocity accordingly.", + "When the rebound speed is too small to clear gravity in one frame, switch to a settled rolling/sliding regime on the floor." + ], + "physical_constants_derived": { + "I_solid_sphere_kg_m2": 0.0017348173803779748, + "initial_contact_tangent_speed_vs0_m_s": 12.338645115105038, + "first_normal_impulse_J_n_estimate": 0.0, + "free_fall_time_to_floor_s": 0.4802677445456816 + }, + "numerical_method": { + "solver": "RK45 with terminal events for ground contact; impulsive update at each event.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=0.05", + "justification": "Hybrid continuous-impulsive system; high-accuracy RK between bounces and exact impulse rules at each contact." + }, + "code_validation": { + "ode_source": "Standard ballistic projectile + Routh friction-cone bounce model.", + "energy_check": "Each bounce dissipates fraction (1 - e_n^2) = 0.7043 of the vertical kinetic energy plus any tangential dissipation when slipping; total mechanical energy strictly decreases.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Ball undergoes a sequence of decreasing-amplitude bounces, eventually settling into rolling/sliding on the floor.", + "Backspin (omega > 0) plus rightward motion (vx > 0) gives positive v_s; a stick impulse therefore reduces vx and omega in tandem.", + "If friction is sufficient and backspin is heavy, the ball can reverse direction after the first bounce." + ], + "parameters": { + "R": { + "value": 0.13396805008692095, + "unit": "", + "description": "" + }, + "m": { + "value": 0.24165250458750998, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "e_n": { + "value": 0.543750146176622, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.3790075377305402, + "unit": "", + "description": "" + }, + "x0": { + "value": -1.5740025955972574, + "unit": "", + "description": "" + }, + "y0": { + "value": 1.265341157229057, + "unit": "", + "description": "" + }, + "vx0": { + "value": 2.185135962571511, + "unit": "", + "description": "" + }, + "vy0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 75.7905272633717, + "unit": "", + "description": "" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_bounce/763/params.json b/scipy/spinning_ball_bounce/763/params.json new file mode 100644 index 0000000000000000000000000000000000000000..2c26cb37e7b2520f89bcbe69ee94c87d4d4fcd6f --- /dev/null +++ b/scipy/spinning_ball_bounce/763/params.json @@ -0,0 +1,13 @@ +{ + "R": 0.13396805008692095, + "m": 0.24165250458750998, + "g": 9.81, + "e_n": 0.543750146176622, + "mu": 0.3790075377305402, + "x0": -1.5740025955972574, + "y0": 1.265341157229057, + "vx0": 2.185135962571511, + "vy0": 0.0, + "omega0": 75.7905272633717, + "theta0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_ball_bounce/763/simulation_code.py b/scipy/spinning_ball_bounce/763/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..edfe50859ad278a3ff81c3347f4e59373c52aba9 --- /dev/null +++ b/scipy/spinning_ball_bounce/763/simulation_code.py @@ -0,0 +1,163 @@ +"""Spinning ball bounce — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches +from matplotlib.lines import Line2D + +R = 0.13396805008692095 +m = 0.24165250458750998 +g = 9.81 +e_n = 0.543750146176622 +mu = 0.3790075377305402 +x0, y0 = -1.5740025955972574, 1.265341157229057 +vx0, vy0= 2.185135962571511, 0.0 +omega0 = 75.7905272633717 +theta0 = 0.0 +duration = 12 +fps = 30 +I_b = (2.0/5.0)*m*R*R + +def ode(t, s): + x,y,vx,vy,om,th = s + return [vx, vy, 0.0, -g, 0.0, om] + +def bounce_event(t, s): + return s[1] - R +bounce_event.terminal = True +bounce_event.direction = -1.0 + +def apply_bounce(state): + x,y,vx,vy,om,th = state + vs = vx + om*R + Jn = -(1.0+e_n)*m*vy + Jt_stick = -(2.0/7.0)*m*vs + cone = mu*Jn + if abs(Jt_stick) <= cone: + Jt = Jt_stick + else: + Jt = -np.sign(vs)*cone + return [x, R, vx+Jt/m, -e_n*vy, om+R*Jt/I_b, th] + +t_grid = np.linspace(0.0, duration, int(duration*fps)+1) +state = [x0,y0,vx0,vy0,omega0,theta0] +t_now = 0.0 +ts=[]; xs=[]; ys=[]; vxs=[]; vys=[]; oms=[]; ths=[] +b_count = 0; max_bounces=200 +while t_now < duration - 1e-9 and b_count < max_bounces: + sub = t_grid[(t_grid>=t_now-1e-12)&(t_grid<=duration+1e-12)] + if sub.size==0 or sub[0] > t_now+1e-12: + sub = np.concatenate(([t_now], sub)) + else: + sub = sub.copy(); sub[0] = t_now + sol = solve_ivp(ode,(t_now,duration), state, t_eval=sub, + events=bounce_event, method="RK45", + rtol=1e-9, atol=1e-11, max_step=0.05) + for i, ti in enumerate(sol.t): + if ts and abs(ti-ts[-1]) < 1e-9: continue + if not np.any(np.isclose(t_grid, ti, atol=1e-7)): continue + ts.append(ti); xs.append(sol.y[0,i]); ys.append(sol.y[1,i]) + vxs.append(sol.y[2,i]); vys.append(sol.y[3,i]) + oms.append(sol.y[4,i]); ths.append(sol.y[5,i]) + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + v_reb = -e_n*ye[3]; v_min = g/fps + if v_reb < v_min: + x_s,_,vx_s,_,om_s,th_s = ye + vs0 = vx_s + om_s*R + if abs(vs0) < 1e-6: + a_x=0.0; a_om=0.0; t_stop=duration + else: + sgn = np.sign(vs0) + a_x = -sgn*mu*g + a_om = -sgn*mu*m*g*R/I_b + t_stop = te + abs(vs0)/((7.0/2.0)*mu*g) + for ti in t_grid: + if ti < te or any(abs(ti-tj)<1e-9 for tj in ts): continue + if ti <= t_stop: + dt_ = ti-te + vxf = vx_s + a_x*dt_; omf = om_s + a_om*dt_ + xf = x_s + vx_s*dt_ + 0.5*a_x*dt_*dt_ + thf = th_s + om_s*dt_ + 0.5*a_om*dt_*dt_ + else: + dts = t_stop-te + vxf = vx_s + a_x*dts; omf = om_s + a_om*dts + xf_stop = x_s + vx_s*dts + 0.5*a_x*dts*dts + th_stop = th_s + om_s*dts + 0.5*a_om*dts*dts + dt2 = ti-t_stop + xf = xf_stop + vxf*dt2; thf = th_stop + omf*dt2 + ts.append(ti); xs.append(xf); ys.append(R) + vxs.append(vxf); vys.append(0.0); oms.append(omf); ths.append(thf) + t_now = duration; break + state = apply_bounce(ye); b_count += 1; t_now = te + else: + t_now = duration + state = [sol.y[i,-1] for i in range(6)]; break + +if len(ts) < len(t_grid): + lx = xs[-1] if xs else x0; ly = ys[-1] if ys else y0 + lvx = vxs[-1] if vxs else vx0; lvy = vys[-1] if vys else vy0 + lom = oms[-1] if oms else omega0; lth = ths[-1] if ths else theta0 + for ti in t_grid: + if not any(abs(ti-tj)<1e-7 for tj in ts): + dt = ti - (ts[-1] if ts else 0.0) + ts.append(ti); xs.append(lx + lvx*dt); ys.append(ly) + vxs.append(lvx); vys.append(lvy); oms.append(lom) + ths.append(lth + lom*dt) + +order = np.argsort(ts) +ts = np.array(ts)[order]; xs=np.array(xs)[order]; ys=np.array(ys)[order] +vxs=np.array(vxs)[order]; vys=np.array(vys)[order] +oms=np.array(oms)[order]; ths=np.array(ths)[order] +keep = np.concatenate(([True], np.diff(ts)>1e-9)) +ts, xs, ys, vxs, vys, oms, ths = (a[keep] for a in (ts,xs,ys,vxs,vys,oms,ths)) + +def near(target, src): + idx = np.searchsorted(src, target); idx = np.clip(idx,1,len(src)-1) + L = src[idx-1]; Rr = src[idx] + idx -= (target-L) < (Rr-target) + return idx +ix = near(t_grid, ts) +xs, ys, vxs, vys, oms, ths = (a[ix] for a in (xs,ys,vxs,vys,oms,ths)) + +fig_w, fig_h = 9.0, 4.0; fa = fig_w/fig_h +xlo_d = min(-3.0, xs.min()-0.3); xhi_d = max(3.0, xs.max()+0.3) +ylo_d = -0.3; yhi_d = max(2.0, ys.max()+0.2) +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo, xhi); ax.set_ylim(ylo, yhi) +ax.set_aspect("equal"); ax.axis("off") +ax.add_patch(patches.Rectangle((xlo, ylo), xhi-xlo, -ylo, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo, xhi], [0,0], color="#adb5bd", lw=2.5, zorder=1) + +trail_line, = ax.plot([],[], color="#e63946", lw=1.5, alpha=0.35, zorder=2) +ball = patches.Circle((xs[0], ys[0]), R, facecolor="#e63946", + edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(ball) +spin = Line2D([xs[0], xs[0]+R*np.cos(ths[0])], + [ys[0], ys[0]+R*np.sin(ths[0])], + color="#1a1a2e", lw=2.0, zorder=5) +ax.add_line(spin) + +def update(f): + cx, cy, th = xs[f], ys[f], ths[f] + ball.set_center((cx, cy)) + spin.set_data([cx, cx+R*np.cos(th)], [cy, cy+R*np.sin(th)]) + lo = max(0, f-30) + trail_line.set_data(xs[lo:f+1], ys[lo:f+1]) + return ball, spin, trail_line + +ani = animation.FuncAnimation(fig, update, frames=len(ts), + interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_ball_bounce/763/video.mp4 b/scipy/spinning_ball_bounce/763/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3574e2dedb3f3c4b6f05fd15d83026eb78f7a3f8 --- /dev/null +++ b/scipy/spinning_ball_bounce/763/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d60f8c643c45acf7693f6f260e9209c18cac009509ee30b39b850c8c88f1363f +size 6637 diff --git a/scipy/spinning_ball_on_moving_belt/102/cot.json b/scipy/spinning_ball_on_moving_belt/102/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5238bb2306d97c76ceb57efe63954cae6cf2a887 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/102/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=1.388 kg, radius r=0.101 m, I=0.618 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and forward (top of ball moves +x) (\\omega(0)=3.875 rad/s). The belt itself starts at v_belt_0=+0.652 m/s (+x) and accelerates uniformly at a_belt=-0.064 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.048) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = +0.652 + (-0.064) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.618 \\cdot 1.388 \\cdot (0.101)^2 = 0.00883 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.227 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (3.875) \\cdot 0.101) - (+0.652) = -1.0447 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 1.045/1.227 = 0.852 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.227 m/s^2.", + "For this run |a_belt| = 0.064 m/s^2 \\leq 1.227 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = 0.2490 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = -3.9682 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = -0.0246 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.85178 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.227 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = -1.045 m/s \\Rightarrow friction is in the +x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.227 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = -0.025 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 1.3875608137581241, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.10145371890474397, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": 0.651571570939939, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": -0.06449611178472175, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.047777739801123154, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.6184749333761123, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 3.8752766605065645, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/102/params.json b/scipy/spinning_ball_on_moving_belt/102/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8c485274a55cb7f4b799fac882a734258ac36b0e --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/102/params.json @@ -0,0 +1,16 @@ +{ + "M": 1.3875608137581241, + "r": 0.10145371890474397, + "v_belt_0": 0.651571570939939, + "a_belt": -0.06449611178472175, + "mu_k": 0.047777739801123154, + "I_factor": 0.6184749333761123, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": 3.8752766605065645, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/102/simulation_code.py b/scipy/spinning_ball_on_moving_belt/102/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..84df464e7f7f4ae7c47dce2341a51cff5d6da317 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/102/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.3875608137581241 +r = 0.10145371890474397 +v_belt_0 = 0.651571570939939 +a_belt = -0.06449611178472175 +mu_k = 0.047777739801123154 +I_factor = 0.6184749333761123 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = 3.8752766605065645 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/102/video.mp4 b/scipy/spinning_ball_on_moving_belt/102/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..32c87e8ed0d52d63375f3f4bcf5bdeae60390eba --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/102/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32691eaa354384b09b19fcf5fef0521972ff716154f6c15dcf1d65d030eceee2 +size 15694 diff --git a/scipy/spinning_ball_on_moving_belt/122/cot.json b/scipy/spinning_ball_on_moving_belt/122/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d1ab9ae651844dda0f683128f06ef4bdec0b706a --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/122/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=1.369 kg, radius r=0.151 m, I=0.447 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and forward (top of ball moves +x) (\\omega(0)=0.255 rad/s). The belt itself starts at v_belt_0=-0.957 m/s (-x) and accelerates uniformly at a_belt=-0.189 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.073) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.957 + (-0.189) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.447 \\cdot 1.369 \\cdot (0.151)^2 = 0.01393 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 2.315 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (0.255) \\cdot 0.151) - (-0.957) = +0.9185 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 0.918/2.315 = 0.397 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 2.315 m/s^2.", + "For this run |a_belt| = 0.189 m/s^2 \\leq 2.315 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.2954 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 4.3817 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = -0.0582 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.39668 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 2.315 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = +0.918 m/s \\Rightarrow friction is in the -x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 2.315 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = -0.058 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 1.3689091002906595, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.15097107014796984, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.9569453376656671, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": -0.18851442364055848, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.07286576102694314, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.44659899586407426, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 0.2548651316459427, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/122/params.json b/scipy/spinning_ball_on_moving_belt/122/params.json new file mode 100644 index 0000000000000000000000000000000000000000..45be8324e5da37dc71cd22e808754319df2fb4fb --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/122/params.json @@ -0,0 +1,16 @@ +{ + "M": 1.3689091002906595, + "r": 0.15097107014796984, + "v_belt_0": -0.9569453376656671, + "a_belt": -0.18851442364055848, + "mu_k": 0.07286576102694314, + "I_factor": 0.44659899586407426, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": 0.2548651316459427, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/122/simulation_code.py b/scipy/spinning_ball_on_moving_belt/122/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..2cbef14c9dd8f1fc03b492b2f331aadc67b38844 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/122/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.3689091002906595 +r = 0.15097107014796984 +v_belt_0 = -0.9569453376656671 +a_belt = -0.18851442364055848 +mu_k = 0.07286576102694314 +I_factor = 0.44659899586407426 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = 0.2548651316459427 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/122/video.mp4 b/scipy/spinning_ball_on_moving_belt/122/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0624073b942379cec7576c824b3cd5565c3f5073 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/122/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7f3f08a3e5422c8a7d7ef27066bc14a6faa88f48928ce646d2a0e8e8f940f32 +size 19254 diff --git a/scipy/spinning_ball_on_moving_belt/189/cot.json b/scipy/spinning_ball_on_moving_belt/189/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..8e3ec7e6b35726103251810c76184b4ed64150df --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/189/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=0.910 kg, radius r=0.137 m, I=0.553 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and backward (top moves -x) (\\omega(0)=-1.777 rad/s). The belt itself starts at v_belt_0=+0.250 m/s (+x) and accelerates uniformly at a_belt=+0.135 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.064) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = +0.250 + (+0.135) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.553 \\cdot 0.910 \\cdot (0.137)^2 = 0.00950 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.757 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (-1.777) \\cdot 0.137) - (+0.250) = -0.0054 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 0.005/1.757 = 0.003 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.757 m/s^2.", + "For this run |a_belt| = 0.135 m/s^2 \\leq 1.757 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = 0.0889 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = -1.1692 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = +0.0482 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.00305 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.757 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = -0.005 m/s \\Rightarrow friction is in the +x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.757 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = +0.048 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 0.909547620369706, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.1374165481752213, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": 0.24952892331063103, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": 0.1354803219576371, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.06378309983436037, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.5530385019546411, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": -1.7768008917591338, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/189/params.json b/scipy/spinning_ball_on_moving_belt/189/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ffcc9cf2398389b83c7fcec760115835c0f7d133 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/189/params.json @@ -0,0 +1,16 @@ +{ + "M": 0.909547620369706, + "r": 0.1374165481752213, + "v_belt_0": 0.24952892331063103, + "a_belt": 0.1354803219576371, + "mu_k": 0.06378309983436037, + "I_factor": 0.5530385019546411, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": -1.7768008917591338, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/189/simulation_code.py b/scipy/spinning_ball_on_moving_belt/189/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..21c26f0350164f9f209ea1caa12253a7515d563b --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/189/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.909547620369706 +r = 0.1374165481752213 +v_belt_0 = 0.24952892331063103 +a_belt = 0.1354803219576371 +mu_k = 0.06378309983436037 +I_factor = 0.5530385019546411 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = -1.7768008917591338 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/189/video.mp4 b/scipy/spinning_ball_on_moving_belt/189/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e0c01c7570c128dbe72913107638c5f52c56890b --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/189/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef9a23e0f1afee9bbbe95d018f50996b8926ecd7a2ab2c482a13e37988b1d22c +size 21686 diff --git a/scipy/spinning_ball_on_moving_belt/196/cot.json b/scipy/spinning_ball_on_moving_belt/196/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..246a9827c351c0fe17bbf05185d2829fe6e282e1 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/196/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=1.485 kg, radius r=0.152 m, I=0.494 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and backward (top moves -x) (\\omega(0)=-10.574 rad/s). The belt itself starts at v_belt_0=-0.019 m/s (-x) and accelerates uniformly at a_belt=+0.122 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.053) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.019 + (+0.122) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.494 \\cdot 1.485 \\cdot (0.152)^2 = 0.01694 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.573 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (-10.574) \\cdot 0.152) - (-0.019) = +1.6257 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 1.626/1.573 = 1.034 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.573 m/s^2.", + "For this run |a_belt| = 0.122 m/s^2 \\leq 1.573 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.0063 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 0.0834 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = +0.0403 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 1.03363 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.573 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = +1.626 m/s \\Rightarrow friction is in the -x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.573 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = +0.040 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 1.4854000500832982, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.15195226943611712, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.0189422971025881, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": 0.12179121868334963, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.05299915312577881, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.49382687023804817, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": -10.573828586482406, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/196/params.json b/scipy/spinning_ball_on_moving_belt/196/params.json new file mode 100644 index 0000000000000000000000000000000000000000..dcc0739e58897e3d33f35fe6145dde86b7bf233e --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/196/params.json @@ -0,0 +1,16 @@ +{ + "M": 1.4854000500832982, + "r": 0.15195226943611712, + "v_belt_0": -0.0189422971025881, + "a_belt": 0.12179121868334963, + "mu_k": 0.05299915312577881, + "I_factor": 0.49382687023804817, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": -10.573828586482406, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/196/simulation_code.py b/scipy/spinning_ball_on_moving_belt/196/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..c7ad4ef3537184d4ee5399918b4931d5d8697f74 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/196/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.4854000500832982 +r = 0.15195226943611712 +v_belt_0 = -0.0189422971025881 +a_belt = 0.12179121868334963 +mu_k = 0.05299915312577881 +I_factor = 0.49382687023804817 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = -10.573828586482406 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/196/video.mp4 b/scipy/spinning_ball_on_moving_belt/196/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..371290a1c6ba9f9d0d74e30ee360e903352d6f5a --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/196/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3840ac93f91fdd0187eed6da203f76ff3633e9ed195fed920c218affa3cbd34b +size 19149 diff --git a/scipy/spinning_ball_on_moving_belt/198/cot.json b/scipy/spinning_ball_on_moving_belt/198/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d53a77aa8fa2c3640f82546da452372b5c4932e4 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/198/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=1.041 kg, radius r=0.099 m, I=0.427 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and forward (top of ball moves +x) (\\omega(0)=0.985 rad/s). The belt itself starts at v_belt_0=-0.667 m/s (-x) and accelerates uniformly at a_belt=-0.245 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.074) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.667 + (-0.245) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.427 \\cdot 1.041 \\cdot (0.099)^2 = 0.00433 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 2.431 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (0.985) \\cdot 0.099) - (-0.667) = +0.5702 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 0.570/2.431 = 0.235 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 2.431 m/s^2.", + "For this run |a_belt| = 0.245 m/s^2 \\leq 2.431 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.1998 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 4.7386 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = -0.0734 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.23459 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 2.431 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = +0.570 m/s \\Rightarrow friction is in the -x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 2.431 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = -0.073 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 1.0408122880595438, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.09869206154780066, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.6674095332640035, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": -0.24515984902022794, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.07416056913056454, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.4271307407097574, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 0.9845722990914858, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/198/params.json b/scipy/spinning_ball_on_moving_belt/198/params.json new file mode 100644 index 0000000000000000000000000000000000000000..933606d92f000877682732c8e43242f76b27f679 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/198/params.json @@ -0,0 +1,16 @@ +{ + "M": 1.0408122880595438, + "r": 0.09869206154780066, + "v_belt_0": -0.6674095332640035, + "a_belt": -0.24515984902022794, + "mu_k": 0.07416056913056454, + "I_factor": 0.4271307407097574, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": 0.9845722990914858, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/198/simulation_code.py b/scipy/spinning_ball_on_moving_belt/198/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..225d6370f0187978ecd3ab84879e046cc1e599ac --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/198/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.0408122880595438 +r = 0.09869206154780066 +v_belt_0 = -0.6674095332640035 +a_belt = -0.24515984902022794 +mu_k = 0.07416056913056454 +I_factor = 0.4271307407097574 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = 0.9845722990914858 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/198/video.mp4 b/scipy/spinning_ball_on_moving_belt/198/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..350edd066522937265669117fa3383cde5f98f13 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/198/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dff2b99fb90db11ed6e52a06789a1d595e407e9acf73a57200d54af022bd399a +size 17875 diff --git a/scipy/spinning_ball_on_moving_belt/221/cot.json b/scipy/spinning_ball_on_moving_belt/221/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..fbea2bc5e4c9a65f67aec134297de821ccdd03f1 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/221/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=0.794 kg, radius r=0.112 m, I=0.490 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and backward (top moves -x) (\\omega(0)=-1.841 rad/s). The belt itself starts at v_belt_0=+0.248 m/s (+x) and accelerates uniformly at a_belt=-0.124 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.057) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = +0.248 + (-0.124) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.490 \\cdot 0.794 \\cdot (0.112)^2 = 0.00485 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.697 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (-1.841) \\cdot 0.112) - (+0.248) = -0.0425 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 0.042/1.697 = 0.025 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.697 m/s^2.", + "For this run |a_belt| = 0.124 m/s^2 \\leq 1.697 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = 0.0816 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = -1.4910 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = -0.0407 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.02503 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.697 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = -0.042 m/s \\Rightarrow friction is in the +x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.697 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = -0.041 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 0.7944446057534141, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.11169499106764597, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": 0.24810255344528676, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": -0.12366019922923974, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.05685471192380168, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.4897466758149698, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": -1.841002489014837, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/221/params.json b/scipy/spinning_ball_on_moving_belt/221/params.json new file mode 100644 index 0000000000000000000000000000000000000000..a1fa6b6d34fbaa4c5fec7d7f2d6347e018d2c55b --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/221/params.json @@ -0,0 +1,16 @@ +{ + "M": 0.7944446057534141, + "r": 0.11169499106764597, + "v_belt_0": 0.24810255344528676, + "a_belt": -0.12366019922923974, + "mu_k": 0.05685471192380168, + "I_factor": 0.4897466758149698, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": -1.841002489014837, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/221/simulation_code.py b/scipy/spinning_ball_on_moving_belt/221/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..6895aac9d81b86ceb313d752122e5e461a38aeac --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/221/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.7944446057534141 +r = 0.11169499106764597 +v_belt_0 = 0.24810255344528676 +a_belt = -0.12366019922923974 +mu_k = 0.05685471192380168 +I_factor = 0.4897466758149698 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = -1.841002489014837 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/221/video.mp4 b/scipy/spinning_ball_on_moving_belt/221/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..d476ffb78b97aefdc19de56cd2f69c03ea89dc99 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/221/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:047ee061d0caddc37f2bfc7c3a8058dd9df2d88d2f3cd7320f6e93431bc60140 +size 17282 diff --git a/scipy/spinning_ball_on_moving_belt/232/cot.json b/scipy/spinning_ball_on_moving_belt/232/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..8483caf2a3f10522711f2be680ab1c0399bd9f8d --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/232/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=0.668 kg, radius r=0.120 m, I=0.483 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and forward (top of ball moves +x) (\\omega(0)=4.164 rad/s). The belt itself starts at v_belt_0=-0.924 m/s (-x) and accelerates uniformly at a_belt=+0.190 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.075) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.924 + (+0.190) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.483 \\cdot 0.668 \\cdot (0.120)^2 = 0.00467 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 2.267 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (4.164) \\cdot 0.120) - (-0.924) = +0.4231 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 0.423/2.267 = 0.187 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 2.267 m/s^2.", + "For this run |a_belt| = 0.190 m/s^2 \\leq 2.267 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.3010 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 5.1791 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = +0.0620 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.18664 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 2.267 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = +0.423 m/s \\Rightarrow friction is in the -x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 2.267 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = +0.062 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 0.6678538209140389, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.12031501177905593, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.9240792501219894, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": 0.19029158370735266, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.07526546133413287, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.4829878038904758, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 4.163582815517351, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/232/params.json b/scipy/spinning_ball_on_moving_belt/232/params.json new file mode 100644 index 0000000000000000000000000000000000000000..547bd919d5b8323c115691ea08d429b06aafcbc7 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/232/params.json @@ -0,0 +1,16 @@ +{ + "M": 0.6678538209140389, + "r": 0.12031501177905593, + "v_belt_0": -0.9240792501219894, + "a_belt": 0.19029158370735266, + "mu_k": 0.07526546133413287, + "I_factor": 0.4829878038904758, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": 4.163582815517351, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/232/simulation_code.py b/scipy/spinning_ball_on_moving_belt/232/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d4b1324878666aea6b776be829d0dba5b753d29c --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/232/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.6678538209140389 +r = 0.12031501177905593 +v_belt_0 = -0.9240792501219894 +a_belt = 0.19029158370735266 +mu_k = 0.07526546133413287 +I_factor = 0.4829878038904758 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = 4.163582815517351 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/232/video.mp4 b/scipy/spinning_ball_on_moving_belt/232/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..dcee54fcb759c733299ccf54e7a7fdff21f96cf0 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/232/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a260ef1cbc8450a3b0c1e9d5fbd54c38f43050fb1588e7b3f3f1bef0d84de2c1 +size 18377 diff --git a/scipy/spinning_ball_on_moving_belt/283/cot.json b/scipy/spinning_ball_on_moving_belt/283/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..98385d3bf8c7c1bb0e5f252a057fe8681e4d5564 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/283/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=0.850 kg, radius r=0.119 m, I=0.496 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and forward (top of ball moves +x) (\\omega(0)=11.912 rad/s). The belt itself starts at v_belt_0=-0.391 m/s (-x) and accelerates uniformly at a_belt=-0.191 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.048) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.391 + (-0.191) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.496 \\cdot 0.850 \\cdot (0.119)^2 = 0.00594 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.409 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (11.912) \\cdot 0.119) - (-0.391) = -1.0232 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 1.023/1.409 = 0.726 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.409 m/s^2.", + "For this run |a_belt| = 0.191 m/s^2 \\leq 1.409 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.1296 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 2.2029 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = -0.0631 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.72617 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.409 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = -1.023 m/s \\Rightarrow friction is in the +x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.409 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = -0.063 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 0.8499698964095048, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.11874278653171388, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.3912233584874276, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": -0.19053112092063937, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.04759595417221618, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.4956153626418842, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 11.911521102041135, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/283/params.json b/scipy/spinning_ball_on_moving_belt/283/params.json new file mode 100644 index 0000000000000000000000000000000000000000..080c3397086cb791e6235865d7bbf67449f8aee6 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/283/params.json @@ -0,0 +1,16 @@ +{ + "M": 0.8499698964095048, + "r": 0.11874278653171388, + "v_belt_0": -0.3912233584874276, + "a_belt": -0.19053112092063937, + "mu_k": 0.04759595417221618, + "I_factor": 0.4956153626418842, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": 11.911521102041135, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/283/simulation_code.py b/scipy/spinning_ball_on_moving_belt/283/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..6ea5b95ba8c12bd70c73d09e6fd97b5095b04a7b --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/283/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.8499698964095048 +r = 0.11874278653171388 +v_belt_0 = -0.3912233584874276 +a_belt = -0.19053112092063937 +mu_k = 0.04759595417221618 +I_factor = 0.4956153626418842 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = 11.911521102041135 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/283/video.mp4 b/scipy/spinning_ball_on_moving_belt/283/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..d74fd23f9bdd41b01ffaa2abe44bbea1e4214d85 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/283/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed33a623ba8689922c857f51ce1635acb8610170c59c185f12d90e3da29496b1 +size 19356 diff --git a/scipy/spinning_ball_on_moving_belt/289/cot.json b/scipy/spinning_ball_on_moving_belt/289/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f5528ae315e3364657043385c81fb9e72e31f5ad --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/289/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=0.956 kg, radius r=0.113 m, I=0.578 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and backward (top moves -x) (\\omega(0)=-0.563 rad/s). The belt itself starts at v_belt_0=+0.204 m/s (+x) and accelerates uniformly at a_belt=-0.188 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.052) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = +0.204 + (-0.188) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.578 \\cdot 0.956 \\cdot (0.113)^2 = 0.00707 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.380 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (-0.563) \\cdot 0.113) - (+0.204) = -0.1401 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 0.140/1.380 = 0.101 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.380 m/s^2.", + "For this run |a_belt| = 0.188 m/s^2 \\leq 1.380 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = 0.0746 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = -1.1414 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = -0.0687 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.10148 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.380 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = -0.140 m/s \\Rightarrow friction is in the +x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.380 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = -0.069 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 0.9555915788683307, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.11308267384522794, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": 0.2036898287758484, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": -0.1876513639073862, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.05154757331766104, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.57817165587555, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": -0.5626221069683233, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/289/params.json b/scipy/spinning_ball_on_moving_belt/289/params.json new file mode 100644 index 0000000000000000000000000000000000000000..9a2804c9902285217d5febbface84f23329b8cdc --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/289/params.json @@ -0,0 +1,16 @@ +{ + "M": 0.9555915788683307, + "r": 0.11308267384522794, + "v_belt_0": 0.2036898287758484, + "a_belt": -0.1876513639073862, + "mu_k": 0.05154757331766104, + "I_factor": 0.57817165587555, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": -0.5626221069683233, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/289/simulation_code.py b/scipy/spinning_ball_on_moving_belt/289/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..25c1681c69b4bdb289efdd7aaaf7bee23ffcde23 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/289/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.9555915788683307 +r = 0.11308267384522794 +v_belt_0 = 0.2036898287758484 +a_belt = -0.1876513639073862 +mu_k = 0.05154757331766104 +I_factor = 0.57817165587555 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = -0.5626221069683233 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/289/video.mp4 b/scipy/spinning_ball_on_moving_belt/289/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..40c409a6cdfc02245bb474814a217b4e320a7de6 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/289/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38ed995efddcf4a2b4083d491da7d7f3340b9ff2df4e0e62eedcd594b3b43683 +size 18940 diff --git a/scipy/spinning_ball_on_moving_belt/303/cot.json b/scipy/spinning_ball_on_moving_belt/303/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..e47385e6533d7244ab641309bab25671a19c7af3 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/303/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=0.414 kg, radius r=0.155 m, I=0.429 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and forward (top of ball moves +x) (\\omega(0)=2.534 rad/s). The belt itself starts at v_belt_0=-0.731 m/s (-x) and accelerates uniformly at a_belt=+0.286 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.037) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.731 + (+0.286) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.429 \\cdot 0.414 \\cdot (0.155)^2 = 0.00427 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.195 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (2.534) \\cdot 0.155) - (-0.731) = +0.3384 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 0.338/1.195 = 0.283 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.195 m/s^2.", + "For this run |a_belt| = 0.286 m/s^2 \\leq 1.195 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.2194 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 3.3012 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = +0.0857 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.28309 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.195 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = +0.338 m/s \\Rightarrow friction is in the -x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.195 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = +0.086 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 0.41376195355232587, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.15509989220055276, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.7314198627729191, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": 0.2856667822842233, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.0365524927315489, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.428513657728345, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 2.5339899295726482, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/303/params.json b/scipy/spinning_ball_on_moving_belt/303/params.json new file mode 100644 index 0000000000000000000000000000000000000000..0654442699cac43a5415e6e28d3d75b18e742104 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/303/params.json @@ -0,0 +1,16 @@ +{ + "M": 0.41376195355232587, + "r": 0.15509989220055276, + "v_belt_0": -0.7314198627729191, + "a_belt": 0.2856667822842233, + "mu_k": 0.0365524927315489, + "I_factor": 0.428513657728345, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": 2.5339899295726482, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/303/simulation_code.py b/scipy/spinning_ball_on_moving_belt/303/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..5f3bbbe04506c84c0c73ef0d418c7d4f3d103d3f --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/303/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.41376195355232587 +r = 0.15509989220055276 +v_belt_0 = -0.7314198627729191 +a_belt = 0.2856667822842233 +mu_k = 0.0365524927315489 +I_factor = 0.428513657728345 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = 2.5339899295726482 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/303/video.mp4 b/scipy/spinning_ball_on_moving_belt/303/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a26ba8d83ff65f8bc34a78b2cd94055a995510e4 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/303/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e5ae605bec34128aa6918ac71a2514203214cd9e220cc2d9446945fef71d6020 +size 18855 diff --git a/scipy/spinning_ball_on_moving_belt/495/cot.json b/scipy/spinning_ball_on_moving_belt/495/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..76702aae1dbed6c89ee87dc70798cf42fad784ea --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/495/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=0.818 kg, radius r=0.146 m, I=0.413 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and forward (top of ball moves +x) (\\omega(0)=0.881 rad/s). The belt itself starts at v_belt_0=+0.625 m/s (+x) and accelerates uniformly at a_belt=-0.182 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.074) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = +0.625 + (-0.182) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.413 \\cdot 0.818 \\cdot (0.146)^2 = 0.00721 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 2.465 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (0.881) \\cdot 0.146) - (+0.625) = -0.7533 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 0.753/2.465 = 0.306 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 2.465 m/s^2.", + "For this run |a_belt| = 0.182 m/s^2 \\leq 2.465 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = 0.1827 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = -3.0251 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = -0.0532 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.3056 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 2.465 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = -0.753 m/s \\Rightarrow friction is in the +x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 2.465 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = -0.053 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 0.8175065259334544, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.14610112689117366, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": 0.6247011194636554, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": -0.1818093718076575, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.07350241451389258, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.4134328469260946, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": 0.8805326118818932, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/495/params.json b/scipy/spinning_ball_on_moving_belt/495/params.json new file mode 100644 index 0000000000000000000000000000000000000000..469d9574793f64f161781394d3c0abf222d6a3da --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/495/params.json @@ -0,0 +1,16 @@ +{ + "M": 0.8175065259334544, + "r": 0.14610112689117366, + "v_belt_0": 0.6247011194636554, + "a_belt": -0.1818093718076575, + "mu_k": 0.07350241451389258, + "I_factor": 0.4134328469260946, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": 0.8805326118818932, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/495/simulation_code.py b/scipy/spinning_ball_on_moving_belt/495/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..407f9eef4a964e84ef187f0335519102ce57ad8b --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/495/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.8175065259334544 +r = 0.14610112689117366 +v_belt_0 = 0.6247011194636554 +a_belt = -0.1818093718076575 +mu_k = 0.07350241451389258 +I_factor = 0.4134328469260946 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = 0.8805326118818932 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/495/video.mp4 b/scipy/spinning_ball_on_moving_belt/495/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c0056e54df89bec6adac9d8a66fab66a0c9641c2 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/495/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:78c01065ff760cfe261fc73b1bb18afe78b1dc7e413d3679db8cee0a778c1732 +size 18436 diff --git a/scipy/spinning_ball_on_moving_belt/537/cot.json b/scipy/spinning_ball_on_moving_belt/537/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..54a7d235bdcc1f62350c3460303a72f1a33e9fde --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/537/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=0.580 kg, radius r=0.092 m, I=0.635 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and backward (top moves -x) (\\omega(0)=-11.585 rad/s). The belt itself starts at v_belt_0=-0.912 m/s (-x) and accelerates uniformly at a_belt=-0.278 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.042) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.912 + (-0.278) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.635 \\cdot 0.580 \\cdot (0.092)^2 = 0.00313 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.061 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (-11.585) \\cdot 0.092) - (-0.912) = +1.9788 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 1.979/1.061 = 1.865 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.061 m/s^2.", + "For this run |a_belt| = 0.278 m/s^2 \\leq 1.061 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.3543 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 6.0590 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = -0.1080 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 1.86528 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.061 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = +1.979 m/s \\Rightarrow friction is in the -x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.061 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = -0.108 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 0.58047536719026, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.09206893698363128, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.9121780166967612, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": -0.27809525421452136, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.04200697432454627, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.6351868320747563, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": -11.58500008368689, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/537/params.json b/scipy/spinning_ball_on_moving_belt/537/params.json new file mode 100644 index 0000000000000000000000000000000000000000..da9f1827f1329f152cb64f937dff1f5944dae9b5 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/537/params.json @@ -0,0 +1,16 @@ +{ + "M": 0.58047536719026, + "r": 0.09206893698363128, + "v_belt_0": -0.9121780166967612, + "a_belt": -0.27809525421452136, + "mu_k": 0.04200697432454627, + "I_factor": 0.6351868320747563, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": -11.58500008368689, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/537/simulation_code.py b/scipy/spinning_ball_on_moving_belt/537/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..585f32c00c4a27d3e92fd916bcc9f4fa05c6ae56 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/537/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.58047536719026 +r = 0.09206893698363128 +v_belt_0 = -0.9121780166967612 +a_belt = -0.27809525421452136 +mu_k = 0.04200697432454627 +I_factor = 0.6351868320747563 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = -11.58500008368689 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/537/video.mp4 b/scipy/spinning_ball_on_moving_belt/537/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9cd4a2ee8e49746357a495df53bed86d45646c24 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/537/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43d693983b1713391db7fe5af2834393d86665ae3158ae50a37c743703eb9d93 +size 18924 diff --git a/scipy/spinning_ball_on_moving_belt/548/cot.json b/scipy/spinning_ball_on_moving_belt/548/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..78475996b31353975cc674a7b976660bcfe1283b --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/548/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=1.170 kg, radius r=0.154 m, I=0.552 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and backward (top moves -x) (\\omega(0)=-8.962 rad/s). The belt itself starts at v_belt_0=-0.832 m/s (-x) and accelerates uniformly at a_belt=-0.048 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.053) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.832 + (-0.048) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.552 \\cdot 1.170 \\cdot (0.154)^2 = 0.01534 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.458 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (-8.962) \\cdot 0.154) - (-0.832) = +2.2133 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 2.213/1.458 = 1.518 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.458 m/s^2.", + "For this run |a_belt| = 0.048 m/s^2 \\leq 1.458 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.2960 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 3.4802 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = -0.0171 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 1.51762 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.458 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = +2.213 m/s \\Rightarrow friction is in the -x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.458 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = -0.017 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 1.1702944837376776, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.1540960707942891, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.8322453729589303, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": -0.048073590092682694, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.05286645484728909, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.5518641950071735, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": -8.962039311207295, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/548/params.json b/scipy/spinning_ball_on_moving_belt/548/params.json new file mode 100644 index 0000000000000000000000000000000000000000..57b62a430006b16da55de793122805318e1bb0c2 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/548/params.json @@ -0,0 +1,16 @@ +{ + "M": 1.1702944837376776, + "r": 0.1540960707942891, + "v_belt_0": -0.8322453729589303, + "a_belt": -0.048073590092682694, + "mu_k": 0.05286645484728909, + "I_factor": 0.5518641950071735, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": -8.962039311207295, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/548/simulation_code.py b/scipy/spinning_ball_on_moving_belt/548/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ea0a35612e81c0a7ef99dbbe670f173e773a4453 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/548/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.1702944837376776 +r = 0.1540960707942891 +v_belt_0 = -0.8322453729589303 +a_belt = -0.048073590092682694 +mu_k = 0.05286645484728909 +I_factor = 0.5518641950071735 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = -8.962039311207295 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/548/video.mp4 b/scipy/spinning_ball_on_moving_belt/548/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..05f5bed83bbc211581575c62fe461e4b6b01224a --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/548/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46df802b1e9aa11dbc764833a90d6aabbf8a86bb4097a4b907453f9fc87d27d5 +size 18466 diff --git a/scipy/spinning_ball_on_moving_belt/603/cot.json b/scipy/spinning_ball_on_moving_belt/603/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..fa9007e2fcb6d4b4baec873b6654ca41aaa5df47 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/603/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=1.147 kg, radius r=0.114 m, I=0.547 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and backward (top moves -x) (\\omega(0)=-10.284 rad/s). The belt itself starts at v_belt_0=-0.238 m/s (-x) and accelerates uniformly at a_belt=+0.222 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.052) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.238 + (+0.222) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.547 \\cdot 1.147 \\cdot (0.114)^2 = 0.00810 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 1.454 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (-10.284) \\cdot 0.114) - (-0.238) = +1.4057 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 1.406/1.454 = 0.967 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 1.454 m/s^2.", + "For this run |a_belt| = 0.222 m/s^2 \\leq 1.454 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.0841 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 1.3539 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = +0.0786 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.96665 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 1.454 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = +1.406 m/s \\Rightarrow friction is in the -x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 1.454 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = +0.079 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 1.1472435019669447, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.1135643505515801, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.2378869981587115, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": 0.22214428575617046, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.052425138797184356, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.5471419423397239, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": -10.283648617680797, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/603/params.json b/scipy/spinning_ball_on_moving_belt/603/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8bdda181a0905ea6c668269b329e53995986c518 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/603/params.json @@ -0,0 +1,16 @@ +{ + "M": 1.1472435019669447, + "r": 0.1135643505515801, + "v_belt_0": -0.2378869981587115, + "a_belt": 0.22214428575617046, + "mu_k": 0.052425138797184356, + "I_factor": 0.5471419423397239, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": -10.283648617680797, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/603/simulation_code.py b/scipy/spinning_ball_on_moving_belt/603/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..241743290b840e07620ae37338883110ff2efdec --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/603/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.1472435019669447 +r = 0.1135643505515801 +v_belt_0 = -0.2378869981587115 +a_belt = 0.22214428575617046 +mu_k = 0.052425138797184356 +I_factor = 0.5471419423397239 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = -10.283648617680797 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/603/video.mp4 b/scipy/spinning_ball_on_moving_belt/603/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ab41c9048da80bc7f42e5fad3789a4e644c47552 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/603/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60fdd44a0e7c1d6d9d820de8dee3e65e6c53efa016c72e77ff28e43af1afddc3 +size 19957 diff --git a/scipy/spinning_ball_on_moving_belt/611/cot.json b/scipy/spinning_ball_on_moving_belt/611/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ac907b65869b5bd1b32cbaa3b5b6184e7ac85706 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/611/cot.json @@ -0,0 +1,169 @@ +{ + "simulation": "spinning_ball_on_moving_belt", + "physical_observation": "A ball (mass M=1.202 kg, radius r=0.091 m, I=0.423 \\cdot M \\cdot r^2) is placed on a horizontal conveyor belt with initial linear velocity v_ball(0)=0.000 m/s and backward (top moves -x) (\\omega(0)=-2.713 rad/s). The belt itself starts at v_belt_0=-0.280 m/s (-x) and accelerates uniformly at a_belt=+0.108 m/s^2 so that v_belt(t) = v_belt_0 + a_belt \\cdot t. Kinetic friction (\\mu_k=0.082) at the contact translates and spins the ball; the system seeks pure rolling on the moving belt: v_ball - \\omega r = v_belt(t).", + "physical_law": { + "name": "Newton-Euler equations + Coulomb friction with a time-varying surface velocity", + "statement": "A rigid ball on a frictional surface whose own velocity v_belt(t) may itself be a function of time obeys Newton's 2nd law for the centre of mass (M \\dot{v} = \\SigmaF) and Euler's equation about the CoM (I_cm \\dot{\\omega} = \\Sigma\\tau). The only horizontal force is kinetic friction at the contact, F = -\\mu_k M g sgn(v_rel) with v_rel = (v - \\omega r) - v_belt(t); it has a moment arm r about the CoM, coupling translation and rotation. Slip persists while v_rel \\neq 0 and is driven to zero at the constant rate \\mu_k g (1 + 1/I_factor); the subsequent rolling state can be maintained iff |a_belt| \\leq \\mu_k g (1 + 1/I_factor), in which case the ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor).", + "formula": "v_belt(t) = v_belt_0 + a_belt t; M \\dot{v} = -mu_k M g sgn(v - omega r - v_belt(t)); I_cm \\dot{omega} = -r F_x = -F_x / (I_factor M r); rolling sustainable iff |a_belt| <= mu_k g (1 + 1/I_factor); in that regime a_ball = a_belt I_factor / (1 + I_factor)." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "v (m/s)", + "theta (rad)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v", + "\\dot{v} = -mu_k g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t)))", + "\\dot{theta} = -omega", + "\\dot{omega} = -r F_x / I_cm, F_x = -mu_k M g \\tanh(alpha (v - omega r - (v_belt_0 + a_belt t))), I_cm = I_factor M r^2" + ], + "equations_python": [ + "x_dot = v", + "v_dot = -mu_k * g np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t)))", + "theta_dot = -omega", + "omega_dot = -r * F_x / I_cm, F_x = -mu_k * M g * np.tanh (alpha (v - omega * r - (v_belt_0 + a_belt * t))), I_cm = I_factor * M r**2" + ] + }, + "derivation_steps": [ + "State variables (1-D translation + planar spin about the y-axis):", + " x(t) --- ball-centre x position", + " v(t) --- ball-centre x velocity (= \\dot{x})", + " \\theta(t) --- orientation angle of a visual marker on the ball (CCW from +x)", + " \\omega(t) --- angular velocity in the FORWARD-ROLLING sign convention (\\omega > 0 \\Rightarrow top of ball moves +x)", + "Bookkeeping for the marker: \\dot{\\theta} = -\\omega so a forward-rolling ball (\\omega > 0) shows the marker rotating clockwise to the viewer.", + "", + "Belt velocity (time-varying):", + " v_belt(t) = v_belt_0 + a_belt \\cdot t = -0.280 + (+0.108) \\cdot t m/s.", + "", + "Contact-point lab velocity (bottom of the ball):", + " v_contact = v - \\omega r.", + "Pure rolling on the (instantaneous) belt corresponds to", + " v - \\omega r = v_belt(t).", + "Slip speed of the contact relative to the belt:", + " v_rel = v_contact - v_belt(t) = (v - \\omega r) - v_belt(t).", + "", + "Kinetic Coulomb friction at the contact opposes v_rel:", + " F_x = -\\mu_k M g \\cdot sgn(v_rel), regularised as -\\mu_k M g \\cdot \\tanh(\\alpha v_rel).", + "", + "Newton-Euler equations:", + " Translation: M \\dot{v} = F_x \\Rightarrow \\dot{v} = -\\mu_k g \\cdot sgn(v_rel).", + " Rotation about the CoM (axis \\perp to the page):", + " I_cm \\dot{\\omega} = (r_contact \\times F)_y = -r F_x", + " \\Rightarrow \\dot{\\omega} = -r F_x / I_cm = -F_x / (I_factor \\cdot M \\cdot r).", + " I_cm = I_factor \\cdot M \\cdot r^2 = 0.423 \\cdot 1.202 \\cdot (0.091)^2 = 0.00421 kg \\cdot m^2.", + "", + "Slip dynamics (combining the two):", + " d v_rel / dt = \\dot{v} - r \\dot{\\omega} - a_belt = -\\mu_k g(1 + 1/I_factor) sgn(v_rel) - a_belt.", + " Slip-decay magnitude (a_belt = 0 limit): \\mu_k g (1 + 1/I_factor) = 2.704 m/s^2.", + "", + "Initial slip speed: v_rel(0) = (v(0) - \\omega(0) r) - v_belt_0 = (0.000 - (-2.713) \\cdot 0.091) - (-0.280) = +0.5265 m/s.", + "Approximate first-rolling time (small-|a_belt| limit):", + " t \\cdot \\approx |v_rel(0)| / [\\mu_k g (1 + 1/I_factor)] = 0.526/2.704 = 0.195 s.", + "", + "Belt-acceleration limit for sustained rolling. Once rolling, the rolling constraint v - \\omega r = v_belt(t) must be maintained as the belt accelerates. Differentiating and using F_x = M \\dot{v} = -r^-^1 I_cm \\dot{\\omega} gives", + " a_ball - r \\alpha_ball = a_belt together with I_cm \\alpha_ball = -r F_x = -r M a_ball.", + "Solving: a_ball = a_belt \\cdot I_factor / (1 + I_factor) and", + " required friction force F_static = M a_ball \\Rightarrow |a_belt| \\leq \\mu_k g (1 + 1/I_factor) = 2.704 m/s^2.", + "For this run |a_belt| = 0.108 m/s^2 \\leq 2.704 m/s^2 \\Rightarrow sustained rolling possible.", + "", + "Reference quasi-steady-state values (a_belt = 0):", + " v_term \\equiv v_belt_0 \\cdot I_factor/(1+I_factor) = -0.0831 m/s", + " \\omega_term \\equiv -v_belt_0 / [r(1+I_factor)] = 2.1593 rad/s", + "", + "After pure rolling is reached and the belt continues to accelerate, the rolling state itself accelerates at", + " a_ball,roll = a_belt \\cdot I_factor/(1+I_factor) = +0.0320 m/s^2." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction keeps the right-hand side continuous; standard non-stiff RK45 with tight tolerances captures the steep slip-to-roll transition within ~1/\\alpha \\approx 0.013 m/s relative-velocity window without spurious sign chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler equations of a 2-D rigid ball with Coulomb friction at the contact point; v_rel-based regularisation.", + "rolling_check": "At t > t \\cdot the residual v - \\omega r - v_belt should be < 1e-3 m/s (numerical tolerance set by the \\tanh regularisation).", + "energy_check": "Kinetic friction dissipates relative-slip energy, while the moving/accelerating belt can supply or remove mechanical energy. After rolling is reached, energy is constant only when a_belt=0; otherwise static-friction work changes the ball's energy as it tracks the belt.", + "physical_plausibility": true, + "t_star_est": 0.19467 + }, + "expected_behavior": [ + "During slip (|v_rel| > 0) friction drives v_rel toward 0 at the constant rate \\mu_k g (1+1/I_factor) = 2.704 m/s^2; the ball's linear velocity changes by \\pm \\mu_k g \\cdot \\Deltat and its angular velocity by \\mp \\mu_k g \\cdot \\Deltat / (I_factor r) --- the sign depends on sgn(v_rel).", + "Initial v_rel(0) = +0.526 m/s \\Rightarrow friction is in the -x direction at t=0; ball translation and spin both change in the corresponding senses.", + "Once v_rel \\approx 0 the contact-point velocity matches the belt surface --- this is pure rolling on a moving belt: v_ball - \\omega r = v_belt(t).", + "For |a_belt| \\leq \\mu_k g (1 + 1/I_factor) \\approx 2.704 m/s^2 the rolling state is sustainable: ball CoM accelerates at a_belt \\cdot I_factor/(1+I_factor) = +0.032 m/s^2 to keep up with the belt (this run: satisfies this bound).", + "Camera follows the ball, so on screen the ball appears nearly stationary while the belt's tick marks drift past it --- their drift speed is v_belt(t), so any acceleration of the belt shows up as a speed-up or slow-down of the ticks." + ], + "parameters": { + "M": { + "value": 1.2019061878754378, + "unit": "kg", + "description": "Ball mass" + }, + "r": { + "value": 0.09100474369973746, + "unit": "m", + "description": "Ball radius" + }, + "v_belt_0": { + "value": -0.27960593081179397, + "unit": "m/s", + "description": "Initial belt surface velocity (signed)" + }, + "a_belt": { + "value": 0.10779590490738622, + "unit": "m/s^2", + "description": "Belt acceleration (signed)" + }, + "mu_k": { + "value": 0.0819353313853775, + "unit": "", + "description": "Kinetic friction coefficient (ball-belt)" + }, + "I_factor": { + "value": 0.42289166442743675, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot r^2" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "s/m", + "description": "\\tanh sharpness for sgn(v_rel)" + }, + "x0": { + "value": 0.0, + "unit": "m", + "description": "Initial ball centre x" + }, + "v0": { + "value": 0.0, + "unit": "m/s", + "description": "Initial ball linear velocity" + }, + "theta0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "omega0": { + "value": -2.712766502646854, + "unit": "rad/s", + "description": "Initial ball angular velocity (forward-rolling sense)" + }, + "cam_window": { + "value": 4.0, + "unit": "", + "description": "" + }, + "belt_thickness": { + "value": 0.12, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_ball_on_moving_belt/611/params.json b/scipy/spinning_ball_on_moving_belt/611/params.json new file mode 100644 index 0000000000000000000000000000000000000000..a2d5fb63022d5a29061271762fe55a9d9204bc21 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/611/params.json @@ -0,0 +1,16 @@ +{ + "M": 1.2019061878754378, + "r": 0.09100474369973746, + "v_belt_0": -0.27960593081179397, + "a_belt": 0.10779590490738622, + "mu_k": 0.0819353313853775, + "I_factor": 0.42289166442743675, + "g": 9.81, + "alpha_tanh": 80.0, + "x0": 0.0, + "v0": 0.0, + "theta0": 0.0, + "omega0": -2.712766502646854, + "cam_window": 4.0, + "belt_thickness": 0.12 +} \ No newline at end of file diff --git a/scipy/spinning_ball_on_moving_belt/611/simulation_code.py b/scipy/spinning_ball_on_moving_belt/611/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..cc9d307c4dd84ecf60254423dae5b4552046c72a --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/611/simulation_code.py @@ -0,0 +1,98 @@ +""" +Spinning Ball on a Moving Belt — auto-generated standalone simulation. + +Belt: v_belt(t) = v_belt_0 + a_belt · t. +Ball: Newton-Euler, Coulomb friction at the contact point opposing + v_rel = (v - omega r) - v_belt(t). +Camera-following render; no on-frame text or numerals. +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.2019061878754378 +r = 0.09100474369973746 +v_belt_0 = -0.27960593081179397 +a_belt = 0.10779590490738622 +mu_k = 0.0819353313853775 +I_factor = 0.42289166442743675 +g = 9.81 +alpha_tanh = 80.0 +x0 = 0.0 +v0 = 0.0 +theta0 = 0.0 +omega0 = -2.712766502646854 +cam_window = 4.0 +belt_thick = 0.12 +duration = 12 +fps = 30 +I = I_factor * M * r * r + +def ode(t, y): + x, v, theta, omega = y + v_belt_t = v_belt_0 + a_belt * t + v_contact = v - omega * r + v_rel = v_contact - v_belt_t + F_x = -mu_k * M * g * np.tanh(alpha_tanh * v_rel) + return [v, F_x / M, -omega, -r * F_x / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, v0, theta0, omega0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; x_arr, v_arr, theta_arr, omega_arr = sol.y[0], sol.y[1], sol.y[2], sol.y[3] + + +HW = cam_window / 2.0 +y_min = -belt_thick - 0.18 +y_max = 2.0 * r + 0.30 + +fig, ax = plt.subplots(figsize=(10, 4.4), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(-HW, HW); ax.set_ylim(y_min, y_max) +ax.set_aspect("equal"); ax.axis("off") + +belt_rect = patches.Rectangle((-200.0, -belt_thick), 400.0, belt_thick, + facecolor="#3a3a4f", edgecolor="white", lw=1.2, zorder=1) +ax.add_patch(belt_rect) + +N_ticks = 24 +tick_spacing = cam_window / N_ticks +tick_y0 = -belt_thick * 0.85 +tick_y1 = -belt_thick * 0.15 +tick_lines = [ax.plot([], [], "-", color="#a8dadc", lw=1.5, + zorder=3)[0] for _ in range(N_ticks)] + +ball_circle = patches.Circle((x0, r), r, facecolor="#457b9d", edgecolor="white", + lw=1.6, zorder=4) +ax.add_patch(ball_circle) +spoke_h, = ax.plot([], [], "-", color="#e63946", lw=2.6, zorder=5) +spoke_v, = ax.plot([], [], "-", color="#ffd166", lw=2.6, zorder=5) + + +def update(frame): + cx = float(x_arr[frame]); th = float(theta_arr[frame]) + t_now = float(t[frame]) + belt_disp = v_belt_0 * t_now + 0.5 * a_belt * t_now * t_now + + ax.set_xlim(cx - HW, cx + HW) + ball_circle.center = (cx, r) + spoke_h.set_data([cx, cx + r * math.cos(th)], + [r, r + r * math.sin(th)]) + spoke_v.set_data([cx, cx + r * math.cos(th + math.pi / 2.0)], + [r, r + r * math.sin(th + math.pi / 2.0)]) + for i, line in enumerate(tick_lines): + x_orig_rel = (i + 0.5) * tick_spacing - HW + x_drifted = x_orig_rel + belt_disp + x_wrapped = ((x_drifted + HW) % cam_window) - HW + x_lab = cx + x_wrapped + line.set_data([x_lab, x_lab], [tick_y0, tick_y1]) + return [ball_circle, spoke_h, spoke_v] + tick_lines + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close(); print("Saved video.mp4") diff --git a/scipy/spinning_ball_on_moving_belt/611/video.mp4 b/scipy/spinning_ball_on_moving_belt/611/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a600809e7cc9c568dc89a1b0b851447445d646d5 --- /dev/null +++ b/scipy/spinning_ball_on_moving_belt/611/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c20a52372c18af0188ba9c622589b6b7a74ea38fc575f4782de222f8ea36a8d9 +size 16986 diff --git a/scipy/spinning_disc_block_spring/014/cot.json b/scipy/spinning_disc_block_spring/014/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5ae47fbf85caea9d08a8be8af3416a1ea7864f92 --- /dev/null +++ b/scipy/spinning_disc_block_spring/014/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.845 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=4.821 rad/s over t_ramp=3.611 s, then constant. A small block of mass m_b=0.346 kg sits on the disc surface at initial radius 0.309 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=8.968 N/m and rest length L_0=0.281 m. Coulomb friction (mu_s=0.473 static, mu_k=0.284 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 4.0612 rad/s, reached at t_slip ~ 3.0420 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 4.061245683297612, + "t_slip_onset_estimate_s": 3.04202598298569, + "spring_omega_n_rad_s": 5.093614365962243, + "spring_period_s": 1.2335416181418397, + "initial_radius_m": 0.30897912257180055 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 4.0612 rad/s (until t ~ 3.042 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3456700699535355, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.8453917777555581, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.28088732784306075, + "unit": "", + "description": "" + }, + "k": { + "value": 8.968377924487363, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.4727424442770477, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.28434082250699283, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 4.820730093226778, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 3.6109084118864514, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.30897912257180055, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/014/params.json b/scipy/spinning_disc_block_spring/014/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b2fba60502a0fa2a65fba4baf6beb683b38a4190 --- /dev/null +++ b/scipy/spinning_disc_block_spring/014/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.3456700699535355, + "R_disc": 0.8453917777555581, + "L_0": 0.28088732784306075, + "k": 8.968377924487363, + "mu_s": 0.4727424442770477, + "mu_k": 0.28434082250699283, + "omega_max": 4.820730093226778, + "t_ramp": 3.6109084118864514, + "x_b_0": 0.30897912257180055, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/014/simulation_code.py b/scipy/spinning_disc_block_spring/014/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..bdaea70106b1e5a331df376ba6ebf368f6de2f64 --- /dev/null +++ b/scipy/spinning_disc_block_spring/014/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.3456700699535355 +R_disc = 0.8453917777555581 +L_0 = 0.28088732784306075 +k = 8.968377924487363 +mu_s = 0.4727424442770477 +mu_k = 0.28434082250699283 +omega_max = 4.820730093226778 +t_ramp = 3.6109084118864514 +x_b_0 = 0.30897912257180055 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/014/video.mp4 b/scipy/spinning_disc_block_spring/014/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..fc2b3e742b0c467718e1119335c14fb965ed8cfa --- /dev/null +++ b/scipy/spinning_disc_block_spring/014/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82369af018d56deddececf516f6c56e03b8b90496b54609500410f4cc885b376 +size 103609 diff --git a/scipy/spinning_disc_block_spring/046/cot.json b/scipy/spinning_disc_block_spring/046/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..3114493659930fb2a51300dad4ed0efec3f26177 --- /dev/null +++ b/scipy/spinning_disc_block_spring/046/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.827 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=5.295 rad/s over t_ramp=3.895 s, then constant. A small block of mass m_b=0.302 kg sits on the disc surface at initial radius 0.285 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=7.334 N/m and rest length L_0=0.320 m. Coulomb friction (mu_s=0.430 static, mu_k=0.305 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.6315 rad/s, reached at t_slip ~ 2.6714 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.6314946194305087, + "t_slip_onset_estimate_s": 2.671443495466173, + "spring_omega_n_rad_s": 4.926593463677664, + "spring_period_s": 1.2753610285694728, + "initial_radius_m": 0.28472352109615146 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.6315 rad/s (until t ~ 2.671 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3021476202246677, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.8272682749379642, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.3195202904781618, + "unit": "", + "description": "" + }, + "k": { + "value": 7.333522531395468, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.42997497183031796, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.30480387234004286, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 5.295102689225981, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 3.895246756327701, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.28472352109615146, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/046/params.json b/scipy/spinning_disc_block_spring/046/params.json new file mode 100644 index 0000000000000000000000000000000000000000..fd0765e83cadf0a978e7a92759665cf58958b05e --- /dev/null +++ b/scipy/spinning_disc_block_spring/046/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.3021476202246677, + "R_disc": 0.8272682749379642, + "L_0": 0.3195202904781618, + "k": 7.333522531395468, + "mu_s": 0.42997497183031796, + "mu_k": 0.30480387234004286, + "omega_max": 5.295102689225981, + "t_ramp": 3.895246756327701, + "x_b_0": 0.28472352109615146, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/046/simulation_code.py b/scipy/spinning_disc_block_spring/046/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..a170d2aa7d0b532f17d664e00e00ce68d5697ea9 --- /dev/null +++ b/scipy/spinning_disc_block_spring/046/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.3021476202246677 +R_disc = 0.8272682749379642 +L_0 = 0.3195202904781618 +k = 7.333522531395468 +mu_s = 0.42997497183031796 +mu_k = 0.30480387234004286 +omega_max = 5.295102689225981 +t_ramp = 3.895246756327701 +x_b_0 = 0.28472352109615146 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/046/video.mp4 b/scipy/spinning_disc_block_spring/046/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..35beec37d21e931ceabc49384fe3d7702a58b831 --- /dev/null +++ b/scipy/spinning_disc_block_spring/046/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:435f7c4d7092f1cc858c6a067221aad17f1aedb70e32d2fca09d276b7f9dc513 +size 94743 diff --git a/scipy/spinning_disc_block_spring/055/cot.json b/scipy/spinning_disc_block_spring/055/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4e7b635074921a78dec9ce0bf06cc5a363aecf6b --- /dev/null +++ b/scipy/spinning_disc_block_spring/055/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.757 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=5.293 rad/s over t_ramp=4.183 s, then constant. A small block of mass m_b=0.345 kg sits on the disc surface at initial radius 0.286 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=7.086 N/m and rest length L_0=0.309 m. Coulomb friction (mu_s=0.415 static, mu_k=0.259 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.6266 rad/s, reached at t_slip ~ 2.8659 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.6266448765530916, + "t_slip_onset_estimate_s": 2.8658589771318748, + "spring_omega_n_rad_s": 4.532396025578596, + "spring_period_s": 1.3862833855912862, + "initial_radius_m": 0.2864736269450349 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.6266 rad/s (until t ~ 2.866 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.34496096613071403, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.7565027979278047, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.3091851560044028, + "unit": "", + "description": "" + }, + "k": { + "value": 7.086399880075593, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.414956547949663, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.2586563596648795, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 5.29324985428635, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 4.182848922204488, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.2864736269450349, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/055/params.json b/scipy/spinning_disc_block_spring/055/params.json new file mode 100644 index 0000000000000000000000000000000000000000..1f23bb3190fa80aac091bcc52631e84e1bc6a404 --- /dev/null +++ b/scipy/spinning_disc_block_spring/055/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.34496096613071403, + "R_disc": 0.7565027979278047, + "L_0": 0.3091851560044028, + "k": 7.086399880075593, + "mu_s": 0.414956547949663, + "mu_k": 0.2586563596648795, + "omega_max": 5.29324985428635, + "t_ramp": 4.182848922204488, + "x_b_0": 0.2864736269450349, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/055/simulation_code.py b/scipy/spinning_disc_block_spring/055/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..4bc19ca19b4930b2ac98495723c84e18258b7992 --- /dev/null +++ b/scipy/spinning_disc_block_spring/055/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.34496096613071403 +R_disc = 0.7565027979278047 +L_0 = 0.3091851560044028 +k = 7.086399880075593 +mu_s = 0.414956547949663 +mu_k = 0.2586563596648795 +omega_max = 5.29324985428635 +t_ramp = 4.182848922204488 +x_b_0 = 0.2864736269450349 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/055/video.mp4 b/scipy/spinning_disc_block_spring/055/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..274625cb7bfa4d8e7ea921c947e332141adb4b84 --- /dev/null +++ b/scipy/spinning_disc_block_spring/055/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b9a418073b1dd62d717b2f4b9972963928782856ecab04536e21ff6e37d06f3 +size 90779 diff --git a/scipy/spinning_disc_block_spring/129/cot.json b/scipy/spinning_disc_block_spring/129/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..1ad5987d8bc3383e4915ecba242ee77db9abf6ba --- /dev/null +++ b/scipy/spinning_disc_block_spring/129/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.771 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=4.863 rad/s over t_ramp=3.536 s, then constant. A small block of mass m_b=0.347 kg sits on the disc surface at initial radius 0.281 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=8.940 N/m and rest length L_0=0.295 m. Coulomb friction (mu_s=0.433 static, mu_k=0.315 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.7901 rad/s, reached at t_slip ~ 2.7562 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.790075194263868, + "t_slip_onset_estimate_s": 2.7562001234943447, + "spring_omega_n_rad_s": 5.076354097745107, + "spring_period_s": 1.2377358210631026, + "initial_radius_m": 0.28106622018798777 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.7901 rad/s (until t ~ 2.756 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3469192741296851, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.7711656727850994, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.29529262757928854, + "unit": "", + "description": "" + }, + "k": { + "value": 8.939891456320217, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.43283481042493976, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.3150721555319692, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 4.862723505991656, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 3.5362462327970245, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.28106622018798777, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/129/params.json b/scipy/spinning_disc_block_spring/129/params.json new file mode 100644 index 0000000000000000000000000000000000000000..e3ee565d75cf82c672a5782e012edeb41729e050 --- /dev/null +++ b/scipy/spinning_disc_block_spring/129/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.3469192741296851, + "R_disc": 0.7711656727850994, + "L_0": 0.29529262757928854, + "k": 8.939891456320217, + "mu_s": 0.43283481042493976, + "mu_k": 0.3150721555319692, + "omega_max": 4.862723505991656, + "t_ramp": 3.5362462327970245, + "x_b_0": 0.28106622018798777, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/129/simulation_code.py b/scipy/spinning_disc_block_spring/129/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..fd2c9c27dbc71246e3117b434011db2bca57e4d6 --- /dev/null +++ b/scipy/spinning_disc_block_spring/129/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.3469192741296851 +R_disc = 0.7711656727850994 +L_0 = 0.29529262757928854 +k = 8.939891456320217 +mu_s = 0.43283481042493976 +mu_k = 0.3150721555319692 +omega_max = 4.862723505991656 +t_ramp = 3.5362462327970245 +x_b_0 = 0.28106622018798777 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/129/video.mp4 b/scipy/spinning_disc_block_spring/129/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c771915039cdd9218d74baf758d5747d066b91a6 --- /dev/null +++ b/scipy/spinning_disc_block_spring/129/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4124aba79708210b08d75213721e4b7350e23ed438885165f730f146c95bcd01 +size 105362 diff --git a/scipy/spinning_disc_block_spring/183/cot.json b/scipy/spinning_disc_block_spring/183/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..bd2b3636460fe3c2750e9f030f2268160357b205 --- /dev/null +++ b/scipy/spinning_disc_block_spring/183/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.844 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=5.116 rad/s over t_ramp=4.152 s, then constant. A small block of mass m_b=0.341 kg sits on the disc surface at initial radius 0.285 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=7.931 N/m and rest length L_0=0.309 m. Coulomb friction (mu_s=0.471 static, mu_k=0.281 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.8671 rad/s, reached at t_slip ~ 3.1386 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.867058120009939, + "t_slip_onset_estimate_s": 3.1385833081684895, + "spring_omega_n_rad_s": 4.821516595441167, + "spring_period_s": 1.3031553833332137, + "initial_radius_m": 0.2854472895808147 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.8671 rad/s (until t ~ 3.139 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3411462654031682, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.8444700416277008, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.3086861068836857, + "unit": "", + "description": "" + }, + "k": { + "value": 7.930634832605334, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.47103416290363104, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.28059079005334564, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 5.116155636468445, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 4.1523763502604725, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.2854472895808147, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/183/params.json b/scipy/spinning_disc_block_spring/183/params.json new file mode 100644 index 0000000000000000000000000000000000000000..44611742174bbec4f11d7856cfdbe058a5f940ad --- /dev/null +++ b/scipy/spinning_disc_block_spring/183/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.3411462654031682, + "R_disc": 0.8444700416277008, + "L_0": 0.3086861068836857, + "k": 7.930634832605334, + "mu_s": 0.47103416290363104, + "mu_k": 0.28059079005334564, + "omega_max": 5.116155636468445, + "t_ramp": 4.1523763502604725, + "x_b_0": 0.2854472895808147, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/183/simulation_code.py b/scipy/spinning_disc_block_spring/183/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..91902dc7605b8444a66eaf3b73ea2d8d231f4f45 --- /dev/null +++ b/scipy/spinning_disc_block_spring/183/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.3411462654031682 +R_disc = 0.8444700416277008 +L_0 = 0.3086861068836857 +k = 7.930634832605334 +mu_s = 0.47103416290363104 +mu_k = 0.28059079005334564 +omega_max = 5.116155636468445 +t_ramp = 4.1523763502604725 +x_b_0 = 0.2854472895808147 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/183/video.mp4 b/scipy/spinning_disc_block_spring/183/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1db47c9a6c057e51051c76c550563f4d1491ef21 --- /dev/null +++ b/scipy/spinning_disc_block_spring/183/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93781dd06202b6094aedf5e72ec75930ea16298304fdb3fa9b65f7ee3eab69d1 +size 96871 diff --git a/scipy/spinning_disc_block_spring/280/cot.json b/scipy/spinning_disc_block_spring/280/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..e14745285db0e98cbc61afbcfb03a9568d87e9e8 --- /dev/null +++ b/scipy/spinning_disc_block_spring/280/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.833 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=4.988 rad/s over t_ramp=3.714 s, then constant. A small block of mass m_b=0.269 kg sits on the disc surface at initial radius 0.308 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=7.242 N/m and rest length L_0=0.294 m. Coulomb friction (mu_s=0.482 static, mu_k=0.266 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 4.0063 rad/s, reached at t_slip ~ 2.9837 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 4.006266166573621, + "t_slip_onset_estimate_s": 2.9836539183932604, + "spring_omega_n_rad_s": 5.191662282992653, + "spring_period_s": 1.2102453828251982, + "initial_radius_m": 0.30781075615791936 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 4.0063 rad/s (until t ~ 2.984 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.26868283761048223, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.8326007899758383, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.2942008734545741, + "unit": "", + "description": "" + }, + "k": { + "value": 7.241904511920131, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.4818340429038586, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.26648583945566084, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 4.987594392217348, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 3.714494976858418, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.30781075615791936, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/280/params.json b/scipy/spinning_disc_block_spring/280/params.json new file mode 100644 index 0000000000000000000000000000000000000000..2a5d859fe8594665cb429b75f43639dcaa98b13d --- /dev/null +++ b/scipy/spinning_disc_block_spring/280/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.26868283761048223, + "R_disc": 0.8326007899758383, + "L_0": 0.2942008734545741, + "k": 7.241904511920131, + "mu_s": 0.4818340429038586, + "mu_k": 0.26648583945566084, + "omega_max": 4.987594392217348, + "t_ramp": 3.714494976858418, + "x_b_0": 0.30781075615791936, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/280/simulation_code.py b/scipy/spinning_disc_block_spring/280/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..0cb03682762daa5f56ca966abd602289d65cdfd5 --- /dev/null +++ b/scipy/spinning_disc_block_spring/280/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.26868283761048223 +R_disc = 0.8326007899758383 +L_0 = 0.2942008734545741 +k = 7.241904511920131 +mu_s = 0.4818340429038586 +mu_k = 0.26648583945566084 +omega_max = 4.987594392217348 +t_ramp = 3.714494976858418 +x_b_0 = 0.30781075615791936 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/280/video.mp4 b/scipy/spinning_disc_block_spring/280/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c08e9d34d305022d17032bc7ce0b8a6886e84ace --- /dev/null +++ b/scipy/spinning_disc_block_spring/280/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2027e90bb393d0d1c77e2c56845a6e1f4ea7cfe42dca52fe42bc31f699b3342a +size 101977 diff --git a/scipy/spinning_disc_block_spring/299/cot.json b/scipy/spinning_disc_block_spring/299/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..dfe70a9f38de968817ba0cf7cb19d8e942e57df3 --- /dev/null +++ b/scipy/spinning_disc_block_spring/299/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.810 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=4.752 rad/s over t_ramp=4.330 s, then constant. A small block of mass m_b=0.346 kg sits on the disc surface at initial radius 0.309 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=7.866 N/m and rest length L_0=0.295 m. Coulomb friction (mu_s=0.424 static, mu_k=0.267 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.7486 rad/s, reached at t_slip ~ 3.4161 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.7485878454289856, + "t_slip_onset_estimate_s": 3.4161023090264684, + "spring_omega_n_rad_s": 4.7658898356882595, + "spring_period_s": 1.3183656198113125, + "initial_radius_m": 0.30864732233994596 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.7486 rad/s (until t ~ 3.416 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.34633176515847797, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.8098089611975163, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.2953604944773514, + "unit": "", + "description": "" + }, + "k": { + "value": 7.8664778666133, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.42350809515786764, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.2668215126443022, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 4.751671028992696, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 4.330215815448904, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.30864732233994596, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/299/params.json b/scipy/spinning_disc_block_spring/299/params.json new file mode 100644 index 0000000000000000000000000000000000000000..d6c0c28d1bc894449dd6c6ca6854f42e0424d357 --- /dev/null +++ b/scipy/spinning_disc_block_spring/299/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.34633176515847797, + "R_disc": 0.8098089611975163, + "L_0": 0.2953604944773514, + "k": 7.8664778666133, + "mu_s": 0.42350809515786764, + "mu_k": 0.2668215126443022, + "omega_max": 4.751671028992696, + "t_ramp": 4.330215815448904, + "x_b_0": 0.30864732233994596, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/299/simulation_code.py b/scipy/spinning_disc_block_spring/299/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..9fee9d5adf806bd60fe0e0663a403519b43a63c0 --- /dev/null +++ b/scipy/spinning_disc_block_spring/299/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.34633176515847797 +R_disc = 0.8098089611975163 +L_0 = 0.2953604944773514 +k = 7.8664778666133 +mu_s = 0.42350809515786764 +mu_k = 0.2668215126443022 +omega_max = 4.751671028992696 +t_ramp = 4.330215815448904 +x_b_0 = 0.30864732233994596 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/299/video.mp4 b/scipy/spinning_disc_block_spring/299/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..8bf7ee15d5209975f824e1fbe2a283440adfbb67 --- /dev/null +++ b/scipy/spinning_disc_block_spring/299/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3ba61a9e88d61f7636a17b59b9a7bc8adc66ef8883ba87c3e4146495a25a135 +size 101341 diff --git a/scipy/spinning_disc_block_spring/309/cot.json b/scipy/spinning_disc_block_spring/309/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..514fda80a641b1ccb7a67c40e11924135ca007f7 --- /dev/null +++ b/scipy/spinning_disc_block_spring/309/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.778 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=4.719 rad/s over t_ramp=3.969 s, then constant. A small block of mass m_b=0.302 kg sits on the disc surface at initial radius 0.284 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=8.439 N/m and rest length L_0=0.296 m. Coulomb friction (mu_s=0.417 static, mu_k=0.337 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.7157 rad/s, reached at t_slip ~ 3.1248 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.7157159484061353, + "t_slip_onset_estimate_s": 3.1247849181414185, + "spring_omega_n_rad_s": 5.284677807194136, + "spring_period_s": 1.1889438744262066, + "initial_radius_m": 0.2843894241900269 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.7157 rad/s (until t ~ 3.125 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.302178119747575, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.7784922237223774, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.29593146440453544, + "unit": "", + "description": "" + }, + "k": { + "value": 8.439175992971032, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.4169174574440241, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.33738252509412736, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 4.71902637430634, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 3.9685332914291624, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.2843894241900269, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/309/params.json b/scipy/spinning_disc_block_spring/309/params.json new file mode 100644 index 0000000000000000000000000000000000000000..26ec8084e30d48a0b712dd2ef50302f327aa3c94 --- /dev/null +++ b/scipy/spinning_disc_block_spring/309/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.302178119747575, + "R_disc": 0.7784922237223774, + "L_0": 0.29593146440453544, + "k": 8.439175992971032, + "mu_s": 0.4169174574440241, + "mu_k": 0.33738252509412736, + "omega_max": 4.71902637430634, + "t_ramp": 3.9685332914291624, + "x_b_0": 0.2843894241900269, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/309/simulation_code.py b/scipy/spinning_disc_block_spring/309/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..06f7b46a4b2865be9b73473d9ebb3a6b18ee3fd8 --- /dev/null +++ b/scipy/spinning_disc_block_spring/309/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.302178119747575 +R_disc = 0.7784922237223774 +L_0 = 0.29593146440453544 +k = 8.439175992971032 +mu_s = 0.4169174574440241 +mu_k = 0.33738252509412736 +omega_max = 4.71902637430634 +t_ramp = 3.9685332914291624 +x_b_0 = 0.2843894241900269 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/309/video.mp4 b/scipy/spinning_disc_block_spring/309/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..8c37a038df8adf3372c9329bd9e2c4081f5b8a72 --- /dev/null +++ b/scipy/spinning_disc_block_spring/309/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed578191de4eef713a0dfefaed29d7b8663c02245089f111c77d359a1ae8cdcd +size 101120 diff --git a/scipy/spinning_disc_block_spring/369/cot.json b/scipy/spinning_disc_block_spring/369/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ed7d2da6df83becbd5c53c7f4ff2cc3db07fe133 --- /dev/null +++ b/scipy/spinning_disc_block_spring/369/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.816 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=5.426 rad/s over t_ramp=3.840 s, then constant. A small block of mass m_b=0.265 kg sits on the disc surface at initial radius 0.282 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=8.469 N/m and rest length L_0=0.292 m. Coulomb friction (mu_s=0.453 static, mu_k=0.274 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.8972 rad/s, reached at t_slip ~ 2.7578 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.897151257901355, + "t_slip_onset_estimate_s": 2.7578365782407728, + "spring_omega_n_rad_s": 5.648425165158366, + "spring_period_s": 1.1123782511870144, + "initial_radius_m": 0.28235517626423706 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.8972 rad/s (until t ~ 2.758 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.26543154658068313, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.8155118482325363, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.292104422321848, + "unit": "", + "description": "" + }, + "k": { + "value": 8.468515681441751, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.45269592028081695, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.2736229882661364, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 5.425857163832703, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 3.839632173472679, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.28235517626423706, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/369/params.json b/scipy/spinning_disc_block_spring/369/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8e51a87b81de97485e618aff5fdf894abf71afc2 --- /dev/null +++ b/scipy/spinning_disc_block_spring/369/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.26543154658068313, + "R_disc": 0.8155118482325363, + "L_0": 0.292104422321848, + "k": 8.468515681441751, + "mu_s": 0.45269592028081695, + "mu_k": 0.2736229882661364, + "omega_max": 5.425857163832703, + "t_ramp": 3.839632173472679, + "x_b_0": 0.28235517626423706, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/369/simulation_code.py b/scipy/spinning_disc_block_spring/369/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..248e253f107cc11e5cc7455108a0e9e7c1885a07 --- /dev/null +++ b/scipy/spinning_disc_block_spring/369/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.26543154658068313 +R_disc = 0.8155118482325363 +L_0 = 0.292104422321848 +k = 8.468515681441751 +mu_s = 0.45269592028081695 +mu_k = 0.2736229882661364 +omega_max = 5.425857163832703 +t_ramp = 3.839632173472679 +x_b_0 = 0.28235517626423706 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/369/video.mp4 b/scipy/spinning_disc_block_spring/369/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1c9a0991611ac30a70491e27214a5987f1a66173 --- /dev/null +++ b/scipy/spinning_disc_block_spring/369/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e9d088bfd1f84b96317b7cca76732293b037f919d8d6779cd8ffba7cc0db544 +size 99446 diff --git a/scipy/spinning_disc_block_spring/546/cot.json b/scipy/spinning_disc_block_spring/546/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d0a6917c9b9d372589969316e80d1a9a8f75dd9d --- /dev/null +++ b/scipy/spinning_disc_block_spring/546/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.797 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=5.460 rad/s over t_ramp=3.597 s, then constant. A small block of mass m_b=0.310 kg sits on the disc surface at initial radius 0.313 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=8.364 N/m and rest length L_0=0.313 m. Coulomb friction (mu_s=0.475 static, mu_k=0.297 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.8586 rad/s, reached at t_slip ~ 2.5421 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.858586001878411, + "t_slip_onset_estimate_s": 2.542074372514171, + "spring_omega_n_rad_s": 5.1953371385101175, + "spring_period_s": 1.2093893311765778, + "initial_radius_m": 0.3133778415481303 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.8586 rad/s (until t ~ 2.542 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3098725052294669, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.7970195870406047, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.312904435860244, + "unit": "", + "description": "" + }, + "k": { + "value": 8.363932395996072, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.47538121151477886, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.2965752138480432, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 5.459677349636095, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 3.5968890847449226, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.3133778415481303, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/546/params.json b/scipy/spinning_disc_block_spring/546/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3f1944603e698d1e3fabb90aeaec1093c5353d8c --- /dev/null +++ b/scipy/spinning_disc_block_spring/546/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.3098725052294669, + "R_disc": 0.7970195870406047, + "L_0": 0.312904435860244, + "k": 8.363932395996072, + "mu_s": 0.47538121151477886, + "mu_k": 0.2965752138480432, + "omega_max": 5.459677349636095, + "t_ramp": 3.5968890847449226, + "x_b_0": 0.3133778415481303, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/546/simulation_code.py b/scipy/spinning_disc_block_spring/546/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..c0cb0793f798bfde5e21e5b022ca0585f4aa9728 --- /dev/null +++ b/scipy/spinning_disc_block_spring/546/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.3098725052294669 +R_disc = 0.7970195870406047 +L_0 = 0.312904435860244 +k = 8.363932395996072 +mu_s = 0.47538121151477886 +mu_k = 0.2965752138480432 +omega_max = 5.459677349636095 +t_ramp = 3.5968890847449226 +x_b_0 = 0.3133778415481303 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/546/video.mp4 b/scipy/spinning_disc_block_spring/546/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0a9f770f25df7029ca0867ae3a52b2b5d8a07037 --- /dev/null +++ b/scipy/spinning_disc_block_spring/546/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36ad90f601cd5bf09316e6ed48d3935fc1bb5d1c43242d73dbee337ce9e5c118 +size 103170 diff --git a/scipy/spinning_disc_block_spring/566/cot.json b/scipy/spinning_disc_block_spring/566/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4749d9c1a4d32d91d83a1ff7e0ea19a224eb6aea --- /dev/null +++ b/scipy/spinning_disc_block_spring/566/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.774 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=5.077 rad/s over t_ramp=4.367 s, then constant. A small block of mass m_b=0.282 kg sits on the disc surface at initial radius 0.302 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=8.341 N/m and rest length L_0=0.286 m. Coulomb friction (mu_s=0.500 static, mu_k=0.286 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 4.1361 rad/s, reached at t_slip ~ 3.5577 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 4.13611316217019, + "t_slip_onset_estimate_s": 3.5576731052454136, + "spring_omega_n_rad_s": 5.441833455983046, + "spring_period_s": 1.154608158813003, + "initial_radius_m": 0.30153833251068524 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 4.1361 rad/s (until t ~ 3.558 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.28167691387204796, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.7737406149439672, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.2861698390843161, + "unit": "", + "description": "" + }, + "k": { + "value": 8.34145375662443, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.4995541926959769, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.285741848221781, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 5.077375461101856, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 4.36729881774251, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.30153833251068524, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/566/params.json b/scipy/spinning_disc_block_spring/566/params.json new file mode 100644 index 0000000000000000000000000000000000000000..71114b7fdef8282c8315cd9aeaf1d638ee7d3025 --- /dev/null +++ b/scipy/spinning_disc_block_spring/566/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.28167691387204796, + "R_disc": 0.7737406149439672, + "L_0": 0.2861698390843161, + "k": 8.34145375662443, + "mu_s": 0.4995541926959769, + "mu_k": 0.285741848221781, + "omega_max": 5.077375461101856, + "t_ramp": 4.36729881774251, + "x_b_0": 0.30153833251068524, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/566/simulation_code.py b/scipy/spinning_disc_block_spring/566/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..98e0c0b102305ef828a173ca1cb1f9d91ecc221f --- /dev/null +++ b/scipy/spinning_disc_block_spring/566/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.28167691387204796 +R_disc = 0.7737406149439672 +L_0 = 0.2861698390843161 +k = 8.34145375662443 +mu_s = 0.4995541926959769 +mu_k = 0.285741848221781 +omega_max = 5.077375461101856 +t_ramp = 4.36729881774251 +x_b_0 = 0.30153833251068524 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/566/video.mp4 b/scipy/spinning_disc_block_spring/566/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3cc2d1af8be5ee778a4fd68e45f887157a2b2c2e --- /dev/null +++ b/scipy/spinning_disc_block_spring/566/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8dafc196fcaae716e9d26f1d200dfd2394059b031df903d906e96075c315271 +size 95678 diff --git a/scipy/spinning_disc_block_spring/653/cot.json b/scipy/spinning_disc_block_spring/653/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4cf5ead577e304c7753c5d9115367902bde2885f --- /dev/null +++ b/scipy/spinning_disc_block_spring/653/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.829 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=4.615 rad/s over t_ramp=4.401 s, then constant. A small block of mass m_b=0.311 kg sits on the disc surface at initial radius 0.303 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=7.747 N/m and rest length L_0=0.312 m. Coulomb friction (mu_s=0.434 static, mu_k=0.315 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.6913 rad/s, reached at t_slip ~ 3.5202 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.6913317005329023, + "t_slip_onset_estimate_s": 3.5202049677077145, + "spring_omega_n_rad_s": 4.988067251974217, + "spring_period_s": 1.2596432625668343, + "initial_radius_m": 0.30274253119069044 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.6913 rad/s (until t ~ 3.520 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.31135528773831705, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.8293027443287657, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.31188805203154746, + "unit": "", + "description": "" + }, + "k": { + "value": 7.746773285534614, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.4336494569935959, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.3151118034663383, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 4.615074910692593, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 4.401124294686911, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.30274253119069044, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/653/params.json b/scipy/spinning_disc_block_spring/653/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ae7150f1e72972784abc47bd039e9c419fa9099f --- /dev/null +++ b/scipy/spinning_disc_block_spring/653/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.31135528773831705, + "R_disc": 0.8293027443287657, + "L_0": 0.31188805203154746, + "k": 7.746773285534614, + "mu_s": 0.4336494569935959, + "mu_k": 0.3151118034663383, + "omega_max": 4.615074910692593, + "t_ramp": 4.401124294686911, + "x_b_0": 0.30274253119069044, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/653/simulation_code.py b/scipy/spinning_disc_block_spring/653/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ab6eedba5b142e984e8831286b40a5cba4bfd286 --- /dev/null +++ b/scipy/spinning_disc_block_spring/653/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.31135528773831705 +R_disc = 0.8293027443287657 +L_0 = 0.31188805203154746 +k = 7.746773285534614 +mu_s = 0.4336494569935959 +mu_k = 0.3151118034663383 +omega_max = 4.615074910692593 +t_ramp = 4.401124294686911 +x_b_0 = 0.30274253119069044 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/653/video.mp4 b/scipy/spinning_disc_block_spring/653/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..16177e9a5090ed027b39933920131130542a4e6d --- /dev/null +++ b/scipy/spinning_disc_block_spring/653/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af0df0053d0ea3475ab2d0884601932e8b50d07011b48f3ecc7860cd2204e3f4 +size 101078 diff --git a/scipy/spinning_disc_block_spring/714/cot.json b/scipy/spinning_disc_block_spring/714/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..cf2d47ab036f79405a732e7dfc9c68da41a769d3 --- /dev/null +++ b/scipy/spinning_disc_block_spring/714/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.784 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=5.322 rad/s over t_ramp=3.738 s, then constant. A small block of mass m_b=0.280 kg sits on the disc surface at initial radius 0.306 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=8.670 N/m and rest length L_0=0.299 m. Coulomb friction (mu_s=0.409 static, mu_k=0.332 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.6596 rad/s, reached at t_slip ~ 2.5699 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.6595695605258656, + "t_slip_onset_estimate_s": 2.5698801907497275, + "spring_omega_n_rad_s": 5.559965462492013, + "spring_period_s": 1.1300763196401982, + "initial_radius_m": 0.30577949892789785 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.6596 rad/s (until t ~ 2.570 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.2804617142456798, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.7844727288072454, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.2994442388378845, + "unit": "", + "description": "" + }, + "k": { + "value": 8.669973536530295, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.40921344972180895, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.3317164955848242, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 5.322319314343828, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 3.737522336591804, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.30577949892789785, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/714/params.json b/scipy/spinning_disc_block_spring/714/params.json new file mode 100644 index 0000000000000000000000000000000000000000..cfb0141b84489dff69ff00dae30adbee37ed8281 --- /dev/null +++ b/scipy/spinning_disc_block_spring/714/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.2804617142456798, + "R_disc": 0.7844727288072454, + "L_0": 0.2994442388378845, + "k": 8.669973536530295, + "mu_s": 0.40921344972180895, + "mu_k": 0.3317164955848242, + "omega_max": 5.322319314343828, + "t_ramp": 3.737522336591804, + "x_b_0": 0.30577949892789785, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/714/simulation_code.py b/scipy/spinning_disc_block_spring/714/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b9ef3157b6336ccb6d2dc041c21ca302bf1322b3 --- /dev/null +++ b/scipy/spinning_disc_block_spring/714/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.2804617142456798 +R_disc = 0.7844727288072454 +L_0 = 0.2994442388378845 +k = 8.669973536530295 +mu_s = 0.40921344972180895 +mu_k = 0.3317164955848242 +omega_max = 5.322319314343828 +t_ramp = 3.737522336591804 +x_b_0 = 0.30577949892789785 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/714/video.mp4 b/scipy/spinning_disc_block_spring/714/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..84c04eebbdacedb2dfed34fa662e5d79618e9203 --- /dev/null +++ b/scipy/spinning_disc_block_spring/714/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a223fe72d61200b2c2932218ea0a3387340dd9b7fbd361b04623dd470397df4b +size 97707 diff --git a/scipy/spinning_disc_block_spring/725/cot.json b/scipy/spinning_disc_block_spring/725/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..3501f3d10e76a55ebcc91cacf5587b13866d8e65 --- /dev/null +++ b/scipy/spinning_disc_block_spring/725/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.801 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=5.262 rad/s over t_ramp=4.490 s, then constant. A small block of mass m_b=0.330 kg sits on the disc surface at initial radius 0.294 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=7.088 N/m and rest length L_0=0.312 m. Coulomb friction (mu_s=0.494 static, mu_k=0.338 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 3.9415 rad/s, reached at t_slip ~ 3.3632 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 3.941523128699113, + "t_slip_onset_estimate_s": 3.363245412519941, + "spring_omega_n_rad_s": 4.638110089400552, + "spring_period_s": 1.3546865395753576, + "initial_radius_m": 0.2938478517821241 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 3.9415 rad/s (until t ~ 3.363 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.3295124621777, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.8007140490737374, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.31171852077798406, + "unit": "", + "description": "" + }, + "k": { + "value": 7.08849357104027, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.49415670175722415, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.33828090921716397, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 5.262209364118325, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 4.49016812174121, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.2938478517821241, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/725/params.json b/scipy/spinning_disc_block_spring/725/params.json new file mode 100644 index 0000000000000000000000000000000000000000..289e8c07762dcb279136f2004e49c1c0383dd994 --- /dev/null +++ b/scipy/spinning_disc_block_spring/725/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.3295124621777, + "R_disc": 0.8007140490737374, + "L_0": 0.31171852077798406, + "k": 7.08849357104027, + "mu_s": 0.49415670175722415, + "mu_k": 0.33828090921716397, + "omega_max": 5.262209364118325, + "t_ramp": 4.49016812174121, + "x_b_0": 0.2938478517821241, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/725/simulation_code.py b/scipy/spinning_disc_block_spring/725/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..3be40fad7833f62acdb005bca39bae2fca940ed0 --- /dev/null +++ b/scipy/spinning_disc_block_spring/725/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.3295124621777 +R_disc = 0.8007140490737374 +L_0 = 0.31171852077798406 +k = 7.08849357104027 +mu_s = 0.49415670175722415 +mu_k = 0.33828090921716397 +omega_max = 5.262209364118325 +t_ramp = 4.49016812174121 +x_b_0 = 0.2938478517821241 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/725/video.mp4 b/scipy/spinning_disc_block_spring/725/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b079963d8c3e3594859d7d42501f23727704b2e8 --- /dev/null +++ b/scipy/spinning_disc_block_spring/725/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ab728763f8e6d8acc299420dc657b24a018ba43a6ba74382b6ba16a3faa4886 +size 91688 diff --git a/scipy/spinning_disc_block_spring/889/cot.json b/scipy/spinning_disc_block_spring/889/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..eff2503ad01bd85521f8aca80b446fda4cacc996 --- /dev/null +++ b/scipy/spinning_disc_block_spring/889/cot.json @@ -0,0 +1,123 @@ +{ + "simulation": "spinning_disc_block_spring", + "physical_observation": "A circular disc of radius R=0.760 m spins about its centre at the origin with angular velocity omega(t) ramping linearly from 0 to omega_max=4.527 rad/s over t_ramp=3.767 s, then constant. A small block of mass m_b=0.305 kg sits on the disc surface at initial radius 0.305 m, tethered to the FIXED LAB origin by a Hookean spring of stiffness k=7.353 N/m and rest length L_0=0.296 m. Coulomb friction (mu_s=0.498 static, mu_k=0.304 kinetic) couples the block to the disc surface.", + "physical_law": { + "name": "Newton's laws + Coulomb friction (static/kinetic) + Hooke's spring law in non-inertial rotating contact", + "statement": "STICK: the block co-rotates with the disc, requiring static friction to supply m_b a_required - F_spring (centripetal + tangential). Slip onset when |F_required| > mu_s m_b g. SLIP: m_b \\dot{v} = -k (r - L_0) r_hat - mu_k m_b g v_slip / |v_slip|, where v_slip = v_block - omega x r.", + "formula": "STICK: r=|r0|, position rotates rigidly with disc. SLIP ODE: m_b \\dot{v} = F_spring + F_friction. Slip-onset critical omega (at r=L_0): omega_crit = \\sqrt(mu_s g / L_0)." + }, + "ode_system": { + "state_variables": [ + "x, y (m)", + "vx, vy (m/s)", + "status in {0=stick, 1=slip}" + ], + "equations_latex": [ + "STICK: x(t) = r0 \\cos(phi0 + theta_disc(t)), y(t) = r0 \\sin(phi0 + theta_disc(t)).", + "SLIP: m_b \\dot{vx} = -k (r - L_0) x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ], + "equations_python": [ + "STICK: x(t) = r0 np.cos (phi0 + theta_disc(t)), y(t) = r0 np.sin (phi0 + theta_disc(t)).", + "SLIP: m_b vx_dot = -k (r - L_0) * x/r + Ff_x, similarly y.", + "Hybrid: switch when slip-onset criterion or v_slip drops below threshold." + ] + }, + "derivation_steps": [ + "Set up disc-fixed and lab-fixed frames; spring anchored at lab origin.", + "STICK regime: block point co-rotates with the disc surface point beneath it. Required centripetal+tangential acceleration in the lab frame must come from spring + static friction.", + "Spring force at radius r: F_spring = -k (r - L_0) r_hat. At r = L_0 the spring is at rest length and exerts no force.", + "Slip onset criterion (at r=L_0): m_b L_0 omega^2 > mu_s m_b g, i.e. omega_crit = \\sqrt(mu_s g / L_0) = 4.0596 rad/s, reached at t_slip ~ 3.3779 s.", + "SLIP regime: integrate m_b \\dot{v} = F_spring + F_friction (kinetic). The friction force opposes the slip velocity v_slip = v_block - omega x r.", + "Re-stick when |v_slip| drops below threshold AND required static friction at that moment is below the limit." + ], + "physical_constants_derived": { + "omega_critical_rad_s": 4.059627537072586, + "t_slip_onset_estimate_s": 3.3779057209421954, + "spring_omega_n_rad_s": 4.913328215653677, + "spring_period_s": 1.2788043117416004, + "initial_radius_m": 0.3048439113602654 + }, + "numerical_method": { + "solver": "Hybrid stick/slip integration: analytic kinematics during stick, RK45 with re-stick events during slip.", + "tolerance": "rtol=1e-9, atol=1e-11, max_step=5e-3", + "justification": "Capturing the transition between regimes precisely is critical; using analytic stick kinematics avoids numerical drift in radius." + }, + "code_validation": { + "ode_source": "Newton's 2nd law in the lab frame with Coulomb friction; Hooke's law for the radial spring; smooth ramp in disc angular velocity.", + "energy_check": "Friction monotonically removes energy from the relative slip; spring stores/releases energy elastically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Block remains stuck while omega(t) < omega_crit ~ 4.0596 rad/s (until t ~ 3.378 s).", + "Once slip begins, the block spirals outward, decelerated by the spring and kinetic friction.", + "Possible re-sticking at larger radius if spring force balances out the centripetal requirement." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_b": { + "value": 0.30456928367972036, + "unit": "", + "description": "" + }, + "R_disc": { + "value": 0.7602168054857243, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.29616815278856873, + "unit": "", + "description": "" + }, + "k": { + "value": 7.3525443831683, + "unit": "", + "description": "" + }, + "mu_s": { + "value": 0.4980634360955344, + "unit": "", + "description": "" + }, + "mu_k": { + "value": 0.30435968172067074, + "unit": "", + "description": "" + }, + "omega_max": { + "value": 4.527105953022605, + "unit": "", + "description": "" + }, + "t_ramp": { + "value": 3.7668818034113913, + "unit": "", + "description": "" + }, + "x_b_0": { + "value": 0.3048439113602654, + "unit": "", + "description": "" + }, + "y_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vx_b_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "vy_b_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spinning_disc_block_spring/889/params.json b/scipy/spinning_disc_block_spring/889/params.json new file mode 100644 index 0000000000000000000000000000000000000000..f5a986a634d9a0294ab69dd9fb4142d6c17a407b --- /dev/null +++ b/scipy/spinning_disc_block_spring/889/params.json @@ -0,0 +1,15 @@ +{ + "g": 9.8, + "m_b": 0.30456928367972036, + "R_disc": 0.7602168054857243, + "L_0": 0.29616815278856873, + "k": 7.3525443831683, + "mu_s": 0.4980634360955344, + "mu_k": 0.30435968172067074, + "omega_max": 4.527105953022605, + "t_ramp": 3.7668818034113913, + "x_b_0": 0.3048439113602654, + "y_b_0": 0.0, + "vx_b_0": 0.0, + "vy_b_0": 0.0 +} \ No newline at end of file diff --git a/scipy/spinning_disc_block_spring/889/simulation_code.py b/scipy/spinning_disc_block_spring/889/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..da3ca3d6f103bfc28f2e6ff3fb5aad143de2094e --- /dev/null +++ b/scipy/spinning_disc_block_spring/889/simulation_code.py @@ -0,0 +1,201 @@ +"""Spinning disc + block + spring — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Rectangle, Circle +import matplotlib.transforms as mtransforms + +g = 9.8 +m_b = 0.30456928367972036 +R_disc = 0.7602168054857243 +L_0 = 0.29616815278856873 +k = 7.3525443831683 +mu_s = 0.4980634360955344 +mu_k = 0.30435968172067074 +omega_max = 4.527105953022605 +t_ramp = 3.7668818034113913 +x_b_0 = 0.3048439113602654 +y_b_0 = 0.0 +vx_b_0 = 0.0 +vy_b_0 = 0.0 +duration = 12 +fps = 30 + +def omega_disc(t): + if t < t_ramp: return omega_max*(t/t_ramp) + return omega_max +def alpha_disc(t): + return omega_max/t_ramp if t < t_ramp else 0.0 +def theta_disc_of_t(t): + if t <= t_ramp: return 0.5*(omega_max/t_ramp)*t*t + return 0.5*omega_max*t_ramp + omega_max*(t - t_ramp) + +def req_force(x, y, t): + om = omega_disc(t); r = np.hypot(x, y) + if r < 1e-12: return 0.0 + rh = np.array([x,y])/r + a_req = -r*om*om*rh + F_spring = -k*(r-L_0)*rh + al = alpha_disc(t); that = np.array([-rh[1], rh[0]]) + a_tan = al*r*that + F_req = m_b*(a_req + a_tan) - F_spring + return float(np.linalg.norm(F_req)) + +def slip_ode(t, y): + x, yy, vx, vy = y + r = np.hypot(x, yy) + if r < 1e-12: Fs = np.zeros(2) + else: + rh = np.array([x,yy])/r + Fs = -k*(r-L_0)*rh + if r <= R_disc: + om = omega_disc(t) + v_d = np.array([-om*yy, om*x]) + v_s = np.array([vx,vy]) - v_d + vsm = float(np.linalg.norm(v_s)) + if vsm < 1e-12: Ff = np.zeros(2) + else: Ff = -mu_k*m_b*g*v_s/vsm + else: Ff = np.zeros(2) + a = (Fs+Ff)/m_b + return [vx, vy, a[0], a[1]] + +n_frames = int(duration*fps)+1 +t_frames = np.linspace(0.0, duration, n_frames) +X_hist = np.zeros(n_frames); Y_hist = np.zeros(n_frames) +DISC_HIST = np.zeros(n_frames); STATUS = np.zeros(n_frames, dtype=int) + +v_slip_eps = 1e-3 +status = 0; t = 0.0 +x = x_b_0; yy = y_b_0; vx = vx_b_0; vy = vy_b_0 +r_stick = np.hypot(x, yy) +phi_stick = np.arctan2(yy, x) - theta_disc_of_t(0.0) + +def re_stick(tt, yv): + xs, ys, vxs, vys = yv + om = omega_disc(tt) + return np.hypot(vxs-(-om*ys), vys-(om*xs)) - v_slip_eps +re_stick.terminal=True; re_stick.direction=-1 + +fi = 0; SAFETY=0 +while fi < n_frames: + SAFETY += 1 + if SAFETY > 200: break + if status == 0: + ds = 1e-3; slip_at = None; t_loc = t + while t_loc < duration - 1e-15: + t_n = min(t_loc + ds, duration) + th_d = theta_disc_of_t(t_n) + x_n = r_stick*np.cos(phi_stick + th_d) + y_n = r_stick*np.sin(phi_stick + th_d) + if req_force(x_n, y_n, t_n) > mu_s*m_b*g: + lo, hi = t_loc, t_n + for _ in range(40): + mid = 0.5*(lo+hi) + thm = theta_disc_of_t(mid) + xm = r_stick*np.cos(phi_stick + thm) + ym = r_stick*np.sin(phi_stick + thm) + if req_force(xm, ym, mid) > mu_s*m_b*g: hi = mid + else: lo = mid + slip_at = hi; break + t_loc = t_n + seg_end = duration if slip_at is None else slip_at + while fi < n_frames and t_frames[fi] <= seg_end + 1e-12: + tf = t_frames[fi] + if tf < t - 1e-12: tf = t + th_d = theta_disc_of_t(tf) + X_hist[fi] = r_stick*np.cos(phi_stick + th_d) + Y_hist[fi] = r_stick*np.sin(phi_stick + th_d) + DISC_HIST[fi] = th_d; STATUS[fi] = 0; fi += 1 + if slip_at is None: + t = duration; break + t = slip_at; th_d = theta_disc_of_t(t) + x = r_stick*np.cos(phi_stick + th_d) + yy = r_stick*np.sin(phi_stick + th_d) + om = omega_disc(t); vx = -om*yy; vy = om*x + status = 1; continue + + rm = (t_frames > t + 1e-12) & (t_frames <= duration + 1e-12) + t_eval_seg = t_frames[rm] if rm.any() else None + sol = solve_ivp(slip_ode, (t, duration), [x, yy, vx, vy], + method="RK45", rtol=1e-9, atol=1e-11, + max_step=5e-3, events=re_stick, t_eval=t_eval_seg) + for j, tf in enumerate(sol.t): + if fi < n_frames and abs(t_frames[fi]-tf) < 1e-6: + X_hist[fi] = sol.y[0,j]; Y_hist[fi] = sol.y[1,j] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + if sol.t_events[0].size > 0: + te = sol.t_events[0][0]; ye = sol.y_events[0][0] + while fi < n_frames and t_frames[fi] <= te + 1e-9: + tf = t_frames[fi] + X_hist[fi] = ye[0]; Y_hist[fi] = ye[1] + DISC_HIST[fi] = theta_disc_of_t(tf); STATUS[fi] = 1; fi += 1 + t = te; x, yy, vx, vy = ye + if req_force(x, yy, t) <= mu_s*m_b*g: + status = 0; r_stick = np.hypot(x, yy) + phi_stick = np.arctan2(yy, x) - theta_disc_of_t(t) + else: + r_here = np.hypot(x, yy) + if r_here > 1e-9: + vx += 1e-2*x/r_here; vy += 1e-2*yy/r_here + else: + t = duration + if sol.y.shape[1] > 0: x, yy, vx, vy = sol.y[:,-1] + break + +while fi < n_frames: + X_hist[fi] = x; Y_hist[fi] = yy + DISC_HIST[fi] = theta_disc_of_t(t_frames[fi]) + STATUS[fi] = status; fi += 1 + +W, H = 6.0, 6.0 +fig = plt.figure(figsize=(W,H), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.axis("off"); ax.set_aspect("equal") +extent = R_disc + 0.20 +ax.set_xlim(-extent, +extent); ax.set_ylim(-extent, +extent) + +disc = Circle((0.0,0.0), R_disc, facecolor="#21304e", edgecolor="#a8dadc", lw=1.2, zorder=1) +ax.add_patch(disc) +spokes = [] +for i in range(4): + ln, = ax.plot([],[], "-", color="#a8dadc", lw=1.6, zorder=2) + spokes.append(ln) +anchor = Circle((0.0,0.0), 0.018, facecolor="#ffffff", edgecolor="#1a1a2e", lw=0.6, zorder=6) +ax.add_patch(anchor) +spring_l, = ax.plot([],[], "-", color="#f4a261", lw=1.8, zorder=4) +trail, = ax.plot([],[], "-", color="#e63946", lw=1.0, alpha=0.5, zorder=3) +block_size = 0.10 +block = Rectangle((-block_size/2, -block_size/2), block_size, block_size, + facecolor="#e63946", edgecolor="#ffffff", lw=1.0, zorder=5) +ax.add_patch(block) + +def sp_path(x1, y1, x2, y2, n_coils=10, amp=0.025): + dx, dy = x2-x1, y2-y1; L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dx/L, dy/L; nx, ny = -uy, ux + np_pts = n_coils*20+2 + s = np.linspace(0,1, np_pts); m = 0.10 + env = np.where((s1-m), 0.0, np.sin(n_coils*2*np.pi*(s-m)/(1-2*m))) + return x1+s*dx+amp*env*nx, y1+s*dy+amp*env*ny + +def update(f): + th_d = DISC_HIST[f] + for i, ln in enumerate(spokes): + ang = th_d + i*(np.pi/2.0) + ln.set_data([0.0, R_disc*0.95*np.cos(ang)], + [0.0, R_disc*0.95*np.sin(ang)]) + bx, by = X_hist[f], Y_hist[f] + sxs, sys = sp_path(0.0, 0.0, bx, by) + spring_l.set_data(sxs, sys) + lo = max(0, f-150) + trail.set_data(X_hist[lo:f+1], Y_hist[lo:f+1]) + tr = (mtransforms.Affine2D().rotate(th_d).translate(bx, by)) + ax.transData + block.set_transform(tr) + return spokes + [spring_l, trail, block, anchor] + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spinning_disc_block_spring/889/video.mp4 b/scipy/spinning_disc_block_spring/889/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e1c702126606689dcc5e7ae9837e08a7673d8a02 --- /dev/null +++ b/scipy/spinning_disc_block_spring/889/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ddc2621e652e189a8f938c5ab3d44a65593b810b7424781a2b827cd0c0baa846 +size 103204 diff --git a/scipy/spool_pull_direction_2d/012/cot.json b/scipy/spool_pull_direction_2d/012/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..0f9da57242883106ffc1e968e8c89b831d379b14 --- /dev/null +++ b/scipy/spool_pull_direction_2d/012/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=0.720 kg, outer (flange) radius R=0.181 m and inner (spindle) radius r=0.112 m (r/R=0.616) rests on a horizontal floor with kinetic friction \\mu_k=0.261. A constant tension T=0.859 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=58.9^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 51.98^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 0.720 \\cdot (0.181)^2 = 0.01301 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.4434 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.09592 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = +0.01557 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 51.98^{\\circ}.", + "Here \\cos(\\theta) = 0.5160 < r/R = 0.6160 \\Rightarrow \\theta > \\theta_c \\Rightarrow spool rolls away from the pull (-x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 51.9769 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.09592 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = +0.01557 N \\cdot m.", + "Direction of rolling: away from the pull (-x) (because \\theta > \\theta_c = 52.0^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = -0.0770 m/s^2." + ], + "parameters": { + "M": { + "value": 0.7204462800320527, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.1812036564022816, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.6159787939389607, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.26080153844998866, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.8593746952178603, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 58.9370985991377, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.11161760972800724, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 1.0286464221274905, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/012/params.json b/scipy/spool_pull_direction_2d/012/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c16518313dac55687c4dd433210156307a3d9568 --- /dev/null +++ b/scipy/spool_pull_direction_2d/012/params.json @@ -0,0 +1,15 @@ +{ + "M": 0.7204462800320527, + "R": 0.1812036564022816, + "r_over_R": 0.6159787939389607, + "I_factor": 0.55, + "mu_k": 0.26080153844998866, + "g": 9.81, + "T": 0.8593746952178603, + "theta_deg": 58.9370985991377, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.11161760972800724, + "theta": 1.0286464221274905 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/012/simulation_code.py b/scipy/spool_pull_direction_2d/012/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..342f4b16eed7c31858541cf36b11316be2ab50e8 --- /dev/null +++ b/scipy/spool_pull_direction_2d/012/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.7204462800320527 +R = 0.1812036564022816 +r = 0.11161760972800724 +I_factor = 0.55 +mu_k = 0.26080153844998866 +g = 9.81 +T = 0.8593746952178603 +theta = 1.0286464221274905 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/012/video.mp4 b/scipy/spool_pull_direction_2d/012/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6d58ea4214a11e69ccc3094daf8eba5da46dcd3f --- /dev/null +++ b/scipy/spool_pull_direction_2d/012/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c033752f757c9287410524f9768dfc753138bfc4d2fd9f4e75cd3ba308883082 +size 12635 diff --git a/scipy/spool_pull_direction_2d/052/cot.json b/scipy/spool_pull_direction_2d/052/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..eecf69eb30f35a6c06c133ee719aa02f4b3cb502 --- /dev/null +++ b/scipy/spool_pull_direction_2d/052/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=0.807 kg, outer (flange) radius R=0.223 m and inner (spindle) radius r=0.088 m (r/R=0.395) rests on a horizontal floor with kinetic friction \\mu_k=0.205. A constant tension T=0.990 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=53.0^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 66.73^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 0.807 \\cdot (0.223)^2 = 0.02213 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.5952 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.08733 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.04561 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 66.73^{\\circ}.", + "Here \\cos(\\theta) = 0.6015 > r/R = 0.3951 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 66.7271 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.08733 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.04561 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 66.7^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.1633 m/s^2." + ], + "parameters": { + "M": { + "value": 0.8065816605754585, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.22336012313578563, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.3951118388527871, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.20458810483110523, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.989510213156453, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 53.023897253953166, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.08825222897856522, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 0.9254415893206627, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/052/params.json b/scipy/spool_pull_direction_2d/052/params.json new file mode 100644 index 0000000000000000000000000000000000000000..9abdb0177960561d9184eb94ea15801ae9fc6dcf --- /dev/null +++ b/scipy/spool_pull_direction_2d/052/params.json @@ -0,0 +1,15 @@ +{ + "M": 0.8065816605754585, + "R": 0.22336012313578563, + "r_over_R": 0.3951118388527871, + "I_factor": 0.55, + "mu_k": 0.20458810483110523, + "g": 9.81, + "T": 0.989510213156453, + "theta_deg": 53.023897253953166, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.08825222897856522, + "theta": 0.9254415893206627 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/052/simulation_code.py b/scipy/spool_pull_direction_2d/052/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..47dec0471897017379b75f14b10be807756b3295 --- /dev/null +++ b/scipy/spool_pull_direction_2d/052/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.8065816605754585 +R = 0.22336012313578563 +r = 0.08825222897856522 +I_factor = 0.55 +mu_k = 0.20458810483110523 +g = 9.81 +T = 0.989510213156453 +theta = 0.9254415893206627 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/052/video.mp4 b/scipy/spool_pull_direction_2d/052/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a8fd0bac09ff458476742b06710cd1dfdd598846 --- /dev/null +++ b/scipy/spool_pull_direction_2d/052/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b183d43bbdef0b75df4f17548a054b549f4162ee154167a96856118098f68316 +size 10127 diff --git a/scipy/spool_pull_direction_2d/066/cot.json b/scipy/spool_pull_direction_2d/066/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..8ca3e43be110440d0516de3a4e25ef189c260a0d --- /dev/null +++ b/scipy/spool_pull_direction_2d/066/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=1.355 kg, outer (flange) radius R=0.236 m and inner (spindle) radius r=0.072 m (r/R=0.305) rests on a horizontal floor with kinetic friction \\mu_k=0.182. A constant tension T=0.666 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=63.7^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 72.23^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 1.355 \\cdot (0.236)^2 = 0.04161 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.2954 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.04800 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.02182 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 72.23^{\\circ}.", + "Here \\cos(\\theta) = 0.4438 > r/R = 0.3051 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 72.2333 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.04800 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.02182 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 72.2^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.0440 m/s^2." + ], + "parameters": { + "M": { + "value": 1.354781825869612, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.2363230445091621, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.3051414561308239, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.18214732463041777, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.6656397358771791, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 63.65079396865321, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.07211195791879522, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 1.110915926261547, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/066/params.json b/scipy/spool_pull_direction_2d/066/params.json new file mode 100644 index 0000000000000000000000000000000000000000..9f8db468e4d3d7dfe64c3e4b98c39add488596be --- /dev/null +++ b/scipy/spool_pull_direction_2d/066/params.json @@ -0,0 +1,15 @@ +{ + "M": 1.354781825869612, + "R": 0.2363230445091621, + "r_over_R": 0.3051414561308239, + "I_factor": 0.55, + "mu_k": 0.18214732463041777, + "g": 9.81, + "T": 0.6656397358771791, + "theta_deg": 63.65079396865321, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.07211195791879522, + "theta": 1.110915926261547 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/066/simulation_code.py b/scipy/spool_pull_direction_2d/066/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..84d4f66d88b20bc4887962e7fe2fde70059b5ebb --- /dev/null +++ b/scipy/spool_pull_direction_2d/066/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.354781825869612 +R = 0.2363230445091621 +r = 0.07211195791879522 +I_factor = 0.55 +mu_k = 0.18214732463041777 +g = 9.81 +T = 0.6656397358771791 +theta = 1.110915926261547 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/066/video.mp4 b/scipy/spool_pull_direction_2d/066/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6ead5ad23836504547449da9a1fd2426515d7273 --- /dev/null +++ b/scipy/spool_pull_direction_2d/066/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14b4f6f2f457802a62cf223060f9f66d4560eb683bff54d359c34fdae1c36ad8 +size 15413 diff --git a/scipy/spool_pull_direction_2d/105/cot.json b/scipy/spool_pull_direction_2d/105/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..fc6f66ca97cf989b984fb32ea907c45694ad2e17 --- /dev/null +++ b/scipy/spool_pull_direction_2d/105/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=1.314 kg, outer (flange) radius R=0.222 m and inner (spindle) radius r=0.080 m (r/R=0.360) rests on a horizontal floor with kinetic friction \\mu_k=0.298. A constant tension T=0.749 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=54.5^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 68.87^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 1.314 \\cdot (0.222)^2 = 0.03550 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.4345 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.05980 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.03650 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 68.87^{\\circ}.", + "Here \\cos(\\theta) = 0.5804 > r/R = 0.3604 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 68.8733 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.05980 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.03650 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 68.9^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.0809 m/s^2." + ], + "parameters": { + "M": { + "value": 1.313879563816728, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.22163357682118284, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.36043223390690604, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.2978116598236842, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.7485577682873439, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 54.51905058628091, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.0798838852024368, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 0.9515369377919467, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/105/params.json b/scipy/spool_pull_direction_2d/105/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6523715e7410fa06379d97dae59b9cd3c93f40bf --- /dev/null +++ b/scipy/spool_pull_direction_2d/105/params.json @@ -0,0 +1,15 @@ +{ + "M": 1.313879563816728, + "R": 0.22163357682118284, + "r_over_R": 0.36043223390690604, + "I_factor": 0.55, + "mu_k": 0.2978116598236842, + "g": 9.81, + "T": 0.7485577682873439, + "theta_deg": 54.51905058628091, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.0798838852024368, + "theta": 0.9515369377919467 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/105/simulation_code.py b/scipy/spool_pull_direction_2d/105/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..fe3f0fd3f6c5af62c29bd95f48460b3f16e1e1af --- /dev/null +++ b/scipy/spool_pull_direction_2d/105/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.313879563816728 +R = 0.22163357682118284 +r = 0.0798838852024368 +I_factor = 0.55 +mu_k = 0.2978116598236842 +g = 9.81 +T = 0.7485577682873439 +theta = 0.9515369377919467 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/105/video.mp4 b/scipy/spool_pull_direction_2d/105/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..25b5e9b7f30605b4df9471d6d2117f7e3a62307f --- /dev/null +++ b/scipy/spool_pull_direction_2d/105/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51a51465ee444f78ff80263af52b982edb13585e094c7fdf8f07dd1585b19ed9 +size 12620 diff --git a/scipy/spool_pull_direction_2d/116/cot.json b/scipy/spool_pull_direction_2d/116/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..af2e8f7a459ddea74fd63ae9c978c602d53bc055 --- /dev/null +++ b/scipy/spool_pull_direction_2d/116/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=0.961 kg, outer (flange) radius R=0.198 m and inner (spindle) radius r=0.101 m (r/R=0.510) rests on a horizontal floor with kinetic friction \\mu_k=0.226. A constant tension T=0.855 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=71.5^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 59.33^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 0.961 \\cdot (0.198)^2 = 0.02081 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.2718 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.08655 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = +0.03262 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 59.33^{\\circ}.", + "Here \\cos(\\theta) = 0.3179 < r/R = 0.5101 \\Rightarrow \\theta > \\theta_c \\Rightarrow spool rolls away from the pull (-x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 59.3291 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.08655 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = +0.03262 N \\cdot m.", + "Direction of rolling: away from the pull (-x) (because \\theta > \\theta_c = 59.3^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = -0.1103 m/s^2." + ], + "parameters": { + "M": { + "value": 0.9610952352353322, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.19842673215467432, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.5101064311092927, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.22638081407107774, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.8550657195250799, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 71.46677227560781, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.10121875217610045, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 1.2473304819823567, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/116/params.json b/scipy/spool_pull_direction_2d/116/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5299cd6dabe16e53649a337f7af2f61eacd096ba --- /dev/null +++ b/scipy/spool_pull_direction_2d/116/params.json @@ -0,0 +1,15 @@ +{ + "M": 0.9610952352353322, + "R": 0.19842673215467432, + "r_over_R": 0.5101064311092927, + "I_factor": 0.55, + "mu_k": 0.22638081407107774, + "g": 9.81, + "T": 0.8550657195250799, + "theta_deg": 71.46677227560781, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.10121875217610045, + "theta": 1.2473304819823567 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/116/simulation_code.py b/scipy/spool_pull_direction_2d/116/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..23a3b22c9f27d624125cf1bac34319476ea3c632 --- /dev/null +++ b/scipy/spool_pull_direction_2d/116/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.9610952352353322 +R = 0.19842673215467432 +r = 0.10121875217610045 +I_factor = 0.55 +mu_k = 0.22638081407107774 +g = 9.81 +T = 0.8550657195250799 +theta = 1.2473304819823567 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/116/video.mp4 b/scipy/spool_pull_direction_2d/116/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..bbd6a348c5971f5e7c0e79ebb80b17d108a70faa --- /dev/null +++ b/scipy/spool_pull_direction_2d/116/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ecd1f02d569a9abb53b64dfc4a0bdcd09fadfc931c25002bb6b8c553c8d1996 +size 11593 diff --git a/scipy/spool_pull_direction_2d/188/cot.json b/scipy/spool_pull_direction_2d/188/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..fad83f8d42c01b371015b5dbbc51dde290887e18 --- /dev/null +++ b/scipy/spool_pull_direction_2d/188/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=1.529 kg, outer (flange) radius R=0.230 m and inner (spindle) radius r=0.106 m (r/R=0.461) rests on a horizontal floor with kinetic friction \\mu_k=0.186. A constant tension T=0.790 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=47.1^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 62.53^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 1.529 \\cdot (0.230)^2 = 0.04459 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.5381 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.08389 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.04001 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 62.53^{\\circ}.", + "Here \\cos(\\theta) = 0.6812 > r/R = 0.4612 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 62.5329 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.08389 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.04001 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 62.5^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.0733 m/s^2." + ], + "parameters": { + "M": { + "value": 1.529027101763813, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.2302781662217201, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.46123936015290234, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.18614214163155376, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.7898517487667308, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 47.05943290730207, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.10621335404528987, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 0.8213420483537885, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/188/params.json b/scipy/spool_pull_direction_2d/188/params.json new file mode 100644 index 0000000000000000000000000000000000000000..be9d4fe689aa6ad7df8f7a27aef0f9e54c9f6412 --- /dev/null +++ b/scipy/spool_pull_direction_2d/188/params.json @@ -0,0 +1,15 @@ +{ + "M": 1.529027101763813, + "R": 0.2302781662217201, + "r_over_R": 0.46123936015290234, + "I_factor": 0.55, + "mu_k": 0.18614214163155376, + "g": 9.81, + "T": 0.7898517487667308, + "theta_deg": 47.05943290730207, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.10621335404528987, + "theta": 0.8213420483537885 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/188/simulation_code.py b/scipy/spool_pull_direction_2d/188/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..f80468c433eaf0cb0f8bd90f926152ab7fb776f0 --- /dev/null +++ b/scipy/spool_pull_direction_2d/188/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.529027101763813 +R = 0.2302781662217201 +r = 0.10621335404528987 +I_factor = 0.55 +mu_k = 0.18614214163155376 +g = 9.81 +T = 0.7898517487667308 +theta = 0.8213420483537885 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/188/video.mp4 b/scipy/spool_pull_direction_2d/188/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3a27b1a35eefc8c0139834a2897f7498ff855870 --- /dev/null +++ b/scipy/spool_pull_direction_2d/188/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60b1f123737c970420438d772ae216b85b39584bbf628bef2ea160011501bc34 +size 12682 diff --git a/scipy/spool_pull_direction_2d/258/cot.json b/scipy/spool_pull_direction_2d/258/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f2ae1f179dbdf56ed0bc90367032bd9d350a8a6c --- /dev/null +++ b/scipy/spool_pull_direction_2d/258/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=0.969 kg, outer (flange) radius R=0.225 m and inner (spindle) radius r=0.100 m (r/R=0.445) rests on a horizontal floor with kinetic friction \\mu_k=0.307. A constant tension T=0.745 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=48.3^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 63.55^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 0.969 \\cdot (0.225)^2 = 0.02700 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.4959 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.07473 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.03691 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 63.55^{\\circ}.", + "Here \\cos(\\theta) = 0.6655 > r/R = 0.4455 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 63.5455 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.07473 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.03691 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 63.5^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.1092 m/s^2." + ], + "parameters": { + "M": { + "value": 0.9687928531773129, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.22511098751693626, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.445486972867201, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.30650544251594614, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.7452272777400235, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 48.28030452621232, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.10028401238806621, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 0.8426502778479259, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/258/params.json b/scipy/spool_pull_direction_2d/258/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5effb470e5b0e34b614aea89d88c4f47a6292da6 --- /dev/null +++ b/scipy/spool_pull_direction_2d/258/params.json @@ -0,0 +1,15 @@ +{ + "M": 0.9687928531773129, + "R": 0.22511098751693626, + "r_over_R": 0.445486972867201, + "I_factor": 0.55, + "mu_k": 0.30650544251594614, + "g": 9.81, + "T": 0.7452272777400235, + "theta_deg": 48.28030452621232, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.10028401238806621, + "theta": 0.8426502778479259 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/258/simulation_code.py b/scipy/spool_pull_direction_2d/258/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d81cb06f3a2795940f2917e0c052a4179e982d02 --- /dev/null +++ b/scipy/spool_pull_direction_2d/258/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.9687928531773129 +R = 0.22511098751693626 +r = 0.10028401238806621 +I_factor = 0.55 +mu_k = 0.30650544251594614 +g = 9.81 +T = 0.7452272777400235 +theta = 0.8426502778479259 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/258/video.mp4 b/scipy/spool_pull_direction_2d/258/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f1e69350e75b290b9759523bc71ea8261d8e9077 --- /dev/null +++ b/scipy/spool_pull_direction_2d/258/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91d8bc3c677335e280a39bc662a2d8170d3cd1aca2243c69b2873ed63948d64f +size 11656 diff --git a/scipy/spool_pull_direction_2d/291/cot.json b/scipy/spool_pull_direction_2d/291/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..2207e2d86fc8d92ca637fd842921f5cc166f1c21 --- /dev/null +++ b/scipy/spool_pull_direction_2d/291/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=1.220 kg, outer (flange) radius R=0.240 m and inner (spindle) radius r=0.139 m (r/R=0.578) rests on a horizontal floor with kinetic friction \\mu_k=0.194. A constant tension T=0.764 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=38.2^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 54.68^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 1.220 \\cdot (0.240)^2 = 0.03880 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.5999 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.10618 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.03807 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 54.68^{\\circ}.", + "Here \\cos(\\theta) = 0.7854 > r/R = 0.5781 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 54.6821 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.10618 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.03807 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 54.7^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.0837 m/s^2." + ], + "parameters": { + "M": { + "value": 1.2203508748337222, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.24043837672386348, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.5781125025114567, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.19397930702563831, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.7638755457818904, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 38.24458584307054, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.1390004316676251, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 0.6674939440231923, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/291/params.json b/scipy/spool_pull_direction_2d/291/params.json new file mode 100644 index 0000000000000000000000000000000000000000..2d2b5be82e3e1540036a3aaedcf7e6c69690e805 --- /dev/null +++ b/scipy/spool_pull_direction_2d/291/params.json @@ -0,0 +1,15 @@ +{ + "M": 1.2203508748337222, + "R": 0.24043837672386348, + "r_over_R": 0.5781125025114567, + "I_factor": 0.55, + "mu_k": 0.19397930702563831, + "g": 9.81, + "T": 0.7638755457818904, + "theta_deg": 38.24458584307054, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.1390004316676251, + "theta": 0.6674939440231923 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/291/simulation_code.py b/scipy/spool_pull_direction_2d/291/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..6a04a67525ba9f2f75668bc8f661d511a61b2e43 --- /dev/null +++ b/scipy/spool_pull_direction_2d/291/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.2203508748337222 +R = 0.24043837672386348 +r = 0.1390004316676251 +I_factor = 0.55 +mu_k = 0.19397930702563831 +g = 9.81 +T = 0.7638755457818904 +theta = 0.6674939440231923 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/291/video.mp4 b/scipy/spool_pull_direction_2d/291/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..2260cd57948727e2c8d6f8ffe89bbaf60e10c8e9 --- /dev/null +++ b/scipy/spool_pull_direction_2d/291/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95b435c69f25c455f01419679b5d39d7847b14803794a69ff20a55802ed00495 +size 12262 diff --git a/scipy/spool_pull_direction_2d/348/cot.json b/scipy/spool_pull_direction_2d/348/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..093f2b37d88dd8a5fa91dfa2743ba45425aad40e --- /dev/null +++ b/scipy/spool_pull_direction_2d/348/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=1.543 kg, outer (flange) radius R=0.250 m and inner (spindle) radius r=0.091 m (r/R=0.364) rests on a horizontal floor with kinetic friction \\mu_k=0.198. A constant tension T=0.622 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=58.1^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 68.66^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 1.543 \\cdot (0.250)^2 = 0.05296 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.3290 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.05658 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.02562 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 68.66^{\\circ}.", + "Here \\cos(\\theta) = 0.5286 > r/R = 0.3639 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 68.6619 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.05658 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.02562 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 68.7^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.0429 m/s^2." + ], + "parameters": { + "M": { + "value": 1.542654009557389, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.24984846773833508, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.3638705144941996, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.19754729820740302, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.6224017497350748, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 58.08761645666387, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.09091249050153542, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 1.0138201618044267, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/348/params.json b/scipy/spool_pull_direction_2d/348/params.json new file mode 100644 index 0000000000000000000000000000000000000000..eaeb8dbc2693cae1f8552e4a5dc83874eaf8de24 --- /dev/null +++ b/scipy/spool_pull_direction_2d/348/params.json @@ -0,0 +1,15 @@ +{ + "M": 1.542654009557389, + "R": 0.24984846773833508, + "r_over_R": 0.3638705144941996, + "I_factor": 0.55, + "mu_k": 0.19754729820740302, + "g": 9.81, + "T": 0.6224017497350748, + "theta_deg": 58.08761645666387, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.09091249050153542, + "theta": 1.0138201618044267 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/348/simulation_code.py b/scipy/spool_pull_direction_2d/348/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e8f011c859b096c790cf29bd23b96d2d535b1dc7 --- /dev/null +++ b/scipy/spool_pull_direction_2d/348/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.542654009557389 +R = 0.24984846773833508 +r = 0.09091249050153542 +I_factor = 0.55 +mu_k = 0.19754729820740302 +g = 9.81 +T = 0.6224017497350748 +theta = 1.0138201618044267 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/348/video.mp4 b/scipy/spool_pull_direction_2d/348/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..749d75ad5a05c2ac379432e3bad2baf645754ae7 --- /dev/null +++ b/scipy/spool_pull_direction_2d/348/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d14d0168ea14c347c7216f29af6fecb5830e1384b0de57b8ef0050209078ee7 +size 15526 diff --git a/scipy/spool_pull_direction_2d/451/cot.json b/scipy/spool_pull_direction_2d/451/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..1b3c19c14cc5fbdc8c858295cb053b8b983ff00f --- /dev/null +++ b/scipy/spool_pull_direction_2d/451/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=1.179 kg, outer (flange) radius R=0.225 m and inner (spindle) radius r=0.091 m (r/R=0.402) rests on a horizontal floor with kinetic friction \\mu_k=0.280. A constant tension T=0.599 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=51.6^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 66.32^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 1.179 \\cdot (0.225)^2 = 0.03297 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.3724 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.05426 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.02972 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 66.32^{\\circ}.", + "Here \\cos(\\theta) = 0.6217 > r/R = 0.4017 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 66.3167 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.05426 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.02972 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 66.3^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.0721 m/s^2." + ], + "parameters": { + "M": { + "value": 1.1790006982018935, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.2254993887179985, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.4016813297825048, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.28014764976717454, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.598993844023467, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 51.56098169608739, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.0905788943253876, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 0.8999088961572552, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/451/params.json b/scipy/spool_pull_direction_2d/451/params.json new file mode 100644 index 0000000000000000000000000000000000000000..38fb4ac2446c70dd6ae28594bbc33b96aac0feb4 --- /dev/null +++ b/scipy/spool_pull_direction_2d/451/params.json @@ -0,0 +1,15 @@ +{ + "M": 1.1790006982018935, + "R": 0.2254993887179985, + "r_over_R": 0.4016813297825048, + "I_factor": 0.55, + "mu_k": 0.28014764976717454, + "g": 9.81, + "T": 0.598993844023467, + "theta_deg": 51.56098169608739, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.0905788943253876, + "theta": 0.8999088961572552 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/451/simulation_code.py b/scipy/spool_pull_direction_2d/451/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..19922c0e3f05c425462cf6bd3bf614b7a33c3441 --- /dev/null +++ b/scipy/spool_pull_direction_2d/451/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.1790006982018935 +R = 0.2254993887179985 +r = 0.0905788943253876 +I_factor = 0.55 +mu_k = 0.28014764976717454 +g = 9.81 +T = 0.598993844023467 +theta = 0.8999088961572552 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/451/video.mp4 b/scipy/spool_pull_direction_2d/451/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a4a08b03e081895fe9f9b1cb12963aab4c3e3082 --- /dev/null +++ b/scipy/spool_pull_direction_2d/451/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72e6f9234ae747b8fd03f61cc468d23c0feca65022b04c92a3e70994191e89f7 +size 12724 diff --git a/scipy/spool_pull_direction_2d/480/cot.json b/scipy/spool_pull_direction_2d/480/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..c8a78a2217e388068787c2e6089b3da3df0d182c --- /dev/null +++ b/scipy/spool_pull_direction_2d/480/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=1.558 kg, outer (flange) radius R=0.219 m and inner (spindle) radius r=0.099 m (r/R=0.454) rests on a horizontal floor with kinetic friction \\mu_k=0.204. A constant tension T=0.906 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=47.6^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 63.00^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 1.558 \\cdot (0.219)^2 = 0.04099 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.6105 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.08995 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.04359 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 63.00^{\\circ}.", + "Here \\cos(\\theta) = 0.6740 > r/R = 0.4540 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 63.0019 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.08995 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.04359 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 63.0^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.0825 m/s^2." + ], + "parameters": { + "M": { + "value": 1.55783065019918, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.21873040383520925, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.45396121769041387, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.20394761797930078, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.9058380930864984, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 47.62646534338103, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.09929512047094756, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 0.8312386313289707, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/480/params.json b/scipy/spool_pull_direction_2d/480/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3f0b0a312e70bfeacdf55235efccda3b6e5bea8b --- /dev/null +++ b/scipy/spool_pull_direction_2d/480/params.json @@ -0,0 +1,15 @@ +{ + "M": 1.55783065019918, + "R": 0.21873040383520925, + "r_over_R": 0.45396121769041387, + "I_factor": 0.55, + "mu_k": 0.20394761797930078, + "g": 9.81, + "T": 0.9058380930864984, + "theta_deg": 47.62646534338103, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.09929512047094756, + "theta": 0.8312386313289707 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/480/simulation_code.py b/scipy/spool_pull_direction_2d/480/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d6e86eafac68c64d2a9ac2cf7a3e76d3ffb7bdb4 --- /dev/null +++ b/scipy/spool_pull_direction_2d/480/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.55783065019918 +R = 0.21873040383520925 +r = 0.09929512047094756 +I_factor = 0.55 +mu_k = 0.20394761797930078 +g = 9.81 +T = 0.9058380930864984 +theta = 0.8312386313289707 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/480/video.mp4 b/scipy/spool_pull_direction_2d/480/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..39753efaafaa2e3596e972d998b71f099ef8ecd6 --- /dev/null +++ b/scipy/spool_pull_direction_2d/480/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8f30e0dc3739bce7d7e79d62f5fc8780879bfc56141cc1795279369ac6da3e8 +size 12253 diff --git a/scipy/spool_pull_direction_2d/489/cot.json b/scipy/spool_pull_direction_2d/489/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..802dbd3b82f3e179bc1d9c90a4738650aaf40108 --- /dev/null +++ b/scipy/spool_pull_direction_2d/489/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=0.645 kg, outer (flange) radius R=0.220 m and inner (spindle) radius r=0.121 m (r/R=0.551) rests on a horizontal floor with kinetic friction \\mu_k=0.197. A constant tension T=0.604 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=39.6^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 56.58^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 0.645 \\cdot (0.220)^2 = 0.01719 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.4658 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.07327 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.02927 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 56.58^{\\circ}.", + "Here \\cos(\\theta) = 0.7708 > r/R = 0.5508 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 56.5805 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.07327 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.02927 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 56.6^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.1330 m/s^2." + ], + "parameters": { + "M": { + "value": 0.6451117254897801, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.22011857779919156, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.5507650894477585, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.19733989809932895, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.6043544137098312, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 39.57735698776733, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.12123362819068512, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 0.6907551886737251, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/489/params.json b/scipy/spool_pull_direction_2d/489/params.json new file mode 100644 index 0000000000000000000000000000000000000000..207716bcad44076024f5c9be5e853fdb4ef04f81 --- /dev/null +++ b/scipy/spool_pull_direction_2d/489/params.json @@ -0,0 +1,15 @@ +{ + "M": 0.6451117254897801, + "R": 0.22011857779919156, + "r_over_R": 0.5507650894477585, + "I_factor": 0.55, + "mu_k": 0.19733989809932895, + "g": 9.81, + "T": 0.6043544137098312, + "theta_deg": 39.57735698776733, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.12123362819068512, + "theta": 0.6907551886737251 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/489/simulation_code.py b/scipy/spool_pull_direction_2d/489/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b93317301f4689ec006fc06ff63201a21647a2af --- /dev/null +++ b/scipy/spool_pull_direction_2d/489/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.6451117254897801 +R = 0.22011857779919156 +r = 0.12123362819068512 +I_factor = 0.55 +mu_k = 0.19733989809932895 +g = 9.81 +T = 0.6043544137098312 +theta = 0.6907551886737251 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/489/video.mp4 b/scipy/spool_pull_direction_2d/489/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..96dd478b1b5afb6cf71e273d38dea53105802522 --- /dev/null +++ b/scipy/spool_pull_direction_2d/489/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66d363646cdf9271d0edff29e5a54475202d84c1048f5df86d1727efbf19c3d9 +size 11138 diff --git a/scipy/spool_pull_direction_2d/490/cot.json b/scipy/spool_pull_direction_2d/490/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f027c25449d64e04b7f9ed6dbf98eb6b6d3588fd --- /dev/null +++ b/scipy/spool_pull_direction_2d/490/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=1.038 kg, outer (flange) radius R=0.182 m and inner (spindle) radius r=0.055 m (r/R=0.304) rests on a horizontal floor with kinetic friction \\mu_k=0.270. A constant tension T=0.864 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=58.4^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 72.31^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 1.038 \\cdot (0.182)^2 = 0.01880 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.4528 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.04767 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.03451 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 72.31^{\\circ}.", + "Here \\cos(\\theta) = 0.5239 > r/R = 0.3039 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 72.3074 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.04767 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.03451 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 72.3^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.1182 m/s^2." + ], + "parameters": { + "M": { + "value": 1.0377207163453135, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.18150367480839597, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.3039094550425563, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.2704323428051752, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.8642450085623724, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 58.405142721665754, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.05516068289924097, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 1.0193620405902695, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/490/params.json b/scipy/spool_pull_direction_2d/490/params.json new file mode 100644 index 0000000000000000000000000000000000000000..a90212a03ed08b75f328eb58e673b45a5819c9e9 --- /dev/null +++ b/scipy/spool_pull_direction_2d/490/params.json @@ -0,0 +1,15 @@ +{ + "M": 1.0377207163453135, + "R": 0.18150367480839597, + "r_over_R": 0.3039094550425563, + "I_factor": 0.55, + "mu_k": 0.2704323428051752, + "g": 9.81, + "T": 0.8642450085623724, + "theta_deg": 58.405142721665754, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.05516068289924097, + "theta": 1.0193620405902695 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/490/simulation_code.py b/scipy/spool_pull_direction_2d/490/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d166649298b5bf2615c9407ecf94aa641caf21e3 --- /dev/null +++ b/scipy/spool_pull_direction_2d/490/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.0377207163453135 +R = 0.18150367480839597 +r = 0.05516068289924097 +I_factor = 0.55 +mu_k = 0.2704323428051752 +g = 9.81 +T = 0.8642450085623724 +theta = 1.0193620405902695 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/490/video.mp4 b/scipy/spool_pull_direction_2d/490/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..085328bce7d86d16c81de88726a72a956259e5bd --- /dev/null +++ b/scipy/spool_pull_direction_2d/490/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1211e59b49c9c580eca2fe389bbbf4570f42e8b7251d0166d72369753d8a10f6 +size 10813 diff --git a/scipy/spool_pull_direction_2d/502/cot.json b/scipy/spool_pull_direction_2d/502/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..50685a4773eb23541965ac67393291446d7b7606 --- /dev/null +++ b/scipy/spool_pull_direction_2d/502/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=0.864 kg, outer (flange) radius R=0.228 m and inner (spindle) radius r=0.142 m (r/R=0.620) rests on a horizontal floor with kinetic friction \\mu_k=0.289. A constant tension T=0.989 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=66.4^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 51.67^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 0.864 \\cdot (0.228)^2 = 0.02479 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.3959 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.14011 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = +0.04970 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 51.67^{\\circ}.", + "Here \\cos(\\theta) = 0.4002 < r/R = 0.6202 \\Rightarrow \\theta > \\theta_c \\Rightarrow spool rolls away from the pull (-x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 51.6663 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.14011 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = +0.04970 N \\cdot m.", + "Direction of rolling: away from the pull (-x) (because \\theta > \\theta_c = 51.7^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = -0.1624 m/s^2." + ], + "parameters": { + "M": { + "value": 0.8642880817792888, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.22837745748235797, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.6202399446237415, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.28918586845017297, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.9891540402679891, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 66.40682056946547, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.1416488215821686, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 1.1590176647182682, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/502/params.json b/scipy/spool_pull_direction_2d/502/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3ccf8741a7eb9c34915698bbcb87d1204c0aeb16 --- /dev/null +++ b/scipy/spool_pull_direction_2d/502/params.json @@ -0,0 +1,15 @@ +{ + "M": 0.8642880817792888, + "R": 0.22837745748235797, + "r_over_R": 0.6202399446237415, + "I_factor": 0.55, + "mu_k": 0.28918586845017297, + "g": 9.81, + "T": 0.9891540402679891, + "theta_deg": 66.40682056946547, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.1416488215821686, + "theta": 1.1590176647182682 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/502/simulation_code.py b/scipy/spool_pull_direction_2d/502/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..5d5993961d7701b006a0d29c40f5ed283dd0e72d --- /dev/null +++ b/scipy/spool_pull_direction_2d/502/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 0.8642880817792888 +R = 0.22837745748235797 +r = 0.1416488215821686 +I_factor = 0.55 +mu_k = 0.28918586845017297 +g = 9.81 +T = 0.9891540402679891 +theta = 1.1590176647182682 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/502/video.mp4 b/scipy/spool_pull_direction_2d/502/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..29b0fd1a1f78553847a6895d253bf9f2c789905b --- /dev/null +++ b/scipy/spool_pull_direction_2d/502/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ec320925446fd70e5cda5416179e5e8f6803220dbf6a27febcc62714ae329c6b +size 10879 diff --git a/scipy/spool_pull_direction_2d/587/cot.json b/scipy/spool_pull_direction_2d/587/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..e8cfa8a99def1533d169eabb601cc91715b03dd5 --- /dev/null +++ b/scipy/spool_pull_direction_2d/587/cot.json @@ -0,0 +1,135 @@ +{ + "simulation": "spool_pull_direction_2d", + "physical_observation": "A spool of mass M=1.400 kg, outer (flange) radius R=0.215 m and inner (spindle) radius r=0.093 m (r/R=0.431) rests on a horizontal floor with kinetic friction \\mu_k=0.257. A constant tension T=0.816 N is applied through a thread wound around the inner spindle; the thread emerges tangent at angle \\theta=49.4^{\\circ} above the horizontal. Critical angle: \\theta_c = \\arccos(r/R) = 64.49^{\\circ}.", + "physical_law": { + "name": "Newton-Euler (planar rigid body) + Coulomb friction + rolling resistance", + "statement": "A spool on a floor obeys Newton's 2nd law for translation, M \\dot{v}_x = \\SigmaF_x, and Euler's equation for rotation about the centre of mass, I_cm \\dot{\\omega} = \\Sigma\\tau. A thread wound around the inner spindle pulls with tension T at angle \\theta; that tension applies a horizontal force T \\cos(\\theta) at the spindle tangent point and a torque T \\cdot r about the CoM (independent of \\theta). The torque about the floor contact point is \\tau_contact = T (r - R \\cos(\\theta)); it vanishes at the critical angle \\cos(\\theta) = r/R, which separates rolling toward the pull (\\theta<\\theta_c) from rolling away (\\theta>\\theta_c).", + "formula": "M v_x_dot = T \\cos(theta) - mu_k M g \\tanh(alpha (v_x + omega R)); I_cm omega_dot = T r - mu_k M g R \\tanh(alpha (v_x + omega R)); theta_c = \\arccos(r / R); v_x(0) = 0; omega(0) = 0." + }, + "ode_system": { + "state_variables": [ + "x (m)", + "phi (rad)", + "v_x (m/s)", + "omega (rad/s)" + ], + "equations_latex": [ + "\\dot{x} = v_x", + "\\dot{phi} = omega", + "\\dot{v}_x = (T \\cos(theta) + F_f) / M", + "\\dot{omega} = (T r + R F_f) / I_cm", + "F_f = -mu_k M g \\tanh(alpha (v_x + omega R))" + ], + "equations_python": [ + "x_dot = v_x", + "phi_dot = omega", + "v_dot_x = (T * np.cos (theta) + F_f) / M", + "omega_dot = (T * r + R * F_f) / I_cm", + "F_f = -mu_k * M g * np.tanh (alpha (v_x + omega * R))" + ] + }, + "derivation_steps": [ + "Generalised coordinates: x (centre-of-mass position) and \\phi (rotation).", + "Moment of inertia about the centre of mass: I_cm = I_factor \\cdot M \\cdot R^2 = 0.550 \\cdot 1.400 \\cdot (0.215)^2 = 0.03558 kg \\cdot m^2.", + "", + "Force/torque from the thread. The thread emerges tangent to the inner spindle at point P = (r \\sin(\\theta), -r \\cos(\\theta)) relative to the spool centre, pulling in the direction (\\cos(\\theta), \\sin(\\theta)) with constant magnitude T:", + " F_T = T (\\cos(\\theta), \\sin(\\theta)); horizontal component = T \\cos(\\theta) = +0.5310 N.", + " Torque about CoM: \\tau_T = (P \\times F_T)_z = T r \\sin^2\\theta + T r \\cos^2\\theta = T r = +0.07555 N \\cdot m (independent of \\theta, always CCW).", + "", + "Floor friction at the contact point opposes the bottom-of-spool velocity:", + " v_contact = v_x + \\omega R, F_f = -\\mu_k M g \\cdot \\tanh(\\alpha v_contact).", + "", + "Newton-Euler equations of motion:", + " M \\dot{v}_x = T \\cos(\\theta) + F_f", + " I_cm \\dot{\\omega} = T r + R F_f", + "", + "Critical-angle analysis. Net torque about the floor contact point (arm to spindle tangent point is (r \\sin(\\theta), R - r \\cos(\\theta)); to tension (T \\cos(\\theta), T \\sin(\\theta))):", + " \\tau_contact = T (r - R \\cos(\\theta)) = -0.03860 N \\cdot m.", + " \\tau_contact = 0 \\Rightarrow \\cos(\\theta) = r/R, \\theta_c = 64.49^{\\circ}.", + "Here \\cos(\\theta) = 0.6506 > r/R = 0.4306 \\Rightarrow \\theta < \\theta_c \\Rightarrow spool rolls toward the pull (+x)." + ], + "numerical_method": { + "solver": "RK45 (Dormand-Prince 4(5))", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth \\tanh-regularised Coulomb friction and rolling-resistance sgn() functions keep the right-hand side continuous, so a non-stiff Runge-Kutta integrator with tight tolerances tracks the slip-to-roll transition without spurious sign-chatter." + }, + "code_validation": { + "ode_source": "Newton-Euler 2-D rigid body: F = m a for the centre of mass and \\tau = I \\alpha about the centre of mass, with continuous thread tension applied at the spindle tangent point, plus kinetic-friction and rolling-resistance couplings. Initial state: spool at rest.", + "energy_check": "Power input from the thread = T \\cdot v_thread_pull_point; dissipation = \\mu_k M g |v_contact| + \\mu_r M g R |\\omega|.", + "physical_plausibility": true, + "critical_angle_deg": 64.4935 + }, + "expected_behavior": [ + "Tension torque about CoM: \\tau_T = T \\cdot r = 0.07555 N \\cdot m (always CCW).", + "Tension torque about contact: \\tau_contact = T(r - R \\cos(\\theta)) = -0.03860 N \\cdot m.", + "Direction of rolling: toward the pull (+x) (because \\theta < \\theta_c = 64.5^{\\circ}).", + "Steady-state CoM acceleration (rolling without slipping): a = T \\cdot (\\cos(\\theta) - r/R) / [M \\cdot (1 + I_factor)] = +0.0827 m/s^2." + ], + "parameters": { + "M": { + "value": 1.4001252647409932, + "unit": "kg", + "description": "Spool mass" + }, + "R": { + "value": 0.2149641602382578, + "unit": "m", + "description": "Outer (flange) radius" + }, + "r_over_R": { + "value": 0.43061283360335306, + "unit": "", + "description": "Ratio r / R" + }, + "I_factor": { + "value": 0.55, + "unit": "", + "description": "I_cm = I_factor \\cdot M \\cdot R^2" + }, + "mu_k": { + "value": 0.25665781222331163, + "unit": "", + "description": "Kinetic friction (rim-floor)" + }, + "g": { + "value": 9.81, + "unit": "m/s^2", + "description": "Gravity" + }, + "T": { + "value": 0.8161575391148659, + "unit": "N", + "description": "Continuous thread tension" + }, + "theta_deg": { + "value": 49.41217715013511, + "unit": "^{\\circ}", + "description": "Thread angle above horizontal" + }, + "alpha_\\tanh": { + "value": 80.0, + "unit": "", + "description": "" + }, + "x0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "phi0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "r": { + "value": 0.09256632616336143, + "unit": "m", + "description": "Inner (spindle) radius" + }, + "theta": { + "value": 0.8624051818485661, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spool_pull_direction_2d/587/params.json b/scipy/spool_pull_direction_2d/587/params.json new file mode 100644 index 0000000000000000000000000000000000000000..9112d08bae46844a7a76459560b2d1c84cf3d54c --- /dev/null +++ b/scipy/spool_pull_direction_2d/587/params.json @@ -0,0 +1,15 @@ +{ + "M": 1.4001252647409932, + "R": 0.2149641602382578, + "r_over_R": 0.43061283360335306, + "I_factor": 0.55, + "mu_k": 0.25665781222331163, + "g": 9.81, + "T": 0.8161575391148659, + "theta_deg": 49.41217715013511, + "alpha_tanh": 80.0, + "x0": 0.0, + "phi0": 0.0, + "r": 0.09256632616336143, + "theta": 0.8624051818485661 +} \ No newline at end of file diff --git a/scipy/spool_pull_direction_2d/587/simulation_code.py b/scipy/spool_pull_direction_2d/587/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..bdb572b253d01f4ee5de90ff0a2c91cd2bcf224d --- /dev/null +++ b/scipy/spool_pull_direction_2d/587/simulation_code.py @@ -0,0 +1,99 @@ +""" +Spool Pull Direction (2D) — auto-generated simulation script. + +Physics: + τ_contact = T (r − R cosθ); critical cos θ_c = r/R. + M v̇_x = T cosθ + F_f, I ω̇ = T r + R F_f, I = I_factor · M R². + F_f = −μ_k M g · tanh(α (v_x + ω R)) + Tension acts at P = (r sinθ, −r cosθ) on the inner spindle in direction + (cosθ, sinθ); torque about CoM is T r CCW (independent of θ). +""" +import math +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + + +M = 1.4001252647409932 +R = 0.2149641602382578 +r = 0.09256632616336143 +I_factor = 0.55 +mu_k = 0.25665781222331163 +g = 9.81 +T = 0.8161575391148659 +theta = 0.8624051818485661 +alpha_tanh = 80.0 +x0 = 0.0 +phi0 = 0.0 +duration = 12 +fps = 30 +I = I_factor * M * R**2 + +cos_th = math.cos(theta); sin_th = math.sin(theta) + +def ode(t, y): + x, phi, vx, omega = y + v_contact = vx + omega * R + F_f = -mu_k * M * g * np.tanh(alpha_tanh * v_contact) + F_T_x = T * cos_th + tau_T = T * r + return [vx, omega, (F_T_x + F_f) / M, (R * F_f + tau_T) / I] + +t_eval = np.linspace(0.0, duration, int(duration * fps) + 1) +sol = solve_ivp(ode, (0.0, duration), [x0, phi0, 0.0, 0.0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +t = sol.t; y = sol.y +x_arr, phi_arr = y[0], y[1] + + +L_thread = 1.6 +pad_x = max(R * 1.5, 0.4) +x_min = float(np.min(x_arr)) - pad_x - 0.2 +x_max = float(np.max(x_arr)) + pad_x + L_thread * cos_th + 0.5 +if x_max - x_min < 5.0: + mid = 0.5 * (x_min + x_max) + x_min, x_max = mid - 2.5, mid + 2.5 +y_top = max(2 * R + 0.5, R - r * cos_th + L_thread * sin_th + 0.4) + +fig, ax = plt.subplots(figsize=(11, 4.6), facecolor="#1a1a2e") +ax.set_facecolor("#16213e") +ax.set_xlim(x_min, x_max); ax.set_ylim(-0.18, y_top) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(0.0, color="#3a3a4f", lw=2.5, zorder=1) + +outer_disc = patches.Circle((x0, R), R, + facecolor="#457b9d", edgecolor="white", lw=1.5, zorder=3) +inner_disc = patches.Circle((x0, R), r, + facecolor="#1d3557", edgecolor="white", lw=1.0, zorder=4) +ax.add_patch(outer_disc); ax.add_patch(inner_disc) + +spoke_line, = ax.plot([], [], "-", color="#e63946", lw=2.5, zorder=5) +tip_dot, = ax.plot([], [], "o", color="#e63946", ms=8, zorder=5) +thread_line, = ax.plot([], [], "-", color="#ffd166", lw=2.5, zorder=6) +grip = patches.Circle((0, 0), 0.05, facecolor="#ffd166", + edgecolor="white", lw=1.0, zorder=7) +ax.add_patch(grip) + + +def update(frame): + cx = float(x_arr[frame]) + ph = float(phi_arr[frame]) + outer_disc.center = (cx, R) + inner_disc.center = (cx, R) + sx = cx + R * math.cos(ph) + sy = R + R * math.sin(ph) + spoke_line.set_data([cx, sx], [R, sy]) + tip_dot.set_data([sx], [sy]) + tx0 = cx + r * sin_th; ty0 = R - r * cos_th + tx1 = tx0 + L_thread * cos_th; ty1 = ty0 + L_thread * sin_th + thread_line.set_data([tx0, tx1], [ty0, ty1]) + grip.center = (tx1, ty1) + return [outer_disc, inner_disc, spoke_line, tip_dot, thread_line, grip] + +ani = animation.FuncAnimation(fig, update, frames=len(t), + interval=1000 / fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spool_pull_direction_2d/587/video.mp4 b/scipy/spool_pull_direction_2d/587/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..82c683e0ec542b7893cca84f5e6cb2c3e3c029f0 --- /dev/null +++ b/scipy/spool_pull_direction_2d/587/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b20c07713829f9b8981c2b402fa949e5c395faa92fa4f564e9e367a9977f957 +size 12211 diff --git a/scipy/spring_2d/054/cot.json b/scipy/spring_2d/054/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..2a402d5202052def05394ca1f6a753a5f2a3a3c6 --- /dev/null +++ b/scipy/spring_2d/054/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=0.324 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=5.535 N/m, rest length R=1.880 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.784 kg/s. The mass is released from (1.306, 2.021) with velocity (1.422, -0.715) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = 0.5470." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 4.1362, + "T_nat_s": 1.5191, + "damping_ratio_zeta": 0.2928, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": 0.547 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 4.136 rad/s (period T_0 = 1.519 s).", + "Damping ratio \\zeta = 0.2928: underdamped.", + "Equilibrium position: (0.000, 0.547) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 5.534692049996119, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 0.32350463337856294, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.7835088296543656, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.8802035642307888, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": 1.3063280525075727, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 2.0211885275770705, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 1.4216937502515368, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": -0.7147859893823356, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/054/params.json b/scipy/spring_2d/054/params.json new file mode 100644 index 0000000000000000000000000000000000000000..a9262e171e54c28f8846183a54dfeb4aaaa125a6 --- /dev/null +++ b/scipy/spring_2d/054/params.json @@ -0,0 +1,13 @@ +{ + "k": 5.534692049996119, + "m": 0.32350463337856294, + "b": 0.7835088296543656, + "g": 9.8, + "R": 1.8802035642307888, + "ax": 0.0, + "ay": 3.0, + "x0": 1.3063280525075727, + "y0": 2.0211885275770705, + "vx0": 1.4216937502515368, + "vy0": -0.7147859893823356 +} \ No newline at end of file diff --git a/scipy/spring_2d/054/simulation_code.py b/scipy/spring_2d/054/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..9a97813a7d7fcdd6418148eb63945962b965a1ed --- /dev/null +++ b/scipy/spring_2d/054/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=5.534692049996119 N/m, m=0.32350463337856294 kg, b=0.7835088296543656 kg/s, g=9.8 m/s^2 + R=1.8802035642307888 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 5.534692049996119, 0.32350463337856294, 0.7835088296543656, 9.8 +R = 1.8802035642307888 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = 1.306328, 2.021189, 1.421694, -0.714786 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/054/video.mp4 b/scipy/spring_2d/054/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..12e9454b80d23d2f3ee91bdd11b7ff7a2db603e0 --- /dev/null +++ b/scipy/spring_2d/054/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b48be139b14c4a8d0fcbb609fee9a0942bcbe682894d1bc0ac79e39867c16e8f +size 10664 diff --git a/scipy/spring_2d/075/cot.json b/scipy/spring_2d/075/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..9419ceef203d9176f4b23b9e325328f5472f2157 --- /dev/null +++ b/scipy/spring_2d/075/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=0.534 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=5.453 N/m, rest length R=1.512 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.242 kg/s. The mass is released from (0.881, 1.443) with velocity (0.614, 1.212) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = 0.5285." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 3.1953, + "T_nat_s": 1.9664, + "damping_ratio_zeta": 0.0708, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": 0.5285 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 3.195 rad/s (period T_0 = 1.966 s).", + "Damping ratio \\zeta = 0.0708: underdamped.", + "Equilibrium position: (0.000, 0.528) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 5.453150956868657, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 0.5340933469371478, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.24151413401019417, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.5116857570922697, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": 0.8807649983527113, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 1.4430664549238743, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 0.6141950675744003, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": 1.2117354548422403, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/075/params.json b/scipy/spring_2d/075/params.json new file mode 100644 index 0000000000000000000000000000000000000000..05224d1218824ccf48307cfbb639f4be579b4867 --- /dev/null +++ b/scipy/spring_2d/075/params.json @@ -0,0 +1,13 @@ +{ + "k": 5.453150956868657, + "m": 0.5340933469371478, + "b": 0.24151413401019417, + "g": 9.8, + "R": 1.5116857570922697, + "ax": 0.0, + "ay": 3.0, + "x0": 0.8807649983527113, + "y0": 1.4430664549238743, + "vx0": 0.6141950675744003, + "vy0": 1.2117354548422403 +} \ No newline at end of file diff --git a/scipy/spring_2d/075/simulation_code.py b/scipy/spring_2d/075/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..21808d780b17706414094c359d4b2749409f6858 --- /dev/null +++ b/scipy/spring_2d/075/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=5.453150956868657 N/m, m=0.5340933469371478 kg, b=0.24151413401019417 kg/s, g=9.8 m/s^2 + R=1.5116857570922697 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 5.453150956868657, 0.5340933469371478, 0.24151413401019417, 9.8 +R = 1.5116857570922697 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = 0.880765, 1.443066, 0.614195, 1.211735 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/075/video.mp4 b/scipy/spring_2d/075/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4df187d8e52d50fc98aef715ff716e8c4fc48662 --- /dev/null +++ b/scipy/spring_2d/075/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:512b7aa7b7cbf58d19315d0d9afa5e2d2c9327e59ab4f4718e384ed4148453e9 +size 17265 diff --git a/scipy/spring_2d/087/cot.json b/scipy/spring_2d/087/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..c65df088e00665a9e16f3393adcf8615227602cb --- /dev/null +++ b/scipy/spring_2d/087/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=0.333 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=5.774 N/m, rest length R=1.247 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.012 kg/s. The mass is released from (-0.016, 0.595) with velocity (0.027, 0.922) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = 1.1881." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 4.1638, + "T_nat_s": 1.509, + "damping_ratio_zeta": 0.0042, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": 1.1881 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 4.164 rad/s (period T_0 = 1.509 s).", + "Damping ratio \\zeta = 0.0042: underdamped.", + "Equilibrium position: (0.000, 1.188) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 5.774321522794291, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 0.33306451079385485, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.011515858526508382, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.2466206974620948, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": -0.01577090613829779, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 0.5952198186273574, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 0.026566567802935204, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": 0.9220463241832242, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/087/params.json b/scipy/spring_2d/087/params.json new file mode 100644 index 0000000000000000000000000000000000000000..af069e1595d5917d33db31317f56077ff3a0666a --- /dev/null +++ b/scipy/spring_2d/087/params.json @@ -0,0 +1,13 @@ +{ + "k": 5.774321522794291, + "m": 0.33306451079385485, + "b": 0.011515858526508382, + "g": 9.8, + "R": 1.2466206974620948, + "ax": 0.0, + "ay": 3.0, + "x0": -0.01577090613829779, + "y0": 0.5952198186273574, + "vx0": 0.026566567802935204, + "vy0": 0.9220463241832242 +} \ No newline at end of file diff --git a/scipy/spring_2d/087/simulation_code.py b/scipy/spring_2d/087/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..f3ee6dcfd972c004d68bf599f6b53118b4c3fcd4 --- /dev/null +++ b/scipy/spring_2d/087/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=5.774321522794291 N/m, m=0.33306451079385485 kg, b=0.011515858526508382 kg/s, g=9.8 m/s^2 + R=1.2466206974620948 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 5.774321522794291, 0.33306451079385485, 0.011515858526508382, 9.8 +R = 1.2466206974620948 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = -0.015771, 0.595220, 0.026567, 0.922046 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/087/video.mp4 b/scipy/spring_2d/087/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..d3d6cb33999ac6ea83625b2402ca42350a2e2ff5 --- /dev/null +++ b/scipy/spring_2d/087/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4275f7a3c4cb96efb6262b9f05a883728d50a0eb9b3c67cb35f74bc3e8250d02 +size 18500 diff --git a/scipy/spring_2d/121/cot.json b/scipy/spring_2d/121/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..3afb18018f2cdc3855c87b3e7e02b4d23a045ed4 --- /dev/null +++ b/scipy/spring_2d/121/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=1.078 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=7.240 N/m, rest length R=1.012 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.433 kg/s. The mass is released from (-0.361, 1.159) with velocity (-1.843, 1.361) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = 0.5296." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 2.5918, + "T_nat_s": 2.4243, + "damping_ratio_zeta": 0.0774, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": 0.5296 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 2.592 rad/s (period T_0 = 2.424 s).", + "Damping ratio \\zeta = 0.0774: underdamped.", + "Equilibrium position: (0.000, 0.530) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 7.240449896742383, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 1.0778764117638395, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.4325535727264034, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.0115049113210934, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": -0.36146930833769897, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 1.1591618772429273, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": -1.8425121712781674, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": 1.360823698027692, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/121/params.json b/scipy/spring_2d/121/params.json new file mode 100644 index 0000000000000000000000000000000000000000..113b457d550e0c8b97628dc9b11aab06ad0a10ed --- /dev/null +++ b/scipy/spring_2d/121/params.json @@ -0,0 +1,13 @@ +{ + "k": 7.240449896742383, + "m": 1.0778764117638395, + "b": 0.4325535727264034, + "g": 9.8, + "R": 1.0115049113210934, + "ax": 0.0, + "ay": 3.0, + "x0": -0.36146930833769897, + "y0": 1.1591618772429273, + "vx0": -1.8425121712781674, + "vy0": 1.360823698027692 +} \ No newline at end of file diff --git a/scipy/spring_2d/121/simulation_code.py b/scipy/spring_2d/121/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..2b55ac26d766f7fd4cead6aa9dbe91bb2f8de26f --- /dev/null +++ b/scipy/spring_2d/121/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=7.240449896742383 N/m, m=1.0778764117638395 kg, b=0.4325535727264034 kg/s, g=9.8 m/s^2 + R=1.0115049113210934 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 7.240449896742383, 1.0778764117638395, 0.4325535727264034, 9.8 +R = 1.0115049113210934 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = -0.361469, 1.159162, -1.842512, 1.360824 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/121/video.mp4 b/scipy/spring_2d/121/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e384a73dbaaa56c09633b1e4015832fa3e63be62 --- /dev/null +++ b/scipy/spring_2d/121/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf13b8750722bf2446ca9ed2bb26ee6b38fe5867ffc8dd36d61e7a3257d82649 +size 17625 diff --git a/scipy/spring_2d/152/cot.json b/scipy/spring_2d/152/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..231ad7562213851e5b7410951eae570f47a845f0 --- /dev/null +++ b/scipy/spring_2d/152/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=0.516 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=6.487 N/m, rest length R=1.937 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.226 kg/s. The mass is released from (0.806, 1.117) with velocity (-1.552, 1.545) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = 0.2834." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 3.5456, + "T_nat_s": 1.7721, + "damping_ratio_zeta": 0.0617, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": 0.2834 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 3.546 rad/s (period T_0 = 1.772 s).", + "Damping ratio \\zeta = 0.0617: underdamped.", + "Equilibrium position: (0.000, 0.283) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 6.487199712909698, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 0.5160244096920481, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.22562282618876417, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.9370568742038279, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": 0.8063779794667658, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 1.117050726748349, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": -1.5516372511630947, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": 1.5448901301450642, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/152/params.json b/scipy/spring_2d/152/params.json new file mode 100644 index 0000000000000000000000000000000000000000..de8acf1f5788f8d8ca520b603dbac610b18385ff --- /dev/null +++ b/scipy/spring_2d/152/params.json @@ -0,0 +1,13 @@ +{ + "k": 6.487199712909698, + "m": 0.5160244096920481, + "b": 0.22562282618876417, + "g": 9.8, + "R": 1.9370568742038279, + "ax": 0.0, + "ay": 3.0, + "x0": 0.8063779794667658, + "y0": 1.117050726748349, + "vx0": -1.5516372511630947, + "vy0": 1.5448901301450642 +} \ No newline at end of file diff --git a/scipy/spring_2d/152/simulation_code.py b/scipy/spring_2d/152/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..a1eb3485e12d4ffd6d7ade20e21ce24a97240179 --- /dev/null +++ b/scipy/spring_2d/152/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=6.487199712909698 N/m, m=0.5160244096920481 kg, b=0.22562282618876417 kg/s, g=9.8 m/s^2 + R=1.9370568742038279 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 6.487199712909698, 0.5160244096920481, 0.22562282618876417, 9.8 +R = 1.9370568742038279 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = 0.806378, 1.117051, -1.551637, 1.544890 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/152/video.mp4 b/scipy/spring_2d/152/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a1f0bf89c4c30d8e25c9aed7904e01589b1cd700 --- /dev/null +++ b/scipy/spring_2d/152/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f364aeba6d7b18555a1076e2ed5b4b99dc507928a86b46bf01206ec6ef739bd5 +size 17279 diff --git a/scipy/spring_2d/155/cot.json b/scipy/spring_2d/155/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..6136709c07fe97321eb6150b0dbb3598a7c15ff8 --- /dev/null +++ b/scipy/spring_2d/155/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=1.529 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=7.442 N/m, rest length R=1.239 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.162 kg/s. The mass is released from (-1.447, 1.378) with velocity (0.842, -0.833) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = -0.2527." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 2.2062, + "T_nat_s": 2.848, + "damping_ratio_zeta": 0.024, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": -0.2527 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 2.206 rad/s (period T_0 = 2.848 s).", + "Damping ratio \\zeta = 0.0240: underdamped.", + "Equilibrium position: (0.000, -0.253) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 7.441862240491609, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 1.5289380156548065, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.1619974203349358, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.2393131923159157, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": -1.4468543819638913, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 1.3778657829439886, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 0.8424147060432006, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": -0.8327597821324297, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/155/params.json b/scipy/spring_2d/155/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5baab61815370edf11475835a3906cf4ab931407 --- /dev/null +++ b/scipy/spring_2d/155/params.json @@ -0,0 +1,13 @@ +{ + "k": 7.441862240491609, + "m": 1.5289380156548065, + "b": 0.1619974203349358, + "g": 9.8, + "R": 1.2393131923159157, + "ax": 0.0, + "ay": 3.0, + "x0": -1.4468543819638913, + "y0": 1.3778657829439886, + "vx0": 0.8424147060432006, + "vy0": -0.8327597821324297 +} \ No newline at end of file diff --git a/scipy/spring_2d/155/simulation_code.py b/scipy/spring_2d/155/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..c01902169b79a3fe2a4b74f745532a39d446dd95 --- /dev/null +++ b/scipy/spring_2d/155/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=7.441862240491609 N/m, m=1.5289380156548065 kg, b=0.1619974203349358 kg/s, g=9.8 m/s^2 + R=1.2393131923159157 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 7.441862240491609, 1.5289380156548065, 0.1619974203349358, 9.8 +R = 1.2393131923159157 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = -1.446854, 1.377866, 0.842415, -0.832760 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/155/video.mp4 b/scipy/spring_2d/155/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..7d37b7ec961aebbe25e5f6ddd994ab7205eb0206 --- /dev/null +++ b/scipy/spring_2d/155/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c35b72a061ab830bfe43d742b7a19a1974fcd4247e67d80339ea77e9618e7f99 +size 19142 diff --git a/scipy/spring_2d/254/cot.json b/scipy/spring_2d/254/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..b8c2297d8cf3982d65c8b18fd275d50776100a74 --- /dev/null +++ b/scipy/spring_2d/254/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=0.637 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=1.258 N/m, rest length R=1.866 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.774 kg/s. The mass is released from (-0.707, 1.262) with velocity (1.603, -0.652) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = -3.8248." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 1.4057, + "T_nat_s": 4.4697, + "damping_ratio_zeta": 0.4324, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": -3.8248 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 1.406 rad/s (period T_0 = 4.470 s).", + "Damping ratio \\zeta = 0.4324: underdamped.", + "Equilibrium position: (0.000, -3.825) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 1.2583915480954313, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 0.6368047722894175, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.7741168731438653, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.865500292220033, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": -0.7070442539008163, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 1.2623160696107805, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 1.603076034927739, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": -0.6523372569330319, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/254/params.json b/scipy/spring_2d/254/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5e8a36024be12abc749bcf70891cd3f8a06ced02 --- /dev/null +++ b/scipy/spring_2d/254/params.json @@ -0,0 +1,13 @@ +{ + "k": 1.2583915480954313, + "m": 0.6368047722894175, + "b": 0.7741168731438653, + "g": 9.8, + "R": 1.865500292220033, + "ax": 0.0, + "ay": 3.0, + "x0": -0.7070442539008163, + "y0": 1.2623160696107805, + "vx0": 1.603076034927739, + "vy0": -0.6523372569330319 +} \ No newline at end of file diff --git a/scipy/spring_2d/254/simulation_code.py b/scipy/spring_2d/254/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..2e651a0539bfa5cbb5e1eac6db9ef9b8e6f1f1f9 --- /dev/null +++ b/scipy/spring_2d/254/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=1.2583915480954313 N/m, m=0.6368047722894175 kg, b=0.7741168731438653 kg/s, g=9.8 m/s^2 + R=1.865500292220033 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 1.2583915480954313, 0.6368047722894175, 0.7741168731438653, 9.8 +R = 1.865500292220033 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = -0.707044, 1.262316, 1.603076, -0.652337 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/254/video.mp4 b/scipy/spring_2d/254/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ddead784e366fa5adc42eb6e22e9442d5b41a80b --- /dev/null +++ b/scipy/spring_2d/254/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:992e2c99fabd8539c07281d0a58f1250ddfa2586d10aae45c3a5d04f6054caaf +size 11438 diff --git a/scipy/spring_2d/311/cot.json b/scipy/spring_2d/311/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..988df4d9a0d0f20be2daa0351b0f6601cacdf9e1 --- /dev/null +++ b/scipy/spring_2d/311/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=1.155 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=5.284 N/m, rest length R=0.566 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.186 kg/s. The mass is released from (0.969, 0.684) with velocity (1.541, -1.145) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = 0.2909." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 2.1387, + "T_nat_s": 2.9379, + "damping_ratio_zeta": 0.0377, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": 0.2909 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 2.139 rad/s (period T_0 = 2.938 s).", + "Damping ratio \\zeta = 0.0377: underdamped.", + "Equilibrium position: (0.000, 0.291) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 5.284383649110211, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 1.1553238612326964, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.1861878842286272, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 0.5664785753105659, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": 0.9689172799676902, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 0.6844954695961176, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 1.5413329619933416, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": -1.1447431577670257, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/311/params.json b/scipy/spring_2d/311/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b6c5b437c1b781a79e27f40d81359d5f45ae0c69 --- /dev/null +++ b/scipy/spring_2d/311/params.json @@ -0,0 +1,13 @@ +{ + "k": 5.284383649110211, + "m": 1.1553238612326964, + "b": 0.1861878842286272, + "g": 9.8, + "R": 0.5664785753105659, + "ax": 0.0, + "ay": 3.0, + "x0": 0.9689172799676902, + "y0": 0.6844954695961176, + "vx0": 1.5413329619933416, + "vy0": -1.1447431577670257 +} \ No newline at end of file diff --git a/scipy/spring_2d/311/simulation_code.py b/scipy/spring_2d/311/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..0d655ac53d938fd784e82f2b0d2abbafafb69d34 --- /dev/null +++ b/scipy/spring_2d/311/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=5.284383649110211 N/m, m=1.1553238612326964 kg, b=0.1861878842286272 kg/s, g=9.8 m/s^2 + R=0.5664785753105659 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 5.284383649110211, 1.1553238612326964, 0.1861878842286272, 9.8 +R = 0.5664785753105659 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = 0.968917, 0.684495, 1.541333, -1.144743 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/311/video.mp4 b/scipy/spring_2d/311/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b6ad632332e636f7f5e6cd919428512ab588e26c --- /dev/null +++ b/scipy/spring_2d/311/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:868353eaa561e22285896a599cfa2029ec17fd8eb3b56ac865c32cbff48e809e +size 19624 diff --git a/scipy/spring_2d/410/cot.json b/scipy/spring_2d/410/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5f322c8582b0af153168742dd51b54c3a9ca5bc1 --- /dev/null +++ b/scipy/spring_2d/410/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=1.949 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=5.142 N/m, rest length R=2.496 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.976 kg/s. The mass is released from (-1.164, 0.504) with velocity (1.295, 1.153) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = -3.2111." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 1.6241, + "T_nat_s": 3.8687, + "damping_ratio_zeta": 0.1541, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": -3.2111 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 1.624 rad/s (period T_0 = 3.869 s).", + "Damping ratio \\zeta = 0.1541: underdamped.", + "Equilibrium position: (0.000, -3.211) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 5.142081977077394, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 1.9494554662058996, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.9758496481888492, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 2.495705766400617, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": -1.1635062166632264, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 0.5042032036107773, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 1.2951515649409364, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": 1.153040488536051, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/410/params.json b/scipy/spring_2d/410/params.json new file mode 100644 index 0000000000000000000000000000000000000000..e63522c84a37ef74793c3ce50907268a7da0e915 --- /dev/null +++ b/scipy/spring_2d/410/params.json @@ -0,0 +1,13 @@ +{ + "k": 5.142081977077394, + "m": 1.9494554662058996, + "b": 0.9758496481888492, + "g": 9.8, + "R": 2.495705766400617, + "ax": 0.0, + "ay": 3.0, + "x0": -1.1635062166632264, + "y0": 0.5042032036107773, + "vx0": 1.2951515649409364, + "vy0": 1.153040488536051 +} \ No newline at end of file diff --git a/scipy/spring_2d/410/simulation_code.py b/scipy/spring_2d/410/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..dbe1df75a1e0e4c9ca2dc217278d6b62819e5891 --- /dev/null +++ b/scipy/spring_2d/410/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=5.142081977077394 N/m, m=1.9494554662058996 kg, b=0.9758496481888492 kg/s, g=9.8 m/s^2 + R=2.495705766400617 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 5.142081977077394, 1.9494554662058996, 0.9758496481888492, 9.8 +R = 2.495705766400617 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = -1.163506, 0.504203, 1.295152, 1.153040 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/410/video.mp4 b/scipy/spring_2d/410/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3d58613ee19977d81cc3cd454cbe460e4cd1dbef --- /dev/null +++ b/scipy/spring_2d/410/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:366a72965001cb355abdf3d870c0868976f94ef160fd736f7cf758d537a0eddf +size 13990 diff --git a/scipy/spring_2d/503/cot.json b/scipy/spring_2d/503/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..2c1fd978a9b29fda7f5aae03487000d73f3603b5 --- /dev/null +++ b/scipy/spring_2d/503/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=1.606 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=5.553 N/m, rest length R=1.256 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.201 kg/s. The mass is released from (0.298, 1.351) with velocity (0.997, -1.712) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = -1.0897." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 1.8597, + "T_nat_s": 3.3786, + "damping_ratio_zeta": 0.0336, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": -1.0897 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 1.860 rad/s (period T_0 = 3.379 s).", + "Damping ratio \\zeta = 0.0336: underdamped.", + "Equilibrium position: (0.000, -1.090) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 5.553272284872766, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 1.6056628416335579, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.20055542284686467, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.2561477410229183, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": 0.29844174112272626, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 1.3510232086670222, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 0.996677371990053, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": -1.7116919598070708, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/503/params.json b/scipy/spring_2d/503/params.json new file mode 100644 index 0000000000000000000000000000000000000000..05ae6ffabe1979961fa3bf314c6da6231e7bb9b7 --- /dev/null +++ b/scipy/spring_2d/503/params.json @@ -0,0 +1,13 @@ +{ + "k": 5.553272284872766, + "m": 1.6056628416335579, + "b": 0.20055542284686467, + "g": 9.8, + "R": 1.2561477410229183, + "ax": 0.0, + "ay": 3.0, + "x0": 0.29844174112272626, + "y0": 1.3510232086670222, + "vx0": 0.996677371990053, + "vy0": -1.7116919598070708 +} \ No newline at end of file diff --git a/scipy/spring_2d/503/simulation_code.py b/scipy/spring_2d/503/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..bf690a070c3aff3a657df35ec4e4b3512140ba15 --- /dev/null +++ b/scipy/spring_2d/503/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=5.553272284872766 N/m, m=1.6056628416335579 kg, b=0.20055542284686467 kg/s, g=9.8 m/s^2 + R=1.2561477410229183 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 5.553272284872766, 1.6056628416335579, 0.20055542284686467, 9.8 +R = 1.2561477410229183 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = 0.298442, 1.351023, 0.996677, -1.711692 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/503/video.mp4 b/scipy/spring_2d/503/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..cd02eccdbb8c884e7234496833dfd1d53e0837d9 --- /dev/null +++ b/scipy/spring_2d/503/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ce62967bc09ae0825f8d15608b66de971be890456aa3a2534d4075f1d728504 +size 16565 diff --git a/scipy/spring_2d/571/cot.json b/scipy/spring_2d/571/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..086e0433b4f4dbf6dee7697668a0db8582c43162 --- /dev/null +++ b/scipy/spring_2d/571/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=1.849 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=2.672 N/m, rest length R=1.905 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.351 kg/s. The mass is released from (1.174, 1.904) with velocity (1.047, 1.669) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = -5.6861." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 1.2022, + "T_nat_s": 5.2264, + "damping_ratio_zeta": 0.0789, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": -5.6861 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 1.202 rad/s (period T_0 = 5.226 s).", + "Damping ratio \\zeta = 0.0789: underdamped.", + "Equilibrium position: (0.000, -5.686) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 2.6717202775274913, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 1.8485945030198232, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.3508484660996676, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.90536210607134, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": 1.1736380538143294, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 1.9036896951820053, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 1.0467396917061995, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": 1.668946323412201, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/571/params.json b/scipy/spring_2d/571/params.json new file mode 100644 index 0000000000000000000000000000000000000000..fcc5fe9f6fc88eb9651f05add4284cf42ffcd4ac --- /dev/null +++ b/scipy/spring_2d/571/params.json @@ -0,0 +1,13 @@ +{ + "k": 2.6717202775274913, + "m": 1.8485945030198232, + "b": 0.3508484660996676, + "g": 9.8, + "R": 1.90536210607134, + "ax": 0.0, + "ay": 3.0, + "x0": 1.1736380538143294, + "y0": 1.9036896951820053, + "vx0": 1.0467396917061995, + "vy0": 1.668946323412201 +} \ No newline at end of file diff --git a/scipy/spring_2d/571/simulation_code.py b/scipy/spring_2d/571/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d2567577694ee334f4a9386e798790f7e1e3ce19 --- /dev/null +++ b/scipy/spring_2d/571/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=2.6717202775274913 N/m, m=1.8485945030198232 kg, b=0.3508484660996676 kg/s, g=9.8 m/s^2 + R=1.90536210607134 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 2.6717202775274913, 1.8485945030198232, 0.3508484660996676, 9.8 +R = 1.90536210607134 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = 1.173638, 1.903690, 1.046740, 1.668946 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/571/video.mp4 b/scipy/spring_2d/571/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e5c2d475420912ab2b9d1136f05c72cec7c7ea94 --- /dev/null +++ b/scipy/spring_2d/571/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a91025fe55f9c3c5415b7442121aa11210056aae7537b91c459c18a5b09bd92e +size 13413 diff --git a/scipy/spring_2d/576/cot.json b/scipy/spring_2d/576/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..38129afcfd35ef498ba0d019e7ef96039b96b980 --- /dev/null +++ b/scipy/spring_2d/576/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=1.010 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=6.736 N/m, rest length R=1.901 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.119 kg/s. The mass is released from (0.602, 0.778) with velocity (-0.978, -0.261) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = -0.3710." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 2.5822, + "T_nat_s": 2.4333, + "damping_ratio_zeta": 0.0228, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": -0.371 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 2.582 rad/s (period T_0 = 2.433 s).", + "Damping ratio \\zeta = 0.0228: underdamped.", + "Equilibrium position: (0.000, -0.371) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 6.7359176428572765, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 1.0102087981728423, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.11871957136295297, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.9012731420105258, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": 0.6022966779577441, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 0.7777700496842355, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": -0.9781084088632306, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": -0.26075396292629094, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/576/params.json b/scipy/spring_2d/576/params.json new file mode 100644 index 0000000000000000000000000000000000000000..dc481296b78d35b538e5d66073004127b0f704dd --- /dev/null +++ b/scipy/spring_2d/576/params.json @@ -0,0 +1,13 @@ +{ + "k": 6.7359176428572765, + "m": 1.0102087981728423, + "b": 0.11871957136295297, + "g": 9.8, + "R": 1.9012731420105258, + "ax": 0.0, + "ay": 3.0, + "x0": 0.6022966779577441, + "y0": 0.7777700496842355, + "vx0": -0.9781084088632306, + "vy0": -0.26075396292629094 +} \ No newline at end of file diff --git a/scipy/spring_2d/576/simulation_code.py b/scipy/spring_2d/576/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..1f8799e8791e91249a21fd1054989063cda6fcd8 --- /dev/null +++ b/scipy/spring_2d/576/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=6.7359176428572765 N/m, m=1.0102087981728423 kg, b=0.11871957136295297 kg/s, g=9.8 m/s^2 + R=1.9012731420105258 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 6.7359176428572765, 1.0102087981728423, 0.11871957136295297, 9.8 +R = 1.9012731420105258 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = 0.602297, 0.777770, -0.978108, -0.260754 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/576/video.mp4 b/scipy/spring_2d/576/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b114c362ef726c77cf6ab061949018eefd46ea6a --- /dev/null +++ b/scipy/spring_2d/576/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1832c8bc5a8c06af7340e7fbe70f63ea24a5edd5ecddc9094908178ea43cffd1 +size 17583 diff --git a/scipy/spring_2d/590/cot.json b/scipy/spring_2d/590/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..3295c9de4e4379b8c694cc65ee6ddbed300cb93f --- /dev/null +++ b/scipy/spring_2d/590/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=0.251 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=6.253 N/m, rest length R=0.854 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.830 kg/s. The mass is released from (-0.296, 0.853) with velocity (-0.033, 1.343) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = 1.7521." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 4.9887, + "T_nat_s": 1.2595, + "damping_ratio_zeta": 0.331, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": 1.7521 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 4.989 rad/s (period T_0 = 1.259 s).", + "Damping ratio \\zeta = 0.3310: underdamped.", + "Equilibrium position: (0.000, 1.752) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 6.25283433423017, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 0.25124598887370614, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.8297017814695445, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 0.8541474912512552, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": -0.2958990301148452, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 0.8527734308002315, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": -0.03304472958405702, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": 1.3431061172306547, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/590/params.json b/scipy/spring_2d/590/params.json new file mode 100644 index 0000000000000000000000000000000000000000..7264484f88cc93389619a3e09b0ffe9440198649 --- /dev/null +++ b/scipy/spring_2d/590/params.json @@ -0,0 +1,13 @@ +{ + "k": 6.25283433423017, + "m": 0.25124598887370614, + "b": 0.8297017814695445, + "g": 9.8, + "R": 0.8541474912512552, + "ax": 0.0, + "ay": 3.0, + "x0": -0.2958990301148452, + "y0": 0.8527734308002315, + "vx0": -0.03304472958405702, + "vy0": 1.3431061172306547 +} \ No newline at end of file diff --git a/scipy/spring_2d/590/simulation_code.py b/scipy/spring_2d/590/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..3f2c48767e2a6f3e19f1800fa7a0922dde832163 --- /dev/null +++ b/scipy/spring_2d/590/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=6.25283433423017 N/m, m=0.25124598887370614 kg, b=0.8297017814695445 kg/s, g=9.8 m/s^2 + R=0.8541474912512552 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 6.25283433423017, 0.25124598887370614, 0.8297017814695445, 9.8 +R = 0.8541474912512552 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = -0.295899, 0.852773, -0.033045, 1.343106 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/590/video.mp4 b/scipy/spring_2d/590/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..62bfd3becc15d939b5e8d23bddd113f182097154 --- /dev/null +++ b/scipy/spring_2d/590/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51140130316c802a3a3c4e6cb3073916c0eeed353295453303ea281bfa46db63 +size 7559 diff --git a/scipy/spring_2d/644/cot.json b/scipy/spring_2d/644/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..c4675bfb86d7eaf8c17a507e06997731f28f1815 --- /dev/null +++ b/scipy/spring_2d/644/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=1.061 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=2.218 N/m, rest length R=1.776 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.176 kg/s. The mass is released from (0.374, 2.096) with velocity (0.682, -0.105) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = -3.4623." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 1.4461, + "T_nat_s": 4.3449, + "damping_ratio_zeta": 0.0573, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": -3.4623 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 1.446 rad/s (period T_0 = 4.345 s).", + "Damping ratio \\zeta = 0.0573: underdamped.", + "Equilibrium position: (0.000, -3.462) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 2.218433449414859, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 1.0608104699465473, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.17579570207347228, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 1.7760922267099315, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": 0.3736498754952646, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 2.096424294331812, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 0.6820057132146498, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": -0.1053246591662722, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/644/params.json b/scipy/spring_2d/644/params.json new file mode 100644 index 0000000000000000000000000000000000000000..44a3e464a63918b7ac9a32af1075e0533837f07b --- /dev/null +++ b/scipy/spring_2d/644/params.json @@ -0,0 +1,13 @@ +{ + "k": 2.218433449414859, + "m": 1.0608104699465473, + "b": 0.17579570207347228, + "g": 9.8, + "R": 1.7760922267099315, + "ax": 0.0, + "ay": 3.0, + "x0": 0.3736498754952646, + "y0": 2.096424294331812, + "vx0": 0.6820057132146498, + "vy0": -0.1053246591662722 +} \ No newline at end of file diff --git a/scipy/spring_2d/644/simulation_code.py b/scipy/spring_2d/644/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..281c756cfecda7c8e7732e64f926aff5c383a5fd --- /dev/null +++ b/scipy/spring_2d/644/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=2.218433449414859 N/m, m=1.0608104699465473 kg, b=0.17579570207347228 kg/s, g=9.8 m/s^2 + R=1.7760922267099315 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 2.218433449414859, 1.0608104699465473, 0.17579570207347228, 9.8 +R = 1.7760922267099315 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = 0.373650, 2.096424, 0.682006, -0.105325 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/644/video.mp4 b/scipy/spring_2d/644/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..127ae883039d746ed23ff82c12c2deac755d5690 --- /dev/null +++ b/scipy/spring_2d/644/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f00105873867e5d914e9e4ff156d97e136f89eeb420ec8f50fee38b338f05aff +size 14066 diff --git a/scipy/spring_2d/702/cot.json b/scipy/spring_2d/702/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..193fb42bd2b2dc2256829ed1408e4b14f0d89224 --- /dev/null +++ b/scipy/spring_2d/702/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "spring_2d", + "physical_observation": "A mass (m=0.732 kg) hangs in 2D from an anchor at (0.00, 3.00) via a spring (k=5.834 N/m, rest length R=0.557 m). Gravity acts downward (g=9.800 m/s^2). Damping coefficient b=0.120 kg/s. The mass is released from (-0.384, 2.324) with velocity (1.112, 1.688) m/s.", + "physical_law": { + "name": "Hooke's Law in 2D + Newton's 2nd Law", + "statement": "The spring exerts a force along the displacement vector from anchor to mass, proportional to the stretch beyond rest length R.", + "formula": "F_spring = -k \\cdot (|r - r_anchor| - R) \\cdot (r - r_anchor)/|r - r_anchor|" + }, + "ode_system": { + "state_variables": [ + "x (m)", + "y (m)", + "vx (m/s)", + "vy (m/s)" + ], + "equations_latex": [ + "\\dot{x} = vx", + "\\dot{y} = vy", + "\\dot{v}_x = -(k/m) \\cdot (dist-R)/dist \\cdot (x-ax) - (b/m) \\cdot vx", + "\\dot{v}_y = -(k/m) \\cdot (dist-R)/dist \\cdot (y-ay) - (b/m) \\cdot vy - g", + "where dist = \\sqrt((x-ax)^2+(y-ay)^2)" + ], + "equations_python": [ + "x_dot = vx", + "y_dot = vy", + "v_dot_x = -(k/m) * (dist-R)/dist * (x-ax) - (b/m) * vx", + "v_dot_y = -(k/m) * (dist-R)/dist * (y-ay) - (b/m) * vy - g", + "where dist = np.sqrt ((x-ax)**2+(y-ay)**2)" + ] + }, + "derivation_steps": [ + "Let r = (x, y) be the mass position; r_anchor = (ax, ay).", + "Displacement vector from anchor to mass: \\Deltar = r - r_anchor.", + "Current spring length: dist = |\\Deltar| = \\sqrt((x-ax)^2+(y-ay)^2).", + "Spring stretch: s = dist - R.", + "Spring force (Hooke's Law in vector form): F_s = -k \\cdot s \\cdot (\\Deltar/dist).", + "Gravity force: F_g = (0, -m \\cdot g).", + "Viscous damping: F_d = -b \\cdot v.", + "Newton's 2nd: m \\cdot \\ddot{r} = F_s + F_g + F_d.", + "Component form: m \\cdot \\ddot{x} = -k \\cdot s \\cdot (x-ax)/dist - b \\cdot vx", + " m \\cdot \\ddot{y} = -k \\cdot s \\cdot (y-ay)/dist - b \\cdot vy - m \\cdot g.", + "Equilibrium (spring stretched by mg/k below anchor): x_eq = 0.0000, y_eq = 1.2133." + ], + "physical_constants_derived": { + "omega0_nat_rad_s": 2.823, + "T_nat_s": 2.2257, + "damping_ratio_zeta": 0.029, + "equilibrium_x_m": 0.0, + "equilibrium_y_m": 1.2133 + }, + "numerical_method": { + "solver": "RK45 (Dormand-Prince, 4th/5th order Runge-Kutta)", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "2D spring has nonlinear geometry; adaptive RK45 handles arbitrary trajectories." + }, + "code_validation": { + "ode_source": "Hooke's Law vector form; matches Spring2DSim.ts evaluate()", + "energy_check": "E = \\tfrac{1}{2} m(vx^2+vy^2) + \\tfrac{1}{2} k(dist-R)^2 + m \\cdot g \\cdot y decreases when b>0", + "physical_plausibility": true + }, + "expected_behavior": [ + "Natural frequency \\omega_0 = 2.823 rad/s (period T_0 = 2.226 s).", + "Damping ratio \\zeta = 0.0290: underdamped.", + "Equilibrium position: (0.000, 1.213) m.", + "Elliptical or complex Lissajous-like trajectories in 2D due to combined spring and gravity." + ], + "parameters": { + "k": { + "value": 5.833775029518882, + "unit": "N/m", + "description": "Spring stiffness" + }, + "m": { + "value": 0.7320474812223765, + "unit": "kg", + "description": "Mass" + }, + "b": { + "value": 0.11969575076040295, + "unit": "kg/s", + "description": "Damping coefficient" + }, + "g": { + "value": 9.8, + "unit": "m/s^2", + "description": "Gravitational acceleration" + }, + "R": { + "value": 0.556936180512472, + "unit": "m", + "description": "Spring rest length" + }, + "ax": { + "value": 0.0, + "unit": "m", + "description": "Anchor x-coordinate" + }, + "ay": { + "value": 3.0, + "unit": "m", + "description": "Anchor y-coordinate" + }, + "x0": { + "value": -0.3836238606459976, + "unit": "m", + "description": "Horizontal position" + }, + "y0": { + "value": 2.3243040557048436, + "unit": "m", + "description": "Vertical position" + }, + "vx0": { + "value": 1.111834279311649, + "unit": "m/s", + "description": "Horizontal velocity" + }, + "vy0": { + "value": 1.6878245119010855, + "unit": "m/s", + "description": "Vertical velocity" + } + } +} diff --git a/scipy/spring_2d/702/params.json b/scipy/spring_2d/702/params.json new file mode 100644 index 0000000000000000000000000000000000000000..f3d7c14e54e864b4d48db62c59e072e1b07077f3 --- /dev/null +++ b/scipy/spring_2d/702/params.json @@ -0,0 +1,13 @@ +{ + "k": 5.833775029518882, + "m": 0.7320474812223765, + "b": 0.11969575076040295, + "g": 9.8, + "R": 0.556936180512472, + "ax": 0.0, + "ay": 3.0, + "x0": -0.3836238606459976, + "y0": 2.3243040557048436, + "vx0": 1.111834279311649, + "vy0": 1.6878245119010855 +} \ No newline at end of file diff --git a/scipy/spring_2d/702/simulation_code.py b/scipy/spring_2d/702/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..6b3977d9ea086582cd9bd40a60c2da46e277aaba --- /dev/null +++ b/scipy/spring_2d/702/simulation_code.py @@ -0,0 +1,74 @@ +""" +2D Spring — auto-generated simulation script. +Physics (Spring2DSim.ts): + Vx' = -(k/m)*L*sin(th) - (b/m)*Vx + Vy' = -g + (k/m)*L*cos(th) - (b/m)*Vy + where L = dist - R, sin(th) = xx/dist, cos(th) = -yy/dist +Parameters: k=5.833775029518882 N/m, m=0.7320474812223765 kg, b=0.11969575076040295 kg/s, g=9.8 m/s^2 + R=0.556936180512472 m (rest length), anchor=(0.0,3.0) +""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +k, m, b, g = 5.833775029518882, 0.7320474812223765, 0.11969575076040295, 9.8 +R = 0.556936180512472 +ax_pt, ay_pt = 0.0, 3.0 +x0, y0, vx0, vy0 = -0.383624, 2.324304, 1.111834, 1.687825 +duration = 12 + +def ode(t, y): + x, yp, vx, vy = y + xx, yy = x - ax_pt, yp - ay_pt + dist = np.hypot(xx, yy) + if dist < 1e-10: + return [vx, vy, 0.0, -g] + stretch = dist - R + Fx = -k * stretch * xx / dist + Fy = k * stretch * (-yy) / dist + return [vx, vy, + (Fx - b*vx) / m, + -g + (Fy - b*vy) / m] + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [x0, y0, vx0, vy0], + t_eval=t_eval, method="RK45", rtol=1e-8, atol=1e-10) +x_arr, y_arr = sol.y[0], sol.y[1] + +all_x = np.concatenate([[ax_pt], x_arr]) +all_y = np.concatenate([[ay_pt], y_arr]) +mg = 1.5 +xlim = (all_x.min()-mg, all_x.max()+mg) +ylim = (all_y.min()-mg, all_y.max()+mg) + +fig, ax2 = plt.subplots(figsize=(8,6),facecolor="#1a1a2e") +ax2.set_facecolor("#16213e"); ax2.set_xlim(xlim); ax2.set_ylim(ylim) +ax2.set_aspect("equal"); ax2.axis("off") + +anch_sz = 0.2 +ax2.add_patch(patches.Rectangle((ax_pt-anch_sz/2, ay_pt-anch_sz/2), anch_sz, anch_sz, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=4)) +sp, = ax2.plot([],[],"-",color="#a8dadc",lw=2.5,zorder=3) +bob = plt.Circle((x0,y0),0.18,facecolor="#e63946",edgecolor="white",lw=1.5,zorder=5) +ax2.add_patch(bob) + +def spring_path_fn(x1,y1,x2,y2,n=8,r=0.12): + dx,dy = x2-x1, y2-y1 + L = np.hypot(dx,dy) + if L < 1e-10: return np.array([x1,x2]), np.array([y1,y2]) + ux,uy = dx/L, dy/L; nx,ny = -uy, ux + n_pts = n*20+2; t = np.linspace(0,1,n_pts); mg2=0.08 + env = np.where((t1-mg2),0,np.sin(n*2*np.pi*(t-mg2)/(1-2*mg2))) + return x1+t*dx+r*env*nx, y1+t*dy+r*env*ny + +def update(f): + bx,by = x_arr[f],y_arr[f]; bob.set_center((bx,by)) + sx,sy=spring_path_fn(ax_pt,ay_pt,bx,by); sp.set_data(sx,sy) + return (sp, bob) + +ani=animation.FuncAnimation(fig,update,frames=len(sol.t),interval=1000/fps,blit=False) +ani.save("spring_2d.mp4",writer=animation.FFMpegWriter(fps=fps,bitrate=1800),dpi=100) +plt.close(); print("Saved spring_2d.mp4") diff --git a/scipy/spring_2d/702/video.mp4 b/scipy/spring_2d/702/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ea94a16411c314824e8f1e9374feb711950703a8 --- /dev/null +++ b/scipy/spring_2d/702/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7908ac29d934cbe8837a5122ef2211286c2f6baf629602e72524713cfb71f8af +size 18248 diff --git a/scipy/spring_atwood/115/cot.json b/scipy/spring_atwood/115/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..3c06856f33ae6c8979da8a1ee0f5776769079f9a --- /dev/null +++ b/scipy/spring_atwood/115/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=28.008 N/m, natural length L_0=0.613 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=0.941 kg and m_3=1.249 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.1407 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.6124 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 10.5171 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.7510 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.6124 rad/s, period 1.7393 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 10.517085248029169, + "T_A_equilibrium_N": 21.034170496058337, + "spring_extension_equilibrium_m": 0.7509950049663346, + "L_s_equilibrium_m": 1.3641985815420559, + "y_se_equilibrium_m": 3.135801418457944, + "oscillation_omega_rad_s": 3.6123890206764866, + "oscillation_period_s": 1.7393434846623865, + "mass_asymmetry": 0.14068419253162173 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.6124 rad/s (period 1.7393 s).", + "Mass asymmetry 0.1407 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.9408142684109816, + "unit": "", + "description": "" + }, + "m_3": { + "value": 1.2488679420971787, + "unit": "", + "description": "" + }, + "k": { + "value": 28.00840266174773, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6132035765757212, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/115/params.json b/scipy/spring_atwood/115/params.json new file mode 100644 index 0000000000000000000000000000000000000000..58c2dc40c2172696996b3d48d350db429aebeabc --- /dev/null +++ b/scipy/spring_atwood/115/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 0.9408142684109816, + "m_3": 1.2488679420971787, + "k": 28.00840266174773, + "L_0": 0.6132035765757212, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/115/simulation_code.py b/scipy/spring_atwood/115/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..2094b2d82211c51f015b691209df60cd88092410 --- /dev/null +++ b/scipy/spring_atwood/115/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 0.9408142684109816 +m_3 = 1.2488679420971787 +k = 28.00840266174773 +L_0 = 0.6132035765757212 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/115/video.mp4 b/scipy/spring_atwood/115/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..bf0aa3a8d99d3b90b7cca43170989185a90e7ef3 --- /dev/null +++ b/scipy/spring_atwood/115/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbd3adcce141dcc4161e6a0b418b52c63562b6491148ce26b1c8124aa5a70a1b +size 9879 diff --git a/scipy/spring_atwood/152/cot.json b/scipy/spring_atwood/152/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..480b04f296021fb484902c64fbf6493b50accf37 --- /dev/null +++ b/scipy/spring_atwood/152/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=30.032 N/m, natural length L_0=0.942 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=1.002 kg and m_3=1.173 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0783 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.7272 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 10.5928 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.7054 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.7272 rad/s, period 1.6858 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 10.592787076075993, + "T_A_equilibrium_N": 21.185574152151986, + "spring_extension_equilibrium_m": 0.7054312998788226, + "L_s_equilibrium_m": 1.6476518800871858, + "y_se_equilibrium_m": 2.852348119912814, + "oscillation_omega_rad_s": 3.727225555605473, + "oscillation_period_s": 1.6857539779770339, + "mass_asymmetry": 0.07829682130051813 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.7272 rad/s (period 1.6858 s).", + "Mass asymmetry 0.0783 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 1.002411042176925, + "unit": "", + "description": "" + }, + "m_3": { + "value": 1.1727166243920923, + "unit": "", + "description": "" + }, + "k": { + "value": 30.0320869740132, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.9422205802083632, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/152/params.json b/scipy/spring_atwood/152/params.json new file mode 100644 index 0000000000000000000000000000000000000000..dd3f46b6adf1980ff062663cb76e9999416854b7 --- /dev/null +++ b/scipy/spring_atwood/152/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 1.002411042176925, + "m_3": 1.1727166243920923, + "k": 30.0320869740132, + "L_0": 0.9422205802083632, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/152/simulation_code.py b/scipy/spring_atwood/152/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..7fd034ffc4fa58ba4a5bc380dc0793874f27f119 --- /dev/null +++ b/scipy/spring_atwood/152/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 1.002411042176925 +m_3 = 1.1727166243920923 +k = 30.0320869740132 +L_0 = 0.9422205802083632 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/152/video.mp4 b/scipy/spring_atwood/152/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..fcb5ee4a5e84f227c407eef2a03c60023bb1cc69 --- /dev/null +++ b/scipy/spring_atwood/152/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5c033509db6bf06640cde363d0793d7c2969b9fa1146734d5a50c15eee90ca4 +size 10680 diff --git a/scipy/spring_atwood/156/cot.json b/scipy/spring_atwood/156/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..50ad46b0495955f74ddd35e5dbf87384221f6caf --- /dev/null +++ b/scipy/spring_atwood/156/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=28.542 N/m, natural length L_0=0.685 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=0.872 kg and m_3=0.972 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0543 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.9409 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 9.0051 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.6310 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.9409 rad/s, period 1.5943 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 9.00507574847834, + "T_A_equilibrium_N": 18.01015149695668, + "spring_extension_equilibrium_m": 0.6310031229352843, + "L_s_equilibrium_m": 1.316451610733611, + "y_se_equilibrium_m": 3.183548389266389, + "oscillation_omega_rad_s": 3.9409169571469578, + "oscillation_period_s": 1.594346030505632, + "mass_asymmetry": 0.054340591299112014 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.9409 rad/s (period 1.5943 s).", + "Mass asymmetry 0.0543 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.8715260401050894, + "unit": "", + "description": "" + }, + "m_3": { + "value": 0.9716873453617981, + "unit": "", + "description": "" + }, + "k": { + "value": 28.542095660600722, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6854484877983268, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/156/params.json b/scipy/spring_atwood/156/params.json new file mode 100644 index 0000000000000000000000000000000000000000..d2a601786f531c36ed64e25f4c3d60b313a877c6 --- /dev/null +++ b/scipy/spring_atwood/156/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 0.8715260401050894, + "m_3": 0.9716873453617981, + "k": 28.542095660600722, + "L_0": 0.6854484877983268, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/156/simulation_code.py b/scipy/spring_atwood/156/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..87cf2224c6a0fadb49a204757cc95c494b36484e --- /dev/null +++ b/scipy/spring_atwood/156/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 0.8715260401050894 +m_3 = 0.9716873453617981 +k = 28.542095660600722 +L_0 = 0.6854484877983268 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/156/video.mp4 b/scipy/spring_atwood/156/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..480c4fdc8214fa3c4ff3b335586d6a985b631126 --- /dev/null +++ b/scipy/spring_atwood/156/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e07792f9a5e75b57c5b279a20e6f26cac5a8d39a9568c969ad566f50b30720d7 +size 13176 diff --git a/scipy/spring_atwood/194/cot.json b/scipy/spring_atwood/194/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..3c6bb554927d5e88bcd65699462335a1166c86c6 --- /dev/null +++ b/scipy/spring_atwood/194/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=30.399 N/m, natural length L_0=0.821 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=1.027 kg and m_3=0.986 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0203 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.8871 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 9.8583 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.6486 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.8871 rad/s, period 1.6164 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 9.858276895347238, + "T_A_equilibrium_N": 19.716553790694476, + "spring_extension_equilibrium_m": 0.6485872210214311, + "L_s_equilibrium_m": 1.4692654491870265, + "y_se_equilibrium_m": 3.0307345508129737, + "oscillation_omega_rad_s": 3.887128019758035, + "oscillation_period_s": 1.616408123231995, + "mass_asymmetry": 0.02033428818497548 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.8871 rad/s (period 1.6164 s).", + "Mass asymmetry 0.0203 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 1.026826406030372, + "unit": "", + "description": "" + }, + "m_3": { + "value": 0.9858990662399857, + "unit": "", + "description": "" + }, + "k": { + "value": 30.399232596109055, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.8206782281655954, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/194/params.json b/scipy/spring_atwood/194/params.json new file mode 100644 index 0000000000000000000000000000000000000000..920cc9b35485163d428e88ddb21465c11efce3ec --- /dev/null +++ b/scipy/spring_atwood/194/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 1.026826406030372, + "m_3": 0.9858990662399857, + "k": 30.399232596109055, + "L_0": 0.8206782281655954, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/194/simulation_code.py b/scipy/spring_atwood/194/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8fab40f820b0d076598fae8f72285bd02fc31c82 --- /dev/null +++ b/scipy/spring_atwood/194/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 1.026826406030372 +m_3 = 0.9858990662399857 +k = 30.399232596109055 +L_0 = 0.8206782281655954 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/194/video.mp4 b/scipy/spring_atwood/194/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3bfaaffaee05cacb88c495577625d5cbc9f7ea0f --- /dev/null +++ b/scipy/spring_atwood/194/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4aa3232bb07d6cfabd3a8ade4d6e9e6c811ca5e8add3a5278859819bc569c30a +size 13729 diff --git a/scipy/spring_atwood/213/cot.json b/scipy/spring_atwood/213/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f7a55ca8bbd91e6922d0790b0d3077510ee8c2c4 --- /dev/null +++ b/scipy/spring_atwood/213/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=27.836 N/m, natural length L_0=0.904 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=0.946 kg and m_3=0.923 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0121 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.8594 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 9.1572 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.6579 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.8594 rad/s, period 1.6280 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 9.157196358110115, + "T_A_equilibrium_N": 18.31439271622023, + "spring_extension_equilibrium_m": 0.6579298441268195, + "L_s_equilibrium_m": 1.5618940478348686, + "y_se_equilibrium_m": 2.9381059521651314, + "oscillation_omega_rad_s": 3.859430676418988, + "oscillation_period_s": 1.6280083343819778, + "mass_asymmetry": 0.012076527555682082 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.8594 rad/s (period 1.6280 s).", + "Mass asymmetry 0.0121 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.9458301353362724, + "unit": "", + "description": "" + }, + "m_3": { + "value": 0.9232580404770631, + "unit": "", + "description": "" + }, + "k": { + "value": 27.836391493269957, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.903964203708049, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/213/params.json b/scipy/spring_atwood/213/params.json new file mode 100644 index 0000000000000000000000000000000000000000..0c9024806f60f30caada806e640f0da590ad0923 --- /dev/null +++ b/scipy/spring_atwood/213/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 0.9458301353362724, + "m_3": 0.9232580404770631, + "k": 27.836391493269957, + "L_0": 0.903964203708049, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/213/simulation_code.py b/scipy/spring_atwood/213/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..46ff5939006f92abbd8323fc97e433732f17ca5e --- /dev/null +++ b/scipy/spring_atwood/213/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 0.9458301353362724 +m_3 = 0.9232580404770631 +k = 27.836391493269957 +L_0 = 0.903964203708049 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/213/video.mp4 b/scipy/spring_atwood/213/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3d6855e1ac41cc84335b8d2cbb41fcafdd33202c --- /dev/null +++ b/scipy/spring_atwood/213/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9eb4b344866849b70ac3eaa4e3b614e158f8736532d25830c0b395697551c277 +size 13310 diff --git a/scipy/spring_atwood/219/cot.json b/scipy/spring_atwood/219/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..9a41f719b251af3ac13178d418b9eb4ac3bc85bd --- /dev/null +++ b/scipy/spring_atwood/219/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=29.137 N/m, natural length L_0=0.651 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=1.022 kg and m_3=0.854 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0899 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.9571 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 9.1177 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.6258 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.9571 rad/s, period 1.5878 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 9.117668280582553, + "T_A_equilibrium_N": 18.235336561165106, + "spring_extension_equilibrium_m": 0.6258375089609144, + "L_s_equilibrium_m": 1.2767687447962621, + "y_se_equilibrium_m": 3.223231255203738, + "oscillation_omega_rad_s": 3.957147545027939, + "oscillation_period_s": 1.5878066803635507, + "mass_asymmetry": 0.08987835091840245 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.9571 rad/s (period 1.5878 s).", + "Mass asymmetry 0.0899 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 1.0222527013657985, + "unit": "", + "description": "" + }, + "m_3": { + "value": 0.8536496881153428, + "unit": "", + "description": "" + }, + "k": { + "value": 29.137493838363024, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6509312358353477, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/219/params.json b/scipy/spring_atwood/219/params.json new file mode 100644 index 0000000000000000000000000000000000000000..17904d963bd49a3efbd0ada888df9619cd91438a --- /dev/null +++ b/scipy/spring_atwood/219/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 1.0222527013657985, + "m_3": 0.8536496881153428, + "k": 29.137493838363024, + "L_0": 0.6509312358353477, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/219/simulation_code.py b/scipy/spring_atwood/219/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..9d136fd7bca7449417e316a2126b7c4a612a69a7 --- /dev/null +++ b/scipy/spring_atwood/219/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 1.0222527013657985 +m_3 = 0.8536496881153428 +k = 29.137493838363024 +L_0 = 0.6509312358353477 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/219/video.mp4 b/scipy/spring_atwood/219/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f06823fe291f62ba2f432dae75452d6dd850ee41 --- /dev/null +++ b/scipy/spring_atwood/219/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1bfecb5e6dcc3bf9af0942cdf4fcb3eeed3af9ed580c212651c47fabbe3bc7cb +size 11577 diff --git a/scipy/spring_atwood/226/cot.json b/scipy/spring_atwood/226/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..28d835f68b27a42951f0c4f1ee055f98605587e9 --- /dev/null +++ b/scipy/spring_atwood/226/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=26.354 N/m, natural length L_0=0.884 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=1.002 kg and m_3=1.117 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0543 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.5322 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 10.3503 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.7855 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.5322 rad/s, period 1.7788 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 10.350262254205681, + "T_A_equilibrium_N": 20.700524508411362, + "spring_extension_equilibrium_m": 0.7854771089628768, + "L_s_equilibrium_m": 1.6689866524400134, + "y_se_equilibrium_m": 2.8310133475599866, + "oscillation_omega_rad_s": 3.5322080124911657, + "oscillation_period_s": 1.7788265257765028, + "mass_asymmetry": 0.05433947495677179 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.5322 rad/s (period 1.7788 s).", + "Mass asymmetry 0.0543 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 1.0017164629600224, + "unit": "", + "description": "" + }, + "m_3": { + "value": 1.116837577168134, + "unit": "", + "description": "" + }, + "k": { + "value": 26.354077378198568, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.8835095434771367, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/226/params.json b/scipy/spring_atwood/226/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3a20178bd9abe1b13a2ad3b86905c48d22b16d3e --- /dev/null +++ b/scipy/spring_atwood/226/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 1.0017164629600224, + "m_3": 1.116837577168134, + "k": 26.354077378198568, + "L_0": 0.8835095434771367, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/226/simulation_code.py b/scipy/spring_atwood/226/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..85ab09e868fd07e61bac8c206d60ff3cbba07bc4 --- /dev/null +++ b/scipy/spring_atwood/226/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 1.0017164629600224 +m_3 = 1.116837577168134 +k = 26.354077378198568 +L_0 = 0.8835095434771367 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/226/video.mp4 b/scipy/spring_atwood/226/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..d684bae360f3e15aeeb8ae46e95251b5841c248f --- /dev/null +++ b/scipy/spring_atwood/226/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41ee247242500310dee6d832986da96668220a151c84ddbb1f19d665acfef22f +size 11423 diff --git a/scipy/spring_atwood/230/cot.json b/scipy/spring_atwood/230/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ee072801f78863702dd13c15b23185f37c4913bd --- /dev/null +++ b/scipy/spring_atwood/230/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=30.806 N/m, natural length L_0=0.630 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=0.958 kg and m_3=1.230 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.1245 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.7815 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 10.5562 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.6853 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.7815 rad/s, period 1.6616 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 10.556241576213255, + "T_A_equilibrium_N": 21.11248315242651, + "spring_extension_equilibrium_m": 0.6853299716490941, + "L_s_equilibrium_m": 1.3149423954937758, + "y_se_equilibrium_m": 3.185057604506224, + "oscillation_omega_rad_s": 3.781491906307537, + "oscillation_period_s": 1.6615625427359024, + "mass_asymmetry": 0.12449885790196538 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.7815 rad/s (period 1.6616 s).", + "Mass asymmetry 0.1245 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.957908938908652, + "unit": "", + "description": "" + }, + "m_3": { + "value": 1.230343920734996, + "unit": "", + "description": "" + }, + "k": { + "value": 30.806303570269975, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6296124238446817, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/230/params.json b/scipy/spring_atwood/230/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b380f0b7a9b236d49b289b3d4431d6117091f378 --- /dev/null +++ b/scipy/spring_atwood/230/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 0.957908938908652, + "m_3": 1.230343920734996, + "k": 30.806303570269975, + "L_0": 0.6296124238446817, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/230/simulation_code.py b/scipy/spring_atwood/230/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..6c170315e6ff487d9d10245fdbcd08c18dd864d6 --- /dev/null +++ b/scipy/spring_atwood/230/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 0.957908938908652 +m_3 = 1.230343920734996 +k = 30.806303570269975 +L_0 = 0.6296124238446817 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/230/video.mp4 b/scipy/spring_atwood/230/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b3c6b64c44117d463eac720b0c5a52f3cc48e752 --- /dev/null +++ b/scipy/spring_atwood/230/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:584c9b4d972e788acf1c642a0656c03dd616865c290204bc35bc09edd1250ce0 +size 10103 diff --git a/scipy/spring_atwood/267/cot.json b/scipy/spring_atwood/267/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..fa7cdf5e1563cf87c6b74a8fd7f65e0c18b3ac3f --- /dev/null +++ b/scipy/spring_atwood/267/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=32.898 N/m, natural length L_0=0.931 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=1.047 kg and m_3=1.055 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0040 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.9562 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 10.2993 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.6261 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.9562 rad/s, period 1.5882 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 10.299345433586012, + "T_A_equilibrium_N": 20.598690867172024, + "spring_extension_equilibrium_m": 0.6261393698964733, + "L_s_equilibrium_m": 1.5567689800799553, + "y_se_equilibrium_m": 2.9432310199200447, + "oscillation_omega_rad_s": 3.956193562320624, + "oscillation_period_s": 1.5881895585245316, + "mass_asymmetry": 0.0040346066780311916 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.9562 rad/s (period 1.5882 s).", + "Mass asymmetry 0.0040 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 1.0467304699279718, + "unit": "", + "description": "" + }, + "m_3": { + "value": 1.0552109769262805, + "unit": "", + "description": "" + }, + "k": { + "value": 32.89793272475078, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.930629610183482, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/267/params.json b/scipy/spring_atwood/267/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3de0482f8102f36105497f524877ca51a8799721 --- /dev/null +++ b/scipy/spring_atwood/267/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 1.0467304699279718, + "m_3": 1.0552109769262805, + "k": 32.89793272475078, + "L_0": 0.930629610183482, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/267/simulation_code.py b/scipy/spring_atwood/267/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..c41c7de55e3881f2b1b7a5cc04c6ecf6f379ea31 --- /dev/null +++ b/scipy/spring_atwood/267/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 1.0467304699279718 +m_3 = 1.0552109769262805 +k = 32.89793272475078 +L_0 = 0.930629610183482 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/267/video.mp4 b/scipy/spring_atwood/267/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..21a0689b12405d2f59931b2ebeabb9436e2a4aba --- /dev/null +++ b/scipy/spring_atwood/267/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0330eec01e1af4221f60fb21712ffc271cc9bd072c547d77a2124d1012e39b7a +size 15827 diff --git a/scipy/spring_atwood/301/cot.json b/scipy/spring_atwood/301/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..59e31c4ff3f81d4b4c42dd7591b68ad7e101bde4 --- /dev/null +++ b/scipy/spring_atwood/301/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=26.783 N/m, natural length L_0=0.674 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=1.130 kg and m_3=0.904 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.1112 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.6511 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 9.8447 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.7352 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.6511 rad/s, period 1.7209 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 9.8446903067558, + "T_A_equilibrium_N": 19.6893806135116, + "spring_extension_equilibrium_m": 0.7351501203134901, + "L_s_equilibrium_m": 1.4087856482657937, + "y_se_equilibrium_m": 3.091214351734206, + "oscillation_omega_rad_s": 3.6511108745753122, + "oscillation_period_s": 1.720896878517947, + "mass_asymmetry": 0.11122957963754378 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.6511 rad/s (period 1.7209 s).", + "Mass asymmetry 0.1112 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 1.1302809053586271, + "unit": "", + "description": "" + }, + "m_3": { + "value": 0.9040078250174981, + "unit": "", + "description": "" + }, + "k": { + "value": 26.782802681329162, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6736355279523035, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/301/params.json b/scipy/spring_atwood/301/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c280b837e14c2657f40f220dee5099d94650e3d3 --- /dev/null +++ b/scipy/spring_atwood/301/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 1.1302809053586271, + "m_3": 0.9040078250174981, + "k": 26.782802681329162, + "L_0": 0.6736355279523035, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/301/simulation_code.py b/scipy/spring_atwood/301/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..3f4322b27a70eb6905d4659b001806a7cf499a3d --- /dev/null +++ b/scipy/spring_atwood/301/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 1.1302809053586271 +m_3 = 0.9040078250174981 +k = 26.782802681329162 +L_0 = 0.6736355279523035 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/301/video.mp4 b/scipy/spring_atwood/301/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b060fe03f9ec553becd2dd3c0b642d4d6d3b40c7 --- /dev/null +++ b/scipy/spring_atwood/301/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d87b81bbf1b949c172549be8920f9a3556097dfcff45506fed89534cf41ae5d1 +size 10177 diff --git a/scipy/spring_atwood/305/cot.json b/scipy/spring_atwood/305/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f0885b730f352fde5f389579db07a0f10e185efe --- /dev/null +++ b/scipy/spring_atwood/305/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=26.405 N/m, natural length L_0=0.829 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=0.993 kg and m_3=1.146 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0716 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.5232 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 10.4234 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.7895 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.5232 rad/s, period 1.7834 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 10.423434247805574, + "T_A_equilibrium_N": 20.846868495611147, + "spring_extension_equilibrium_m": 0.7895058410510324, + "L_s_equilibrium_m": 1.6182460952073965, + "y_se_equilibrium_m": 2.8817539047926033, + "oscillation_omega_rad_s": 3.5231843173554256, + "oscillation_period_s": 1.7833825145701925, + "mass_asymmetry": 0.07156039257940837 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.5232 rad/s (period 1.7834 s).", + "Mass asymmetry 0.0716 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.992585902705598, + "unit": "", + "description": "" + }, + "m_3": { + "value": 1.145594965004729, + "unit": "", + "description": "" + }, + "k": { + "value": 26.40495790108238, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.8287402541563641, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/305/params.json b/scipy/spring_atwood/305/params.json new file mode 100644 index 0000000000000000000000000000000000000000..e3652db4571f2f0db170c10a5c0425c7590420dd --- /dev/null +++ b/scipy/spring_atwood/305/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 0.992585902705598, + "m_3": 1.145594965004729, + "k": 26.40495790108238, + "L_0": 0.8287402541563641, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/305/simulation_code.py b/scipy/spring_atwood/305/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..25e483c4adbca455d844e0400d9964a8a6613b43 --- /dev/null +++ b/scipy/spring_atwood/305/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 0.992585902705598 +m_3 = 1.145594965004729 +k = 26.40495790108238 +L_0 = 0.8287402541563641 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/305/video.mp4 b/scipy/spring_atwood/305/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..8163552b7dbf64a71307cdc905e25412ab7ac364 --- /dev/null +++ b/scipy/spring_atwood/305/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc4f59ee0565018beaf51e511bcc9bfbc989fc8234a797c5fccbebc183391b25 +size 10774 diff --git a/scipy/spring_atwood/310/cot.json b/scipy/spring_atwood/310/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..bdc41cefa7538c64a74c1762ee69f415b2cdf53d --- /dev/null +++ b/scipy/spring_atwood/310/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=27.502 N/m, natural length L_0=0.702 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=1.197 kg and m_3=0.941 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.1198 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.6120 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 10.3290 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.7512 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.6120 rad/s, period 1.7395 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 10.329008398791204, + "T_A_equilibrium_N": 20.65801679758241, + "spring_extension_equilibrium_m": 0.7511578476517886, + "L_s_equilibrium_m": 1.4536096990119387, + "y_se_equilibrium_m": 3.0463903009880613, + "oscillation_omega_rad_s": 3.6119974365268264, + "oscillation_period_s": 1.7395320505047986, + "mass_asymmetry": 0.11982866581517364 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.6120 rad/s (period 1.7395 s).", + "Mass asymmetry 0.1198 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 1.1974719102075653, + "unit": "", + "description": "" + }, + "m_3": { + "value": 0.9411979537860871, + "unit": "", + "description": "" + }, + "k": { + "value": 27.501565565961798, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.70245185136015, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/310/params.json b/scipy/spring_atwood/310/params.json new file mode 100644 index 0000000000000000000000000000000000000000..facd164caaa274b880eaf68a8db6cbe043099344 --- /dev/null +++ b/scipy/spring_atwood/310/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 1.1974719102075653, + "m_3": 0.9411979537860871, + "k": 27.501565565961798, + "L_0": 0.70245185136015, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/310/simulation_code.py b/scipy/spring_atwood/310/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8b97164344dda827d4b541389061a87565f72e45 --- /dev/null +++ b/scipy/spring_atwood/310/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 1.1974719102075653 +m_3 = 0.9411979537860871 +k = 27.501565565961798 +L_0 = 0.70245185136015 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/310/video.mp4 b/scipy/spring_atwood/310/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ddd6b8e5439e648a7147cdd14866bb916bd06d58 --- /dev/null +++ b/scipy/spring_atwood/310/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c5d75c1b22cfa6e83ec9fe9c4f6a2e0e951203fa100c0fbee448817a6ddbd839 +size 10055 diff --git a/scipy/spring_atwood/316/cot.json b/scipy/spring_atwood/316/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..68316d8b633580ee662ad9164ccc5fc01838c085 --- /dev/null +++ b/scipy/spring_atwood/316/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=26.149 N/m, natural length L_0=0.914 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=0.982 kg and m_3=1.239 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.1158 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.4550 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 10.7336 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.8210 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.4550 rad/s, period 1.8186 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 10.733615406228656, + "T_A_equilibrium_N": 21.467230812457313, + "spring_extension_equilibrium_m": 0.8209720398423732, + "L_s_equilibrium_m": 1.7350506109351795, + "y_se_equilibrium_m": 2.7649493890648205, + "oscillation_omega_rad_s": 3.455006387554834, + "oscillation_period_s": 1.818574150777852, + "mass_asymmetry": 0.11575042490556676 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.4550 rad/s (period 1.8186 s).", + "Mass asymmetry 0.1158 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.9816414618702001, + "unit": "", + "description": "" + }, + "m_3": { + "value": 1.238639982461545, + "unit": "", + "description": "" + }, + "k": { + "value": 26.148552899047605, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.9140785710928062, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/316/params.json b/scipy/spring_atwood/316/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6ed42099e92cb0f662bafed9b5dd02524ffc4852 --- /dev/null +++ b/scipy/spring_atwood/316/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 0.9816414618702001, + "m_3": 1.238639982461545, + "k": 26.148552899047605, + "L_0": 0.9140785710928062, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/316/simulation_code.py b/scipy/spring_atwood/316/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d00f1838669f77db592cdf02f9e77cf769349fba --- /dev/null +++ b/scipy/spring_atwood/316/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 0.9816414618702001 +m_3 = 1.238639982461545 +k = 26.148552899047605 +L_0 = 0.9140785710928062 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/316/video.mp4 b/scipy/spring_atwood/316/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..313a66d29fff01cb726290cc0583111fc69cfdaa --- /dev/null +++ b/scipy/spring_atwood/316/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4433328eb0f51069617e2ee1d544c8c344897f64ab809f1e124afbe2121faff2 +size 9069 diff --git a/scipy/spring_atwood/391/cot.json b/scipy/spring_atwood/391/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..1c074287dedd35c0aadbcabfa1abc8cacaabe938 --- /dev/null +++ b/scipy/spring_atwood/391/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=27.234 N/m, natural length L_0=0.616 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=0.937 kg and m_3=1.049 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0568 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.7093 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 9.6991 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.7123 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.7093 rad/s, period 1.6939 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 9.699132727846145, + "T_A_equilibrium_N": 19.39826545569229, + "spring_extension_equilibrium_m": 0.7122759501500852, + "L_s_equilibrium_m": 1.32852863113337, + "y_se_equilibrium_m": 3.17147136886663, + "oscillation_omega_rad_s": 3.7092738472152096, + "oscillation_period_s": 1.6939124923054083, + "mass_asymmetry": 0.05677781508071555 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.7093 rad/s (period 1.6939 s).", + "Mass asymmetry 0.0568 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.9365331170707794, + "unit": "", + "description": "" + }, + "m_3": { + "value": 1.0492834424727655, + "unit": "", + "description": "" + }, + "k": { + "value": 27.234199682868475, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.6162526809832848, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/391/params.json b/scipy/spring_atwood/391/params.json new file mode 100644 index 0000000000000000000000000000000000000000..9f4c8ee539dff998ec81a0ef3522076de5079606 --- /dev/null +++ b/scipy/spring_atwood/391/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 0.9365331170707794, + "m_3": 1.0492834424727655, + "k": 27.234199682868475, + "L_0": 0.6162526809832848, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/391/simulation_code.py b/scipy/spring_atwood/391/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b095599462cee62359a7dc5f1622c239df4a81db --- /dev/null +++ b/scipy/spring_atwood/391/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 0.9365331170707794 +m_3 = 1.0492834424727655 +k = 27.234199682868475 +L_0 = 0.6162526809832848 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/391/video.mp4 b/scipy/spring_atwood/391/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0bb3fe2a208dca95b82ff8fe5cf5fbfdbce60839 --- /dev/null +++ b/scipy/spring_atwood/391/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a368b121e7f23b2a0dd54ed64b714579405b71374f9e3a49f52bbe1f77d930a +size 12364 diff --git a/scipy/spring_atwood/397/cot.json b/scipy/spring_atwood/397/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..428b3fad7f47dad716fbe1614733969bf9042af1 --- /dev/null +++ b/scipy/spring_atwood/397/cot.json @@ -0,0 +1,120 @@ +{ + "simulation": "spring_atwood", + "physical_observation": "Compound Atwood machine with a vertical Hookean spring (stiffness k=25.209 N/m, natural length L_0=0.798 m) replacing the left hanging mass. The string over fixed pulley A connects the spring's top to the axle of movable pulley B; the rope over B carries m_2=0.945 kg and m_3=0.899 kg. Mass asymmetry (m_3 - m_2)/(m_3 + m_2) = 0.0250 produces a slow gravity-driven drift superimposed on a vertical bounce of the spring at angular frequency omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.6993 rad/s.", + "physical_law": { + "name": "Newton's laws + ideal-string + ideal-spring constraints (massless inextensible cords, massless pulley B)", + "statement": "Massless inextensible cord on pulley A: y_se + y_B = const_A. Cord on movable pulley B: (y_2 - y_B) + (y_3 - y_B) = const_rope. Massless pulley B: T_A = 2 T_B. Spring: T_A = k (L_s - L_0) where L_s = y_floor - y_se.", + "formula": "m_i \\ddot{y}_i= m_i g - T_B for i in {2, 3}" + }, + "ode_system": { + "state_variables": [ + "y_2 (m, +y down)", + "y_3 (m)", + "v_2 (m/s)", + "v_3 (m/s)" + ], + "equations_latex": [ + "\\dot{y}_2 = v_2", + "\\dot{y}_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "\\dot{v}_2 = g - T_B / m_2", + "\\dot{v}_3 = g - T_B / m_3" + ], + "equations_python": [ + "y_dot_2 = v_2", + "y_dot_3 = v_3", + "y_B = (y_2 + y_3)/2 + C_pulley", + "y_se = const_A - y_B", + "L_s = y_floor - y_se", + "T_A = k (L_s - L_0); T_B = T_A / 2", + "v_dot_2 = g - T_B / m_2", + "v_dot_3 = g - T_B / m_3" + ] + }, + "derivation_steps": [ + "Take +y as downward; ceiling at y=0; floor at y=y_floor.", + "Pulley A is fixed; string over A is inextensible: y_se + y_B = const.", + "Pulley B is movable, massless: tensions on the two sides of B sum to support T_A; T_A = 2 T_B.", + "Rope over B is inextensible: (y_2 - y_B) + (y_3 - y_B) = const.", + "From the two constraint equations, y_B is a linear function of (y_2 + y_3); y_se follows.", + "Spring: T_A = k (L_s - L_0); L_s = y_floor - y_se. T_B = T_A / 2.", + "Newton's 2nd law on each mass: m_i a_i = m_i g - T_B.", + "Equilibrium tension: T_B_eq = 2 m_2 m_3 g / (m_2 + m_3) = 9.0265 N.", + "Equilibrium spring extension: Delta_eq = T_A_eq / k = 0.7161 m.", + "Small-oscillation angular frequency: omega = \\sqrt((k/4)(1/m_2 + 1/m_3)) = 3.6993 rad/s, period 1.6985 s." + ], + "physical_constants_derived": { + "T_B_equilibrium_N": 9.026505603945695, + "T_A_equilibrium_N": 18.05301120789139, + "spring_extension_equilibrium_m": 0.7161289752907467, + "L_s_equilibrium_m": 1.5136913101614495, + "y_se_equilibrium_m": 2.9863086898385505, + "oscillation_omega_rad_s": 3.699281791549161, + "oscillation_period_s": 1.6984878852790382, + "mass_asymmetry": 0.025042054962683767 + }, + "numerical_method": { + "solver": "RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth ODE with no impacts (an event-based termination guards against m_2 reaching pulley B for unphysical parameter sets)." + }, + "code_validation": { + "ode_source": "Newton-Euler with massless inextensible string/rope and ideal Hookean spring; pulley B is massless so T_A = 2 T_B.", + "energy_check": "Total mechanical energy E = (1/2) m_2 v_2^2 + (1/2) m_3 v_3^2 - m_2 g y_2 - m_3 g y_3 + (1/2) k (L_s - L_0)^2 should be conserved (no damping).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Spring oscillates at angular frequency 3.6993 rad/s (period 1.6985 s).", + "Mass asymmetry 0.0250 causes the heavier side to slowly accelerate downward while the lighter rises." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.9447299804991774, + "unit": "", + "description": "" + }, + "m_3": { + "value": 0.8985699620257562, + "unit": "", + "description": "" + }, + "k": { + "value": 25.20916180016583, + "unit": "", + "description": "" + }, + "L_0": { + "value": 0.7975623348707029, + "unit": "", + "description": "" + }, + "y_floor": { + "value": 4.5, + "unit": "", + "description": "" + }, + "y_se_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "y_B_0": { + "value": 2.5, + "unit": "", + "description": "" + }, + "ROPE_HALF": { + "value": 10.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_atwood/397/params.json b/scipy/spring_atwood/397/params.json new file mode 100644 index 0000000000000000000000000000000000000000..570094695d6158531015ae3c15f81f79e95e64b5 --- /dev/null +++ b/scipy/spring_atwood/397/params.json @@ -0,0 +1,11 @@ +{ + "g": 9.8, + "m_2": 0.9447299804991774, + "m_3": 0.8985699620257562, + "k": 25.20916180016583, + "L_0": 0.7975623348707029, + "y_floor": 4.5, + "y_se_0": 2.5, + "y_B_0": 2.5, + "ROPE_HALF": 10.0 +} \ No newline at end of file diff --git a/scipy/spring_atwood/397/simulation_code.py b/scipy/spring_atwood/397/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..cac33e9df41d37dbb596bbc6b95ed087808b4406 --- /dev/null +++ b/scipy/spring_atwood/397/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring Atwood — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_2 = 0.9447299804991774 +m_3 = 0.8985699620257562 +k = 25.20916180016583 +L_0 = 0.7975623348707029 +y_floor = 4.5 +y_se_0 = 2.5 +y_B_0 = 2.5 +ROPE_HALF = 10.0 +duration = 12 + +r_A = 0.55; r_B = 0.55 +x_A = 1.50; y_A = r_A + 0.05 +x_B = x_A + r_A +mass_side = 0.80 +x_spring = x_A - r_A +x_m2 = x_B - r_B +x_m3 = x_B + r_B + +y_2_0 = y_B_0 + ROPE_HALF +y_3_0 = y_B_0 + ROPE_HALF +const_A = y_se_0 + y_B_0 +C_pulley = y_B_0 - 0.5*(y_2_0 + y_3_0) + +def ode(t, y): + y2, y3, v2, v3 = y + y_B = 0.5*(y2+y3) + C_pulley + y_se = const_A - y_B + L_s = y_floor - y_se + T_A = k*(L_s - L_0); T_B = 0.5*T_A + return [v2, v3, g - T_B/m_2, g - T_B/m_3] + +MASS_OFFSET = 0.6 +def ev_m2_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[0] - (y_B + MASS_OFFSET) +ev_m2_p.terminal=True; ev_m2_p.direction=-1 +def ev_m3_p(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y[1] - (y_B + MASS_OFFSET) +ev_m3_p.terminal=True; ev_m3_p.direction=-1 +def ev_m2_f(t, y): return y_floor - (y[0] + MASS_OFFSET) +ev_m2_f.terminal=True; ev_m2_f.direction=-1 +def ev_m3_f(t, y): return y_floor - (y[1] + MASS_OFFSET) +ev_m3_f.terminal=True; ev_m3_f.direction=-1 +def ev_spring_min(t, y): + y_B = 0.5*(y[0]+y[1]) + C_pulley + return y_floor - (const_A - y_B) +ev_spring_min.terminal=True; ev_spring_min.direction=-1 + +fps = 30 +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0,duration), [y_2_0,y_3_0,0.0,0.0], t_eval=t_eval, + method="RK45", rtol=1e-9, atol=1e-11, + events=[ev_m2_p, ev_m3_p, ev_m2_f, ev_m3_f, ev_spring_min], + dense_output=True) +if sol.status == 1: + t_f = sol.t[-1]; sf = sol.y[:,-1] + y2_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[0], sf[0]) + y3_a = np.where(t_eval<=t_f, sol.sol(np.minimum(t_eval,t_f))[1], sf[1]) +else: + y2_a, y3_a = sol.y[0], sol.y[1] +yB_a = 0.5*(y2_a+y3_a) + C_pulley +yse_a = const_A - yB_a + +fig_w, fig_h = 5.0, 8.0; fa = fig_w/fig_h +xlo_d = min(x_spring, x_m2 - mass_side/2.0) - 0.4 +xhi_d = max(x_m3 + mass_side/2.0, x_A + r_A) + 0.4 +ylo_d = -0.4 +yhi_d = max(y2_a.max(), y3_a.max()) + mass_side + 0.5 +dx, dy = xhi_d-xlo_d, yhi_d-ylo_d +if dx/dy < fa: + e=(fa*dy-dx)/2.0; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e=(dx/fa-dy)/2.0; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(yhi,ylo) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((xlo,ylo), xhi-xlo, -ylo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [0,0], color="#adb5bd", lw=2.2, zorder=1) +ax.add_patch(patches.Rectangle((x_spring-0.20, y_floor-0.05), 0.40, 0.10, + facecolor="#adb5bd", edgecolor="none", zorder=2)) + +ax.plot([x_A,x_A], [0,y_A-r_A], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Circle((x_A,y_A), r_A, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4)) +arc_A = patches.Arc((x_A,y_A), 2*r_A, 2*r_A, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +ax.add_patch(arc_A) +ax.add_patch(patches.Circle((x_A,y_A), r_A*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6)) + +pBb = patches.Circle((x_B,y_B_0), r_B, facecolor="#4a4e69", edgecolor="white", lw=1.6, zorder=4) +arc_B = patches.Arc((x_B,y_B_0), 2*r_B, 2*r_B, angle=0, theta1=180, theta2=360, color="#a8dadc", lw=2.5, zorder=5) +hub_B = patches.Circle((x_B,y_B_0), r_B*0.18, facecolor="#1a1a2e", edgecolor="#adb5bd", lw=1.0, zorder=6) +ax.add_patch(pBb); ax.add_patch(arc_B); ax.add_patch(hub_B) + +m2_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=7) +m3_p = patches.Rectangle((0,0), mass_side, mass_side, facecolor="#f4d35e", edgecolor="white", lw=1.5, zorder=7) +ax.add_patch(m2_p); ax.add_patch(m3_p) + +sAL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sAR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBL, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +rBR, = ax.plot([],[], "-", color="#a8dadc", lw=2.5, zorder=5) +sp_l, = ax.plot([],[], "-", color="#f4d35e", lw=2.4, zorder=4) + +def sp_path(xt, yt, xb, yb, n=10, r=0.10): + s = np.linspace(0,1, n*20+2) + pad = 0.08 + env = np.where((s1-pad), 0.0, np.sin(n*2*np.pi*(s-pad)/(1-2*pad))) + return xt + s*(xb-xt) + r*env, yt + s*(yb-yt) + +def update(f): + y_se = yse_a[f]; y_B = yB_a[f] + y_2 = y2_a[f]; y_3 = y3_a[f] + pBb.center = (x_B, y_B); hub_B.center = (x_B, y_B); arc_B.set_center((x_B, y_B)) + sAL.set_data([x_spring,x_spring], [y_A, y_se]) + sAR.set_data([x_B,x_B], [y_A, y_B-r_B]) + rBL.set_data([x_m2,x_m2], [y_B, y_2]) + rBR.set_data([x_m3,x_m3], [y_B, y_3]) + sx, sy = sp_path(x_spring, y_se, x_spring, y_floor) + sp_l.set_data(sx, sy) + m2_p.set_xy((x_m2-mass_side/2.0, y_2)) + m3_p.set_xy((x_m3-mass_side/2.0, y_3)) + return (pBb, hub_B, arc_B, sAL, sAR, rBL, rBR, sp_l, m2_p, m3_p) + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_atwood/397/video.mp4 b/scipy/spring_atwood/397/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0ec3e3cad4c352d8f935dd227ac72e171a512e69 --- /dev/null +++ b/scipy/spring_atwood/397/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4500a3228c9a8e4b43f292b68fe470d0632d793673ff612a0edc79ed5988fce5 +size 13342 diff --git a/scipy/spring_mass_string_fixed/061/cot.json b/scipy/spring_mass_string_fixed/061/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..157429dbf24c2421f3d88ef1aeff34033ec59b6a --- /dev/null +++ b/scipy/spring_mass_string_fixed/061/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=26.329 N/m) hangs from a ceiling. A mass m=0.334 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.1246 m and angular frequency omega_s = \\sqrt(k/m) = 8.873 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=3.599 m, linear density mu=0.132 kg/m, tension T=3.706 N, giving wave speed c = \\sqrt(T/mu) = 5.305 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.1246 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 8.873 rad/s (= 1.412 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 5.305 m/s.", + "Driven wavelength: lambda = c/f_s = 3.757 m, ~0.958 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.443 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.1246039182586593, + "omega_spring_rad_s": 8.872962663805012, + "f_spring_Hz": 1.4121758678143987, + "wave_speed_c_m_s": 5.3054345971054655, + "wavelength_m": 3.7569220081041315, + "wavelengths_in_string": 0.9580956379499621 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 8.873 rad/s (period 0.708 s) with amplitude 0.1246 m.", + "Driven string carries a travelling wave of wavelength 3.757 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 0.687 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.3344177117707937, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 26.328528013552255, + "unit": "", + "description": "" + }, + "L": { + "value": 3.5994905880827806, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.13165608412490457, + "unit": "", + "description": "" + }, + "T_str": { + "value": 3.7058075679119424, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.6872510479985714, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.44287107710703644, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/061/params.json b/scipy/spring_mass_string_fixed/061/params.json new file mode 100644 index 0000000000000000000000000000000000000000..d921bb9fc55390c383fcfcce2bbe9d61961a1322 --- /dev/null +++ b/scipy/spring_mass_string_fixed/061/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.3344177117707937, + "k_spring": 26.328528013552255, + "L": 3.5994905880827806, + "mu": 0.13165608412490457, + "T_str": 3.7058075679119424, + "gamma_w": 0.6872510479985714, + "tau_ramp": 0.44287107710703644, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/061/simulation_code.py b/scipy/spring_mass_string_fixed/061/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..df71e57b06c2ba6dba74a3f9fd56a775a00bb12b --- /dev/null +++ b/scipy/spring_mass_string_fixed/061/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.3344177117707937 +k_spring = 26.328528013552255 +L = 3.5994905880827806 +mu = 0.13165608412490457 +T_str = 3.7058075679119424 +gamma_w = 0.6872510479985714 +tau_ramp = 0.44287107710703644 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/061/video.mp4 b/scipy/spring_mass_string_fixed/061/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..75b96e52e61339c29ba7ca11d7dc06217b6dfb9c --- /dev/null +++ b/scipy/spring_mass_string_fixed/061/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d45e88526fd0fcfdb61cc9b7e1ba84b776e543a3dbffdd110c860447c41bcf62 +size 52829 diff --git a/scipy/spring_mass_string_fixed/083/cot.json b/scipy/spring_mass_string_fixed/083/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..a2fbb98645f059baf89fa6a246408920ab2f8f94 --- /dev/null +++ b/scipy/spring_mass_string_fixed/083/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=30.160 N/m) hangs from a ceiling. A mass m=0.332 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.1079 m and angular frequency omega_s = \\sqrt(k/m) = 9.533 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=4.274 m, linear density mu=0.090 kg/m, tension T=4.326 N, giving wave speed c = \\sqrt(T/mu) = 6.933 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.1079 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 9.533 rad/s (= 1.517 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 6.933 m/s.", + "Driven wavelength: lambda = c/f_s = 4.570 m, ~0.935 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.389 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.10794566351829038, + "omega_spring_rad_s": 9.533050718501423, + "f_spring_Hz": 1.517232144595246, + "wave_speed_c_m_s": 6.933057968368301, + "wavelength_m": 4.56954329175371, + "wavelengths_in_string": 0.9353411781841884 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 9.533 rad/s (period 0.659 s) with amplitude 0.1079 m.", + "Driven string carries a travelling wave of wavelength 4.570 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 0.673 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.33187435237673313, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 30.16042785511348, + "unit": "", + "description": "" + }, + "L": { + "value": 4.27408200627257, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.0900047197393151, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.326283216439532, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.6734527089471439, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.38878690437154984, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/083/params.json b/scipy/spring_mass_string_fixed/083/params.json new file mode 100644 index 0000000000000000000000000000000000000000..7819544b7e6518a48677e7e8ca1a8f2bc33cf4a4 --- /dev/null +++ b/scipy/spring_mass_string_fixed/083/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.33187435237673313, + "k_spring": 30.16042785511348, + "L": 4.27408200627257, + "mu": 0.0900047197393151, + "T_str": 4.326283216439532, + "gamma_w": 0.6734527089471439, + "tau_ramp": 0.38878690437154984, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/083/simulation_code.py b/scipy/spring_mass_string_fixed/083/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..c99c3da669a9590c80c88c2fe07552048401efb4 --- /dev/null +++ b/scipy/spring_mass_string_fixed/083/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.33187435237673313 +k_spring = 30.16042785511348 +L = 4.27408200627257 +mu = 0.0900047197393151 +T_str = 4.326283216439532 +gamma_w = 0.6734527089471439 +tau_ramp = 0.38878690437154984 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/083/video.mp4 b/scipy/spring_mass_string_fixed/083/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9d9f06d637ef75ac7cf2ac0c0ae4e411c0db87b1 --- /dev/null +++ b/scipy/spring_mass_string_fixed/083/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7148321af8179d5e39ae88e3bf1e3cb7cff7048f4d6a6cd7007393cd21954509 +size 46415 diff --git a/scipy/spring_mass_string_fixed/101/cot.json b/scipy/spring_mass_string_fixed/101/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..6b466156e0c8e74460ddf30785983b3fa431f1a8 --- /dev/null +++ b/scipy/spring_mass_string_fixed/101/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=32.996 N/m) hangs from a ceiling. A mass m=0.212 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0629 m and angular frequency omega_s = \\sqrt(k/m) = 12.489 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=4.487 m, linear density mu=0.137 kg/m, tension T=4.391 N, giving wave speed c = \\sqrt(T/mu) = 5.661 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0629 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 12.489 rad/s (= 1.988 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 5.661 m/s.", + "Driven wavelength: lambda = c/f_s = 2.848 m, ~1.575 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.414 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.062894636759703, + "omega_spring_rad_s": 12.489000904627813, + "f_spring_Hz": 1.987686228250669, + "wave_speed_c_m_s": 5.660868977006589, + "wavelength_m": 2.847969109283727, + "wavelengths_in_string": 1.5754951674893423 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 12.489 rad/s (period 0.503 s) with amplitude 0.0629 m.", + "Driven string carries a travelling wave of wavelength 2.848 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 1.074 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.21154412912171855, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 32.99562591660731, + "unit": "", + "description": "" + }, + "L": { + "value": 4.486961568835438, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.13703006757727695, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.391188476423136, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.074404695208353, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.4135229759882706, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/101/params.json b/scipy/spring_mass_string_fixed/101/params.json new file mode 100644 index 0000000000000000000000000000000000000000..a0d3e2cce2a16b55c594bfb131e52119101daf2a --- /dev/null +++ b/scipy/spring_mass_string_fixed/101/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.21154412912171855, + "k_spring": 32.99562591660731, + "L": 4.486961568835438, + "mu": 0.13703006757727695, + "T_str": 4.391188476423136, + "gamma_w": 1.074404695208353, + "tau_ramp": 0.4135229759882706, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/101/simulation_code.py b/scipy/spring_mass_string_fixed/101/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b0388de95f8d943baf5801f716a32aa3df173c24 --- /dev/null +++ b/scipy/spring_mass_string_fixed/101/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.21154412912171855 +k_spring = 32.99562591660731 +L = 4.486961568835438 +mu = 0.13703006757727695 +T_str = 4.391188476423136 +gamma_w = 1.074404695208353 +tau_ramp = 0.4135229759882706 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/101/video.mp4 b/scipy/spring_mass_string_fixed/101/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..391c6509d2b5c746e21ec34f731a1d9c840ccb99 --- /dev/null +++ b/scipy/spring_mass_string_fixed/101/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:444f330d922416279eb414fb78d03be5bf463b7966900da8ea69206cf398b20a +size 34221 diff --git a/scipy/spring_mass_string_fixed/160/cot.json b/scipy/spring_mass_string_fixed/160/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4f975bd6b34be318e912d36e701f2e4ef2251f50 --- /dev/null +++ b/scipy/spring_mass_string_fixed/160/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=33.402 N/m) hangs from a ceiling. A mass m=0.310 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0910 m and angular frequency omega_s = \\sqrt(k/m) = 10.381 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=3.941 m, linear density mu=0.130 kg/m, tension T=4.999 N, giving wave speed c = \\sqrt(T/mu) = 6.202 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0910 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 10.381 rad/s (= 1.652 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 6.202 m/s.", + "Driven wavelength: lambda = c/f_s = 3.754 m, ~1.050 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.460 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.0910363221636599, + "omega_spring_rad_s": 10.380712225030345, + "f_spring_Hz": 1.6521416634280468, + "wave_speed_c_m_s": 6.2024857061046195, + "wavelength_m": 3.7542093655788658, + "wavelengths_in_string": 1.0497264515638136 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 10.381 rad/s (period 0.605 s) with amplitude 0.0910 m.", + "Driven string carries a travelling wave of wavelength 3.754 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 0.576 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.3099714098219765, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 33.40226689833733, + "unit": "", + "description": "" + }, + "L": { + "value": 3.9408928757567385, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.12994902591686736, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.99924674624389, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.5759268677864595, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.4601545782281498, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/160/params.json b/scipy/spring_mass_string_fixed/160/params.json new file mode 100644 index 0000000000000000000000000000000000000000..54578fc18e30f2e66f079ae03d6bbd544168a394 --- /dev/null +++ b/scipy/spring_mass_string_fixed/160/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.3099714098219765, + "k_spring": 33.40226689833733, + "L": 3.9408928757567385, + "mu": 0.12994902591686736, + "T_str": 4.99924674624389, + "gamma_w": 0.5759268677864595, + "tau_ramp": 0.4601545782281498, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/160/simulation_code.py b/scipy/spring_mass_string_fixed/160/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ba01fc46558f6fa7623243de434af80d246ce1e2 --- /dev/null +++ b/scipy/spring_mass_string_fixed/160/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.3099714098219765 +k_spring = 33.40226689833733 +L = 3.9408928757567385 +mu = 0.12994902591686736 +T_str = 4.99924674624389 +gamma_w = 0.5759268677864595 +tau_ramp = 0.4601545782281498 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/160/video.mp4 b/scipy/spring_mass_string_fixed/160/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..2435dcded539a996bcae2737d56f67abc3b0bdff --- /dev/null +++ b/scipy/spring_mass_string_fixed/160/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a2b5e104c5a8d51c0b982751845d276804c5c02d3616314eb96271878e3a309 +size 48355 diff --git a/scipy/spring_mass_string_fixed/177/cot.json b/scipy/spring_mass_string_fixed/177/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..59ba1ca962a87410e62a6a00802ff23167f27214 --- /dev/null +++ b/scipy/spring_mass_string_fixed/177/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=39.200 N/m) hangs from a ceiling. A mass m=0.303 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0759 m and angular frequency omega_s = \\sqrt(k/m) = 11.369 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=4.175 m, linear density mu=0.109 kg/m, tension T=3.642 N, giving wave speed c = \\sqrt(T/mu) = 5.791 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0759 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 11.369 rad/s (= 1.809 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 5.791 m/s.", + "Driven wavelength: lambda = c/f_s = 3.201 m, ~1.305 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.459 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.07589552536494051, + "omega_spring_rad_s": 11.369108676508302, + "f_spring_Hz": 1.8094498444152525, + "wave_speed_c_m_s": 5.791254695404416, + "wavelength_m": 3.2005610507960425, + "wavelengths_in_string": 1.3045127364807887 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 11.369 rad/s (period 0.553 s) with amplitude 0.0759 m.", + "Driven string carries a travelling wave of wavelength 3.201 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 0.794 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.30327061535189176, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 39.1997383547513, + "unit": "", + "description": "" + }, + "L": { + "value": 4.175172654647774, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.1086039508043094, + "unit": "", + "description": "" + }, + "T_str": { + "value": 3.6424278254166227, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.7936683085946356, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.4588139925619017, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/177/params.json b/scipy/spring_mass_string_fixed/177/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c59c7a2ebd8e370de3c6276be6223ced0c2d3034 --- /dev/null +++ b/scipy/spring_mass_string_fixed/177/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.30327061535189176, + "k_spring": 39.1997383547513, + "L": 4.175172654647774, + "mu": 0.1086039508043094, + "T_str": 3.6424278254166227, + "gamma_w": 0.7936683085946356, + "tau_ramp": 0.4588139925619017, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/177/simulation_code.py b/scipy/spring_mass_string_fixed/177/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..140336bd7987b668de69a596b3c4fde1c8a959f5 --- /dev/null +++ b/scipy/spring_mass_string_fixed/177/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.30327061535189176 +k_spring = 39.1997383547513 +L = 4.175172654647774 +mu = 0.1086039508043094 +T_str = 3.6424278254166227 +gamma_w = 0.7936683085946356 +tau_ramp = 0.4588139925619017 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/177/video.mp4 b/scipy/spring_mass_string_fixed/177/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c67c0dfa2e7eb5a00d7cb39c0682f4e8c60adcd6 --- /dev/null +++ b/scipy/spring_mass_string_fixed/177/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9029e6607dbca9c25aa7fcf1c1ca1a3559259e30398fc59ec4703426218ecbd7 +size 36573 diff --git a/scipy/spring_mass_string_fixed/212/cot.json b/scipy/spring_mass_string_fixed/212/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..eca94ad18f1b71ef18817e902a1aa581339f2efe --- /dev/null +++ b/scipy/spring_mass_string_fixed/212/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=32.451 N/m) hangs from a ceiling. A mass m=0.295 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0891 m and angular frequency omega_s = \\sqrt(k/m) = 10.493 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=4.437 m, linear density mu=0.083 kg/m, tension T=4.273 N, giving wave speed c = \\sqrt(T/mu) = 7.186 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0891 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 10.493 rad/s (= 1.670 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 7.186 m/s.", + "Driven wavelength: lambda = c/f_s = 4.303 m, ~1.031 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.441 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.08910646594925124, + "omega_spring_rad_s": 10.492522132315992, + "f_spring_Hz": 1.6699367628592041, + "wave_speed_c_m_s": 7.186173909732116, + "wavelength_m": 4.303261099197681, + "wavelengths_in_string": 1.031173032559845 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 10.493 rad/s (period 0.599 s) with amplitude 0.0891 m.", + "Driven string carries a travelling wave of wavelength 4.303 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 0.928 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.2947595596121226, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 32.45097029705756, + "unit": "", + "description": "" + }, + "L": { + "value": 4.437406797556484, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.08274480385978264, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.273032315017686, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.9276989856475453, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.44090305726723356, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/212/params.json b/scipy/spring_mass_string_fixed/212/params.json new file mode 100644 index 0000000000000000000000000000000000000000..898d38103b2e4fd106cb0f52b3386020b5b4c485 --- /dev/null +++ b/scipy/spring_mass_string_fixed/212/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.2947595596121226, + "k_spring": 32.45097029705756, + "L": 4.437406797556484, + "mu": 0.08274480385978264, + "T_str": 4.273032315017686, + "gamma_w": 0.9276989856475453, + "tau_ramp": 0.44090305726723356, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/212/simulation_code.py b/scipy/spring_mass_string_fixed/212/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..00bafea5bd41ec33e19528e91c8e55de379e0484 --- /dev/null +++ b/scipy/spring_mass_string_fixed/212/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.2947595596121226 +k_spring = 32.45097029705756 +L = 4.437406797556484 +mu = 0.08274480385978264 +T_str = 4.273032315017686 +gamma_w = 0.9276989856475453 +tau_ramp = 0.44090305726723356 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/212/video.mp4 b/scipy/spring_mass_string_fixed/212/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..fdf702b00beb25fa8117d56efdbd80c087e6fb83 --- /dev/null +++ b/scipy/spring_mass_string_fixed/212/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d3d06506687729387b72f92f05f32e45156ed1549774d56082e9ade3f9dc3e1 +size 40956 diff --git a/scipy/spring_mass_string_fixed/216/cot.json b/scipy/spring_mass_string_fixed/216/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..e17558ba30c73de89e4a7d78782113beb4594a27 --- /dev/null +++ b/scipy/spring_mass_string_fixed/216/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=36.763 N/m) hangs from a ceiling. A mass m=0.261 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0695 m and angular frequency omega_s = \\sqrt(k/m) = 11.877 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=4.433 m, linear density mu=0.125 kg/m, tension T=4.704 N, giving wave speed c = \\sqrt(T/mu) = 6.146 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0695 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 11.877 rad/s (= 1.890 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 6.146 m/s.", + "Driven wavelength: lambda = c/f_s = 3.251 m, ~1.363 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.317 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.06953805344184334, + "omega_spring_rad_s": 11.877450768661326, + "f_spring_Hz": 1.8903550011630819, + "wave_speed_c_m_s": 6.146107446160909, + "wavelength_m": 3.251298006130797, + "wavelengths_in_string": 1.363478156233953 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 11.877 rad/s (period 0.529 s) with amplitude 0.0695 m.", + "Driven string carries a travelling wave of wavelength 3.251 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 0.662 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.260597201739357, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 36.76344709880514, + "unit": "", + "description": "" + }, + "L": { + "value": 4.433073810766347, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.12453334035331415, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.704201693834661, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.6621483869772022, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.31695816298860396, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/216/params.json b/scipy/spring_mass_string_fixed/216/params.json new file mode 100644 index 0000000000000000000000000000000000000000..e8c3840826d801c3b795389f3a43698f1952b487 --- /dev/null +++ b/scipy/spring_mass_string_fixed/216/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.260597201739357, + "k_spring": 36.76344709880514, + "L": 4.433073810766347, + "mu": 0.12453334035331415, + "T_str": 4.704201693834661, + "gamma_w": 0.6621483869772022, + "tau_ramp": 0.31695816298860396, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/216/simulation_code.py b/scipy/spring_mass_string_fixed/216/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..7d66bf23f4495ca96e5973bbc5feb74696128dbe --- /dev/null +++ b/scipy/spring_mass_string_fixed/216/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.260597201739357 +k_spring = 36.76344709880514 +L = 4.433073810766347 +mu = 0.12453334035331415 +T_str = 4.704201693834661 +gamma_w = 0.6621483869772022 +tau_ramp = 0.31695816298860396 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/216/video.mp4 b/scipy/spring_mass_string_fixed/216/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c2e20b4eb4c8044c3f285ca170e602a8efadc355 --- /dev/null +++ b/scipy/spring_mass_string_fixed/216/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:560942990b06f8fec1d056d8e548cb23ef65bcb9d747c31f16d6e03d31c65a20 +size 35428 diff --git a/scipy/spring_mass_string_fixed/245/cot.json b/scipy/spring_mass_string_fixed/245/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..67de6157fe44dda8007f4e306dbe4e696d3eb1f9 --- /dev/null +++ b/scipy/spring_mass_string_fixed/245/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=26.827 N/m) hangs from a ceiling. A mass m=0.345 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.1261 m and angular frequency omega_s = \\sqrt(k/m) = 8.819 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=4.100 m, linear density mu=0.100 kg/m, tension T=4.020 N, giving wave speed c = \\sqrt(T/mu) = 6.352 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.1261 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 8.819 rad/s (= 1.404 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 6.352 m/s.", + "Driven wavelength: lambda = c/f_s = 4.526 m, ~0.906 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.450 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.126128704297873, + "omega_spring_rad_s": 8.81916639163721, + "f_spring_Hz": 1.4036139251789763, + "wave_speed_c_m_s": 6.3522895357520355, + "wavelength_m": 4.5256672235864635, + "wavelengths_in_string": 0.9058925536488223 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 8.819 rad/s (period 0.712 s) with amplitude 0.1261 m.", + "Driven string carries a travelling wave of wavelength 4.526 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 1.355 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.34491999968759846, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 26.8270828260019, + "unit": "", + "description": "" + }, + "L": { + "value": 4.099768238139517, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.09961871076397066, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.01977261059719, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.3547443690439143, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.4496919242983394, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/245/params.json b/scipy/spring_mass_string_fixed/245/params.json new file mode 100644 index 0000000000000000000000000000000000000000..00b601a257f6fd304593679da10fe6c9791a5862 --- /dev/null +++ b/scipy/spring_mass_string_fixed/245/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.34491999968759846, + "k_spring": 26.8270828260019, + "L": 4.099768238139517, + "mu": 0.09961871076397066, + "T_str": 4.01977261059719, + "gamma_w": 1.3547443690439143, + "tau_ramp": 0.4496919242983394, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/245/simulation_code.py b/scipy/spring_mass_string_fixed/245/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..5a975535c97e559c01df0c41a10ce0446e2c9527 --- /dev/null +++ b/scipy/spring_mass_string_fixed/245/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.34491999968759846 +k_spring = 26.8270828260019 +L = 4.099768238139517 +mu = 0.09961871076397066 +T_str = 4.01977261059719 +gamma_w = 1.3547443690439143 +tau_ramp = 0.4496919242983394 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/245/video.mp4 b/scipy/spring_mass_string_fixed/245/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3ed6aecbc7efe96010242393861f74cbb03ecbfb --- /dev/null +++ b/scipy/spring_mass_string_fixed/245/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3af8090606513082cb4ff8304fb42ace41c210217cd96fad38fae0688721ab88 +size 44232 diff --git a/scipy/spring_mass_string_fixed/270/cot.json b/scipy/spring_mass_string_fixed/270/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ef998b8e952f73458007a43ff9e47a5a3bd6be5e --- /dev/null +++ b/scipy/spring_mass_string_fixed/270/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=38.432 N/m) hangs from a ceiling. A mass m=0.261 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0665 m and angular frequency omega_s = \\sqrt(k/m) = 12.145 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=4.396 m, linear density mu=0.115 kg/m, tension T=4.853 N, giving wave speed c = \\sqrt(T/mu) = 6.499 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0665 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 12.145 rad/s (= 1.933 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 6.499 m/s.", + "Driven wavelength: lambda = c/f_s = 3.362 m, ~1.307 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.473 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.06650865288873267, + "omega_spring_rad_s": 12.144941520911994, + "f_spring_Hz": 1.9329274766151452, + "wave_speed_c_m_s": 6.498593871339443, + "wavelength_m": 3.3620474383857823, + "wavelengths_in_string": 1.3074840479365002 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 12.145 rad/s (period 0.517 s) with amplitude 0.0665 m.", + "Driven string carries a travelling wave of wavelength 3.362 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 1.057 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.2605546602230483, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 38.43170934561398, + "unit": "", + "description": "" + }, + "L": { + "value": 4.395823394095184, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.11492218524778593, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.853361814023509, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.0566451904900518, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.47290055833055705, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/270/params.json b/scipy/spring_mass_string_fixed/270/params.json new file mode 100644 index 0000000000000000000000000000000000000000..353ac1bbd836d18b49f379492434ffc3696d9228 --- /dev/null +++ b/scipy/spring_mass_string_fixed/270/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.2605546602230483, + "k_spring": 38.43170934561398, + "L": 4.395823394095184, + "mu": 0.11492218524778593, + "T_str": 4.853361814023509, + "gamma_w": 1.0566451904900518, + "tau_ramp": 0.47290055833055705, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/270/simulation_code.py b/scipy/spring_mass_string_fixed/270/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d869012bdf341e9153c6b999cecd43c9fc5540ee --- /dev/null +++ b/scipy/spring_mass_string_fixed/270/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.2605546602230483 +k_spring = 38.43170934561398 +L = 4.395823394095184 +mu = 0.11492218524778593 +T_str = 4.853361814023509 +gamma_w = 1.0566451904900518 +tau_ramp = 0.47290055833055705 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/270/video.mp4 b/scipy/spring_mass_string_fixed/270/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..08891a62ba243cb751e98cec004b027c193d83af --- /dev/null +++ b/scipy/spring_mass_string_fixed/270/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:17df836ff94bfe5020a2e2329f849a9305913df38a4fa40187280f0b9f78457d +size 30983 diff --git a/scipy/spring_mass_string_fixed/565/cot.json b/scipy/spring_mass_string_fixed/565/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4388e36e202ec568f1c00ea72fa3eccedba2e5f6 --- /dev/null +++ b/scipy/spring_mass_string_fixed/565/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=27.722 N/m) hangs from a ceiling. A mass m=0.233 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0824 m and angular frequency omega_s = \\sqrt(k/m) = 10.914 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=4.168 m, linear density mu=0.136 kg/m, tension T=4.994 N, giving wave speed c = \\sqrt(T/mu) = 6.064 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0824 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 10.914 rad/s (= 1.737 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 6.064 m/s.", + "Driven wavelength: lambda = c/f_s = 3.491 m, ~1.194 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.368 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.0823635352887381, + "omega_spring_rad_s": 10.913574411226357, + "f_spring_Hz": 1.736949314347896, + "wave_speed_c_m_s": 6.064296921035419, + "wavelength_m": 3.4913493853516053, + "wavelengths_in_string": 1.1939002606422493 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 10.914 rad/s (period 0.576 s) with amplitude 0.0824 m.", + "Driven string carries a travelling wave of wavelength 3.491 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 0.708 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.23274990312289334, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 27.721934732781992, + "unit": "", + "description": "" + }, + "L": { + "value": 4.168322941164439, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.1357875562046257, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.9936820432419005, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.7077178034126562, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.36775251026945543, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/565/params.json b/scipy/spring_mass_string_fixed/565/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5db7a226525bd5591baf9eda8f47a9ca53e07fbc --- /dev/null +++ b/scipy/spring_mass_string_fixed/565/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.23274990312289334, + "k_spring": 27.721934732781992, + "L": 4.168322941164439, + "mu": 0.1357875562046257, + "T_str": 4.9936820432419005, + "gamma_w": 0.7077178034126562, + "tau_ramp": 0.36775251026945543, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/565/simulation_code.py b/scipy/spring_mass_string_fixed/565/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..85748f64757111e08fc7a1e2cedae38b544b2a09 --- /dev/null +++ b/scipy/spring_mass_string_fixed/565/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.23274990312289334 +k_spring = 27.721934732781992 +L = 4.168322941164439 +mu = 0.1357875562046257 +T_str = 4.9936820432419005 +gamma_w = 0.7077178034126562 +tau_ramp = 0.36775251026945543 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/565/video.mp4 b/scipy/spring_mass_string_fixed/565/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..074e6746226b43ebe995d56c1bee994129d7a690 --- /dev/null +++ b/scipy/spring_mass_string_fixed/565/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d03c0804da2f2400af25f14e5a396652a7007c4e4b5daa6749a3ec2c9a4ccbb5 +size 35883 diff --git a/scipy/spring_mass_string_fixed/582/cot.json b/scipy/spring_mass_string_fixed/582/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..a7855301139653bdd65004d8804c5c0f2c721e4a --- /dev/null +++ b/scipy/spring_mass_string_fixed/582/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=28.280 N/m) hangs from a ceiling. A mass m=0.203 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0703 m and angular frequency omega_s = \\sqrt(k/m) = 11.815 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=3.810 m, linear density mu=0.133 kg/m, tension T=4.321 N, giving wave speed c = \\sqrt(T/mu) = 5.697 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0703 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 11.815 rad/s (= 1.880 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 5.697 m/s.", + "Driven wavelength: lambda = c/f_s = 3.030 m, ~1.257 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.355 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.07027645822180024, + "omega_spring_rad_s": 11.814886957474558, + "f_spring_Hz": 1.8803976613540399, + "wave_speed_c_m_s": 5.69678266031518, + "wavelength_m": 3.0295627235640312, + "wavelengths_in_string": 1.2574527331919205 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 11.815 rad/s (period 0.532 s) with amplitude 0.0703 m.", + "Driven string carries a travelling wave of wavelength 3.030 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 1.373 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.20259004881133647, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 28.279859701619152, + "unit": "", + "description": "" + }, + "L": { + "value": 3.80953192712195, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.133130249571998, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.320520278980736, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.3733514733048886, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.35516607971061437, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/582/params.json b/scipy/spring_mass_string_fixed/582/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5389ec6c4bd7b4dc46313c3eb90d9d8bb8e15536 --- /dev/null +++ b/scipy/spring_mass_string_fixed/582/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.20259004881133647, + "k_spring": 28.279859701619152, + "L": 3.80953192712195, + "mu": 0.133130249571998, + "T_str": 4.320520278980736, + "gamma_w": 1.3733514733048886, + "tau_ramp": 0.35516607971061437, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/582/simulation_code.py b/scipy/spring_mass_string_fixed/582/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ea165cf13daeb55f300f5f2b6ad4dd21e1b43724 --- /dev/null +++ b/scipy/spring_mass_string_fixed/582/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.20259004881133647 +k_spring = 28.279859701619152 +L = 3.80953192712195 +mu = 0.133130249571998 +T_str = 4.320520278980736 +gamma_w = 1.3733514733048886 +tau_ramp = 0.35516607971061437 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/582/video.mp4 b/scipy/spring_mass_string_fixed/582/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..85e3d32318142d270504d2facd8a359ba6f017ba --- /dev/null +++ b/scipy/spring_mass_string_fixed/582/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e5aeb180feb6d6a54a00f039935097cd5afcbb3e4874b7b92083d19f1fcbcf59 +size 35463 diff --git a/scipy/spring_mass_string_fixed/624/cot.json b/scipy/spring_mass_string_fixed/624/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..6ed5a69852f15f1d5b49b3a9c4679e1623169981 --- /dev/null +++ b/scipy/spring_mass_string_fixed/624/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=26.876 N/m) hangs from a ceiling. A mass m=0.392 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.1430 m and angular frequency omega_s = \\sqrt(k/m) = 8.282 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=3.554 m, linear density mu=0.089 kg/m, tension T=4.254 N, giving wave speed c = \\sqrt(T/mu) = 6.926 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.1430 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 8.282 rad/s (= 1.318 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 6.926 m/s.", + "Driven wavelength: lambda = c/f_s = 5.254 m, ~0.676 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.379 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.14303158411823405, + "omega_spring_rad_s": 8.281681598339665, + "f_spring_Hz": 1.3180705634889462, + "wave_speed_c_m_s": 6.925527116906398, + "wavelength_m": 5.254291620453504, + "wavelengths_in_string": 0.6763542194019149 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 8.282 rad/s (period 0.759 s) with amplitude 0.1430 m.", + "Driven string carries a travelling wave of wavelength 5.254 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 1.056 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.39185627504548065, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 26.875952482065166, + "unit": "", + "description": "" + }, + "L": { + "value": 3.553762307461852, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.08870365054824066, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.254486613603986, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.0558589563158982, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.3786485685570441, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/624/params.json b/scipy/spring_mass_string_fixed/624/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8a9198f134878a64c86fd7c67387588259356ac8 --- /dev/null +++ b/scipy/spring_mass_string_fixed/624/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.39185627504548065, + "k_spring": 26.875952482065166, + "L": 3.553762307461852, + "mu": 0.08870365054824066, + "T_str": 4.254486613603986, + "gamma_w": 1.0558589563158982, + "tau_ramp": 0.3786485685570441, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/624/simulation_code.py b/scipy/spring_mass_string_fixed/624/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..0b97b86a14b45ef12ad1165bee5f5b28f57a0124 --- /dev/null +++ b/scipy/spring_mass_string_fixed/624/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.39185627504548065 +k_spring = 26.875952482065166 +L = 3.553762307461852 +mu = 0.08870365054824066 +T_str = 4.254486613603986 +gamma_w = 1.0558589563158982 +tau_ramp = 0.3786485685570441 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/624/video.mp4 b/scipy/spring_mass_string_fixed/624/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..13772b421ae7f60f9084b2dad6ba887fec270db8 --- /dev/null +++ b/scipy/spring_mass_string_fixed/624/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:093d336de65f0979d243f0b1edb272c225f21ed05b8e888231186fbc69e338e2 +size 43993 diff --git a/scipy/spring_mass_string_fixed/635/cot.json b/scipy/spring_mass_string_fixed/635/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..837d97d909ebf2e24b19658d132dde465a7ffc56 --- /dev/null +++ b/scipy/spring_mass_string_fixed/635/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=38.564 N/m) hangs from a ceiling. A mass m=0.242 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0615 m and angular frequency omega_s = \\sqrt(k/m) = 12.630 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=3.602 m, linear density mu=0.125 kg/m, tension T=4.310 N, giving wave speed c = \\sqrt(T/mu) = 5.880 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0615 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 12.630 rad/s (= 2.010 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 5.880 m/s.", + "Driven wavelength: lambda = c/f_s = 2.925 m, ~1.231 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.403 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.061496432290929666, + "omega_spring_rad_s": 12.630180093934666, + "f_spring_Hz": 2.010155594090561, + "wave_speed_c_m_s": 5.879961807391617, + "wavelength_m": 2.9251276989092196, + "wavelengths_in_string": 1.2313770143701857 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 12.630 rad/s (period 0.497 s) with amplitude 0.0615 m.", + "Driven string carries a travelling wave of wavelength 2.925 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 0.980 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.24174772665986533, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 38.56394769884995, + "unit": "", + "description": "" + }, + "L": { + "value": 3.601935012534366, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.12464662296833329, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.309526216921392, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.9798644673872764, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.4028744608626274, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/635/params.json b/scipy/spring_mass_string_fixed/635/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ee7f984f7440fa973c6b59e68d6e9230175af279 --- /dev/null +++ b/scipy/spring_mass_string_fixed/635/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.24174772665986533, + "k_spring": 38.56394769884995, + "L": 3.601935012534366, + "mu": 0.12464662296833329, + "T_str": 4.309526216921392, + "gamma_w": 0.9798644673872764, + "tau_ramp": 0.4028744608626274, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/635/simulation_code.py b/scipy/spring_mass_string_fixed/635/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..3599f6e06a832cf12dc1c2dac60dc6c97596bbc0 --- /dev/null +++ b/scipy/spring_mass_string_fixed/635/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.24174772665986533 +k_spring = 38.56394769884995 +L = 3.601935012534366 +mu = 0.12464662296833329 +T_str = 4.309526216921392 +gamma_w = 0.9798644673872764 +tau_ramp = 0.4028744608626274 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/635/video.mp4 b/scipy/spring_mass_string_fixed/635/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..fb6c4cb14ce995657908611a2a7a03eab808fec3 --- /dev/null +++ b/scipy/spring_mass_string_fixed/635/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d87d9e1cf134c4c9cf4b2b972074ed1a6ecb2c573f3d28d0931daf53d8b34a6b +size 35545 diff --git a/scipy/spring_mass_string_fixed/640/cot.json b/scipy/spring_mass_string_fixed/640/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..2b178d2c1fe3a3e5c8a00671e09d7c53b4269810 --- /dev/null +++ b/scipy/spring_mass_string_fixed/640/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=37.256 N/m) hangs from a ceiling. A mass m=0.214 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0563 m and angular frequency omega_s = \\sqrt(k/m) = 13.198 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=4.366 m, linear density mu=0.095 kg/m, tension T=4.455 N, giving wave speed c = \\sqrt(T/mu) = 6.839 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0563 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 13.198 rad/s (= 2.101 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 6.839 m/s.", + "Driven wavelength: lambda = c/f_s = 3.256 m, ~1.341 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.497 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.05631860571975791, + "omega_spring_rad_s": 13.198013141848728, + "f_spring_Hz": 2.1005290305170212, + "wave_speed_c_m_s": 6.83870595333089, + "wavelength_m": 3.255706469168684, + "wavelengths_in_string": 1.340904020750164 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 13.198 rad/s (period 0.476 s) with amplitude 0.0563 m.", + "Driven string carries a travelling wave of wavelength 3.256 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 0.682 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.21388713825274608, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 37.25647677963251, + "unit": "", + "description": "" + }, + "L": { + "value": 4.365589894890608, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.0952540320472122, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.4548309611880015, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.6823029065024564, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.4967733992436426, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/640/params.json b/scipy/spring_mass_string_fixed/640/params.json new file mode 100644 index 0000000000000000000000000000000000000000..bf71c62bee6a060373504f4387deab08b8cb31b2 --- /dev/null +++ b/scipy/spring_mass_string_fixed/640/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.21388713825274608, + "k_spring": 37.25647677963251, + "L": 4.365589894890608, + "mu": 0.0952540320472122, + "T_str": 4.4548309611880015, + "gamma_w": 0.6823029065024564, + "tau_ramp": 0.4967733992436426, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/640/simulation_code.py b/scipy/spring_mass_string_fixed/640/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..3eb833f393160e7083a67563078be7f9ec7907e3 --- /dev/null +++ b/scipy/spring_mass_string_fixed/640/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.21388713825274608 +k_spring = 37.25647677963251 +L = 4.365589894890608 +mu = 0.0952540320472122 +T_str = 4.4548309611880015 +gamma_w = 0.6823029065024564 +tau_ramp = 0.4967733992436426 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/640/video.mp4 b/scipy/spring_mass_string_fixed/640/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..fc69d13a35d2cd89e175360f971a19b8e70573b8 --- /dev/null +++ b/scipy/spring_mass_string_fixed/640/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bafd47b19ffeae7c92fa64e67f671b226c709629b644e085624bd9d086b38125 +size 32660 diff --git a/scipy/spring_mass_string_fixed/676/cot.json b/scipy/spring_mass_string_fixed/676/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ea997c8fab4db3847ca54a9f752361e0bceafcd0 --- /dev/null +++ b/scipy/spring_mass_string_fixed/676/cot.json @@ -0,0 +1,115 @@ +{ + "simulation": "spring_mass_string_fixed", + "physical_observation": "A vertical Hookean spring (k=39.160 N/m) hangs from a ceiling. A mass m=0.286 kg released from the unstretched length performs SHM about its equilibrium position with amplitude DeltaL_eq = m g / k = 0.0718 m and angular frequency omega_s = \\sqrt(k/m) = 11.692 rad/s. The mass's vertical motion drives the LEFT end of a horizontal taut string of length L=3.720 m, linear density mu=0.108 kg/m, tension T=3.966 N, giving wave speed c = \\sqrt(T/mu) = 6.071 m/s; the right end is fixed.", + "physical_law": { + "name": "Driven 1D wave equation with viscous damping + spring-mass SHM (Hooke + Newton)", + "statement": "Mass: m \\ddot{y}= -k (y - y_eq) (SHM with amplitude DeltaL_eq). String: u_tt = c^2 u_xx - 2 gamma_w u_t with Dirichlet BCs u(0, t) = ramp(t) y_mass(t) and u(L, t) = 0.", + "formula": "y(t) = DeltaL_eq \\cos(omega_s t); u_tt = c^2 u_xx - 2 gamma_w u_t" + }, + "ode_system": { + "state_variables": [ + "y(t) --- mass vertical displacement", + "u(x, t) --- transverse string displacement" + ], + "equations_latex": [ + "y(t) = (m g / k) \\cos(\\sqrt(k/m) t)", + "u_tt = (T/mu) u_xx - 2 gamma_w u_t, 0 < x < L", + "u(0, t) = (1 - \\exp(-t/tau_ramp)) \\cdot y(t), u(L, t) = 0" + ], + "equations_python": [ + "y(t) = (m * g / k) * np.cos ( np.sqrt (k/m) * t)", + "u_tt = (T/mu) * u_xx - 2 * gamma_w * u_t, 0 < x < L", + "u(0, t) = (1 - np.exp (-t/tau_ramp)) * y(t), u(L, t) = 0" + ] + }, + "derivation_steps": [ + "Spring equilibrium extension: DeltaL_eq = m g / k = 0.0718 m.", + "Spring-mass natural angular frequency: omega_s = \\sqrt(k/m) = 11.692 rad/s (= 1.861 Hz).", + "String wave speed: c = \\sqrt(T/mu) = 6.071 m/s.", + "Driven wavelength: lambda = c/f_s = 3.262 m, ~1.140 wavelengths fit on the string of length L.", + "Wave equation derivation: small-amplitude transverse string under tension T and density mu yields u_tt = (T/mu) u_xx; viscous damping adds -2 gamma_w u_t.", + "Smooth ramp-in (1 - \\exp(-t/tau_ramp)) with tau_ramp=0.312 s avoids the t=0 step discontinuity.", + "Right end fixed: u(L, t) = 0 (Dirichlet BC).", + "Numerical integration: explicit leapfrog FDM with centred-time damping, subject to CFL constraint (c dt / dx) ^2 < 1." + ], + "physical_constants_derived": { + "spring_extension_DeltaL_eq_m": 0.07176283060058086, + "omega_spring_rad_s": 11.691890070621406, + "f_spring_Hz": 1.8608220988264461, + "wave_speed_c_m_s": 6.070899383651626, + "wavelength_m": 3.2624824197220814, + "wavelengths_in_string": 1.1402113355683046 + }, + "numerical_method": { + "solver": "Explicit second-order leapfrog finite-difference for the wave equation; mass SHM treated analytically.", + "tolerance": "CFL factor (c dt / dx)^2 < 1 enforced; spatial grid with N=200 cells, 16 sub-steps per video frame.", + "justification": "Leapfrog is second-order, energy-stable, simple to implement; SHM is analytic so no integrator error from the source term." + }, + "code_validation": { + "ode_source": "Wave equation u_tt = c^2 u_xx with linear viscous damping; spring-mass SHM via Hooke's law.", + "energy_check": "Wave energy E = \\int ((mu/2) u_t^2 + (T/2) u_x^2) dx decays at rate 2 gamma_w E in the absence of forcing; with a sustained drive, E approaches a steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates sinusoidally at 11.692 rad/s (period 0.537 s) with amplitude 0.0718 m.", + "Driven string carries a travelling wave of wavelength 3.262 m, reflecting at the fixed right end with phase reversal.", + "Damping coefficient gamma_w = 1.139 1/s prevents long-time amplitude growth." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.2864665913574925, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 39.16006709459778, + "unit": "", + "description": "" + }, + "L": { + "value": 3.7199194370594286, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.10761503211140928, + "unit": "", + "description": "" + }, + "T_str": { + "value": 3.966240180305169, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.1388368803912385, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.31220903928973937, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_fixed/676/params.json b/scipy/spring_mass_string_fixed/676/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b41854b1298135e6e9238822755023cb5ffe7c16 --- /dev/null +++ b/scipy/spring_mass_string_fixed/676/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.2864665913574925, + "k_spring": 39.16006709459778, + "L": 3.7199194370594286, + "mu": 0.10761503211140928, + "T_str": 3.966240180305169, + "gamma_w": 1.1388368803912385, + "tau_ramp": 0.31220903928973937, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_fixed/676/simulation_code.py b/scipy/spring_mass_string_fixed/676/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e1d359e1ad762c3c2077f86fe83d489be5ffcbdc --- /dev/null +++ b/scipy/spring_mass_string_fixed/676/simulation_code.py @@ -0,0 +1,116 @@ +"""Spring-mass driven string + fixed end — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle + +g = 9.81 +m_mass = 0.2864665913574925 +k_spring = 39.16006709459778 +L = 3.7199194370594286 +mu = 0.10761503211140928 +T_str = 3.966240180305169 +gamma_w = 1.1388368803912385 +tau_ramp = 0.31220903928973937 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest= 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) +y_string_eq = 0.0; y_mass_eq = 0.0 +y_ceiling = L_spring_rest + DeltaL_eq + H_mass/2 + y_mass_eq +x_mass_c = -W_mass/2 +spring_x = x_mass_c + +def y_mass_at(t): + return DeltaL_eq * np.cos(omega_spring*t) +def ramp(t): + return 1.0 - np.exp(-t/tau_ramp) + +N = 200 +dx = L/N +x_grid = np.linspace(0.0, L, N+1) +n_per_frame = 16 +dt = 1.0/(fps*n_per_frame) +factor = (c*dt/dx)**2 +damp_n = 1.0/(1.0 + gamma_w*dt) +damp_p = 1.0 - gamma_w*dt + +u_curr = np.zeros(N+1) +u_prev = u_curr.copy() +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_curr.copy() +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame-1)/fps + (sub+1)*dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n*(2*u_curr[1:-1] - damp_p*u_prev[1:-1] + factor*lap_int) + u_next[-1] = 0.0 + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dxv, dyv = x2-x1, y2-y1 + Lc = np.hypot(dxv, dyv) + if Lc < 1e-9: return np.array([x1,x2]), np.array([y1,y2]) + ux, uy = dxv/Lc, dyv/Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s*Lc + middle = (arc >= lead) & (arc <= Lc-lead) + amp = np.where(middle, w*np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + return x1+ux*arc+nx*amp, y1+uy*arc+ny*amp + +fig_w, fig_h = 12.0, 4.5; fa = fig_w/fig_h +xlo_d = x_mass_c - W_mass/2 - 0.20 +xhi_d = L + 0.40 +ylo_d = -4.5*DeltaL_eq - 0.10 +yhi_d = y_ceiling + 0.10 +dx_d, dy_d = xhi_d-xlo_d, yhi_d-ylo_d +if dx_d/dy_d < fa: + e = (fa*dy_d-dx_d)/2; xlo, xhi, ylo, yhi = xlo_d-e, xhi_d+e, ylo_d, yhi_d +else: + e = (dx_d/fa-dy_d)/2; xlo, xhi, ylo, yhi = xlo_d, xhi_d, ylo_d-e, yhi_d+e + +fig = plt.figure(figsize=(fig_w,fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]) +ax.set_facecolor("#16213e") +ax.set_xlim(xlo,xhi); ax.set_ylim(ylo,yhi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(Rectangle((xlo, y_ceiling), xhi-xlo, yhi-y_ceiling, + facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([xlo,xhi], [y_ceiling,y_ceiling], color="#adb5bd", lw=2.0, zorder=1) + +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0) - H_mass/2), + W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +ax.add_patch(Rectangle((L, ylo), 0.12, yhi-ylo, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1.5, zorder=2)) +ax.plot([L,L], [ylo,yhi], color="#adb5bd", lw=2.0, zorder=3) +ax.add_patch(Circle((L,0), 0.05, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=5)) +str_line, = ax.plot([],[], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f/fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((spring_x, y_ceiling), (spring_x, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + str_line.set_data(x_grid, U_frames[f]) + return mass_patch, spring_line, str_line + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_fixed/676/video.mp4 b/scipy/spring_mass_string_fixed/676/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..521a0560b3e4d9d94e593005549997b5d6c3ed11 --- /dev/null +++ b/scipy/spring_mass_string_fixed/676/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e779bb3ee7cae8bfe07d7c33beef14caafccd563e3c22d7ee6dc5fb6eddd66e1 +size 37529 diff --git a/scipy/spring_mass_string_ring/002/cot.json b/scipy/spring_mass_string_ring/002/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..6e1616c0c4ff6b52a8c411150fe3d873114f3316 --- /dev/null +++ b/scipy/spring_mass_string_ring/002/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=49.320 N/m hangs from a ceiling; a cubical mass of m=0.436 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.0867 m and angular frequency omega_spring=10.636 rad/s. The mass drives the left end of a horizontal string (length L=4.044 m, tension T=3.926 N, mu=0.151 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.0867 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 10.636 rad/s.", + "Period: T = 2 pi/omega_spring = 0.591 s, frequency = 1.693 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(3.926/0.151) = 5.091 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 3.007 m, so 1.345 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.08672225975821533, + "omega_spring_rad_per_s": 10.635776701377553, + "f_spring_Hz": 1.6927364356458507, + "T_spring_period_s": 0.5907594229921904, + "c_phase_speed_mps": 5.090883210117415, + "lambda_m": 3.007487227729594, + "n_wavelengths_in_L": 1.3447042780163105, + "tau_ramp_s": 0.3709314041498679 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=10.636 rad/s with amplitude 0.0867 m.", + "Wave train propagates rightward at c=5.091 m/s; leading edge reaches the ring at t = L/c = 0.794 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.43599897723415115, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 49.32009357910951, + "unit": "", + "description": "" + }, + "L": { + "value": 4.044180941207399, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.15147225843135248, + "unit": "", + "description": "" + }, + "T_str": { + "value": 3.9257204358639406, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.7010013106514008, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.3709314041498679, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/002/params.json b/scipy/spring_mass_string_ring/002/params.json new file mode 100644 index 0000000000000000000000000000000000000000..d7788fa10ece5901790fc1b52ebeda9fd5be5946 --- /dev/null +++ b/scipy/spring_mass_string_ring/002/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.43599897723415115, + "k_spring": 49.32009357910951, + "L": 4.044180941207399, + "mu": 0.15147225843135248, + "T_str": 3.9257204358639406, + "gamma_w": 1.7010013106514008, + "tau_ramp": 0.3709314041498679, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/002/simulation_code.py b/scipy/spring_mass_string_ring/002/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..75a94c76ed83abf7ac3efe05884cd32ad3b8e166 --- /dev/null +++ b/scipy/spring_mass_string_ring/002/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.43599897723415115 +k_spring = 49.32009357910951 +L = 4.044180941207399 +mu = 0.15147225843135248 +T_str = 3.9257204358639406 +gamma_w = 1.7010013106514008 +tau_ramp = 0.3709314041498679 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/002/video.mp4 b/scipy/spring_mass_string_ring/002/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..bfc3ad53b2da62b374b17a12b87eae4a08991621 --- /dev/null +++ b/scipy/spring_mass_string_ring/002/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a451b7f740a06bfc0fe9fa3d4f7daa0389b27ed45c7692c86090bff6d81de7e +size 38319 diff --git a/scipy/spring_mass_string_ring/033/cot.json b/scipy/spring_mass_string_ring/033/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f5d7f4dcdfae133b086a980eb56cd381a06cb0ef --- /dev/null +++ b/scipy/spring_mass_string_ring/033/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=21.613 N/m hangs from a ceiling; a cubical mass of m=0.279 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.1268 m and angular frequency omega_spring=8.796 rad/s. The mass drives the left end of a horizontal string (length L=3.771 m, tension T=5.844 N, mu=0.144 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.1268 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 8.796 rad/s.", + "Period: T = 2 pi/omega_spring = 0.714 s, frequency = 1.400 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(5.844/0.144) = 6.370 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 4.550 m, so 0.829 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.12678132149565824, + "omega_spring_rad_per_s": 8.796438416049465, + "f_spring_Hz": 1.3999966555177146, + "T_spring_period_s": 0.7142874206583036, + "c_phase_speed_mps": 6.370231632282054, + "lambda_m": 4.550176321618683, + "n_wavelengths_in_L": 0.828839463722978, + "tau_ramp_s": 0.378246307630972 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=8.796 rad/s with amplitude 0.1268 m.", + "Wave train propagates rightward at c=6.370 m/s; leading edge reaches the ring at t = L/c = 0.592 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.2793252005116661, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 21.613437884170384, + "unit": "", + "description": "" + }, + "L": { + "value": 3.771365702255422, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.1440130760975307, + "unit": "", + "description": "" + }, + "T_str": { + "value": 5.844029177135568, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.1520117853035976, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.378246307630972, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/033/params.json b/scipy/spring_mass_string_ring/033/params.json new file mode 100644 index 0000000000000000000000000000000000000000..0a20274cac9951d18afb788f100e9d71e7f0f8ce --- /dev/null +++ b/scipy/spring_mass_string_ring/033/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.2793252005116661, + "k_spring": 21.613437884170384, + "L": 3.771365702255422, + "mu": 0.1440130760975307, + "T_str": 5.844029177135568, + "gamma_w": 1.1520117853035976, + "tau_ramp": 0.378246307630972, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/033/simulation_code.py b/scipy/spring_mass_string_ring/033/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..13f290316630e3552a096fc923822d10ffec70f3 --- /dev/null +++ b/scipy/spring_mass_string_ring/033/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.2793252005116661 +k_spring = 21.613437884170384 +L = 3.771365702255422 +mu = 0.1440130760975307 +T_str = 5.844029177135568 +gamma_w = 1.1520117853035976 +tau_ramp = 0.378246307630972 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/033/video.mp4 b/scipy/spring_mass_string_ring/033/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..7a6cb499a404b59da56cd1e24cf6720f4ce673db --- /dev/null +++ b/scipy/spring_mass_string_ring/033/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbd9d46a61f1cc1dcdb0e7b1dc6fb8f023ef6a23d7e7ba81e1f5614f12182e60 +size 52052 diff --git a/scipy/spring_mass_string_ring/072/cot.json b/scipy/spring_mass_string_ring/072/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..bdaffd26ea00fd32e7fc324225e5ba67b3607cf7 --- /dev/null +++ b/scipy/spring_mass_string_ring/072/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=58.660 N/m hangs from a ceiling; a cubical mass of m=0.309 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.0516 m and angular frequency omega_spring=13.786 rad/s. The mass drives the left end of a horizontal string (length L=4.423 m, tension T=5.801 N, mu=0.063 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.0516 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 13.786 rad/s.", + "Period: T = 2 pi/omega_spring = 0.456 s, frequency = 2.194 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(5.801/0.063) = 9.621 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 4.385 m, so 1.009 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.051617335815845135, + "omega_spring_rad_per_s": 13.78595038527726, + "f_spring_Hz": 2.194102149036495, + "T_spring_period_s": 0.45576729435278757, + "c_phase_speed_mps": 9.621315922568137, + "lambda_m": 4.385081126142273, + "n_wavelengths_in_L": 1.008577919821765, + "tau_ramp_s": 0.43157574669784393 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=13.786 rad/s with amplitude 0.0516 m.", + "Wave train propagates rightward at c=9.621 m/s; leading edge reaches the ring at t = L/c = 0.460 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.30865176187085264, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 58.66001675785035, + "unit": "", + "description": "" + }, + "L": { + "value": 4.422696000454256, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.06266685003956432, + "unit": "", + "description": "" + }, + "T_str": { + "value": 5.801052766574564, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.5601339085953925, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.43157574669784393, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/072/params.json b/scipy/spring_mass_string_ring/072/params.json new file mode 100644 index 0000000000000000000000000000000000000000..03c214e63849035b88281c008d0c8fed02841559 --- /dev/null +++ b/scipy/spring_mass_string_ring/072/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.30865176187085264, + "k_spring": 58.66001675785035, + "L": 4.422696000454256, + "mu": 0.06266685003956432, + "T_str": 5.801052766574564, + "gamma_w": 1.5601339085953925, + "tau_ramp": 0.43157574669784393, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/072/simulation_code.py b/scipy/spring_mass_string_ring/072/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..40e2fd4b667962eaca5482f4e4acde3d308b36a9 --- /dev/null +++ b/scipy/spring_mass_string_ring/072/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.30865176187085264 +k_spring = 58.66001675785035 +L = 4.422696000454256 +mu = 0.06266685003956432 +T_str = 5.801052766574564 +gamma_w = 1.5601339085953925 +tau_ramp = 0.43157574669784393 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/072/video.mp4 b/scipy/spring_mass_string_ring/072/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..2969c1ab17050cb00dae5007f6f83cd31d1aa375 --- /dev/null +++ b/scipy/spring_mass_string_ring/072/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f396f5723f77db0f076ff0a383d5872c680ddf46a1a62eee910fde4283ce3d1 +size 32731 diff --git a/scipy/spring_mass_string_ring/076/cot.json b/scipy/spring_mass_string_ring/076/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..9b23c327ef269d112ae7b807a7e5ed7cfa73b8ad --- /dev/null +++ b/scipy/spring_mass_string_ring/076/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=30.912 N/m hangs from a ceiling; a cubical mass of m=0.340 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.1079 m and angular frequency omega_spring=9.534 rad/s. The mass drives the left end of a horizontal string (length L=4.129 m, tension T=4.924 N, mu=0.168 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.1079 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 9.534 rad/s.", + "Period: T = 2 pi/omega_spring = 0.659 s, frequency = 1.517 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(4.924/0.168) = 5.420 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 3.572 m, so 1.156 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.10793086420936868, + "omega_spring_rad_per_s": 9.533704274496086, + "f_spring_Hz": 1.517336161262384, + "T_spring_period_s": 0.6590497383045469, + "c_phase_speed_mps": 5.420388725480582, + "lambda_m": 3.5723057710368944, + "n_wavelengths_in_L": 1.1559239009869882, + "tau_ramp_s": 0.4247978766217134 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=9.534 rad/s with amplitude 0.1079 m.", + "Wave train propagates rightward at c=5.420 m/s; leading edge reaches the ring at t = L/c = 0.762 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.3400976662408841, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 30.911992878617834, + "unit": "", + "description": "" + }, + "L": { + "value": 4.129313622375298, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.167592506499939, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.923970731926816, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.839625672237217, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.4247978766217134, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/076/params.json b/scipy/spring_mass_string_ring/076/params.json new file mode 100644 index 0000000000000000000000000000000000000000..fb68b4e6be6af2bd30972ca6661d12a736986e02 --- /dev/null +++ b/scipy/spring_mass_string_ring/076/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.3400976662408841, + "k_spring": 30.911992878617834, + "L": 4.129313622375298, + "mu": 0.167592506499939, + "T_str": 4.923970731926816, + "gamma_w": 1.839625672237217, + "tau_ramp": 0.4247978766217134, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/076/simulation_code.py b/scipy/spring_mass_string_ring/076/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ad013afcd4bd608744f81e157ac6ff32437ff7f4 --- /dev/null +++ b/scipy/spring_mass_string_ring/076/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.3400976662408841 +k_spring = 30.911992878617834 +L = 4.129313622375298 +mu = 0.167592506499939 +T_str = 4.923970731926816 +gamma_w = 1.839625672237217 +tau_ramp = 0.4247978766217134 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/076/video.mp4 b/scipy/spring_mass_string_ring/076/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..97c282b964ed053cd864475985a077890abc993d --- /dev/null +++ b/scipy/spring_mass_string_ring/076/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d98be5f7c258c9222fa03e0192305403b5f906e122385240be14e9a7b73f55f +size 43117 diff --git a/scipy/spring_mass_string_ring/160/cot.json b/scipy/spring_mass_string_ring/160/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..eab1f3df393daa7232097a32aa4ac5d716d9dad9 --- /dev/null +++ b/scipy/spring_mass_string_ring/160/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=30.919 N/m hangs from a ceiling; a cubical mass of m=0.434 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.1376 m and angular frequency omega_spring=8.443 rad/s. The mass drives the left end of a horizontal string (length L=4.556 m, tension T=5.075 N, mu=0.099 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.1376 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 8.443 rad/s.", + "Period: T = 2 pi/omega_spring = 0.744 s, frequency = 1.344 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(5.075/0.099) = 7.145 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 5.317 m, so 0.857 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.13760747810723467, + "omega_spring_rad_per_s": 8.443324599285319, + "f_spring_Hz": 1.3437968461056549, + "T_spring_period_s": 0.7441601034397545, + "c_phase_speed_mps": 7.145002661380008, + "lambda_m": 5.3170259195698675, + "n_wavelengths_in_L": 0.8568671674883527, + "tau_ramp_s": 0.3099037497543413 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=8.443 rad/s with amplitude 0.1376 m.", + "Wave train propagates rightward at c=7.145 m/s; leading edge reaches the ring at t = L/c = 0.638 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.4337131471795357, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 30.91929328517761, + "unit": "", + "description": "" + }, + "L": { + "value": 4.555984939163986, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.09941223611584259, + "unit": "", + "description": "" + }, + "T_str": { + "value": 5.0751003320152, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.3553429722070889, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.3099037497543413, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/160/params.json b/scipy/spring_mass_string_ring/160/params.json new file mode 100644 index 0000000000000000000000000000000000000000..0ca3b89e6da64bae390d9e80e9cf7cdaf5fbdb66 --- /dev/null +++ b/scipy/spring_mass_string_ring/160/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.4337131471795357, + "k_spring": 30.91929328517761, + "L": 4.555984939163986, + "mu": 0.09941223611584259, + "T_str": 5.0751003320152, + "gamma_w": 1.3553429722070889, + "tau_ramp": 0.3099037497543413, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/160/simulation_code.py b/scipy/spring_mass_string_ring/160/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d4a62ff4001d16b33a79c0adf398e43e4b445f6f --- /dev/null +++ b/scipy/spring_mass_string_ring/160/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.4337131471795357 +k_spring = 30.91929328517761 +L = 4.555984939163986 +mu = 0.09941223611584259 +T_str = 5.0751003320152 +gamma_w = 1.3553429722070889 +tau_ramp = 0.3099037497543413 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/160/video.mp4 b/scipy/spring_mass_string_ring/160/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9ce12667e163e94df59a7c13a6396472a247c44d --- /dev/null +++ b/scipy/spring_mass_string_ring/160/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3e32a3f6e19e7395df05e87d71030992522632ab5e7fa7bee804852fef1339b +size 47732 diff --git a/scipy/spring_mass_string_ring/237/cot.json b/scipy/spring_mass_string_ring/237/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..0237e1ee4860afaf21a3178224faec2f27e47a61 --- /dev/null +++ b/scipy/spring_mass_string_ring/237/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=53.286 N/m hangs from a ceiling; a cubical mass of m=0.365 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.0673 m and angular frequency omega_spring=12.076 rad/s. The mass drives the left end of a horizontal string (length L=3.785 m, tension T=4.661 N, mu=0.069 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.0673 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 12.076 rad/s.", + "Period: T = 2 pi/omega_spring = 0.520 s, frequency = 1.922 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(4.661/0.069) = 8.199 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 4.266 m, so 0.887 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.06727488417208093, + "omega_spring_rad_per_s": 12.075580692132215, + "f_spring_Hz": 1.921888357857893, + "T_spring_period_s": 0.520321586793202, + "c_phase_speed_mps": 8.199105440586566, + "lambda_m": 4.266171553130777, + "n_wavelengths_in_L": 0.8872631060053623, + "tau_ramp_s": 0.43383329778218777 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=12.076 rad/s with amplitude 0.0673 m.", + "Wave train propagates rightward at c=8.199 m/s; leading edge reaches the ring at t = L/c = 0.462 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.365424670179167, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 53.28609716054074, + "unit": "", + "description": "" + }, + "L": { + "value": 3.7852166229825333, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.06933114828055201, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.660809324231683, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.363289665772463, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.43383329778218777, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/237/params.json b/scipy/spring_mass_string_ring/237/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3f1a99bfb5cc96fc956b02522a3b223e45f00c60 --- /dev/null +++ b/scipy/spring_mass_string_ring/237/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.365424670179167, + "k_spring": 53.28609716054074, + "L": 3.7852166229825333, + "mu": 0.06933114828055201, + "T_str": 4.660809324231683, + "gamma_w": 1.363289665772463, + "tau_ramp": 0.43383329778218777, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/237/simulation_code.py b/scipy/spring_mass_string_ring/237/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..43ce61f8ec98455e66e281d912d4be3138d343af --- /dev/null +++ b/scipy/spring_mass_string_ring/237/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.365424670179167 +k_spring = 53.28609716054074 +L = 3.7852166229825333 +mu = 0.06933114828055201 +T_str = 4.660809324231683 +gamma_w = 1.363289665772463 +tau_ramp = 0.43383329778218777 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/237/video.mp4 b/scipy/spring_mass_string_ring/237/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..fdb8e8b6a071d7f7dde78544948901bbb9493d9d --- /dev/null +++ b/scipy/spring_mass_string_ring/237/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eae5f9d7ea9ab975543e0c076b64acb44ed0ea4730f75a988ed362d87b35aa4f +size 41924 diff --git a/scipy/spring_mass_string_ring/239/cot.json b/scipy/spring_mass_string_ring/239/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ddaf6fb0fbdeebd5e57590878ff730f4c9839a54 --- /dev/null +++ b/scipy/spring_mass_string_ring/239/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=49.665 N/m hangs from a ceiling; a cubical mass of m=0.252 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.0497 m and angular frequency omega_spring=14.053 rad/s. The mass drives the left end of a horizontal string (length L=4.366 m, tension T=4.644 N, mu=0.096 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.0497 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 14.053 rad/s.", + "Period: T = 2 pi/omega_spring = 0.447 s, frequency = 2.237 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(4.644/0.096) = 6.957 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 3.111 m, so 1.404 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.04967696929478053, + "omega_spring_rad_per_s": 14.052608833803662, + "f_spring_Hz": 2.2365421592366874, + "T_spring_period_s": 0.4471187792593596, + "c_phase_speed_mps": 6.957226223882156, + "lambda_m": 3.1107064962533935, + "n_wavelengths_in_L": 1.4036422708100214, + "tau_ramp_s": 0.34812983639367606 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=14.053 rad/s with amplitude 0.0497 m.", + "Wave train propagates rightward at c=6.957 m/s; leading edge reaches the ring at t = L/c = 0.628 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.251500636562412, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 49.66529318720916, + "unit": "", + "description": "" + }, + "L": { + "value": 4.366319130224598, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.09593943650589648, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.643756231499195, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.966199384581667, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.34812983639367606, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/239/params.json b/scipy/spring_mass_string_ring/239/params.json new file mode 100644 index 0000000000000000000000000000000000000000..2f698a22eb82bdf03abd295c1d07f8ba90c937d8 --- /dev/null +++ b/scipy/spring_mass_string_ring/239/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.251500636562412, + "k_spring": 49.66529318720916, + "L": 4.366319130224598, + "mu": 0.09593943650589648, + "T_str": 4.643756231499195, + "gamma_w": 0.966199384581667, + "tau_ramp": 0.34812983639367606, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/239/simulation_code.py b/scipy/spring_mass_string_ring/239/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e2a6ac357b416251b83dbc8d544aab9b8830630d --- /dev/null +++ b/scipy/spring_mass_string_ring/239/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.251500636562412 +k_spring = 49.66529318720916 +L = 4.366319130224598 +mu = 0.09593943650589648 +T_str = 4.643756231499195 +gamma_w = 0.966199384581667 +tau_ramp = 0.34812983639367606 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/239/video.mp4 b/scipy/spring_mass_string_ring/239/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6deab659e5d3be9a48546000fbf049a38fe4bc14 --- /dev/null +++ b/scipy/spring_mass_string_ring/239/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36f2453579a8e0f3e0f21aaca6a87a757744ce97e6f574647f3536616b61d057 +size 37276 diff --git a/scipy/spring_mass_string_ring/289/cot.json b/scipy/spring_mass_string_ring/289/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..a90ad879679ebb370ea1193576987e9750977b56 --- /dev/null +++ b/scipy/spring_mass_string_ring/289/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=29.683 N/m hangs from a ceiling; a cubical mass of m=0.245 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.0808 m and angular frequency omega_spring=11.016 rad/s. The mass drives the left end of a horizontal string (length L=3.590 m, tension T=5.512 N, mu=0.179 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.0808 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 11.016 rad/s.", + "Period: T = 2 pi/omega_spring = 0.570 s, frequency = 1.753 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(5.512/0.179) = 5.553 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 3.167 m, so 1.134 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.08084318654577936, + "omega_spring_rad_per_s": 11.015717553459258, + "f_spring_Hz": 1.7532059003372007, + "T_spring_period_s": 0.5703836610449841, + "c_phase_speed_mps": 5.552917806862582, + "lambda_m": 3.167293588160163, + "n_wavelengths_in_L": 1.1336139394244158, + "tau_ramp_s": 0.3943141875985837 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=11.016 rad/s with amplitude 0.0808 m.", + "Wave train propagates rightward at c=5.553 m/s; leading edge reaches the ring at t = L/c = 0.647 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.24461404919443205, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 29.682944539036846, + "unit": "", + "description": "" + }, + "L": { + "value": 3.5904881617879356, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.17877021172548896, + "unit": "", + "description": "" + }, + "T_str": { + "value": 5.512360916803528, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.253074482012304, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.3943141875985837, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/289/params.json b/scipy/spring_mass_string_ring/289/params.json new file mode 100644 index 0000000000000000000000000000000000000000..d06b16046f2c36e9d2b77e5e47d805b6670941bd --- /dev/null +++ b/scipy/spring_mass_string_ring/289/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.24461404919443205, + "k_spring": 29.682944539036846, + "L": 3.5904881617879356, + "mu": 0.17877021172548896, + "T_str": 5.512360916803528, + "gamma_w": 1.253074482012304, + "tau_ramp": 0.3943141875985837, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/289/simulation_code.py b/scipy/spring_mass_string_ring/289/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..9db12df5dfee08cedbd6a60121913f267e4ba033 --- /dev/null +++ b/scipy/spring_mass_string_ring/289/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.24461404919443205 +k_spring = 29.682944539036846 +L = 3.5904881617879356 +mu = 0.17877021172548896 +T_str = 5.512360916803528 +gamma_w = 1.253074482012304 +tau_ramp = 0.3943141875985837 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/289/video.mp4 b/scipy/spring_mass_string_ring/289/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ff3163936a402d77442e71e44402a6018f73e880 --- /dev/null +++ b/scipy/spring_mass_string_ring/289/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d115f0e97408399a15e43332dbb81802b05f2d956c0ec808f30b9d33807b2217 +size 46706 diff --git a/scipy/spring_mass_string_ring/295/cot.json b/scipy/spring_mass_string_ring/295/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ebbbf3ad79cb228549660964423caad401a6ca09 --- /dev/null +++ b/scipy/spring_mass_string_ring/295/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=34.173 N/m hangs from a ceiling; a cubical mass of m=0.457 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.1313 m and angular frequency omega_spring=8.644 rad/s. The mass drives the left end of a horizontal string (length L=3.062 m, tension T=3.475 N, mu=0.170 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.1313 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 8.644 rad/s.", + "Period: T = 2 pi/omega_spring = 0.727 s, frequency = 1.376 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(3.475/0.170) = 4.528 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 3.291 m, so 0.930 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.13128333179823584, + "omega_spring_rad_per_s": 8.644297572582747, + "f_spring_Hz": 1.3757826882338162, + "T_spring_period_s": 0.7268589789305799, + "c_phase_speed_mps": 4.527916417896984, + "lambda_m": 3.291156704195611, + "n_wavelengths_in_L": 0.9302293391592735, + "tau_ramp_s": 0.4585679816013358 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=8.644 rad/s with amplitude 0.1313 m.", + "Wave train propagates rightward at c=4.528 m/s; leading edge reaches the ring at t = L/c = 0.676 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.4573204904031914, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 34.172761685772464, + "unit": "", + "description": "" + }, + "L": { + "value": 3.061530526013496, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.1695009702540985, + "unit": "", + "description": "" + }, + "T_str": { + "value": 3.475113483500458, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.2485287740473043, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.4585679816013358, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/295/params.json b/scipy/spring_mass_string_ring/295/params.json new file mode 100644 index 0000000000000000000000000000000000000000..465f5a5602c0af319dceda213c7292357406d545 --- /dev/null +++ b/scipy/spring_mass_string_ring/295/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.4573204904031914, + "k_spring": 34.172761685772464, + "L": 3.061530526013496, + "mu": 0.1695009702540985, + "T_str": 3.475113483500458, + "gamma_w": 1.2485287740473043, + "tau_ramp": 0.4585679816013358, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/295/simulation_code.py b/scipy/spring_mass_string_ring/295/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..91664591a51b0dd23c6e71e66320cfad88686282 --- /dev/null +++ b/scipy/spring_mass_string_ring/295/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.4573204904031914 +k_spring = 34.172761685772464 +L = 3.061530526013496 +mu = 0.1695009702540985 +T_str = 3.475113483500458 +gamma_w = 1.2485287740473043 +tau_ramp = 0.4585679816013358 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/295/video.mp4 b/scipy/spring_mass_string_ring/295/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a388be53f9eb062f583b3df5d89b9b46ab939a29 --- /dev/null +++ b/scipy/spring_mass_string_ring/295/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea05ea8cab8ab58c7e47a35e6d91b8b576b539315d6f6e35db3ed2445a696fc7 +size 54955 diff --git a/scipy/spring_mass_string_ring/298/cot.json b/scipy/spring_mass_string_ring/298/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..f47ffda57943fa14e4b53b5675918e183027146f --- /dev/null +++ b/scipy/spring_mass_string_ring/298/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=22.613 N/m hangs from a ceiling; a cubical mass of m=0.224 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.0972 m and angular frequency omega_spring=10.048 rad/s. The mass drives the left end of a horizontal string (length L=4.621 m, tension T=5.332 N, mu=0.102 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.0972 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 10.048 rad/s.", + "Period: T = 2 pi/omega_spring = 0.625 s, frequency = 1.599 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(5.332/0.102) = 7.236 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 4.524 m, so 1.021 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.09715840029341169, + "omega_spring_rad_per_s": 10.048340099264074, + "f_spring_Hz": 1.5992429966663837, + "T_spring_period_s": 0.6252958443991916, + "c_phase_speed_mps": 7.235546844158543, + "lambda_m": 4.524357373608023, + "n_wavelengths_in_L": 1.0213751007992888, + "tau_ramp_s": 0.3950854451112804 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=10.048 rad/s with amplitude 0.0972 m.", + "Wave train propagates rightward at c=7.236 m/s; leading edge reaches the ring at t = L/c = 0.639 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.22396184746372608, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 22.613234851378422, + "unit": "", + "description": "" + }, + "L": { + "value": 4.621065968520901, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.1018487911755593, + "unit": "", + "description": "" + }, + "T_str": { + "value": 5.332103833196266, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.9853426285979944, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.3950854451112804, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/298/params.json b/scipy/spring_mass_string_ring/298/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6d029a9c580f86c0662f378019b86024de8d840c --- /dev/null +++ b/scipy/spring_mass_string_ring/298/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.22396184746372608, + "k_spring": 22.613234851378422, + "L": 4.621065968520901, + "mu": 0.1018487911755593, + "T_str": 5.332103833196266, + "gamma_w": 0.9853426285979944, + "tau_ramp": 0.3950854451112804, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/298/simulation_code.py b/scipy/spring_mass_string_ring/298/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..fe113897d3ab72f7b5ad2bbd94a703c67c6f8e79 --- /dev/null +++ b/scipy/spring_mass_string_ring/298/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.22396184746372608 +k_spring = 22.613234851378422 +L = 4.621065968520901 +mu = 0.1018487911755593 +T_str = 5.332103833196266 +gamma_w = 0.9853426285979944 +tau_ramp = 0.3950854451112804 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/298/video.mp4 b/scipy/spring_mass_string_ring/298/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..499dfeff05b837de2b5ee73d4e9e4022c41e5c56 --- /dev/null +++ b/scipy/spring_mass_string_ring/298/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ad3aeb9afb0f8bc9537380c987feda93a6bdbb1aff43c492cc3b6f4b4c6cfed +size 41572 diff --git a/scipy/spring_mass_string_ring/418/cot.json b/scipy/spring_mass_string_ring/418/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ae96262948a39188de30086c9aee9e8345ece3ad --- /dev/null +++ b/scipy/spring_mass_string_ring/418/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=36.937 N/m hangs from a ceiling; a cubical mass of m=0.451 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.1199 m and angular frequency omega_spring=9.046 rad/s. The mass drives the left end of a horizontal string (length L=3.294 m, tension T=5.733 N, mu=0.060 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.1199 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 9.046 rad/s.", + "Period: T = 2 pi/omega_spring = 0.695 s, frequency = 1.440 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(5.733/0.060) = 9.786 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 6.797 m, so 0.485 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.11987001373764003, + "omega_spring_rad_per_s": 9.046471641898982, + "f_spring_Hz": 1.4397906793488775, + "T_spring_period_s": 0.694545404650233, + "c_phase_speed_mps": 9.785878522906755, + "lambda_m": 6.796736958550296, + "n_wavelengths_in_L": 0.4846352906415882, + "tau_ramp_s": 0.3070919530387831 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=9.046 rad/s with amplitude 0.1199 m.", + "Wave train propagates rightward at c=9.786 m/s; leading edge reaches the ring at t = L/c = 0.337 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.4513346620202578, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 36.93661906229042, + "unit": "", + "description": "" + }, + "L": { + "value": 3.293938591321447, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.059868987650923515, + "unit": "", + "description": "" + }, + "T_str": { + "value": 5.733258917496555, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.77629492971568, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.3070919530387831, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/418/params.json b/scipy/spring_mass_string_ring/418/params.json new file mode 100644 index 0000000000000000000000000000000000000000..d6c01c833fee83d0ddbbb6d90141d0dbf142faa9 --- /dev/null +++ b/scipy/spring_mass_string_ring/418/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.4513346620202578, + "k_spring": 36.93661906229042, + "L": 3.293938591321447, + "mu": 0.059868987650923515, + "T_str": 5.733258917496555, + "gamma_w": 1.77629492971568, + "tau_ramp": 0.3070919530387831, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/418/simulation_code.py b/scipy/spring_mass_string_ring/418/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e901c31826d5fdb8fc8f5a6802711e98c93b64ed --- /dev/null +++ b/scipy/spring_mass_string_ring/418/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.4513346620202578 +k_spring = 36.93661906229042 +L = 3.293938591321447 +mu = 0.059868987650923515 +T_str = 5.733258917496555 +gamma_w = 1.77629492971568 +tau_ramp = 0.3070919530387831 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/418/video.mp4 b/scipy/spring_mass_string_ring/418/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..02188a74f9a12966ea667e181c7f548b7fde5838 --- /dev/null +++ b/scipy/spring_mass_string_ring/418/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b42d28896e97ab8d661f2dd64841f1897b947df03f8912eecb15f6d07a751ffd +size 47446 diff --git a/scipy/spring_mass_string_ring/461/cot.json b/scipy/spring_mass_string_ring/461/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..1a250c320acbe3dfb9994a8f2a24800543047996 --- /dev/null +++ b/scipy/spring_mass_string_ring/461/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=45.421 N/m hangs from a ceiling; a cubical mass of m=0.440 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.0950 m and angular frequency omega_spring=10.161 rad/s. The mass drives the left end of a horizontal string (length L=3.779 m, tension T=4.630 N, mu=0.149 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.0950 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 10.161 rad/s.", + "Period: T = 2 pi/omega_spring = 0.618 s, frequency = 1.617 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(4.630/0.149) = 5.580 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 3.450 m, so 1.095 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.09501247706377715, + "omega_spring_rad_per_s": 10.1611809032886, + "f_spring_Hz": 1.6172021684093507, + "T_spring_period_s": 0.618351879272819, + "c_phase_speed_mps": 5.579692923592938, + "lambda_m": 3.4502136050689427, + "n_wavelengths_in_L": 1.0951635195674143, + "tau_ramp_s": 0.34865536196086216 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=10.161 rad/s with amplitude 0.0950 m.", + "Wave train propagates rightward at c=5.580 m/s; leading edge reaches the ring at t = L/c = 0.677 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.4399142422105117, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 45.420968376482804, + "unit": "", + "description": "" + }, + "L": { + "value": 3.77854807498668, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.14872871547370212, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.630367101251837, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.1246885032120684, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.34865536196086216, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/461/params.json b/scipy/spring_mass_string_ring/461/params.json new file mode 100644 index 0000000000000000000000000000000000000000..9fcc84a8987bb0eec55cf3baf57687c8fc3ae847 --- /dev/null +++ b/scipy/spring_mass_string_ring/461/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.4399142422105117, + "k_spring": 45.420968376482804, + "L": 3.77854807498668, + "mu": 0.14872871547370212, + "T_str": 4.630367101251837, + "gamma_w": 1.1246885032120684, + "tau_ramp": 0.34865536196086216, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/461/simulation_code.py b/scipy/spring_mass_string_ring/461/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b504a58f4ed79ea0d8b69f2e99ad401e0fed0339 --- /dev/null +++ b/scipy/spring_mass_string_ring/461/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.4399142422105117 +k_spring = 45.420968376482804 +L = 3.77854807498668 +mu = 0.14872871547370212 +T_str = 4.630367101251837 +gamma_w = 1.1246885032120684 +tau_ramp = 0.34865536196086216 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/461/video.mp4 b/scipy/spring_mass_string_ring/461/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..62c5a60c6d641f64936e19399bbd59aa14e6ada0 --- /dev/null +++ b/scipy/spring_mass_string_ring/461/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b802f9fec0e72c717dbc9b47dfb76245e357689adf3faac58485c2419ae1cda +size 45918 diff --git a/scipy/spring_mass_string_ring/464/cot.json b/scipy/spring_mass_string_ring/464/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ff0bf9e58b60f3d7b5c0d74f04fe2eb98e379e53 --- /dev/null +++ b/scipy/spring_mass_string_ring/464/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=22.301 N/m hangs from a ceiling; a cubical mass of m=0.414 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.1821 m and angular frequency omega_spring=7.340 rad/s. The mass drives the left end of a horizontal string (length L=4.624 m, tension T=4.788 N, mu=0.161 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.1821 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 7.340 rad/s.", + "Period: T = 2 pi/omega_spring = 0.856 s, frequency = 1.168 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(4.788/0.161) = 5.458 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 4.673 m, so 0.990 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.18209078563626444, + "omega_spring_rad_per_s": 7.339906351089514, + "f_spring_Hz": 1.1681823776074929, + "T_spring_period_s": 0.8560307184637211, + "c_phase_speed_mps": 5.4584485625086145, + "lambda_m": 4.672599644661514, + "n_wavelengths_in_L": 0.9896720870246114, + "tau_ramp_s": 0.3015271694375355 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=7.340 rad/s with amplitude 0.1821 m.", + "Wave train propagates rightward at c=5.458 m/s; leading edge reaches the ring at t = L/c = 0.847 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.413952952674972, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 22.301394612318745, + "unit": "", + "description": "" + }, + "L": { + "value": 4.624341442162619, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.16068920709039336, + "unit": "", + "description": "" + }, + "T_str": { + "value": 4.787680404945265, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.6040319264297769, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.3015271694375355, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/464/params.json b/scipy/spring_mass_string_ring/464/params.json new file mode 100644 index 0000000000000000000000000000000000000000..f252cd60658c93cf417220558138ec1cc1649a17 --- /dev/null +++ b/scipy/spring_mass_string_ring/464/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.413952952674972, + "k_spring": 22.301394612318745, + "L": 4.624341442162619, + "mu": 0.16068920709039336, + "T_str": 4.787680404945265, + "gamma_w": 1.6040319264297769, + "tau_ramp": 0.3015271694375355, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/464/simulation_code.py b/scipy/spring_mass_string_ring/464/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..5923f23fb6b78d6a214fba5b8943a1bdc1ad6302 --- /dev/null +++ b/scipy/spring_mass_string_ring/464/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.413952952674972 +k_spring = 22.301394612318745 +L = 4.624341442162619 +mu = 0.16068920709039336 +T_str = 4.787680404945265 +gamma_w = 1.6040319264297769 +tau_ramp = 0.3015271694375355 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/464/video.mp4 b/scipy/spring_mass_string_ring/464/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e04dae59e1a661cafd2ffb330cd95ed1d69f0395 --- /dev/null +++ b/scipy/spring_mass_string_ring/464/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50fe29b21cdd5fd230d22c021fc5d4a1997ddc7bcc07cb537a88b7c53ad13fe6 +size 47664 diff --git a/scipy/spring_mass_string_ring/481/cot.json b/scipy/spring_mass_string_ring/481/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..c4b01c442f1167ba5b61d4289980350537327062 --- /dev/null +++ b/scipy/spring_mass_string_ring/481/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=43.602 N/m hangs from a ceiling; a cubical mass of m=0.266 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.0599 m and angular frequency omega_spring=12.795 rad/s. The mass drives the left end of a horizontal string (length L=4.729 m, tension T=3.901 N, mu=0.159 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.0599 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 12.795 rad/s.", + "Period: T = 2 pi/omega_spring = 0.491 s, frequency = 2.036 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(3.901/0.159) = 4.959 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 2.435 m, so 1.942 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.05991914195007222, + "omega_spring_rad_per_s": 12.7953364755297, + "f_spring_Hz": 2.036441048604582, + "T_spring_period_s": 0.4910527612302963, + "c_phase_speed_mps": 4.958941569970685, + "lambda_m": 2.4351019507138054, + "n_wavelengths_in_L": 1.9418903599693222, + "tau_ramp_s": 0.39414829740778584 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=12.795 rad/s with amplitude 0.0599 m.", + "Wave train propagates rightward at c=4.959 m/s; leading edge reaches the ring at t = L/c = 0.954 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.26631733662352103, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 43.60164360253481, + "unit": "", + "description": "" + }, + "L": { + "value": 4.72870100363363, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.158627813621725, + "unit": "", + "description": "" + }, + "T_str": { + "value": 3.9008326646039615, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 0.5138893934773745, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.39414829740778584, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/481/params.json b/scipy/spring_mass_string_ring/481/params.json new file mode 100644 index 0000000000000000000000000000000000000000..901b709b575b67f83281e076abd2c636bf746b86 --- /dev/null +++ b/scipy/spring_mass_string_ring/481/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.26631733662352103, + "k_spring": 43.60164360253481, + "L": 4.72870100363363, + "mu": 0.158627813621725, + "T_str": 3.9008326646039615, + "gamma_w": 0.5138893934773745, + "tau_ramp": 0.39414829740778584, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/481/simulation_code.py b/scipy/spring_mass_string_ring/481/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..99ce5519e766a66216fd45438e5b9b215d89cc13 --- /dev/null +++ b/scipy/spring_mass_string_ring/481/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.26631733662352103 +k_spring = 43.60164360253481 +L = 4.72870100363363 +mu = 0.158627813621725 +T_str = 3.9008326646039615 +gamma_w = 0.5138893934773745 +tau_ramp = 0.39414829740778584 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/481/video.mp4 b/scipy/spring_mass_string_ring/481/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..066764b2b60ddcac37edb02d211ca1f5d310dabd --- /dev/null +++ b/scipy/spring_mass_string_ring/481/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c272a5a22edf7e3e883f499a15946d85532089184899df2eafbc8aac25326b12 +size 37873 diff --git a/scipy/spring_mass_string_ring/608/cot.json b/scipy/spring_mass_string_ring/608/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..2e2c6be07474449f30ca9252b7dac5a7d42486b2 --- /dev/null +++ b/scipy/spring_mass_string_ring/608/cot.json @@ -0,0 +1,119 @@ +{ + "simulation": "spring_mass_string_ring", + "physical_observation": "A vertical Hookean spring of stiffness k=27.059 N/m hangs from a ceiling; a cubical mass of m=0.440 kg is attached at the bottom and released from rest at the spring's unstretched length. Under gravity it performs SHM with amplitude DeltaL_eq=0.1596 m and angular frequency omega_spring=7.840 rad/s. The mass drives the left end of a horizontal string (length L=4.397 m, tension T=5.025 N, mu=0.062 kg/m) connected to a free ring on a frictionless rod at x=L.", + "physical_law": { + "name": "1-D Wave Equation with Linear Viscous Damping, Driven by SHM Mass-Spring; Free-End BC", + "statement": "Decoupled spring-mass SHM provides a Dirichlet driver at the string's left end via a smooth ramp-in; the string is governed by the damped 1-D wave equation; the right end is a free, massless ring (Neumann BC).", + "formula": "y_mass(t) = DeltaL_eq \\cos(omega_spring t); u_tt = c^2 u_xx - 2 gamma_w u_t; u(0, t) = (1 - \\exp(-t/tau_ramp)) y_mass(t); u_x(L, t) = 0" + }, + "ode_system": { + "state_variables": [ + "y_mass(t) (analytic SHM)", + "u(x, t) (string transverse displacement)" + ], + "equations_latex": [ + "y_mass(t) = DeltaL_eq \\cdot \\cos(omega_spring \\cdot t)", + "u_tt = c^2 u_xx - 2 gamma_w u_t (interior)", + "u(0, t) = ramp(t) \\cdot y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ], + "equations_python": [ + "y_mass(t) = DeltaL_eq * np.cos (omega_spring * t)", + "u_tt = c**2 * u_xx - 2 * gamma_w * u_t (interior)", + "u(0, t) = ramp(t) * y_mass(t) (Dirichlet, left)", + "u_x(L, t) = 0 (Neumann/free, right)" + ] + }, + "derivation_steps": [ + "Static equilibrium of mass: k DeltaL_eq = m g => DeltaL_eq = 0.1596 m.", + "Released from rest at unstretched length: SHM amplitude = DeltaL_eq, omega_spring = \\sqrt(k/m) = 7.840 rad/s.", + "Period: T = 2 pi/omega_spring = 0.801 s, frequency = 1.248 Hz.", + "Wave phase speed: c = \\sqrt(T/mu) = \\sqrt(5.025/0.062) = 8.980 m/s.", + "Wavelength at driver frequency: lambda = 2 pi c / omega_spring = 7.197 m, so 0.611 wavelengths fit in L.", + "Wave equation derived from Newton II on a string element; viscous term -2 gamma_w u_t bounds long-time amplitude.", + "Free-end ring (Neumann) gives reflection without phase inversion." + ], + "physical_constants_derived": { + "DeltaL_eq_m": 0.15960290732470486, + "omega_spring_rad_per_s": 7.8399646521256106, + "f_spring_Hz": 1.2477691280515226, + "T_spring_period_s": 0.8014303107190741, + "c_phase_speed_mps": 8.980011047281106, + "lambda_m": 7.196853043883215, + "n_wavelengths_in_L": 0.6109254572122984, + "tau_ramp_s": 0.5766715434069469 + }, + "numerical_method": { + "solver": "Hybrid: closed-form SHM + leapfrog FDM with viscous damping", + "tolerance": "CFL factor < 1; explicit second-order in space and time", + "justification": "Mass dynamics decoupled (mu \\cdot L << m), so the SHM solution prescribes the left BC via a smooth ramp." + }, + "code_validation": { + "ode_source": "Hooke's law SHM + damped 1-D wave equation; Neumann free-end BC.", + "energy_check": "The prescribed spring-mass driver is an ideal SHM source in this reduced model. Wave-equation damping dissipates injected string energy until the driven envelope approaches a bounded steady state.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Mass oscillates indefinitely at omega_spring=7.840 rad/s with amplitude 0.1596 m.", + "Wave train propagates rightward at c=8.980 m/s; leading edge reaches the ring at t = L/c = 0.490 s.", + "Free-end reflection at the ring (no inversion) builds a near-standing wave with antinodes near the ring.", + "Wave-equation damping limits the long-time string amplitude to a finite envelope." + ], + "parameters": { + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "m_mass": { + "value": 0.4402348118789124, + "unit": "", + "description": "" + }, + "k_spring": { + "value": 27.059052851373973, + "unit": "", + "description": "" + }, + "L": { + "value": 4.396740736324075, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.062315752160864074, + "unit": "", + "description": "" + }, + "T_str": { + "value": 5.025179544577129, + "unit": "", + "description": "" + }, + "gamma_w": { + "value": 1.449449487858495, + "unit": "", + "description": "" + }, + "tau_ramp": { + "value": 0.5766715434069469, + "unit": "", + "description": "" + }, + "H_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "W_mass": { + "value": 0.2, + "unit": "", + "description": "" + }, + "L_spring_rest": { + "value": 0.5, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/spring_mass_string_ring/608/params.json b/scipy/spring_mass_string_ring/608/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c6852061660958b0f2bff8fe12582664dfadcfdb --- /dev/null +++ b/scipy/spring_mass_string_ring/608/params.json @@ -0,0 +1,13 @@ +{ + "g": 9.81, + "m_mass": 0.4402348118789124, + "k_spring": 27.059052851373973, + "L": 4.396740736324075, + "mu": 0.062315752160864074, + "T_str": 5.025179544577129, + "gamma_w": 1.449449487858495, + "tau_ramp": 0.5766715434069469, + "H_mass": 0.2, + "W_mass": 0.2, + "L_spring_rest": 0.5 +} \ No newline at end of file diff --git a/scipy/spring_mass_string_ring/608/simulation_code.py b/scipy/spring_mass_string_ring/608/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..68755ed694e59e2df6aa43fd622c9350ec659d02 --- /dev/null +++ b/scipy/spring_mass_string_ring/608/simulation_code.py @@ -0,0 +1,139 @@ +"""Spring-Mass Driven String + Ring — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +from matplotlib.patches import Circle, Rectangle, Arc + +g = 9.81 +m_mass = 0.4402348118789124 +k_spring = 27.059052851373973 +L = 4.396740736324075 +mu = 0.062315752160864074 +T_str = 5.025179544577129 +gamma_w = 1.449449487858495 +tau_ramp = 0.5766715434069469 +H_mass = 0.2 +W_mass = 0.2 +L_spring_rest = 0.5 +duration = 12 +fps = 30 + +DeltaL_eq = m_mass * g / k_spring +omega_spring = np.sqrt(k_spring / m_mass) +c = np.sqrt(T_str / mu) + +y_string_eq = 0.0 +y_mass_eq = y_string_eq +y_ceiling = L_spring_rest + DeltaL_eq + H_mass / 2 + y_mass_eq +x_mass_c = -W_mass / 2 + +def y_mass_at(t): + return y_mass_eq + DeltaL_eq * np.cos(omega_spring * t) + +def ramp(t): + return 1.0 - np.exp(-t / tau_ramp) + +N = 200 +dx = L / N +x_grid = np.linspace(0.0, L, N + 1) +n_per_frame = 16 +dt = 1.0 / (fps * n_per_frame) +factor = (c * dt / dx) ** 2 +if factor >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 4 + dt = 1.0 / (fps * n_per_frame) + factor = (c * dt / dx) ** 2 +damp_n = 1.0 / (1.0 + gamma_w * dt) +damp_p = 1.0 - gamma_w * dt + +u_curr = np.zeros(N + 1) +u_prev = u_curr.copy() +n_frames = int(duration * fps) + 1 +U_frames = np.zeros((n_frames, N + 1)) +U_frames[0] = u_curr.copy() + +for frame in range(1, n_frames): + for sub in range(n_per_frame): + t_curr = (frame - 1) / fps + (sub + 1) * dt + u_next = np.empty_like(u_curr) + lap_int = u_curr[2:] - 2 * u_curr[1:-1] + u_curr[:-2] + u_next[1:-1] = damp_n * (2 * u_curr[1:-1] - damp_p * u_prev[1:-1] + factor * lap_int) + lap_right = 2 * (u_curr[-2] - u_curr[-1]) + u_next[-1] = damp_n * (2 * u_curr[-1] - damp_p * u_prev[-1] + factor * lap_right) + u_next[0] = ramp(t_curr) * (y_mass_at(t_curr) - y_string_eq) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr.copy() + +def coil_xy(p_top, p_bot, n_coils=10, w=0.04, n_pts=80): + x1, y1 = p_top; x2, y2 = p_bot + dx_v, dy_v = x2 - x1, y2 - y1 + Lc = np.hypot(dx_v, dy_v) + if Lc < 1e-9: + return np.array([x1, x2]), np.array([y1, y2]) + ux, uy = dx_v / Lc, dy_v / Lc + nx, ny = -uy, ux + s = np.linspace(0.0, 1.0, n_pts) + lead = 0.06 + arc = s * Lc + middle = (arc >= lead) & (arc <= Lc - lead) + amp = np.where(middle, w * np.sin(2*np.pi*n_coils*(arc-lead)/max(Lc-2*lead,1e-6)), 0.0) + xs = x1 + ux*arc + nx*amp + ys = y1 + uy*arc + ny*amp + return xs, ys + +fig_w, fig_h = 12.0, 4.5 +fig_aspect = fig_w / fig_h +x_lo_d = x_mass_c - W_mass/2 - 0.20 +x_hi_d = L + 0.40 +y_lo_d = -4.5*DeltaL_eq - 0.10 +y_hi_d = y_ceiling + 0.10 +dx_d, dy_d = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_d/dy_d < fig_aspect: + extra = (fig_aspect*dy_d - dx_d)/2.0 + x_lo, x_hi = x_lo_d - extra, x_hi_d + extra + y_lo, y_hi = y_lo_d, y_hi_d +else: + extra = (dx_d/fig_aspect - dy_d)/2.0 + x_lo, x_hi = x_lo_d, x_hi_d + y_lo, y_hi = y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.axhline(y_string_eq, color="#3a4357", lw=1, ls="--", zorder=0) +ax.add_patch(Rectangle((x_lo, y_ceiling), x_hi - x_lo, y_hi - y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.0, zorder=1) +spring_line, = ax.plot([], [], color="#a8dadc", lw=2.0, zorder=3) +mass_patch = Rectangle((x_mass_c - W_mass/2, y_mass_at(0.0)-H_mass/2), W_mass, H_mass, facecolor="#e63946", edgecolor="#adb5bd", lw=1.0, zorder=4) +ax.add_patch(mass_patch) +r_x, r_y = 0.22, 0.11 +back_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, edgecolor="#e63946", lw=10, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=14, solid_capstyle="butt", zorder=3) +front_arc = Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, edgecolor="#e63946", lw=10, zorder=5) +ax.add_patch(front_arc) +n_cut = int(round(r_x/dx)) +n_inside = (N+1) - n_cut +str_x_plot = x_grid[:n_inside] +str_line, = ax.plot([], [], color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + t = f / fps + y_m = y_mass_at(t) + mass_patch.set_xy((x_mass_c - W_mass/2, y_m - H_mass/2)) + xs_s, ys_s = coil_xy((x_mass_c, y_ceiling), (x_mass_c, y_m + H_mass/2)) + spring_line.set_data(xs_s, ys_s) + u = U_frames[f] + yy = u[-1] + str_y = u[:n_inside].copy() + str_y[-1] = yy + str_line.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return mass_patch, spring_line, str_line, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000.0/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/spring_mass_string_ring/608/video.mp4 b/scipy/spring_mass_string_ring/608/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6e32f4b2de7228868ea43b21c495a2cb8bb2c19e --- /dev/null +++ b/scipy/spring_mass_string_ring/608/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:758e920acead93d9ef5fd5fd54086a8dfa01b7835124cc4b65dbfc87b40887c8 +size 46824 diff --git a/scipy/springs_two_slabs_compound/117/cot.json b/scipy/springs_two_slabs_compound/117/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..a89ab3f8c079bc5990707fb43467ff1275c2b7d7 --- /dev/null +++ b/scipy/springs_two_slabs_compound/117/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=127.92 N/m support an upper slab of mass m_1=0.736 kg. From the upper slab, a second parallel-spring bank K_mid=79.40 N/m hangs a lower slab of mass m_2=0.760 kg. Linear viscous damping gamma_1=0.245 kg/s, gamma_2=0.193 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 16.782 rad/s -> T_1 = 0.374 s; omega_2 = \\sqrt(K_mid/m_2) = 10.218 rad/s -> T_2 = 0.615 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 16.78212128394954, + "omega_2_uncoupled_rad_per_s": 10.218478682628998, + "T_1_uncoupled_s": 0.3743975627913522, + "T_2_uncoupled_s": 0.6148846127027449 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~16.78 rad/s, lower slab near omega_2~10.22 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 0.7361053696648882, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.7603651421481323, + "unit": "", + "description": "" + }, + "K_top": { + "value": 127.92113786855727, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 79.39528016601037, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.4707183545425634, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.30997463624525695, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.24541695630671662, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.19308528009052014, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 0.9971932376966186, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.6698976134354188, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/117/params.json b/scipy/springs_two_slabs_compound/117/params.json new file mode 100644 index 0000000000000000000000000000000000000000..e4e49b5850b01264d5cd9c4e9a0974722f43a98d --- /dev/null +++ b/scipy/springs_two_slabs_compound/117/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 0.7361053696648882, + "m_2": 0.7603651421481323, + "K_top": 127.92113786855727, + "K_mid": 79.39528016601037, + "L_top": 0.4707183545425634, + "L_mid": 0.30997463624525695, + "gamma_1": 0.24541695630671662, + "gamma_2": 0.19308528009052014, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 0.9971932376966186, + "y2_0": 0.6698976134354188, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/117/simulation_code.py b/scipy/springs_two_slabs_compound/117/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..643491e2a636bb622e64d705c6eb218cf7ec9581 --- /dev/null +++ b/scipy/springs_two_slabs_compound/117/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 0.7361053696648882 +m_2 = 0.7603651421481323 +K_top = 127.92113786855727 +K_mid = 79.39528016601037 +L_top = 0.4707183545425634 +L_mid = 0.30997463624525695 +gamma_1 = 0.24541695630671662 +gamma_2 = 0.19308528009052014 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 0.9971932376966186 +y2_0 = 0.6698976134354188 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/117/video.mp4 b/scipy/springs_two_slabs_compound/117/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b347b9b4724cba14a492eb899db29d8acbdfed27 --- /dev/null +++ b/scipy/springs_two_slabs_compound/117/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ec571f639e1ae9fc8f296697900e16ce6579bbc7257ca69b6ccfbd545d9c3a4 +size 91451 diff --git a/scipy/springs_two_slabs_compound/202/cot.json b/scipy/springs_two_slabs_compound/202/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..53381b3bb1e2c9c467808b6621426c6aa28adf62 --- /dev/null +++ b/scipy/springs_two_slabs_compound/202/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=187.08 N/m support an upper slab of mass m_1=0.528 kg. From the upper slab, a second parallel-spring bank K_mid=65.13 N/m hangs a lower slab of mass m_2=0.537 kg. Linear viscous damping gamma_1=0.243 kg/s, gamma_2=0.179 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 21.860 rad/s -> T_1 = 0.287 s; omega_2 = \\sqrt(K_mid/m_2) = 11.015 rad/s -> T_2 = 0.570 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 21.859549435057495, + "omega_2_uncoupled_rad_per_s": 11.015470754107973, + "T_1_uncoupled_s": 0.28743434652421784, + "T_2_uncoupled_s": 0.5703964403733188 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~21.86 rad/s, lower slab near omega_2~11.02 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 0.5278057612686223, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.53674546043361, + "unit": "", + "description": "" + }, + "K_top": { + "value": 187.0776389434859, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 65.12901403420985, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.4352235251773954, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.26279257480784407, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.24271114132599825, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.17922344119896544, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 1.0289724368328947, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.670031627134358, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/202/params.json b/scipy/springs_two_slabs_compound/202/params.json new file mode 100644 index 0000000000000000000000000000000000000000..1e27c4e1a6627b7c8006be664ce139da36a2ac2e --- /dev/null +++ b/scipy/springs_two_slabs_compound/202/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 0.5278057612686223, + "m_2": 0.53674546043361, + "K_top": 187.0776389434859, + "K_mid": 65.12901403420985, + "L_top": 0.4352235251773954, + "L_mid": 0.26279257480784407, + "gamma_1": 0.24271114132599825, + "gamma_2": 0.17922344119896544, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 1.0289724368328947, + "y2_0": 0.670031627134358, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/202/simulation_code.py b/scipy/springs_two_slabs_compound/202/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..67dd75ae19a4773682b97a9b6b2bbc9eb122a839 --- /dev/null +++ b/scipy/springs_two_slabs_compound/202/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 0.5278057612686223 +m_2 = 0.53674546043361 +K_top = 187.0776389434859 +K_mid = 65.12901403420985 +L_top = 0.4352235251773954 +L_mid = 0.26279257480784407 +gamma_1 = 0.24271114132599825 +gamma_2 = 0.17922344119896544 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 1.0289724368328947 +y2_0 = 0.670031627134358 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/202/video.mp4 b/scipy/springs_two_slabs_compound/202/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..15aa9ff08c3d252cc74df1bc8d543b559077b580 --- /dev/null +++ b/scipy/springs_two_slabs_compound/202/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:546b973643d3a6ac3fd6726154078a1a03ec0abef62a5070de2f729449c382b1 +size 71071 diff --git a/scipy/springs_two_slabs_compound/230/cot.json b/scipy/springs_two_slabs_compound/230/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..cc7f3274f09a854ff53b0819b79a38b5bc1cb68f --- /dev/null +++ b/scipy/springs_two_slabs_compound/230/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=193.30 N/m support an upper slab of mass m_1=0.521 kg. From the upper slab, a second parallel-spring bank K_mid=32.90 N/m hangs a lower slab of mass m_2=0.535 kg. Linear viscous damping gamma_1=0.266 kg/s, gamma_2=0.249 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 20.830 rad/s -> T_1 = 0.302 s; omega_2 = \\sqrt(K_mid/m_2) = 7.843 rad/s -> T_2 = 0.801 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 20.83013410137911, + "omega_2_uncoupled_rad_per_s": 7.843402891805343, + "T_1_uncoupled_s": 0.30163921540781596, + "T_2_uncoupled_s": 0.8010789951570835 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~20.83 rad/s, lower slab near omega_2~7.84 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 0.5213253940176558, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.5347817029645041, + "unit": "", + "description": "" + }, + "K_top": { + "value": 193.30099526592974, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 32.89921896535883, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.44397009311480273, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.32275499869233626, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.2664070690570443, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.24862696202102613, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 0.9793690648972011, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.6792979428971224, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/230/params.json b/scipy/springs_two_slabs_compound/230/params.json new file mode 100644 index 0000000000000000000000000000000000000000..4c1e090f49d9d2d6fda6092914f47ad8d7993c72 --- /dev/null +++ b/scipy/springs_two_slabs_compound/230/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 0.5213253940176558, + "m_2": 0.5347817029645041, + "K_top": 193.30099526592974, + "K_mid": 32.89921896535883, + "L_top": 0.44397009311480273, + "L_mid": 0.32275499869233626, + "gamma_1": 0.2664070690570443, + "gamma_2": 0.24862696202102613, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 0.9793690648972011, + "y2_0": 0.6792979428971224, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/230/simulation_code.py b/scipy/springs_two_slabs_compound/230/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8e856162425040f04dacfa4141581bdd9cd90dbb --- /dev/null +++ b/scipy/springs_two_slabs_compound/230/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 0.5213253940176558 +m_2 = 0.5347817029645041 +K_top = 193.30099526592974 +K_mid = 32.89921896535883 +L_top = 0.44397009311480273 +L_mid = 0.32275499869233626 +gamma_1 = 0.2664070690570443 +gamma_2 = 0.24862696202102613 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 0.9793690648972011 +y2_0 = 0.6792979428971224 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/230/video.mp4 b/scipy/springs_two_slabs_compound/230/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..620832514daa71e2dfdc50b248b5ffc8e4e1b995 --- /dev/null +++ b/scipy/springs_two_slabs_compound/230/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac028c48bd8375874ba51657d4feea38dcc279faae7dbff74449f57ae654bf7f +size 74246 diff --git a/scipy/springs_two_slabs_compound/270/cot.json b/scipy/springs_two_slabs_compound/270/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..748774bb7c14f51c1efa713cc2e508350b0c8586 --- /dev/null +++ b/scipy/springs_two_slabs_compound/270/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=127.04 N/m support an upper slab of mass m_1=0.974 kg. From the upper slab, a second parallel-spring bank K_mid=57.94 N/m hangs a lower slab of mass m_2=0.651 kg. Linear viscous damping gamma_1=0.238 kg/s, gamma_2=0.104 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 13.784 rad/s -> T_1 = 0.456 s; omega_2 = \\sqrt(K_mid/m_2) = 9.432 rad/s -> T_2 = 0.666 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 13.783722357484837, + "omega_2_uncoupled_rad_per_s": 9.432406701512244, + "T_1_uncoupled_s": 0.455840965468061, + "T_2_uncoupled_s": 0.6661274800812225 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~13.78 rad/s, lower slab near omega_2~9.43 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 0.9736220142306226, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.6511981383512329, + "unit": "", + "description": "" + }, + "K_top": { + "value": 127.04213083766342, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 57.93729124275359, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.42514769227458477, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.37564637589071054, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.2384360364799771, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.10409572607700768, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 1.0312599032780134, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.7156756616558315, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/270/params.json b/scipy/springs_two_slabs_compound/270/params.json new file mode 100644 index 0000000000000000000000000000000000000000..298582929dcd8aea15ca1d75741c09a79db5e24d --- /dev/null +++ b/scipy/springs_two_slabs_compound/270/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 0.9736220142306226, + "m_2": 0.6511981383512329, + "K_top": 127.04213083766342, + "K_mid": 57.93729124275359, + "L_top": 0.42514769227458477, + "L_mid": 0.37564637589071054, + "gamma_1": 0.2384360364799771, + "gamma_2": 0.10409572607700768, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 1.0312599032780134, + "y2_0": 0.7156756616558315, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/270/simulation_code.py b/scipy/springs_two_slabs_compound/270/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..077b21b9b1746d22b536c34cfd09863b13710fd3 --- /dev/null +++ b/scipy/springs_two_slabs_compound/270/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 0.9736220142306226 +m_2 = 0.6511981383512329 +K_top = 127.04213083766342 +K_mid = 57.93729124275359 +L_top = 0.42514769227458477 +L_mid = 0.37564637589071054 +gamma_1 = 0.2384360364799771 +gamma_2 = 0.10409572607700768 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 1.0312599032780134 +y2_0 = 0.7156756616558315 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/270/video.mp4 b/scipy/springs_two_slabs_compound/270/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..669756bda3abe7c03fd2593817b301bc130b588b --- /dev/null +++ b/scipy/springs_two_slabs_compound/270/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b138a7b2c0547dae9af821bbbee3be01fee6bf6cb0a4538bed4839a236e42951 +size 105525 diff --git a/scipy/springs_two_slabs_compound/435/cot.json b/scipy/springs_two_slabs_compound/435/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..b706dba7dca0fd5a7fc6f6c78fecc069ff40aa8b --- /dev/null +++ b/scipy/springs_two_slabs_compound/435/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=158.09 N/m support an upper slab of mass m_1=0.732 kg. From the upper slab, a second parallel-spring bank K_mid=42.03 N/m hangs a lower slab of mass m_2=0.677 kg. Linear viscous damping gamma_1=0.335 kg/s, gamma_2=0.122 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 16.536 rad/s -> T_1 = 0.380 s; omega_2 = \\sqrt(K_mid/m_2) = 7.878 rad/s -> T_2 = 0.798 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 16.535915533826397, + "omega_2_uncoupled_rad_per_s": 7.877911062015064, + "T_1_uncoupled_s": 0.37997202479212605, + "T_2_uncoupled_s": 0.7975699722576497 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~16.54 rad/s, lower slab near omega_2~7.88 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 0.7318775033379236, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.6772705356447832, + "unit": "", + "description": "" + }, + "K_top": { + "value": 158.08961116994772, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 42.0324136318288, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.3300527977480541, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.29514931311393844, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.3349822797843733, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.12209040403096899, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 1.0017545004414037, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.7477833206584188, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/435/params.json b/scipy/springs_two_slabs_compound/435/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3530d6bc95983dd62e5bcee1aa9ed4ec8ced023d --- /dev/null +++ b/scipy/springs_two_slabs_compound/435/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 0.7318775033379236, + "m_2": 0.6772705356447832, + "K_top": 158.08961116994772, + "K_mid": 42.0324136318288, + "L_top": 0.3300527977480541, + "L_mid": 0.29514931311393844, + "gamma_1": 0.3349822797843733, + "gamma_2": 0.12209040403096899, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 1.0017545004414037, + "y2_0": 0.7477833206584188, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/435/simulation_code.py b/scipy/springs_two_slabs_compound/435/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..442095306a824564b7a00c259d1ec808641e116d --- /dev/null +++ b/scipy/springs_two_slabs_compound/435/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 0.7318775033379236 +m_2 = 0.6772705356447832 +K_top = 158.08961116994772 +K_mid = 42.0324136318288 +L_top = 0.3300527977480541 +L_mid = 0.29514931311393844 +gamma_1 = 0.3349822797843733 +gamma_2 = 0.12209040403096899 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 1.0017545004414037 +y2_0 = 0.7477833206584188 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/435/video.mp4 b/scipy/springs_two_slabs_compound/435/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3c00a7751e83b5d814e2828882c8d9a2dfd508f1 --- /dev/null +++ b/scipy/springs_two_slabs_compound/435/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:211b4a106a5b28c7bb251f59277343aa962044e6694d6a0cbd4918322d463ded +size 77608 diff --git a/scipy/springs_two_slabs_compound/557/cot.json b/scipy/springs_two_slabs_compound/557/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..484a2a96d6d65ebf770becce00f83c49e72f9a25 --- /dev/null +++ b/scipy/springs_two_slabs_compound/557/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=166.42 N/m support an upper slab of mass m_1=1.456 kg. From the upper slab, a second parallel-spring bank K_mid=79.78 N/m hangs a lower slab of mass m_2=0.590 kg. Linear viscous damping gamma_1=0.145 kg/s, gamma_2=0.146 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 13.003 rad/s -> T_1 = 0.483 s; omega_2 = \\sqrt(K_mid/m_2) = 11.629 rad/s -> T_2 = 0.540 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 13.003038875343218, + "omega_2_uncoupled_rad_per_s": 11.629260496856, + "T_1_uncoupled_s": 0.4832089919452571, + "T_2_uncoupled_s": 0.5402910450650118 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~13.00 rad/s, lower slab near omega_2~11.63 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 1.4561231038884088, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.589919912899468, + "unit": "", + "description": "" + }, + "K_top": { + "value": 166.41927552584002, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 79.78059186977785, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.4570552443906982, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.20196666368692687, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.14469289739842398, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.1461275398817296, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 0.99392032078885, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.6540683894869314, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/557/params.json b/scipy/springs_two_slabs_compound/557/params.json new file mode 100644 index 0000000000000000000000000000000000000000..024f7d4890aa9e83d0f14f8d8d41b491b04f02fe --- /dev/null +++ b/scipy/springs_two_slabs_compound/557/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 1.4561231038884088, + "m_2": 0.589919912899468, + "K_top": 166.41927552584002, + "K_mid": 79.78059186977785, + "L_top": 0.4570552443906982, + "L_mid": 0.20196666368692687, + "gamma_1": 0.14469289739842398, + "gamma_2": 0.1461275398817296, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 0.99392032078885, + "y2_0": 0.6540683894869314, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/557/simulation_code.py b/scipy/springs_two_slabs_compound/557/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e71f91276254e34b7c4739d6d32c85071e5c7b6e --- /dev/null +++ b/scipy/springs_two_slabs_compound/557/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 1.4561231038884088 +m_2 = 0.589919912899468 +K_top = 166.41927552584002 +K_mid = 79.78059186977785 +L_top = 0.4570552443906982 +L_mid = 0.20196666368692687 +gamma_1 = 0.14469289739842398 +gamma_2 = 0.1461275398817296 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 0.99392032078885 +y2_0 = 0.6540683894869314 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/557/video.mp4 b/scipy/springs_two_slabs_compound/557/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..aaed364a23e7eeb8cda396f13f0ba24d2a046736 --- /dev/null +++ b/scipy/springs_two_slabs_compound/557/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7f0510984ec82dd82938f6d0d0f11f32a783adb39e1a373cd4ee69b6fab7fa5 +size 83917 diff --git a/scipy/springs_two_slabs_compound/603/cot.json b/scipy/springs_two_slabs_compound/603/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..473c5900da450ad740507d698f0e0f7557f75d03 --- /dev/null +++ b/scipy/springs_two_slabs_compound/603/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=172.54 N/m support an upper slab of mass m_1=0.928 kg. From the upper slab, a second parallel-spring bank K_mid=30.85 N/m hangs a lower slab of mass m_2=0.630 kg. Linear viscous damping gamma_1=0.217 kg/s, gamma_2=0.245 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 14.802 rad/s -> T_1 = 0.424 s; omega_2 = \\sqrt(K_mid/m_2) = 6.997 rad/s -> T_2 = 0.898 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 14.801940185018955, + "omega_2_uncoupled_rad_per_s": 6.997378383921882, + "T_1_uncoupled_s": 0.4244839006672111, + "T_2_uncoupled_s": 0.8979341922707336 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~14.80 rad/s, lower slab near omega_2~7.00 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 0.928318070675104, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.6300566838101855, + "unit": "", + "description": "" + }, + "K_top": { + "value": 172.54244941329648, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 30.849657102743684, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.45274864775855306, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.3505077018520921, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.21734755494334118, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.24547206241628494, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 1.046696122047259, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.7168273678169207, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/603/params.json b/scipy/springs_two_slabs_compound/603/params.json new file mode 100644 index 0000000000000000000000000000000000000000..04b5dff60bafde3776a1adf1c38dfa28f626b427 --- /dev/null +++ b/scipy/springs_two_slabs_compound/603/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 0.928318070675104, + "m_2": 0.6300566838101855, + "K_top": 172.54244941329648, + "K_mid": 30.849657102743684, + "L_top": 0.45274864775855306, + "L_mid": 0.3505077018520921, + "gamma_1": 0.21734755494334118, + "gamma_2": 0.24547206241628494, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 1.046696122047259, + "y2_0": 0.7168273678169207, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/603/simulation_code.py b/scipy/springs_two_slabs_compound/603/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..24268879ca0932dc91325c06919472a00715b6fc --- /dev/null +++ b/scipy/springs_two_slabs_compound/603/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 0.928318070675104 +m_2 = 0.6300566838101855 +K_top = 172.54244941329648 +K_mid = 30.849657102743684 +L_top = 0.45274864775855306 +L_mid = 0.3505077018520921 +gamma_1 = 0.21734755494334118 +gamma_2 = 0.24547206241628494 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 1.046696122047259 +y2_0 = 0.7168273678169207 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/603/video.mp4 b/scipy/springs_two_slabs_compound/603/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..61fbb663e46b43de12b8c138aa39c5ed0e27db80 --- /dev/null +++ b/scipy/springs_two_slabs_compound/603/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a80d11ea6277ec08efe4b6c3bfd3b46e089f2e70378193368aca4d243bbec48a +size 100038 diff --git a/scipy/springs_two_slabs_compound/640/cot.json b/scipy/springs_two_slabs_compound/640/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..61b32f9ac4b24710a16fa7f46a1a52a5ff5e4d7a --- /dev/null +++ b/scipy/springs_two_slabs_compound/640/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=163.45 N/m support an upper slab of mass m_1=0.561 kg. From the upper slab, a second parallel-spring bank K_mid=64.46 N/m hangs a lower slab of mass m_2=0.686 kg. Linear viscous damping gamma_1=0.195 kg/s, gamma_2=0.128 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 20.158 rad/s -> T_1 = 0.312 s; omega_2 = \\sqrt(K_mid/m_2) = 9.695 rad/s -> T_2 = 0.648 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 20.158178198992257, + "omega_2_uncoupled_rad_per_s": 9.69453095378394, + "T_1_uncoupled_s": 0.3116941047526653, + "T_2_uncoupled_s": 0.6481164831112487 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~20.16 rad/s, lower slab near omega_2~9.69 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 0.5608688743623492, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.6858452025087067, + "unit": "", + "description": "" + }, + "K_top": { + "value": 163.45184422578015, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 64.45842778726825, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.39118001703262717, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.34037664937379497, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.19503662861930315, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.12791607465107044, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 1.039955816563858, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.6869823374943412, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/640/params.json b/scipy/springs_two_slabs_compound/640/params.json new file mode 100644 index 0000000000000000000000000000000000000000..aa63fd9694bf282d348197626fcfa65b02923e2e --- /dev/null +++ b/scipy/springs_two_slabs_compound/640/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 0.5608688743623492, + "m_2": 0.6858452025087067, + "K_top": 163.45184422578015, + "K_mid": 64.45842778726825, + "L_top": 0.39118001703262717, + "L_mid": 0.34037664937379497, + "gamma_1": 0.19503662861930315, + "gamma_2": 0.12791607465107044, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 1.039955816563858, + "y2_0": 0.6869823374943412, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/640/simulation_code.py b/scipy/springs_two_slabs_compound/640/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b5384aeb34d4752c3ffe0620bc909b4849d787c9 --- /dev/null +++ b/scipy/springs_two_slabs_compound/640/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 0.5608688743623492 +m_2 = 0.6858452025087067 +K_top = 163.45184422578015 +K_mid = 64.45842778726825 +L_top = 0.39118001703262717 +L_mid = 0.34037664937379497 +gamma_1 = 0.19503662861930315 +gamma_2 = 0.12791607465107044 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 1.039955816563858 +y2_0 = 0.6869823374943412 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/640/video.mp4 b/scipy/springs_two_slabs_compound/640/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..27448235dfe319b68df8f28010c55874ab74174d --- /dev/null +++ b/scipy/springs_two_slabs_compound/640/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cae7e0a6d0a474f19cea0f5be633bba36c2c43a6bb2f35adc8b07251257afd60 +size 81874 diff --git a/scipy/springs_two_slabs_compound/663/cot.json b/scipy/springs_two_slabs_compound/663/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..6bb38f9cc424bda384e894f2edd85032aa629b22 --- /dev/null +++ b/scipy/springs_two_slabs_compound/663/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=137.04 N/m support an upper slab of mass m_1=1.091 kg. From the upper slab, a second parallel-spring bank K_mid=73.83 N/m hangs a lower slab of mass m_2=0.530 kg. Linear viscous damping gamma_1=0.157 kg/s, gamma_2=0.215 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 13.903 rad/s -> T_1 = 0.452 s; omega_2 = \\sqrt(K_mid/m_2) = 11.806 rad/s -> T_2 = 0.532 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 13.903078269997673, + "omega_2_uncoupled_rad_per_s": 11.80575786023907, + "T_1_uncoupled_s": 0.4519276368269081, + "T_2_uncoupled_s": 0.5322136352076893 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~13.90 rad/s, lower slab near omega_2~11.81 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 1.090931236296731, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.5297127087893403, + "unit": "", + "description": "" + }, + "K_top": { + "value": 137.042996520609, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 73.82919541052908, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.43569994712408233, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.2386591213456598, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.15656824652060405, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.2149316631804179, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 1.042148037933138, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.7299468612350343, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/663/params.json b/scipy/springs_two_slabs_compound/663/params.json new file mode 100644 index 0000000000000000000000000000000000000000..33fa2ad70c22b78070da5d69d55abf8f083a9e72 --- /dev/null +++ b/scipy/springs_two_slabs_compound/663/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 1.090931236296731, + "m_2": 0.5297127087893403, + "K_top": 137.042996520609, + "K_mid": 73.82919541052908, + "L_top": 0.43569994712408233, + "L_mid": 0.2386591213456598, + "gamma_1": 0.15656824652060405, + "gamma_2": 0.2149316631804179, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 1.042148037933138, + "y2_0": 0.7299468612350343, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/663/simulation_code.py b/scipy/springs_two_slabs_compound/663/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..3be0923dff3c08cca2a3a132246ba2afe6a86395 --- /dev/null +++ b/scipy/springs_two_slabs_compound/663/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 1.090931236296731 +m_2 = 0.5297127087893403 +K_top = 137.042996520609 +K_mid = 73.82919541052908 +L_top = 0.43569994712408233 +L_mid = 0.2386591213456598 +gamma_1 = 0.15656824652060405 +gamma_2 = 0.2149316631804179 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 1.042148037933138 +y2_0 = 0.7299468612350343 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/663/video.mp4 b/scipy/springs_two_slabs_compound/663/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..389fd52f466ae94d61afa4ef660fd95c6f8cd87e --- /dev/null +++ b/scipy/springs_two_slabs_compound/663/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5edac5b95dec20cba0c3aa7d6d19bb557af8ea25bca2c4f3c2dd3cf3d689846 +size 83058 diff --git a/scipy/springs_two_slabs_compound/677/cot.json b/scipy/springs_two_slabs_compound/677/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..b2d93af7e8a5b66cf0d69e9e657ac408d78f024a --- /dev/null +++ b/scipy/springs_two_slabs_compound/677/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=85.50 N/m support an upper slab of mass m_1=0.674 kg. From the upper slab, a second parallel-spring bank K_mid=36.11 N/m hangs a lower slab of mass m_2=0.541 kg. Linear viscous damping gamma_1=0.164 kg/s, gamma_2=0.273 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 13.434 rad/s -> T_1 = 0.468 s; omega_2 = \\sqrt(K_mid/m_2) = 8.171 rad/s -> T_2 = 0.769 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 13.433825102363517, + "omega_2_uncoupled_rad_per_s": 8.170966055755803, + "T_1_uncoupled_s": 0.4677137940462048, + "T_2_uncoupled_s": 0.7689648034645274 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~13.43 rad/s, lower slab near omega_2~8.17 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 0.673832412930165, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.5408308444421838, + "unit": "", + "description": "" + }, + "K_top": { + "value": 85.4965550298419, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 36.108401662062775, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.47045785339427454, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.2802205404272811, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.1641935977200652, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.2728487520414047, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 0.982072309283114, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.6547492550863991, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/677/params.json b/scipy/springs_two_slabs_compound/677/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6ed9b53ca491933dbc5af2cb7cb7d51ae24f2d55 --- /dev/null +++ b/scipy/springs_two_slabs_compound/677/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 0.673832412930165, + "m_2": 0.5408308444421838, + "K_top": 85.4965550298419, + "K_mid": 36.108401662062775, + "L_top": 0.47045785339427454, + "L_mid": 0.2802205404272811, + "gamma_1": 0.1641935977200652, + "gamma_2": 0.2728487520414047, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 0.982072309283114, + "y2_0": 0.6547492550863991, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/677/simulation_code.py b/scipy/springs_two_slabs_compound/677/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e67449531c804886938f4daf06de9ae65ba3706c --- /dev/null +++ b/scipy/springs_two_slabs_compound/677/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 0.673832412930165 +m_2 = 0.5408308444421838 +K_top = 85.4965550298419 +K_mid = 36.108401662062775 +L_top = 0.47045785339427454 +L_mid = 0.2802205404272811 +gamma_1 = 0.1641935977200652 +gamma_2 = 0.2728487520414047 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 0.982072309283114 +y2_0 = 0.6547492550863991 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/677/video.mp4 b/scipy/springs_two_slabs_compound/677/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e1e30ae12ce6a35e02282352ac71d309c0f68f32 --- /dev/null +++ b/scipy/springs_two_slabs_compound/677/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9538b11f286cd2773bf443e258c429f99f9b418a98b1a6469929ba12b4a7a14d +size 39337 diff --git a/scipy/springs_two_slabs_compound/806/cot.json b/scipy/springs_two_slabs_compound/806/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..46d8fccbcb9a40139f42819d4557501e279932b7 --- /dev/null +++ b/scipy/springs_two_slabs_compound/806/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=168.38 N/m support an upper slab of mass m_1=1.225 kg. From the upper slab, a second parallel-spring bank K_mid=35.18 N/m hangs a lower slab of mass m_2=0.333 kg. Linear viscous damping gamma_1=0.122 kg/s, gamma_2=0.149 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 12.890 rad/s -> T_1 = 0.487 s; omega_2 = \\sqrt(K_mid/m_2) = 10.286 rad/s -> T_2 = 0.611 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 12.890282181202375, + "omega_2_uncoupled_rad_per_s": 10.286275770183549, + "T_1_uncoupled_s": 0.48743582327020135, + "T_2_uncoupled_s": 0.6108318936375812 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~12.89 rad/s, lower slab near omega_2~10.29 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 1.2251294062863654, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.3325180533745029, + "unit": "", + "description": "" + }, + "K_top": { + "value": 168.3838423910247, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 35.18289369760521, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.36711930037238616, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.3244192880529665, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.12162784016999985, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.14910428522643282, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 0.9744357864338412, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.6710670176990075, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/806/params.json b/scipy/springs_two_slabs_compound/806/params.json new file mode 100644 index 0000000000000000000000000000000000000000..f7b979be075f56330e1b88406d83d4d7788550ae --- /dev/null +++ b/scipy/springs_two_slabs_compound/806/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 1.2251294062863654, + "m_2": 0.3325180533745029, + "K_top": 168.3838423910247, + "K_mid": 35.18289369760521, + "L_top": 0.36711930037238616, + "L_mid": 0.3244192880529665, + "gamma_1": 0.12162784016999985, + "gamma_2": 0.14910428522643282, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 0.9744357864338412, + "y2_0": 0.6710670176990075, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/806/simulation_code.py b/scipy/springs_two_slabs_compound/806/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..1df9dd32dde2d192f6c2cbd6cca41964c8b5f212 --- /dev/null +++ b/scipy/springs_two_slabs_compound/806/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 1.2251294062863654 +m_2 = 0.3325180533745029 +K_top = 168.3838423910247 +K_mid = 35.18289369760521 +L_top = 0.36711930037238616 +L_mid = 0.3244192880529665 +gamma_1 = 0.12162784016999985 +gamma_2 = 0.14910428522643282 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 0.9744357864338412 +y2_0 = 0.6710670176990075 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/806/video.mp4 b/scipy/springs_two_slabs_compound/806/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6b22c3f9c1240098986dafb7ccc7076d3d954425 --- /dev/null +++ b/scipy/springs_two_slabs_compound/806/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab8fc0b9a879c9c1071b92e15e8acc323bc1b8d1cdbab9f00b2db12b2820f08c +size 65799 diff --git a/scipy/springs_two_slabs_compound/810/cot.json b/scipy/springs_two_slabs_compound/810/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4cae9e341ee8c8202ee965d2069da685083bf457 --- /dev/null +++ b/scipy/springs_two_slabs_compound/810/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=135.10 N/m support an upper slab of mass m_1=1.033 kg. From the upper slab, a second parallel-spring bank K_mid=63.69 N/m hangs a lower slab of mass m_2=0.536 kg. Linear viscous damping gamma_1=0.332 kg/s, gamma_2=0.169 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 13.871 rad/s -> T_1 = 0.453 s; omega_2 = \\sqrt(K_mid/m_2) = 10.903 rad/s -> T_2 = 0.576 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 13.87103296508688, + "omega_2_uncoupled_rad_per_s": 10.90283974197274, + "T_1_uncoupled_s": 0.4529716945374034, + "T_2_uncoupled_s": 0.5762888803172226 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~13.87 rad/s, lower slab near omega_2~10.90 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 1.033169722898592, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.5357969973331774, + "unit": "", + "description": "" + }, + "K_top": { + "value": 135.09637965548845, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 63.69121482373769, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.38119799584187547, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.31535467752597357, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.331974591277174, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.16858582325280536, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 1.012179714776743, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.6625523315381967, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/810/params.json b/scipy/springs_two_slabs_compound/810/params.json new file mode 100644 index 0000000000000000000000000000000000000000..689ecbce470d4e1b35aa442e2752b722ef20778a --- /dev/null +++ b/scipy/springs_two_slabs_compound/810/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 1.033169722898592, + "m_2": 0.5357969973331774, + "K_top": 135.09637965548845, + "K_mid": 63.69121482373769, + "L_top": 0.38119799584187547, + "L_mid": 0.31535467752597357, + "gamma_1": 0.331974591277174, + "gamma_2": 0.16858582325280536, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 1.012179714776743, + "y2_0": 0.6625523315381967, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/810/simulation_code.py b/scipy/springs_two_slabs_compound/810/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..4ea967d94623da8b71cf6c460b3904629d7a3880 --- /dev/null +++ b/scipy/springs_two_slabs_compound/810/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 1.033169722898592 +m_2 = 0.5357969973331774 +K_top = 135.09637965548845 +K_mid = 63.69121482373769 +L_top = 0.38119799584187547 +L_mid = 0.31535467752597357 +gamma_1 = 0.331974591277174 +gamma_2 = 0.16858582325280536 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 1.012179714776743 +y2_0 = 0.6625523315381967 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/810/video.mp4 b/scipy/springs_two_slabs_compound/810/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a740dbdf72eff1e091572fb783b77ef99a32545b --- /dev/null +++ b/scipy/springs_two_slabs_compound/810/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b704ca0c0c94e23079e365830c88ed2d435c040a13cdf2659f97ee4b57ce8a36 +size 70616 diff --git a/scipy/springs_two_slabs_compound/823/cot.json b/scipy/springs_two_slabs_compound/823/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d3f1397000682c3ec4033c92c9a2c6c7893cddf4 --- /dev/null +++ b/scipy/springs_two_slabs_compound/823/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=126.55 N/m support an upper slab of mass m_1=0.606 kg. From the upper slab, a second parallel-spring bank K_mid=45.49 N/m hangs a lower slab of mass m_2=0.336 kg. Linear viscous damping gamma_1=0.248 kg/s, gamma_2=0.099 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 16.849 rad/s -> T_1 = 0.373 s; omega_2 = \\sqrt(K_mid/m_2) = 11.635 rad/s -> T_2 = 0.540 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 16.848991761270323, + "omega_2_uncoupled_rad_per_s": 11.635248893750662, + "T_1_uncoupled_s": 0.37291164932624243, + "T_2_uncoupled_s": 0.5400129696025936 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~16.85 rad/s, lower slab near omega_2~11.64 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 0.606029385911036, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.3360388800223775, + "unit": "", + "description": "" + }, + "K_top": { + "value": 126.55217429536907, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 45.49261319056412, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.45640697725902385, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.2656666920667167, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.2484863926094903, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.09855322910050412, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 1.0115713776282405, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.746140411250939, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/823/params.json b/scipy/springs_two_slabs_compound/823/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c1b1bb870a25c52a82b052d7a3412bfb734e1fdf --- /dev/null +++ b/scipy/springs_two_slabs_compound/823/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 0.606029385911036, + "m_2": 0.3360388800223775, + "K_top": 126.55217429536907, + "K_mid": 45.49261319056412, + "L_top": 0.45640697725902385, + "L_mid": 0.2656666920667167, + "gamma_1": 0.2484863926094903, + "gamma_2": 0.09855322910050412, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 1.0115713776282405, + "y2_0": 0.746140411250939, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/823/simulation_code.py b/scipy/springs_two_slabs_compound/823/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..00f1c807331a01985dad0b2a7532693dc27f2d4e --- /dev/null +++ b/scipy/springs_two_slabs_compound/823/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 0.606029385911036 +m_2 = 0.3360388800223775 +K_top = 126.55217429536907 +K_mid = 45.49261319056412 +L_top = 0.45640697725902385 +L_mid = 0.2656666920667167 +gamma_1 = 0.2484863926094903 +gamma_2 = 0.09855322910050412 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 1.0115713776282405 +y2_0 = 0.746140411250939 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/823/video.mp4 b/scipy/springs_two_slabs_compound/823/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..d70547420a47443b252d97055c939e8086258b61 --- /dev/null +++ b/scipy/springs_two_slabs_compound/823/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c9d97e186991aa536db062e0d9d21d5de9347b7edac07bf0aef385716aa3f96c +size 80986 diff --git a/scipy/springs_two_slabs_compound/946/cot.json b/scipy/springs_two_slabs_compound/946/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..2f4a48577f8e81f8140544b7e8778543a1f7e07a --- /dev/null +++ b/scipy/springs_two_slabs_compound/946/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=96.67 N/m support an upper slab of mass m_1=1.267 kg. From the upper slab, a second parallel-spring bank K_mid=60.79 N/m hangs a lower slab of mass m_2=0.405 kg. Linear viscous damping gamma_1=0.150 kg/s, gamma_2=0.223 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 11.150 rad/s -> T_1 = 0.564 s; omega_2 = \\sqrt(K_mid/m_2) = 12.256 rad/s -> T_2 = 0.513 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 11.150277419442677, + "omega_2_uncoupled_rad_per_s": 12.256113464609035, + "T_1_uncoupled_s": 0.5635003570605006, + "T_2_uncoupled_s": 0.5126572404313179 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~11.15 rad/s, lower slab near omega_2~12.26 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 1.2665089526172038, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.4046861772370986, + "unit": "", + "description": "" + }, + "K_top": { + "value": 96.67454611324665, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 60.78884844481168, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.41346072529774247, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.21379676716842996, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.15013378973424218, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.22321462142464837, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 1.041082559607513, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.7267072332291329, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/946/params.json b/scipy/springs_two_slabs_compound/946/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6c65a8fd3d4c796df2d7f2743daa40a23ab21b12 --- /dev/null +++ b/scipy/springs_two_slabs_compound/946/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 1.2665089526172038, + "m_2": 0.4046861772370986, + "K_top": 96.67454611324665, + "K_mid": 60.78884844481168, + "L_top": 0.41346072529774247, + "L_mid": 0.21379676716842996, + "gamma_1": 0.15013378973424218, + "gamma_2": 0.22321462142464837, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 1.041082559607513, + "y2_0": 0.7267072332291329, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/946/simulation_code.py b/scipy/springs_two_slabs_compound/946/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..eb9e7773bf4a791f372c477028a82965acd157d2 --- /dev/null +++ b/scipy/springs_two_slabs_compound/946/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 1.2665089526172038 +m_2 = 0.4046861772370986 +K_top = 96.67454611324665 +K_mid = 60.78884844481168 +L_top = 0.41346072529774247 +L_mid = 0.21379676716842996 +gamma_1 = 0.15013378973424218 +gamma_2 = 0.22321462142464837 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 1.041082559607513 +y2_0 = 0.7267072332291329 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/946/video.mp4 b/scipy/springs_two_slabs_compound/946/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c66155f8c33b59f0534b13cf65ea14a73c04bfd8 --- /dev/null +++ b/scipy/springs_two_slabs_compound/946/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0c4fab94f4ec5df3fa40d1346fd15d61f635b1b26f5c0aae369740a5b71b79c +size 88367 diff --git a/scipy/springs_two_slabs_compound/956/cot.json b/scipy/springs_two_slabs_compound/956/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..8a570781125c4d5fa798136f33b143e08f4ce8f0 --- /dev/null +++ b/scipy/springs_two_slabs_compound/956/cot.json @@ -0,0 +1,147 @@ +{ + "simulation": "springs_two_slabs_compound", + "physical_observation": "From a rigid ceiling at y=1.40 m, parallel-springs of effective stiffness K_top=80.84 N/m support an upper slab of mass m_1=1.174 kg. From the upper slab, a second parallel-spring bank K_mid=74.96 N/m hangs a lower slab of mass m_2=0.612 kg. Linear viscous damping gamma_1=0.306 kg/s, gamma_2=0.299 kg/s acts on each slab. The system oscillates and settles to its damped two-mass equilibrium under gravity.", + "physical_law": { + "name": "Newton's Second Law (Coupled Linear Spring-Mass System)", + "statement": "Linear superposition of Hookean restoring forces, viscous damping, and gravity for two coupled DoF.", + "formula": "m_1 y1_dd = K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g; m_2 y2_dd = K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g" + }, + "ode_system": { + "state_variables": [ + "y_1", + "y_2", + "v_1", + "v_2" + ], + "equations_latex": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 v_1 - m_1 g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 v_2 - m_2 g)/m_2" + ], + "equations_python": [ + "dy1/dt = v_1; dy2/dt = v_2", + "dv1/dt = (K_top (y_ceil - y_1 - L_top) - K_mid (y_1 - y_2 - L_mid) - gamma_1 * v_1 - m_1 * g)/m_1", + "dv2/dt = (K_mid (y_1 - y_2 - L_mid) - gamma_2 * v_2 - m_2 * g)/m_2" + ] + }, + "derivation_steps": [ + "Treat each spring bank as a single effective Hookean spring with K = sum of individual k.", + "For the upper slab: top spring pulls up if stretched, middle spring pulls down on slab 1 if stretched.", + "Hooke's law for each: F = K \\cdot stretch, where stretch = (separation distance) - rest length.", + "Add gravity (-m g, downward) and viscous damping (-gamma v) to each equation.", + "Approx uncoupled natural frequencies: omega_1 = \\sqrt((K_top+K_mid)/m_1) = 11.518 rad/s -> T_1 = 0.546 s; omega_2 = \\sqrt(K_mid/m_2) = 11.066 rad/s -> T_2 = 0.568 s." + ], + "physical_constants_derived": { + "omega_1_uncoupled_rad_per_s": 11.517743151394404, + "omega_2_uncoupled_rad_per_s": 11.065582112253363, + "T_1_uncoupled_s": 0.5455222628765521, + "T_2_uncoupled_s": 0.5678133552704799 + }, + "numerical_method": { + "solver": "scipy.solve_ivp RK45", + "tolerance": "rtol=1e-9, atol=1e-11", + "justification": "Smooth linear ODE; RK45 with tight tolerances captures both natural modes." + }, + "code_validation": { + "ode_source": "Newton II for each slab with Hookean spring forces, gravity, and linear damping.", + "energy_check": "Total mechanical energy decreases monotonically due to viscous damping; reaches static equilibrium asymptotically.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Upper slab oscillates near omega_1~11.52 rad/s, lower slab near omega_2~11.07 rad/s.", + "Coupling between slabs gives two normal modes; damping makes the motion settle.", + "Equilibrium positions shifted downward from rest lengths by gravity-induced stretches." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "m_1": { + "value": 1.1744087865096198, + "unit": "", + "description": "" + }, + "m_2": { + "value": 0.6121481805485589, + "unit": "", + "description": "" + }, + "K_top": { + "value": 80.83942508007944, + "unit": "", + "description": "" + }, + "K_mid": { + "value": 74.95577405916549, + "unit": "", + "description": "" + }, + "L_top": { + "value": 0.32601190908475014, + "unit": "", + "description": "" + }, + "L_mid": { + "value": 0.3462794133208309, + "unit": "", + "description": "" + }, + "gamma_1": { + "value": 0.3060338393410751, + "unit": "", + "description": "" + }, + "gamma_2": { + "value": 0.29854988857059966, + "unit": "", + "description": "" + }, + "y_ceil": { + "value": 1.4, + "unit": "", + "description": "" + }, + "slab_w_1": { + "value": 0.8, + "unit": "", + "description": "" + }, + "slab_h_1": { + "value": 0.06, + "unit": "", + "description": "" + }, + "slab_w_2": { + "value": 0.5, + "unit": "", + "description": "" + }, + "slab_h_2": { + "value": 0.06, + "unit": "", + "description": "" + }, + "y1_0": { + "value": 0.9764730291394289, + "unit": "", + "description": "" + }, + "y2_0": { + "value": 0.6918884085709628, + "unit": "", + "description": "" + }, + "v1_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v2_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/springs_two_slabs_compound/956/params.json b/scipy/springs_two_slabs_compound/956/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c749fa0476677b44bdf42524af4f463dfd92f1e5 --- /dev/null +++ b/scipy/springs_two_slabs_compound/956/params.json @@ -0,0 +1,20 @@ +{ + "g": 9.8, + "m_1": 1.1744087865096198, + "m_2": 0.6121481805485589, + "K_top": 80.83942508007944, + "K_mid": 74.95577405916549, + "L_top": 0.32601190908475014, + "L_mid": 0.3462794133208309, + "gamma_1": 0.3060338393410751, + "gamma_2": 0.29854988857059966, + "y_ceil": 1.4, + "slab_w_1": 0.8, + "slab_h_1": 0.06, + "slab_w_2": 0.5, + "slab_h_2": 0.06, + "y1_0": 0.9764730291394289, + "y2_0": 0.6918884085709628, + "v1_0": 0.0, + "v2_0": 0.0 +} \ No newline at end of file diff --git a/scipy/springs_two_slabs_compound/956/simulation_code.py b/scipy/springs_two_slabs_compound/956/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..4fddf682c213c0f853a27c5eaab08bce1876a504 --- /dev/null +++ b/scipy/springs_two_slabs_compound/956/simulation_code.py @@ -0,0 +1,99 @@ +"""Springs Two Slabs Compound — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +m_1 = 1.1744087865096198 +m_2 = 0.6121481805485589 +K_top = 80.83942508007944 +K_mid = 74.95577405916549 +L_top = 0.32601190908475014 +L_mid = 0.3462794133208309 +gamma_1 = 0.3060338393410751 +gamma_2 = 0.29854988857059966 +y_ceil = 1.4 +slab_w_1 = 0.8 +slab_h_1 = 0.06 +slab_w_2 = 0.5 +slab_h_2 = 0.06 +y1_0 = 0.9764730291394289 +y2_0 = 0.6918884085709628 +v1_0 = 0.0 +v2_0 = 0.0 +duration = 12 +fps = 30 +N_top, N_mid = 3, 2 + +def ode(t, y): + y1, y2, v1, v2 = y + F_top = K_top * (y_ceil - y1 - L_top) + F_mid = K_mid * (y1 - y2 - L_mid) + a1 = (F_top - F_mid - gamma_1*v1 - m_1*g)/m_1 + a2 = (F_mid - gamma_2*v2 - m_2*g)/m_2 + return [v1, v2, a1, a2] + +t_eval = np.linspace(0, duration, int(duration*fps)+1) +sol = solve_ivp(ode, (0, duration), [y1_0, y2_0, v1_0, v2_0], + t_eval=t_eval, method="RK45", rtol=1e-9, atol=1e-11) +y1a, y2a = sol.y[0], sol.y[1] + +xpad = 0.20 +half_w = max(slab_w_1, slab_w_2)/2.0 +xlim_lo, xlim_hi = -half_w-xpad, half_w+xpad +ylim_lo, ylim_hi = -0.10, y_ceil+0.10 + +fig, ax = plt.subplots(figsize=(6,6), facecolor="#1a1a2e") +fig.subplots_adjust(left=0, right=1, bottom=0, top=1) +ax.set_facecolor("#16213e") +ax.set_xlim(xlim_lo, xlim_hi); ax.set_ylim(ylim_lo, ylim_hi) +ax.set_aspect("equal"); ax.axis("off") +ax.plot([xlim_lo, xlim_hi], [y_ceil, y_ceil], color="#adb5bd", lw=2.5, zorder=2) +ax.add_patch(patches.Rectangle((xlim_lo, y_ceil), xlim_hi-xlim_lo, 0.06, + facecolor="#4a4e69", edgecolor="#adb5bd", lw=1, hatch="////", zorder=2)) + +def even_x(n, width, centre=0.0): + if n == 1: return np.array([centre]) + inset = min(0.06, width*0.12) + return np.linspace(centre - width/2.0 + inset, centre + width/2.0 - inset, n) + +top_xs = even_x(N_top, slab_w_1, 0.0) +mid_xs = even_x(N_mid, slab_w_2, 0.0) + +def vertical_spring_path(x, y_top, y_bot, n=8, r=0.04): + ts = np.linspace(0, 1, n*20+2) + margin = 0.08 + env = np.where((ts1-margin), 0, + np.sin(n*2*np.pi*(ts-margin)/(1-2*margin))) + ys = y_top + ts*(y_bot-y_top) + xs = x + r*env + return xs, ys + +top_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_top)] +mid_lines = [ax.plot([], [], "-", color="#a8dadc", lw=2.0, zorder=3)[0] for _ in range(N_mid)] +slab1 = patches.Rectangle((-slab_w_1/2, y1_0-slab_h_1/2), slab_w_1, slab_h_1, + facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=4) +slab2 = patches.Rectangle((-slab_w_2/2, y2_0-slab_h_2/2), slab_w_2, slab_h_2, + facecolor="#ffd166", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(slab1); ax.add_patch(slab2) + +def update(f): + y1, y2 = y1a[f], y2a[f] + slab1.set_y(y1 - slab_h_1/2); slab2.set_y(y2 - slab_h_2/2) + upper_top = y1 + slab_h_1/2 + upper_bot = y1 - slab_h_1/2 + lower_top = y2 + slab_h_2/2 + for i, ln in enumerate(top_lines): + xs, ys = vertical_spring_path(top_xs[i], y_ceil, upper_top) + ln.set_data(xs, ys) + for i, ln in enumerate(mid_lines): + xs, ys = vertical_spring_path(mid_xs[i], upper_bot, lower_top) + ln.set_data(xs, ys) + return top_lines + mid_lines + [slab1, slab2] + +ani = animation.FuncAnimation(fig, update, frames=len(sol.t), interval=1000/fps, blit=False) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/springs_two_slabs_compound/956/video.mp4 b/scipy/springs_two_slabs_compound/956/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..146104a65d024fb0f828b9e7e9745ff660d800d6 --- /dev/null +++ b/scipy/springs_two_slabs_compound/956/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:819863a16b329b9cc6f3e813f799d8efdc0509dc4ba9d825a05d88396eff0e4a +size 80446 diff --git a/scipy/stacked_balls_drop/061/cot.json b/scipy/stacked_balls_drop/061/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..99260f64accc148d370c782c188d043c40d48c3f --- /dev/null +++ b/scipy/stacked_balls_drop/061/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.989 kg, radius R=0.132 m) and a light upper ball (m=0.251 kg, radius r=0.092 m) are stacked vertically and released from rest with the lower-ball centre at 0.939 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.940 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.958). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.807 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.977 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 3.737 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 9.962 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.977241553580007, + "v_after_floor_mps": 3.7370226029601668, + "approx_upper_post_collision_mps": 9.961529395453644, + "mass_ratio_M_over_m": 11.925708781254215 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.98 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.9885133586164154, + "unit": "", + "description": "" + }, + "R": { + "value": 0.13193488865615466, + "unit": "", + "description": "" + }, + "m": { + "value": 0.25059419221388335, + "unit": "", + "description": "" + }, + "r": { + "value": 0.09153505685049969, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.9396016190156684, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.9583943269553593, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.9389986833257213, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/061/params.json b/scipy/stacked_balls_drop/061/params.json new file mode 100644 index 0000000000000000000000000000000000000000..370d6bb88b9927759c16685eb5c40ddbadbf6552 --- /dev/null +++ b/scipy/stacked_balls_drop/061/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.9885133586164154, + "R": 0.13193488865615466, + "m": 0.25059419221388335, + "r": 0.09153505685049969, + "e_floor": 0.9396016190156684, + "e_b": 0.9583943269553593, + "y_lower_0": 0.9389986833257213, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/061/simulation_code.py b/scipy/stacked_balls_drop/061/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..0ac4d1dbd7fdd3452f378911d846093dba3f4e62 --- /dev/null +++ b/scipy/stacked_balls_drop/061/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.9885133586164154 +R = 0.13193488865615466 +m = 0.25059419221388335 +r = 0.09153505685049969 +e_floor = 0.9396016190156684 +e_b = 0.9583943269553593 +y_lower_0 = 0.9389986833257213 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/061/video.mp4 b/scipy/stacked_balls_drop/061/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..7a470cfb4cc00226bebf31e14a250150001fbf67 --- /dev/null +++ b/scipy/stacked_balls_drop/061/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3f56925c29aafbec19d471d1b7771d31e2193d338fe15221808f9fad02789d1e +size 16310 diff --git a/scipy/stacked_balls_drop/073/cot.json b/scipy/stacked_balls_drop/073/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..9b1ffb6f08dcfd98ce2ba7b6a424c1ff4c431475 --- /dev/null +++ b/scipy/stacked_balls_drop/073/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=1.980 kg, radius R=0.110 m) and a light upper ball (m=0.238 kg, radius r=0.054 m) are stacked vertically and released from rest with the lower-ball centre at 0.922 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.816 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.939). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.812 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.989 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 3.257 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 8.557 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.9891693576347516, + "v_after_floor_mps": 3.2570990495262047, + "approx_upper_post_collision_mps": 8.557037159380293, + "mass_ratio_M_over_m": 8.32177157738645 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.99 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.9803768517837685, + "unit": "", + "description": "" + }, + "R": { + "value": 0.11043924682302975, + "unit": "", + "description": "" + }, + "m": { + "value": 0.23797539182224575, + "unit": "", + "description": "" + }, + "r": { + "value": 0.05444205783421055, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.816485528069281, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.939459349337819, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.9223510919195632, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/073/params.json b/scipy/stacked_balls_drop/073/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ff695585afaffc8925aa36529c3e7191b5417634 --- /dev/null +++ b/scipy/stacked_balls_drop/073/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.9803768517837685, + "R": 0.11043924682302975, + "m": 0.23797539182224575, + "r": 0.05444205783421055, + "e_floor": 0.816485528069281, + "e_b": 0.939459349337819, + "y_lower_0": 0.9223510919195632, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/073/simulation_code.py b/scipy/stacked_balls_drop/073/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d34dc21220f1386f440d1af56350b5ae8e81372d --- /dev/null +++ b/scipy/stacked_balls_drop/073/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 1.9803768517837685 +R = 0.11043924682302975 +m = 0.23797539182224575 +r = 0.05444205783421055 +e_floor = 0.816485528069281 +e_b = 0.939459349337819 +y_lower_0 = 0.9223510919195632 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/073/video.mp4 b/scipy/stacked_balls_drop/073/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..8edda070cc5d03697eec0e9792f1f5a4e2ed7eed --- /dev/null +++ b/scipy/stacked_balls_drop/073/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:90733486f7a0eef842984c948e0b504f8f4c1e09492e7cc52607cb449168b372 +size 13607 diff --git a/scipy/stacked_balls_drop/127/cot.json b/scipy/stacked_balls_drop/127/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..6d6d0c496ffe874992f29ade3f3219893340120c --- /dev/null +++ b/scipy/stacked_balls_drop/127/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.532 kg, radius R=0.148 m) and a light upper ball (m=0.176 kg, radius r=0.068 m) are stacked vertically and released from rest with the lower-ball centre at 0.963 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.858 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.932). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.815 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.997 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 3.431 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 9.420 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.997031579283475, + "v_after_floor_mps": 3.4306776136754853, + "approx_upper_post_collision_mps": 9.420388363743841, + "mass_ratio_M_over_m": 14.409736180555775 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~4.00 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.532358101486354, + "unit": "", + "description": "" + }, + "R": { + "value": 0.14788191778854254, + "unit": "", + "description": "" + }, + "m": { + "value": 0.1757393799411449, + "unit": "", + "description": "" + }, + "r": { + "value": 0.06763025988991872, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.8583063570116909, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.9317605578278433, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.9629972976757544, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/127/params.json b/scipy/stacked_balls_drop/127/params.json new file mode 100644 index 0000000000000000000000000000000000000000..28a80fef6a878b62aa87a0d4c116f70ec36b2ce1 --- /dev/null +++ b/scipy/stacked_balls_drop/127/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.532358101486354, + "R": 0.14788191778854254, + "m": 0.1757393799411449, + "r": 0.06763025988991872, + "e_floor": 0.8583063570116909, + "e_b": 0.9317605578278433, + "y_lower_0": 0.9629972976757544, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/127/simulation_code.py b/scipy/stacked_balls_drop/127/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ffd95aa55217b07cc0119000a5fa49eec4e3a867 --- /dev/null +++ b/scipy/stacked_balls_drop/127/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.532358101486354 +R = 0.14788191778854254 +m = 0.1757393799411449 +r = 0.06763025988991872 +e_floor = 0.8583063570116909 +e_b = 0.9317605578278433 +y_lower_0 = 0.9629972976757544 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/127/video.mp4 b/scipy/stacked_balls_drop/127/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6ed10fe0dc472fcd0993162d2c19fb5452c9076f --- /dev/null +++ b/scipy/stacked_balls_drop/127/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1c5b720b0477e9ec432498078231a6758370d31f004b44edd1a7362a1f47e2e +size 12134 diff --git a/scipy/stacked_balls_drop/145/cot.json b/scipy/stacked_balls_drop/145/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..ec39c078821e05ab50e07c1209c950b23074f44d --- /dev/null +++ b/scipy/stacked_balls_drop/145/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.503 kg, radius R=0.107 m) and a light upper ball (m=0.242 kg, radius r=0.066 m) are stacked vertically and released from rest with the lower-ball centre at 0.624 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.930 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.852). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.517 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.184 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 2.962 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 7.196 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.1836238539038413, + "v_after_floor_mps": 2.9618679891516675, + "approx_upper_post_collision_mps": 7.195710878911951, + "mass_ratio_M_over_m": 10.351600642809792 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.18 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.502880918074582, + "unit": "", + "description": "" + }, + "R": { + "value": 0.10721566443950525, + "unit": "", + "description": "" + }, + "m": { + "value": 0.24178685059813235, + "unit": "", + "description": "" + }, + "r": { + "value": 0.0664297377628835, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.9303448287459427, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.8520916195758956, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.6243310135795841, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/145/params.json b/scipy/stacked_balls_drop/145/params.json new file mode 100644 index 0000000000000000000000000000000000000000..e977c7d83036e65bb619efa6add0bc5f9ade628f --- /dev/null +++ b/scipy/stacked_balls_drop/145/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.502880918074582, + "R": 0.10721566443950525, + "m": 0.24178685059813235, + "r": 0.0664297377628835, + "e_floor": 0.9303448287459427, + "e_b": 0.8520916195758956, + "y_lower_0": 0.6243310135795841, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/145/simulation_code.py b/scipy/stacked_balls_drop/145/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b245d23074b31cd4e32ece04dcaeef02fb0c80b2 --- /dev/null +++ b/scipy/stacked_balls_drop/145/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.502880918074582 +R = 0.10721566443950525 +m = 0.24178685059813235 +r = 0.0664297377628835 +e_floor = 0.9303448287459427 +e_b = 0.8520916195758956 +y_lower_0 = 0.6243310135795841 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/145/video.mp4 b/scipy/stacked_balls_drop/145/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0a07f40b170df256c92c7ee5bd5646d1f3497b46 --- /dev/null +++ b/scipy/stacked_balls_drop/145/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4cb9dc1bb15edbfc960babe3cbee29c92f7bb1341b5d6693a36e6a085918ca8 +size 14777 diff --git a/scipy/stacked_balls_drop/152/cot.json b/scipy/stacked_balls_drop/152/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..26459dcdc0af9632dc9345fa04530b8b66273691 --- /dev/null +++ b/scipy/stacked_balls_drop/152/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.394 kg, radius R=0.100 m) and a light upper ball (m=0.234 kg, radius r=0.057 m) are stacked vertically and released from rest with the lower-ball centre at 0.851 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.825 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.933). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.751 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.836 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 3.164 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 8.489 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.8363802203194255, + "v_after_floor_mps": 3.1641807822327856, + "approx_upper_post_collision_mps": 8.488830681326217, + "mass_ratio_M_over_m": 10.216334617096065 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.84 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.3941778448165447, + "unit": "", + "description": "" + }, + "R": { + "value": 0.10040370978830294, + "unit": "", + "description": "" + }, + "m": { + "value": 0.2343480254464371, + "unit": "", + "description": "" + }, + "r": { + "value": 0.05657043804164466, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.8247828944257587, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.9329355036841767, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.8513125462606561, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/152/params.json b/scipy/stacked_balls_drop/152/params.json new file mode 100644 index 0000000000000000000000000000000000000000..0b5bdc05d22fafdafc4118f1b98a92e354d2a3f0 --- /dev/null +++ b/scipy/stacked_balls_drop/152/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.3941778448165447, + "R": 0.10040370978830294, + "m": 0.2343480254464371, + "r": 0.05657043804164466, + "e_floor": 0.8247828944257587, + "e_b": 0.9329355036841767, + "y_lower_0": 0.8513125462606561, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/152/simulation_code.py b/scipy/stacked_balls_drop/152/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8858d3b33c55b05506a793d5aaee23fb8c53cf75 --- /dev/null +++ b/scipy/stacked_balls_drop/152/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.3941778448165447 +R = 0.10040370978830294 +m = 0.2343480254464371 +r = 0.05657043804164466 +e_floor = 0.8247828944257587 +e_b = 0.9329355036841767 +y_lower_0 = 0.8513125462606561 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/152/video.mp4 b/scipy/stacked_balls_drop/152/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..942a04f9b2eb2f496838a1340c51c91e13f8c2f6 --- /dev/null +++ b/scipy/stacked_balls_drop/152/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6578581a9ab03acf00a0800e594a37ec77903ace407ffd06204689198d7b54ad +size 13204 diff --git a/scipy/stacked_balls_drop/169/cot.json b/scipy/stacked_balls_drop/169/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..8d6cba7c979834f2ba6e0149815c6a716027e69c --- /dev/null +++ b/scipy/stacked_balls_drop/169/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.846 kg, radius R=0.133 m) and a light upper ball (m=0.193 kg, radius r=0.060 m) are stacked vertically and released from rest with the lower-ball centre at 0.856 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.923 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.861). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.723 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.765 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 3.476 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 8.858 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.7649931858246704, + "v_after_floor_mps": 3.4759532513442837, + "approx_upper_post_collision_mps": 8.85806410122443, + "mass_ratio_M_over_m": 14.768083077853358 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.76 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.846315497739928, + "unit": "", + "description": "" + }, + "R": { + "value": 0.13325565724429614, + "unit": "", + "description": "" + }, + "m": { + "value": 0.19273425553844187, + "unit": "", + "description": "" + }, + "r": { + "value": 0.05987097709107517, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.9232296261335526, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.8613326304539527, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.8564788046578777, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/169/params.json b/scipy/stacked_balls_drop/169/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8cac4119c0350b3cf20030832ddf62d42c699eae --- /dev/null +++ b/scipy/stacked_balls_drop/169/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.846315497739928, + "R": 0.13325565724429614, + "m": 0.19273425553844187, + "r": 0.05987097709107517, + "e_floor": 0.9232296261335526, + "e_b": 0.8613326304539527, + "y_lower_0": 0.8564788046578777, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/169/simulation_code.py b/scipy/stacked_balls_drop/169/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..58093a2439d74752e2b86316807ef63b17b18c89 --- /dev/null +++ b/scipy/stacked_balls_drop/169/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.846315497739928 +R = 0.13325565724429614 +m = 0.19273425553844187 +r = 0.05987097709107517 +e_floor = 0.9232296261335526 +e_b = 0.8613326304539527 +y_lower_0 = 0.8564788046578777 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/169/video.mp4 b/scipy/stacked_balls_drop/169/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..27941cef1b661ae192754fbc6958623e9a468168 --- /dev/null +++ b/scipy/stacked_balls_drop/169/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8902f5be48067de790e9cedadff7f189d7cea66dcd5f34462e7988300b7472c +size 15029 diff --git a/scipy/stacked_balls_drop/272/cot.json b/scipy/stacked_balls_drop/272/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..3a3b7425c9997d17689cc5473cf6e61860c65a2a --- /dev/null +++ b/scipy/stacked_balls_drop/272/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.204 kg, radius R=0.172 m) and a light upper ball (m=0.194 kg, radius r=0.084 m) are stacked vertically and released from rest with the lower-ball centre at 0.852 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.818 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.886). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.679 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.649 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 2.986 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 7.853 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.6492911607206144, + "v_after_floor_mps": 2.9859953332108615, + "approx_upper_post_collision_mps": 7.853020602480246, + "mass_ratio_M_over_m": 11.361282892555522 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.65 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.2040961013620968, + "unit": "", + "description": "" + }, + "R": { + "value": 0.17214805622408963, + "unit": "", + "description": "" + }, + "m": { + "value": 0.19400063550977417, + "unit": "", + "description": "" + }, + "r": { + "value": 0.08441463414084455, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.8182398174612151, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.8860865896425881, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.8516034631482533, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/272/params.json b/scipy/stacked_balls_drop/272/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3e6bee4161ceb009fe84f9c839aeaecc7107f7f7 --- /dev/null +++ b/scipy/stacked_balls_drop/272/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.2040961013620968, + "R": 0.17214805622408963, + "m": 0.19400063550977417, + "r": 0.08441463414084455, + "e_floor": 0.8182398174612151, + "e_b": 0.8860865896425881, + "y_lower_0": 0.8516034631482533, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/272/simulation_code.py b/scipy/stacked_balls_drop/272/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..7987de607a92ac50d4225ae7f5ab9027978e9582 --- /dev/null +++ b/scipy/stacked_balls_drop/272/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.2040961013620968 +R = 0.17214805622408963 +m = 0.19400063550977417 +r = 0.08441463414084455 +e_floor = 0.8182398174612151 +e_b = 0.8860865896425881 +y_lower_0 = 0.8516034631482533 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/272/video.mp4 b/scipy/stacked_balls_drop/272/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..77eac860c1b894af6ae0229c8670fb30e157f06c --- /dev/null +++ b/scipy/stacked_balls_drop/272/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37a6bdc0bf207fb79d015fc9d8594ce9730a3f02c2df3e6d8d431fcd2ac63568 +size 10731 diff --git a/scipy/stacked_balls_drop/295/cot.json b/scipy/stacked_balls_drop/295/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..2205ecc275a16bd5ecab9f2483798b4fe3cebc35 --- /dev/null +++ b/scipy/stacked_balls_drop/295/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=3.000 kg, radius R=0.112 m) and a light upper ball (m=0.273 kg, radius r=0.089 m) are stacked vertically and released from rest with the lower-ball centre at 0.927 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.799 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.863). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.816 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.998 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 3.195 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 8.287 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.9983166828248384, + "v_after_floor_mps": 3.1950691059613243, + "approx_upper_post_collision_mps": 8.28662820507407, + "mass_ratio_M_over_m": 10.987761227120936 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~4.00 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.9999076167327248, + "unit": "", + "description": "" + }, + "R": { + "value": 0.1116912733537494, + "unit": "", + "description": "" + }, + "m": { + "value": 0.2730226435325237, + "unit": "", + "description": "" + }, + "r": { + "value": 0.0890465507801195, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.7991035626782783, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.8632397067268845, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.9273308803004544, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/295/params.json b/scipy/stacked_balls_drop/295/params.json new file mode 100644 index 0000000000000000000000000000000000000000..bd133fdfa95f0d4b8f6558f879a70981f6fede48 --- /dev/null +++ b/scipy/stacked_balls_drop/295/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.9999076167327248, + "R": 0.1116912733537494, + "m": 0.2730226435325237, + "r": 0.0890465507801195, + "e_floor": 0.7991035626782783, + "e_b": 0.8632397067268845, + "y_lower_0": 0.9273308803004544, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/295/simulation_code.py b/scipy/stacked_balls_drop/295/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..61b647c9bfce30bcce430debbad51689b61bae84 --- /dev/null +++ b/scipy/stacked_balls_drop/295/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.9999076167327248 +R = 0.1116912733537494 +m = 0.2730226435325237 +r = 0.0890465507801195 +e_floor = 0.7991035626782783 +e_b = 0.8632397067268845 +y_lower_0 = 0.9273308803004544 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/295/video.mp4 b/scipy/stacked_balls_drop/295/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6fd2e80174c79aa00f7ddabfc2335408c139d3cf --- /dev/null +++ b/scipy/stacked_balls_drop/295/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be352aab95e6933f4bf4acfb93453162cbd6eef025d01cd1dd5fc996945268b0 +size 9813 diff --git a/scipy/stacked_balls_drop/311/cot.json b/scipy/stacked_balls_drop/311/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d95cfd40916af33383ea416033bbb09fbf18a211 --- /dev/null +++ b/scipy/stacked_balls_drop/311/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.294 kg, radius R=0.127 m) and a light upper ball (m=0.259 kg, radius r=0.080 m) are stacked vertically and released from rest with the lower-ball centre at 0.730 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.755 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.868). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.604 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.440 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 2.596 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 6.692 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.440182854997931, + "v_after_floor_mps": 2.5956723199459906, + "approx_upper_post_collision_mps": 6.691945092176186, + "mass_ratio_M_over_m": 8.847533367009163 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.44 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.2935692987336602, + "unit": "", + "description": "" + }, + "R": { + "value": 0.12666101307904795, + "unit": "", + "description": "" + }, + "m": { + "value": 0.25923262491283294, + "unit": "", + "description": "" + }, + "r": { + "value": 0.08032191928474688, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.754515800279329, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.8683881600300395, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.7304803026617885, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/311/params.json b/scipy/stacked_balls_drop/311/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b3a1a8701e78e5f230eb8bd13c8c0711e90c86cc --- /dev/null +++ b/scipy/stacked_balls_drop/311/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.2935692987336602, + "R": 0.12666101307904795, + "m": 0.25923262491283294, + "r": 0.08032191928474688, + "e_floor": 0.754515800279329, + "e_b": 0.8683881600300395, + "y_lower_0": 0.7304803026617885, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/311/simulation_code.py b/scipy/stacked_balls_drop/311/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..674c8848e04825bfcbd09d979fc335a7acab08ce --- /dev/null +++ b/scipy/stacked_balls_drop/311/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.2935692987336602 +R = 0.12666101307904795 +m = 0.25923262491283294 +r = 0.08032191928474688 +e_floor = 0.754515800279329 +e_b = 0.8683881600300395 +y_lower_0 = 0.7304803026617885 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/311/video.mp4 b/scipy/stacked_balls_drop/311/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f68109a843a4d56339e71cb8923f7c57b944c3d9 --- /dev/null +++ b/scipy/stacked_balls_drop/311/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6798b9fea72507c0dab2239a30fc0977c880b232be88d20e5a59c6bf40800cf9 +size 7424 diff --git a/scipy/stacked_balls_drop/314/cot.json b/scipy/stacked_balls_drop/314/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..879adb03c570526660b712733fbd78927b747e17 --- /dev/null +++ b/scipy/stacked_balls_drop/314/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.506 kg, radius R=0.128 m) and a light upper ball (m=0.201 kg, radius r=0.081 m) are stacked vertically and released from rest with the lower-ball centre at 0.997 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.842 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.942). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.869 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 4.127 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 3.475 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 9.536 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 4.126506577094526, + "v_after_floor_mps": 3.474867409618742, + "approx_upper_post_collision_mps": 9.536200839786417, + "mass_ratio_M_over_m": 12.464332747533655 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~4.13 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.5055396680116386, + "unit": "", + "description": "" + }, + "R": { + "value": 0.1277920787552368, + "unit": "", + "description": "" + }, + "m": { + "value": 0.2010167506565817, + "unit": "", + "description": "" + }, + "r": { + "value": 0.08124310123134316, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.8420845440807214, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.9416031565472247, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.9965704731840316, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/314/params.json b/scipy/stacked_balls_drop/314/params.json new file mode 100644 index 0000000000000000000000000000000000000000..fd6c10ade2d844305f6499f21db2cca7e2475470 --- /dev/null +++ b/scipy/stacked_balls_drop/314/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.5055396680116386, + "R": 0.1277920787552368, + "m": 0.2010167506565817, + "r": 0.08124310123134316, + "e_floor": 0.8420845440807214, + "e_b": 0.9416031565472247, + "y_lower_0": 0.9965704731840316, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/314/simulation_code.py b/scipy/stacked_balls_drop/314/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..89d0eb4578b07b1f55f6c8d370a5a69e2c0cdd01 --- /dev/null +++ b/scipy/stacked_balls_drop/314/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.5055396680116386 +R = 0.1277920787552368 +m = 0.2010167506565817 +r = 0.08124310123134316 +e_floor = 0.8420845440807214 +e_b = 0.9416031565472247 +y_lower_0 = 0.9965704731840316 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/314/video.mp4 b/scipy/stacked_balls_drop/314/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..084b69f390ab1a7c78fb3d00baa376a804e736b0 --- /dev/null +++ b/scipy/stacked_balls_drop/314/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ab16e56b65b921eb7f22bdf19ab03871efa1fb9a091a5edd68ac9650fd405fe +size 13784 diff --git a/scipy/stacked_balls_drop/412/cot.json b/scipy/stacked_balls_drop/412/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..eba7a9e6b17950ba24f3eab33240ffca5ae4b7d1 --- /dev/null +++ b/scipy/stacked_balls_drop/412/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=1.604 kg, radius R=0.154 m) and a light upper ball (m=0.115 kg, radius r=0.069 m) are stacked vertically and released from rest with the lower-ball centre at 0.806 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.837 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.914). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.652 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.575 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 2.992 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 8.156 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.5745494458172513, + "v_after_floor_mps": 2.9918071975422578, + "approx_upper_post_collision_mps": 8.156014549744409, + "mass_ratio_M_over_m": 13.960647685713155 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.57 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.6038503051890745, + "unit": "", + "description": "" + }, + "R": { + "value": 0.15414189673512788, + "unit": "", + "description": "" + }, + "m": { + "value": 0.11488366022089358, + "unit": "", + "description": "" + }, + "r": { + "value": 0.06921067398152068, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.8369746293601037, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.9144289557034263, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.806050250846986, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/412/params.json b/scipy/stacked_balls_drop/412/params.json new file mode 100644 index 0000000000000000000000000000000000000000..bfe2b876596590dae5e111d753f36442723010b9 --- /dev/null +++ b/scipy/stacked_balls_drop/412/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.6038503051890745, + "R": 0.15414189673512788, + "m": 0.11488366022089358, + "r": 0.06921067398152068, + "e_floor": 0.8369746293601037, + "e_b": 0.9144289557034263, + "y_lower_0": 0.806050250846986, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/412/simulation_code.py b/scipy/stacked_balls_drop/412/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..a2b29c67a7fcd81a0400393c10d24c22271d418e --- /dev/null +++ b/scipy/stacked_balls_drop/412/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 1.6038503051890745 +R = 0.15414189673512788 +m = 0.11488366022089358 +r = 0.06921067398152068 +e_floor = 0.8369746293601037 +e_b = 0.9144289557034263 +y_lower_0 = 0.806050250846986 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/412/video.mp4 b/scipy/stacked_balls_drop/412/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..023b64b243e6536312d85d5ceb04e69a7cb42f36 --- /dev/null +++ b/scipy/stacked_balls_drop/412/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:686be2968e6f5f71ba93c7385288db96bc6fbdcbf2aa6a8fbaf524af96e0774f +size 10369 diff --git a/scipy/stacked_balls_drop/449/cot.json b/scipy/stacked_balls_drop/449/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..a5ba74e98dedf795e92c6263b96aec2f438df559 --- /dev/null +++ b/scipy/stacked_balls_drop/449/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.307 kg, radius R=0.116 m) and a light upper ball (m=0.280 kg, radius r=0.089 m) are stacked vertically and released from rest with the lower-ball centre at 0.968 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.874 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.850). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.852 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 4.086 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 3.572 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 8.548 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 4.086374674175052, + "v_after_floor_mps": 3.5717898398668075, + "approx_upper_post_collision_mps": 8.54823923122708, + "mass_ratio_M_over_m": 8.226822075708064 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~4.09 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.3074231347637157, + "unit": "", + "description": "" + }, + "R": { + "value": 0.11644228570939788, + "unit": "", + "description": "" + }, + "m": { + "value": 0.28047563366868133, + "unit": "", + "description": "" + }, + "r": { + "value": 0.08942311403666724, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.8740730169555175, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.8503646572450634, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.9684044274307886, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/449/params.json b/scipy/stacked_balls_drop/449/params.json new file mode 100644 index 0000000000000000000000000000000000000000..546b0e8d573d40d542d29addb7f3710ac9660082 --- /dev/null +++ b/scipy/stacked_balls_drop/449/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.3074231347637157, + "R": 0.11644228570939788, + "m": 0.28047563366868133, + "r": 0.08942311403666724, + "e_floor": 0.8740730169555175, + "e_b": 0.8503646572450634, + "y_lower_0": 0.9684044274307886, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/449/simulation_code.py b/scipy/stacked_balls_drop/449/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..c98c781f729c836f522f211023fef60689c868e7 --- /dev/null +++ b/scipy/stacked_balls_drop/449/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.3074231347637157 +R = 0.11644228570939788 +m = 0.28047563366868133 +r = 0.08942311403666724 +e_floor = 0.8740730169555175 +e_b = 0.8503646572450634 +y_lower_0 = 0.9684044274307886 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/449/video.mp4 b/scipy/stacked_balls_drop/449/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..314d44b94afce693d02d690289547104211e8445 --- /dev/null +++ b/scipy/stacked_balls_drop/449/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7deda333229ca2fe2c0385427419da039d83f4f301b990d582fa25e5ad98822 +size 14469 diff --git a/scipy/stacked_balls_drop/479/cot.json b/scipy/stacked_balls_drop/479/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2e5832601693d9e670d386edc9557ccb9536f3 --- /dev/null +++ b/scipy/stacked_balls_drop/479/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=1.908 kg, radius R=0.155 m) and a light upper ball (m=0.244 kg, radius r=0.053 m) are stacked vertically and released from rest with the lower-ball centre at 0.935 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.930 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.971). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.780 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.909 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 3.634 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 9.273 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.9091768636401922, + "v_after_floor_mps": 3.633922689691755, + "approx_upper_post_collision_mps": 9.273444985798497, + "mass_ratio_M_over_m": 7.811865093601388 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.91 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.9082499175073246, + "unit": "", + "description": "" + }, + "R": { + "value": 0.15523503905856884, + "unit": "", + "description": "" + }, + "m": { + "value": 0.24427584125465132, + "unit": "", + "description": "" + }, + "r": { + "value": 0.052634100624814745, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.9295876898002198, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.9713560031718845, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.9349117610595774, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/479/params.json b/scipy/stacked_balls_drop/479/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ac6e958df30b88c1e762dc192f5fcd24271db6a4 --- /dev/null +++ b/scipy/stacked_balls_drop/479/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.9082499175073246, + "R": 0.15523503905856884, + "m": 0.24427584125465132, + "r": 0.052634100624814745, + "e_floor": 0.9295876898002198, + "e_b": 0.9713560031718845, + "y_lower_0": 0.9349117610595774, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/479/simulation_code.py b/scipy/stacked_balls_drop/479/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..f5c921d4c21e04ef02c79cae62e13827d3e630b2 --- /dev/null +++ b/scipy/stacked_balls_drop/479/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 1.9082499175073246 +R = 0.15523503905856884 +m = 0.24427584125465132 +r = 0.052634100624814745 +e_floor = 0.9295876898002198 +e_b = 0.9713560031718845 +y_lower_0 = 0.9349117610595774 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/479/video.mp4 b/scipy/stacked_balls_drop/479/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3983be69658a8c74e6e569de3354cfd3d78a8cf0 --- /dev/null +++ b/scipy/stacked_balls_drop/479/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2bebc87e2c3460db44442edae09d4107b62fd4e71880a4beaf72678c345266cb +size 16569 diff --git a/scipy/stacked_balls_drop/582/cot.json b/scipy/stacked_balls_drop/582/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..58f04534a86d2ce85304b31a7945956699bed629 --- /dev/null +++ b/scipy/stacked_balls_drop/582/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=1.519 kg, radius R=0.164 m) and a light upper ball (m=0.284 kg, radius r=0.089 m) are stacked vertically and released from rest with the lower-ball centre at 0.742 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.835 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.971). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.578 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.367 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 2.811 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 6.887 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.3667618093073317, + "v_after_floor_mps": 2.8108523393270812, + "approx_upper_post_collision_mps": 6.8871462582137575, + "mass_ratio_M_over_m": 5.342768834212357 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.37 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 1.518794983445326, + "unit": "", + "description": "" + }, + "R": { + "value": 0.16350040335106447, + "unit": "", + "description": "" + }, + "m": { + "value": 0.2842711392863828, + "unit": "", + "description": "" + }, + "r": { + "value": 0.08917871403925898, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.8348830414900597, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.9705213291746646, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.741821070729145, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/582/params.json b/scipy/stacked_balls_drop/582/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3fb6515786eea4f086dbfcacfd3a5a6b74c6739e --- /dev/null +++ b/scipy/stacked_balls_drop/582/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 1.518794983445326, + "R": 0.16350040335106447, + "m": 0.2842711392863828, + "r": 0.08917871403925898, + "e_floor": 0.8348830414900597, + "e_b": 0.9705213291746646, + "y_lower_0": 0.741821070729145, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/582/simulation_code.py b/scipy/stacked_balls_drop/582/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..a89e4e16f1701ab8bcf0e7ac7d6537d12537dc94 --- /dev/null +++ b/scipy/stacked_balls_drop/582/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 1.518794983445326 +R = 0.16350040335106447 +m = 0.2842711392863828 +r = 0.08917871403925898 +e_floor = 0.8348830414900597 +e_b = 0.9705213291746646 +y_lower_0 = 0.741821070729145 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/582/video.mp4 b/scipy/stacked_balls_drop/582/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b39cf0563e1939dcb6ccb674b657f64e9f17799b --- /dev/null +++ b/scipy/stacked_balls_drop/582/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e713453c454945baad572b1a9b9f9f2fd102ae839747a3191b687e062c5bd47c +size 7927 diff --git a/scipy/stacked_balls_drop/609/cot.json b/scipy/stacked_balls_drop/609/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..df74fcd6a663d779bd99d679e9ce1a06ec8c15fe --- /dev/null +++ b/scipy/stacked_balls_drop/609/cot.json @@ -0,0 +1,110 @@ +{ + "simulation": "stacked_balls_drop", + "physical_observation": "A heavy lower ball (M=2.985 kg, radius R=0.152 m) and a light upper ball (m=0.198 kg, radius r=0.088 m) are stacked vertically and released from rest with the lower-ball centre at 0.798 m. They free-fall, the lower ball strikes the floor with restitution e_floor=0.815 and is immediately struck from above by the still-falling upper ball (restitution e_b=0.978). The upper ball is launched upward at much higher speed than its drop speed.", + "physical_law": { + "name": "Newton's Laws of Motion + Newton's Law of Restitution for Hard-Body Collisions", + "statement": "Both balls undergo free-fall under gravity (constant acceleration -g). Discrete impulsive collisions exchange velocities by Newton-restitution laws.", + "formula": "Free-fall: \\dot{v} = -g. Floor: v_lower' = -e_floor v_lower. Ball-ball: v_lower' = ((M - e_b m) v_lower + (1 + e_b) m v_upper)/(M + m); v_upper' = ((m - e_b M) v_upper + (1 + e_b) M v_lower)/(M + m)." + }, + "ode_system": { + "state_variables": [ + "y_lower (lower-ball centre)", + "y_upper (upper-ball centre)", + "v_lower", + "v_upper" + ], + "equations_latex": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor event (y_lower=R, v_lower<0): v_lower <- -e_floor v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ], + "equations_python": [ + "dy_lower/dt = v_lower; dy_upper/dt = v_upper", + "dv_lower/dt = -g; dv_upper/dt = -g (free-flight)", + "Floor * event (y_lower=R, v_lower<0): v_lower <- -e_floor * v_lower", + "Ball-ball event (y_upper - y_lower = R + r): apply 1-D Newton restitution" + ] + }, + "derivation_steps": [ + "Drop distance for lower-ball CoM to reach floor: y_lower_0 - R = 0.647 m.", + "Speed when lower ball hits floor: \\sqrt(2 g h) = 3.560 m/s.", + "After floor bounce: v_lower' = +e_floor \\cdot v_drop = 2.901 m/s.", + "Upper ball is still descending at the same speed (it dropped from the same height and has not yet been deflected).", + "Apply 1-D Newton-restitution to the M-m collision; in the M >> m limit and e=1 this gives v_upper' approx 3 \\cdot v_drop.", + "Approximate upper-ball post-collision velocity (using v_after_floor for the lower): 8.429 m/s." + ], + "physical_constants_derived": { + "v_drop_lower_mps": 3.559842255255871, + "v_after_floor_mps": 2.9012358488236933, + "approx_upper_post_collision_mps": 8.429166467871795, + "mass_ratio_M_over_m": 15.113160535171412 + }, + "numerical_method": { + "solver": "scipy.solve_ivp (RK45) with terminal events for floor and ball-ball contact", + "tolerance": "rtol=1e-9, atol=1e-11; max_step=0.02 to bracket events accurately", + "justification": "Hybrid integration: smooth free-flight ODE between impulsive collision events; standard for hard-body dynamics." + }, + "code_validation": { + "ode_source": "Newton II for free-fall and Newton's restitution law for hard-body collisions.", + "energy_check": "Total energy decreases monotonically through both impacts; ratio is e_floor^2 and e_b^2 weighted by mass.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Lower ball reaches floor with speed ~3.56 m/s and bounces.", + "Upper ball is kicked upward at much higher speed than its drop speed (textbook stacked-ball amplification).", + "Damped cascade of subsequent floor and ball-ball impacts until the system settles." + ], + "parameters": { + "g": { + "value": 9.8, + "unit": "", + "description": "" + }, + "M": { + "value": 2.9848637408702836, + "unit": "", + "description": "" + }, + "R": { + "value": 0.15180267643394524, + "unit": "", + "description": "" + }, + "m": { + "value": 0.19750096175607318, + "unit": "", + "description": "" + }, + "r": { + "value": 0.08751944299258456, + "unit": "", + "description": "" + }, + "e_floor": { + "value": 0.8149900025879548, + "unit": "", + "description": "" + }, + "e_b": { + "value": 0.9783527164467429, + "unit": "", + "description": "" + }, + "y_lower_0": { + "value": 0.7983576194087005, + "unit": "", + "description": "" + }, + "v_lower_0": { + "value": 0.0, + "unit": "", + "description": "" + }, + "v_upper_0": { + "value": 0.0, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/stacked_balls_drop/609/params.json b/scipy/stacked_balls_drop/609/params.json new file mode 100644 index 0000000000000000000000000000000000000000..cf732dc0eb4293b7d3654e0a8e5c5b01889876a8 --- /dev/null +++ b/scipy/stacked_balls_drop/609/params.json @@ -0,0 +1,12 @@ +{ + "g": 9.8, + "M": 2.9848637408702836, + "R": 0.15180267643394524, + "m": 0.19750096175607318, + "r": 0.08751944299258456, + "e_floor": 0.8149900025879548, + "e_b": 0.9783527164467429, + "y_lower_0": 0.7983576194087005, + "v_lower_0": 0.0, + "v_upper_0": 0.0 +} \ No newline at end of file diff --git a/scipy/stacked_balls_drop/609/simulation_code.py b/scipy/stacked_balls_drop/609/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8d87b86a85ce7cb1f90278a3abd26d0e8451543f --- /dev/null +++ b/scipy/stacked_balls_drop/609/simulation_code.py @@ -0,0 +1,111 @@ +"""Stacked Balls Drop — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +g = 9.8 +M = 2.9848637408702836 +R = 0.15180267643394524 +m = 0.19750096175607318 +r = 0.08751944299258456 +e_floor = 0.8149900025879548 +e_b = 0.9783527164467429 +y_lower_0 = 0.7983576194087005 +y_upper_0 = y_lower_0 + R + r + 1e-3 +v_lower_0 = 0.0 +v_upper_0 = 0.0 +duration = 12 +fps = 30 + +def free(t, y): + return [y[2], y[3], -g, -g] + +def ev_floor(t, y): + return y[0] - R +ev_floor.terminal = True; ev_floor.direction = -1 + +def ev_ball(t, y): + return y[1] - y[0] - (R + r) +ev_ball.terminal = True; ev_ball.direction = -1 + +t_eval_g = np.linspace(0.0, duration, int(duration * fps) + 1) +S = np.zeros((4, len(t_eval_g))) +state = np.array([y_lower_0, y_upper_0, v_lower_0, v_upper_0], dtype=float) +S[:, 0] = state +last_idx = 1 +t_cur = 0.0 +MAX_SEGMENTS = 200 + +for _seg in range(MAX_SEGMENTS): + if t_cur >= duration - 1e-12: + break + sol = solve_ivp(free, (t_cur, duration), state, events=[ev_floor, ev_ball], + dense_output=True, max_step=0.02, rtol=1e-9, atol=1e-11) + seg_end = sol.t[-1] + while last_idx < len(t_eval_g) and t_eval_g[last_idx] <= seg_end + 1e-12: + S[:, last_idx] = sol.sol(t_eval_g[last_idx]) + last_idx += 1 + state = sol.y[:, -1].copy() + t_cur = seg_end + if sol.status != 1: + break + t_floor = sol.t_events[0] + t_ball = sol.t_events[1] + if len(t_floor) == 0 and len(t_ball) == 0: + break + for _resolve in range(10): + applied = False + if state[0] - R < 1e-9 and state[2] < 0: + state[2] = -e_floor * state[2] + state[0] = max(state[0], R + 1e-12) + applied = True + gap = state[1] - state[0] - (R + r) + if gap < 1e-9 and (state[3] - state[2]) < 0: + vl, vu = state[2], state[3] + state[2] = ((M - e_b*m) * vl + (1.0+e_b)*m*vu)/(M+m) + state[3] = ((m - e_b*M) * vu + (1.0+e_b)*M*vl)/(M+m) + state[1] = max(state[1], state[0]+R+r+1e-12) + applied = True + if not applied: + break + +if last_idx < len(t_eval_g): + S[:, last_idx:] = state[:, None] + +yl_arr = S[0]; yu_arr = S[1] +fig_w, fig_h = 4, 7 +x_lo, x_hi = -0.40, 0.40 +y_lo = -0.10 +y_hi = max(2.8, y_upper_0 + 0.30) +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo, x_hi = x_lo-extra, x_hi+extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo, y_hi = y_lo-extra, y_hi+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") +floor_band = patches.Rectangle((x_lo, y_lo), x_hi-x_lo, -y_lo, facecolor="#4a4e69", edgecolor="none", alpha=0.8, zorder=0) +ax.add_patch(floor_band) +ax.axhline(0.0, color="#adb5bd", lw=2.0, zorder=1) +lower_ball = patches.Circle((0.0, y_lower_0), R, facecolor="#8ecae6", edgecolor="white", lw=1.5, zorder=3) +ax.add_patch(lower_ball) +upper_ball = patches.Circle((0.0, y_upper_0), r, facecolor="#e63946", edgecolor="white", lw=1.5, zorder=4) +ax.add_patch(upper_ball) + +def update(f): + lower_ball.set_center((0.0, yl_arr[f])) + upper_ball.set_center((0.0, yu_arr[f])) + return lower_ball, upper_ball + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval_g), interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/stacked_balls_drop/609/video.mp4 b/scipy/stacked_balls_drop/609/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1fa9eaf97c4810fd6437a876bc767e4679017a9c --- /dev/null +++ b/scipy/stacked_balls_drop/609/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1faab3cbf9a317008d394fa74ecf7d43245b9aa446fdb4233b49f9eb079f7ca0 +size 10846 diff --git a/scipy/string_block_wave/021/cot.json b/scipy/string_block_wave/021/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5362ffef7bef943adcf112067909c56645f90604 --- /dev/null +++ b/scipy/string_block_wave/021/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.498 kg hangs from a rigid ceiling on a vertical taut string of length L=3.151 m and linear mass density mu=0.708 kg/m. The block's weight provides string tension T=4.883 N. At t=0 a Gaussian transverse pulse of amplitude A=0.231 m, width sigma=0.376 m centred at s_pulse=1.484 m travels DOWN at c=2.626 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.498 \\cdot 9.810 = 4.883 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(4.883/0.708) = 2.626 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 0.635 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 2.400 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 4.882858456884225, + "c_phase_speed_mps": 2.6263277541332326, + "transit_time_s": 0.6348983885357611, + "round_trip_time_s": 2.399660333802317, + "mass_ratio_block_over_string": 0.22313111659562695 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=2.63 m/s, reaching block at t~0.63 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~2.40 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 3.1511472675788212, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.7079071338409114, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.49774296196577217, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.23057638584642337, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 1.4836960087128872, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.3757775978820933, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/021/params.json b/scipy/string_block_wave/021/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b7f49ffb5a8f2dd09d035d3cc018c569021e9385 --- /dev/null +++ b/scipy/string_block_wave/021/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.1511472675788212, + "mu": 0.7079071338409114, + "M_block": 0.49774296196577217, + "g": 9.81, + "A": 0.23057638584642337, + "s_pulse": 1.4836960087128872, + "sigma": 0.3757775978820933 +} \ No newline at end of file diff --git a/scipy/string_block_wave/021/simulation_code.py b/scipy/string_block_wave/021/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..4535dab4fb59a6aa65ec86f25b3858533153faf8 --- /dev/null +++ b/scipy/string_block_wave/021/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.1511472675788212 +mu = 0.7079071338409114 +M_block = 0.49774296196577217 +g = 9.81 +A = 0.23057638584642337 +s_pulse = 1.4836960087128872 +sigma = 0.3757775978820933 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/021/video.mp4 b/scipy/string_block_wave/021/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4927fb2d87457842ee22c3d09071cdc94ee19ffe --- /dev/null +++ b/scipy/string_block_wave/021/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ddc886edb1af17c6530447835be286da88a3cb99597f69d9494637925e21f569 +size 22227 diff --git a/scipy/string_block_wave/026/cot.json b/scipy/string_block_wave/026/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..6337f985d1e007a1edd31ddcad4eef8bf0fc5580 --- /dev/null +++ b/scipy/string_block_wave/026/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.883 kg hangs from a rigid ceiling on a vertical taut string of length L=4.821 m and linear mass density mu=0.784 kg/m. The block's weight provides string tension T=8.658 N. At t=0 a Gaussian transverse pulse of amplitude A=0.294 m, width sigma=0.296 m centred at s_pulse=1.298 m travels DOWN at c=3.323 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.883 \\cdot 9.810 = 8.658 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(8.658/0.784) = 3.323 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 1.060 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 2.902 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 8.657688659019994, + "c_phase_speed_mps": 3.3227508553318144, + "transit_time_s": 1.0603497465986633, + "round_trip_time_s": 2.901684929829959, + "mass_ratio_block_over_string": 0.23345786663333712 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=3.32 m/s, reaching block at t~1.06 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~2.90 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 4.820788041247966, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.784163109045876, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.8825370702364927, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.2939716680581946, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 1.2975100137863853, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.29587489685749657, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/026/params.json b/scipy/string_block_wave/026/params.json new file mode 100644 index 0000000000000000000000000000000000000000..449a06efaa511be23c349f38e8a0d2ee6e453c84 --- /dev/null +++ b/scipy/string_block_wave/026/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.820788041247966, + "mu": 0.784163109045876, + "M_block": 0.8825370702364927, + "g": 9.81, + "A": 0.2939716680581946, + "s_pulse": 1.2975100137863853, + "sigma": 0.29587489685749657 +} \ No newline at end of file diff --git a/scipy/string_block_wave/026/simulation_code.py b/scipy/string_block_wave/026/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..74d7e948f766cb108519d7240b285f3c1f6eca68 --- /dev/null +++ b/scipy/string_block_wave/026/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.820788041247966 +mu = 0.784163109045876 +M_block = 0.8825370702364927 +g = 9.81 +A = 0.2939716680581946 +s_pulse = 1.2975100137863853 +sigma = 0.29587489685749657 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/026/video.mp4 b/scipy/string_block_wave/026/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..6c1238e2e5e912f6eef1e046801d877188479038 --- /dev/null +++ b/scipy/string_block_wave/026/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a85d14e9a0790784a888e66a4636d9d230abbf14cbea27f34414bb0926ab2866 +size 17633 diff --git a/scipy/string_block_wave/040/cot.json b/scipy/string_block_wave/040/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..0a26f0cd202e4331410fa58eafe75f4f5197d56b --- /dev/null +++ b/scipy/string_block_wave/040/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.963 kg hangs from a rigid ceiling on a vertical taut string of length L=3.173 m and linear mass density mu=0.306 kg/m. The block's weight provides string tension T=9.445 N. At t=0 a Gaussian transverse pulse of amplitude A=0.395 m, width sigma=0.206 m centred at s_pulse=1.164 m travels DOWN at c=5.559 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.963 \\cdot 9.810 = 9.445 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(9.445/0.306) = 5.559 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 0.361 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 1.142 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 9.445372572431943, + "c_phase_speed_mps": 5.558632902357394, + "transit_time_s": 0.36133189570888413, + "round_trip_time_s": 1.1416025840669344, + "mass_ratio_block_over_string": 0.9926908957921012 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=5.56 m/s, reaching block at t~0.36 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~1.14 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 3.172874842605342, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.3056913189984784, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.9628310471388319, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.39536274096728896, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 1.1643634784467682, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.2055515264047496, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/040/params.json b/scipy/string_block_wave/040/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b589bead947ab9afbd61e14f8c9ee69cf672a2a7 --- /dev/null +++ b/scipy/string_block_wave/040/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.172874842605342, + "mu": 0.3056913189984784, + "M_block": 0.9628310471388319, + "g": 9.81, + "A": 0.39536274096728896, + "s_pulse": 1.1643634784467682, + "sigma": 0.2055515264047496 +} \ No newline at end of file diff --git a/scipy/string_block_wave/040/simulation_code.py b/scipy/string_block_wave/040/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..4918add36f9cac149317a4a15dc38ecccdd862d1 --- /dev/null +++ b/scipy/string_block_wave/040/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.172874842605342 +mu = 0.3056913189984784 +M_block = 0.9628310471388319 +g = 9.81 +A = 0.39536274096728896 +s_pulse = 1.1643634784467682 +sigma = 0.2055515264047496 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/040/video.mp4 b/scipy/string_block_wave/040/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ebc607f93bd3e373c5e5b5ec4659db24b7da351b --- /dev/null +++ b/scipy/string_block_wave/040/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55360d3c2e380f7b21c6476bd02661d730980f7995d9d271f0cba47267f702aa +size 37438 diff --git a/scipy/string_block_wave/082/cot.json b/scipy/string_block_wave/082/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..2c863e31d42435c427dd6cab587db102b0bb6a1b --- /dev/null +++ b/scipy/string_block_wave/082/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.409 kg hangs from a rigid ceiling on a vertical taut string of length L=4.327 m and linear mass density mu=0.618 kg/m. The block's weight provides string tension T=4.010 N. At t=0 a Gaussian transverse pulse of amplitude A=0.235 m, width sigma=0.240 m centred at s_pulse=0.965 m travels DOWN at c=2.547 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.409 \\cdot 9.810 = 4.010 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(4.010/0.618) = 2.547 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 1.320 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 3.398 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 4.009624338848929, + "c_phase_speed_mps": 2.546718908654631, + "transit_time_s": 1.3201454253396638, + "round_trip_time_s": 3.398446219859922, + "mass_ratio_block_over_string": 0.1527782740558483 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=2.55 m/s, reaching block at t~1.32 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~3.40 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 4.327443624081559, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.6182180200446896, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.40872827103454934, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.2353704982280321, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 0.965404307195126, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.24021393994597554, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/082/params.json b/scipy/string_block_wave/082/params.json new file mode 100644 index 0000000000000000000000000000000000000000..1b8aef0e76711f94cea1fa53c4b03da8ece40b09 --- /dev/null +++ b/scipy/string_block_wave/082/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.327443624081559, + "mu": 0.6182180200446896, + "M_block": 0.40872827103454934, + "g": 9.81, + "A": 0.2353704982280321, + "s_pulse": 0.965404307195126, + "sigma": 0.24021393994597554 +} \ No newline at end of file diff --git a/scipy/string_block_wave/082/simulation_code.py b/scipy/string_block_wave/082/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..9a688f64730af198b5537c2da80bb0eb9064731f --- /dev/null +++ b/scipy/string_block_wave/082/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.327443624081559 +mu = 0.6182180200446896 +M_block = 0.40872827103454934 +g = 9.81 +A = 0.2353704982280321 +s_pulse = 0.965404307195126 +sigma = 0.24021393994597554 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/082/video.mp4 b/scipy/string_block_wave/082/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..639272d0fabfb6c9314bb39ceae77d5aefc393a9 --- /dev/null +++ b/scipy/string_block_wave/082/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:859f4cf0b65a8a7b8fda7fdf6d72f2c30491c0bb924774921c0fb5bc252364b3 +size 15064 diff --git a/scipy/string_block_wave/093/cot.json b/scipy/string_block_wave/093/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..098dbe829b105935b0ae7c5e6b7ed4f3578bda69 --- /dev/null +++ b/scipy/string_block_wave/093/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.445 kg hangs from a rigid ceiling on a vertical taut string of length L=4.288 m and linear mass density mu=0.379 kg/m. The block's weight provides string tension T=4.369 N. At t=0 a Gaussian transverse pulse of amplitude A=0.331 m, width sigma=0.216 m centred at s_pulse=1.433 m travels DOWN at c=3.396 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.445 \\cdot 9.810 = 4.369 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(4.369/0.379) = 3.396 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 0.840 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 2.525 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 4.368668295691131, + "c_phase_speed_mps": 3.3963762800099606, + "transit_time_s": 0.8403326480875069, + "round_trip_time_s": 2.5247563172592646, + "mass_ratio_block_over_string": 0.2742567466362268 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=3.40 m/s, reaching block at t~0.84 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~2.52 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 4.287511234372334, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.3787193302498538, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.44532806276158315, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.3312276669709698, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 1.4334253610899683, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.21600543526561525, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/093/params.json b/scipy/string_block_wave/093/params.json new file mode 100644 index 0000000000000000000000000000000000000000..0a35a70c9354c5fa23be6198664ec38ef8d54947 --- /dev/null +++ b/scipy/string_block_wave/093/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.287511234372334, + "mu": 0.3787193302498538, + "M_block": 0.44532806276158315, + "g": 9.81, + "A": 0.3312276669709698, + "s_pulse": 1.4334253610899683, + "sigma": 0.21600543526561525 +} \ No newline at end of file diff --git a/scipy/string_block_wave/093/simulation_code.py b/scipy/string_block_wave/093/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..4cba1183151e74c5d4ad39790e10817b7ebc45cf --- /dev/null +++ b/scipy/string_block_wave/093/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.287511234372334 +mu = 0.3787193302498538 +M_block = 0.44532806276158315 +g = 9.81 +A = 0.3312276669709698 +s_pulse = 1.4334253610899683 +sigma = 0.21600543526561525 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/093/video.mp4 b/scipy/string_block_wave/093/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1981d2d1f278bc78f0704b9912f782670df58210 --- /dev/null +++ b/scipy/string_block_wave/093/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b5b77a3cccea5428fa71d490b932cb515d8e294f1a2c16191cc6c16a20b8a151 +size 21892 diff --git a/scipy/string_block_wave/234/cot.json b/scipy/string_block_wave/234/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..79be2c3c0e785c09383288a0e2ee6ff3114479a7 --- /dev/null +++ b/scipy/string_block_wave/234/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.483 kg hangs from a rigid ceiling on a vertical taut string of length L=4.404 m and linear mass density mu=0.538 kg/m. The block's weight provides string tension T=4.743 N. At t=0 a Gaussian transverse pulse of amplitude A=0.285 m, width sigma=0.255 m centred at s_pulse=1.269 m travels DOWN at c=2.968 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.483 \\cdot 9.810 = 4.743 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(4.743/0.538) = 2.968 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 1.056 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 2.967 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 4.74300422295765, + "c_phase_speed_mps": 2.9681807181953443, + "transit_time_s": 1.0561233935262047, + "round_trip_time_s": 2.967279119885987, + "mass_ratio_block_over_string": 0.20393554471250824 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=2.97 m/s, reaching block at t~1.06 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~2.97 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 4.403710334574619, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.5383600593298921, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.48348666900689596, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.2848692319667955, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 1.2689452418751044, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.2549565377168353, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/234/params.json b/scipy/string_block_wave/234/params.json new file mode 100644 index 0000000000000000000000000000000000000000..809b2b353b22cdac73c02a916daad8523bac1d97 --- /dev/null +++ b/scipy/string_block_wave/234/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.403710334574619, + "mu": 0.5383600593298921, + "M_block": 0.48348666900689596, + "g": 9.81, + "A": 0.2848692319667955, + "s_pulse": 1.2689452418751044, + "sigma": 0.2549565377168353 +} \ No newline at end of file diff --git a/scipy/string_block_wave/234/simulation_code.py b/scipy/string_block_wave/234/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..4f360ad8d716564e651e603d1f1b34b173d0062b --- /dev/null +++ b/scipy/string_block_wave/234/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.403710334574619 +mu = 0.5383600593298921 +M_block = 0.48348666900689596 +g = 9.81 +A = 0.2848692319667955 +s_pulse = 1.2689452418751044 +sigma = 0.2549565377168353 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/234/video.mp4 b/scipy/string_block_wave/234/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a07d15ab84a1c63e21325ca38344cff76e9090cc --- /dev/null +++ b/scipy/string_block_wave/234/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:539936181ba557fe06d07be828c112580407d33825b1132e2ad29a709304546d +size 17449 diff --git a/scipy/string_block_wave/256/cot.json b/scipy/string_block_wave/256/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..cb16893f29e4e213d1fc550543b7ac5ff5983196 --- /dev/null +++ b/scipy/string_block_wave/256/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.476 kg hangs from a rigid ceiling on a vertical taut string of length L=3.948 m and linear mass density mu=0.581 kg/m. The block's weight provides string tension T=4.670 N. At t=0 a Gaussian transverse pulse of amplitude A=0.296 m, width sigma=0.238 m centred at s_pulse=0.819 m travels DOWN at c=2.834 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.476 \\cdot 9.810 = 4.670 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(4.670/0.581) = 2.834 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 1.104 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 2.786 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 4.670003132906865, + "c_phase_speed_mps": 2.8342996991588167, + "transit_time_s": 1.1042170557738875, + "round_trip_time_s": 2.7860679597028852, + "mass_ratio_block_over_string": 0.2074030091445926 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=2.83 m/s, reaching block at t~1.10 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~2.79 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 3.9482757900109533, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.5813338750103281, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.4760451715501392, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.2964743730183979, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 0.8185937210249898, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.23821393042388522, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/256/params.json b/scipy/string_block_wave/256/params.json new file mode 100644 index 0000000000000000000000000000000000000000..9c263d2597dbcb988fd651fce7bc24311be1ee8d --- /dev/null +++ b/scipy/string_block_wave/256/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.9482757900109533, + "mu": 0.5813338750103281, + "M_block": 0.4760451715501392, + "g": 9.81, + "A": 0.2964743730183979, + "s_pulse": 0.8185937210249898, + "sigma": 0.23821393042388522 +} \ No newline at end of file diff --git a/scipy/string_block_wave/256/simulation_code.py b/scipy/string_block_wave/256/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ab6662a8b6e764ce1dd8f6db10ecb6a18955e690 --- /dev/null +++ b/scipy/string_block_wave/256/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.9482757900109533 +mu = 0.5813338750103281 +M_block = 0.4760451715501392 +g = 9.81 +A = 0.2964743730183979 +s_pulse = 0.8185937210249898 +sigma = 0.23821393042388522 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/256/video.mp4 b/scipy/string_block_wave/256/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c5a473ba9a6d0cdf51a90f2b4a7d90ed95d6a43e --- /dev/null +++ b/scipy/string_block_wave/256/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f594ba6020e6758340b00d830c7a5359ad47a547c8973babf2b2f065161b33a1 +size 18416 diff --git a/scipy/string_block_wave/278/cot.json b/scipy/string_block_wave/278/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..71eab2d1e5b374a41d59966335e444a5271ad02c --- /dev/null +++ b/scipy/string_block_wave/278/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.600 kg hangs from a rigid ceiling on a vertical taut string of length L=4.876 m and linear mass density mu=0.781 kg/m. The block's weight provides string tension T=5.890 N. At t=0 a Gaussian transverse pulse of amplitude A=0.311 m, width sigma=0.299 m centred at s_pulse=1.207 m travels DOWN at c=2.746 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.600 \\cdot 9.810 = 5.890 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(5.890/0.781) = 2.746 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 1.336 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 3.551 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 5.889658296762724, + "c_phase_speed_mps": 2.7461501469532825, + "transit_time_s": 1.3361122673993222, + "round_trip_time_s": 3.551205721692843, + "mass_ratio_block_over_string": 0.15765561220544222 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=2.75 m/s, reaching block at t~1.34 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~3.55 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 4.87607205724407, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.7809829294325495, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.600372915062459, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.3109482438750498, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 1.2069071577793375, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.2988309037874283, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/278/params.json b/scipy/string_block_wave/278/params.json new file mode 100644 index 0000000000000000000000000000000000000000..783624b268a95d8f89309e4b7c1752384c3cee87 --- /dev/null +++ b/scipy/string_block_wave/278/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.87607205724407, + "mu": 0.7809829294325495, + "M_block": 0.600372915062459, + "g": 9.81, + "A": 0.3109482438750498, + "s_pulse": 1.2069071577793375, + "sigma": 0.2988309037874283 +} \ No newline at end of file diff --git a/scipy/string_block_wave/278/simulation_code.py b/scipy/string_block_wave/278/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ecb0b7ec14e76041ccef3650508bf508ac6121c0 --- /dev/null +++ b/scipy/string_block_wave/278/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.87607205724407 +mu = 0.7809829294325495 +M_block = 0.600372915062459 +g = 9.81 +A = 0.3109482438750498 +s_pulse = 1.2069071577793375 +sigma = 0.2988309037874283 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/278/video.mp4 b/scipy/string_block_wave/278/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..db6de05c8db9ba29f5940e7362a6ca5b0bfa1f2c --- /dev/null +++ b/scipy/string_block_wave/278/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3704eb65c2539335fbb29fc8f1ade356f8b6e0824e45610a03860f1a771fbd2 +size 15673 diff --git a/scipy/string_block_wave/330/cot.json b/scipy/string_block_wave/330/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..3a786c282ff7338ca378ebe2ef0b72b48530e127 --- /dev/null +++ b/scipy/string_block_wave/330/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.781 kg hangs from a rigid ceiling on a vertical taut string of length L=4.979 m and linear mass density mu=0.499 kg/m. The block's weight provides string tension T=7.661 N. At t=0 a Gaussian transverse pulse of amplitude A=0.308 m, width sigma=0.201 m centred at s_pulse=0.750 m travels DOWN at c=3.918 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.781 \\cdot 9.810 = 7.661 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(7.661/0.499) = 3.918 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 1.079 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 2.542 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 7.661404216798681, + "c_phase_speed_mps": 3.917657413165146, + "transit_time_s": 1.0794855041487827, + "round_trip_time_s": 2.5419376537230365, + "mass_ratio_block_over_string": 0.31421184261903046 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=3.92 m/s, reaching block at t~1.08 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~2.54 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 4.979220446455836, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.49917803270070166, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.7809790231191316, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.30764978239116253, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 0.7501660587230425, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.20051994860606098, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/330/params.json b/scipy/string_block_wave/330/params.json new file mode 100644 index 0000000000000000000000000000000000000000..aebf8194cf351c3a27791b389b67563ad87826d0 --- /dev/null +++ b/scipy/string_block_wave/330/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.979220446455836, + "mu": 0.49917803270070166, + "M_block": 0.7809790231191316, + "g": 9.81, + "A": 0.30764978239116253, + "s_pulse": 0.7501660587230425, + "sigma": 0.20051994860606098 +} \ No newline at end of file diff --git a/scipy/string_block_wave/330/simulation_code.py b/scipy/string_block_wave/330/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..0c5550288ceb319c89f218215c219d6c6653853d --- /dev/null +++ b/scipy/string_block_wave/330/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.979220446455836 +mu = 0.49917803270070166 +M_block = 0.7809790231191316 +g = 9.81 +A = 0.30764978239116253 +s_pulse = 0.7501660587230425 +sigma = 0.20051994860606098 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/330/video.mp4 b/scipy/string_block_wave/330/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..8ae24ce177cf4f579fa373027cbd27ce4ff88af3 --- /dev/null +++ b/scipy/string_block_wave/330/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abfcf28538285cd5bc95121bc9190e3ffdd4511d5f506a9bb2921528d957f294 +size 19576 diff --git a/scipy/string_block_wave/442/cot.json b/scipy/string_block_wave/442/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..34808291b914887426c81c84e730dbd456d08ba6 --- /dev/null +++ b/scipy/string_block_wave/442/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.820 kg hangs from a rigid ceiling on a vertical taut string of length L=3.206 m and linear mass density mu=0.657 kg/m. The block's weight provides string tension T=8.047 N. At t=0 a Gaussian transverse pulse of amplitude A=0.373 m, width sigma=0.284 m centred at s_pulse=0.852 m travels DOWN at c=3.499 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.820 \\cdot 9.810 = 8.047 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(8.047/0.657) = 3.499 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 0.673 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 1.833 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 8.046773394575922, + "c_phase_speed_mps": 3.4989284907482703, + "transit_time_s": 0.6729764223458491, + "round_trip_time_s": 1.832699342744355, + "mass_ratio_block_over_string": 0.3892286777254591 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=3.50 m/s, reaching block at t~0.67 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~1.83 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 3.2062419726519265, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.6572818469379157, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.8202623236061082, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.3725948477533689, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 0.8515455949041942, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.2835631222086303, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/442/params.json b/scipy/string_block_wave/442/params.json new file mode 100644 index 0000000000000000000000000000000000000000..c75f0746c75d17dd7c44844775d4aebad4af2f88 --- /dev/null +++ b/scipy/string_block_wave/442/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.2062419726519265, + "mu": 0.6572818469379157, + "M_block": 0.8202623236061082, + "g": 9.81, + "A": 0.3725948477533689, + "s_pulse": 0.8515455949041942, + "sigma": 0.2835631222086303 +} \ No newline at end of file diff --git a/scipy/string_block_wave/442/simulation_code.py b/scipy/string_block_wave/442/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..0c2d453eb6dfbdb8887fb0d2ed6d0e3a782c86ca --- /dev/null +++ b/scipy/string_block_wave/442/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.2062419726519265 +mu = 0.6572818469379157 +M_block = 0.8202623236061082 +g = 9.81 +A = 0.3725948477533689 +s_pulse = 0.8515455949041942 +sigma = 0.2835631222086303 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/442/video.mp4 b/scipy/string_block_wave/442/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..67750b77ed6a5c6b06fe4dbf9b098c2ed2fabe10 --- /dev/null +++ b/scipy/string_block_wave/442/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5df08ae668687c02ac3fddaca32e364f1732cb0a895b690cb706677319b2ade +size 31403 diff --git a/scipy/string_block_wave/448/cot.json b/scipy/string_block_wave/448/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..a11158d928369fc3285906b4748356c11b227497 --- /dev/null +++ b/scipy/string_block_wave/448/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.683 kg hangs from a rigid ceiling on a vertical taut string of length L=4.912 m and linear mass density mu=0.518 kg/m. The block's weight provides string tension T=6.697 N. At t=0 a Gaussian transverse pulse of amplitude A=0.302 m, width sigma=0.217 m centred at s_pulse=0.762 m travels DOWN at c=3.594 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.683 \\cdot 9.810 = 6.697 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(6.697/0.518) = 3.594 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 1.155 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 2.733 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 6.696867335583961, + "c_phase_speed_mps": 3.5940503563218633, + "transit_time_s": 1.1546461158157606, + "round_trip_time_s": 2.7334520936254485, + "mass_ratio_block_over_string": 0.2680610282402732 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=3.59 m/s, reaching block at t~1.15 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~2.73 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 4.912082235541643, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.5184458234954253, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.6826572207526973, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.30234078687797983, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 0.7622259515683529, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.21727409969405917, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/448/params.json b/scipy/string_block_wave/448/params.json new file mode 100644 index 0000000000000000000000000000000000000000..0c589029744443f604f849c845df040032aa9da9 --- /dev/null +++ b/scipy/string_block_wave/448/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.912082235541643, + "mu": 0.5184458234954253, + "M_block": 0.6826572207526973, + "g": 9.81, + "A": 0.30234078687797983, + "s_pulse": 0.7622259515683529, + "sigma": 0.21727409969405917 +} \ No newline at end of file diff --git a/scipy/string_block_wave/448/simulation_code.py b/scipy/string_block_wave/448/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8003a93a89a08ce25575237abb27bbdbbc0d5ae8 --- /dev/null +++ b/scipy/string_block_wave/448/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.912082235541643 +mu = 0.5184458234954253 +M_block = 0.6826572207526973 +g = 9.81 +A = 0.30234078687797983 +s_pulse = 0.7622259515683529 +sigma = 0.21727409969405917 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/448/video.mp4 b/scipy/string_block_wave/448/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..d051ce336e9fcceb158550054eab96f8bc2d202e --- /dev/null +++ b/scipy/string_block_wave/448/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7e5fceaa28e8a9046dc12a48395e272f73d5294baf95f8827bafffdb38cee638 +size 17936 diff --git a/scipy/string_block_wave/505/cot.json b/scipy/string_block_wave/505/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..eae4bd3bacbbf6126b2d7e157f2010f287d0c641 --- /dev/null +++ b/scipy/string_block_wave/505/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.568 kg hangs from a rigid ceiling on a vertical taut string of length L=3.078 m and linear mass density mu=0.429 kg/m. The block's weight provides string tension T=5.576 N. At t=0 a Gaussian transverse pulse of amplitude A=0.202 m, width sigma=0.213 m centred at s_pulse=0.817 m travels DOWN at c=3.605 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.568 \\cdot 9.810 = 5.576 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(5.576/0.429) = 3.605 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 0.627 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 1.708 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 5.576037910905257, + "c_phase_speed_mps": 3.6053724839033703, + "transit_time_s": 0.6271284266918927, + "round_trip_time_s": 1.7076073922488821, + "mass_ratio_block_over_string": 0.43045038636543254 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=3.61 m/s, reaching block at t~0.63 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~1.71 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 3.0782803526620546, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.4289685353524173, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.5684034567691394, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.2023262996952296, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 0.8172487791934927, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.21349912643529548, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/505/params.json b/scipy/string_block_wave/505/params.json new file mode 100644 index 0000000000000000000000000000000000000000..83d394e3414c3f5c25076ee169b3f27f5a4cb6b9 --- /dev/null +++ b/scipy/string_block_wave/505/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.0782803526620546, + "mu": 0.4289685353524173, + "M_block": 0.5684034567691394, + "g": 9.81, + "A": 0.2023262996952296, + "s_pulse": 0.8172487791934927, + "sigma": 0.21349912643529548 +} \ No newline at end of file diff --git a/scipy/string_block_wave/505/simulation_code.py b/scipy/string_block_wave/505/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..4388798e74895b1286f8516dc23d94e0ed298eae --- /dev/null +++ b/scipy/string_block_wave/505/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.0782803526620546 +mu = 0.4289685353524173 +M_block = 0.5684034567691394 +g = 9.81 +A = 0.2023262996952296 +s_pulse = 0.8172487791934927 +sigma = 0.21349912643529548 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/505/video.mp4 b/scipy/string_block_wave/505/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c356dc7c147d16b1cb120fb13f0f819436daaa38 --- /dev/null +++ b/scipy/string_block_wave/505/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c79c51716c6f350e17c57b84cc77591787c59a05390e00d98fb8c879f29cc256 +size 25050 diff --git a/scipy/string_block_wave/512/cot.json b/scipy/string_block_wave/512/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..c4049e5674b75e19851fcbad45dd90574d2ef47f --- /dev/null +++ b/scipy/string_block_wave/512/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.540 kg hangs from a rigid ceiling on a vertical taut string of length L=4.778 m and linear mass density mu=0.431 kg/m. The block's weight provides string tension T=5.293 N. At t=0 a Gaussian transverse pulse of amplitude A=0.364 m, width sigma=0.396 m centred at s_pulse=1.497 m travels DOWN at c=3.506 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.540 \\cdot 9.810 = 5.293 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(5.293/0.431) = 3.506 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 0.936 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 2.725 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 5.293168525466345, + "c_phase_speed_mps": 3.5058566326297464, + "transit_time_s": 0.9356693281935662, + "round_trip_time_s": 2.7254976437547347, + "mass_ratio_block_over_string": 0.26224627590410454 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=3.51 m/s, reaching block at t~0.94 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~2.73 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 4.777601995787141, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.43065294053569375, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.5395686570302084, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.36362492575151567, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 1.4972794755915084, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.3959684320744252, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/512/params.json b/scipy/string_block_wave/512/params.json new file mode 100644 index 0000000000000000000000000000000000000000..fdba67bb9b7a622f78b6821db619d152c121f505 --- /dev/null +++ b/scipy/string_block_wave/512/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.777601995787141, + "mu": 0.43065294053569375, + "M_block": 0.5395686570302084, + "g": 9.81, + "A": 0.36362492575151567, + "s_pulse": 1.4972794755915084, + "sigma": 0.3959684320744252 +} \ No newline at end of file diff --git a/scipy/string_block_wave/512/simulation_code.py b/scipy/string_block_wave/512/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..e2dd0c4c1c448fc9942616374599d3790ba33d25 --- /dev/null +++ b/scipy/string_block_wave/512/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.777601995787141 +mu = 0.43065294053569375 +M_block = 0.5395686570302084 +g = 9.81 +A = 0.36362492575151567 +s_pulse = 1.4972794755915084 +sigma = 0.3959684320744252 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/512/video.mp4 b/scipy/string_block_wave/512/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e88a91e9ca5be8c472cbea3eb3033f2e902e4e15 --- /dev/null +++ b/scipy/string_block_wave/512/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ac20cd97c20a348a46984979c6448b50775cf38990d16a7620184699f7b34ed +size 20537 diff --git a/scipy/string_block_wave/552/cot.json b/scipy/string_block_wave/552/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..88921c56676f6cb4723baea645322a6707e26a7a --- /dev/null +++ b/scipy/string_block_wave/552/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.641 kg hangs from a rigid ceiling on a vertical taut string of length L=3.222 m and linear mass density mu=0.535 kg/m. The block's weight provides string tension T=6.290 N. At t=0 a Gaussian transverse pulse of amplitude A=0.240 m, width sigma=0.222 m centred at s_pulse=1.327 m travels DOWN at c=3.430 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.641 \\cdot 9.810 = 6.290 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(6.290/0.535) = 3.430 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 0.552 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 1.879 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 6.2903823560535885, + "c_phase_speed_mps": 3.4295468447520663, + "transit_time_s": 0.5522834509410401, + "round_trip_time_s": 1.8787188573029663, + "mass_ratio_block_over_string": 0.37216534730397866 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=3.43 m/s, reaching block at t~0.55 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~1.88 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 3.2215771646197977, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.5348149832258221, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.6412214430227918, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.23956160418062122, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 1.3274951980361709, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.22238728168723879, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/552/params.json b/scipy/string_block_wave/552/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6e417180512b6af003f86c0613919ab8370b003d --- /dev/null +++ b/scipy/string_block_wave/552/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.2215771646197977, + "mu": 0.5348149832258221, + "M_block": 0.6412214430227918, + "g": 9.81, + "A": 0.23956160418062122, + "s_pulse": 1.3274951980361709, + "sigma": 0.22238728168723879 +} \ No newline at end of file diff --git a/scipy/string_block_wave/552/simulation_code.py b/scipy/string_block_wave/552/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8a24802b364a5d4cf027784edb6d7756103c8a26 --- /dev/null +++ b/scipy/string_block_wave/552/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.2215771646197977 +mu = 0.5348149832258221 +M_block = 0.6412214430227918 +g = 9.81 +A = 0.23956160418062122 +s_pulse = 1.3274951980361709 +sigma = 0.22238728168723879 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/552/video.mp4 b/scipy/string_block_wave/552/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..cd7cf464d3ae5c12af1a7f2c03a9b5587c7cd31c --- /dev/null +++ b/scipy/string_block_wave/552/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:608f0dadaf6902edaef3873539d9a4636be13d336c01af2affd1382cec55031d +size 25529 diff --git a/scipy/string_block_wave/589/cot.json b/scipy/string_block_wave/589/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..879ed89a938e232a5c78a513cd08185e4dddefeb --- /dev/null +++ b/scipy/string_block_wave/589/cot.json @@ -0,0 +1,91 @@ +{ + "simulation": "string_block_wave", + "physical_observation": "A heavy block of mass M_block=0.454 kg hangs from a rigid ceiling on a vertical taut string of length L=4.239 m and linear mass density mu=0.435 kg/m. The block's weight provides string tension T=4.451 N. At t=0 a Gaussian transverse pulse of amplitude A=0.388 m, width sigma=0.292 m centred at s_pulse=1.006 m travels DOWN at c=3.199 m/s. It reflects from the heavy block (near-Dirichlet, sign-inverting) and from the rigid ceiling (Dirichlet).", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Block) Boundary", + "statement": "Newton II for transverse string element; Newton II for the block under transverse tension component.", + "formula": "u_tt = c^2 u_ss; u(0,t)=0; M_block u_tt(L,t) = -T u_s(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "u(s, t)" + ], + "equations_latex": [ + "u_tt = c^2 u_ss (interior)", + "u(0, t) = 0 (rigid ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ], + "equations_python": [ + "u_tt = c**2 * u_ss (interior)", + "u(0, t) = 0 * (rigid * ceiling)", + "M_block u_tt(L, t) = -T u_s(L, t) (block)" + ] + }, + "derivation_steps": [ + "Tension supplied by block weight: T = M_block g = 0.454 \\cdot 9.810 = 4.451 N.", + "Phase speed: c = \\sqrt(T/mu) = \\sqrt(4.451/0.435) = 3.199 m/s.", + "Transit time pulse->block: (L - s_pulse)/c = 1.011 s.", + "Round-trip time ceiling->block->ceiling: 2L/c = 2.651 s.", + "Block much heavier than the string mass mu \\cdot L => near-Dirichlet bottom BC; reflection inverts pulse phase.", + "Ceiling is rigid => exact Dirichlet, full inversion on reflection." + ], + "physical_constants_derived": { + "tension_N": 4.4512182453335924, + "c_phase_speed_mps": 3.1985636757161777, + "transit_time_s": 1.0106807312184618, + "round_trip_time_s": 2.6506142044618257, + "mass_ratio_block_over_string": 0.24601946412381415 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM", + "tolerance": "CFL factor < 1, sub-stepping if needed", + "justification": "Leapfrog is stable and second-order; lumped boundary mass m_eff = M_block + 0.5 \\cdot mu \\cdot dx makes the block BC second-order." + }, + "code_validation": { + "ode_source": "Standard 1-D linear wave equation with mass-loaded boundary.", + "energy_check": "No damping; total energy conserved up to leapfrog drift (<0.1% in 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse propagates downward at c=3.20 m/s, reaching block at t~1.01 s.", + "Block barely moves (heavy compared to string mass); reflection is near-fixed-end with phase inversion.", + "Round-trip time wall-block-wall is ~2.65 s; multiple reflections during 12 s window." + ], + "parameters": { + "L": { + "value": 4.239079156364465, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.4350797663875791, + "unit": "", + "description": "" + }, + "M_block": { + "value": 0.45374294040097785, + "unit": "", + "description": "" + }, + "g": { + "value": 9.81, + "unit": "", + "description": "" + }, + "A": { + "value": 0.38840589459878716, + "unit": "", + "description": "" + }, + "s_pulse": { + "value": 1.0063524817428275, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.2921551392378639, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_block_wave/589/params.json b/scipy/string_block_wave/589/params.json new file mode 100644 index 0000000000000000000000000000000000000000..177a3a4154b79bd49cc36c0ed1f41e058ebb6729 --- /dev/null +++ b/scipy/string_block_wave/589/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.239079156364465, + "mu": 0.4350797663875791, + "M_block": 0.45374294040097785, + "g": 9.81, + "A": 0.38840589459878716, + "s_pulse": 1.0063524817428275, + "sigma": 0.2921551392378639 +} \ No newline at end of file diff --git a/scipy/string_block_wave/589/simulation_code.py b/scipy/string_block_wave/589/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..204ad2b927024a289df70109b5ec0c0f1abd12cd --- /dev/null +++ b/scipy/string_block_wave/589/simulation_code.py @@ -0,0 +1,103 @@ +"""String Block Wave — auto-generated.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.239079156364465 +mu = 0.4350797663875791 +M_block = 0.45374294040097785 +g = 9.81 +A = 0.38840589459878716 +s_pulse = 1.0063524817428275 +sigma = 0.2921551392378639 +duration = 12 +T = M_block * g +c = (T/mu)**0.5 + +N = 200 +dx = L/N +s_grid = np.linspace(0, L, N+1) +fps = 30 +n_per_frame = 8 +dt = 1.0/(fps*n_per_frame) +factor_int = (c*dt/dx)**2 +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c/(fps*dx))) + 4 + dt = 1.0/(fps*n_per_frame) + factor_int = (c*dt/dx)**2 +m_eff = M_block + 0.5*mu*dx +factor_block = T*dt*dt/(m_eff*dx) + +u_prev = A*np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +u_prev[0] = 0.0 +du_ds_init = -A*(s_grid-s_pulse)/sigma**2 * np.exp(-((s_grid-s_pulse)**2)/(2*sigma**2)) +v_init = -c*du_ds_init; v_init[0] = 0.0 + +a_init = np.zeros(N+1) +a_init[1:-1] = c**2 * (u_prev[2:] - 2*u_prev[1:-1] + u_prev[:-2])/dx**2 +a_init[-1] = T*(u_prev[-2]-u_prev[-1])/(m_eff*dx) +u_curr = u_prev + dt*v_init + 0.5*dt*dt*a_init +u_curr[0] = 0.0 + +n_frames = int(duration*fps)+1 +U_frames = np.zeros((n_frames, N+1)) +U_frames[0] = u_prev +for frame in range(1, n_frames): + for _ in range(n_per_frame): + u_next = np.empty_like(u_curr) + u_next[1:-1] = (2*u_curr[1:-1] - u_prev[1:-1] + + factor_int*(u_curr[2:] - 2*u_curr[1:-1] + u_curr[:-2])) + u_next[0] = 0.0 + u_next[-1] = (2*u_curr[-1] - u_prev[-1] + + factor_block*(u_curr[-2]-u_curr[-1])) + u_prev, u_curr = u_curr, u_next + U_frames[frame] = u_curr + +y_ceiling = 0.0 +block_w, block_h = 0.40, 0.40 +y_block_top = y_ceiling - L +y_floor = y_block_top - block_h + +fig_w, fig_h = 5, 8 +fig_aspect = fig_w/fig_h +x_lo_d, x_hi_d = -0.95, 0.95 +y_lo_d = y_floor - 0.40 +y_hi_d = y_ceiling + 0.40 +dx_v, dy_v = x_hi_d-x_lo_d, y_hi_d-y_lo_d +if dx_v/dy_v < fig_aspect: + extra = (fig_aspect*dy_v - dx_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d-extra, x_hi_d+extra, y_lo_d, y_hi_d +else: + extra = (dx_v/fig_aspect - dy_v)/2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d-extra, y_hi_d+extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +ax.add_patch(patches.Rectangle((x_lo, y_ceiling), x_hi-x_lo, y_hi-y_ceiling, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_ceiling, y_ceiling], color="#adb5bd", lw=2.5, zorder=1) +ax.add_patch(patches.Rectangle((x_lo, y_lo), x_hi-x_lo, y_floor-y_lo, facecolor="#4a4e69", edgecolor="none", zorder=0)) +ax.plot([x_lo, x_hi], [y_floor, y_floor], color="#adb5bd", lw=2.5, zorder=1) +ax.axvline(0.0, color="#3a4357", lw=1, ls="--", zorder=1) + +str_y_plot = y_ceiling - s_grid +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) +block_patch = patches.Rectangle((-block_w/2, y_block_top-block_h), block_w, block_h, + facecolor="#e63946", edgecolor="#adb5bd", lw=1.5, zorder=5) +ax.add_patch(block_patch) + +def update(f): + u_block = U_frames[f, -1] + str_x = U_frames[f, :].copy() + str_x[-1] = u_block + str_ln.set_data(str_x, str_y_plot) + block_patch.set_xy((u_block - block_w/2, y_block_top - block_h)) + return str_ln, block_patch + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_block_wave/589/video.mp4 b/scipy/string_block_wave/589/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f1eea6bf0c6f9b7e0a41fc8ae5a14caf482a2b1f --- /dev/null +++ b/scipy/string_block_wave/589/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36ccf64eba717ad43ce7521f087c4c4514fcb5e0117f477c5204c3dd5fdb07fb +size 22646 diff --git a/scipy/string_ring_wave/041/cot.json b/scipy/string_ring_wave/041/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..d43539b6419443feb46c5957047046a525b79e71 --- /dev/null +++ b/scipy/string_ring_wave/041/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=3.932 m, tension T=4.967 N, linear mass density mu=0.770 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.132 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.192 m, width sigma=0.353 m centred at x_pulse=0.885 m propagates along the string at c=2.540 m/s, hits the ring at t=1.200 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(4.967/0.770) = 2.540 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (3.932-0.885)/2.540 = 1.200 s.", + "Round-trip wall-ring-wall: 2L/c = 3.096 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 2.5402319389474615, + "round_trip_time_s": 3.096016790588654, + "pulse_to_ring_time_s": 1.1996183553122284, + "ring_mass_kg": 0.1315295965073999 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=2.540 m/s, reaching the ring at t~1.200 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 3.096 s." + ], + "parameters": { + "L": { + "value": 3.932300367485457, + "unit": "", + "description": "" + }, + "T": { + "value": 4.966832857940002, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.7697200530090215, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.1315295965073999, + "unit": "", + "description": "" + }, + "A": { + "value": 0.19151537601808533, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 0.8849915067737101, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.3532729471817876, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/041/params.json b/scipy/string_ring_wave/041/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8855b6ecf6f49f7437d44e04f1c7ebe6bd8fb32d --- /dev/null +++ b/scipy/string_ring_wave/041/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.932300367485457, + "T": 4.966832857940002, + "mu": 0.7697200530090215, + "m_ring": 0.1315295965073999, + "A": 0.19151537601808533, + "x_pulse": 0.8849915067737101, + "sigma": 0.3532729471817876 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/041/simulation_code.py b/scipy/string_ring_wave/041/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b86c0a387c2c2281d83d251a71f6552ea95c9b0c --- /dev/null +++ b/scipy/string_ring_wave/041/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.932300367485457 +T = 4.966832857940002 +mu = 0.7697200530090215 +m_ring = 0.1315295965073999 +A = 0.19151537601808533 +x_pulse = 0.8849915067737101 +sigma = 0.3532729471817876 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/041/video.mp4 b/scipy/string_ring_wave/041/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b2cfcf8a5c20ec878ee61ea88303d30906fefa19 --- /dev/null +++ b/scipy/string_ring_wave/041/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:554f45ccc605b289f552472b68c337a9d5d69958f474c875ff74cf1e265e952d +size 16638 diff --git a/scipy/string_ring_wave/179/cot.json b/scipy/string_ring_wave/179/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..0c94bff6f839daec4d714906b82c512ade34608d --- /dev/null +++ b/scipy/string_ring_wave/179/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.164 m, tension T=2.209 N, linear mass density mu=1.461 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.406 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.325 m, width sigma=0.427 m centred at x_pulse=0.824 m propagates along the string at c=1.230 m/s, hits the ring at t=2.716 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(2.209/1.461) = 1.230 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.164-0.824)/1.230 = 2.716 s.", + "Round-trip wall-ring-wall: 2L/c = 6.773 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 1.2296577159305595, + "round_trip_time_s": 6.772979345272734, + "pulse_to_ring_time_s": 2.7164155814371003, + "ring_mass_kg": 0.4059599570864778 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=1.230 m/s, reaching the ring at t~2.716 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 6.773 s." + ], + "parameters": { + "L": { + "value": 4.1642231558764635, + "unit": "", + "description": "" + }, + "T": { + "value": 2.2094342341281186, + "unit": "", + "description": "" + }, + "mu": { + "value": 1.46120988111679, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.4059599570864778, + "unit": "", + "description": "" + }, + "A": { + "value": 0.32455600866110756, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 0.8239617764883361, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.4273173926025251, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/179/params.json b/scipy/string_ring_wave/179/params.json new file mode 100644 index 0000000000000000000000000000000000000000..5f0567e60bd96af18e6a5aaddc3111945b25f930 --- /dev/null +++ b/scipy/string_ring_wave/179/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.1642231558764635, + "T": 2.2094342341281186, + "mu": 1.46120988111679, + "m_ring": 0.4059599570864778, + "A": 0.32455600866110756, + "x_pulse": 0.8239617764883361, + "sigma": 0.4273173926025251 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/179/simulation_code.py b/scipy/string_ring_wave/179/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..37b1cb1b1efcb498dfd5cd88adc16c8e5826e60b --- /dev/null +++ b/scipy/string_ring_wave/179/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.1642231558764635 +T = 2.2094342341281186 +mu = 1.46120988111679 +m_ring = 0.4059599570864778 +A = 0.32455600866110756 +x_pulse = 0.8239617764883361 +sigma = 0.4273173926025251 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/179/video.mp4 b/scipy/string_ring_wave/179/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e23e996f7466d15ab57a927cefdd75273902d618 --- /dev/null +++ b/scipy/string_ring_wave/179/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:624fd31c48c52107186702444cc45a19532f7bdce8e308cf463859870c46be4a +size 21383 diff --git a/scipy/string_ring_wave/185/cot.json b/scipy/string_ring_wave/185/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..0606f98e64b5b1ef7a2c87c3969aaa9300d5e9f1 --- /dev/null +++ b/scipy/string_ring_wave/185/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.744 m, tension T=3.798 N, linear mass density mu=0.840 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.478 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.194 m, width sigma=0.359 m centred at x_pulse=1.417 m propagates along the string at c=2.127 m/s, hits the ring at t=1.564 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(3.798/0.840) = 2.127 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.744-1.417)/2.127 = 1.564 s.", + "Round-trip wall-ring-wall: 2L/c = 4.461 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 2.126543146264119, + "round_trip_time_s": 4.461249004860524, + "pulse_to_ring_time_s": 1.564383543341801, + "ring_mass_kg": 0.47845105517498354 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=2.127 m/s, reaching the ring at t~1.564 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 4.461 s." + ], + "parameters": { + "L": { + "value": 4.743519247531884, + "unit": "", + "description": "" + }, + "T": { + "value": 3.7981759913999147, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.8398982701993117, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.47845105517498354, + "unit": "", + "description": "" + }, + "A": { + "value": 0.1935060434535778, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 1.4167901453099998, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.35901200909491243, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/185/params.json b/scipy/string_ring_wave/185/params.json new file mode 100644 index 0000000000000000000000000000000000000000..1cd5ff825e6417da619b4bec57a19908e1691c6c --- /dev/null +++ b/scipy/string_ring_wave/185/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.743519247531884, + "T": 3.7981759913999147, + "mu": 0.8398982701993117, + "m_ring": 0.47845105517498354, + "A": 0.1935060434535778, + "x_pulse": 1.4167901453099998, + "sigma": 0.35901200909491243 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/185/simulation_code.py b/scipy/string_ring_wave/185/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..710de0c74bd5986e953b1b56249fa46c349dd936 --- /dev/null +++ b/scipy/string_ring_wave/185/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.743519247531884 +T = 3.7981759913999147 +mu = 0.8398982701993117 +m_ring = 0.47845105517498354 +A = 0.1935060434535778 +x_pulse = 1.4167901453099998 +sigma = 0.35901200909491243 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/185/video.mp4 b/scipy/string_ring_wave/185/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3c5b40321b1240404d87cbc5a8980cf83cf276e4 --- /dev/null +++ b/scipy/string_ring_wave/185/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1100cf7ebf807bf838f13641140f1e621bb97d0d872de2efac309079d430e8d +size 17065 diff --git a/scipy/string_ring_wave/275/cot.json b/scipy/string_ring_wave/275/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..7862826d41fbd98528ac24022235b18ce0ae6df1 --- /dev/null +++ b/scipy/string_ring_wave/275/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=3.619 m, tension T=4.121 N, linear mass density mu=0.826 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.286 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.254 m, width sigma=0.293 m centred at x_pulse=1.420 m propagates along the string at c=2.233 m/s, hits the ring at t=0.985 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(4.121/0.826) = 2.233 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (3.619-1.420)/2.233 = 0.985 s.", + "Round-trip wall-ring-wall: 2L/c = 3.241 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 2.233448607884476, + "round_trip_time_s": 3.2406236068512086, + "pulse_to_ring_time_s": 0.9846983069220451, + "ring_mass_kg": 0.2860124701199339 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=2.233 m/s, reaching the ring at t~0.985 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 3.241 s." + ], + "parameters": { + "L": { + "value": 3.618883141699701, + "unit": "", + "description": "" + }, + "T": { + "value": 4.121070644950095, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.8261485253497632, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.2860124701199339, + "unit": "", + "description": "" + }, + "A": { + "value": 0.2544260085864893, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 1.419610078918459, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.2929057373423759, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/275/params.json b/scipy/string_ring_wave/275/params.json new file mode 100644 index 0000000000000000000000000000000000000000..940db5b06322e902bee3317e89acdd799a4f6214 --- /dev/null +++ b/scipy/string_ring_wave/275/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.618883141699701, + "T": 4.121070644950095, + "mu": 0.8261485253497632, + "m_ring": 0.2860124701199339, + "A": 0.2544260085864893, + "x_pulse": 1.419610078918459, + "sigma": 0.2929057373423759 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/275/simulation_code.py b/scipy/string_ring_wave/275/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..a3ef05c703420b91ae630a8e37f4932013ba7937 --- /dev/null +++ b/scipy/string_ring_wave/275/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.618883141699701 +T = 4.121070644950095 +mu = 0.8261485253497632 +m_ring = 0.2860124701199339 +A = 0.2544260085864893 +x_pulse = 1.419610078918459 +sigma = 0.2929057373423759 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/275/video.mp4 b/scipy/string_ring_wave/275/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..db587a833755db35a3f4c77fd053a65a6898d58d --- /dev/null +++ b/scipy/string_ring_wave/275/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37dcab5bb0fc89a013c523f447bf807a826ec5c9bdce28852ee73098b7ef2f9c +size 22465 diff --git a/scipy/string_ring_wave/284/cot.json b/scipy/string_ring_wave/284/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..c3a81f7f1e3790c63ffa70079a2eca7ced99d02c --- /dev/null +++ b/scipy/string_ring_wave/284/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.568 m, tension T=2.038 N, linear mass density mu=1.468 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.043 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.220 m, width sigma=0.263 m centred at x_pulse=1.181 m propagates along the string at c=1.178 m/s, hits the ring at t=2.875 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(2.038/1.468) = 1.178 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.568-1.181)/1.178 = 2.875 s.", + "Round-trip wall-ring-wall: 2L/c = 7.755 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 1.178233466694587, + "round_trip_time_s": 7.754633429299645, + "pulse_to_ring_time_s": 2.874568218853753, + "ring_mass_kg": 0.04295403967406775 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=1.178 m/s, reaching the ring at t~2.875 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 7.755 s." + ], + "parameters": { + "L": { + "value": 4.568384314174727, + "unit": "", + "description": "" + }, + "T": { + "value": 2.0376591679145277, + "unit": "", + "description": "" + }, + "mu": { + "value": 1.4678065932262132, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.04295403967406775, + "unit": "", + "description": "" + }, + "A": { + "value": 0.22006127160134642, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 1.1814718364245853, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.2634099176353112, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/284/params.json b/scipy/string_ring_wave/284/params.json new file mode 100644 index 0000000000000000000000000000000000000000..507266e2ee609b169d6f16bdbc7e0488b42768f1 --- /dev/null +++ b/scipy/string_ring_wave/284/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.568384314174727, + "T": 2.0376591679145277, + "mu": 1.4678065932262132, + "m_ring": 0.04295403967406775, + "A": 0.22006127160134642, + "x_pulse": 1.1814718364245853, + "sigma": 0.2634099176353112 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/284/simulation_code.py b/scipy/string_ring_wave/284/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..9924d200a4b858921677876a571edb2ba8f10cdd --- /dev/null +++ b/scipy/string_ring_wave/284/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.568384314174727 +T = 2.0376591679145277 +mu = 1.4678065932262132 +m_ring = 0.04295403967406775 +A = 0.22006127160134642 +x_pulse = 1.1814718364245853 +sigma = 0.2634099176353112 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/284/video.mp4 b/scipy/string_ring_wave/284/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a2d3946e1aa7dd6d684818988fc492d6a1072864 --- /dev/null +++ b/scipy/string_ring_wave/284/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea8b8efd436b387ae33383db9ac6c7238aba28194453b64369c756de0c651767 +size 12528 diff --git a/scipy/string_ring_wave/446/cot.json b/scipy/string_ring_wave/446/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..52c7c4ae09440e485ca8487d217ce421584344ab --- /dev/null +++ b/scipy/string_ring_wave/446/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.945 m, tension T=4.734 N, linear mass density mu=0.700 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.457 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.209 m, width sigma=0.279 m centred at x_pulse=1.315 m propagates along the string at c=2.600 m/s, hits the ring at t=1.396 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(4.734/0.700) = 2.600 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.945-1.315)/2.600 = 1.396 s.", + "Round-trip wall-ring-wall: 2L/c = 3.804 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 2.599821006824291, + "round_trip_time_s": 3.8037436267238642, + "pulse_to_ring_time_s": 1.3960815175350767, + "ring_mass_kg": 0.45683714545861975 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=2.600 m/s, reaching the ring at t~1.396 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 3.804 s." + ], + "parameters": { + "L": { + "value": 4.944526292665358, + "unit": "", + "description": "" + }, + "T": { + "value": 4.734121467605821, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.7004102606777142, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.45683714545861975, + "unit": "", + "description": "" + }, + "A": { + "value": 0.20930170372222257, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 1.3149642361385312, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.279110702421567, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/446/params.json b/scipy/string_ring_wave/446/params.json new file mode 100644 index 0000000000000000000000000000000000000000..20730595cdffec96463817a09889914b5df03cc6 --- /dev/null +++ b/scipy/string_ring_wave/446/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.944526292665358, + "T": 4.734121467605821, + "mu": 0.7004102606777142, + "m_ring": 0.45683714545861975, + "A": 0.20930170372222257, + "x_pulse": 1.3149642361385312, + "sigma": 0.279110702421567 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/446/simulation_code.py b/scipy/string_ring_wave/446/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..7873bee86ccff6e47d7bc42af65f6f7ec2f501c3 --- /dev/null +++ b/scipy/string_ring_wave/446/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.944526292665358 +T = 4.734121467605821 +mu = 0.7004102606777142 +m_ring = 0.45683714545861975 +A = 0.20930170372222257 +x_pulse = 1.3149642361385312 +sigma = 0.279110702421567 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/446/video.mp4 b/scipy/string_ring_wave/446/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..13b7d4d3523e9b87b97aa2dbc38002daaff006c1 --- /dev/null +++ b/scipy/string_ring_wave/446/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c4583d0971d647d4ddcea37af7d34621cba399ed00f5e1346a55270db6bb6576 +size 18912 diff --git a/scipy/string_ring_wave/452/cot.json b/scipy/string_ring_wave/452/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..248ac0d8c867ae3fb389289bc38c77df24f1b5d9 --- /dev/null +++ b/scipy/string_ring_wave/452/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=3.732 m, tension T=5.151 N, linear mass density mu=1.349 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.443 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.331 m, width sigma=0.397 m centred at x_pulse=1.207 m propagates along the string at c=1.954 m/s, hits the ring at t=1.292 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(5.151/1.349) = 1.954 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (3.732-1.207)/1.954 = 1.292 s.", + "Round-trip wall-ring-wall: 2L/c = 3.821 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 1.9537517559001523, + "round_trip_time_s": 3.8206794357529907, + "pulse_to_ring_time_s": 1.2923999150775598, + "ring_mass_kg": 0.44269880274649553 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=1.954 m/s, reaching the ring at t~1.292 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 3.821 s." + ], + "parameters": { + "L": { + "value": 3.7323295781670045, + "unit": "", + "description": "" + }, + "T": { + "value": 5.150554230882975, + "unit": "", + "description": "" + }, + "mu": { + "value": 1.3493207579325452, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.44269880274649553, + "unit": "", + "description": "" + }, + "A": { + "value": 0.3314682207775614, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 1.2073009747590144, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.39701734140248873, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/452/params.json b/scipy/string_ring_wave/452/params.json new file mode 100644 index 0000000000000000000000000000000000000000..304d612ebef6d50b536cc7fca88418b29221a676 --- /dev/null +++ b/scipy/string_ring_wave/452/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.7323295781670045, + "T": 5.150554230882975, + "mu": 1.3493207579325452, + "m_ring": 0.44269880274649553, + "A": 0.3314682207775614, + "x_pulse": 1.2073009747590144, + "sigma": 0.39701734140248873 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/452/simulation_code.py b/scipy/string_ring_wave/452/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..722a71967692619b5deb2098fd40ab6557e6c101 --- /dev/null +++ b/scipy/string_ring_wave/452/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.7323295781670045 +T = 5.150554230882975 +mu = 1.3493207579325452 +m_ring = 0.44269880274649553 +A = 0.3314682207775614 +x_pulse = 1.2073009747590144 +sigma = 0.39701734140248873 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/452/video.mp4 b/scipy/string_ring_wave/452/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..d7fe50f2788bd7c750bff9715412036ed3f59b86 --- /dev/null +++ b/scipy/string_ring_wave/452/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b3d1b0215b3546983aa69104fb03c3bf16cb23471075e28d0f87acb9f5df1ec +size 22680 diff --git a/scipy/string_ring_wave/481/cot.json b/scipy/string_ring_wave/481/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..223704179039dae144e703a3d791682fec5d2eb6 --- /dev/null +++ b/scipy/string_ring_wave/481/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=3.276 m, tension T=5.996 N, linear mass density mu=0.812 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.247 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.192 m, width sigma=0.238 m centred at x_pulse=1.298 m propagates along the string at c=2.718 m/s, hits the ring at t=0.728 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(5.996/0.812) = 2.718 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (3.276-1.298)/2.718 = 0.728 s.", + "Round-trip wall-ring-wall: 2L/c = 2.411 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 2.7177736395671523, + "round_trip_time_s": 2.410581885516415, + "pulse_to_ring_time_s": 0.7275117163122568, + "ring_mass_kg": 0.24719614665575068 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=2.718 m/s, reaching the ring at t~0.728 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 2.411 s." + ], + "parameters": { + "L": { + "value": 3.2757079522372976, + "unit": "", + "description": "" + }, + "T": { + "value": 5.996224064045541, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.8118041909172051, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.24719614665575068, + "unit": "", + "description": "" + }, + "A": { + "value": 0.19179123301976503, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 1.29849578716759, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.23769277962109123, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/481/params.json b/scipy/string_ring_wave/481/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6791035d512805a48cf3e058d982e3a6f7a77688 --- /dev/null +++ b/scipy/string_ring_wave/481/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.2757079522372976, + "T": 5.996224064045541, + "mu": 0.8118041909172051, + "m_ring": 0.24719614665575068, + "A": 0.19179123301976503, + "x_pulse": 1.29849578716759, + "sigma": 0.23769277962109123 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/481/simulation_code.py b/scipy/string_ring_wave/481/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..0c280b25bb26311df7f79dfa1a86868897cf7c44 --- /dev/null +++ b/scipy/string_ring_wave/481/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.2757079522372976 +T = 5.996224064045541 +mu = 0.8118041909172051 +m_ring = 0.24719614665575068 +A = 0.19179123301976503 +x_pulse = 1.29849578716759 +sigma = 0.23769277962109123 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/481/video.mp4 b/scipy/string_ring_wave/481/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..61bcc86884a14e8c190ce729766d978a38c3262e --- /dev/null +++ b/scipy/string_ring_wave/481/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfb48f5400653fb4a6293b5bd95100fd38b1892c8a64f07cb9fb747e47cb1642 +size 23956 diff --git a/scipy/string_ring_wave/503/cot.json b/scipy/string_ring_wave/503/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..a332fa21fed4b36019292e43e3dde13495df1a8e --- /dev/null +++ b/scipy/string_ring_wave/503/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.860 m, tension T=3.204 N, linear mass density mu=1.451 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.332 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.193 m, width sigma=0.362 m centred at x_pulse=0.942 m propagates along the string at c=1.486 m/s, hits the ring at t=2.637 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(3.204/1.451) = 1.486 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.860-0.942)/1.486 = 2.637 s.", + "Round-trip wall-ring-wall: 2L/c = 6.542 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 1.4857985161537608, + "round_trip_time_s": 6.541987177442546, + "pulse_to_ring_time_s": 2.636842066855138, + "ring_mass_kg": 0.3317801924534469 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=1.486 m/s, reaching the ring at t~2.637 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 6.542 s." + ], + "parameters": { + "L": { + "value": 4.860037420470532, + "unit": "", + "description": "" + }, + "T": { + "value": 3.203888051128064, + "unit": "", + "description": "" + }, + "mu": { + "value": 1.4513009921879805, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.3317801924534469, + "unit": "", + "description": "" + }, + "A": { + "value": 0.1930149049132347, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 0.9422213902053523, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.361699811431818, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/503/params.json b/scipy/string_ring_wave/503/params.json new file mode 100644 index 0000000000000000000000000000000000000000..e5d8164005628fce4d221b16187c9204d23ddfd6 --- /dev/null +++ b/scipy/string_ring_wave/503/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.860037420470532, + "T": 3.203888051128064, + "mu": 1.4513009921879805, + "m_ring": 0.3317801924534469, + "A": 0.1930149049132347, + "x_pulse": 0.9422213902053523, + "sigma": 0.361699811431818 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/503/simulation_code.py b/scipy/string_ring_wave/503/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..5aa82985ff7a0cad1ac7f211649910b06f170143 --- /dev/null +++ b/scipy/string_ring_wave/503/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.860037420470532 +T = 3.203888051128064 +mu = 1.4513009921879805 +m_ring = 0.3317801924534469 +A = 0.1930149049132347 +x_pulse = 0.9422213902053523 +sigma = 0.361699811431818 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/503/video.mp4 b/scipy/string_ring_wave/503/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..210e78ed65136fc628fe03e69066f451f173fce8 --- /dev/null +++ b/scipy/string_ring_wave/503/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac2e20a0a54a4923a86c0daab7b6a1914f4161bdf106b8d78ef4673fdfb21a9d +size 12770 diff --git a/scipy/string_ring_wave/531/cot.json b/scipy/string_ring_wave/531/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..096f0535760f4ba53bfa2a3c73874594fc9c7930 --- /dev/null +++ b/scipy/string_ring_wave/531/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.894 m, tension T=4.637 N, linear mass density mu=1.114 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.134 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.250 m, width sigma=0.311 m centred at x_pulse=1.419 m propagates along the string at c=2.040 m/s, hits the ring at t=1.703 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(4.637/1.114) = 2.040 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.894-1.419)/2.040 = 1.703 s.", + "Round-trip wall-ring-wall: 2L/c = 4.798 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 2.039777735616256, + "round_trip_time_s": 4.79841971071686, + "pulse_to_ring_time_s": 1.703472911651822, + "ring_mass_kg": 0.13436540269827774 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=2.040 m/s, reaching the ring at t~1.703 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 4.798 s." + ], + "parameters": { + "L": { + "value": 4.893854846031223, + "unit": "", + "description": "" + }, + "T": { + "value": 4.636747658823227, + "unit": "", + "description": "" + }, + "mu": { + "value": 1.1144170992663862, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.13436540269827774, + "unit": "", + "description": "" + }, + "A": { + "value": 0.2500622624871888, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 1.4191487276184396, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.3111986288568849, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/531/params.json b/scipy/string_ring_wave/531/params.json new file mode 100644 index 0000000000000000000000000000000000000000..909210a4eb1377e862bbdf2235150e8b5f25ac94 --- /dev/null +++ b/scipy/string_ring_wave/531/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.893854846031223, + "T": 4.636747658823227, + "mu": 1.1144170992663862, + "m_ring": 0.13436540269827774, + "A": 0.2500622624871888, + "x_pulse": 1.4191487276184396, + "sigma": 0.3111986288568849 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/531/simulation_code.py b/scipy/string_ring_wave/531/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b8959e731f47c399a9352007722fad579d80a085 --- /dev/null +++ b/scipy/string_ring_wave/531/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.893854846031223 +T = 4.636747658823227 +mu = 1.1144170992663862 +m_ring = 0.13436540269827774 +A = 0.2500622624871888 +x_pulse = 1.4191487276184396 +sigma = 0.3111986288568849 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/531/video.mp4 b/scipy/string_ring_wave/531/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..386bc6c196aadd13cef60916e1d21cb2b3a483d7 --- /dev/null +++ b/scipy/string_ring_wave/531/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ff5f6490be566d8aec388104395d29326bbe602c9959b664262d31ff8159e9f +size 12871 diff --git a/scipy/string_ring_wave/590/cot.json b/scipy/string_ring_wave/590/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4521e9995d3bdc688db823207f55b2629c35c6e2 --- /dev/null +++ b/scipy/string_ring_wave/590/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=3.786 m, tension T=2.188 N, linear mass density mu=0.937 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.076 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.180 m, width sigma=0.360 m centred at x_pulse=1.387 m propagates along the string at c=1.528 m/s, hits the ring at t=1.570 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(2.188/0.937) = 1.528 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (3.786-1.387)/1.528 = 1.570 s.", + "Round-trip wall-ring-wall: 2L/c = 4.955 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 1.527967583138129, + "round_trip_time_s": 4.955380150707996, + "pulse_to_ring_time_s": 1.5699525837185813, + "ring_mass_kg": 0.07596634976235114 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=1.528 m/s, reaching the ring at t~1.570 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 4.955 s." + ], + "parameters": { + "L": { + "value": 3.785830116203977, + "unit": "", + "description": "" + }, + "T": { + "value": 2.187947990167585, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.9371491447321193, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.07596634976235114, + "unit": "", + "description": "" + }, + "A": { + "value": 0.18049146177966788, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 1.3869934612180352, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.35973605206363396, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/590/params.json b/scipy/string_ring_wave/590/params.json new file mode 100644 index 0000000000000000000000000000000000000000..6a7b518871efd93b69311cd39b58e6af3a4bdf3d --- /dev/null +++ b/scipy/string_ring_wave/590/params.json @@ -0,0 +1,9 @@ +{ + "L": 3.785830116203977, + "T": 2.187947990167585, + "mu": 0.9371491447321193, + "m_ring": 0.07596634976235114, + "A": 0.18049146177966788, + "x_pulse": 1.3869934612180352, + "sigma": 0.35973605206363396 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/590/simulation_code.py b/scipy/string_ring_wave/590/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..fcda562eeccaa0811176b655d5ca137dd65cb506 --- /dev/null +++ b/scipy/string_ring_wave/590/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 3.785830116203977 +T = 2.187947990167585 +mu = 0.9371491447321193 +m_ring = 0.07596634976235114 +A = 0.18049146177966788 +x_pulse = 1.3869934612180352 +sigma = 0.35973605206363396 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/590/video.mp4 b/scipy/string_ring_wave/590/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1737f553935f823f1ef5819025677fdcd6621509 --- /dev/null +++ b/scipy/string_ring_wave/590/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4476f23f968317ff8742e13d2ea256e04b004246ebb94670f60799b250d6b5bd +size 14910 diff --git a/scipy/string_ring_wave/599/cot.json b/scipy/string_ring_wave/599/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..63dcd427dc078888be6968b3fb6094e95925f430 --- /dev/null +++ b/scipy/string_ring_wave/599/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.501 m, tension T=5.724 N, linear mass density mu=0.686 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.350 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.211 m, width sigma=0.270 m centred at x_pulse=0.972 m propagates along the string at c=2.889 m/s, hits the ring at t=1.222 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(5.724/0.686) = 2.889 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.501-0.972)/2.889 = 1.222 s.", + "Round-trip wall-ring-wall: 2L/c = 3.116 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 2.8888825389295785, + "round_trip_time_s": 3.1161481467978245, + "pulse_to_ring_time_s": 1.2216061416777775, + "ring_mass_kg": 0.3501318852428367 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=2.889 m/s, reaching the ring at t~1.222 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 3.116 s." + ], + "parameters": { + "L": { + "value": 4.501092985001, + "unit": "", + "description": "" + }, + "T": { + "value": 5.723575270597527, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.685816028123036, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.3501318852428367, + "unit": "", + "description": "" + }, + "A": { + "value": 0.21104583660507248, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 0.9720163328589355, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.26958335492490404, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/599/params.json b/scipy/string_ring_wave/599/params.json new file mode 100644 index 0000000000000000000000000000000000000000..658f69c625fd43483742bebfc388a69661c173b0 --- /dev/null +++ b/scipy/string_ring_wave/599/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.501092985001, + "T": 5.723575270597527, + "mu": 0.685816028123036, + "m_ring": 0.3501318852428367, + "A": 0.21104583660507248, + "x_pulse": 0.9720163328589355, + "sigma": 0.26958335492490404 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/599/simulation_code.py b/scipy/string_ring_wave/599/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..39559b5cce4800f6ff2f80fa59f6875a0a8b9e26 --- /dev/null +++ b/scipy/string_ring_wave/599/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.501092985001 +T = 5.723575270597527 +mu = 0.685816028123036 +m_ring = 0.3501318852428367 +A = 0.21104583660507248 +x_pulse = 0.9720163328589355 +sigma = 0.26958335492490404 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/599/video.mp4 b/scipy/string_ring_wave/599/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e14238ae73835688518c2c3e59ebdc526f25ee38 --- /dev/null +++ b/scipy/string_ring_wave/599/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dabd70d13399599155a08d08a790c7a72aec4b200fcda1c2e91616f80c2c4419 +size 19641 diff --git a/scipy/string_ring_wave/650/cot.json b/scipy/string_ring_wave/650/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..c5d082fe76d71993e038156f94a96ea11c247f30 --- /dev/null +++ b/scipy/string_ring_wave/650/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.933 m, tension T=3.905 N, linear mass density mu=1.334 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.219 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.222 m, width sigma=0.369 m centred at x_pulse=0.853 m propagates along the string at c=1.711 m/s, hits the ring at t=2.384 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(3.905/1.334) = 1.711 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.933-0.853)/1.711 = 2.384 s.", + "Round-trip wall-ring-wall: 2L/c = 5.766 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 1.7109424670578661, + "round_trip_time_s": 5.7659750222823885, + "pulse_to_ring_time_s": 2.3843369255109197, + "ring_mass_kg": 0.218872209926352 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=1.711 m/s, reaching the ring at t~2.384 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 5.766 s." + ], + "parameters": { + "L": { + "value": 4.9326257648089324, + "unit": "", + "description": "" + }, + "T": { + "value": 3.904949331354486, + "unit": "", + "description": "" + }, + "mu": { + "value": 1.3339654796778069, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.218872209926352, + "unit": "", + "description": "" + }, + "A": { + "value": 0.22172419679189537, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 0.8531624631781122, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.3688255866858638, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/650/params.json b/scipy/string_ring_wave/650/params.json new file mode 100644 index 0000000000000000000000000000000000000000..d423f7a52d9a4c3cc1d778cc2146e72b0eaca98c --- /dev/null +++ b/scipy/string_ring_wave/650/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.9326257648089324, + "T": 3.904949331354486, + "mu": 1.3339654796778069, + "m_ring": 0.218872209926352, + "A": 0.22172419679189537, + "x_pulse": 0.8531624631781122, + "sigma": 0.3688255866858638 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/650/simulation_code.py b/scipy/string_ring_wave/650/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..9e7c29e8899174f7c3c128ad1080c89d2243f5c9 --- /dev/null +++ b/scipy/string_ring_wave/650/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.9326257648089324 +T = 3.904949331354486 +mu = 1.3339654796778069 +m_ring = 0.218872209926352 +A = 0.22172419679189537 +x_pulse = 0.8531624631781122 +sigma = 0.3688255866858638 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/650/video.mp4 b/scipy/string_ring_wave/650/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e0dec6ce710a9ff8c3e8b474337693674b12a35e --- /dev/null +++ b/scipy/string_ring_wave/650/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bed4ae59849042350321fd960271bc50bef42ed83fb9cdfde4841b87dab7a52e +size 13857 diff --git a/scipy/string_ring_wave/667/cot.json b/scipy/string_ring_wave/667/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..5731373052a2355af80272f2dafa17d4c516c5fa --- /dev/null +++ b/scipy/string_ring_wave/667/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.722 m, tension T=2.923 N, linear mass density mu=1.168 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.453 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.262 m, width sigma=0.403 m centred at x_pulse=0.868 m propagates along the string at c=1.582 m/s, hits the ring at t=2.436 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(2.923/1.168) = 1.582 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.722-0.868)/1.582 = 2.436 s.", + "Round-trip wall-ring-wall: 2L/c = 5.969 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 1.5822504084805635, + "round_trip_time_s": 5.968860265850667, + "pulse_to_ring_time_s": 2.4358042558931836, + "ring_mass_kg": 0.4530463558484117 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=1.582 m/s, reaching the ring at t~2.436 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 5.969 s." + ], + "parameters": { + "L": { + "value": 4.722115796902812, + "unit": "", + "description": "" + }, + "T": { + "value": 2.9231944596353454, + "unit": "", + "description": "" + }, + "mu": { + "value": 1.16763545548137, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.4530463558484117, + "unit": "", + "description": "" + }, + "A": { + "value": 0.26245573034238867, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 0.868063518037127, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.4027917825490326, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/667/params.json b/scipy/string_ring_wave/667/params.json new file mode 100644 index 0000000000000000000000000000000000000000..63946629180e545ba870e26cea656a5dd07529cf --- /dev/null +++ b/scipy/string_ring_wave/667/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.722115796902812, + "T": 2.9231944596353454, + "mu": 1.16763545548137, + "m_ring": 0.4530463558484117, + "A": 0.26245573034238867, + "x_pulse": 0.868063518037127, + "sigma": 0.4027917825490326 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/667/simulation_code.py b/scipy/string_ring_wave/667/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..6fb7403306f5f939def2ea336c3229464e2d3fd3 --- /dev/null +++ b/scipy/string_ring_wave/667/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.722115796902812 +T = 2.9231944596353454 +mu = 1.16763545548137 +m_ring = 0.4530463558484117 +A = 0.26245573034238867 +x_pulse = 0.868063518037127 +sigma = 0.4027917825490326 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/667/video.mp4 b/scipy/string_ring_wave/667/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..23622708f41bf7502324f8c67a37217431b1c007 --- /dev/null +++ b/scipy/string_ring_wave/667/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be47757819041a7ea24f22df518e988a5c329e9f94e4473e2e550bca139a268d +size 16433 diff --git a/scipy/string_ring_wave/688/cot.json b/scipy/string_ring_wave/688/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..b1b224c63fe892c0890a219a4c1a2574a25d3841 --- /dev/null +++ b/scipy/string_ring_wave/688/cot.json @@ -0,0 +1,93 @@ +{ + "simulation": "string_ring_wave", + "physical_observation": "A taut string of length L=4.057 m, tension T=3.494 N, linear mass density mu=0.950 kg/m connects a rigid wall at x=0 to a ring of mass m_ring=0.272 kg at x=L. A right-travelling Gaussian pulse of amplitude A=0.309 m, width sigma=0.239 m centred at x_pulse=1.139 m propagates along the string at c=1.918 m/s, hits the ring at t=1.521 s, partially reflects, returns to the wall, and inverts there.", + "physical_law": { + "name": "1-D Linear Wave Equation with Inertial (Ring) Boundary", + "statement": "Newton's 2nd law for transverse string element gives the wave equation; the ring obeys Newton's 2nd law under the transverse component of string tension.", + "formula": "y_tt = c^2 y_xx; y(0,t)=0; m_ring y_tt(L,t) = -T y_x(L,t); c=\\sqrt(T/mu)" + }, + "ode_system": { + "state_variables": [ + "y(x, t) (transverse displacement)" + ], + "equations_latex": [ + "y_tt = c^2 y_xx (interior)", + "y(0, t) = 0 (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ], + "equations_python": [ + "y_tt = c**2 * y_xx (interior)", + "y(0, t) = 0 * (wall)", + "m_ring y_tt(L, t) = -T y_x(L, t) (ring)" + ] + }, + "derivation_steps": [ + "Apply Newton's 2nd law to a small string element: mu \\cdot y_tt dx = T (y_x|_(x+dx) - y_x|_x).", + "Take the limit dx->0 to obtain y_tt = (T/mu) y_xx, defining c = \\sqrt(T/mu).", + "Pulse speed: c = \\sqrt(T/mu) = \\sqrt(3.494/0.950) = 1.918 m/s.", + "Pulse-to-ring travel time: (L - x_pulse)/c = (4.057-1.139)/1.918 = 1.521 s.", + "Round-trip wall-ring-wall: 2L/c = 4.230 s.", + "Right boundary: vertical force on ring = -T \\cdot dy/dx|_L; inertia m_ring gives the ODE m_ring y_tt = -T y_x.", + "m_ring->0 reduces to free-end (Neumann); m_ring->infinity reduces to fixed-end (Dirichlet)." + ], + "physical_constants_derived": { + "c_phase_speed_mps": 1.9179337331283768, + "round_trip_time_s": 4.2300873641481695, + "pulse_to_ring_time_s": 1.5210973676082715, + "ring_mass_kg": 0.2717221429378476 + }, + "numerical_method": { + "solver": "Explicit leapfrog FDM in space and time (second-order)", + "tolerance": "CFL factor < 1; sub-stepping to maintain stability", + "justification": "Leapfrog conserves the discrete wave energy when undamped; effective boundary mass m_ring + 0.5 \\cdot mu \\cdot dx makes the ring BC second-order accurate." + }, + "code_validation": { + "ode_source": "Newton II for string element + Newton II for ring; standard derivation.", + "energy_check": "No damping; total kinetic + potential energy is conserved up to leapfrog drift (<0.1% over 12 s).", + "physical_plausibility": true + }, + "expected_behavior": [ + "Pulse travels right at c=1.918 m/s, reaching the ring at t~1.521 s.", + "Ring momentarily lifts the string by inertial response.", + "Reflection from ring depends on m_ring vs mu \\cdot L (light ring => near-free reflection, no inversion).", + "Reflection from rigid wall fully inverts pulse phase.", + "Round-trip time wall-ring-wall is 4.230 s." + ], + "parameters": { + "L": { + "value": 4.056513624889937, + "unit": "", + "description": "" + }, + "T": { + "value": 3.4939175336235944, + "unit": "", + "description": "" + }, + "mu": { + "value": 0.9498290645708792, + "unit": "", + "description": "" + }, + "m_ring": { + "value": 0.2717221429378476, + "unit": "", + "description": "" + }, + "A": { + "value": 0.3090521598210981, + "unit": "", + "description": "" + }, + "x_pulse": { + "value": 1.139149672181258, + "unit": "", + "description": "" + }, + "sigma": { + "value": 0.23923820233182314, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/string_ring_wave/688/params.json b/scipy/string_ring_wave/688/params.json new file mode 100644 index 0000000000000000000000000000000000000000..3327f158d3e774d2091828239418748fdbd99ea4 --- /dev/null +++ b/scipy/string_ring_wave/688/params.json @@ -0,0 +1,9 @@ +{ + "L": 4.056513624889937, + "T": 3.4939175336235944, + "mu": 0.9498290645708792, + "m_ring": 0.2717221429378476, + "A": 0.3090521598210981, + "x_pulse": 1.139149672181258, + "sigma": 0.23923820233182314 +} \ No newline at end of file diff --git a/scipy/string_ring_wave/688/simulation_code.py b/scipy/string_ring_wave/688/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..003e77793f79cf4ca7eaadcb779b09ed60278650 --- /dev/null +++ b/scipy/string_ring_wave/688/simulation_code.py @@ -0,0 +1,110 @@ +"""Wave Pulse on a Ring-Loaded String — auto-generated script.""" +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import matplotlib.patches as patches + +L = 4.056513624889937 +T = 3.4939175336235944 +mu = 0.9498290645708792 +m_ring = 0.2717221429378476 +A = 0.3090521598210981 +x_pulse = 1.139149672181258 +sigma = 0.23923820233182314 +duration = 12 + +c = (T / mu) ** 0.5 +N = 200 +dx = L / N +x_grid = np.linspace(0, L, N + 1) + +fps = 30 +n_per_frame = 4 +dt = 1.0 / (fps * n_per_frame) +factor_int = (c * dt / dx) ** 2 +m_eff = m_ring + 0.5 * mu * dx +factor_ring = T * dt * dt / (m_eff * dx) +if factor_int >= 1.0: + n_per_frame = int(np.ceil(c / (fps * dx))) + 2 + dt = 1.0 / (fps * n_per_frame) + factor_int = (c * dt / dx) ** 2 + factor_ring = T * dt * dt / (m_eff * dx) + +y_prev = A * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +y_prev[0] = 0.0 +dy_dx_init = -A * (x_grid - x_pulse) / sigma ** 2 * np.exp(-((x_grid - x_pulse) ** 2) / (2 * sigma ** 2)) +v_init = -c * dy_dx_init +v_init[0] = 0.0 + +a_init = np.zeros(N + 1) +a_init[1:-1] = c**2 * (y_prev[2:] - 2 * y_prev[1:-1] + y_prev[:-2]) / dx ** 2 +a_init[-1] = T * (y_prev[-2] - y_prev[-1]) / (m_eff * dx) +y_curr = y_prev + dt * v_init + 0.5 * dt * dt * a_init +y_curr[0] = 0.0 + +n_frames = int(duration * fps) + 1 +Y_frames = np.zeros((n_frames, N + 1)) +Y_frames[0] = y_prev + +for frame in range(1, n_frames): + for _ in range(n_per_frame): + y_next = np.empty_like(y_curr) + y_next[1:-1] = (2 * y_curr[1:-1] - y_prev[1:-1] + + factor_int * (y_curr[2:] - 2 * y_curr[1:-1] + y_curr[:-2])) + y_next[0] = 0.0 + y_next[-1] = (2 * y_curr[-1] - y_prev[-1] + + factor_ring * (y_curr[-2] - y_curr[-1])) + y_prev, y_curr = y_curr, y_next + Y_frames[frame] = y_curr + +fig_w, fig_h = 10, 4 +fig_aspect = fig_w / fig_h +x_lo_d, x_hi_d = -0.35, L + 0.35 +y_lo_d, y_hi_d = -0.65, 0.65 +dx_v, dy_v = x_hi_d - x_lo_d, y_hi_d - y_lo_d +if dx_v / dy_v < fig_aspect: + extra = (fig_aspect * dy_v - dx_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d - extra, x_hi_d + extra, y_lo_d, y_hi_d +else: + extra = (dx_v / fig_aspect - dy_v) / 2.0 + x_lo, x_hi, y_lo, y_hi = x_lo_d, x_hi_d, y_lo_d - extra, y_hi_d + extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#1a1a2e") +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_facecolor("#16213e") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +wall_patch = patches.Rectangle((x_lo, y_lo), -x_lo, y_hi - y_lo, + facecolor="#4a4e69", edgecolor="none", zorder=0) +ax.add_patch(wall_patch) +ax.plot([0, 0], [y_lo, y_hi], color="#adb5bd", lw=2.5, zorder=1) +ax.axhline(0, color="#3a4357", lw=1, ls="--", zorder=1) + +r_x, r_y = 0.22, 0.11 +back_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=0, theta2=180, + edgecolor="#e63946", lw=11, zorder=2) +ax.add_patch(back_arc) +ax.plot([L, L], [y_lo, y_hi], color="#adb5bd", lw=16, solid_capstyle="butt", zorder=3) +front_arc = patches.Arc((L, 0), 2*r_x, 2*r_y, theta1=180, theta2=360, + edgecolor="#e63946", lw=11, zorder=5) +ax.add_patch(front_arc) + +n_cut = int(round(r_x / dx)) +n_inside = (N + 1) - n_cut +str_x_plot = x_grid[:n_inside] +str_ln, = ax.plot([], [], "-", color="#a8dadc", lw=2.4, zorder=4) + +def update(f): + yy = Y_frames[f, -1] + str_y = Y_frames[f, :n_inside].copy() + str_y[-1] = yy + str_ln.set_data(str_x_plot, str_y) + back_arc.set_center((L, yy)) + front_arc.set_center((L, yy)) + return str_ln, back_arc, front_arc + +ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=1000/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=1800), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/string_ring_wave/688/video.mp4 b/scipy/string_ring_wave/688/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..231c3ab2dc5068ca66ab6d7c239d21532b2bd5ed --- /dev/null +++ b/scipy/string_ring_wave/688/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8230af4c52ad89194454a96a364b8014295798928435cd961d7a2eebeee40f80 +size 17563 diff --git a/scipy/three_body_gravity/075/cot.json b/scipy/three_body_gravity/075/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..84751794cbc4f0fe15732be1dc3578f2fd9be7ac --- /dev/null +++ b/scipy/three_body_gravity/075/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=1.269 kg, m2=1.631 kg, m3=0.590 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.210,-2.326), v3=(0.823,-0.087). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 3.4899317447281035, + "r3_initial": [ + -0.21016505634375202, + -2.3259115905485754 + ], + "v3_initial": [ + 0.8225655933027849, + -0.08689561242363116 + ], + "kinetic_energy_initial": 0.3064681067019669 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 1.2694748021791502, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.630673927991448, + "unit": "", + "description": "" + }, + "m3": { + "value": 0.5897830145575049, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 0.8149876885519874, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": 0.26901087189088374, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.5584528817110561, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.6318127790019237, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": -0.016607797584374917, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.2012790904029898, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.284576840759287, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.1252667217637494, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/075/params.json b/scipy/three_body_gravity/075/params.json new file mode 100644 index 0000000000000000000000000000000000000000..f52b21d7412e3ef115a159b9ea50c16d3c164bbe --- /dev/null +++ b/scipy/three_body_gravity/075/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 1.2694748021791502, + "m2": 1.630673927991448, + "m3": 0.5897830145575049, + "eps": 0.05, + "r1x_0": 0.8149876885519874, + "r1y_0": 0.26901087189088374, + "r2x_0": -0.5584528817110561, + "r2y_0": 0.6318127790019237, + "v1x_0": -0.016607797584374917, + "v1y_0": 0.2012790904029898, + "v2x_0": -0.284576840759287, + "v2y_0": -0.1252667217637494 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/075/simulation_code.py b/scipy/three_body_gravity/075/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..b16b254191fe5bf885abc148d3a3315d24d5175c --- /dev/null +++ b/scipy/three_body_gravity/075/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 1.2694748021791502 +m2 = 1.630673927991448 +m3 = 0.5897830145575049 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([0.8149876885519874, 0.26901087189088374]) +r2_0 = np.array([-0.5584528817110561, 0.6318127790019237]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([-0.016607797584374917, 0.2012790904029898]) +v2_0 = np.array([-0.284576840759287, -0.1252667217637494]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/075/video.mp4 b/scipy/three_body_gravity/075/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..0e58d7bd9973234841653f7479601ba55323723c --- /dev/null +++ b/scipy/three_body_gravity/075/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46611981c8ce39c9bc871727ff87fea9a47658e441dd450c0df7ac9d84404f39 +size 24179 diff --git a/scipy/three_body_gravity/1078/cot.json b/scipy/three_body_gravity/1078/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..4bc5a55e123bd7caaa6fbcae7239c9e90eced759 --- /dev/null +++ b/scipy/three_body_gravity/1078/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=1.194 kg, m2=1.212 kg, m3=1.059 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.513,-0.258), v3=(0.241,-0.122). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 3.46428984220064, + "r3_initial": [ + -0.5131355534887224, + -0.25840631335161773 + ], + "v3_initial": [ + 0.2406738413344925, + -0.12212263812588843 + ], + "kinetic_energy_initial": 0.13487644669738147 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 1.1937963526321824, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.21152630538398, + "unit": "", + "description": "" + }, + "m3": { + "value": 1.0589671841844774, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 1.0988940844584378, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": -0.18343626939811342, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.6342924906852214, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.40661878589358663, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": 0.062331648644677495, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.25028687135429983, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.2717869132573685, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.13987949511291914, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/1078/params.json b/scipy/three_body_gravity/1078/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8e844259343cce3e8e854dfb6ab3298e96cc1451 --- /dev/null +++ b/scipy/three_body_gravity/1078/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 1.1937963526321824, + "m2": 1.21152630538398, + "m3": 1.0589671841844774, + "eps": 0.05, + "r1x_0": 1.0988940844584378, + "r1y_0": -0.18343626939811342, + "r2x_0": -0.6342924906852214, + "r2y_0": 0.40661878589358663, + "v1x_0": 0.062331648644677495, + "v1y_0": 0.25028687135429983, + "v2x_0": -0.2717869132573685, + "v2y_0": -0.13987949511291914 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/1078/simulation_code.py b/scipy/three_body_gravity/1078/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..124004575a8d209b385813ce67b0cfe869c7878a --- /dev/null +++ b/scipy/three_body_gravity/1078/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 1.1937963526321824 +m2 = 1.21152630538398 +m3 = 1.0589671841844774 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([1.0988940844584378, -0.18343626939811342]) +r2_0 = np.array([-0.6342924906852214, 0.40661878589358663]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([0.062331648644677495, 0.25028687135429983]) +v2_0 = np.array([-0.2717869132573685, -0.13987949511291914]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/1078/video.mp4 b/scipy/three_body_gravity/1078/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..640958ac169c6a86b09aabad3abed48f15325d11 --- /dev/null +++ b/scipy/three_body_gravity/1078/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da4bc5d15fa75c1585233db7cc6bfe90fa207dbb0ab5297263d531c767a1f4dd +size 25186 diff --git a/scipy/three_body_gravity/114/cot.json b/scipy/three_body_gravity/114/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..23ff069ff44036a0ac84196b27afb5e0139263fc --- /dev/null +++ b/scipy/three_body_gravity/114/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=0.878 kg, m2=1.724 kg, m3=1.074 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.049,-0.582), v3=(0.273,0.134). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 3.676144325873753, + "r3_initial": [ + -0.04888492244478969, + -0.5818978264251461 + ], + "v3_initial": [ + 0.27335452594117043, + 0.13438200640645653 + ], + "kinetic_energy_initial": 0.21308773275595483 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 0.8776398738766374, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.724479833055264, + "unit": "", + "description": "" + }, + "m3": { + "value": 1.0740246189418516, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 1.2687193920540532, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": -0.2103046491790221, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.6152435631251568, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.469442623539549, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": 0.16865238810922348, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.3136906553039182, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.2560804381265366, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.24334121068674652, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/114/params.json b/scipy/three_body_gravity/114/params.json new file mode 100644 index 0000000000000000000000000000000000000000..8234a8cb1e534b856a02db5c8949ed50db435cd1 --- /dev/null +++ b/scipy/three_body_gravity/114/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 0.8776398738766374, + "m2": 1.724479833055264, + "m3": 1.0740246189418516, + "eps": 0.05, + "r1x_0": 1.2687193920540532, + "r1y_0": -0.2103046491790221, + "r2x_0": -0.6152435631251568, + "r2y_0": 0.469442623539549, + "v1x_0": 0.16865238810922348, + "v1y_0": 0.3136906553039182, + "v2x_0": -0.2560804381265366, + "v2y_0": -0.24334121068674652 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/114/simulation_code.py b/scipy/three_body_gravity/114/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..8283f96c14286c6cdafd904715427f352580dc36 --- /dev/null +++ b/scipy/three_body_gravity/114/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 0.8776398738766374 +m2 = 1.724479833055264 +m3 = 1.0740246189418516 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([1.2687193920540532, -0.2103046491790221]) +r2_0 = np.array([-0.6152435631251568, 0.469442623539549]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([0.16865238810922348, 0.3136906553039182]) +v2_0 = np.array([-0.2560804381265366, -0.24334121068674652]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/114/video.mp4 b/scipy/three_body_gravity/114/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..2a198cc64fa95303fc7bff41e586e4df046f3a9a --- /dev/null +++ b/scipy/three_body_gravity/114/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f9fefa37368351a365ce9e5b7d6a279bd1afac82c583003eaa27bc7f5285659 +size 30990 diff --git a/scipy/three_body_gravity/229/cot.json b/scipy/three_body_gravity/229/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..7abf254898373ad8dad806865f9d63961074baf6 --- /dev/null +++ b/scipy/three_body_gravity/229/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=1.026 kg, m2=1.030 kg, m3=0.946 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.839,-0.404), v3=(0.198,-0.207). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 3.00111522451962, + "r3_initial": [ + -0.8392623286092106, + -0.4039209900229234 + ], + "v3_initial": [ + 0.19832248574835282, + -0.2070014138069996 + ], + "kinetic_energy_initial": 0.13114412769965805 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 1.025841156319597, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.0296864338679566, + "unit": "", + "description": "" + }, + "m3": { + "value": 0.9455876343320667, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 1.212617706883179, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": -0.2718854268682721, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.437373025317342, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.641801166220457, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": 0.08917946633738758, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.29554445938278123, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.2709710916099436, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.10434603121682645, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/229/params.json b/scipy/three_body_gravity/229/params.json new file mode 100644 index 0000000000000000000000000000000000000000..785fd3203ba9d77a469b865f3c1cdaa2bd6db12d --- /dev/null +++ b/scipy/three_body_gravity/229/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 1.025841156319597, + "m2": 1.0296864338679566, + "m3": 0.9455876343320667, + "eps": 0.05, + "r1x_0": 1.212617706883179, + "r1y_0": -0.2718854268682721, + "r2x_0": -0.437373025317342, + "r2y_0": 0.641801166220457, + "v1x_0": 0.08917946633738758, + "v1y_0": 0.29554445938278123, + "v2x_0": -0.2709710916099436, + "v2y_0": -0.10434603121682645 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/229/simulation_code.py b/scipy/three_body_gravity/229/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..6f749547d8f5e6b91b228668a97f1482f74dbb67 --- /dev/null +++ b/scipy/three_body_gravity/229/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 1.025841156319597 +m2 = 1.0296864338679566 +m3 = 0.9455876343320667 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([1.212617706883179, -0.2718854268682721]) +r2_0 = np.array([-0.437373025317342, 0.641801166220457]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([0.08917946633738758, 0.29554445938278123]) +v2_0 = np.array([-0.2709710916099436, -0.10434603121682645]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/229/video.mp4 b/scipy/three_body_gravity/229/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a8c69dc3334169a83fd60f9973690d9eefa338e2 --- /dev/null +++ b/scipy/three_body_gravity/229/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:386ef46e82bc07c564410eb20dfbf913caa5a5262d31cc70849e8b08c38b59d2 +size 29170 diff --git a/scipy/three_body_gravity/490/cot.json b/scipy/three_body_gravity/490/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..485c223eed0a9e8f31fa9ceefa2ff4cd9551abd9 --- /dev/null +++ b/scipy/three_body_gravity/490/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=0.931 kg, m2=1.490 kg, m3=0.617 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.432,-1.645), v3=(0.271,-0.406). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 3.0389210088119407, + "r3_initial": [ + -0.4318141201084455, + -1.644812214910878 + ], + "v3_initial": [ + 0.27114680414931935, + -0.406049393079626 + ], + "kinetic_energy_initial": 0.19423194532494675 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 0.9313473316579016, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.490178169779471, + "unit": "", + "description": "" + }, + "m3": { + "value": 0.6173955073745683, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 1.2783112348011407, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": -0.26011029648288897, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.620027644024095, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.8440284041424431, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": 0.19268553174262956, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.36058925827153065, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.2327654381151451, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.05713462603519459, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/490/params.json b/scipy/three_body_gravity/490/params.json new file mode 100644 index 0000000000000000000000000000000000000000..ce45ff212a7aea029d1648f47d4f4f2c9fbf26eb --- /dev/null +++ b/scipy/three_body_gravity/490/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 0.9313473316579016, + "m2": 1.490178169779471, + "m3": 0.6173955073745683, + "eps": 0.05, + "r1x_0": 1.2783112348011407, + "r1y_0": -0.26011029648288897, + "r2x_0": -0.620027644024095, + "r2y_0": 0.8440284041424431, + "v1x_0": 0.19268553174262956, + "v1y_0": 0.36058925827153065, + "v2x_0": -0.2327654381151451, + "v2y_0": -0.05713462603519459 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/490/simulation_code.py b/scipy/three_body_gravity/490/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..501da5bc5d4c8817841ad7057c93ce5928ed9e5e --- /dev/null +++ b/scipy/three_body_gravity/490/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 0.9313473316579016 +m2 = 1.490178169779471 +m3 = 0.6173955073745683 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([1.2783112348011407, -0.26011029648288897]) +r2_0 = np.array([-0.620027644024095, 0.8440284041424431]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([0.19268553174262956, 0.36058925827153065]) +v2_0 = np.array([-0.2327654381151451, -0.05713462603519459]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/490/video.mp4 b/scipy/three_body_gravity/490/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..1d1ac0a7e6720ecd3ebf3d21684090ff6c66f40d --- /dev/null +++ b/scipy/three_body_gravity/490/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c7cb500bdaa99c0e0924d25242adb79272cff27fccb8f95ed8a50980c33ad9c +size 23192 diff --git a/scipy/three_body_gravity/557/cot.json b/scipy/three_body_gravity/557/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..790bdd425e29819d665721d9aef196ccfc892908 --- /dev/null +++ b/scipy/three_body_gravity/557/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=1.019 kg, m2=1.032 kg, m3=1.046 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.281,-0.876), v3=(0.208,-0.168). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 3.0969690784000936, + "r3_initial": [ + -0.2811939781038418, + -0.8758611004936174 + ], + "v3_initial": [ + 0.2077548842414061, + -0.16780599271662888 + ], + "kinetic_energy_initial": 0.1381303571070751 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 1.0186398763045534, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.0320739525395095, + "unit": "", + "description": "" + }, + "m3": { + "value": 1.0462552495560309, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 0.7033411480051508, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": 0.218842892742868, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.40912830251184634, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.671901635898613, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": -0.061021371029576534, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.3663122090971009, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.15038247602226254, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.19143233107534616, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/557/params.json b/scipy/three_body_gravity/557/params.json new file mode 100644 index 0000000000000000000000000000000000000000..cb7a0d36ee4d930f1df0f8f9decb471cf40d498c --- /dev/null +++ b/scipy/three_body_gravity/557/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 1.0186398763045534, + "m2": 1.0320739525395095, + "m3": 1.0462552495560309, + "eps": 0.05, + "r1x_0": 0.7033411480051508, + "r1y_0": 0.218842892742868, + "r2x_0": -0.40912830251184634, + "r2y_0": 0.671901635898613, + "v1x_0": -0.061021371029576534, + "v1y_0": 0.3663122090971009, + "v2x_0": -0.15038247602226254, + "v2y_0": -0.19143233107534616 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/557/simulation_code.py b/scipy/three_body_gravity/557/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..56304475495ec2308ea5f3c20fadf056135e6df8 --- /dev/null +++ b/scipy/three_body_gravity/557/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 1.0186398763045534 +m2 = 1.0320739525395095 +m3 = 1.0462552495560309 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([0.7033411480051508, 0.218842892742868]) +r2_0 = np.array([-0.40912830251184634, 0.671901635898613]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([-0.061021371029576534, 0.3663122090971009]) +v2_0 = np.array([-0.15038247602226254, -0.19143233107534616]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/557/video.mp4 b/scipy/three_body_gravity/557/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9ffcbf0d8182ebc6132f0a6baac3b981395c27f7 --- /dev/null +++ b/scipy/three_body_gravity/557/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d584b2485861946082ae1dc813ae4b721d2f84fdd3c79bf7a4bbcaa9ec30d89a +size 28122 diff --git a/scipy/three_body_gravity/575/cot.json b/scipy/three_body_gravity/575/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..6d0b42d901981796e6b13edb4b2334b1ffd429a1 --- /dev/null +++ b/scipy/three_body_gravity/575/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=1.130 kg, m2=1.499 kg, m3=1.024 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.054,-1.004), v3=(0.213,0.000). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 3.653451063033849, + "r3_initial": [ + -0.05412200558210601, + -1.0042007983102785 + ], + "v3_initial": [ + 0.21321587734048972, + 0.00014220145648832693 + ], + "kinetic_energy_initial": 0.1770694433135135 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 1.130291915740141, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.4994725384934107, + "unit": "", + "description": "" + }, + "m3": { + "value": 1.023686608800297, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 0.988843215870246, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": -0.19555097241527086, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.7084341281395687, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.8329706353060982, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": 0.11570906354973151, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.3263654453911847, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.2327826942905521, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.24610907152733247, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/575/params.json b/scipy/three_body_gravity/575/params.json new file mode 100644 index 0000000000000000000000000000000000000000..67d739b67d68de161974f373c5ea247b2faf0d4a --- /dev/null +++ b/scipy/three_body_gravity/575/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 1.130291915740141, + "m2": 1.4994725384934107, + "m3": 1.023686608800297, + "eps": 0.05, + "r1x_0": 0.988843215870246, + "r1y_0": -0.19555097241527086, + "r2x_0": -0.7084341281395687, + "r2y_0": 0.8329706353060982, + "v1x_0": 0.11570906354973151, + "v1y_0": 0.3263654453911847, + "v2x_0": -0.2327826942905521, + "v2y_0": -0.24610907152733247 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/575/simulation_code.py b/scipy/three_body_gravity/575/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..87ff86c324e9e679870f82745ec1893eb8d9680c --- /dev/null +++ b/scipy/three_body_gravity/575/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 1.130291915740141 +m2 = 1.4994725384934107 +m3 = 1.023686608800297 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([0.988843215870246, -0.19555097241527086]) +r2_0 = np.array([-0.7084341281395687, 0.8329706353060982]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([0.11570906354973151, 0.3263654453911847]) +v2_0 = np.array([-0.2327826942905521, -0.24610907152733247]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/575/video.mp4 b/scipy/three_body_gravity/575/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..dda4a5d09e6ad54aec7e7ff635c9d9669e8412c3 --- /dev/null +++ b/scipy/three_body_gravity/575/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:559af171d75e03a867b7403216f5d0761e61f87d7542b1756f1b6722286bfbed +size 27532 diff --git a/scipy/three_body_gravity/582/cot.json b/scipy/three_body_gravity/582/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..251d66ddc30bb84a3253b154c59cd89f1b6c21de --- /dev/null +++ b/scipy/three_body_gravity/582/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=1.477 kg, m2=1.547 kg, m3=1.125 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.630,-0.646), v3=(0.258,-0.151). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 4.148242991570276, + "r3_initial": [ + -0.6301194647780813, + -0.6461959117487558 + ], + "v3_initial": [ + 0.2575547465438092, + -0.1505196926789351 + ], + "kinetic_energy_initial": 0.1515985900928963 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 1.4769894963634576, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.54669944082915, + "unit": "", + "description": "" + }, + "m3": { + "value": 1.124554054377669, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 1.1358683560788436, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": -0.10253457948861588, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.6265355806956971, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.5677410272595205, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": 0.039842732924998486, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.2536205772764803, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.22530656137037067, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.13275197017149595, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/582/params.json b/scipy/three_body_gravity/582/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b8c42e9884db3a4b865d3c7cd7ed79f56f1b9d52 --- /dev/null +++ b/scipy/three_body_gravity/582/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 1.4769894963634576, + "m2": 1.54669944082915, + "m3": 1.124554054377669, + "eps": 0.05, + "r1x_0": 1.1358683560788436, + "r1y_0": -0.10253457948861588, + "r2x_0": -0.6265355806956971, + "r2y_0": 0.5677410272595205, + "v1x_0": 0.039842732924998486, + "v1y_0": 0.2536205772764803, + "v2x_0": -0.22530656137037067, + "v2y_0": -0.13275197017149595 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/582/simulation_code.py b/scipy/three_body_gravity/582/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..7560e0c9f8bc41cb70225bf344e0c5e2461be08b --- /dev/null +++ b/scipy/three_body_gravity/582/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 1.4769894963634576 +m2 = 1.54669944082915 +m3 = 1.124554054377669 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([1.1358683560788436, -0.10253457948861588]) +r2_0 = np.array([-0.6265355806956971, 0.5677410272595205]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([0.039842732924998486, 0.2536205772764803]) +v2_0 = np.array([-0.22530656137037067, -0.13275197017149595]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/582/video.mp4 b/scipy/three_body_gravity/582/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4070f9d6bd681de5324f7232909083ccb4798d18 --- /dev/null +++ b/scipy/three_body_gravity/582/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e278ba39032135cec22bfd237ebe3fbe73474d9cd07326d37cb5bd7647a013a3 +size 32798 diff --git a/scipy/three_body_gravity/612/cot.json b/scipy/three_body_gravity/612/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..145be0a5526fb040ae445b3482f3b0e68bf25826 --- /dev/null +++ b/scipy/three_body_gravity/612/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=1.254 kg, m2=1.428 kg, m3=0.850 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-1.018,-0.394), v3=(0.342,0.010). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 3.5318649905096304, + "r3_initial": [ + -1.0180680876972956, + -0.3936900352183935 + ], + "v3_initial": [ + 0.341615904733354, + 0.009504246238306986 + ], + "kinetic_energy_initial": 0.15359780411738377 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 1.2535470248089786, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.4280760586972598, + "unit": "", + "description": "" + }, + "m3": { + "value": 0.8502419070033922, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 1.0843915197084586, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": -0.2008017313196349, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.3457320132976522, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.4106547236143124, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": -0.03363934108411169, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.2603636650537493, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.17386165173663787, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.23420251610959844, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/612/params.json b/scipy/three_body_gravity/612/params.json new file mode 100644 index 0000000000000000000000000000000000000000..2579ec00978549bed736274574598ec4e2209e31 --- /dev/null +++ b/scipy/three_body_gravity/612/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 1.2535470248089786, + "m2": 1.4280760586972598, + "m3": 0.8502419070033922, + "eps": 0.05, + "r1x_0": 1.0843915197084586, + "r1y_0": -0.2008017313196349, + "r2x_0": -0.3457320132976522, + "r2y_0": 0.4106547236143124, + "v1x_0": -0.03363934108411169, + "v1y_0": 0.2603636650537493, + "v2x_0": -0.17386165173663787, + "v2y_0": -0.23420251610959844 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/612/simulation_code.py b/scipy/three_body_gravity/612/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..d068392af6573704bde7c56d3ca727d1b93b8991 --- /dev/null +++ b/scipy/three_body_gravity/612/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 1.2535470248089786 +m2 = 1.4280760586972598 +m3 = 0.8502419070033922 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([1.0843915197084586, -0.2008017313196349]) +r2_0 = np.array([-0.3457320132976522, 0.4106547236143124]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([-0.03363934108411169, 0.2603636650537493]) +v2_0 = np.array([-0.17386165173663787, -0.23420251610959844]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/612/video.mp4 b/scipy/three_body_gravity/612/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..5e7181b8826ac800b0b984104a386458dcb3e7e6 --- /dev/null +++ b/scipy/three_body_gravity/612/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:80694cbd44bcd58d112b9b83cd154421024824165de3d6391491d70a04d8e750 +size 22169 diff --git a/scipy/three_body_gravity/720/cot.json b/scipy/three_body_gravity/720/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..8d325cf50da31257791cc9e875185931b113b76e --- /dev/null +++ b/scipy/three_body_gravity/720/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=0.931 kg, m2=1.127 kg, m3=0.917 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.750,-0.889), v3=(0.228,0.009). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 2.97561573898894, + "r3_initial": [ + -0.749577009141641, + -0.8893128722772706 + ], + "v3_initial": [ + 0.22817467168880198, + 0.009386363157481854 + ], + "kinetic_energy_initial": 0.12217283061258719 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 0.9312768113142282, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.1274206607349346, + "unit": "", + "description": "" + }, + "m3": { + "value": 0.9169182669397772, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 1.2544004134035518, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": -0.1477050457075645, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.4265427995901489, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.8452758892816908, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": 0.12983843312751772, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.2182323908588309, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.292821533267161, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.18789906935502182, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/720/params.json b/scipy/three_body_gravity/720/params.json new file mode 100644 index 0000000000000000000000000000000000000000..38e146251aa3af71829fccba90163e0e3faba9fb --- /dev/null +++ b/scipy/three_body_gravity/720/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 0.9312768113142282, + "m2": 1.1274206607349346, + "m3": 0.9169182669397772, + "eps": 0.05, + "r1x_0": 1.2544004134035518, + "r1y_0": -0.1477050457075645, + "r2x_0": -0.4265427995901489, + "r2y_0": 0.8452758892816908, + "v1x_0": 0.12983843312751772, + "v1y_0": 0.2182323908588309, + "v2x_0": -0.292821533267161, + "v2y_0": -0.18789906935502182 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/720/simulation_code.py b/scipy/three_body_gravity/720/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..3c33f5d82fe49bb2eacb465390290ed1584b3a68 --- /dev/null +++ b/scipy/three_body_gravity/720/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 0.9312768113142282 +m2 = 1.1274206607349346 +m3 = 0.9169182669397772 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([1.2544004134035518, -0.1477050457075645]) +r2_0 = np.array([-0.4265427995901489, 0.8452758892816908]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([0.12983843312751772, 0.2182323908588309]) +v2_0 = np.array([-0.292821533267161, -0.18789906935502182]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/720/video.mp4 b/scipy/three_body_gravity/720/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..c92a622029105e3b91f8fc30f0020b830f9bd05a --- /dev/null +++ b/scipy/three_body_gravity/720/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36aba39b85921088c3dfedf5dbc6e8c69fe7566d534a98a745b237f662707671 +size 25013 diff --git a/scipy/three_body_gravity/736/cot.json b/scipy/three_body_gravity/736/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..0bb83de34649adaf4ad735f77f0fe26dc49629dc --- /dev/null +++ b/scipy/three_body_gravity/736/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=0.820 kg, m2=1.232 kg, m3=0.990 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.335,-1.057), v3=(0.494,0.142). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 3.0416424579676495, + "r3_initial": [ + -0.3352948871650023, + -1.0569609811464495 + ], + "v3_initial": [ + 0.4943293406111392, + 0.1416763349084723 + ], + "kinetic_energy_initial": 0.30221368037832125 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 0.8201227669782187, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.2315015044832558, + "unit": "", + "description": "" + }, + "m3": { + "value": 0.9900181865061751, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 1.037904280471749, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": 0.23151645176693775, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.42164860727557485, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.6955238606043954, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": -0.021988592184498487, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.26543041812801976, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.38275364711154986, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.2906595532438761, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/736/params.json b/scipy/three_body_gravity/736/params.json new file mode 100644 index 0000000000000000000000000000000000000000..b22354356fb8fa74fb17cd2c7f323856b8dcda64 --- /dev/null +++ b/scipy/three_body_gravity/736/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 0.8201227669782187, + "m2": 1.2315015044832558, + "m3": 0.9900181865061751, + "eps": 0.05, + "r1x_0": 1.037904280471749, + "r1y_0": 0.23151645176693775, + "r2x_0": -0.42164860727557485, + "r2y_0": 0.6955238606043954, + "v1x_0": -0.021988592184498487, + "v1y_0": 0.26543041812801976, + "v2x_0": -0.38275364711154986, + "v2y_0": -0.2906595532438761 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/736/simulation_code.py b/scipy/three_body_gravity/736/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ab3fbca7ba2b4e4cb1493faf8d2153bf8bac764b --- /dev/null +++ b/scipy/three_body_gravity/736/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 0.8201227669782187 +m2 = 1.2315015044832558 +m3 = 0.9900181865061751 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([1.037904280471749, 0.23151645176693775]) +r2_0 = np.array([-0.42164860727557485, 0.6955238606043954]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([-0.021988592184498487, 0.26543041812801976]) +v2_0 = np.array([-0.38275364711154986, -0.2906595532438761]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4") diff --git a/scipy/three_body_gravity/736/video.mp4 b/scipy/three_body_gravity/736/video.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..80cc6d0e3eed011fa1d3849c20ec8b58706f206c --- /dev/null +++ b/scipy/three_body_gravity/736/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:beabd7913891c6a88afddb4cc4bdfa0f1975ca06018150ff636a0f150259a7b3 +size 20049 diff --git a/scipy/three_body_gravity/743/cot.json b/scipy/three_body_gravity/743/cot.json new file mode 100644 index 0000000000000000000000000000000000000000..2d5441538fdb906d1347660e8c64dbab4b65ed5e --- /dev/null +++ b/scipy/three_body_gravity/743/cot.json @@ -0,0 +1,124 @@ +{ + "simulation": "three_body_gravity", + "physical_observation": "Three point masses (m1=1.029 kg, m2=1.187 kg, m3=0.783 kg) interact only via mutual Newtonian gravitation (G=1.000 in code units) in otherwise empty 2-D space. Body 3's initial conditions are fixed by total-momentum=0 and centre-of-mass=origin: r3=(-0.718,-0.922), v3=(0.105,-0.446). The COM stays at the origin throughout.", + "physical_law": { + "name": "Newton's Law of Universal Gravitation + Newton's Second Law", + "statement": "Each body experiences pairwise inverse-square attraction; sum gives net acceleration.", + "formula": "\\ddot{r_i} = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + }, + "ode_system": { + "state_variables": [ + "r1, r2, r3 (positions, 2-D)", + "v1, v2, v3 (velocities, 2-D)" + ], + "equations_latex": [ + "\\dot{r}_i = v_i", + "\\dot{v}_i = G \\cdot sum_{j!=i} m_j (r_j - r_i) / (|r_j - r_i|^2 + eps^2)^(3/2)" + ], + "equations_python": [ + "r_dot_i = v_i", + "v_dot_i = G * sum_j_i * m_j (r_j - r_i) / (|r_j - r_i|**2 + eps**2)^(3/2)" + ] + }, + "derivation_steps": [ + "Apply Newton's law of universal gravitation pairwise; sum forces on each body.", + "Divide by m_i (Newton II) to get acceleration; gives 12-D first-order ODE for the 6 DoF (3 bodies x 2-D).", + "Use softening eps to prevent the 1/r^3 singularity at close passes; this keeps the integrator well-behaved.", + "Set body-3 IC from total-momentum=0 and COM=0 so dynamics stays bounded with COM stationary.", + "Conserved quantities: total energy, total momentum (=0 by construction), COM position (=0), L_z." + ], + "physical_constants_derived": { + "M_total_kg": 2.998540364945414, + "r3_initial": [ + -0.7175156908487925, + -0.922010527963968 + ], + "v3_initial": [ + 0.10488511627781691, + -0.44561726372437666 + ], + "kinetic_energy_initial": 0.22348005122114245 + }, + "numerical_method": { + "solver": "DOP853 (Dormand-Prince 8th order)", + "tolerance": "rtol=1e-11, atol=1e-13", + "justification": "High-order with tight tolerances needed because three-body problem is chaotic and conservation drift accumulates." + }, + "code_validation": { + "ode_source": "Newton's law of universal gravitation, summed pairwise.", + "energy_check": "Total energy E and momentum P should be conserved to better than 1e-9 with DOP853.", + "physical_plausibility": true + }, + "expected_behavior": [ + "Generic chaotic motion: small differences in IC lead to exponentially diverging trajectories.", + "Bodies experience close passes occasionally; eps softening prevents numerical blow-up.", + "Centre-of-mass remains at origin throughout the rendered run." + ], + "parameters": { + "G": { + "value": 1.0, + "unit": "", + "description": "" + }, + "m1": { + "value": 1.0285510011267034, + "unit": "", + "description": "" + }, + "m2": { + "value": 1.1874531066531633, + "unit": "", + "description": "" + }, + "m3": { + "value": 0.7825362571655473, + "unit": "", + "description": "" + }, + "eps": { + "value": 0.05, + "unit": "", + "description": "" + }, + "r1x_0": { + "value": 1.2225637282004367, + "unit": "", + "description": "" + }, + "r1y_0": { + "value": 0.08951396011742296, + "unit": "", + "description": "" + }, + "r2x_0": { + "value": -0.5861175481438823, + "unit": "", + "description": "" + }, + "r2y_0": { + "value": 0.5300731378779502, + "unit": "", + "description": "" + }, + "v1x_0": { + "value": 0.09683356017205152, + "unit": "", + "description": "" + }, + "v1y_0": { + "value": 0.4725155831016614, + "unit": "", + "description": "" + }, + "v2x_0": { + "value": -0.15299523034984733, + "unit": "", + "description": "" + }, + "v2y_0": { + "value": -0.11562116398088404, + "unit": "", + "description": "" + } + } +} diff --git a/scipy/three_body_gravity/743/params.json b/scipy/three_body_gravity/743/params.json new file mode 100644 index 0000000000000000000000000000000000000000..494da38ee2aa3d05d8b51acf71bf06d1404cc64d --- /dev/null +++ b/scipy/three_body_gravity/743/params.json @@ -0,0 +1,15 @@ +{ + "G": 1.0, + "m1": 1.0285510011267034, + "m2": 1.1874531066531633, + "m3": 0.7825362571655473, + "eps": 0.05, + "r1x_0": 1.2225637282004367, + "r1y_0": 0.08951396011742296, + "r2x_0": -0.5861175481438823, + "r2y_0": 0.5300731378779502, + "v1x_0": 0.09683356017205152, + "v1y_0": 0.4725155831016614, + "v2x_0": -0.15299523034984733, + "v2y_0": -0.11562116398088404 +} \ No newline at end of file diff --git a/scipy/three_body_gravity/743/simulation_code.py b/scipy/three_body_gravity/743/simulation_code.py new file mode 100644 index 0000000000000000000000000000000000000000..0faadb1a6af6e2fae0be99310467118e4519d135 --- /dev/null +++ b/scipy/three_body_gravity/743/simulation_code.py @@ -0,0 +1,97 @@ +"""Three-Body Gravity — auto-generated.""" +import numpy as np +from scipy.integrate import solve_ivp +import matplotlib.pyplot as plt +import matplotlib.animation as animation + +G = 1.0 +m1 = 1.0285510011267034 +m2 = 1.1874531066531633 +m3 = 0.7825362571655473 +eps = 0.05 +duration = 12 +fps = 30 + +r1_0 = np.array([1.2225637282004367, 0.08951396011742296]) +r2_0 = np.array([-0.5861175481438823, 0.5300731378779502]) +r3_0 = -(m1*r1_0 + m2*r2_0)/m3 +v1_0 = np.array([0.09683356017205152, 0.4725155831016614]) +v2_0 = np.array([-0.15299523034984733, -0.11562116398088404]) +v3_0 = -(m1*v1_0 + m2*v2_0)/m3 +masses = np.array([m1, m2, m3]) + +def three_body(t, s): + p = s[0:6].reshape(3, 2) + v = s[6:12].reshape(3, 2) + a = np.zeros((3, 2)) + eps2 = eps*eps + for i in range(3): + for j in range(3): + if i == j: continue + d = p[j] - p[i] + inv_r3 = (d[0]*d[0] + d[1]*d[1] + eps2) ** (-1.5) + a[i] += G * masses[j] * d * inv_r3 + return np.concatenate([v.flatten(), a.flatten()]) + +t_eval = np.linspace(0.0, duration, int(duration*fps)+1) +y0 = np.concatenate([r1_0, r2_0, r3_0, v1_0, v2_0, v3_0]) +sol = solve_ivp(three_body, (0.0, duration), y0, t_eval=t_eval, + method="DOP853", rtol=1e-11, atol=1e-13) +x1_arr, y1_arr = sol.y[0], sol.y[1] +x2_arr, y2_arr = sol.y[2], sol.y[3] +x3_arr, y3_arr = sol.y[4], sol.y[5] + +all_x = np.concatenate([x1_arr, x2_arr, x3_arr]) +all_y = np.concatenate([y1_arr, y2_arr, y3_arr]) +pad = 0.30 +x_lo, x_hi = all_x.min()-pad, all_x.max()+pad +y_lo, y_hi = all_y.min()-pad, all_y.max()+pad +fig_w, fig_h = 7.0, 5.5 +fig_aspect = fig_w/fig_h +dx, dy = x_hi-x_lo, y_hi-y_lo +if dx/dy < fig_aspect: + extra = (fig_aspect*dy - dx)/2.0 + x_lo -= extra; x_hi += extra +else: + extra = (dx/fig_aspect - dy)/2.0 + y_lo -= extra; y_hi += extra + +fig = plt.figure(figsize=(fig_w, fig_h), facecolor="#0b0b1f") +ax = fig.add_axes([0,0,1,1]); ax.set_facecolor("#0b0b1f") +ax.set_xlim(x_lo, x_hi); ax.set_ylim(y_lo, y_hi) +ax.set_aspect("equal"); ax.axis("off") + +rng = np.random.default_rng(13) +star_x = rng.uniform(x_lo, x_hi, size=160) +star_y = rng.uniform(y_lo, y_hi, size=160) +star_s = rng.uniform(0.5, 3.5, size=160)**2 +star_a = rng.uniform(0.30, 0.85, size=160) +ax.scatter(star_x, star_y, s=star_s, c="white", alpha=star_a, zorder=0, edgecolors='none') +ax.plot([0.0], [0.0], '+', color="#e0e0e0", markersize=11, markeredgewidth=1.0, zorder=1) + +trail_len = 80 +trail1, = ax.plot([], [], '-', color="#80c0ff", lw=1.4, alpha=0.75, zorder=2) +trail2, = ax.plot([], [], '-', color="#ffd166", lw=1.4, alpha=0.75, zorder=2) +trail3, = ax.plot([], [], '-', color="#ef476f", lw=1.4, alpha=0.75, zorder=2) +m_max = max(m1, m2, m3) +size1 = 18.0 * (m1/m_max)**(1.0/3.0) +size2 = 18.0 * (m2/m_max)**(1.0/3.0) +size3 = 18.0 * (m3/m_max)**(1.0/3.0) +body1, = ax.plot([], [], 'o', color="#80c0ff", markersize=size1, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body2, = ax.plot([], [], 'o', color="#ffd166", markersize=size2, markeredgecolor="white", markeredgewidth=1.0, zorder=4) +body3, = ax.plot([], [], 'o', color="#ef476f", markersize=size3, markeredgecolor="white", markeredgewidth=1.0, zorder=4) + +def update(f): + s = max(0, f - trail_len) + trail1.set_data(x1_arr[s:f+1], y1_arr[s:f+1]) + trail2.set_data(x2_arr[s:f+1], y2_arr[s:f+1]) + trail3.set_data(x3_arr[s:f+1], y3_arr[s:f+1]) + body1.set_data([x1_arr[f]], [y1_arr[f]]) + body2.set_data([x2_arr[f]], [y2_arr[f]]) + body3.set_data([x3_arr[f]], [y3_arr[f]]) + return trail1, trail2, trail3, body1, body2, body3 + +ani = animation.FuncAnimation(fig, update, frames=len(t_eval), interval=1000.0/fps, blit=True) +ani.save("video.mp4", writer=animation.FFMpegWriter(fps=fps, bitrate=2400), dpi=120) +plt.close() +print("Saved video.mp4")