From 6298ed5b346abcc95eed8862015e723ea58df432 Mon Sep 17 00:00:00 2001 From: Ying-Li Niu <64801511@qq.com> Date: Fri, 12 Jun 2026 08:11:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=96=E9=83=A8=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=20display.txt=20=E6=9C=AA=E9=9A=8F=20T=5Ftot?= =?UTF-8?q?al=20=E5=8F=98=E6=9B=B4=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当 T_total 从 20→100 时,外部引擎写入的 trajectory.txt 是新的, 但 display.txt 缓存未刷新(检查是否存在而非检查是否过期), 导致总帧数仍为 200(NT=20000 时的数据)。 修复:外部引擎路径总是从 trajectory.txt 重新抽帧生成 display.txt。 --- dynamics.py | 11 +++++++---- examples/case06/input/input.txt | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/dynamics.py b/dynamics.py index 030092b..b2919cc 100644 --- a/dynamics.py +++ b/dynamics.py @@ -245,12 +245,15 @@ def run_case(config_path, runtime_base, input_dir="input", output_dir="output", else: print("[run] 步骤 [模拟] 已跳过") - # 3. 检查 display.txt(新格式),不存在则从 trajectory.txt 抽帧生成 + # 3. 生成 display.txt:模拟完成后总是刷新,避免参数变更后缓存过时 disp_path_new = os.path.join(output_dir_abs, "display.txt") - if os.path.exists(disp_path_new): - print(f"[run] 发现已有 display.txt(引擎直接抽帧)") + + if engine == "python": + # Python 引擎在 run_simulation 内部已写入 display.txt + if os.path.exists(disp_path_new): + print(f"[run] 发现已有 display.txt(引擎直接抽帧)") else: - # 从 trajectory.txt 抽帧(外部引擎) + # 外部引擎:从 trajectory.txt 重新抽帧(覆盖旧的 display.txt) traj_path = os.path.join(output_dir_abs, "trajectory.txt") if not os.path.exists(traj_path): print(f"[run] 错误: 找不到 trajectory.txt 或 display.txt") diff --git a/examples/case06/input/input.txt b/examples/case06/input/input.txt index bab4691..95cbaf0 100644 --- a/examples/case06/input/input.txt +++ b/examples/case06/input/input.txt @@ -10,7 +10,7 @@ step_sample: 0 # (旧版)从 trajectory.txt 重新抽帧,默认0=不 step_plot: 0 # 绘制轨迹/能量图 → output/trajectory_plots.png step_animation: 1 # 自动播放 VisPy 3D 动画窗口(需安装 vispy) step_plot_wave: 0 # 绘制波形能量动画 -force_calc: 0 # 强制重新计算:1=跳过缓存强算,0=自动使用已有输出 +force_calc: 1 # 强制重新计算:1=跳过缓存强算,0=自动使用已有输出 plot_wave_save_gif: 1 # 输出波形 GIF(需 step_plot_wave=1) plot_wave_save_mp4: 1 # 输出波形 MP4(需 step_plot_wave=1) @@ -66,10 +66,10 @@ warmup_steps: 0 # 默认 0(立即开始记录) # 总模拟时间(秒),程序自动计算 NT = T_total / DT # 如果同时指定了 NT,以 NT 为准 -T_total: 20.0 +T_total: 100.0 # 抽帧间隔(每 NSTEP 步取一帧用于动画) -NSTEP: 10 +NSTEP: 100 # ── 时间步长 ────────────────────────────────── DT: 0.01 # 时间步长 (s)