"""The full (nonlinear) model on the 16 inch crash with a bell, compared with the linear model for the same strike. On a CPU this takes a few minutes per second of sound; pass a shorter duration or a coarser spacing to try it out.""" import sys import matplotlib.pyplot as plt import cymsim from cymsim import plot duration = float(sys.argv[1]) if len(sys.argv) > 1 else 1.0 spacing = float(sys.argv[2]) if len(sys.argv) > 2 else 0.008 plate = cymsim.presets.crash_bell_16().evaluate(spacing=spacing) print(plate.summary()) strike = cymsim.Strike(x=0.9, y=0.5, velocity=3.0) listener = cymsim.Listener(distance=0.5, angle=30) sim = cymsim.Simulation(plate, strike, listener, duration=duration, movie=True) print(f"device {sim.device}, dt {sim.dt * 1e6:.2f} us, {sim.steps_per_sample} steps per sample, loss sigma0 {sim.loss[0]:.2f} 1/s, sigma1 {sim.loss[1]:.2e} m^2/s") sim.run(progress=True) full = sim.sound() print(full, f"in {full.info['seconds']:.0f} s wall") full.to_wav("crash_bell_full.wav") modes = cymsim.compute_modes(plate, fmax=16000) linear = cymsim.synthesize(modes, strike, listener, duration=duration) linear.to_wav("crash_bell_linear.wav") fig, axes = plt.subplots(2, 1, figsize=(10, 8), sharex=True) plot.spectrogram(full, ax=axes[0], modes=modes, fmax=16000) axes[0].set_title("full model") plot.spectrogram(linear, ax=axes[1], modes=modes, fmax=16000) axes[1].set_title("linear model") fig.tight_layout() fig.savefig("crash_bell.png", dpi=120) print("wrote crash_bell_full.wav, crash_bell_linear.wav, crash_bell.png")