docs: case05纵波 + case06横波一维原子链
- case05 Readme.md 更新为纵波模拟描述 - case05 run_dynamics.py 注释更新 - case06 创建为一维原子链横波模拟 - coord.txt: fix_x=1, fix_y=1, fix_z=0 (z方向自由) - driver.txt: amp_z=0.5, freq_z=0.1, phi_z=90° - input.txt: 横波配置 + step_plot_wave - Readme.md + doc/index.html + run_dynamics.py - 模拟验证通过 (50000步/30s)
This commit is contained in:
+26
-7
@@ -234,19 +234,38 @@ def plot_wave(output_dir):
|
||||
|
||||
ani = FuncAnimation(fig, update, frames=n_frames, interval=50, blit=True)
|
||||
|
||||
# 保存 GIF
|
||||
# ── 先输出 GIF(自动循环)──
|
||||
gif_path = os.path.join(output_dir, "wave_animation.gif")
|
||||
ani.save(gif_path, writer="pillow", fps=min(20, max(1, n_frames // 5)))
|
||||
print(f"[plot_wave] GIF 已保存: {gif_path}")
|
||||
|
||||
# 尝试保存 MP4
|
||||
# ── 再输出 MP4(需要 ffmpeg)──
|
||||
try:
|
||||
mp4_path = os.path.join(output_dir, "wave_animation.mp4")
|
||||
ani.save(mp4_path, writer="ffmpeg", fps=min(20, max(1, n_frames // 5)))
|
||||
print(f"[plot_wave] MP4 已保存: {mp4_path}")
|
||||
except Exception:
|
||||
pass
|
||||
import matplotlib.animation as manim
|
||||
import matplotlib.pyplot as _plt
|
||||
|
||||
# 尝试通过 imageio_ffmpeg 定位 ffmpeg
|
||||
ffmpeg_path = None
|
||||
try:
|
||||
import imageio_ffmpeg
|
||||
ffmpeg_path = imageio_ffmpeg.get_ffmpeg_exe()
|
||||
except Exception:
|
||||
pass
|
||||
if ffmpeg_path and os.path.exists(ffmpeg_path):
|
||||
_plt.rcParams['animation.ffmpeg_path'] = ffmpeg_path
|
||||
|
||||
ffps = min(20, max(1, n_frames // 5))
|
||||
writer = manim.FFMpegWriter(fps=ffps, codec="libx264",
|
||||
extra_args=["-pix_fmt", "yuv420p"])
|
||||
mp4_path = os.path.join(output_dir, "wave_animation.mp4")
|
||||
ani.save(mp4_path, writer=writer)
|
||||
print(f"[plot_wave] MP4 已保存: {mp4_path}")
|
||||
except FileNotFoundError:
|
||||
print("[plot_wave] 警告: 未找到 ffmpeg,跳过 MP4 输出")
|
||||
except Exception as e:
|
||||
print(f"[plot_wave] 警告: MP4 输出失败 ({e}),跳过")
|
||||
|
||||
# ── 最后显示动画窗口 ──
|
||||
plt.show()
|
||||
return gif_path
|
||||
|
||||
|
||||
Reference in New Issue
Block a user